Commit b4132364 authored by webchick's avatar webchick

#517814 by jmstacey, justinrandell, pwolanin, drewish, Jody Lynn, aaron,...

#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://.
parent 0138e394
......@@ -127,10 +127,13 @@ INSTALLATION
files directory may be changed after Drupal is installed). In some
cases, you may need to create the directory and modify its permissions
manually. Use the following commands (from the installation directory)
to create the files directory and grant the web server write privileges to it:
to create the public and private files directories and grant the web server
write privileges to them:
mkdir sites/default/files
chmod o+w sites/default/files
mkdir sites/default/private
chmod o+w sites/default/private
The install script will attempt to write-protect the settings.php file and
the sites/default directory after saving your configuration. However, you
......
......@@ -656,8 +656,8 @@ function drupal_get_filename($type, $name, $filename = NULL) {
if (drupal_function_exists('drupal_system_listing')) {
$matches = drupal_system_listing($mask, $dir, 'name', 0);
if (!empty($matches[$name]->filepath)) {
$files[$type][$name] = $matches[$name]->filepath;
if (!empty($matches[$name]->uri)) {
$files[$type][$name] = $matches[$name]->uri;
}
}
}
......
......@@ -2560,8 +2560,8 @@ function drupal_get_css($css = NULL) {
}
$preprocess_css = (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
$directory = file_directory_path();
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
$directory = file_directory_path('public');
$is_writable = is_dir($directory) && is_writable($directory);
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
......@@ -2601,7 +2601,7 @@ function drupal_get_css($css = NULL) {
case 'file':
// Depending on whether aggregation is desired, include the file.
if (!$item['preprocess'] || !($is_writable && $preprocess_css)) {
$rendered_css[] = '<link type="text/css" rel="stylesheet" media="' . $item['media'] . '" href="' . base_path() . $item['data'] . $query_string . '" />';
$rendered_css[] = '<link type="text/css" rel="stylesheet" media="' . $item['media'] . '" href="' . file_create_url($item['data']) . $query_string . '" />';
}
else {
$preprocess_items[$item['media']][] = $item;
......@@ -2626,8 +2626,8 @@ function drupal_get_css($css = NULL) {
// Prefix filename to prevent blocking by firewalls which reject files
// starting with "ad*".
$filename = 'css_' . md5(serialize($items) . $query_string) . '.css';
$preprocess_file = drupal_build_css_cache($items, $filename);
$rendered_css['preprocess'] .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $preprocess_file . '" />' . "\n";
$preprocess_file = file_create_url(drupal_build_css_cache($items, $filename));
$rendered_css['preprocess'] .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . $preprocess_file . '" />' . "\n";
}
}
// Enclose the inline CSS with the style tag if required.
......@@ -2653,9 +2653,8 @@ function drupal_build_css_cache($css, $filename) {
$data = '';
// Create the css/ within the files folder.
$csspath = file_create_path('css');
file_check_directory($csspath, FILE_CREATE_DIRECTORY);
$csspath = 'public://css';
file_prepare_directory($csspath, FILE_CREATE_DIRECTORY);
if (!file_exists($csspath . '/' . $filename)) {
// Build aggregate CSS file.
foreach ($css as $stylesheet) {
......@@ -2797,7 +2796,7 @@ function _drupal_load_stylesheet($matches) {
* Delete all cached CSS files.
*/
function drupal_clear_css_cache() {
file_scan_directory(file_create_path('css'), '/.*/', array('callback' => 'file_unmanaged_delete'));
file_scan_directory('public://css', '/.*/', array('callback' => 'file_unmanaged_delete'));
}
/**
......@@ -3039,8 +3038,8 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
$no_preprocess = '';
$files = array();
$preprocess_js = (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
$directory = file_directory_path();
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
$directory = file_directory_path('public');
$is_writable = is_dir($directory) && is_writable($directory);
// A dummy query-string is added to filenames, to gain control over
// browser-caching. The string changes on every update or full cache
......@@ -3072,7 +3071,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
case 'file':
if (!$item['preprocess'] || !$is_writable || !$preprocess_js) {
$no_preprocess .= '<script type="text/javascript"' . ($item['defer'] ? ' defer="defer"' : '') . ' src="' . base_path() . $item['data'] . ($item['cache'] ? $query_string : '?' . REQUEST_TIME) . "\"></script>\n";
$no_preprocess .= '<script type="text/javascript"' . ($item['defer'] ? ' defer="defer"' : '') . ' src="' . file_create_url($item['data']) . ($item['cache'] ? $query_string : '?' . REQUEST_TIME) . "\"></script>\n";
}
else {
$files[$item['data']] = $item;
......@@ -3091,8 +3090,8 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
// Prefix filename to prevent blocking by firewalls which reject files
// starting with "ad*".
$filename = 'js_' . md5(serialize($files) . $query_string) . '.js';
$preprocess_file = drupal_build_js_cache($files, $filename);
$preprocessed .= '<script type="text/javascript" src="' . base_path() . $preprocess_file . '"></script>' . "\n";
$preprocess_file = file_create_url(drupal_build_js_cache($files, $filename));
$preprocessed .= '<script type="text/javascript" src="' . $preprocess_file . '"></script>' . "\n";
}
// Keep the order of JS files consistent as some are preprocessed and others are not.
......@@ -3363,8 +3362,8 @@ function drupal_build_js_cache($files, $filename) {
$contents = '';
// Create the js/ within the files folder.
$jspath = file_create_path('js');
file_check_directory($jspath, FILE_CREATE_DIRECTORY);
$jspath = 'public://js';
file_prepare_directory($jspath, FILE_CREATE_DIRECTORY);
if (!file_exists($jspath . '/' . $filename)) {
// Build aggregate JS file.
......@@ -3386,7 +3385,7 @@ function drupal_build_js_cache($files, $filename) {
* Delete all cached JS files.
*/
function drupal_clear_js_cache() {
file_scan_directory(file_create_path('js'), '/.*/', array('callback' => 'file_unmanaged_delete'));
file_scan_directory('public://js', '/.*/', array('callback' => 'file_unmanaged_delete'));
variable_set('javascript_parsed', array());
}
......
This diff is collapsed.
......@@ -114,7 +114,7 @@ function __get($name) {
* A path to check against the jail.
*/
protected final function checkPath($path) {
if (realpath(substr($path, 0, strlen($this->jail))) !== $this->jail) {
if (drupal_realpath(substr($path, 0, strlen($this->jail))) !== $this->jail) {
throw new FileTransferException('@directory is outside of the @jail', NULL, array('@directory' => $path, '@jail' => $this->jail));
}
}
......
......@@ -19,7 +19,7 @@ static function factory($jail, $settings) {
}
function createDirectoryJailed($directory) {
if (!@mkdir($directory)) {
if (!@drupal_mkdir($directory)) {
$exception = new FileTransferException('Cannot create directory @directory.', NULL, array('@directory' => $directory));
throw $exception;
}
......
......@@ -2325,7 +2325,7 @@ function theme_image_button($element) {
(!empty($element['#value']) ? ('value="' . check_plain($element['#value']) . '" ') : '') .
'id="' . $element['#id'] . '" ' .
drupal_attributes($element['#attributes']) .
' src="' . base_path() . $element['#src'] . '" ' .
' src="' . file_create_url($element['#src']) . '" ' .
(!empty($element['#title']) ? 'alt="' . check_plain($element['#title']) . '" title="' . check_plain($element['#title']) . '" ' : '' ) .
"/>\n";
}
......
......@@ -216,9 +216,9 @@ function drupal_detect_database_types() {
// file for the driver explicitly.
require_once DRUPAL_ROOT . '/includes/database/database.inc';
foreach (file_scan_directory(DRUPAL_ROOT . '/includes/database', '/^[a-z]*$/i', array('recurse' => FALSE)) as $file) {
include_once "{$file->filepath}/install.inc";
include_once "{$file->filepath}/database.inc";
$drivers[$file->filename] = $file->filepath;
include_once "{$file->uri}/install.inc";
include_once "{$file->uri}/database.inc";
$drivers[$file->filename] = $file->uri;
}
foreach ($drivers as $driver => $file) {
......@@ -810,7 +810,7 @@ function drupal_install_mkdir($file, $mask, $message = TRUE) {
}
}
if (@mkdir($file, intval("0$mod", 8))) {
if (@drupal_mkdir($file, intval("0$mod", 8))) {
return TRUE;
}
else {
......@@ -934,7 +934,7 @@ function st($string, $args = array()) {
$filename = 'profiles/' . $install_state['parameters']['profile'] . '/translations/' . $install_state['parameters']['locale'] . '.po';
if (file_exists(DRUPAL_ROOT . '/' . $filename)) {
require_once DRUPAL_ROOT . '/includes/locale.inc';
$file = (object) array('filepath' => $filename);
$file = (object) array('uri' => $filename);
_locale_import_read_po('mem-store', $file);
$locale_strings = _locale_import_one_string('mem-report');
}
......@@ -986,7 +986,7 @@ function drupal_check_profile($profile) {
// Collect requirement testing results
$requirements = array();
foreach ($installs as $install) {
require_once DRUPAL_ROOT . '/' . $install->filepath;
require_once DRUPAL_ROOT . '/' . $install->uri;
$function = $install->name . '_requirements';
if (function_exists($function)) {
$requirements = array_merge($requirements, $function('install'));
......@@ -1026,7 +1026,7 @@ function drupal_check_module($module) {
// Include install file
$install = drupal_get_install_files(array($module));
if (isset($install[$module])) {
require_once DRUPAL_ROOT . '/' . $install[$module]->filepath;
require_once DRUPAL_ROOT . '/' . $install[$module]->uri;
// Check requirements
$requirements = module_invoke($module, 'requirements', 'install');
......
......@@ -1223,7 +1223,7 @@ function _locale_import_po($file, $langcode, $mode, $group = NULL) {
*/
function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') {
$fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return
$fd = fopen($file->uri, "rb"); // File will get closed by PHP on return
if (!$fd) {
_locale_import_message('The translation import failed, because the file %filename could not be read.', $file);
return FALSE;
......@@ -1439,7 +1439,7 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL
$header = _locale_import_parse_header($value['msgstr']);
// Get the plural formula and update in database.
if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filepath)) {
if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) {
list($nplurals, $plural) = $p;
db_update('languages')
->fields(array(
......@@ -2435,11 +2435,11 @@ function _locale_rebuild_js($langcode = NULL) {
// Construct the filepath where JS translation files are stored.
// There is (on purpose) no front end to edit that variable.
$dir = file_create_path(variable_get('locale_js_directory', 'languages'));
$dir = 'public://' . variable_get('locale_js_directory', 'languages');
// Delete old file, if we have no translations anymore, or a different file to be saved.
if (!empty($language->javascript) && (!$data || $language->javascript != $data_hash)) {
file_unmanaged_delete(file_create_path($dir . '/' . $language->language . '_' . $language->javascript . '.js'));
file_unmanaged_delete($dir . '/' . $language->language . '_' . $language->javascript . '.js');
$language->javascript = '';
$status = 'deleted';
}
......@@ -2447,7 +2447,7 @@ function _locale_rebuild_js($langcode = NULL) {
// Only create a new file if the content has changed.
if ($data && $language->javascript != $data_hash) {
// Ensure that the directory exists and is writable, if possible.
file_check_directory($dir, TRUE);
file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
// Save the file.
$dest = $dir . '/' . $language->language . '_' . $data_hash . '.js';
......@@ -2650,7 +2650,7 @@ function _locale_batch_build($files, $finished = NULL, $components = array()) {
$operations = array();
foreach ($files as $file) {
// We call _locale_batch_import for every batch operation.
$operations[] = array('_locale_batch_import', array($file->filepath));
$operations[] = array('_locale_batch_import', array($file->uri));
}
$batch = array(
'operations' => $operations,
......@@ -2682,7 +2682,7 @@ function _locale_batch_import($filepath, &$context) {
// The filename is either {langcode}.po or {prefix}.{langcode}.po, so
// we can extract the language code to use for the import from the end.
if (preg_match('!(/|\.)([^\./]+)\.po$!', $filepath, $langcode)) {
$file = (object) array('filename' => basename($filepath), 'filepath' => $filepath);
$file = (object) array('filename' => basename($filepath), 'uri' => $filepath);
_locale_import_read_po('db-store', $file, LOCALE_IMPORT_KEEP, $langcode[2]);
$context['results'][] = $filepath;
}
......
......@@ -503,7 +503,7 @@ function drupal_required_modules() {
$files = drupal_system_listing('/\.info$/', 'modules', 'name', 0);
$required = array();
foreach ($files as $name => $file) {
$info = drupal_parse_info_file($file->filepath);
$info = drupal_parse_info_file($file->uri);
if (!empty($info) && !empty($info['required']) && $info['required']) {
$required[] = $name;
}
......
......@@ -42,7 +42,7 @@ function _registry_rebuild() {
// Get the list of files we are going to parse.
$files = array();
foreach ($modules as &$module) {
$dir = dirname($module->filepath);
$dir = dirname($module->uri);
// Store the module directory for use in hook_registry_files_alter().
$module->dir = $dir;
......
......@@ -226,14 +226,14 @@ static function getMimeType($uri, $mapping = NULL) {
* Base implementation of chmod().
*/
function chmod($mode) {
return @chmod($this->realpath(), $mode);
return @chmod($this->getLocalPath(), $mode);
}
/**
* Base implementaiton of realpath().
* Base implementation of realpath().
*/
function realpath() {
return @realpath($this->getDirectoryPath() . '/' . file_uri_target($this->uri));
return $this->getLocalPath();
}
/**
......@@ -246,14 +246,24 @@ protected function getLocalPath($uri = NULL) {
if (!isset($uri)) {
$uri = $this->uri;
}
return $this->getDirectoryPath() . '/' . file_uri_target($uri);
$path = $this->getDirectoryPath() . '/' . file_uri_target($uri);
$realpath = realpath($path);
if (!$realpath) {
// This file does not yet exist.
$realpath = realpath(dirname($path)) . '/' . basename($path);
}
$directory = realpath($this->getDirectoryPath());
if (!$realpath || !$directory || strpos($realpath, $directory) !== 0) {
return FALSE;
}
return $realpath;
}
/**
* Support for fopen(), file_get_contents(), file_put_contents() etc.
*
* @param $uri
* A string containing the path to the file to open.
* A string containing the URI to the file to open.
* @param $mode
* The file mode ("r", "wb" etc.).
* @param $options
......@@ -428,7 +438,7 @@ public function rename($from_uri, $to_uri) {
* Support for mkdir().
*
* @param $uri
* A string containing the url to the directory to create.
* A string containing the URI to the directory to create.
* @param $mode
* Permission flags - see mkdir().
* @param $options
......@@ -440,11 +450,19 @@ public function rename($from_uri, $to_uri) {
public function mkdir($uri, $mode, $options) {
$this->uri = $uri;
$recursive = (bool)($options & STREAM_MKDIR_RECURSIVE);
if ($recursive) {
// $this->getLocalPath() fails if $uri has multiple levels of directories
// that do not yet exist.
$localpath = $this->getDirectoryPath() . '/' . file_uri_target($uri);
}
else {
$localpath = $this->getLocalPath($uri);
}
if ($options & STREAM_REPORT_ERRORS) {
return mkdir($this->getLocalPath(), $mode, $recursive);
return mkdir($localpath, $mode, $recursive);
}
else {
return @mkdir($this->getLocalPath(), $mode, $recursive);
return @mkdir($localpath, $mode, $recursive);
}
}
......@@ -452,7 +470,7 @@ public function mkdir($uri, $mode, $options) {
* Support for rmdir().
*
* @param $uri
* A string containing the url to the directory to delete.
* A string containing the URI to the directory to delete.
* @param $options
* A bit mask of STREAM_REPORT_ERRORS.
* @return
......@@ -473,7 +491,7 @@ public function rmdir($uri, $options) {
* Support for stat().
*
* @param $uri
* A string containing the url to get information about.
* A string containing the URI to get information about.
* @param $flags
* A bit mask of STREAM_URL_STAT_LINK and STREAM_URL_STAT_QUIET.
* @return
......@@ -495,7 +513,7 @@ public function url_stat($uri, $flags) {
* Support for opendir().
*
* @param $uri
* A string containing the url to the directory to open.
* A string containing the URI to the directory to open.
* @param $options
* Unknown (parameter is not documented in PHP Manual).
* @return
......@@ -554,7 +572,7 @@ class DrupalPublicStreamWrapper extends DrupalLocalStreamWrapper {
* Implements abstract public function getDirectoryPath()
*/
public function getDirectoryPath() {
return variable_get('file_public_path', 'sites/default/files');
return variable_get('file_public_path', conf_path() . '/files');
}
/**
......@@ -582,7 +600,7 @@ class DrupalPrivateStreamWrapper extends DrupalLocalStreamWrapper {
* Implements abstract public function getDirectoryPath()
*/
public function getDirectoryPath() {
return variable_get('file_private_path', 'sites/default/files-private');
return variable_get('file_private_path', conf_path() . '/private/files');
}
/**
......@@ -609,13 +627,14 @@ class DrupalTemporaryStreamWrapper extends DrupalLocalStreamWrapper {
* Implements abstract public function getDirectoryPath()
*/
public function getDirectoryPath() {
return variable_get('file_temporary_path', '/tmp');
return variable_get('file_temporary_path', conf_path() . '/private/temp');
}
/**
* Overrides getExternalUrl().
*/
public function getExternalUrl() {
return '';
$path = str_replace('\\', '/', file_uri_target($this->uri));
return url('system/temporary/' . $path, array('absolute' => TRUE));
}
}
......@@ -967,7 +967,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
$files = drupal_system_listing($regex, $path, 'name', 0);
foreach ($files as $template => $file) {
// Ignore sub-theme templates for the current theme.
if (strpos($file->filepath, str_replace($subtheme_paths, '', $file->filepath)) !== 0) {
if (strpos($file->uri, str_replace($subtheme_paths, '', $file->uri)) !== 0) {
continue;
}
// Chop off the remaining extensions if there are any. $template already
......@@ -982,7 +982,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
if (isset($cache[$hook])) {
$templates[$hook] = array(
'template' => $template,
'path' => dirname($file->filepath),
'path' => dirname($file->uri),
);
}
// Ensure that the pattern is maintained from base themes to its sub-themes.
......@@ -1008,7 +1008,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
// Put the underscores back in for the hook name and register this pattern.
$templates[strtr($file, '-', '_')] = array(
'template' => $file,
'path' => dirname($files[$match]->filepath),
'path' => dirname($files[$match]->uri),
'arguments' => $info['arguments'],
);
}
......@@ -1099,24 +1099,24 @@ function theme_get_setting($setting_name, $refresh = FALSE) {
if ($settings['toggle_logo']) {
if ($settings['default_logo']) {
$settings['logo'] = base_path() . dirname($theme_object->filename) . '/logo.png';
$settings['logo'] = file_create_url(dirname($theme_object->filename) . '/logo.png');
}
elseif ($settings['logo_path']) {
$settings['logo'] = base_path() . $settings['logo_path'];
$settings['logo'] = file_create_url($settings['logo_path']);
}
}
if ($settings['toggle_favicon']) {
if ($settings['default_favicon']) {
if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) {
$settings['favicon'] = base_path() . $favicon;
$settings['favicon'] = file_create_url($favicon);
}
else {
$settings['favicon'] = base_path() . 'misc/favicon.ico';
$settings['favicon'] = file_create_url('misc/favicon.ico');
}
}
elseif ($settings['favicon_path']) {
$settings['favicon'] = base_path() . $settings['favicon_path'];
$settings['favicon'] = file_create_url($settings['favicon_path']);
}
else {
$settings['toggle_favicon'] = FALSE;
......@@ -1340,7 +1340,7 @@ function theme_links($links, $attributes = array('class' => 'links')) {
function theme_image($path, $alt = '', $title = '', $attributes = array(), $getsize = TRUE) {
if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) {
$attributes = drupal_attributes($attributes);
$url = (url($path) == $path) ? $path : (base_path() . $path);
$url = file_create_url($path);
return '<img src="' . check_url($url) . '" alt="' . check_plain($alt) . '" title="' . check_plain($title) . '" ' . (isset($image_attributes) ? $image_attributes : '') . $attributes . ' />';
}
}
......
......@@ -1039,6 +1039,8 @@ function _install_select_profile($profiles) {
// Don't need to choose profile if only one available.
if (sizeof($profiles) == 1) {
$profile = array_pop($profiles);
// TODO: is this right?
require_once $profile->uri;
return $profile->name;
}
else {
......@@ -1063,7 +1065,8 @@ function install_select_profile_form(&$form_state, $profile_files) {
$names = array();
foreach ($profile_files as $profile) {
include_once DRUPAL_ROOT . '/' . $profile->filepath;
// TODO: is this right?
include_once DRUPAL_ROOT . '/' . $profile->uri;
$details = install_profile_info($profile->name);
$profiles[$profile->name] = $details;
......
......@@ -297,7 +297,7 @@ function aggregator_form_opml_validate($form, &$form_state) {
function aggregator_form_opml_submit($form, &$form_state) {
$data = '';
if ($file = file_save_upload('upload')) {
$data = file_get_contents($file->filepath);
$data = file_get_contents($file->uri);
}
else {
$response = drupal_http_request($form_state['values']['remote']);
......
......@@ -200,7 +200,7 @@ class AggregatorTestCase extends DrupalWebTestCase {
</opml>
EOF;
$path = file_directory_path() . '/valid-opml.xml';
$path = 'public://valid-opml.xml';
return file_unmanaged_save_data($opml, $path);
}
......@@ -217,7 +217,7 @@ EOF;
</opml>
EOF;
$path = file_directory_path() . '/invalid-opml.xml';
$path = 'public://invalid-opml.xml';
return file_unmanaged_save_data($opml, $path);
}
......@@ -239,7 +239,7 @@ EOF;
</opml>
EOF;
$path = file_directory_path() . '/empty-opml.xml';
$path = 'public://empty-opml.xml';
return file_unmanaged_save_data($opml, $path);
}
......
......@@ -460,19 +460,23 @@ function blogapi_metaweblog_new_media_object($blogid, $username, $password, $fil
$filename .= '.' . $final_extension;
}
else {
$filename = $name;
}
$uri = file_build_uri($filename);
$data = $file['bits'];
if (!$data) {
return blogapi_error(t('No file sent.'));
}
if (!$file = file_unmanaged_save_data($data, $filename)) {
if (!$file = file_unmanaged_save_data($data, $uri)) {
return blogapi_error(t('Error storing file.'));
}
$row = new stdClass();
$row->uid = $user->uid;
$row->filepath = $file;
$row->uri = $file;
$row->filesize = $filesize;
drupal_write_record('blogapi_files', $row);
......
......@@ -70,7 +70,7 @@ class BlogAPITestCase extends DrupalWebTestCase {
// Upload file.
$file = current($this->drupalGetTestFiles('text'));
$file_contents = file_get_contents($file->filepath);
$file_contents = file_get_contents($file->uri);
$file = array();
$file['name'] = $this->randomName() . '.txt';
$file['type'] = 'text';
......
......@@ -7,7 +7,7 @@
function color_help($path, $arg) {
switch ($path) {
case 'admin/help#color':
$output = '<p>' . t('The color module allows a site administrator to quickly and easily change the color scheme of certain themes. Although not all themes support color module, both Garland (the default theme) and Minnelli were designed to take advantage of its features. By using color module with a compatible theme, you can easily change the color of links, backgrounds, text, and other theme elements. Color module requires that your <a href="@url">file download method</a> be set to public.', array('@url' => url('admin/settings/file-system'))) . '</p>';
$output = '<p>' . t('The color module allows a site administrator to quickly and easily change the color scheme of certain themes. Although not all themes support color module, both Garland (the default theme) and Minnelli were designed to take advantage of its features. By using color module with a compatible theme, you can easily change the color of links, backgrounds, text, and other theme elements.', array('@url' => url('admin/settings/file-system'))) . '</p>';
$output .= '<p>' . t("It is important to remember that color module saves a modified copy of the theme's specified stylesheets in the files directory. This means that if you make any manual changes to your theme's stylesheet, you must save your color settings again, even if they haven't changed. This causes the color module generated version of the stylesheets in the files directory to be recreated using the new version of the original file.") . '</p>';
$output .= '<p>' . t('To change the color settings for a compatible theme, select the "configure" link for the theme on the <a href="@themes">themes administration page</a>.', array('@themes' => url('admin/appearance'))) . '</p>';
$output .= '<p>' . t('For more information, see the online handbook entry for <a href="@color">Color module</a>.', array('@color' => 'http://drupal.org/handbook/modules/color/')) . '</p>';
......@@ -32,22 +32,15 @@ function color_theme() {
*/
function color_form_system_theme_settings_alter(&$form, &$form_state) {
if (color_get_info(arg(4)) && function_exists('gd_info')) {
if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) != FILE_DOWNLOADS_PUBLIC) {
// Disables the color changer when the private download method is used.
// TODO: This should be solved in a different way. See issue #181003.
drupal_set_message(t('The color picker only works if the <a href="@url">download method</a> is set to public.', array('@url' => url('admin/settings/file-system'))), 'warning');
}
else {
$form['color'] = array(
'#type' => 'fieldset',
'#title' => t('Color scheme'),
'#weight' => -1,
'#attributes' => array('id' => 'color_scheme_form'),
'#theme' => 'color_scheme_form',
);
$form['color'] += color_scheme_form($form_state, arg(4));
$form['#submit'][] = 'color_scheme_form_submit';
}
$form['color'] = array(
'#type' => 'fieldset',
'#title' => t('Color scheme'),
'#weight' => -1,
'#attributes' => array('id' => 'color_scheme_form'),
'#theme' => 'color_scheme_form',
);
$form['color'] += color_scheme_form($form_state, arg(4));
$form['#submit'][] = 'color_scheme_form_submit';
}
}
......@@ -300,7 +293,7 @@ function color_scheme_form_submit($form, &$form_state) {
$paths['color'] = file_directory_path() . '/color';
$paths['target'] = $paths['color'] . '/' . $id;
foreach ($paths as $path) {
file_check_directory($path, FILE_CREATE_DIRECTORY);
file_prepare_directory($path, FILE_CREATE_DIRECTORY);
}
$paths['target'] = $paths['target'] . '/';
$paths['id'] = $id;
......
......@@ -679,11 +679,10 @@ function theme_image_style_preview($style) {
// Set up preview file information.
$preview_file = image_style_path($style['name'], $original_path);
$preview_path = file_create_path($preview_file);
if (!file_exists($preview_path) && image_style_create_derivative($style, $original_path, $preview_file)) {
$preview_path = file_create_path($preview_file);
if (!file_exists($preview_file)) {
image_style_create_derivative($style, $original_path, $preview_file);
}
$preview_image = image_get_info($preview_path);
$preview_image = image_get_info($preview_file);
if ($preview_image['width'] > $preview_image['height']) {
$preview_width = min($preview_image['width'], $sample_width);
$preview_height = round($preview_width / $preview_image['width'] * $preview_image['height']);
......
......@@ -14,7 +14,7 @@ function image_install() {
// Create the styles directory and ensure it's writable.
$path = file_directory_path() . '/styles';
file_check_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
/**
......
......@@ -200,7 +200,7 @@ function image_file_download($filepath) {
$original_path = implode('/', $args);
// Check that the file exists and is an image.
if ($info = image_get_info(file_create_path($filepath))) {
if ($info = image_get_info($filepath)) {
// Check the permissions of the original to grant access to this image.
$headers = module_invoke_all('file_download', $original_path);
if (!in_array(-1, $headers)) {
......@@ -219,7 +219,7 @@ function image_file_download($filepath) {
*/
function image_file_move($file, $source) {
// Delete any image derivatives at the original image path.
image_path_flush($file->filepath);
image_path_flush($file->uri);
}
/**
......@@ -227,7 +227,7 @@ function image_file_move($file, $source) {
*/
function image_file_delete($file) {
// Delete any image derivatives of this image.
image_path_flush($file->filepath);
image_path_flush($file->uri);
}
/**
......@@ -237,10 +237,10 @@ function image_file_delete($file) {
* The Drupal file path to the original image.
*/
function image_path_flush($path) {
$path = file_directory_strip($path);
$styles = image_styles();
foreach ($styles as $style) {
if ($path = file_create_path('styles/' . $style['name'] . '/' . $path)) {
$path = image_style_path($style['name'], $path);
if (file_exists($path)) {
file_unmanaged_delete($path);
}
}
......@@ -426,9 +426,10 @@ function image_style_generate() {
$args = func_get_args();
$style = array_shift($args);
$style_name = $style['name'];
$scheme = array_shift($args);
$path = implode('/', $args);
$source = file_create_path($path);