updated core to 7.73

This commit is contained in:
2020-09-24 17:04:08 +02:00
parent 084d28842a
commit 7d87153100
524 changed files with 25194 additions and 7745 deletions
+69 -50
View File
@@ -32,10 +32,9 @@ function image_style_list() {
* An image style array.
* @ingroup forms
* @see image_style_form_submit()
* @see image_style_name_validate()
*/
function image_style_form($form, &$form_state, $style) {
$title = t('Edit %name style', array('%name' => $style['name']));
$title = t('Edit %name style', array('%name' => $style['label']));
drupal_set_title($title, PASS_THROUGH);
// Adjust this form for styles that must be overridden to edit.
@@ -56,27 +55,31 @@ function image_style_form($form, &$form_state, $style) {
'#markup' => theme('image_style_preview', array('style' => $style)),
);
// Show the Image Style label.
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Image style name'),
'#default_value' => $style['label'],
'#disabled' => !$editable,
'#required' => TRUE,
);
// Allow the name of the style to be changed, unless this style is
// provided by a module's hook_default_image_styles().
if ($style['storage'] & IMAGE_STORAGE_MODULE) {
$form['name'] = array(
'#type' => 'item',
'#title' => t('Image style name'),
'#markup' => $style['name'],
'#description' => t('This image style is being provided by %module module and may not be renamed.', array('%module' => $style['module'])),
);
}
else {
$form['name'] = array(
'#type' => 'textfield',
'#size' => '64',
'#title' => t('Image style name'),
'#default_value' => $style['name'],
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#element_validate' => array('image_style_name_validate'),
'#required' => TRUE,
);
}
$form['name'] = array(
'#type' => 'machine_name',
'#size' => '64',
'#default_value' => $style['name'],
'#disabled' => !$editable,
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#required' => TRUE,
'#machine_name' => array(
'exists' => 'image_style_load',
'source' => array('label'),
'replace_pattern' => '[^0-9a-z_\-]',
'error' => t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'),
),
);
// Build the list of existing image effects for this image style.
$form['effects'] = array(
@@ -199,7 +202,7 @@ function image_style_form_add_submit($form, &$form_state) {
* Submit handler for overriding a module-defined style.
*/
function image_style_form_override_submit($form, &$form_state) {
drupal_set_message(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $form_state['image_style']['name'])));
drupal_set_message(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $form_state['image_style']['label'])));
image_default_style_save($form_state['image_style']);
}
@@ -207,11 +210,10 @@ function image_style_form_override_submit($form, &$form_state) {
* Submit handler for saving an image style.
*/
function image_style_form_submit($form, &$form_state) {
// Update the image style name if it has changed.
// Update the image style.
$style = $form_state['image_style'];
if (isset($form_state['values']['name']) && $style['name'] != $form_state['values']['name']) {
$style['name'] = $form_state['values']['name'];
}
$style['name'] = $form_state['values']['name'];
$style['label'] = $form_state['values']['label'];
// Update image effect weights.
if (!empty($form_state['values']['effects'])) {
@@ -236,18 +238,26 @@ function image_style_form_submit($form, &$form_state) {
*
* @ingroup forms
* @see image_style_add_form_submit()
* @see image_style_name_validate()
*/
function image_style_add_form($form, &$form_state) {
$form['name'] = array(
$form['label'] = array(
'#type' => 'textfield',
'#size' => '64',
'#title' => t('Style name'),
'#default_value' => '',
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#element_validate' => array('image_style_name_validate'),
'#required' => TRUE,
);
$form['name'] = array(
'#type' => 'machine_name',
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#size' => '64',
'#required' => TRUE,
'#machine_name' => array(
'exists' => 'image_style_load',
'source' => array('label'),
'replace_pattern' => '[^0-9a-z_\-]',
'error' => t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'),
),
);
$form['submit'] = array(
'#type' => 'submit',
@@ -261,14 +271,22 @@ function image_style_add_form($form, &$form_state) {
* Submit handler for adding a new image style.
*/
function image_style_add_form_submit($form, &$form_state) {
$style = array('name' => $form_state['values']['name']);
$style = array(
'name' => $form_state['values']['name'],
'label' => $form_state['values']['label'],
);
$style = image_style_save($style);
drupal_set_message(t('Style %name was created.', array('%name' => $style['name'])));
drupal_set_message(t('Style %name was created.', array('%name' => $style['label'])));
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];
}
/**
* Element validate function to ensure unique, URL safe style names.
*
* This function is no longer used in Drupal core since image style names are
* now validated using #machine_name functionality. It is kept for backwards
* compatibility (since non-core modules may be using it) and will be removed
* in Drupal 8.
*/
function image_style_name_validate($element, $form_state) {
// Check for duplicates.
@@ -295,7 +313,7 @@ function image_style_name_validate($element, $form_state) {
function image_style_delete_form($form, &$form_state, $style) {
$form_state['image_style'] = $style;
$replacement_styles = array_diff_key(image_style_options(), array($style['name'] => ''));
$replacement_styles = array_diff_key(image_style_options(TRUE, PASS_THROUGH), array($style['name'] => ''));
$form['replacement'] = array(
'#title' => t('Replacement style'),
'#type' => 'select',
@@ -305,7 +323,7 @@ function image_style_delete_form($form, &$form_state, $style) {
return confirm_form(
$form,
t('Optionally select a style before deleting %style', array('%style' => $style['name'])),
t('Optionally select a style before deleting %style', array('%style' => $style['label'])),
'admin/config/media/image-styles',
t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted.'),
t('Delete'), t('Cancel')
@@ -319,7 +337,7 @@ function image_style_delete_form_submit($form, &$form_state) {
$style = $form_state['image_style'];
image_style_delete($style, $form_state['values']['replacement']);
drupal_set_message(t('Style %name was deleted.', array('%name' => $style['name'])));
drupal_set_message(t('Style %name was deleted.', array('%name' => $style['label'])));
$form_state['redirect'] = 'admin/config/media/image-styles';
}
@@ -331,7 +349,7 @@ function image_style_revert_form($form, &$form_state, $style) {
return confirm_form(
$form,
t('Revert the %style style?', array('%style' => $style['name'])),
t('Revert the %style style?', array('%style' => $style['label'])),
'admin/config/media/image-styles',
t('Reverting this style will delete the customized settings and restore the defaults provided by the @module module.', array('@module' => $style['module'])),
t('Revert'), t('Cancel')
@@ -342,7 +360,7 @@ function image_style_revert_form($form, &$form_state, $style) {
* Submit handler to convert an overridden style to its default.
*/
function image_style_revert_form_submit($form, &$form_state) {
drupal_set_message(t('The %style style has been reverted to its defaults.', array('%style' => $form_state['image_style']['name'])));
drupal_set_message(t('The %style style has been reverted to its defaults.', array('%style' => $form_state['image_style']['label'])));
image_default_style_revert($form_state['image_style']);
$form_state['redirect'] = 'admin/config/media/image-styles';
}
@@ -439,7 +457,7 @@ function image_effect_delete_form($form, &$form_state, $style, $effect) {
$form_state['image_style'] = $style;
$form_state['image_effect'] = $effect;
$question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style['name'], '@effect' => $effect['label']));
$question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style['label'], '@effect' => $effect['label']));
return confirm_form($form, $question, 'admin/config/media/image-styles/edit/' . $style['name'], '', t('Delete'));
}
@@ -574,15 +592,15 @@ function image_crop_form($data) {
'#type' => 'radios',
'#title' => t('Anchor'),
'#options' => array(
'left-top' => t('Top') . ' ' . t('Left'),
'center-top' => t('Top') . ' ' . t('Center'),
'right-top' => t('Top') . ' ' . t('Right'),
'left-center' => t('Center') . ' ' . t('Left'),
'left-top' => t('Top left'),
'center-top' => t('Top center'),
'right-top' => t('Top right'),
'left-center' => t('Center left'),
'center-center' => t('Center'),
'right-center' => t('Center') . ' ' . t('Right'),
'left-bottom' => t('Bottom') . ' ' . t('Left'),
'center-bottom' => t('Bottom') . ' ' . t('Center'),
'right-bottom' => t('Bottom') . ' ' . t('Right'),
'right-center' => t('Center right'),
'left-bottom' => t('Bottom left'),
'center-bottom' => t('Bottom center'),
'right-bottom' => t('Bottom right'),
),
'#theme' => 'image_anchor',
'#default_value' => $data['anchor'],
@@ -650,7 +668,7 @@ function theme_image_style_list($variables) {
$rows = array();
foreach ($styles as $style) {
$row = array();
$row[] = l($style['name'], 'admin/config/media/image-styles/edit/' . $style['name']);
$row[] = l($style['label'], 'admin/config/media/image-styles/edit/' . $style['name']);
$link_attributes = array(
'attributes' => array(
'class' => array('image-style-link'),
@@ -718,7 +736,8 @@ function theme_image_style_effects($variables) {
if (!isset($form[$key]['#access']) || $form[$key]['#access']) {
$rows[] = array(
'data' => $row,
'class' => !empty($form[$key]['weight']['#access']) || $key == 'new' ? array('draggable') : array(),
// Use a strict (===) comparison since $key can be 0.
'class' => !empty($form[$key]['weight']['#access']) || $key === 'new' ? array('draggable') : array(),
);
}
}
@@ -805,7 +824,7 @@ function theme_image_style_preview($variables) {
// Build the preview of the image style.
$preview_url = file_create_url($preview_file) . '?cache_bypass=' . REQUEST_TIME;
$output .= '<div class="preview-image-wrapper">';
$output .= check_plain($style['name']) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')';
$output .= check_plain($style['label']) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')';
$output .= '<div class="preview-image modified-image" style="' . $preview_attributes['style'] . '">';
$output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . theme('image', array('path' => $preview_url, 'alt' => t('Sample modified image'), 'title' => '', 'attributes' => $preview_attributes)) . '</a>';
$output .= '<div class="height" style="height: ' . $preview_height . 'px"><span>' . $preview_image['height'] . 'px</span></div>';
+1
View File
@@ -177,6 +177,7 @@ function hook_image_default_styles() {
$styles = array();
$styles['mymodule_preview'] = array(
'label' => 'My module preview',
'effects' => array(
array(
'name' => 'image_scale',
+4 -4
View File
@@ -311,7 +311,7 @@ function image_field_widget_settings_form($field, $instance) {
$form['preview_image_style'] = array(
'#title' => t('Preview image style'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#options' => image_style_options(FALSE, PASS_THROUGH),
'#empty_option' => '<' . t('no preview') . '>',
'#default_value' => $settings['preview_image_style'],
'#description' => t('The preview image will be shown while editing the content.'),
@@ -351,7 +351,7 @@ function image_field_widget_form(&$form, &$form_state, $field, $instance, $langc
if ($field['cardinality'] == 1) {
// If there's only one field, return it as delta 0.
if (empty($elements[0]['#default_value']['fid'])) {
$elements[0]['#description'] = theme('file_upload_help', array('description' => $instance['description'], 'upload_validators' => $elements[0]['#upload_validators']));
$elements[0]['#description'] = theme('file_upload_help', array('description' => field_filter_xss($instance['description']), 'upload_validators' => $elements[0]['#upload_validators']));
}
}
else {
@@ -495,7 +495,7 @@ function image_field_formatter_settings_form($field, $instance, $view_mode, $for
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$image_styles = image_style_options(FALSE);
$image_styles = image_style_options(FALSE, PASS_THROUGH);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
@@ -528,7 +528,7 @@ function image_field_formatter_settings_summary($field, $instance, $view_mode) {
$summary = array();
$image_styles = image_style_options(FALSE);
$image_styles = image_style_options(FALSE, PASS_THROUGH);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
// Styles could be lost because of enabled/disabled modules that defines
+3 -4
View File
@@ -7,8 +7,7 @@ dependencies[] = file
files[] = image.test
configure = admin/config/media/image-styles
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
+32 -1
View File
@@ -41,11 +41,18 @@ function image_schema() {
'not null' => TRUE,
),
'name' => array(
'description' => 'The style name.',
'description' => 'The style machine name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'label' => array(
'description' => 'The style administrative name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('isid'),
'unique keys' => array(
@@ -448,6 +455,30 @@ function image_update_7004() {
}
}
/**
* Add a column to the 'image_style' table to store administrative labels.
*/
function image_update_7005() {
$field = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The style administrative name.',
);
db_add_field('image_styles', 'label', $field);
// Do a direct query here, rather than calling image_styles(),
// in case Image module is disabled.
$styles = db_query('SELECT name FROM {image_styles}')->fetchCol();
foreach ($styles as $style) {
db_update('image_styles')
->fields(array('label' => $style))
->condition('name', $style)
->execute();
}
}
/**
* @} End of "addtogroup updates-7.x-extra".
*/
+61 -16
View File
@@ -64,7 +64,7 @@ function image_help($path, $arg) {
$effect = image_effect_definition_load($arg[7]);
return isset($effect['help']) ? ('<p>' . $effect['help'] . '</p>') : NULL;
case 'admin/config/media/image-styles/edit/%/effects/%':
$effect = ($arg[5] == 'add') ? image_effect_definition_load($arg[6]) : image_effect_load($arg[6], $arg[4]);
$effect = ($arg[5] == 'add') ? image_effect_definition_load($arg[6]) : image_effect_load($arg[7], $arg[5]);
return isset($effect['help']) ? ('<p>' . $effect['help'] . '</p>') : NULL;
}
}
@@ -347,6 +347,7 @@ function image_image_default_styles() {
$styles = array();
$styles['thumbnail'] = array(
'label' => 'Thumbnail (100x100)',
'effects' => array(
array(
'name' => 'image_scale',
@@ -357,6 +358,7 @@ function image_image_default_styles() {
);
$styles['medium'] = array(
'label' => 'Medium (220x220)',
'effects' => array(
array(
'name' => 'image_scale',
@@ -367,6 +369,7 @@ function image_image_default_styles() {
);
$styles['large'] = array(
'label' => 'Large (480x480)',
'effects' => array(
array(
'name' => 'image_scale',
@@ -575,6 +578,7 @@ function image_styles() {
$module_styles = module_invoke($module, 'image_default_styles');
foreach ($module_styles as $style_name => $style) {
$style['name'] = $style_name;
$style['label'] = empty($style['label']) ? $style_name : $style['label'];
$style['module'] = $module;
$style['storage'] = IMAGE_STORAGE_DEFAULT;
foreach ($style['effects'] as $key => $effect) {
@@ -689,6 +693,10 @@ function image_style_save($style) {
}
}
else {
// Add a default label when not given.
if (empty($style['label'])) {
$style['label'] = $style['name'];
}
drupal_write_record('image_styles', $style);
$style['is_new'] = TRUE;
}
@@ -758,20 +766,28 @@ function image_style_effects($style) {
*
* @param $include_empty
* If TRUE a <none> option will be inserted in the options array.
* @param $output
* Optional flag determining how the options will be sanitized on output.
* Leave this at the default (CHECK_PLAIN) if you are using the output of
* this function directly in an HTML context, such as for checkbox or radio
* button labels, and do not plan to sanitize it on your own. If using the
* output of this function as select list options (its primary use case), you
* should instead set this flag to PASS_THROUGH to avoid double-escaping of
* the output (the form API sanitizes select list options by default).
*
* @return
* Array of image styles both key and value are set to style name.
* Array of image styles with the machine name as key and the label as value.
*/
function image_style_options($include_empty = TRUE) {
function image_style_options($include_empty = TRUE, $output = CHECK_PLAIN) {
$styles = image_styles();
$options = array();
if ($include_empty && !empty($styles)) {
$options[''] = t('<none>');
}
// Use the array concatenation operator '+' here instead of array_merge(),
// because the latter loses the datatype of the array keys, turning
// associative string keys into numeric ones without warning.
$options = $options + drupal_map_assoc(array_keys($styles));
foreach ($styles as $name => $style) {
$options[$name] = ($output == PASS_THROUGH) ? $style['label'] : check_plain($style['label']);
}
if (empty($options)) {
$options[''] = t('No defined styles');
}
@@ -785,6 +801,8 @@ function image_style_options($include_empty = TRUE) {
*
* @param $style
* The image style
* @param $scheme
* The file scheme, for example 'public' for public files.
*/
function image_style_deliver($style, $scheme) {
$args = func_get_args();
@@ -817,9 +835,9 @@ function image_style_deliver($style, $scheme) {
file_download($scheme, file_uri_target($derivative_uri));
}
else {
$headers = module_invoke_all('file_download', $image_uri);
if (in_array(-1, $headers) || empty($headers)) {
return drupal_access_denied();
$headers = file_download_headers($image_uri);
if (empty($headers)) {
return MENU_ACCESS_DENIED;
}
if (count($headers)) {
foreach ($headers as $name => $value) {
@@ -829,6 +847,12 @@ function image_style_deliver($style, $scheme) {
}
}
// Confirm that the original source image exists before trying to process it.
if (!is_file($image_uri)) {
watchdog('image', 'Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.', array('%source_image_path' => $image_uri, '%derivative_path' => $derivative_uri));
return MENU_NOT_FOUND;
}
// Don't start generating the image if the derivative already exists or if
// generation is in progress in another thread.
$lock_name = 'image_style_deliver:' . $style['name'] . ':' . drupal_hash_base64($image_uri);
@@ -838,6 +862,7 @@ function image_style_deliver($style, $scheme) {
// Tell client to retry again in 3 seconds. Currently no browsers are known
// to support Retry-After.
drupal_add_http_header('Status', '503 Service Unavailable');
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
drupal_add_http_header('Retry-After', 3);
print t('Image generation in progress. Try again shortly.');
drupal_exit();
@@ -859,6 +884,7 @@ function image_style_deliver($style, $scheme) {
else {
watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri));
drupal_add_http_header('Status', '500 Internal Server Error');
drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
print t('Error generating image.');
drupal_exit();
}
@@ -953,9 +979,12 @@ function image_style_transform_dimensions($style_name, array &$dimensions) {
* An image style array.
*/
function image_style_flush($style) {
$style_directory = drupal_realpath(file_default_scheme() . '://styles/' . $style['name']);
if (is_dir($style_directory)) {
file_unmanaged_delete_recursive($style_directory);
// Delete the style directory in each registered wrapper.
$wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE);
foreach ($wrappers as $wrapper => $wrapper_data) {
if (file_exists($directory = $wrapper . '://styles/' . $style['name'])) {
file_unmanaged_delete_recursive($directory);
}
}
// Let other modules update as necessary on flush.
@@ -993,10 +1022,22 @@ function image_style_flush($style) {
*/
function image_style_url($style_name, $path) {
$uri = image_style_path($style_name, $path);
// The passed-in $path variable can be either a relative path or a full URI.
$original_uri = file_uri_scheme($path) ? file_stream_wrapper_uri_normalize($path) : file_build_uri($path);
// The token query is added even if the 'image_allow_insecure_derivatives'
// variable is TRUE, so that the emitted links remain valid if it is changed
// back to the default FALSE.
$token_query = array(IMAGE_DERIVATIVE_TOKEN => image_style_path_token($style_name, file_stream_wrapper_uri_normalize($path)));
// However, sites which need to prevent the token query from being emitted at
// all can additionally set the 'image_suppress_itok_output' variable to TRUE
// to achieve that (if both are set, the security token will neither be
// emitted in the image derivative URL nor checked for in
// image_style_deliver()).
$token_query = array();
if (!variable_get('image_suppress_itok_output', FALSE)) {
$token_query = array(IMAGE_DERIVATIVE_TOKEN => image_style_path_token($style_name, $original_uri));
}
// If not using clean URLs, the image derivative callback is only available
// with the query string. If the file does not exist, use url() to ensure
@@ -1008,8 +1049,12 @@ function image_style_url($style_name, $path) {
}
$file_url = file_create_url($uri);
// Append the query string with the token.
return $file_url . (strpos($file_url, '?') !== FALSE ? '&' : '?') . drupal_http_build_query($token_query);
// Append the query string with the token, if necessary.
if ($token_query) {
$file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . drupal_http_build_query($token_query);
}
return $file_url;
}
/**
+386 -155
View File
File diff suppressed because it is too large Load Diff
+3 -4
View File
@@ -6,8 +6,7 @@ core = 7.x
files[] = image_module_test.module
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by Drupal.org packaging script on 2020-09-16
version = "7.73"
project = "drupal"
datestamp = "1365027012"
datestamp = "1600272641"
@@ -9,6 +9,9 @@ function image_module_test_file_download($uri) {
if (variable_get('image_module_test_file_download', FALSE) == $uri) {
return array('X-Image-Owned-By' => 'image_module_test');
}
if (variable_get('image_module_test_invalid_headers', FALSE) == $uri) {
return array('Content-Type' => 'image/png');
}
}
/**