diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-17 19:14:42 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-17 19:14:42 +0000 |
commit | b41323642bffd3761f73a8c9dc8260546d7533f1 (patch) | |
tree | 1a0530685d18eb01e0356fbed7de91aba00405e9 /modules/system/system.module | |
parent | 0138e3946ab2458ffb97066d4b8a0cd94d83e516 (diff) | |
download | brdo-b41323642bffd3761f73a8c9dc8260546d7533f1.tar.gz brdo-b41323642bffd3761f73a8c9dc8260546d7533f1.tar.bz2 |
#517814 by jmstacey, justinrandell, pwolanin, drewish, Jody Lynn, aaron, dopry, and c960657: Converted File API to stream wrappers, for enhanced private/public file handling, and the ability to reference other storage mechanisms such as s3:// and flicker://.
Diffstat (limited to 'modules/system/system.module')
-rw-r--r-- | modules/system/system.module | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/modules/system/system.module b/modules/system/system.module index 001949c04..5a63d4a65 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -473,6 +473,14 @@ function system_menu() { $items['system/files'] = array( 'title' => 'File download', 'page callback' => 'file_download', + 'page arguments' => array('private'), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + $items['system/temporary'] = array( + 'title' => 'Temporary files', + 'page callback' => 'file_download', + 'page arguments' => array('temporary'), 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); @@ -1589,16 +1597,37 @@ function system_admin_menu_block($item) { /** * Checks the existence of the directory specified in $form_element. This - * function is called from the system_settings form to check both the - * file_directory_path and file_directory_temp directories. If validation - * fails, the form element is flagged with an error from within the - * file_check_directory function. + * function is called from the system_settings form to check both core file + * directories (file_public_path, file_private_path, file_temporary_path). * * @param $form_element * The form element containing the name of the directory to check. */ function system_check_directory($form_element) { - file_check_directory($form_element['#value'], FILE_CREATE_DIRECTORY, $form_element['#parents'][0]); + $directory = $form_element['#value']; + + if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) { + // If the directory does not exists and cannot be created. + form_set_error($form_element['#parents'][0], t('The directory %directory does not exist and could not be created.', array('%directory' => $directory))); + watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR); + } + + if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) { + // If the directory is not writable and cannont be made so. + form_set_error($form_element['#parents'][0], t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory))); + watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR); + } + else { + if ($form_element['#name'] == 'file_public_path') { + // Create public .htaccess file. + file_create_htaccess($directory, FALSE); + } + else { + // Create private .htaccess file. + file_create_htaccess($directory); + } + } + return $form_element; } @@ -1615,7 +1644,7 @@ function system_get_files_database(&$files, $type) { $result = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = :type", array(':type' => $type)); foreach ($result as $file) { if (isset($files[$file->name]) && is_object($files[$file->name])) { - $file->filepath = $file->filename; + $file->uri = $file->filename; foreach ($file as $key => $value) { if (!isset($files[$file->name]->key)) { $files[$file->name]->$key = $value; @@ -1691,7 +1720,7 @@ function system_update_files_database(&$files, $type) { } else { $query->values(array( - 'filename' => $file->filepath, + 'filename' => $file->uri, 'name' => $file->name, 'type' => $type, 'owner' => isset($file->owner) ? $file->owner : '', @@ -1729,7 +1758,7 @@ function _system_get_module_data() { // Read info files for each module. foreach ($modules as $key => $module) { // Look for the info file. - $module->info = drupal_parse_info_file(dirname($module->filepath) . '/' . $module->name . '.info'); + $module->info = drupal_parse_info_file(dirname($module->uri) . '/' . $module->name . '.info'); // Skip modules that don't provide info. if (empty($module->info)) { @@ -1811,8 +1840,8 @@ function _system_get_theme_data() { $sub_themes = array(); // Read info files for each theme foreach ($themes as $key => $theme) { - $themes[$key]->filename = $theme->filepath; - $themes[$key]->info = drupal_parse_info_file($theme->filepath) + $defaults; + $themes[$key]->filename = $theme->uri; + $themes[$key]->info = drupal_parse_info_file($theme->uri) + $defaults; // Invoke hook_system_info_alter() to give installed modules a chance to // modify the data in the .info files if necessary. @@ -1822,7 +1851,7 @@ function _system_get_theme_data() { $sub_themes[] = $key; } if (empty($themes[$key]->info['engine'])) { - $filename = dirname($themes[$key]->filepath) . '/' . $themes[$key]->name . '.theme'; + $filename = dirname($themes[$key]->uri) . '/' . $themes[$key]->name . '.theme'; if (file_exists($filename)) { $themes[$key]->owner = $filename; $themes[$key]->prefix = $key; @@ -1831,7 +1860,7 @@ function _system_get_theme_data() { else { $engine = $themes[$key]->info['engine']; if (isset($engines[$engine])) { - $themes[$key]->owner = $engines[$engine]->filepath; + $themes[$key]->owner = $engines[$engine]->uri; $themes[$key]->prefix = $engines[$engine]->name; $themes[$key]->template = TRUE; } @@ -1842,7 +1871,7 @@ function _system_get_theme_data() { if (isset($themes[$key]->info['stylesheets'])) { foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) { foreach ($stylesheets as $stylesheet) { - $pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->filepath) . '/' . $stylesheet; + $pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->uri) . '/' . $stylesheet; } } } @@ -1852,13 +1881,13 @@ function _system_get_theme_data() { $scripts = array(); if (isset($themes[$key]->info['scripts'])) { foreach ($themes[$key]->info['scripts'] as $script) { - $scripts[$script] = dirname($themes[$key]->filepath) . '/' . $script; + $scripts[$script] = dirname($themes[$key]->uri) . '/' . $script; } } $themes[$key]->info['scripts'] = $scripts; // Give the screenshot proper path information. if (!empty($themes[$key]->info['screenshot'])) { - $themes[$key]->info['screenshot'] = dirname($themes[$key]->filepath) . '/' . $themes[$key]->info['screenshot']; + $themes[$key]->info['screenshot'] = dirname($themes[$key]->uri) . '/' . $themes[$key]->info['screenshot']; } } @@ -2225,7 +2254,7 @@ function system_cron() { // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE. // Use separate placeholders for the status to avoid a bug in some versions // of PHP. See http://drupal.org/node/352956 - $result = db_query('SELECT fid FROM {files} WHERE status & :permanent1 <> :permanent2 AND timestamp < :timestamp', array( + $result = db_query('SELECT fid FROM {file} WHERE status & :permanent1 <> :permanent2 AND timestamp < :timestamp', array( ':permanent1' => FILE_STATUS_PERMANENT, ':permanent2' => FILE_STATUS_PERMANENT, ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE @@ -2233,7 +2262,7 @@ function system_cron() { foreach ($result as $row) { if ($file = file_load($row->fid)) { if (!file_delete($file)) { - watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->filepath), WATCHDOG_ERROR); + watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR); } } } @@ -3006,7 +3035,7 @@ function system_image_toolkits() { */ function system_retrieve_file($url, $destination = NULL, $overwrite = TRUE) { if (!$destination) { - $destination = file_directory_temp(); + $destination = file_directory_path('temporary'); } $parsed_url = parse_url($url); $local = is_dir(file_directory_path() . '/' . $destination) ? $destination . '/' . basename($parsed_url['path']) : $destination; |