added missing module fixer and updated imagecache_actions

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-21 17:06:08 +01:00
parent 3f7e130321
commit 0bcc558ed5
83 changed files with 6386 additions and 2517 deletions

View File

@@ -21,9 +21,8 @@ Personally, I prefer the imagemagick toolkit:
you will see what I mean.
- It does not execute in the PHP memory space, so is not restricted by the
memory_limit PHP setting.
- The GD toolkit will, at least on my Windows configuration, keep the font file
- The GD toolkit will, at least on my Windows configuration, keep font files
open after a text operation, so you cannot delete, move or rename it anymore.
- This module does a better job with Imagemagick (see below).
Installing
@@ -59,10 +58,11 @@ record so by changing $image->info['width'] and/or $image->info['height'].
General
-------
To ease your task, this effect makes some information regarding the image being
processed available in 2 variables: $image and $image_context. These variables
are readily available in your snippet.
processed available in a number of variables: $image, $image_context,
$image_style, and $image_effect_id. These variables are readily available in
your snippet.
$image is an associative array containing:
$image is an object containing the following properties:
- source: string, the source of the image, e.g. public://photo.jpg
- info: array, example data:
- width (int) 180
@@ -113,6 +113,18 @@ $image_context is an associative array containing:
- title (string) ...
- ...
$image_style is an associative array containing the current image style being
processed. It ocntians a.o.:
- isid: the unique image style id
- name: machine name.
- label: Human readable name.
- effects: An array with the effects of this image style, ordered in the way
they should be applied.
$image_effect_id is an int containng the unique id of the current image effect
being applied. This can be used to look the current image effect up in the
$image_style array.
Of course there are many other possible useful globals. Think of:
- base_url
- base_path
@@ -144,3 +156,41 @@ foreach ($referring_entities as $field_name => $field_referring_entities) {
}
}
?>
"Dynamic" parameters
--------------------
Thee are many requests for adding token support or allowing for dynamic
parameters in another way. However, the current image style processing does not
easily allow for this. But for these cases we have the custom action to our
rescue. It is quite easy to:
- Create you own array of parameters.
- Call the effect callback yourself
Exanple, calling the watermark/canvas overlay effect:
<?php
$data = array(
'xpos' => 'center',
'ypos' => 'center',
'alpha' => '100',
'scale' => '',
'path' => 'module://imagecache_actions/tests/black-ribbon.gif',
);
return canvasactions_file2canvas_effect($image, $data);
?>
Or, to be on the safe side with effect info altering:
<?php
$definition = image_effect_definition_load('canvasactions_file2canvas');
$callback = $definition['effect callback'];
if (function_exists($callback)) {
$data = array(
'xpos' => 'center',
'ypos' => 'center',
'alpha' => '100',
'scale' => '',
'path' => 'module://imagecache_actions/tests/black-ribbon.gif',
);
return $callback($image, $data);
}
return FALSE;
?>

View File

@@ -1,17 +1,14 @@
name = Imagecache Custom Actions
description = Allow direct PHP code manipulation of imagecache images.
description = Provides the custom and subroutine image effects.
package = Media
core = 7.x
dependencies[] = imagecache_actions
dependencies[] = image
files[] = imagecache_customactions.install
files[] = imagecache_customactions.module
; Information added by drupal.org packaging script on 2012-12-04
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2018-03-20
version = "7.x-1.9"
core = "7.x"
project = "imagecache_actions"
datestamp = "1354653754"
datestamp = "1521550387"

View File

@@ -1,8 +1,8 @@
<?php
/**
* Rename 'text' to 'php' in custom action effect data
* Rename 'text' to 'php' in custom action effect data.
*/
function imagecache_customactions_update_7100(&$sandbox) {
function imagecache_customactions_update_7100(/*&$sandbox*/) {
$effects = db_select('image_effects')
->fields('image_effects')
->condition('name', 'imagecache_customactions', '=')

View File

@@ -1,57 +1,82 @@
<?php
/**
* @file Allow advanced users to code their own PHP image manipulation routines
* as part of imagecache processing.
* @file Allows advanced users to code their own PHP image manipulation routines
* as part of image style processing.
*
* @author Originally contributed by crea http://drupal.org/node/325103#comment-
* @author Originally contributed by crea https://drupal.org/node/325103#comment-
* 1076011
*
* @author merged into imagecache_actions by dman http://coders.co.nz
*
* Needs review - currently a security risk etc
* custom action effect:
* @todo: add description field that editors can use to define their own summary?
* @todo: add form field asking if dimensions stay the same (or if the new dimensions are known).
* subroutine effect:
* @todo: use isid to allow for image style renaming, but also use name to allow export and import (features)
*/
/**
* Implements hook_image_effect_info.
* Implements hook_image_effect_info().
*
* @return array
* Defines information about the supported effects.
*/
function imagecache_customactions_image_effect_info() {
$effects = array();
// @todo: implement summary theme callback
$effects['imagecache_customactions'] = array(
'label' => t('Custom action'),
'help' => t('Runs custom PHP code.'),
'effect callback' => 'imagecache_customactions_image',
'effect callback' => 'imagecache_customactions_effect',
'dimensions callback' => 'imagecache_customactions_dimensions',
'form callback' => 'imagecache_customactions_form',
'summary theme' => 'imagecache_customactions_summary',
);
$effects['imagecache_subroutine'] = array(
'label' => t('Subroutine'),
'help' => t('Runs another defined preset on the image.'),
'effect callback' => 'imagecache_subroutine_image',
'effect callback' => 'imagecache_subroutine_effect',
'dimensions callback' => 'imagecache_subroutine_dimensions',
'form callback' => 'imagecache_subroutine_form',
'summary theme' => 'imagecache_subroutine_summary',
);
return $effects;
}
/**
* Implements hook_image_style_flush.
* Implements hook_theme().
*
* This hook checks if the image style that is being flushed is used in an
* subroutine effect. If so, the style that contains the subroutine effect,
* should be flushed as well as the flushed style was probably changed.
* Registers theme functions for the effect summaries.
*/
function imagecache_customactions_theme() {
return array(
'imagecache_customactions_summary' => array(
'variables' => array('data' => NULL),
),
'imagecache_subroutine_summary' => array(
'variables' => array('data' => NULL),
),
);
}
/**
* Implements hook_image_style_flush().
*
* This hook checks if the image style that is being flushed is used in a
* subroutine effect. If so, the style that contains the subroutine effect
* should be flushed as well.
*
* This may lead to recursive calls to image_style_flush() and thus to this
* hook. Without loops in styles that call each other as subroutine, this
* recursion will always end.
*
* @param array $flushed_style
* The image style that is being flushed.
*/
function imagecache_customactions_image_style_flush($flushed_style) {
function imagecache_customactions_image_style_flush(/*array*/ $flushed_style) {
$styles = image_styles();
foreach ($styles as $style) {
if ($style['name'] !== $flushed_style['name']) {
@@ -67,44 +92,34 @@ function imagecache_customactions_image_style_flush($flushed_style) {
}
/**
* @deprecated replaced by summary theme callback
* Implementation of theme_hook() for imagecache_customactions.module
*/
function imagecache_customactions_theme() {
return array(
'imagecache_subroutine' => array(
'render element' => 'element',
),
);
}
/**
* Implements hook_form().
* Image effect form callback for the custom action effect.
*
* Note that this is not a complete form, it only contains the portion of the
* form for configuring the effect options. Therefore it does not not need to
* include metadata about the effect, nor a submit button.
*
* @param array $data
* Array of settings for this action.
* The current configuration for this image effect.
*
* @return array
* A form definition.
* The form definition for this effect.
*/
function imagecache_customactions_form($data) {
function imagecache_customactions_form(array $data) {
// Add defaults.
$data += array('php' => 'return TRUE;');
// Note: we also need to check for the existence of the module: admin has
// all rights, so user_acccess(...) returns TRUE even if the module is not
// enabled and the permission does not exist.
$allow_dynamic = user_access('use PHP for settings') && module_exists('php');
$allow_php = module_exists('php') && user_access('use PHP for settings');
// @todo: for imagemagick, the PHP code should add a set of commands to the
// ops aray of $image. Document this in description.
$form = array(
'php' => array(
'#type' => 'textarea',
'#rows' => 10,
'#rows' => 12,
'#title' => t('PHP code'),
'#default_value' => $data['php'],
'#disabled' => !$allow_dynamic,
'#disabled' => !$allow_php,
'#description' => t("<p>A piece of PHP code that modifies the image.
It should return a boolean indicating success or failure.
You will need the '%use_php' permission, defined by the 'PHP filter' module.
@@ -117,15 +132,30 @@ See the help for an extensive explanation of the possibilities.</p>",
}
/**
* Implements hook_image().
* Implements theme_hook() for the custom action effect summary.
*
* @param object $image
* param array $variables
* An associative array containing:
* - data: The current configuration for this image effect.
*
* @return string
* The HTML for the summary of this image effect.
* @ingroup themeable
*/
function theme_imagecache_customactions_summary(/*array $variables*/) {
return 'Custom PHP code';
}
/**
* Image effect callback for the custom action effect.
*
* @param stdClass $image
* @param array $data
*
* @return bool
* @return boolean
* true on success, false otherwise.
*/
function imagecache_customactions_image($image, $data) {
// Check that the PHP filter module is enabled.
function imagecache_customactions_effect(stdClass $image, array $data) {
$result = module_exists('php');
if ($result) {
// Get context about the image.
@@ -133,10 +163,17 @@ function imagecache_customactions_image($image, $data) {
$GLOBALS['image_context'] = imagecache_actions_get_image_context($image, $data);
$GLOBALS['image'] = $image;
// Get (non-alterable) context about the image style and image effect.
$execution_info = imagecache_actions_get_image_effect_context();
$GLOBALS['image_style'] = $execution_info['image_style'];
$GLOBALS['image_effect_id'] = $execution_info['image_effect_id'];
$result = php_eval('<' . '?php global $image, $image_context; ' . $data['php'] . ' ?' . '>');
// php_eval returns '1' if the snippet returns true.
$result = $result === '1';
unset($GLOBALS['image_effect_id']);
unset($GLOBALS['image_style']);
unset($GLOBALS['image']);
unset($GLOBALS['image_context']);
}
@@ -150,94 +187,102 @@ function imagecache_customactions_image($image, $data) {
}
/**
* Image dimensions callback; Custom action.
* Image dimensions callback for the custom action effect.
*
* @param array $dimensions
* Dimensions to be modified - an array with components width and height, in
* pixels.
* @param array $data
* An array with the effect options.
* Dimensions to be modified - an associative array containing the items
* 'width' and 'height' (in pixels).
* param array $data
* An associative array containing the effect data.
*/
function imagecache_customactions_dimensions(array &$dimensions, array $data) {
// @todo: add form field asking if dimensions stay the same (or if they know
// the new dimesions).
function imagecache_customactions_dimensions(array &$dimensions/*, array $data*/) {
$dimensions['width'] = NULL;
$dimensions['height'] = NULL;
}
/**
* @todo change into summary theme callback
* Implementation of theme_hook() for imagecache_ui.module
*/
function theme_imagecache_customactions($element) {
// TODO: Should this theme imagecache_customactions be declared in hook_theme()?
$data = $element['#value'];
return "<em><strong>" . $data['text'] . "</strong></em>";
}
/**
* Subroutine - an imagecache action that just calls another one.
*
* Contributed by Alan D
* http://drupal.org/node/618784
* https://drupal.org/node/618784
*
* Reworked into customactions by dman 2010-07
*/
/**
* Config form for this preset.
*
* Implementation of imagecache_hook_form()
* Image effect form callback for the subroutine effect.
*
* @param array $data
* The effect data for this effect.
* The current configuration for this image effect.
*
* @return array
* The form definition.
* The form definition for this effect.
*/
function imagecache_subroutine_form($data) {
$data = (array) $data;
$form = array();
function imagecache_subroutine_form(array $data) {
// Add defaults.
$data += array('subroutine_presetname' => '');
// List available presets
// @todo: use image_style_options and remove current style?
$presets = array();
foreach (image_styles(TRUE) as $preset) {
$presets[$preset['name']] = $preset['name'];
}
// List available image styles.
// The PASS_THROUGH parameter is new as of D7.23, and is added here to prevent
// image_style_options() from double-encoding the human-readable image style
// name, since the form API will already sanitize options in a select list.
$styles = image_style_options(TRUE, PASS_THROUGH);
//@todo: unset the current style to prevent obvious recursion.
$form = array();
$form['subroutine_presetname'] = array(
'#type' => 'select',
'#title' => t('Preset to call'),
'#title' => t('Image style to call'),
'#default_value' => $data['subroutine_presetname'],
'#options' => $presets,
'#options' => $styles,
'#required' => TRUE,
);
return $form;
}
/**
* Actually invoke the action - which means just handing off to the named real
* preset to do the job.
* Implements theme_hook() for the subroutine effect summary.
*
* Implementation of hook_image()
* @param array $variables
* An associative array containing:
* - data: The current configuration for this image effect.
*
* @param object $image
* @param array $data
*
* @return bool
* @return string
* The HTML for the summary of this image effect.
* @ingroup themeable
*/
function imagecache_subroutine_image($image, $data) {
if ($preset = image_style_load($data['subroutine_presetname'])) {
foreach ($preset['effects'] as $effect) {
image_effect_apply($image, $effect);
}
}
return TRUE;
function theme_imagecache_subroutine_summary(array $variables) {
$data = $variables['data'];
module_load_include('inc', 'imagecache_actions', 'utility');
$label = imagecache_actions_get_style_label($data['subroutine_presetname']);
return t('Apply image style %label', array('%label' => $label));
}
/**
* Image dimensions callback; Subroutine.
* Image effect callback for the subroutine effect.
*
* @param stdClass $image
* @param array $data
*
* @return boolean
* true on success, false otherwise.
*/
function imagecache_subroutine_effect(stdClass $image, array $data) {
$result = FALSE;
if ($style = image_style_load($data['subroutine_presetname'])) {
$result = TRUE;
foreach ($style['effects'] as $effect) {
$result = $result && image_effect_apply($image, $effect);
}
}
return $result;
}
/**
* Image dimensions callback for the subroutine effect.
*
* @param array $dimensions
* Dimensions to be modified - an array with components width and height, in
@@ -246,25 +291,6 @@ function imagecache_subroutine_image($image, $data) {
* An array with the effect options.
*/
function imagecache_subroutine_dimensions(array &$dimensions, array $data) {
// @todo: dimensions
// @todo: call dimensions callback on subroutine style.
$dimensions['width'] = NULL;
$dimensions['height'] = NULL;
}
/**
* @todo change into summary theme callback
* This lets the user see what parameters were selected for the action
*/
function theme_imagecache_subroutine($variables) {
// @todo: better decsription, do not use internal id's, imagecache_preset_by_name does not exist: fatal error?
$element = $variables['element'];
$data = $element['#value'];
if ($preset = imagecache_preset_by_name($data['subroutine_presetname'])) {
return t('%name (pid: !presetid)', array(
'%name' => $preset['presetname'],
'!presetid' => $preset['presetid']
));
}
return t('<span class="error">Invalid reference. The referenced preset may have been deleted!</span>');
// Let the subroutine transform the dimensions.
image_style_transform_dimensions($data['subroutine_presetname'], $dimensions);
}