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

@@ -1,5 +1,4 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.

View File

@@ -1,5 +1,4 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.

View File

@@ -1,15 +1,16 @@
name = Imagecache_actions Test Suite
description = Displays a collection of demo presets.
description = Displays a collection of demo image styles.
package = Media
core = 7.x
dependencies[] = imagecache_actions
dependencies[] = system_stream_wrapper
features[image][] = 'corners_combo'
; 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,16 +1,12 @@
<?php
/**
* @file An admin-only utility to demo and check a number of imagecache presets
* and actions.
*
* It provides a tab in Home > Administer > Site Building > Imagecache
*
* that lists a whole bunch of sample presets.
*
* @author dman http://coders.co.nz/
*
* @file An admin-only utility to test image styles and effects.
*
* It provides a page Test Suite in Administration > Configuration > Media >
* Image Styles (admin/config/media/image-styles/testsuite) that displays
* results for all existing image styles for all toolkits as well as for a set
* of test image styles defined in the various modules.
*/
include_once('imagecache_testsuite.features.inc');
@@ -22,8 +18,8 @@ function imagecache_testsuite_menu() {
$items = array();
$items['admin/config/media/image-styles/testsuite'] = array(
'title' => 'Test Suite',
'page callback' => 'imagecache_testsuite_generate',
'access arguments' => array('administer imagecache'),
'page callback' => 'imagecache_testsuite_page',
'access arguments' => array('administer image styles'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
@@ -31,13 +27,13 @@ function imagecache_testsuite_menu() {
'title' => 'Test Suite Image',
'page callback' => 'imagecache_testsuite_generate',
'page arguments' => array(5, 6),
'access arguments' => array('administer imagecache'),
'access arguments' => array('administer image styles'),
'type' => MENU_CALLBACK,
);
$items['admin/config/media/image-styles/testsuite/positioning_test'] = array(
'title' => 'Positioning Test',
'page callback' => 'imagecache_testsuite_positioning',
'access arguments' => array('administer imagecache'),
'access arguments' => array('administer image styles'),
'type' => MENU_LOCAL_TASK,
);
return $items;
@@ -46,187 +42,278 @@ function imagecache_testsuite_menu() {
/**
* Implementation of hook_help()
*/
function imagecache_testsuite_help($path, $arg) {
function imagecache_testsuite_help($path /*, $arg*/) {
switch ($path) {
// @todo: this path does not exist anymore.
case 'admin/build/imagecache/test' :
$output = file_get_contents(drupal_get_path('module', 'imagecache_testsuite') ."/README.txt");
$output = file_get_contents(drupal_get_path('module', 'imagecache_testsuite') . "/README.txt");
return _filter_autop($output);
break;
case 'admin/build/imagecache/test' :
return t('This displays a number of examples of keyword positioning. This positioning algorithm is used when placing image overlays, such as watermarks or text on a base image canvas. Illustrated are both the expected result and the actual result. This page is just for debugging to confirm that this behavior doesnt change as the code gets updated. If the two illustrations do not match, there is probably something wrong with the calculation logic.');
break;
break;
case 'admin/config/media/image-styles/testsuite' :
return t("<p>
This page displays a number of examples of image effects.
Illustrated are both the expected result and the actual result.
</p><p>
This page is just for debugging to confirm that this behavior doesn't
change as the code gets updated.
If the two illustrations do not match, there is probably something
that needs fixing.
</p><p>
More actions are provided by each of the imagecache actions submodules
and will be shown as you enable them.
</p>");
break;
case 'admin/config/media/image-styles' :
return t('
A number of styles here are provided by the Imagecache
Testsuite module as examples.
Disable this module to make them go away.
');
break;
}
return '';
}
/**
* Either returns the whole testsuite page or generates the requested
* image+preset
* Returns the test suite page.
*
* The test suite page contians img links to all image derivatives to create as
* part of the test suite.
*
* Samples to test are scanned from:
* - The existing image styles.
* - The file features.inc attached to this module. (@todo: no longer eisting?)
* - Individual *.imagecache_preset.inc files found near any known modules.
* Images illustrating the named preset are looked for also.
*
* Flushes the entire test cache every time anything is done.
*
* @return string
* The html for the page.
*/
function imagecache_testsuite_generate($test_id = '', $toolkit = 'gd') {
// Samples to test are scanned from
// - the existing installed presets
// - features inc attached to this module
// - individual *.imagecache_preset.inc files found near any known modules
// Images illustrating the named preset are looked for also.
function imagecache_testsuite_page() {
module_load_include('inc', 'image', 'image.admin');
module_load_include('inc', 'image', 'image.effects');
$sample_path = drupal_get_path('module' , 'imagecache_testsuite') ;
$target = $sample_path .'/sample.jpg';
$tests = image_styles() + imagecache_testsuite_get_tests();
$toolkits = module_invoke_all('image_toolkits');
$tests = array_merge(image_styles(), imagecache_testsuite_get_tests());
$toolkits = image_get_available_toolkits();
if (empty($test_id)) {
// Present the all-in-one overview page
$sample_folders = imagecache_testsuite_get_folders();
// Present the all-in-one overview page.
$sample_folders = imagecache_testsuite_get_folders();
// Firstly, remove any previous images
image_style_flush('testsuite');
// Draw the admin table.
$test_table = array();
foreach ($tests as $style_name => $style) {
// Firstly, remove any previous images for the current style
image_style_flush($style);
// Draw the admin table
$test_table = array();
foreach ($tests as $style_name => $style) {
$row = array();
$row_class = 'test';
$details = '';
// Render the details
foreach ($style['effects'] as $i => $effect) {
if (! isset($effect['name'])) {
// badness
watchdog('imagecache_testsuite', 'invalid testcase within %style_name. No effect name', array('%style_name' => $style_name), WATCHDOG_ERROR);
$details .= '<div>Unidentified effect</div>';
continue;
}
#$effect_definition = image_effect_definition_load($effect['name'], $style['name']);
$effect_definition = image_effect_definition_load($effect['name']);
if (function_exists($effect_definition['effect callback'])) {
$description = "<strong>{$effect_definition['label']}</strong> ";
$description .= isset($effect_definition['summary theme']) ? theme($effect_definition['summary theme'], array('data' => $effect['data'])) : '';
$details .= "<div>$description</div>";
}
else {
// Probably an action that requires a module that is not installed.
$details .= t("<div><b>Action %action Unavailable</b></div>", array('%action' => $effect['name']));
$row_class = 'error';
}
}
$row['details'] = "<h3>{$style['name']}</h3><p>$details</p>";
// Look for a sample image. May also be defined by the definition itself,
// but normally assume a file named after the presetname, in the preset file path.
foreach ($sample_folders as $sample_folder) {
if (file_exists("{$sample_folder}/{$style_name}.png")) {
$style['sample'] = "{$sample_folder}/{$style_name}.png";
}
elseif (file_exists("{$sample_folder}/{$style_name}.jpg")) {
$style['sample'] = "{$sample_folder}/{$style_name}.jpg";
}
}
if (isset($style['sample']) && file_exists($style['sample']) ) {
$sample_img = theme('image', array('path' => $style['sample']));
// I was having trouble with permissions on an OSX dev machine
if (! is_readable($style['sample'])) {
$sample_img = "FILE UNREADABLE: {$style['sample']}";
}
}
else {
$sample_img = "[no sample]";
}
$row['sample'] = $sample_img;
// Generate a result for each available toolkit
foreach ($toolkits as $toolkit => $toolkit_info) {
$test_url = "admin/config/media/image-styles/testsuite/$style_name/$toolkit";
$test_img = theme('image', array(
'path' => $test_url,
'alt' => "$style_name/$toolkit"
));
$row[$toolkit] = l($test_img, $test_url, array('html' => TRUE));
}
$test_table[$style_name] = array('data' => $row, 'class' => array($row_class));
}
$header = array_merge(array('test', 'sample'), array_keys($toolkits));
$output = theme('table', array('header' => $header, 'rows' => $test_table, 'id' => 'imagecache-testsuite'));
// Default system zebra-striping fails to show my transparency on white
drupal_add_html_head('<style type="text/css" >#imagecache-testsuite tr.even{background-color:#EEEEEE !important;} #imagecache-testsuite td{vertical-align:top;} #imagecache-testsuite tr.error{background-color:#FFCCCC !important;}</style>');
return $output;
}
else {
// Run the process and return the image.
// @see image_style_create_derivative()
$style = $tests[$test_id];
if (! $style) {
trigger_error("Unknown test style preset '$test_id' ", E_USER_ERROR);
return FALSE;
}
// Start emulating image_style_create_derivative()
// The main difference being I determine the toolkit I want to use.
// SOME of this code is probably redundant, was a lot of copy&paste without true understanding of the new image.module
$image_uri = $target;
if (!$image = image_load($target, $toolkit)) {
trigger_error("Failed to open original image $target with toolkit $toolkit", E_USER_ERROR);
return FALSE;
}
// Need to save the result before returning it - to stay compatible with imagemagick
$filename = "$test_id-$toolkit.{$image->info['extension']}";
$derivative_uri = image_style_path($style['name'], $filename);
file_prepare_directory(dirname($derivative_uri), FILE_CREATE_DIRECTORY);
watchdog('imagecache_testsuite', 'Checking a save dir %dir', array('%dir' => dirname($derivative_uri)), WATCHDOG_DEBUG);
// Imagemagick is not quite right? place a file where the file is supposed to go
// before I put the real path there? else drupal_realpath() says nuh.
#file_save_data('touch this for imagemagick', $derivative_uri, FILE_EXISTS_REPLACE);
$row = array();
$row_class = 'test';
$details_list = array();
// Render the details.
foreach ($style['effects'] as $effect) {
// Need to load the full effect definitions, our test ones don't know all the callback info
$effect_definition = image_effect_definition_load($effect['name']);
if (empty($effect_definition)) {
watchdog('imagecache_testsuite', 'I have no idea what %name is', array('%name' => $full_effect['name']), WATCHDOG_ERROR);
if (!isset($effect['name'])) {
// badness
watchdog('imagecache_testsuite', 'invalid testcase within %style_name. No effect name', array('%style_name' => $style_name), WATCHDOG_ERROR);
$details_list[] = '<div>Unidentified effect</div>';
$row_class = 'error';
continue;
}
$full_effect = array_merge($effect_definition, array('data' => $effect['data']));
$effect_definition = image_effect_definition_load($effect['name']);
if (function_exists($effect_definition['effect callback'])) {
$description = "<strong>{$effect_definition['label']}</strong> ";
$description .= isset($effect_definition['summary theme']) ? theme($effect_definition['summary theme'], array('data' => $effect['data'])) : '';
$details_list[] = "<div>$description</div>";
}
else {
// Probably an action that requires a module that is not installed.
$strings = array(
'%action' => $effect['name'],
'%module' => $effect['module'],
);
$details_list[$effect['name']] = t("<div><b>%action unavailable</b>. Please enable %module module.</div>", $strings);
$row_class = 'error';
}
}
$row['details'] = "<h3>{$style['name']}</h3><p>" . implode($details_list) . "</p>";
if (! image_effect_apply($image, $full_effect)) {
watchdog('imagecache_testsuite', 'action: %action (%callback) failed for %src', array('%action' => $full_effect['label'], '%src' => $target, '%callback' => $full_effect['effect callback']), WATCHDOG_ERROR);
#return FALSE;
// Look for a sample image. May also be defined by the definition itself,
// but normally assume a file named after the image style, in (one of the)
// directories with test styles.
foreach ($sample_folders as $sample_folder) {
if (file_exists("{$sample_folder}/{$style_name}.png")) {
$style['sample'] = "{$sample_folder}/{$style_name}.png";
}
elseif (file_exists("{$sample_folder}/{$style_name}.jpg")) {
$style['sample'] = "{$sample_folder}/{$style_name}.jpg";
}
}
#watchdog('imagecache_testsuite', "processed $test_id-$toolkit, ready to save", array(), WATCHDOG_DEBUG);
#watchdog('imagecache_testsuite', print_r($image, 1));
#dpm(get_defined_vars());
if (!image_save($image, $derivative_uri)) {
watchdog('imagecache_testsuite', 'saving image %label failed for %derivative_uri', array('%derivative_uri' => $derivative_uri, '%label' => $effect['label']), WATCHDOG_ERROR);
return FALSE;
if (isset($style['sample']) && file_exists($style['sample'])) {
$sample_img = theme('image', array('path' => $style['sample']));
// I was having trouble with permissions on an OSX dev machine.
if (!is_readable($style['sample'])) {
$sample_img = "FILE UNREADABLE: {$style['sample']}";
}
}
else {
$sample_img = "[no sample]";
}
$row['sample'] = $sample_img;
if ($result_image = image_load($derivative_uri)) {
#watchdog('imagecache_testsuite', 'transferring result', array(), WATCHDOG_DEBUG);
file_transfer($result_image->source, array('Content-Type' => $result_image->info['mime_type'], 'Content-Length' => $result_image->info['file_size']));
drupal_exit();
// Generate a result for each available toolkit.
foreach ($toolkits as $toolkit => $toolkit_info) {
$test_url = "admin/config/media/image-styles/testsuite/$style_name/$toolkit";
$test_img = theme('image', array(
'path' => $test_url,
'alt' => "$style_name/$toolkit"
));
$row[$toolkit] = l($test_img, $test_url, array('html' => TRUE));
}
return "Failed to load the expected result from $derivative_uri";
$test_table[$style_name] = array(
'data' => $row,
'class' => array($row_class)
);
}
$header = array_merge(array('test', 'sample'), array_keys($toolkits));
$output = theme('table', array(
'header' => $header,
'rows' => $test_table,
'id' => 'imagecache-testsuite'
));
// @todo: zebra striping can be disabled in D7.
// Default system zebra-striping fails to show my transparency on white.
drupal_add_html_head('<style type="text/css" >#imagecache-testsuite tr.even{background-color:#EEEEEE !important;} #imagecache-testsuite td{vertical-align:top;} #imagecache-testsuite tr.error{background-color:#FFCCCC !important;}</style>');
return $output;
}
/**
* Returns the requested image derivative.
*
* If the image derivative generation is successful, the function does not
* return but exits processing using drupal_exit().
*
* Flushes the entire test cache every time anything is done.
*
* @param string $test_id
* The id of the test to generate the derivative for.
* @param string $toolkit
* The toolkit to use, or empty for the default toolkit
*
* @return string|bool
* - The html for the page ($test_id is empty)
* - False when the image derivative could not be created.
*/
function imagecache_testsuite_generate($test_id = '', $toolkit = '') {
module_load_include('inc', 'image', 'image.admin');
module_load_include('inc', 'image', 'image.effects');
if (empty($toolkit)) {
$toolkit = image_get_toolkit();
}
else {
// Set the toolkit for this invocation only, so do not use variable_set.
global $conf;
$conf['image_toolkit'] = $toolkit;
if ($toolkit === 'gd') {
// This seems not to be done automatically elsewhere.
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'system') . '/' . 'image.gd.inc';
}
}
$target = 'module://imagecache_testsuite/sample.jpg';
$tests = array_merge(image_styles(), imagecache_testsuite_get_tests());
// Run the process and return the image, @see image_style_create_derivative().
$style = $tests[$test_id];
if (!$style) {
trigger_error("Unknown test style preset '$test_id' ", E_USER_ERROR);
return FALSE;
}
// @todo: should we let the image style system do its work and just interfere on hook_init with setting the toolkit?
// @todo: this would make the page generator easier as well and keep it working with secure image derivatives.
// Start emulating image_style_create_derivative()
// The main difference being I determine the toolkit I want to use.
// SOME of this code is probably redundant, was a lot of copy&paste without true understanding of the new image.module
if (!$image = image_load($target, $toolkit)) {
trigger_error("Failed to open original image $target with toolkit $toolkit", E_USER_ERROR);
return FALSE;
}
// Need to save the result before returning it - to stay compatible with imagemagick
$filename = "$test_id-$toolkit.{$image->info['extension']}";
$derivative_uri = image_style_path($style['name'], $filename);
$directory = dirname($derivative_uri);
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
watchdog('imagecache_testsuite', 'Checking a save dir %dir', array('%dir' => dirname($derivative_uri)), WATCHDOG_DEBUG);
// Imagemagick is not quite right? place a file where the file is supposed to go
// before I put the real path there? else drupal_realpath() says nuh.
#file_save_data('touch this for imagemagick', $derivative_uri, FILE_EXISTS_REPLACE);
foreach ($style['effects'] as $effect) {
// Need to load the full effect definitions, our test ones don't know all the callback info
$effect_definition = image_effect_definition_load($effect['name']);
if (empty($effect_definition)) {
watchdog('imagecache_testsuite', 'I have no idea what %name is', array('%name' => $effect['name']), WATCHDOG_ERROR);
continue;
}
$full_effect = array_merge($effect_definition, array('data' => $effect['data']));
// @todo: effects that involve other images (overlay, underlay) will load that image with the default toolkit which may differ from the toolkit tested here.
if (!image_effect_apply($image, $full_effect)) {
watchdog('imagecache_testsuite', 'action: %action (%callback) failed for %src', array(
'%action' => $full_effect['label'],
'%src' => $target,
'%callback' => $full_effect['effect callback']
), WATCHDOG_ERROR);
}
}
if (!image_save($image, $derivative_uri)) {
watchdog('imagecache_testsuite', 'saving image %label failed for %derivative_uri', array(
'%derivative_uri' => $derivative_uri,
'%label' => isset($style['label']) ? $style['label'] : $style['name']
), WATCHDOG_ERROR);
return FALSE;
}
if ($result_image = image_load($derivative_uri)) {
file_transfer($result_image->source, array(
'Content-Type' => $result_image->info['mime_type'],
'Content-Length' => $result_image->info['file_size']
));
drupal_exit();
}
return "Failed to load the expected result from $derivative_uri";
}
/**
* Implements hook_image_default_styles().
*
* Loads the individual test cases and makes them available as enabled styles
* Lists all our individual test cases and makes them available
* as enabled styles
*/
function imagecache_testsuite_image_default_styles() {
return imagecache_testsuite_get_tests();
$styles = imagecache_testsuite_get_tests();
// Need to filter out the invalid test cases
// (ones that use unavailable actions)
// or the core complains with notices.
// foreach ($styles as $id => $style) {
// foreach ($style['effects'] as $delta => $action) {
// if (!empty($action['module']) && ($action['module'] != 'imagecache') && !module_exists($action['module'])) {
// unset($styles[$id]);
// break;
// }
// }
// }
return $styles;
}
/**
@@ -250,7 +337,7 @@ function imagecache_testsuite_get_tests() {
// Setting filepath in this scope allows the tests to know where they are.
// The inc files may use it to create their rules.
$filepath = $folder;
foreach($preset_files as $preset_file) {
foreach ($preset_files as $preset_file) {
include_once($preset_file->uri);
}
}
@@ -261,8 +348,8 @@ function imagecache_testsuite_get_tests() {
/**
* Places to scan for test presets and sample images.
*
* @return an array of foldernames of everything that implements
* imagecache_actions.
* @return array
* an array of folder names of everything that implements imagecache_actions.
*/
function imagecache_testsuite_get_folders() {
$folders = array(drupal_get_path('module', 'imagecache_testsuite'));
@@ -272,7 +359,6 @@ function imagecache_testsuite_get_folders() {
return $folders;
}
/**
* Display a page demonstrating a number of positioning tests
*
@@ -280,13 +366,16 @@ function imagecache_testsuite_get_folders() {
* pls the css-like left=, top= version also.
*/
function imagecache_testsuite_positioning() {
module_load_include('inc', 'imagecache_actions', 'utility');
drupal_set_title("Testing the positioning algorithm");
$tests = imagecache_testsuite_positioning_get_tests();
$table = array();
// $dst_image represents tha field or canvas.
// $src_image is the item being placed on it.
// Both these represent an imageapi-type image resource handle, but contain just dimensions
$src_image = new stdClass();
$src_image->info = array('width' => 75, 'height' => 100);
$dst_image = new stdClass();
$dst_image->info = array('width' => 200, 'height' => 150);
foreach ($tests as $testname => $test) {
@@ -310,18 +399,27 @@ function imagecache_testsuite_positioning() {
$row['result_image'] = $result_illustration;
$table[] = $row;
}
return 'Result of test:'. theme('table', array('test', 'parameters', 'expected', 'image', 'result', 'actual image', 'status'), $table);
return 'Result of test:' . theme('table', array(
'test',
'parameters',
'expected',
'image',
'result',
'actual image',
'status'
), $table);
}
function theme_positioning_test($x, $y) {
$inner = "<div style='background-color:red; width:75px; height:100px; position:absolute; left:{$x}px; top:{$y}px'>";
$outer = "<div style='background-color:blue; width:200px; height:150px; position:absolute; left:25px; top:25px'><div style='position:relative'>$inner</div></div>";
$wrapper = "<div style='background-color:#CCCCCC; width:250px; height:200px; position:relative'>$outer</div>";
return $wrapper;
}
function theme_positioning_parameters($parameters) {
$outputs = array();
foreach ($parameters as $key => $value) {
$outputs[] = "[$key] => $value";
}
@@ -396,7 +494,6 @@ function imagecache_testsuite_positioning_get_tests() {
'y' => '25',
),
),
'keyword with percent' => array(
'parameters' => array(
'x' => 'right+10%',
@@ -408,7 +505,6 @@ function imagecache_testsuite_positioning_get_tests() {
'y' => '85',
),
),
'css styles' => array(
'parameters' => array(
'left' => '10px',
@@ -420,7 +516,6 @@ function imagecache_testsuite_positioning_get_tests() {
'y' => '40',
),
),
'css negatives' => array(
'parameters' => array(
'left' => '-10px',
@@ -432,7 +527,6 @@ function imagecache_testsuite_positioning_get_tests() {
'y' => '60',
),
),
'css with percents' => array(
'parameters' => array(
'right' => '+10%',
@@ -444,7 +538,6 @@ function imagecache_testsuite_positioning_get_tests() {
'y' => '85',
),
),
'css centering' => array(
'parameters' => array(
'right' => '50%',
@@ -469,4 +562,4 @@ function imagecache_testsuite_positioning_get_tests() {
),
);
}
}

View File

@@ -1,5 +1,4 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.

View File

@@ -1,5 +1,4 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
@@ -15,7 +14,7 @@ $presets['scale'] = array (
'effects' => array (
0 => array (
'weight' => '-1',
'module' => 'imagecache',
'module' => 'image',
'name' => 'image_scale',
'data' => array (
'width' => '100',

View File

@@ -1,5 +1,4 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.
@@ -16,7 +15,7 @@ $presets['scale_canvas'] = array (
'effects' => array (
1 => array (
'weight' => '1',
'module' => 'imagecache',
'module' => 'image',
'name' => 'image_scale',
'data' => array (
'width' => '100',

View File

@@ -1,5 +1,4 @@
<?php
// $ID: $
/**
* @file
* Test imagecache preset.