diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 88cfb9d1..ab902603 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -167,7 +167,7 @@ class AdminPage extends Extension { $zip = new ZipArchive; $images = $database->get_all("SELECT * FROM images"); - $filename = 'data/imgdump-'.date('Ymd').'.zip'; + $filename = data_path('imgdump-'.date('Ymd').'.zip'); if($zip->open($filename, 1 ? ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE) === TRUE){ foreach($images as $img){ diff --git a/contrib/oekaki/main.php b/contrib/oekaki/main.php index 2c534889..49e1e2cc 100644 --- a/contrib/oekaki/main.php +++ b/contrib/oekaki/main.php @@ -24,12 +24,10 @@ class Oekaki extends Extension { if(isset($_FILES["picture"])) { header('Content-type: text/plain'); - $uploaddir = './data/oekaki_unclaimed/'; - if(!file_exists($uploaddir)) mkdir($uploaddir, 0755, true); $file = $_FILES['picture']['name']; $ext = (strpos($file, '.') === FALSE) ? '' : substr($file, strrpos($file, '.')); $uploadname = $_SERVER['REMOTE_ADDR'] . "." . time(); - $uploadfile = $uploaddir . $uploadname; + $uploadfile = data_path('oekaki_unclaimed/'.$uploadname); log_info("oekaki", "Uploading file [$uploadname]"); @@ -53,7 +51,7 @@ class Oekaki extends Extension { // FIXME: move .chi to data/oekaki/$ha/$hash mirroring images and thumbs // FIXME: .chi viewer? // FIXME: clean out old unclaimed images? - $pattern = './data/oekaki_unclaimed/' . $_SERVER['REMOTE_ADDR'] . ".*.png"; + $pattern = data_path('oekaki_unclaimed/' . $_SERVER['REMOTE_ADDR'] . ".*.png"); foreach(glob($pattern) as $tmpname) { assert(file_exists($tmpname)); diff --git a/contrib/resize/main.php b/contrib/resize/main.php index caba3ed4..139f3ca8 100644 --- a/contrib/resize/main.php +++ b/contrib/resize/main.php @@ -265,7 +265,6 @@ class ResizeImage extends Extension { $new_hash = md5_file($tmp_filename); $new_size = filesize($tmp_filename); $target = warehouse_path("images", $new_hash); - if(!file_exists(dirname($target))) mkdir(dirname($target), 0755, true); if(!@copy($tmp_filename, $target)) { throw new ImageResizeException("Failed to copy new image file from temporary location ({$tmp_filename}) to archive ($target)"); } diff --git a/contrib/update/main.php b/contrib/update/main.php index 90372e42..9aad4c2c 100644 --- a/contrib/update/main.php +++ b/contrib/update/main.php @@ -91,7 +91,7 @@ class Update extends Extension { $commit = $matches[2]; mkdir("./backup"); $html .= "
backup folder created!"; - $d_dir = "data/cache"; + $d_dir = data_path("cache"); //This should empty the /data/cache/ folder. if (is_dir($d_dir)) { $objects = scandir($d_dir); diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 83a30d3a..e562de10 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -1080,7 +1080,6 @@ class Tag { */ function move_upload_to_archive(DataUploadEvent $event) { $target = warehouse_path("images", $event->hash); - if(!file_exists(dirname($target))) mkdir(dirname($target), 0755, true); if(!@copy($event->tmpname, $target)) { $errors = error_get_last(); // note: requires php 5.2 throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive ($target): {$errors['type']} / {$errors['message']}"); diff --git a/core/page.class.php b/core/page.class.php index dae6dd9b..6a562f38 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -246,17 +246,13 @@ class Page { $this->add_html_header(""); $this->add_html_header(""); - if(!file_exists("data/cache")) { - mkdir("data/cache"); - } - $css_files = array(); $css_latest = 0; foreach(array_merge(zglob("lib/*.css"), zglob("ext/*/style.css"), zglob("themes/$theme_name/style.css")) as $css) { $css_files[] = $css; $css_latest = max($css_latest, filemtime($css)); } - $css_cache_file = "data/cache/style.$css_latest.css"; + $css_cache_file = data_path("cache/style.$css_latest.css"); if(!file_exists($css_cache_file)) { $css_data = ""; foreach($css_files as $file) { @@ -276,7 +272,7 @@ class Page { $js_files[] = $js; $js_latest = max($js_latest, filemtime($js)); } - $js_cache_file = "data/cache/script.$js_latest.js"; + $js_cache_file = data_path("cache/script.$js_latest.js"); if(!file_exists($js_cache_file)) { $js_data = ""; foreach($js_files as $file) { diff --git a/core/util.inc.php b/core/util.inc.php index 2de968e1..8dff786e 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -645,6 +645,12 @@ function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=tru return $pa; } +function data_path($filename) { + $filename = "data/" . $filename; + if($create && !file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true); + return $filename; +} + function transload($url, $mfile) { global $config; @@ -1075,10 +1081,7 @@ function _load_extensions() { $p .= ");\n"; $p .= "?".">"; - if(!file_exists("data/cache")) { - mkdir("data/cache", 755, true); - } - file_put_contents("data/cache/event_listeners.php", $p); + file_put_contents(data_path("cache/event_listeners.php"), $p); } } @@ -1232,11 +1235,9 @@ function _start_cache() { $_cache_hash = md5($_SERVER["QUERY_STRING"]); $ab = substr($_cache_hash, 0, 2); $cd = substr($_cache_hash, 2, 2); - $_cache_filename = "data/http_cache/$ab/$cd/$_cache_hash"; + $_cache_filename = data_path("http_cache/$ab/$cd/$_cache_hash"); + @chmod(data_path('http_cache'), 750); - if(!file_exists(dirname($_cache_filename))) { - mkdir(dirname($_cache_filename), 0750, true); - } if(file_exists($_cache_filename) && (filemtime($_cache_filename) > time() - 3600)) { $gmdate_mod = gmdate('D, d M Y H:i:s', filemtime($_cache_filename)) . ' GMT';