diff --git a/core/app/OriginalFiles.php b/core/app/OriginalFiles.php index 24dc509f..677ff90b 100644 --- a/core/app/OriginalFiles.php +++ b/core/app/OriginalFiles.php @@ -57,7 +57,10 @@ function create_settings_file() file_put_contents(ROOT_DIR . $target, $file . "\n?" . '>'); } -function create_generic_folders() +// Go through the folder tree, look for folders that have yet to be created, +// create them as needed, and create index.php and .htaccess files if required. +// $force is used by the weekly maintenance task to re-create files if deleted. +function create_generic_folders($force = false) { $folders = array( 'attachments' => true, @@ -81,31 +84,36 @@ function create_generic_folders() foreach ($folders as $key => $folder) { - if (!file_exists(ROOT_DIR . '/' . $key)) - create_generic_folder(ROOT_DIR, $key); + if ($force || !file_exists(ROOT_DIR . '/' . $key)) + create_generic_folder(ROOT_DIR, $key, $force); if (is_array($folder)) foreach ($folder as $sub_folder) - if (!file_exists(ROOT_DIR . '/' . $key . '/' . $sub_folder)) - create_generic_folder(ROOT_DIR, $key . '/' . $sub_folder); + if ($force || !file_exists(ROOT_DIR . '/' . $key . '/' . $sub_folder)) + create_generic_folder(ROOT_DIR, $key . '/' . $sub_folder, $force); } } -function create_generic_folder($root_dir, $folder) +function create_generic_folder($root_dir, $folder, $force = false) { // We're gonna let PHP output warnings or errors on mkdir and copy, because it's serious stuff. $path = str_replace('/', DIRECTORY_SEPARATOR, $root_dir . '/' . $folder); - mkdir($path); + if (!$force || !file_exists($path)) + mkdir($path); // We need to put and index.php file in all folders. - file_put_contents($path . '/index.php', '<' . '?php + if (!$force || !file_exists($path . '/index.php')) + file_put_contents($path . '/index.php', '<' . '?php // Redirect to the upper level. header(\'Location: ../\');'); // Copy assets/icons/media to media/icons. After that, you can freely delete the originals. - if ($folder == 'media/icons' && file_exists($root_dir . '/assets/icons/media')) + if (!$force && ($folder == 'media/icons' && file_exists($root_dir . '/assets/icons/media'))) foreach (glob($root_dir . '/assets/icons/media/*.png') as $png_file) copy($png_file, $root_dir . '/media/icons/' . basename($png_file)); + if ($force && file_exists($path . '/.htaccess')) + return; + // We need to be able to access images and various other files from plugins/, but not the archives of plugins themselves. if ($folder == 'plugins') $file = ' @@ -149,15 +157,15 @@ function create_generic_folder($root_dir, $folder) - AddEncoding x-gzip .gz - AddEncoding x-gzip .cgz + AddEncoding x-gzip .gz' . ($folder == 'gz/js' ? ' AddEncoding x-gzip .jgz ForceType text/javascript - + ' : ' + AddEncoding x-gzip .cgz ForceType text/css - + ') . ' diff --git a/core/app/ScheduledTasks.php b/core/app/ScheduledTasks.php index b0aa7d1b..91b253b0 100644 --- a/core/app/ScheduledTasks.php +++ b/core/app/ScheduledTasks.php @@ -1401,46 +1401,9 @@ function scheduled_weekly_maintenance() ) ); - // Check the cache folders etc. have what they're supposed to have. Just remember that we have to mask things from occasional silly hosts. - if (!file_exists(CACHE_DIR . '/index.php')) - @file_put_contents(CACHE_DIR . '/index.php', '<' . '?ph' . "p\n\n// Redirect to the upper level.\nheader('Location: ../');\n"); - - if (!file_exists($cachedir . '/.htaccess')) - @file_put_contents($cachedir . '/.htaccess', ' - Deny from all - - - - Deny from all - - - - Deny from all - - - - Allow from all - - - - AddEncoding x-gzip .gz - AddEncoding x-gzip .cgz - AddEncoding x-gzip .jgz - - ForceType text/javascript - - - ForceType text/css - - - - - Header set Cache-Control "max-age=2592000" - Header set Expires "Thu, 21 March 2025 03:42:00 GMT" - Header set Vary "Accept-Encoding" - - -FileETag none'); + // Check whether the generic folders were removed or something. + loadSource('OriginalFiles'); + create_generic_folders(true); return true; }