mirror of
https://github.com/tag1consulting/d7_to_d10_migration.git
synced 2025-05-28 08:05:13 +00:00
Initial commit
This commit is contained in:
commit
c5e731d8ae
2773 changed files with 600767 additions and 0 deletions
11
drupal7/web/modules/image/image-rtl.css
Normal file
11
drupal7/web/modules/image/image-rtl.css
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
/**
|
||||
* Image upload widget.
|
||||
*/
|
||||
div.image-preview {
|
||||
float: right;
|
||||
padding: 0 0 10px 10px;
|
||||
}
|
||||
div.image-widget-data {
|
||||
float: right;
|
||||
}
|
60
drupal7/web/modules/image/image.admin.css
Normal file
60
drupal7/web/modules/image/image.admin.css
Normal file
|
@ -0,0 +1,60 @@
|
|||
|
||||
/**
|
||||
* Image style configuration pages.
|
||||
*/
|
||||
div.image-style-new,
|
||||
div.image-style-new div {
|
||||
display: inline;
|
||||
}
|
||||
div.image-style-preview div.preview-image-wrapper {
|
||||
float: left;
|
||||
padding-bottom: 2em;
|
||||
text-align: center;
|
||||
top: 50%;
|
||||
width: 48%;
|
||||
}
|
||||
div.image-style-preview div.preview-image {
|
||||
margin: auto;
|
||||
position: relative;
|
||||
}
|
||||
div.image-style-preview div.preview-image div.width {
|
||||
border: 1px solid #666;
|
||||
border-top: none;
|
||||
height: 2px;
|
||||
left: -1px;
|
||||
bottom: -6px;
|
||||
position: absolute;
|
||||
}
|
||||
div.image-style-preview div.preview-image div.width span {
|
||||
position: relative;
|
||||
top: 4px;
|
||||
}
|
||||
div.image-style-preview div.preview-image div.height {
|
||||
border: 1px solid #666;
|
||||
border-left: none;
|
||||
position: absolute;
|
||||
right: -6px;
|
||||
top: -1px;
|
||||
width: 2px;
|
||||
}
|
||||
div.image-style-preview div.preview-image div.height span {
|
||||
height: 2em;
|
||||
left: 10px;
|
||||
margin-top: -1em;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image anchor element.
|
||||
*/
|
||||
table.image-anchor {
|
||||
width: auto;
|
||||
}
|
||||
table.image-anchor tr.even,
|
||||
table.image-anchor tr.odd {
|
||||
background: none;
|
||||
}
|
||||
table.image-anchor td {
|
||||
border: 1px solid #CCC;
|
||||
}
|
939
drupal7/web/modules/image/image.admin.inc
Normal file
939
drupal7/web/modules/image/image.admin.inc
Normal file
|
@ -0,0 +1,939 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administration pages for image settings.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback; Listing of all current image styles.
|
||||
*/
|
||||
function image_style_list() {
|
||||
$page = array();
|
||||
|
||||
$styles = image_styles();
|
||||
$page['image_style_list'] = array(
|
||||
'#markup' => theme('image_style_list', array('styles' => $styles)),
|
||||
'#attached' => array(
|
||||
'css' => array(drupal_get_path('module', 'image') . '/image.admin.css' => array()),
|
||||
),
|
||||
);
|
||||
|
||||
return $page;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Edit an image style name and effects order.
|
||||
*
|
||||
* @param $form_state
|
||||
* An associative array containing the current state of the form.
|
||||
* @param $style
|
||||
* An image style array.
|
||||
* @ingroup forms
|
||||
* @see image_style_form_submit()
|
||||
*/
|
||||
function image_style_form($form, &$form_state, $style) {
|
||||
$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.
|
||||
$editable = (bool) ($style['storage'] & IMAGE_STORAGE_EDITABLE);
|
||||
|
||||
if (!$editable && empty($form_state['input'])) {
|
||||
drupal_set_message(t('This image style is currently being provided by a module. Click the "Override defaults" button to change its settings.'), 'warning');
|
||||
}
|
||||
|
||||
$form_state['image_style'] = $style;
|
||||
$form['#tree'] = TRUE;
|
||||
$form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array();
|
||||
|
||||
// Show the thumbnail preview.
|
||||
$form['preview'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('Preview'),
|
||||
'#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().
|
||||
$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(
|
||||
'#theme' => 'image_style_effects',
|
||||
);
|
||||
foreach ($style['effects'] as $key => $effect) {
|
||||
$form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
|
||||
$form['effects'][$key]['label'] = array(
|
||||
'#markup' => $effect['label'],
|
||||
);
|
||||
$form['effects'][$key]['summary'] = array(
|
||||
'#markup' => isset($effect['summary theme']) ? theme($effect['summary theme'], array('data' => $effect['data'])) : '',
|
||||
);
|
||||
$form['effects'][$key]['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#title' => t('Weight for @title', array('@title' => $effect['label'])),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $effect['weight'],
|
||||
'#access' => $editable,
|
||||
);
|
||||
|
||||
// Only attempt to display these fields for editable styles as the 'ieid'
|
||||
// key is not set for styles defined in code.
|
||||
if ($editable) {
|
||||
$form['effects'][$key]['configure'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('edit'),
|
||||
'#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'],
|
||||
'#access' => $editable && isset($effect['form callback']),
|
||||
);
|
||||
$form['effects'][$key]['remove'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('delete'),
|
||||
'#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'] . '/delete',
|
||||
'#access' => $editable,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Build the new image effect addition form and add it to the effect list.
|
||||
$new_effect_options = array();
|
||||
foreach (image_effect_definitions() as $effect => $definition) {
|
||||
$new_effect_options[$effect] = check_plain($definition['label']);
|
||||
}
|
||||
$form['effects']['new'] = array(
|
||||
'#tree' => FALSE,
|
||||
'#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
|
||||
'#access' => $editable,
|
||||
);
|
||||
$form['effects']['new']['new'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Effect'),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => $new_effect_options,
|
||||
'#empty_option' => t('Select a new effect'),
|
||||
);
|
||||
$form['effects']['new']['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#title' => t('Weight for new effect'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => count($form['effects']) - 1,
|
||||
);
|
||||
$form['effects']['new']['add'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Add'),
|
||||
'#validate' => array('image_style_form_add_validate'),
|
||||
'#submit' => array('image_style_form_submit', 'image_style_form_add_submit'),
|
||||
);
|
||||
|
||||
// Show the Override or Submit button for this style.
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['override'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Override defaults'),
|
||||
'#validate' => array(),
|
||||
'#submit' => array('image_style_form_override_submit'),
|
||||
'#access' => !$editable,
|
||||
);
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Update style'),
|
||||
'#access' => $editable,
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate handler for adding a new image effect to an image style.
|
||||
*/
|
||||
function image_style_form_add_validate($form, &$form_state) {
|
||||
if (!$form_state['values']['new']) {
|
||||
form_error($form['effects']['new']['new'], t('Select an effect to add.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for adding a new image effect to an image style.
|
||||
*/
|
||||
function image_style_form_add_submit($form, &$form_state) {
|
||||
$style = $form_state['image_style'];
|
||||
// Check if this field has any configuration options.
|
||||
$effect = image_effect_definition_load($form_state['values']['new']);
|
||||
|
||||
// Load the configuration form for this option.
|
||||
if (isset($effect['form callback'])) {
|
||||
$path = 'admin/config/media/image-styles/edit/' . $form_state['image_style']['name'] . '/add/' . $form_state['values']['new'];
|
||||
$form_state['redirect'] = array($path, array('query' => array('weight' => $form_state['values']['weight'])));
|
||||
}
|
||||
// If there's no form, immediately add the image effect.
|
||||
else {
|
||||
$effect['isid'] = $style['isid'];
|
||||
$effect['weight'] = $form_state['values']['weight'];
|
||||
image_effect_save($effect);
|
||||
drupal_set_message(t('The image effect was successfully applied.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']['label'])));
|
||||
image_default_style_save($form_state['image_style']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for saving an image style.
|
||||
*/
|
||||
function image_style_form_submit($form, &$form_state) {
|
||||
// Update the image style.
|
||||
$style = $form_state['image_style'];
|
||||
$style['name'] = $form_state['values']['name'];
|
||||
$style['label'] = $form_state['values']['label'];
|
||||
|
||||
// Update image effect weights.
|
||||
if (!empty($form_state['values']['effects'])) {
|
||||
foreach ($form_state['values']['effects'] as $ieid => $effect_data) {
|
||||
if (isset($style['effects'][$ieid])) {
|
||||
$effect = $style['effects'][$ieid];
|
||||
$effect['weight'] = $effect_data['weight'];
|
||||
image_effect_save($effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image_style_save($style);
|
||||
if ($form_state['values']['op'] == t('Update style')) {
|
||||
drupal_set_message(t('Changes to the style have been saved.'));
|
||||
}
|
||||
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Form for adding a new image style.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see image_style_add_form_submit()
|
||||
*/
|
||||
function image_style_add_form($form, &$form_state) {
|
||||
$form['label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Style name'),
|
||||
'#default_value' => '',
|
||||
'#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_add_form_name_exists',
|
||||
'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',
|
||||
'#value' => t('Create new style'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the proposed machine name is already taken.
|
||||
*
|
||||
* @param string $name
|
||||
* An image style machine name.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the image style machine name already exists, FALSE otherwise.
|
||||
*/
|
||||
function image_style_add_form_name_exists($name) {
|
||||
return (bool) image_style_load($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for adding a new image style.
|
||||
*/
|
||||
function image_style_add_form_submit($form, &$form_state) {
|
||||
$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['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.
|
||||
$styles = image_styles();
|
||||
if (isset($styles[$element['#value']]) && (!isset($form_state['image_style']['isid']) || $styles[$element['#value']]['isid'] != $form_state['image_style']['isid'])) {
|
||||
form_set_error($element['#name'], t('The image style name %name is already in use.', array('%name' => $element['#value'])));
|
||||
}
|
||||
|
||||
// Check for illegal characters in image style names.
|
||||
if (preg_match('/[^0-9a-z_\-]/', $element['#value'])) {
|
||||
form_set_error($element['#name'], t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Form for deleting an image style.
|
||||
*
|
||||
* @param $style
|
||||
* An image style array.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see image_style_delete_form_submit()
|
||||
*/
|
||||
function image_style_delete_form($form, &$form_state, $style) {
|
||||
$form_state['image_style'] = $style;
|
||||
|
||||
$replacement_styles = array_diff_key(image_style_options(TRUE, PASS_THROUGH), array($style['name'] => ''));
|
||||
$form['replacement'] = array(
|
||||
'#title' => t('Replacement style'),
|
||||
'#type' => 'select',
|
||||
'#options' => $replacement_styles,
|
||||
'#empty_option' => t('No replacement, just delete'),
|
||||
);
|
||||
|
||||
return confirm_form(
|
||||
$form,
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler to delete an image style.
|
||||
*/
|
||||
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['label'])));
|
||||
$form_state['redirect'] = 'admin/config/media/image-styles';
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirmation form to revert a database style to its default.
|
||||
*/
|
||||
function image_style_revert_form($form, &$form_state, $style) {
|
||||
$form_state['image_style'] = $style;
|
||||
|
||||
return confirm_form(
|
||||
$form,
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']['label'])));
|
||||
image_default_style_revert($form_state['image_style']);
|
||||
$form_state['redirect'] = 'admin/config/media/image-styles';
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Form for adding and editing image effects.
|
||||
*
|
||||
* This form is used universally for editing all image effects. Each effect adds
|
||||
* its own custom section to the form by calling the form function specified in
|
||||
* hook_image_effects().
|
||||
*
|
||||
* @param $form_state
|
||||
* An associative array containing the current state of the form.
|
||||
* @param $style
|
||||
* An image style array.
|
||||
* @param $effect
|
||||
* An image effect array.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see hook_image_effects()
|
||||
* @see image_effects()
|
||||
* @see image_resize_form()
|
||||
* @see image_scale_form()
|
||||
* @see image_rotate_form()
|
||||
* @see image_crop_form()
|
||||
* @see image_effect_form_submit()
|
||||
*/
|
||||
function image_effect_form($form, &$form_state, $style, $effect) {
|
||||
if (!empty($effect['data'])) {
|
||||
$title = t('Edit %label effect', array('%label' => $effect['label']));
|
||||
}
|
||||
else{
|
||||
$title = t('Add %label effect', array('%label' => $effect['label']));
|
||||
}
|
||||
drupal_set_title($title, PASS_THROUGH);
|
||||
|
||||
$form_state['image_style'] = $style;
|
||||
$form_state['image_effect'] = $effect;
|
||||
|
||||
// If no configuration for this image effect, return to the image style page.
|
||||
if (!isset($effect['form callback'])) {
|
||||
drupal_goto('admin/config/media/image-styles/edit/' . $style['name']);
|
||||
}
|
||||
|
||||
$form['#tree'] = TRUE;
|
||||
$form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array();
|
||||
if (function_exists($effect['form callback'])) {
|
||||
$form['data'] = call_user_func($effect['form callback'], $effect['data']);
|
||||
}
|
||||
|
||||
// Check the URL for a weight, then the image effect, otherwise use default.
|
||||
$form['weight'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => isset($_GET['weight']) ? intval($_GET['weight']) : (isset($effect['weight']) ? $effect['weight'] : count($style['effects'])),
|
||||
);
|
||||
|
||||
$form['actions'] = array('#tree' => FALSE, '#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => isset($effect['ieid']) ? t('Update effect') : t('Add effect'),
|
||||
);
|
||||
$form['actions']['cancel'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('Cancel'),
|
||||
'#href' => 'admin/config/media/image-styles/edit/' . $style['name'],
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for updating an image effect.
|
||||
*/
|
||||
function image_effect_form_submit($form, &$form_state) {
|
||||
$style = $form_state['image_style'];
|
||||
$effect = array_merge($form_state['image_effect'], $form_state['values']);
|
||||
$effect['isid'] = $style['isid'];
|
||||
image_effect_save($effect);
|
||||
drupal_set_message(t('The image effect was successfully applied.'));
|
||||
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Form for deleting an image effect.
|
||||
*
|
||||
* @param $style
|
||||
* Name of the image style from which the image effect will be removed.
|
||||
* @param $effect
|
||||
* Name of the image effect to remove.
|
||||
* @ingroup forms
|
||||
* @see image_effect_delete_form_submit()
|
||||
*/
|
||||
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['label'], '@effect' => $effect['label']));
|
||||
return confirm_form($form, $question, 'admin/config/media/image-styles/edit/' . $style['name'], '', t('Delete'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler to delete an image effect.
|
||||
*/
|
||||
function image_effect_delete_form_submit($form, &$form_state) {
|
||||
$style = $form_state['image_style'];
|
||||
$effect = $form_state['image_effect'];
|
||||
|
||||
image_effect_delete($effect);
|
||||
drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $effect['label'])));
|
||||
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Element validate handler to ensure an integer pixel value.
|
||||
*
|
||||
* The property #allow_negative = TRUE may be set to allow negative integers.
|
||||
*/
|
||||
function image_effect_integer_validate($element, &$form_state) {
|
||||
$value = empty($element['#allow_negative']) ? $element['#value'] : preg_replace('/^-/', '', $element['#value']);
|
||||
if ($element['#value'] != '' && (!is_numeric($value) || intval($value) <= 0)) {
|
||||
if (empty($element['#allow_negative'])) {
|
||||
form_error($element, t('!name must be an integer.', array('!name' => $element['#title'])));
|
||||
}
|
||||
else {
|
||||
form_error($element, t('!name must be a positive integer.', array('!name' => $element['#title'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Element validate handler to ensure a hexadecimal color value.
|
||||
*/
|
||||
function image_effect_color_validate($element, &$form_state) {
|
||||
if ($element['#value'] != '') {
|
||||
$hex_value = preg_replace('/^#/', '', $element['#value']);
|
||||
if (!preg_match('/^#[0-9A-F]{3}([0-9A-F]{3})?$/', $element['#value'])) {
|
||||
form_error($element, t('!name must be a hexadecimal color value.', array('!name' => $element['#title'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Element validate handler to ensure that either a height or a width is
|
||||
* specified.
|
||||
*/
|
||||
function image_effect_scale_validate($element, &$form_state) {
|
||||
if (empty($element['width']['#value']) && empty($element['height']['#value'])) {
|
||||
form_error($element, t('Width and height can not both be blank.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form structure for the image resize form.
|
||||
*
|
||||
* Note that this is not a complete form, it only contains the portion of the
|
||||
* form for configuring the resize options. Therefore it does not not need to
|
||||
* include metadata about the effect, nor a submit button.
|
||||
*
|
||||
* @param $data
|
||||
* The current configuration for this resize effect.
|
||||
*/
|
||||
function image_resize_form($data) {
|
||||
$form['width'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Width'),
|
||||
'#default_value' => isset($data['width']) ? $data['width'] : '',
|
||||
'#field_suffix' => ' ' . t('pixels'),
|
||||
'#required' => TRUE,
|
||||
'#size' => 10,
|
||||
'#element_validate' => array('image_effect_integer_validate'),
|
||||
'#allow_negative' => FALSE,
|
||||
);
|
||||
$form['height'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Height'),
|
||||
'#default_value' => isset($data['height']) ? $data['height'] : '',
|
||||
'#field_suffix' => ' ' . t('pixels'),
|
||||
'#required' => TRUE,
|
||||
'#size' => 10,
|
||||
'#element_validate' => array('image_effect_integer_validate'),
|
||||
'#allow_negative' => FALSE,
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form structure for the image scale form.
|
||||
*
|
||||
* Note that this is not a complete form, it only contains the portion of the
|
||||
* form for configuring the scale options. Therefore it does not not need to
|
||||
* include metadata about the effect, nor a submit button.
|
||||
*
|
||||
* @param $data
|
||||
* The current configuration for this scale effect.
|
||||
*/
|
||||
function image_scale_form($data) {
|
||||
$form = image_resize_form($data);
|
||||
$form['#element_validate'] = array('image_effect_scale_validate');
|
||||
$form['width']['#required'] = FALSE;
|
||||
$form['height']['#required'] = FALSE;
|
||||
$form['upscale'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => (isset($data['upscale'])) ? $data['upscale'] : 0,
|
||||
'#title' => t('Allow Upscaling'),
|
||||
'#description' => t('Let scale make images larger than their original size'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form structure for the image crop form.
|
||||
*
|
||||
* Note that this is not a complete form, it only contains the portion of the
|
||||
* form for configuring the crop options. Therefore it does not not need to
|
||||
* include metadata about the effect, nor a submit button.
|
||||
*
|
||||
* @param $data
|
||||
* The current configuration for this crop effect.
|
||||
*/
|
||||
function image_crop_form($data) {
|
||||
$data += array(
|
||||
'width' => '',
|
||||
'height' => '',
|
||||
'anchor' => 'center-center',
|
||||
);
|
||||
|
||||
$form = image_resize_form($data);
|
||||
$form['anchor'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Anchor'),
|
||||
'#options' => array(
|
||||
'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 right'),
|
||||
'left-bottom' => t('Bottom left'),
|
||||
'center-bottom' => t('Bottom center'),
|
||||
'right-bottom' => t('Bottom right'),
|
||||
),
|
||||
'#theme' => 'image_anchor',
|
||||
'#default_value' => $data['anchor'],
|
||||
'#description' => t('The part of the image that will be retained during the crop.'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form structure for the image rotate form.
|
||||
*
|
||||
* Note that this is not a complete form, it only contains the portion of the
|
||||
* form for configuring the rotate options. Therefore it does not not need to
|
||||
* include metadata about the effect, nor a submit button.
|
||||
*
|
||||
* @param $data
|
||||
* The current configuration for this rotate effect.
|
||||
*/
|
||||
function image_rotate_form($data) {
|
||||
$form['degrees'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => (isset($data['degrees'])) ? $data['degrees'] : 0,
|
||||
'#title' => t('Rotation angle'),
|
||||
'#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'),
|
||||
'#field_suffix' => '°',
|
||||
'#required' => TRUE,
|
||||
'#size' => 6,
|
||||
'#maxlength' => 4,
|
||||
'#element_validate' => array('image_effect_integer_validate'),
|
||||
'#allow_negative' => TRUE,
|
||||
);
|
||||
$form['bgcolor'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => (isset($data['bgcolor'])) ? $data['bgcolor'] : '#FFFFFF',
|
||||
'#title' => t('Background color'),
|
||||
'#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'),
|
||||
'#size' => 7,
|
||||
'#maxlength' => 7,
|
||||
'#element_validate' => array('image_effect_color_validate'),
|
||||
);
|
||||
$form['random'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => (isset($data['random'])) ? $data['random'] : 0,
|
||||
'#title' => t('Randomize'),
|
||||
'#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the page containing the list of image styles.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - styles: An array of all the image styles returned by image_get_styles().
|
||||
*
|
||||
* @see image_get_styles()
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_style_list($variables) {
|
||||
$styles = $variables['styles'];
|
||||
|
||||
$header = array(t('Style name'), t('Settings'), array('data' => t('Operations'), 'colspan' => 3));
|
||||
$rows = array();
|
||||
foreach ($styles as $style) {
|
||||
$row = array();
|
||||
$row[] = l($style['label'], 'admin/config/media/image-styles/edit/' . $style['name']);
|
||||
$link_attributes = array(
|
||||
'attributes' => array(
|
||||
'class' => array('image-style-link'),
|
||||
),
|
||||
);
|
||||
if ($style['storage'] == IMAGE_STORAGE_NORMAL) {
|
||||
$row[] = t('Custom');
|
||||
$row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes);
|
||||
$row[] = l(t('delete'), 'admin/config/media/image-styles/delete/' . $style['name'], $link_attributes);
|
||||
}
|
||||
elseif ($style['storage'] == IMAGE_STORAGE_OVERRIDE) {
|
||||
$row[] = t('Overridden');
|
||||
$row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes);
|
||||
$row[] = l(t('revert'), 'admin/config/media/image-styles/revert/' . $style['name'], $link_attributes);
|
||||
}
|
||||
else {
|
||||
$row[] = t('Default');
|
||||
$row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes);
|
||||
$row[] = '';
|
||||
}
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
if (empty($rows)) {
|
||||
$rows[] = array(array(
|
||||
'colspan' => 4,
|
||||
'data' => t('There are currently no styles. <a href="!url">Add a new one</a>.', array('!url' => url('admin/config/media/image-styles/add'))),
|
||||
));
|
||||
}
|
||||
|
||||
return theme('table', array('header' => $header, 'rows' => $rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a listing of the effects within a specific image style.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - form: A render element representing the form.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_style_effects($variables) {
|
||||
$form = $variables['form'];
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach (element_children($form) as $key) {
|
||||
$row = array();
|
||||
$form[$key]['weight']['#attributes']['class'] = array('image-effect-order-weight');
|
||||
if (is_numeric($key)) {
|
||||
$summary = drupal_render($form[$key]['summary']);
|
||||
$row[] = drupal_render($form[$key]['label']) . (empty($summary) ? '' : ' ' . $summary);
|
||||
$row[] = drupal_render($form[$key]['weight']);
|
||||
$row[] = drupal_render($form[$key]['configure']);
|
||||
$row[] = drupal_render($form[$key]['remove']);
|
||||
}
|
||||
else {
|
||||
// Add the row for adding a new image effect.
|
||||
$row[] = '<div class="image-style-new">' . drupal_render($form['new']['new']) . drupal_render($form['new']['add']) . '</div>';
|
||||
$row[] = drupal_render($form['new']['weight']);
|
||||
$row[] = array('data' => '', 'colspan' => 2);
|
||||
}
|
||||
|
||||
if (!isset($form[$key]['#access']) || $form[$key]['#access']) {
|
||||
$rows[] = array(
|
||||
'data' => $row,
|
||||
// Use a strict (===) comparison since $key can be 0.
|
||||
'class' => !empty($form[$key]['weight']['#access']) || $key === 'new' ? array('draggable') : array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$header = array(
|
||||
t('Effect'),
|
||||
t('Weight'),
|
||||
array('data' => t('Operations'), 'colspan' => 2),
|
||||
);
|
||||
|
||||
if (count($rows) == 1 && $form['new']['#access']) {
|
||||
array_unshift($rows, array(array(
|
||||
'data' => t('There are currently no effects in this style. Add one by selecting an option below.'),
|
||||
'colspan' => 4,
|
||||
)));
|
||||
}
|
||||
|
||||
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'image-style-effects')));
|
||||
drupal_add_tabledrag('image-style-effects', 'order', 'sibling', 'image-effect-order-weight');
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a preview of an image style.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - style: The image style array being previewed.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_style_preview($variables) {
|
||||
$style = $variables['style'];
|
||||
|
||||
$sample_image = variable_get('image_style_preview_image', drupal_get_path('module', 'image') . '/sample.png');
|
||||
$sample_width = 160;
|
||||
$sample_height = 160;
|
||||
|
||||
// Set up original file information.
|
||||
$original_path = $sample_image;
|
||||
$original_image = image_get_info($original_path);
|
||||
if ($original_image['width'] > $original_image['height']) {
|
||||
$original_width = min($original_image['width'], $sample_width);
|
||||
$original_height = round($original_width / $original_image['width'] * $original_image['height']);
|
||||
}
|
||||
else {
|
||||
$original_height = min($original_image['height'], $sample_height);
|
||||
$original_width = round($original_height / $original_image['height'] * $original_image['width']);
|
||||
}
|
||||
$original_attributes = array_intersect_key($original_image, array('width' => '', 'height' => ''));
|
||||
$original_attributes['style'] = 'width: ' . $original_width . 'px; height: ' . $original_height . 'px;';
|
||||
|
||||
// Set up preview file information.
|
||||
$preview_file = image_style_path($style['name'], $original_path);
|
||||
if (!file_exists($preview_file)) {
|
||||
image_style_create_derivative($style, $original_path, $preview_file);
|
||||
}
|
||||
$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']);
|
||||
}
|
||||
else {
|
||||
$preview_height = min($preview_image['height'], $sample_height);
|
||||
$preview_width = round($preview_height / $preview_image['height'] * $preview_image['width']);
|
||||
}
|
||||
$preview_attributes = array_intersect_key($preview_image, array('width' => '', 'height' => ''));
|
||||
$preview_attributes['style'] = 'width: ' . $preview_width . 'px; height: ' . $preview_height . 'px;';
|
||||
|
||||
// In the previews, timestamps are added to prevent caching of images.
|
||||
$output = '<div class="image-style-preview preview clearfix">';
|
||||
|
||||
// Build the preview of the original image.
|
||||
$original_url = file_create_url($original_path);
|
||||
$output .= '<div class="preview-image-wrapper">';
|
||||
$output .= t('original') . ' (' . l(t('view actual size'), $original_url) . ')';
|
||||
$output .= '<div class="preview-image original-image" style="' . $original_attributes['style'] . '">';
|
||||
$output .= '<a href="' . $original_url . '">' . theme('image', array('path' => $original_path, 'alt' => t('Sample original image'), 'title' => '', 'attributes' => $original_attributes)) . '</a>';
|
||||
$output .= '<div class="height" style="height: ' . $original_height . 'px"><span>' . $original_image['height'] . 'px</span></div>';
|
||||
$output .= '<div class="width" style="width: ' . $original_width . 'px"><span>' . $original_image['width'] . 'px</span></div>';
|
||||
$output .= '</div>'; // End preview-image.
|
||||
$output .= '</div>'; // End preview-image-wrapper.
|
||||
|
||||
// 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['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>';
|
||||
$output .= '<div class="width" style="width: ' . $preview_width . 'px"><span>' . $preview_image['width'] . 'px</span></div>';
|
||||
$output .= '</div>'; // End preview-image.
|
||||
$output .= '</div>'; // End preview-image-wrapper.
|
||||
|
||||
$output .= '</div>'; // End image-style-preview.
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a 3x3 grid of checkboxes for image anchors.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - element: A render element containing radio buttons.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_anchor($variables) {
|
||||
$element = $variables['element'];
|
||||
|
||||
$rows = array();
|
||||
$row = array();
|
||||
foreach (element_children($element) as $n => $key) {
|
||||
$element[$key]['#attributes']['title'] = $element[$key]['#title'];
|
||||
unset($element[$key]['#title']);
|
||||
$row[] = drupal_render($element[$key]);
|
||||
if ($n % 3 == 3 - 1) {
|
||||
$rows[] = $row;
|
||||
$row = array();
|
||||
}
|
||||
}
|
||||
|
||||
return theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array('class' => array('image-anchor'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a summary of an image resize effect.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - data: The current configuration for this resize effect.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_resize_summary($variables) {
|
||||
$data = $variables['data'];
|
||||
|
||||
if ($data['width'] && $data['height']) {
|
||||
return check_plain($data['width']) . 'x' . check_plain($data['height']);
|
||||
}
|
||||
else {
|
||||
return ($data['width']) ? t('width @width', array('@width' => $data['width'])) : t('height @height', array('@height' => $data['height']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a summary of an image scale effect.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - data: The current configuration for this scale effect.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_scale_summary($variables) {
|
||||
$data = $variables['data'];
|
||||
return theme('image_resize_summary', array('data' => $data)) . ' ' . ($data['upscale'] ? '(' . t('upscaling allowed') . ')' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a summary of an image crop effect.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - data: The current configuration for this crop effect.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_crop_summary($variables) {
|
||||
return theme('image_resize_summary', $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a summary of an image rotate effect.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - data: The current configuration for this rotate effect.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_rotate_summary($variables) {
|
||||
$data = $variables['data'];
|
||||
return ($data['random']) ? t('random between -@degrees° and @degrees°', array('@degrees' => str_replace('-', '', $data['degrees']))) : t('@degrees°', array('@degrees' => $data['degrees']));
|
||||
}
|
200
drupal7/web/modules/image/image.api.php
Normal file
200
drupal7/web/modules/image/image.api.php
Normal file
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks related to image styles and effects.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hooks
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define information about image effects provided by a module.
|
||||
*
|
||||
* This hook enables modules to define image manipulation effects for use with
|
||||
* an image style.
|
||||
*
|
||||
* @return
|
||||
* An array of image effects. This array is keyed on the machine-readable
|
||||
* effect name. Each effect is defined as an associative array containing the
|
||||
* following items:
|
||||
* - "label": The human-readable name of the effect.
|
||||
* - "effect callback": The function to call to perform this image effect.
|
||||
* - "dimensions passthrough": (optional) Set this item if the effect doesn't
|
||||
* change the dimensions of the image.
|
||||
* - "dimensions callback": (optional) The function to call to transform
|
||||
* dimensions for this effect.
|
||||
* - "help": (optional) A brief description of the effect that will be shown
|
||||
* when adding or configuring this image effect.
|
||||
* - "form callback": (optional) The name of a function that will return a
|
||||
* $form array providing a configuration form for this image effect.
|
||||
* - "summary theme": (optional) The name of a theme function that will output
|
||||
* a summary of this image effect's configuration.
|
||||
*
|
||||
* @see hook_image_effect_info_alter()
|
||||
*/
|
||||
function hook_image_effect_info() {
|
||||
$effects = array();
|
||||
|
||||
$effects['mymodule_resize'] = array(
|
||||
'label' => t('Resize'),
|
||||
'help' => t('Resize an image to an exact set of dimensions, ignoring aspect ratio.'),
|
||||
'effect callback' => 'mymodule_resize_effect',
|
||||
'dimensions callback' => 'mymodule_resize_dimensions',
|
||||
'form callback' => 'mymodule_resize_form',
|
||||
'summary theme' => 'mymodule_resize_summary',
|
||||
);
|
||||
|
||||
return $effects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the information provided in hook_image_effect_info().
|
||||
*
|
||||
* @param $effects
|
||||
* The array of image effects, keyed on the machine-readable effect name.
|
||||
*
|
||||
* @see hook_image_effect_info()
|
||||
*/
|
||||
function hook_image_effect_info_alter(&$effects) {
|
||||
// Override the Image module's crop effect with more options.
|
||||
$effects['image_crop']['effect callback'] = 'mymodule_crop_effect';
|
||||
$effects['image_crop']['dimensions callback'] = 'mymodule_crop_dimensions';
|
||||
$effects['image_crop']['form callback'] = 'mymodule_crop_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to image style updating.
|
||||
*
|
||||
* This hook enables modules to update settings that might be affected by
|
||||
* changes to an image. For example, updating a module specific variable to
|
||||
* reflect a change in the image style's name.
|
||||
*
|
||||
* @param $style
|
||||
* The image style array that is being updated.
|
||||
*/
|
||||
function hook_image_style_save($style) {
|
||||
// If a module defines an image style and that style is renamed by the user
|
||||
// the module should update any references to that style.
|
||||
if (isset($style['old_name']) && $style['old_name'] == variable_get('mymodule_image_style', '')) {
|
||||
variable_set('mymodule_image_style', $style['name']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to image style deletion.
|
||||
*
|
||||
* This hook enables modules to update settings when a image style is being
|
||||
* deleted. If a style is deleted, a replacement name may be specified in
|
||||
* $style['name'] and the style being deleted will be specified in
|
||||
* $style['old_name'].
|
||||
*
|
||||
* @param $style
|
||||
* The image style array that being deleted.
|
||||
*/
|
||||
function hook_image_style_delete($style) {
|
||||
// Administrators can choose an optional replacement style when deleting.
|
||||
// Update the modules style variable accordingly.
|
||||
if (isset($style['old_name']) && $style['old_name'] == variable_get('mymodule_image_style', '')) {
|
||||
variable_set('mymodule_image_style', $style['name']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to image style flushing.
|
||||
*
|
||||
* This hook enables modules to take effect when a style is being flushed (all
|
||||
* images are being deleted from the server and regenerated). Any
|
||||
* module-specific caches that contain information related to the style should
|
||||
* be cleared using this hook. This hook is called whenever a style is updated,
|
||||
* deleted, or any effect associated with the style is update or deleted.
|
||||
*
|
||||
* @param $style
|
||||
* The image style array that is being flushed.
|
||||
*/
|
||||
function hook_image_style_flush($style) {
|
||||
// Empty cached data that contains information about the style.
|
||||
cache_clear_all('*', 'cache_mymodule', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify any image styles provided by other modules or the user.
|
||||
*
|
||||
* This hook allows modules to modify, add, or remove image styles. This may
|
||||
* be useful to modify default styles provided by other modules or enforce
|
||||
* that a specific effect is always enabled on a style. Note that modifications
|
||||
* to these styles may negatively affect the user experience, such as if an
|
||||
* effect is added to a style through this hook, the user may attempt to remove
|
||||
* the effect but it will be immediately be re-added.
|
||||
*
|
||||
* The best use of this hook is usually to modify default styles, which are not
|
||||
* editable by the user until they are overridden, so such interface
|
||||
* contradictions will not occur. This hook can target default (or user) styles
|
||||
* by checking the $style['storage'] property.
|
||||
*
|
||||
* If your module needs to provide a new style (rather than modify an existing
|
||||
* one) use hook_image_default_styles() instead.
|
||||
*
|
||||
* @see hook_image_default_styles()
|
||||
*/
|
||||
function hook_image_styles_alter(&$styles) {
|
||||
// Check that we only affect a default style.
|
||||
if ($styles['thumbnail']['storage'] == IMAGE_STORAGE_DEFAULT) {
|
||||
// Add an additional effect to the thumbnail style.
|
||||
$styles['thumbnail']['effects'][] = array(
|
||||
'name' => 'image_desaturate',
|
||||
'data' => array(),
|
||||
'weight' => 1,
|
||||
'effect callback' => 'image_desaturate_effect',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide module-based image styles for reuse throughout Drupal.
|
||||
*
|
||||
* This hook allows your module to provide image styles. This may be useful if
|
||||
* you require images to fit within exact dimensions. Note that you should
|
||||
* attempt to re-use the default styles provided by Image module whenever
|
||||
* possible, rather than creating image styles that are specific to your module.
|
||||
* Image provides the styles "thumbnail", "medium", and "large".
|
||||
*
|
||||
* You may use this hook to more easily manage your site's changes by moving
|
||||
* existing image styles from the database to a custom module. Note however that
|
||||
* moving image styles to code instead storing them in the database has a
|
||||
* negligible effect on performance, since custom image styles are loaded
|
||||
* from the database all at once. Even if all styles are pulled from modules,
|
||||
* Image module will still perform the same queries to check the database for
|
||||
* any custom styles.
|
||||
*
|
||||
* @return
|
||||
* An array of image styles, keyed by the style name.
|
||||
* @see image_image_default_styles()
|
||||
*/
|
||||
function hook_image_default_styles() {
|
||||
$styles = array();
|
||||
|
||||
$styles['mymodule_preview'] = array(
|
||||
'label' => 'My module preview',
|
||||
'effects' => array(
|
||||
array(
|
||||
'name' => 'image_scale',
|
||||
'data' => array('width' => 400, 'height' => 400, 'upscale' => 1),
|
||||
'weight' => 0,
|
||||
),
|
||||
array(
|
||||
'name' => 'image_desaturate',
|
||||
'data' => array(),
|
||||
'weight' => 1,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
14
drupal7/web/modules/image/image.css
Normal file
14
drupal7/web/modules/image/image.css
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
/**
|
||||
* Image upload widget.
|
||||
*/
|
||||
div.image-preview {
|
||||
float: left; /* LTR */
|
||||
padding: 0 10px 10px 0; /* LTR */
|
||||
}
|
||||
div.image-widget-data {
|
||||
float: left; /* LTR */
|
||||
}
|
||||
div.image-widget-data input.text-field {
|
||||
width: auto;
|
||||
}
|
314
drupal7/web/modules/image/image.effects.inc
Normal file
314
drupal7/web/modules/image/image.effects.inc
Normal file
|
@ -0,0 +1,314 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Functions needed to execute image effects provided by Image module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_image_effect_info().
|
||||
*/
|
||||
function image_image_effect_info() {
|
||||
$effects = array(
|
||||
'image_resize' => array(
|
||||
'label' => t('Resize'),
|
||||
'help' => t('Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately.'),
|
||||
'effect callback' => 'image_resize_effect',
|
||||
'dimensions callback' => 'image_resize_dimensions',
|
||||
'form callback' => 'image_resize_form',
|
||||
'summary theme' => 'image_resize_summary',
|
||||
),
|
||||
'image_scale' => array(
|
||||
'label' => t('Scale'),
|
||||
'help' => t('Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.'),
|
||||
'effect callback' => 'image_scale_effect',
|
||||
'dimensions callback' => 'image_scale_dimensions',
|
||||
'form callback' => 'image_scale_form',
|
||||
'summary theme' => 'image_scale_summary',
|
||||
),
|
||||
'image_scale_and_crop' => array(
|
||||
'label' => t('Scale and crop'),
|
||||
'help' => t('Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.'),
|
||||
'effect callback' => 'image_scale_and_crop_effect',
|
||||
'dimensions callback' => 'image_resize_dimensions',
|
||||
'form callback' => 'image_resize_form',
|
||||
'summary theme' => 'image_resize_summary',
|
||||
),
|
||||
'image_crop' => array(
|
||||
'label' => t('Crop'),
|
||||
'help' => t('Cropping will remove portions of an image to make it the specified dimensions.'),
|
||||
'effect callback' => 'image_crop_effect',
|
||||
'dimensions callback' => 'image_resize_dimensions',
|
||||
'form callback' => 'image_crop_form',
|
||||
'summary theme' => 'image_crop_summary',
|
||||
),
|
||||
'image_desaturate' => array(
|
||||
'label' => t('Desaturate'),
|
||||
'help' => t('Desaturate converts an image to grayscale.'),
|
||||
'effect callback' => 'image_desaturate_effect',
|
||||
'dimensions passthrough' => TRUE,
|
||||
),
|
||||
'image_rotate' => array(
|
||||
'label' => t('Rotate'),
|
||||
'help' => t('Rotating an image may cause the dimensions of an image to increase to fit the diagonal.'),
|
||||
'effect callback' => 'image_rotate_effect',
|
||||
'dimensions callback' => 'image_rotate_dimensions',
|
||||
'form callback' => 'image_rotate_form',
|
||||
'summary theme' => 'image_rotate_summary',
|
||||
),
|
||||
);
|
||||
|
||||
return $effects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image effect callback; Resize an image resource.
|
||||
*
|
||||
* @param $image
|
||||
* An image object returned by image_load().
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the resize effect with the
|
||||
* following items:
|
||||
* - "width": An integer representing the desired width in pixels.
|
||||
* - "height": An integer representing the desired height in pixels.
|
||||
*
|
||||
* @return
|
||||
* TRUE on success. FALSE on failure to resize image.
|
||||
*
|
||||
* @see image_resize()
|
||||
*/
|
||||
function image_resize_effect(&$image, $data) {
|
||||
if (!image_resize($image, $data['width'], $data['height'])) {
|
||||
watchdog('image', 'Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image dimensions callback; Resize.
|
||||
*
|
||||
* @param $dimensions
|
||||
* Dimensions to be modified - an array with components width and height, in
|
||||
* pixels.
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the resize effect with the
|
||||
* following items:
|
||||
* - "width": An integer representing the desired width in pixels.
|
||||
* - "height": An integer representing the desired height in pixels.
|
||||
*/
|
||||
function image_resize_dimensions(array &$dimensions, array $data) {
|
||||
// The new image will have the exact dimensions defined for the effect.
|
||||
$dimensions['width'] = $data['width'];
|
||||
$dimensions['height'] = $data['height'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Image effect callback; Scale an image resource.
|
||||
*
|
||||
* @param $image
|
||||
* An image object returned by image_load().
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the scale effect with the
|
||||
* following items:
|
||||
* - "width": An integer representing the desired width in pixels.
|
||||
* - "height": An integer representing the desired height in pixels.
|
||||
* - "upscale": A boolean indicating that the image should be upscaled if the
|
||||
* dimensions are larger than the original image.
|
||||
*
|
||||
* @return
|
||||
* TRUE on success. FALSE on failure to scale image.
|
||||
*
|
||||
* @see image_scale()
|
||||
*/
|
||||
function image_scale_effect(&$image, $data) {
|
||||
// Set sane default values.
|
||||
$data += array(
|
||||
'width' => NULL,
|
||||
'height' => NULL,
|
||||
'upscale' => FALSE,
|
||||
);
|
||||
|
||||
if (!image_scale($image, $data['width'], $data['height'], $data['upscale'])) {
|
||||
watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image dimensions callback; Scale.
|
||||
*
|
||||
* @param $dimensions
|
||||
* Dimensions to be modified - an array with components width and height, in
|
||||
* pixels.
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the scale effect with the
|
||||
* following items:
|
||||
* - "width": An integer representing the desired width in pixels.
|
||||
* - "height": An integer representing the desired height in pixels.
|
||||
* - "upscale": A boolean indicating that the image should be upscaled if the
|
||||
* dimensions are larger than the original image.
|
||||
*/
|
||||
function image_scale_dimensions(array &$dimensions, array $data) {
|
||||
if ($dimensions['width'] && $dimensions['height']) {
|
||||
image_dimensions_scale($dimensions, $data['width'], $data['height'], $data['upscale']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Image effect callback; Crop an image resource.
|
||||
*
|
||||
* @param $image
|
||||
* An image object returned by image_load().
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the crop effect with the
|
||||
* following items:
|
||||
* - "width": An integer representing the desired width in pixels.
|
||||
* - "height": An integer representing the desired height in pixels.
|
||||
* - "anchor": A string describing where the crop should originate in the form
|
||||
* of "XOFFSET-YOFFSET". XOFFSET is either a number of pixels or
|
||||
* "left", "center", "right" and YOFFSET is either a number of pixels or
|
||||
* "top", "center", "bottom".
|
||||
* @return
|
||||
* TRUE on success. FALSE on failure to crop image.
|
||||
* @see image_crop()
|
||||
*/
|
||||
function image_crop_effect(&$image, $data) {
|
||||
// Set sane default values.
|
||||
$data += array(
|
||||
'anchor' => 'center-center',
|
||||
);
|
||||
|
||||
list($x, $y) = explode('-', $data['anchor']);
|
||||
$x = image_filter_keyword($x, $image->info['width'], $data['width']);
|
||||
$y = image_filter_keyword($y, $image->info['height'], $data['height']);
|
||||
if (!image_crop($image, $x, $y, $data['width'], $data['height'])) {
|
||||
watchdog('image', 'Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image effect callback; Scale and crop an image resource.
|
||||
*
|
||||
* @param $image
|
||||
* An image object returned by image_load().
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the scale and crop effect
|
||||
* with the following items:
|
||||
* - "width": An integer representing the desired width in pixels.
|
||||
* - "height": An integer representing the desired height in pixels.
|
||||
* @return
|
||||
* TRUE on success. FALSE on failure to scale and crop image.
|
||||
* @see image_scale_and_crop()
|
||||
*/
|
||||
function image_scale_and_crop_effect(&$image, $data) {
|
||||
if (!image_scale_and_crop($image, $data['width'], $data['height'])) {
|
||||
watchdog('image', 'Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image effect callback; Desaturate (grayscale) an image resource.
|
||||
*
|
||||
* @param $image
|
||||
* An image object returned by image_load().
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the desaturate effect.
|
||||
* @return
|
||||
* TRUE on success. FALSE on failure to desaturate image.
|
||||
* @see image_desaturate()
|
||||
*/
|
||||
function image_desaturate_effect(&$image, $data) {
|
||||
if (!image_desaturate($image)) {
|
||||
watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image effect callback; Rotate an image resource.
|
||||
*
|
||||
* @param $image
|
||||
* An image object returned by image_load().
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the rotate effect containing
|
||||
* the following items:
|
||||
* - "degrees": The number of (clockwise) degrees to rotate the image.
|
||||
* - "random": A boolean indicating that a random rotation angle should be
|
||||
* used for this image. The angle specified in "degrees" is used as a
|
||||
* positive and negative maximum.
|
||||
* - "bgcolor": The background color to use for exposed areas of the image.
|
||||
* Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave
|
||||
* blank for transparency on image types that support it.
|
||||
* @return
|
||||
* TRUE on success. FALSE on failure to rotate image.
|
||||
* @see image_rotate().
|
||||
*/
|
||||
function image_rotate_effect(&$image, $data) {
|
||||
// Set sane default values.
|
||||
$data += array(
|
||||
'degrees' => 0,
|
||||
'bgcolor' => NULL,
|
||||
'random' => FALSE,
|
||||
);
|
||||
|
||||
// Convert short #FFF syntax to full #FFFFFF syntax.
|
||||
if (strlen((string) $data['bgcolor']) == 4) {
|
||||
$c = $data['bgcolor'];
|
||||
$data['bgcolor'] = $c[0] . $c[1] . $c[1] . $c[2] . $c[2] . $c[3] . $c[3];
|
||||
}
|
||||
|
||||
// Convert #FFFFFF syntax to hexadecimal colors.
|
||||
if ($data['bgcolor'] != '') {
|
||||
$data['bgcolor'] = hexdec(str_replace('#', '0x', $data['bgcolor']));
|
||||
}
|
||||
else {
|
||||
$data['bgcolor'] = NULL;
|
||||
}
|
||||
|
||||
if (!empty($data['random'])) {
|
||||
$degrees = abs((float) $data['degrees']);
|
||||
$data['degrees'] = rand(-1 * $degrees, $degrees);
|
||||
}
|
||||
|
||||
if (!image_rotate($image, $data['degrees'], $data['bgcolor'])) {
|
||||
watchdog('image', 'Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->toolkit, '%path' => $image->source, '%mimetype' => $image->info['mime_type'], '%dimensions' => $image->info['width'] . 'x' . $image->info['height']), WATCHDOG_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image dimensions callback; Rotate.
|
||||
*
|
||||
* @param $dimensions
|
||||
* Dimensions to be modified - an array with components width and height, in
|
||||
* pixels.
|
||||
* @param $data
|
||||
* An array of attributes to use when performing the rotate effect containing
|
||||
* the following items:
|
||||
* - "degrees": The number of (clockwise) degrees to rotate the image.
|
||||
* - "random": A boolean indicating that a random rotation angle should be
|
||||
* used for this image. The angle specified in "degrees" is used as a
|
||||
* positive and negative maximum.
|
||||
*/
|
||||
function image_rotate_dimensions(array &$dimensions, array $data) {
|
||||
// If the rotate is not random and the angle is a multiple of 90 degrees,
|
||||
// then the new dimensions can be determined.
|
||||
if (!$data['random'] && ((int) ($data['degrees']) == $data['degrees']) && ($data['degrees'] % 90 == 0)) {
|
||||
if ($data['degrees'] % 180 != 0) {
|
||||
$temp = $dimensions['width'];
|
||||
$dimensions['width'] = $dimensions['height'];
|
||||
$dimensions['height'] = $temp;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$dimensions['width'] = $dimensions['height'] = NULL;
|
||||
}
|
||||
}
|
647
drupal7/web/modules/image/image.field.inc
Normal file
647
drupal7/web/modules/image/image.field.inc
Normal file
|
@ -0,0 +1,647 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Implement an image field, based on the file module's file field.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_info().
|
||||
*/
|
||||
function image_field_info() {
|
||||
return array(
|
||||
'image' => array(
|
||||
'label' => t('Image'),
|
||||
'description' => t('This field stores the ID of an image file as an integer value.'),
|
||||
'settings' => array(
|
||||
'uri_scheme' => variable_get('file_default_scheme', 'public'),
|
||||
'default_image' => 0,
|
||||
),
|
||||
'instance_settings' => array(
|
||||
'file_extensions' => 'png gif jpg jpeg',
|
||||
'file_directory' => '[date:custom:Y]-[date:custom:m]',
|
||||
'max_filesize' => '',
|
||||
'alt_field' => 0,
|
||||
'title_field' => 0,
|
||||
'max_resolution' => '',
|
||||
'min_resolution' => '',
|
||||
'default_image' => 0,
|
||||
),
|
||||
'default_widget' => 'image_image',
|
||||
'default_formatter' => 'image',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_settings_form().
|
||||
*/
|
||||
function image_field_settings_form($field, $instance) {
|
||||
$defaults = field_info_field_settings($field['type']);
|
||||
$settings = array_merge($defaults, $field['settings']);
|
||||
|
||||
$scheme_options = array();
|
||||
foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {
|
||||
$scheme_options[$scheme] = $stream_wrapper['name'];
|
||||
}
|
||||
$form['uri_scheme'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Upload destination'),
|
||||
'#options' => $scheme_options,
|
||||
'#default_value' => $settings['uri_scheme'],
|
||||
'#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'),
|
||||
);
|
||||
|
||||
// When the user sets the scheme on the UI, even for the first time, it's
|
||||
// updating a field because fields are created on the "Manage fields"
|
||||
// page. So image_field_update_field() can handle this change.
|
||||
$form['default_image'] = array(
|
||||
'#title' => t('Default image'),
|
||||
'#type' => 'managed_file',
|
||||
'#description' => t('If no image is uploaded, this image will be shown on display.'),
|
||||
'#default_value' => $field['settings']['default_image'],
|
||||
'#upload_location' => $settings['uri_scheme'] . '://default_images/',
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_instance_settings_form().
|
||||
*/
|
||||
function image_field_instance_settings_form($field, $instance) {
|
||||
$settings = $instance['settings'];
|
||||
|
||||
// Use the file field instance settings form as a basis.
|
||||
$form = file_field_instance_settings_form($field, $instance);
|
||||
|
||||
// Add maximum and minimum resolution settings.
|
||||
$max_resolution = explode('x', $settings['max_resolution']) + array('', '');
|
||||
$form['max_resolution'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('Maximum image resolution'),
|
||||
'#element_validate' => array('_image_field_resolution_validate'),
|
||||
'#weight' => 4.1,
|
||||
'#field_prefix' => '<div class="container-inline">',
|
||||
'#field_suffix' => '</div>',
|
||||
'#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href="http://en.wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image.'),
|
||||
);
|
||||
$form['max_resolution']['x'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Maximum width'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $max_resolution[0],
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#field_suffix' => ' x ',
|
||||
);
|
||||
$form['max_resolution']['y'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Maximum height'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $max_resolution[1],
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#field_suffix' => ' ' . t('pixels'),
|
||||
);
|
||||
|
||||
$min_resolution = explode('x', $settings['min_resolution']) + array('', '');
|
||||
$form['min_resolution'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('Minimum image resolution'),
|
||||
'#element_validate' => array('_image_field_resolution_validate'),
|
||||
'#weight' => 4.2,
|
||||
'#field_prefix' => '<div class="container-inline">',
|
||||
'#field_suffix' => '</div>',
|
||||
'#description' => t('The minimum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'),
|
||||
);
|
||||
$form['min_resolution']['x'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Minimum width'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $min_resolution[0],
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#field_suffix' => ' x ',
|
||||
);
|
||||
$form['min_resolution']['y'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Minimum height'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $min_resolution[1],
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#field_suffix' => ' ' . t('pixels'),
|
||||
);
|
||||
|
||||
// Remove the description option.
|
||||
unset($form['description_field']);
|
||||
|
||||
// Add title and alt configuration options.
|
||||
$form['alt_field'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable <em>Alt</em> field'),
|
||||
'#default_value' => $settings['alt_field'],
|
||||
'#description' => t('The alt attribute may be used by search engines, screen readers, and when the image cannot be loaded.'),
|
||||
'#weight' => 10,
|
||||
);
|
||||
$form['title_field'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable <em>Title</em> field'),
|
||||
'#default_value' => $settings['title_field'],
|
||||
'#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image.'),
|
||||
'#weight' => 11,
|
||||
);
|
||||
|
||||
// Add the default image to the instance.
|
||||
$form['default_image'] = array(
|
||||
'#title' => t('Default image'),
|
||||
'#type' => 'managed_file',
|
||||
'#description' => t("If no image is uploaded, this image will be shown on display and will override the field's default image."),
|
||||
'#default_value' => $settings['default_image'],
|
||||
'#upload_location' => $field['settings']['uri_scheme'] . '://default_images/',
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Element validate function for resolution fields.
|
||||
*/
|
||||
function _image_field_resolution_validate($element, &$form_state) {
|
||||
if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) {
|
||||
foreach (array('x', 'y') as $dimension) {
|
||||
$value = $element[$dimension]['#value'];
|
||||
if (!is_numeric($value)) {
|
||||
form_error($element[$dimension], t('Height and width values must be numeric.'));
|
||||
return;
|
||||
}
|
||||
if (intval($value) < 0) {
|
||||
form_error($element[$dimension], t('Height and width values must be positive numbers.'));
|
||||
return;
|
||||
}
|
||||
if (intval($value) == 0) {
|
||||
form_error($element[$dimension], t('Both a height and width value must be specified in the !name field.', array('!name' => $element['#title'])));
|
||||
return;
|
||||
}
|
||||
}
|
||||
form_set_value($element, intval($element['x']['#value']) . 'x' . intval($element['y']['#value']), $form_state);
|
||||
}
|
||||
else {
|
||||
form_set_value($element, '', $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_load().
|
||||
*/
|
||||
function image_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
|
||||
file_field_load($entity_type, $entities, $field, $instances, $langcode, $items, $age);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_prepare_view().
|
||||
*/
|
||||
function image_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
|
||||
// If there are no files specified at all, use the default.
|
||||
foreach ($entities as $id => $entity) {
|
||||
if (empty($items[$id])) {
|
||||
$fid = 0;
|
||||
// Use the default for the instance if one is available.
|
||||
if (!empty($instances[$id]['settings']['default_image'])) {
|
||||
$fid = $instances[$id]['settings']['default_image'];
|
||||
}
|
||||
// Otherwise, use the default for the field.
|
||||
elseif (!empty($field['settings']['default_image'])) {
|
||||
$fid = $field['settings']['default_image'];
|
||||
}
|
||||
|
||||
// Add the default image if one is found.
|
||||
if ($fid && ($file = file_load($fid))) {
|
||||
$items[$id][0] = (array) $file + array(
|
||||
'is_default' => TRUE,
|
||||
'alt' => '',
|
||||
'title' => '',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_presave().
|
||||
*/
|
||||
function image_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
file_field_presave($entity_type, $entity, $field, $instance, $langcode, $items);
|
||||
|
||||
// Determine the dimensions if necessary.
|
||||
foreach ($items as &$item) {
|
||||
if (!isset($item['width']) || !isset($item['height'])) {
|
||||
$info = image_get_info(file_load($item['fid'])->uri);
|
||||
|
||||
if (is_array($info)) {
|
||||
$item['width'] = $info['width'];
|
||||
$item['height'] = $info['height'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_insert().
|
||||
*/
|
||||
function image_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
file_field_insert($entity_type, $entity, $field, $instance, $langcode, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_update().
|
||||
*/
|
||||
function image_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
file_field_update($entity_type, $entity, $field, $instance, $langcode, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_delete().
|
||||
*/
|
||||
function image_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
file_field_delete($entity_type, $entity, $field, $instance, $langcode, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_delete_revision().
|
||||
*/
|
||||
function image_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_is_empty().
|
||||
*/
|
||||
function image_field_is_empty($item, $field) {
|
||||
return file_field_is_empty($item, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_info().
|
||||
*/
|
||||
function image_field_widget_info() {
|
||||
return array(
|
||||
'image_image' => array(
|
||||
'label' => t('Image'),
|
||||
'field types' => array('image'),
|
||||
'settings' => array(
|
||||
'progress_indicator' => 'throbber',
|
||||
'preview_image_style' => 'thumbnail',
|
||||
),
|
||||
'behaviors' => array(
|
||||
'multiple values' => FIELD_BEHAVIOR_CUSTOM,
|
||||
'default value' => FIELD_BEHAVIOR_NONE,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_settings_form().
|
||||
*/
|
||||
function image_field_widget_settings_form($field, $instance) {
|
||||
$widget = $instance['widget'];
|
||||
$settings = $widget['settings'];
|
||||
|
||||
// Use the file widget settings form.
|
||||
$form = file_field_widget_settings_form($field, $instance);
|
||||
|
||||
$form['preview_image_style'] = array(
|
||||
'#title' => t('Preview image style'),
|
||||
'#type' => 'select',
|
||||
'#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.'),
|
||||
'#weight' => 15,
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_form().
|
||||
*/
|
||||
function image_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
||||
|
||||
// Add display_field setting to field because file_field_widget_form() assumes it is set.
|
||||
$field['settings']['display_field'] = 0;
|
||||
|
||||
$elements = file_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
|
||||
$settings = $instance['settings'];
|
||||
|
||||
foreach (element_children($elements) as $delta) {
|
||||
// Add upload resolution validation.
|
||||
if ($settings['max_resolution'] || $settings['min_resolution']) {
|
||||
$elements[$delta]['#upload_validators']['file_validate_image_resolution'] = array($settings['max_resolution'], $settings['min_resolution']);
|
||||
}
|
||||
|
||||
// If not using custom extension validation, ensure this is an image.
|
||||
$supported_extensions = array('png', 'gif', 'jpg', 'jpeg');
|
||||
$extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions);
|
||||
$extensions = array_intersect(explode(' ', $extensions), $supported_extensions);
|
||||
$elements[$delta]['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions);
|
||||
$elements[$delta]['#upload_validators']['file_validate_is_image'] = array();
|
||||
|
||||
// Add all extra functionality provided by the image widget.
|
||||
$elements[$delta]['#process'][] = 'image_field_widget_process';
|
||||
}
|
||||
|
||||
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' => field_filter_xss($instance['description']), 'upload_validators' => $elements[0]['#upload_validators']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators']));
|
||||
}
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* An element #process callback for the image_image field type.
|
||||
*
|
||||
* Expands the image_image type to include the alt and title fields.
|
||||
*/
|
||||
function image_field_widget_process($element, &$form_state, $form) {
|
||||
$item = $element['#value'];
|
||||
$item['fid'] = $element['fid']['#value'];
|
||||
|
||||
$instance = field_widget_instance($element, $form_state);
|
||||
|
||||
$settings = $instance['settings'];
|
||||
$widget_settings = $instance['widget']['settings'];
|
||||
|
||||
$element['#theme'] = 'image_widget';
|
||||
$element['#attached']['css'][] = drupal_get_path('module', 'image') . '/image.css';
|
||||
|
||||
// Add the image preview.
|
||||
if ($element['#file'] && $widget_settings['preview_image_style']) {
|
||||
$variables = array(
|
||||
'style_name' => $widget_settings['preview_image_style'],
|
||||
'path' => $element['#file']->uri,
|
||||
);
|
||||
|
||||
// Determine image dimensions.
|
||||
if (isset($element['#value']['width']) && isset($element['#value']['height'])) {
|
||||
$variables['width'] = $element['#value']['width'];
|
||||
$variables['height'] = $element['#value']['height'];
|
||||
}
|
||||
else {
|
||||
$info = image_get_info($element['#file']->uri);
|
||||
|
||||
if (is_array($info)) {
|
||||
$variables['width'] = $info['width'];
|
||||
$variables['height'] = $info['height'];
|
||||
}
|
||||
else {
|
||||
$variables['width'] = $variables['height'] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$element['preview'] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => theme('image_style', $variables),
|
||||
);
|
||||
|
||||
// Store the dimensions in the form so the file doesn't have to be accessed
|
||||
// again. This is important for remote files.
|
||||
$element['width'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => $variables['width'],
|
||||
);
|
||||
$element['height'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => $variables['height'],
|
||||
);
|
||||
}
|
||||
|
||||
// Add the additional alt and title fields.
|
||||
$element['alt'] = array(
|
||||
'#title' => t('Alternate text'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => isset($item['alt']) ? $item['alt'] : '',
|
||||
'#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
|
||||
// @see http://www.gawds.org/show.php?contentid=28
|
||||
'#maxlength' => 512,
|
||||
'#weight' => -2,
|
||||
'#access' => (bool) $item['fid'] && $settings['alt_field'],
|
||||
);
|
||||
$element['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Title'),
|
||||
'#default_value' => isset($item['title']) ? $item['title'] : '',
|
||||
'#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
|
||||
'#maxlength' => 1024,
|
||||
'#weight' => -1,
|
||||
'#access' => (bool) $item['fid'] && $settings['title_field'],
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for an image field widget.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - element: A render element representing the image field widget.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_widget($variables) {
|
||||
$element = $variables['element'];
|
||||
$output = '';
|
||||
$output .= '<div class="image-widget form-managed-file clearfix">';
|
||||
|
||||
if (isset($element['preview'])) {
|
||||
$output .= '<div class="image-preview">';
|
||||
$output .= drupal_render($element['preview']);
|
||||
$output .= '</div>';
|
||||
}
|
||||
|
||||
$output .= '<div class="image-widget-data">';
|
||||
if ($element['fid']['#value'] != 0) {
|
||||
$element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
|
||||
}
|
||||
$output .= drupal_render_children($element);
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function image_field_formatter_info() {
|
||||
$formatters = array(
|
||||
'image' => array(
|
||||
'label' => t('Image'),
|
||||
'field types' => array('image'),
|
||||
'settings' => array('image_style' => '', 'image_link' => ''),
|
||||
),
|
||||
);
|
||||
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_form().
|
||||
*/
|
||||
function image_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
|
||||
$image_styles = image_style_options(FALSE, PASS_THROUGH);
|
||||
$element['image_style'] = array(
|
||||
'#title' => t('Image style'),
|
||||
'#type' => 'select',
|
||||
'#default_value' => $settings['image_style'],
|
||||
'#empty_option' => t('None (original image)'),
|
||||
'#options' => $image_styles,
|
||||
);
|
||||
|
||||
$link_types = array(
|
||||
'content' => t('Content'),
|
||||
'file' => t('File'),
|
||||
);
|
||||
$element['image_link'] = array(
|
||||
'#title' => t('Link image to'),
|
||||
'#type' => 'select',
|
||||
'#default_value' => $settings['image_link'],
|
||||
'#empty_option' => t('Nothing'),
|
||||
'#options' => $link_types,
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_summary().
|
||||
*/
|
||||
function image_field_formatter_settings_summary($field, $instance, $view_mode) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
|
||||
$summary = array();
|
||||
|
||||
$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
|
||||
// their styles in code.
|
||||
if (isset($image_styles[$settings['image_style']])) {
|
||||
$summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
|
||||
}
|
||||
else {
|
||||
$summary[] = t('Original image');
|
||||
}
|
||||
|
||||
$link_types = array(
|
||||
'content' => t('Linked to content'),
|
||||
'file' => t('Linked to file'),
|
||||
);
|
||||
// Display this setting only if image is linked.
|
||||
if (isset($link_types[$settings['image_link']])) {
|
||||
$summary[] = $link_types[$settings['image_link']];
|
||||
}
|
||||
|
||||
return implode('<br />', $summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
// Check if the formatter involves a link.
|
||||
if ($display['settings']['image_link'] == 'content') {
|
||||
$uri = entity_uri($entity_type, $entity);
|
||||
}
|
||||
elseif ($display['settings']['image_link'] == 'file') {
|
||||
$link_file = TRUE;
|
||||
}
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
if (isset($link_file)) {
|
||||
$uri = array(
|
||||
'path' => file_create_url($item['uri']),
|
||||
'options' => array(),
|
||||
);
|
||||
}
|
||||
$element[$delta] = array(
|
||||
'#theme' => 'image_formatter',
|
||||
'#item' => $item,
|
||||
'#image_style' => $display['settings']['image_style'],
|
||||
'#path' => isset($uri) ? $uri : '',
|
||||
);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for an image field formatter.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - item: Associative array of image data, which may include "uri", "alt",
|
||||
* "width", "height", "title" and "attributes".
|
||||
* - image_style: An optional image style.
|
||||
* - path: An array containing the link 'path' and link 'options'.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_image_formatter($variables) {
|
||||
$item = $variables['item'];
|
||||
$image = array(
|
||||
'path' => $item['uri'],
|
||||
);
|
||||
|
||||
if (array_key_exists('alt', $item)) {
|
||||
$image['alt'] = $item['alt'];
|
||||
}
|
||||
|
||||
if (isset($item['attributes'])) {
|
||||
$image['attributes'] = $item['attributes'];
|
||||
}
|
||||
|
||||
if (isset($item['width']) && isset($item['height'])) {
|
||||
$image['width'] = $item['width'];
|
||||
$image['height'] = $item['height'];
|
||||
}
|
||||
|
||||
// Do not output an empty 'title' attribute.
|
||||
if (isset($item['title']) && drupal_strlen($item['title']) > 0) {
|
||||
$image['title'] = $item['title'];
|
||||
}
|
||||
|
||||
if ($variables['image_style']) {
|
||||
$image['style_name'] = $variables['image_style'];
|
||||
$output = theme('image_style', $image);
|
||||
}
|
||||
else {
|
||||
$output = theme('image', $image);
|
||||
}
|
||||
|
||||
// The link path and link options are both optional, but for the options to be
|
||||
// processed, the link path must at least be an empty string.
|
||||
if (isset($variables['path']['path'])) {
|
||||
$path = $variables['path']['path'];
|
||||
$options = isset($variables['path']['options']) ? $variables['path']['options'] : array();
|
||||
// When displaying an image inside a link, the html option must be TRUE.
|
||||
$options['html'] = TRUE;
|
||||
$output = l($output, $path, $options);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
13
drupal7/web/modules/image/image.info
Normal file
13
drupal7/web/modules/image/image.info
Normal file
|
@ -0,0 +1,13 @@
|
|||
name = Image
|
||||
description = Provides image manipulation tools.
|
||||
package = Core
|
||||
version = VERSION
|
||||
core = 7.x
|
||||
dependencies[] = file
|
||||
files[] = image.test
|
||||
configure = admin/config/media/image-styles
|
||||
|
||||
; Information added by Drupal.org packaging script on 2024-03-06
|
||||
version = "7.100"
|
||||
project = "drupal"
|
||||
datestamp = "1709734591"
|
522
drupal7/web/modules/image/image.install
Normal file
522
drupal7/web/modules/image/image.install
Normal file
|
@ -0,0 +1,522 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the image module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function image_install() {
|
||||
// Create the styles directory and ensure it's writable.
|
||||
$directory = file_default_scheme() . '://styles';
|
||||
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function image_uninstall() {
|
||||
// Remove the styles directory and generated images.
|
||||
file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function image_schema() {
|
||||
$schema = array();
|
||||
|
||||
$schema['cache_image'] = drupal_get_schema_unprocessed('system', 'cache');
|
||||
$schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.';
|
||||
|
||||
$schema['image_styles'] = array(
|
||||
'description' => 'Stores configuration options for image styles.',
|
||||
'fields' => array(
|
||||
'isid' => array(
|
||||
'description' => 'The primary identifier for an image style.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'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(
|
||||
'name' => array('name'),
|
||||
),
|
||||
);
|
||||
|
||||
$schema['image_effects'] = array(
|
||||
'description' => 'Stores configuration options for image effects.',
|
||||
'fields' => array(
|
||||
'ieid' => array(
|
||||
'description' => 'The primary identifier for an image effect.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'isid' => array(
|
||||
'description' => 'The {image_styles}.isid for an image style.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'weight' => array(
|
||||
'description' => 'The weight of the effect in the style.',
|
||||
'type' => 'int',
|
||||
'unsigned' => FALSE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'The unique name of the effect to be executed.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'data' => array(
|
||||
'description' => 'The configuration data for the effect.',
|
||||
'type' => 'blob',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('ieid'),
|
||||
'indexes' => array(
|
||||
'isid' => array('isid'),
|
||||
'weight' => array('weight'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'image_style' => array(
|
||||
'table' => 'image_styles',
|
||||
'columns' => array('isid' => 'isid'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_schema().
|
||||
*/
|
||||
function image_field_schema($field) {
|
||||
return array(
|
||||
'columns' => array(
|
||||
'fid' => array(
|
||||
'description' => 'The {file_managed}.fid being referenced in this field.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'alt' => array(
|
||||
'description' => "Alternative image text, for the image's 'alt' attribute.",
|
||||
'type' => 'varchar',
|
||||
'length' => 512,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => "Image title text, for the image's 'title' attribute.",
|
||||
'type' => 'varchar',
|
||||
'length' => 1024,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'width' => array(
|
||||
'description' => 'The width of the image in pixels.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'height' => array(
|
||||
'description' => 'The height of the image in pixels.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'fid' => array('fid'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'fid' => array(
|
||||
'table' => 'file_managed',
|
||||
'columns' => array('fid' => 'fid'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_dependencies().
|
||||
*/
|
||||
function image_update_dependencies() {
|
||||
$dependencies['image'][7002] = array(
|
||||
// Image update 7002 uses field API functions, so must run after
|
||||
// Field API has been enabled.
|
||||
'system' => 7020,
|
||||
);
|
||||
return $dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the schema for users upgrading from the contributed module.
|
||||
*/
|
||||
function image_update_7000() {
|
||||
if (!db_table_exists('image_styles')) {
|
||||
$schema = array();
|
||||
|
||||
$schema['cache_image'] = system_schema_cache_7054();
|
||||
$schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.';
|
||||
|
||||
$schema['image_styles'] = array(
|
||||
'description' => 'Stores configuration options for image styles.',
|
||||
'fields' => array(
|
||||
'isid' => array(
|
||||
'description' => 'The primary identifier for an image style.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'The style name.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('isid'),
|
||||
'unique keys' => array(
|
||||
'name' => array('name'),
|
||||
),
|
||||
);
|
||||
|
||||
$schema['image_effects'] = array(
|
||||
'description' => 'Stores configuration options for image effects.',
|
||||
'fields' => array(
|
||||
'ieid' => array(
|
||||
'description' => 'The primary identifier for an image effect.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'isid' => array(
|
||||
'description' => 'The {image_styles}.isid for an image style.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'weight' => array(
|
||||
'description' => 'The weight of the effect in the style.',
|
||||
'type' => 'int',
|
||||
'unsigned' => FALSE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'The unique name of the effect to be executed.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'data' => array(
|
||||
'description' => 'The configuration data for the effect.',
|
||||
'type' => 'blob',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('ieid'),
|
||||
'indexes' => array(
|
||||
'isid' => array('isid'),
|
||||
'weight' => array('weight'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'image_style' => array(
|
||||
'table' => 'image_styles',
|
||||
'columns' => array('isid' => 'isid'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
db_create_table('cache_image', $schema['cache_image']);
|
||||
db_create_table('image_styles', $schema['image_styles']);
|
||||
db_create_table('image_effects', $schema['image_effects']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @addtogroup updates-7.x-extra
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Rename possibly misnamed {image_effect} table to {image_effects}.
|
||||
*/
|
||||
function image_update_7001() {
|
||||
// Due to a bug in earlier versions of image_update_7000() it is possible
|
||||
// to end up with an {image_effect} table where there should be an
|
||||
// {image_effects} table.
|
||||
if (!db_table_exists('image_effects') && db_table_exists('image_effect')) {
|
||||
db_rename_table('image_effect', 'image_effects');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add width and height columns to a specific table.
|
||||
*
|
||||
* @param $table
|
||||
* The name of the database table to be updated.
|
||||
* @param $columns
|
||||
* Keyed array of columns this table is supposed to have.
|
||||
*/
|
||||
function _image_update_7002_add_columns($table, $field_name) {
|
||||
$spec = array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
);
|
||||
|
||||
$spec['description'] = 'The width of the image in pixels.';
|
||||
db_add_field($table, $field_name . '_width', $spec);
|
||||
|
||||
$spec['description'] = 'The height of the image in pixels.';
|
||||
db_add_field($table, $field_name . '_height', $spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate image dimensions in a specific table.
|
||||
*
|
||||
* @param $table
|
||||
* The name of the database table to be updated.
|
||||
* @param $columns
|
||||
* Keyed array of columns this table is supposed to have.
|
||||
* @param $last_fid
|
||||
* The fid of the last image to have been processed.
|
||||
*
|
||||
* @return
|
||||
* The number of images that were processed.
|
||||
*/
|
||||
function _image_update_7002_populate_dimensions($table, $field_name, &$last_fid) {
|
||||
// Define how many images to process per pass.
|
||||
$images_per_pass = 100;
|
||||
|
||||
// Query the database for fid / URI pairs.
|
||||
$query = db_select($table, NULL, array('fetch' => PDO::FETCH_ASSOC));
|
||||
$query->join('file_managed', NULL, $table . '.' . $field_name . '_fid = file_managed.fid');
|
||||
|
||||
if ($last_fid) {
|
||||
$query->condition('file_managed.fid', $last_fid, '>');
|
||||
}
|
||||
|
||||
$result = $query->fields('file_managed', array('fid', 'uri'))
|
||||
->orderBy('file_managed.fid')
|
||||
->range(0, $images_per_pass)
|
||||
->execute();
|
||||
|
||||
$count = 0;
|
||||
foreach ($result as $file) {
|
||||
$count++;
|
||||
$info = image_get_info($file['uri']);
|
||||
|
||||
if (is_array($info)) {
|
||||
db_update($table)
|
||||
->fields(array(
|
||||
$field_name . '_width' => $info['width'],
|
||||
$field_name . '_height' => $info['height'],
|
||||
))
|
||||
->condition($field_name . '_fid', $file['fid'])
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
// If less than the requested number of rows were returned then this table
|
||||
// has been fully processed.
|
||||
$last_fid = ($count < $images_per_pass) ? NULL : $file['fid'];
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add width and height columns to image field schema and populate.
|
||||
*/
|
||||
function image_update_7002(array &$sandbox) {
|
||||
if (empty($sandbox)) {
|
||||
// Setup the sandbox.
|
||||
$sandbox = array(
|
||||
'tables' => array(),
|
||||
'total' => 0,
|
||||
'processed' => 0,
|
||||
'last_fid' => NULL,
|
||||
);
|
||||
|
||||
$fields = _update_7000_field_read_fields(array(
|
||||
'module' => 'image',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'deleted' => 0,
|
||||
));
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$tables = array(
|
||||
_field_sql_storage_tablename($field),
|
||||
_field_sql_storage_revision_tablename($field),
|
||||
);
|
||||
foreach ($tables as $table) {
|
||||
// Add the width and height columns to the table.
|
||||
_image_update_7002_add_columns($table, $field['field_name']);
|
||||
|
||||
// How many rows need dimensions populated?
|
||||
$count = db_select($table)->countQuery()->execute()->fetchField();
|
||||
|
||||
if (!$count) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sandbox['total'] += $count;
|
||||
$sandbox['tables'][$table] = $field['field_name'];
|
||||
}
|
||||
}
|
||||
|
||||
// If no tables need rows populated with dimensions then we are done.
|
||||
if (empty($sandbox['tables'])) {
|
||||
$sandbox = array();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Process the table at the top of the list.
|
||||
$keys = array_keys($sandbox['tables']);
|
||||
$table = reset($keys);
|
||||
$sandbox['processed'] += _image_update_7002_populate_dimensions($table, $sandbox['tables'][$table], $sandbox['last_fid']);
|
||||
|
||||
// Has the table been fully processed?
|
||||
if (!$sandbox['last_fid']) {
|
||||
unset($sandbox['tables'][$table]);
|
||||
}
|
||||
|
||||
$sandbox['#finished'] = count($sandbox['tables']) ? ($sandbox['processed'] / $sandbox['total']) : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the variables that set alt and title length since they were not
|
||||
* used for database column size and could cause PDO exceptions.
|
||||
*/
|
||||
function image_update_7003() {
|
||||
variable_del('image_alt_length');
|
||||
variable_del('image_title_length');
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a large setting (512 and 1024 characters) for the length of the image alt
|
||||
* and title fields.
|
||||
*/
|
||||
function image_update_7004() {
|
||||
$alt_spec = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 512,
|
||||
'not null' => FALSE,
|
||||
);
|
||||
|
||||
$title_spec = array(
|
||||
'type' => 'varchar',
|
||||
'length' => 1024,
|
||||
'not null' => FALSE,
|
||||
);
|
||||
|
||||
$fields = _update_7000_field_read_fields(array(
|
||||
'module' => 'image',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
));
|
||||
|
||||
foreach ($fields as $field_name => $field) {
|
||||
$tables = array(
|
||||
_field_sql_storage_tablename($field),
|
||||
_field_sql_storage_revision_tablename($field),
|
||||
);
|
||||
$alt_column = $field['field_name'] . '_alt';
|
||||
$title_column = $field['field_name'] . '_title';
|
||||
foreach ($tables as $table) {
|
||||
db_change_field($table, $alt_column, $alt_column, $alt_spec);
|
||||
db_change_field($table, $title_column, $title_column, $title_spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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".
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_requirements() to check the PHP GD Library.
|
||||
*
|
||||
* @param $phase
|
||||
*/
|
||||
function image_requirements($phase) {
|
||||
$requirements = array();
|
||||
|
||||
if ($phase == 'runtime') {
|
||||
// Check for the PHP GD library.
|
||||
if (function_exists('imagegd2')) {
|
||||
$info = gd_info();
|
||||
$requirements['image_gd'] = array(
|
||||
'value' => $info['GD Version'],
|
||||
);
|
||||
|
||||
// Check for filter and rotate support.
|
||||
if (function_exists('imagefilter') && function_exists('imagerotate')) {
|
||||
$requirements['image_gd']['severity'] = REQUIREMENT_OK;
|
||||
}
|
||||
else {
|
||||
$requirements['image_gd']['severity'] = REQUIREMENT_WARNING;
|
||||
$requirements['image_gd']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See <a href="http://www.php.net/manual/book.image.php">the PHP manual</a>.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$requirements['image_gd'] = array(
|
||||
'value' => t('Not installed'),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
'description' => t('The GD library for PHP is missing or outdated. Check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array('@url' => 'http://www.php.net/manual/book.image.php')),
|
||||
);
|
||||
}
|
||||
$requirements['image_gd']['title'] = t('GD library rotate and desaturate effects');
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
}
|
1494
drupal7/web/modules/image/image.module
Normal file
1494
drupal7/web/modules/image/image.module
Normal file
File diff suppressed because it is too large
Load diff
2267
drupal7/web/modules/image/image.test
Normal file
2267
drupal7/web/modules/image/image.test
Normal file
File diff suppressed because it is too large
Load diff
BIN
drupal7/web/modules/image/sample.png
Normal file
BIN
drupal7/web/modules/image/sample.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 164 KiB |
|
@ -0,0 +1,13 @@
|
|||
name = Image Styles test
|
||||
description = Provides additional hook implementations for testing Image Styles functionality.
|
||||
package = Core
|
||||
version = VERSION
|
||||
core = 7.x
|
||||
files[] = image_module_styles_test.module
|
||||
dependencies[] = image_module_test
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2024-03-06
|
||||
version = "7.100"
|
||||
project = "drupal"
|
||||
datestamp = "1709734591"
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides additional Image module hook implementations for testing purposes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_image_default_styles().
|
||||
*/
|
||||
function image_module_styles_test_image_default_styles() {
|
||||
$styles = array();
|
||||
|
||||
$styles['test_image_style'] = array(
|
||||
'label' => 'Test Image Style',
|
||||
'effects' => array(
|
||||
array(
|
||||
'name' => 'image_scale',
|
||||
'data' => array('width' => 100, 'height' => 100, 'upscale' => 1),
|
||||
'weight' => 0,
|
||||
),
|
||||
array(
|
||||
'name' => 'image_module_test_null',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return $styles;
|
||||
}
|
12
drupal7/web/modules/image/tests/image_module_test.info
Normal file
12
drupal7/web/modules/image/tests/image_module_test.info
Normal file
|
@ -0,0 +1,12 @@
|
|||
name = Image test
|
||||
description = Provides hook implementations for testing Image module functionality.
|
||||
package = Core
|
||||
version = VERSION
|
||||
core = 7.x
|
||||
files[] = image_module_test.module
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2024-03-06
|
||||
version = "7.100"
|
||||
project = "drupal"
|
||||
datestamp = "1709734591"
|
54
drupal7/web/modules/image/tests/image_module_test.module
Normal file
54
drupal7/web/modules/image/tests/image_module_test.module
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides Image module hook implementations for testing purposes.
|
||||
*/
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_image_effect_info().
|
||||
*/
|
||||
function image_module_test_image_effect_info() {
|
||||
$effects = array(
|
||||
'image_module_test_null' => array(
|
||||
'label' => 'image_module_test_null',
|
||||
'effect callback' => 'image_module_test_null_effect',
|
||||
),
|
||||
);
|
||||
|
||||
return $effects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image effect callback; Null.
|
||||
*
|
||||
* @param $image
|
||||
* An image object returned by image_load().
|
||||
* @param $data
|
||||
* An array with no attributes.
|
||||
*
|
||||
* @return
|
||||
* TRUE
|
||||
*/
|
||||
function image_module_test_null_effect(&$image, array $data) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_image_effect_info_alter().
|
||||
*
|
||||
* Used to keep a count of cache misses in image_effect_definitions().
|
||||
*/
|
||||
function image_module_test_image_effect_info_alter(&$effects) {
|
||||
$image_effects_definition_called = &drupal_static(__FUNCTION__, 0);
|
||||
$image_effects_definition_called++;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue