Commit 3201287b authored by David_Rothstein's avatar David_Rothstein

Issue #606598 by andypost, BarisW, stBorchert, David_Rothstein, sun,...

Issue #606598 by andypost, BarisW, stBorchert, David_Rothstein, sun, aspilicious, joachim, danielbeeke2, Sutharsan: Added human readable labels to image styles.
parent b0338a93
Drupal 7.23, xxxx-xx-xx (development version)
-----------------------
- Added human-readable labels to image styles, in addition to the existing
machine-readable name (API change).
- Moved the drupal_get_hash_salt() function to bootstrap.inc and used it in
additional places in the code, for added security in the case where there is
no hash salt in settings.php.
......
......@@ -218,12 +218,16 @@
define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
/**
* Flag for drupal_set_title(); text is not sanitized, so run check_plain().
* Flag used to indicate that text is not sanitized, so run check_plain().
*
* @see drupal_set_title()
*/
define('CHECK_PLAIN', 0);
/**
* Flag for drupal_set_title(); text has already been sanitized.
* Flag used to indicate that text has already been sanitized.
*
* @see drupal_set_title()
*/
define('PASS_THROUGH', -1);
......
This diff is collapsed.
......@@ -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',
......
......@@ -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.'),
......@@ -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
......
......@@ -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".
*/
......
......@@ -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');
}
......
This diff is collapsed.
......@@ -406,7 +406,7 @@ function user_admin_settings() {
$form['personalization']['pictures']['settings']['user_picture_style'] = array(
'#type' => 'select',
'#title' => t('Picture display style'),
'#options' => image_style_options(TRUE),
'#options' => image_style_options(TRUE, PASS_THROUGH),
'#default_value' => variable_get('user_picture_style', ''),
'#description' => t('The style selected will be used on display, while the original image is retained. Styles may be configured in the <a href="!url">Image styles</a> administration area.', array('!url' => url('admin/config/media/image-styles'))),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment