updated i18n i10n_update workflwo imachecache_actions

This commit is contained in:
2020-06-23 12:41:21 +02:00
parent 8c39ab6f4a
commit 092758ecb0
134 changed files with 2894 additions and 1205 deletions
@@ -143,7 +143,7 @@ function imagecache_actions_get_style_label($style_name) {
}
/**
* Return an array with context information about the image.
* Returns an array with context information about the image.
*
* This information is called by effects that need contextual information or
* that allow custom PHP:
@@ -192,27 +192,33 @@ function imagecache_actions_get_image_context($image, $data) {
+ file_get_file_references($managed_file, NULL, FIELD_LOAD_CURRENT, 'file');
if ($references) {
// Load referring entities.
// Load referring entities., keep track of 1st reference separately.
$entity_type_first = '';
$field_name_first = '';
foreach ($references as $field_name => $field_references) {
foreach ($field_references as $entity_type => $entity_stubs) {
$image_context['referring_entities'][$field_name][$entity_type] = entity_load($entity_type, array_keys($entity_stubs));
$entities = entity_load($entity_type, array_keys($entity_stubs));
if (!empty($entities)) {
$image_context['referring_entities'][$field_name][$entity_type] = $entities;
// Make it easy to access the '1st' entity and its referring image
// field, part 1: entity.
if (empty($entity_type_first)) {
$entity_type_first = $entity_type;
$field_name_first = $field_name;
$image_context['entity'] = reset($entities);
}
}
}
}
// Make it easy to access the '1st' entity and its referring image field.
reset($image_context['referring_entities']);
list($field_name, $field_references) = each($image_context['referring_entities']);
reset($field_references);
list($entity_type, $entities) = each($field_references);
reset($entities);
list(, $image_context['entity']) = each($entities);
// Make it easy to access the '1st' entity and its referring image field,
// part 2: image field.
/** @var array|false $image_field */
$image_field = field_get_items($entity_type, $image_context['entity'], $field_name);
$image_field = field_get_items($entity_type_first, $image_context['entity'], $field_name_first);
if ($image_field) {
// Get referring item.
foreach ($image_field as $image_field_value) {
if ($image_field_value['fid'] === $managed_file->fid) {
// @todo: file_field as well or just ignore the type of field?
$image_context['image_field'] = $image_field_value;
break;
}
@@ -224,6 +230,53 @@ function imagecache_actions_get_image_context($image, $data) {
return $image_context;
}
/**
* Returns information about the context, image style and image effect id, of
* the current image effect.
*
* Note that this information is not alterable, that is, it will not have any
* effect on the rest of the derivative image generation process including its
* subsequent effects.
*
* This information is called by effects that may need contextual information or
* that allow custom PHP:
* - Custom action.
* - Text from image alt or title.
* - Text with tokens.
* - Text from PHP code.
*
* This information is fetched by traversing the backtrace, looking for known
* functions that have the image style or effect as argument..
*
* @return array
* Array with keys 'image_style' and 'image_effect_id' pointing to the current
* image style (array) resp. image effect id (int).
*/
function imagecache_actions_get_image_effect_context() {
$result = array();
$backtrace = debug_backtrace();
foreach ($backtrace as $function_call) {
if ($function_call['function'] && $function_call['function'] === 'image_effect_apply') {
$result['image_effect_id'] = isset($function_call['args'][1]['ieid']) ? $function_call['args'][1]['ieid'] : NULL;
}
else if ($function_call['function'] && $function_call['function'] === 'image_style_create_derivative') {
$result['image_style'] = isset($function_call['args'][0]) ? $function_call['args'][0] : NULL;
}
if (count($result) === 2) {
break;
}
}
$result += array(
'image_effect_id' => NULL,
'image_style' => NULL,
);
return $result;
}
/**
* Given two imageapi objects with dimensions, and some positioning values,
* calculate a new x,y for the layer to be placed at.
@@ -369,11 +422,14 @@ function imagecache_actions_calculate_offset($keyword, $value, $base_size, $laye
}
// Handle % values.
if (substr($value, strlen($value) - 1, 1) == '%') {
$value = intval($value / 100 * $base_size);
if (substr($value, -1) === '%') {
// Explicitly convert $value to prevent warnings in PHP 7.1.
$value = intval((int) $value / 100 * $base_size);
$offset = -1 * ($layer_size / 2);
}
$value = $base + ($direction * $value);
// $value may contain 'px' at the end: explicitly convert to prevent warnings
// in PHP 7.1.
$value = $base + ($direction * (int) $value);
// Add any extra offset to position the item.
return $value + $offset;
@@ -389,16 +445,16 @@ function imagecache_actions_calculate_offset($keyword, $value, $base_size, $laye
* A string specifing an RGB color in the formats:
* '#ABC','ABC','#ABCD','ABCD','#AABBCC','AABBCC','#AABBCCDD','AABBCCDD'
*
* @return array
* @return array|false
* An array with four elements for red, green, blue, and alpha.
*/
function imagecache_actions_hex2rgba($hex) {
$hex = ltrim($hex, '#');
if (preg_match('/^[0-9a-f]{3}$/i', $hex)) {
// 'FA3' is the same as 'FFAA33' so r=FF, g=AA, b=33
$r = str_repeat($hex{0}, 2);
$g = str_repeat($hex{1}, 2);
$b = str_repeat($hex{2}, 2);
$r = str_repeat($hex[0], 2);
$g = str_repeat($hex[1], 2);
$b = str_repeat($hex[2], 2);
$a = '0';
}
elseif (preg_match('/^[0-9a-f]{6}$/i', $hex)) {
@@ -412,10 +468,10 @@ function imagecache_actions_hex2rgba($hex) {
}
elseif (preg_match('/^[0-9a-f]{4}$/i', $hex)) {
// 'FA37' is the same as 'FFAA3377' so r=FF, g=AA, b=33, a=77
$r = str_repeat($hex{0}, 2);
$g = str_repeat($hex{1}, 2);
$b = str_repeat($hex{2}, 2);
$a = str_repeat($hex{3}, 2);
$r = str_repeat($hex[0], 2);
$g = str_repeat($hex[1], 2);
$b = str_repeat($hex[2], 2);
$a = str_repeat($hex[3], 2);
}
else {
// error: invalid hex string, @todo: set form error.
@@ -468,12 +524,13 @@ function imagecache_actions_keyword_filter($value, $base_size, $layer_size) {
* Computes a length based on a length specification and an actual length.
*
* Examples:
* (50, 400) returns 50; (50%, 400) returns 200;
* (50, 400) returns 50; (50px, 400) returns 50; (50%, 400) returns 200;
* (50, null) returns 50; (50%, null) returns null;
* (null, null) returns null; (null, 100) returns null.
*
* @param string|null $length_specification
* The length specification. An integer constant or a % specification.
* The length specification. An integer constant optionally followed by 'px'
* or '%'.
* @param int|null $current_length
* The current length. May be null.
*
@@ -483,5 +540,9 @@ function imagecache_actions_percent_filter($length_specification, $current_lengt
if (strpos($length_specification, '%') !== FALSE) {
$length_specification = $current_length !== NULL ? str_replace('%', '', $length_specification) * 0.01 * $current_length : NULL;
}
else {
// Strips 'px' if available.
$length_specification = (int) $length_specification;
}
return $length_specification;
}