diff -urp HEAD/imagecache_actions.inc 6.x-2.x-dev/imagecache_actions.inc
--- HEAD/imagecache_actions.inc 2008-05-15 13:59:28.000000000 +1000
+++ 6.x-2.x-dev/imagecache_actions.inc 2008-05-05 12:55:56.000000000 +1000
@@ -2,7 +2,7 @@
// $Id: imagecache_actions.inc,v 1.11 2008/04/21 12:55:01 dopry Exp $
/**
- * Imagecache Scale
+ * Imagecache Scale
*/
function imagecache_scale_form($data) {
$form = imagecache_resize_form($data);
@@ -16,7 +16,7 @@ function imagecache_scale_form($data) {
}
function theme_imagecache_scale($element) {
- $output = theme_imagecache_resize($element) . ', upscale: '.
+ $output = theme_imagecache_resize($element) . ', upscale: '.
$output .= ($element['#value']['upscale']) ? t('Yes') : t('No');
return $output;
}
@@ -114,9 +114,15 @@ function imagecache_deprecated_scale_ima
/**
- * Imagecache Crop
+ * Imagecache Crop
*/
function imagecache_crop_form($data) {
+ $data += array(
+ 'width' => '',
+ 'height' => '',
+ 'xoffset' => '',
+ 'yoffset' => '',
+ );
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
@@ -181,7 +187,7 @@ function imagecache_desaturate_image(&$i
/**
- * Imagecache Rotate
+ * Imagecache Rotate
*/
function imagecache_rotate_form($data) {
$form['degrees'] = array(
diff -urp HEAD/imagecache.info 6.x-2.x-dev/imagecache.info
--- HEAD/imagecache.info 2008-05-15 13:58:58.000000000 +1000
+++ 6.x-2.x-dev/imagecache.info 2008-05-05 12:55:56.000000000 +1000
@@ -2,4 +2,5 @@
name = ImageCache
description = Dynamic image manipulator and cache.
package = ImageCache
-dependencies = imageapi
+dependencies[] = imageapi
+core = 6.x
diff -urp HEAD/imagecache.install 6.x-2.x-dev/imagecache.install
--- HEAD/imagecache.install 2008-05-15 13:59:07.000000000 +1000
+++ 6.x-2.x-dev/imagecache.install 2008-05-15 14:33:37.000000000 +1000
@@ -9,17 +9,23 @@ function imagecache_requirements($phase)
// Ensure translations don't break at install time.
$t = get_t();
- // Check for an image library.
- if (count(imageapi_get_available_toolkits()) == 0) {
- $requirements['imagecache_imageapi_toolkits'] = array(
- 'title' => $t('ImageAPI Toolkit'),
- 'value' => $t('No image toolkits available'),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => $t('Imagecache requires an ImageAPI Toolkit such as ImageAPI GD or ImageAPI Imagemagick to function.'),
- );
- }
-
if ($phase == 'runtime') {
+ // Check this at runtime rather than install time because the order of
+ // installation doesn't take dependencies into account. ImageAPI may have
+ // been installed by not loaded and if we report a requirement error
+ // because we can't find its function or no toolkit is enabled modules that
+ // depend on us will still be enabled but will have a missing dependency.
+ // Seems like a better idea to let everything get enabled and then inform
+ // them of the problem.
+ if (count(imageapi_get_available_toolkits()) == 0) {
+ $requirements['imagecache_imageapi_toolkits'] = array(
+ 'title' => $t('ImageAPI Toolkit'),
+ 'value' => $t('No image toolkits available'),
+ 'severity' => REQUIREMENT_ERROR,
+ 'description' => $t('Imagecache requires an ImageAPI Toolkit such as ImageAPI GD or ImageAPI Imagemagick to function.'),
+ );
+ }
+
$memory_limit = ini_get('memory_limit');
if (parse_size($memory_limit) < parse_size('96M')) {
@@ -68,74 +74,82 @@ function imagecache_requirements($phase)
return $requirements;
}
-function imagecache_install() {
- switch ($GLOBALS['db_type']) {
- case 'mysql':
- case 'mysqli':
- $ret1 = db_query("CREATE TABLE {imagecache_preset} (
- presetid INT UNSIGNED NOT NULL PRIMARY KEY,
- presetname VARCHAR(255) NOT NULL DEFAULT '' )
- /*!40100 DEFAULT CHARACTER SET utf8 */
- ");
-
- $ret2 = db_query("CREATE TABLE {imagecache_action} (
- actionid INT UNSIGNED NOT NULL PRIMARY KEY,
- presetid INT UNSIGNED NOT NULL DEFAULT 0,
- weight INT NOT NULL DEFAULT 0,
- module varchar(255) not null default '',
- action varchar(255) not null default '',
- data TEXT NOT NULL)
- /*!40100 DEFAULT CHARACTER SET utf8 */
- ");
- break;
+function imagecache_schema() {
+ $schema['imagecache_preset'] = array(
+ 'fields' => array(
+ 'presetid' => array(
+ 'description' => t('The primary identifier for an imagecache_preset.'),
+ 'type' => 'serial',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE),
+ 'presetname' => array(
+ 'description' => t('The primary identifier for a node.'),
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE),
+ ),
+ 'primary key' => array('presetid'),
+ );
+
+ $schema['imagecache_action'] = array(
+ 'fields' => array(
+ 'actionid' => array(
+ 'description' => t('The primary identifier for an imagecache_action.'),
+ 'type' => 'serial',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE),
+ 'presetid' => array(
+ 'description' => t('The primary identifier for an imagecache_preset.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0),
+ 'weight' => array(
+ 'description' => t('The weight of the action in the preset.'),
+ 'type' => 'int',
+ 'unsigned' => FALSE,
+ 'not null' => TRUE,
+ 'default' => 0),
+ 'module' => array(
+ 'description' => t('The module that defined the action.'),
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE),
+ 'action' => array(
+ 'description' => t('The unique ID of the action to be executed.'),
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE),
+ 'data' => array(
+ 'description' => t('The configuration data for the action.'),
+ 'type' => 'text',
+ 'not null' => TRUE,
+ 'size' => 'big',
+ 'serialize' => TRUE),
+ ),
+ 'primary key' => array('actionid'),
+ 'indexes' => array(
+ 'presetid' => array('presetid'),
+ ),
+ );
- case 'pgsql':
- $ret1 = db_query("CREATE TABLE {imagecache_preset} (
- presetid INTEGER NOT NULL CHECK (presetid > 0),
- presetname VARCHAR(255) NOT NULL DEFAULT '',
- PRIMARY KEY (presetid));
- ");
- $ret2 = db_query("CREATE TABLE {imagecache_action} (
- actionid INTEGER NOT NULL CHECK (actionid > 0),
- presetid INTEGER NOT NULL DEFAULT 0,
- weight INTEGER NOT NULL DEFAULT 0,
- module varchar(255) not null default '',
- action varchar(255) not null default '',
- data TEXT NOT NULL DEFAULT '',
- PRIMARY KEY (actionid));
- ");
- db_query("CREATE SEQUENCE {imagecache_preset}_presetid_seq INCREMENT 1 START 1;");
- db_query("CREATE SEQUENCE {imagecache_action}_actionid_seq INCREMENT 1 START 1;");
- break;
- }
- if ($ret1 && $ret2) {
- drupal_set_message(t('Imagecache module installed succesfully.'));
- }
- else {
- drupal_set_message(t('Imagecache module installation was unsuccessfull. Necessary database tables should be created by hand.', 'error'));
- }
- return $ret;
+
+ return $schema;
+}
+
+/**
+ * Implementation of hook_install().
+ */
+function imagecache_install() {
+ drupal_install_schema('imagecache');
}
/**
* Implementation of hook_uninstall().
*/
function imagecache_uninstall() {
- db_query('DROP TABLE {imagecache_preset}');
- db_query('DROP TABLE {imagecache_action}');
-
- switch ($GLOBALS['db_type']) {
- case 'mysql':
- case 'mysqli':
- db_query("DELETE FROM {sequences} WHERE name = '{imagecache_action}_actionid'");
- db_query("DELETE FROM {sequences} WHERE name = '{imagecache_action}_presetid'");
- break;
- case 'pgsql':
- db_query('DROP SEQUENCE {imagecache_action}_actionid_seq');
- db_query('DROP SEQUENCE {imagecache_preset}_presetid_seq');
- break;
- }
+ drupal_uninstall_schema('imagecache');
}
// Add action id to actions table.
diff -urp HEAD/imagecache.module 6.x-2.x-dev/imagecache.module
--- HEAD/imagecache.module 2008-05-15 13:59:18.000000000 +1000
+++ 6.x-2.x-dev/imagecache.module 2008-05-16 14:37:39.000000000 +1000
@@ -49,40 +49,114 @@ function imagecache_perm() {
/**
* Implementation of hook_menu().
*/
-function imagecache_menu($may_cache) {
+function imagecache_menu() {
$items = array();
- if ($may_cache) {
- // standard imagecache callback.
- $items[] = array(
- 'path' => file_directory_path() .'/imagecache',
- 'callback' => 'imagecache_cache',
- 'access' => true,
- 'type' => MENU_CALLBACK
- );
+ // standard imagecache callback.
+ $items[file_directory_path() .'/imagecache'] = array(
+ 'page callback' => 'imagecache_cache',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK
+ );
+ // private downloads imagecache callback
+ $items['system/files/imagecache'] = array(
+ 'page callback' => 'imagecache_cache_private',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK
+ );
- // private downloads imagecache callback
- $items[] = array(
- 'path' => 'system/files/imagecache',
- 'callback' => 'imagecache_cache_private',
- 'access' => true,
- 'type' => MENU_CALLBACK
- );
- }
return $items;
}
+
+/**
+ * Implementation of hook_theme().
+ */
+function imagecache_theme() {
+ $theme = array(
+ 'imagecache' => array(
+ 'arguments' => array(
+ 'namespace' => NULL,
+ 'path' => NULL,
+ 'alt' => NULL,
+ 'title' => NULL,
+ )),
+ 'imagecache_imagelink' => array(
+ 'arguments' => array(
+ 'namespace' => NULL,
+ 'path' => NULL,
+ 'alt' => NULL,
+ 'title' => NULL,
+ 'attributes' => array(),
+ )),
+ 'imagecache_resize' => array(
+ 'arguments' => array('element' => NULL),
+ ),
+ 'imagecache_scale' => array(
+ 'file' => 'imagecache_actions.inc',
+ 'arguments' => array('element' => NULL),
+ ),
+ 'imagecache_scale_and_crop' => array(
+ 'file' => 'imagecache_actions.inc',
+ 'arguments' => array('element' => NULL),
+ ),
+ 'imagecache_deprecated_scale' => array(
+ 'file' => 'imagecache_actions.inc',
+ 'arguments' => array('element' => NULL),
+ ),
+ 'imagecache_crop' => array(
+ 'file' => 'imagecache_actions.inc',
+ 'arguments' => array('element' => NULL),
+ ),
+ 'imagecache_desaturate' => array(
+ 'file' => 'imagecache_actions.inc',
+ 'arguments' => array('element' => NULL),
+ ),
+ 'imagecache_rotate' => array(
+ 'file' => 'imagecache_actions.inc',
+ 'arguments' => array('element' => NULL),
+ ),
+ );
+
+ foreach (imagecache_presets() as $preset) {
+ $theme['imagecache_formatter_'. $preset['presetname'] .'_default'] = array(
+ 'arguments' => array('element' => NULL),
+ 'function' => 'theme_imagecache_formatter',
+ );
+ $theme['imagecache_formatter_'. $preset['presetname'] .'_linked'] = array(
+ 'arguments' => array('element' => NULL),
+ 'function' => 'theme_imagecache_formatter',
+ );
+ $theme['imagecache_formatter_'. $preset['presetname'] .'_imagelink'] = array(
+ 'arguments' => array('element' => NULL),
+ 'function' => 'theme_imagecache_formatter',
+ );
+ $theme['imagecache_formatter_'. $preset['presetname'] .'_path'] = array(
+ 'arguments' => array('element' => NULL),
+ 'function' => 'theme_imagecache_formatter',
+ );
+ $theme['imagecache_formatter_'. $preset['presetname'] .'_url'] = array(
+ 'arguments' => array('element' => NULL),
+ 'function' => 'theme_imagecache_formatter',
+ );
+ }
+
+ return $theme;
+
+}
+
/**
* Implementation of hook_imagecache_actions.
*
* @return array
- * An array of information on the actions implemented by a module. The array contains a
- * sub-array for each action node type, with the machine-readable action name as the key.
- * Each sub-array has up to 3 attributes. Possible attributes:
- *
+ * An array of information on the actions implemented by a module. The array
+ * contains a sub-array for each action node type, with the machine-readable
+ * action name as the key. Each sub-array has up to 3 attributes. Possible
+ * attributes:
+ *
* "name": the human-readable name of the action. Required.
* "description": a brief description of the action. Required.
- * "file": the name of the include file the action can be found
+ * "file": the name of the include file the action can be found
* in relative to the implementing module's path.
*/
function imagecache_imagecache_actions() {
@@ -140,20 +214,20 @@ function imagecache_action_definitions($
static $actions;
if (!isset($actions) || $reset) {
if (!$reset && ($cache = cache_get('imagecache_actions')) && !empty($cache->data)) {
- $actions = unserialize($cache->data);
+ $actions = $cache->data;
}
else {
foreach (module_implements('imagecache_actions') as $module) {
foreach (module_invoke($module, 'imagecache_actions') as $key => $action) {
$action['module'] = $module;
- if ($action['file']) {
+ if (!empty($action['file'])) {
$action['file'] = drupal_get_path('module', $action['module']) .'/'. $action['file'];
}
$actions[$key] = $action;
};
}
uasort($actions, '_imagecache_definitions_sort');
- cache_set('imagecache_actions', 'cache', serialize($actions));
+ cache_set('imagecache_actions', $actions);
}
}
return $actions;
@@ -197,12 +271,7 @@ function imagecache_action_definition($a
*/
function imagecache_create_url($presetname, $path) {
$path = _imagecache_strip_file_directory($path);
- switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
- case FILE_DOWNLOADS_PUBLIC:
- return url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path, NULL, NULL, TRUE);
- case FILE_DOWNLOADS_PRIVATE:
- return url('system/files/imagecache/'. $presetname .'/'. $path, NULL, NULL, TRUE);
- }
+ return file_create_url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path);
}
/**
@@ -228,7 +297,7 @@ function _imagecache_strip_file_director
}
-/**
+/**
* callback for handling public files imagecache requests.
*/
function imagecache_cache() {
@@ -248,7 +317,7 @@ function imagecache_cache_private() {
if (user_access('view imagecache '. $preset)) {
_imagecache_cache($preset, $source);
- }
+ }
else {
// if there is a 403 image, display it.
$accesspath = file_create_path('imagecache/'. $preset .'.403.png');
@@ -262,21 +331,22 @@ function imagecache_cache_private() {
}
/**
- * handle request validation and responses to imagecache requests.
+ * handle request validation and responses to imagecache requests.
*/
function _imagecache_cache($presetname, $path) {
if (!$preset = imagecache_preset_by_name($presetname)) {
- // send a 404 if we dont' know of a preset.
- header('HTTP/1.0 404 Not Found');
+ // Send a 404 if we don't know of a preset.
+ header("HTTP/1.0 404 Not Found");
exit;
}
// umm yeah deliver it early if it is there. especially useful
- // to prevent lock files from being created when delivering private files.
+ // to prevent lock files from being created when delivering private files.
$dst = imagecache_create_path($preset['presetname'], $path);
if (file_exists($dst)) {
imagecache_transfer($dst);
- }
+ }
+
$src = $path;
@@ -290,9 +360,10 @@ function _imagecache_cache($presetname,
if (!is_file($src)) {
// scan for imagefield previews
if (!empty($_SESSION['imagefield'])) {
- foreach ($_SESSION['imagefield'] as $fieldname => $files) {
+ foreach ((array) $_SESSION['imagefield'] as $fieldname => $files) {
foreach ($files as $delta => $file) {
if ($file['preview'] != $src) continue;
+
$dst = tempnam(file_directory_temp(), 'imagecache.preview');
// by the time shutdown functions are being called
// the cwd has changed from document root, to server root
@@ -301,15 +372,15 @@ function _imagecache_cache($presetname,
register_shutdown_function('file_delete', realpath($dst));
if (!imagecache_build_derivative($preset['actions'], $file['filepath'], $dst)) {
// Generate an error if image could not generate.
- watchdog('imagecache', t('Failed generating a preview image from %image using imagecache preset %preset.', array('%image' => $path, '%preset' => $presetname)), WATCHDOG_ERROR);
- header('HTTP/1.0 500 Internal Server Error');
+ watchdog('imagecache', 'Failed generating a preview image from %image using imagecache preset %preset.', array('%image' => $path, '%preset' => $presetname), WATCHDOG_ERROR);
+ header("HTTP/1.0 500 Internal Server Error");
exit;
}
imagecache_transfer($dst);
}
}
}
-
+
// if there is a 404 image uploaded for the preset display it.
$notfoundpath = file_create_path('imagecache/'. $preset['presetname'] .'.404.png');
if (file_exists($notfoundpath)) {
@@ -329,8 +400,8 @@ function _imagecache_cache($presetname,
$lockfile = file_directory_temp() .'/'. $preset['presetname'] . basename($src);
if (file_exists($lockfile)) {
- watchdog('imagecache', t('Imagecache already generating: %dst, Lock file: %tmp.', array('%dst' => $dst, '%tmp' => $lockfile)), WATCHDOG_NOTICE);
- // send a response code that will make the browser wait and reload in a 1/2 sec.
+ watchdog('imagecache', 'Imagecache already generating: %dst, Lock file: %tmp.', array('%dst' => $dst, '%tmp' => $lockfile), WATCHDOG_NOTICE);
+ // send a response code that will make the browser wait and reload in a 1/2 sec.
// header()
exit;
}
@@ -343,24 +414,24 @@ function _imagecache_cache($presetname,
register_shutdown_function('file_delete', realpath($lockfile));
// check if deriv exists... (file was created between apaches request handler and reaching this code)
- // otherwise try to create the derivative.
+ // otherwise try to create the derivative.
if (!file_exists($dst) && !imagecache_build_derivative($preset['actions'], $src, $dst)) {
// Generate an error if image could not generate.
- watchdog('imagecache', t('Failed generating an image from %image using imagecache preset %preset.', array('%image' => $path, '%preset' => $preset)), WATCHDOG_ERROR);
- header('HTTP/1.0 500 Internal Server Error');
+ watchdog('imagecache', 'Failed generating an image from %image using imagecache preset %preset.', array('%image' => $path, '%preset' => $preset['presetname']), WATCHDOG_ERROR);
+ header("HTTP/1.0 500 Internal Server Error");
exit;
- }
+ }
imagecache_transfer($dst);
}
function _imagecache_apply_action($action, &$image) {
$actions = imagecache_action_definitions();
-
+
if ($definition = imagecache_action_definition($action['action'])) {
return call_user_func($action['action'] .'_image', $image, $action['data']);
}
// skip undefined actions.. module probably got uninstalled or disabled.
- watchdog('imagecache', t('non-existant action %action', array('%action' => $action['action'])), WATCHDOG_NOTICE);
+ watchdog('imagecache', 'non-existant action %action', array('%action' => $action['action']), WATCHDOG_NOTICE);
return true;
}
@@ -436,24 +507,24 @@ function _imagecache_mkdir($dir) {
continue;
}
if (is_file($path)) {
- watchdog('imagecache', t('file exists where we would like a directory: %path', array('%path' => $path)), WATCHDOG_ERROR);
+ watchdog('imagecache', 'file exists where we would like a directory: %path', array('%path' => $path), WATCHDOG_ERROR);
return false;
- }
+ }
if (!@mkdir($path)) {
- watchdog('imagecache', t('Could not create destination: %dir halted at: %path', array('%dir' => $dir, '%path' => $path)), WATCHDOG_ERROR);
+ watchdog('imagecache', 'Could not create destination: %dir halted at: %path', array('%dir' => $dir, '%path' => $path), WATCHDOG_ERROR);
return false;
}
if (!@chmod($path, 0775)) {
- watchdog('imagecache', t('Could not set permissons on created directory: %dir halted at: %path', array('%dir' => $dir, '%path' => $path)), WATCHDOG_ERROR);
+ watchdog('imagecache', 'Could not set permissons on created directory: %dir halted at: %path', array('%dir' => $dir, '%path' => $path), WATCHDOG_ERROR);
return false;
- }
+ }
}
return true;
}
-
+
/**
* build an image cache derivative
- *
+ *
* @param $actions Array of imagecache actions.
* @param $src Path of the source file.
* @param $dst Path of the destination file.
@@ -466,7 +537,7 @@ function imagecache_build_derivative($ac
// Build the destination folder tree if it doesn't already exists.
if (!file_check_directory($dir) && !_imagecache_mkdir($dir)) {
- watchdog('imagecache', t('Failed to create imagecache directory: %dir', array('%dir' => $dir)), WATCHDOG_ERROR);
+ watchdog('imagecache', 'Failed to create imagecache directory: %dir', array('%dir' => $dir), WATCHDOG_ERROR);
return false;
}
@@ -488,14 +559,14 @@ function imagecache_build_derivative($ac
}
}
if (!_imagecache_apply_action($action, $image)) {
- watchdog( 'imagecache', t('action(id:%id): %action failed for %src', array('%id' => $action['actionid'], '%action' => $action['action'], '%src' => $src)), WATCHDOG_ERROR);
+ watchdog('imagecache', 'action(id:%id): %action failed for %src', array('%id' => $action['actionid'], '%action' => $action['action'], '%src' => $src), WATCHDOG_ERROR);
return false;
}
}
if (!imageapi_image_close($image, $dst)) {
if (file_exists($dst)) {
- watchdog('imagecache', t('Cached image file already exists. There is an issue with your Rewrite configuration.'), WATCHDOG_ERROR);
+ watchdog('imagecache', 'Cached image file already exists. There is an issue with your Rewrite configuration.', WATCHDOG_ERROR);
}
return false;
}
@@ -503,16 +574,16 @@ function imagecache_build_derivative($ac
return true;
}
-
+
function imagecache_imagefield_file($op, $file) {
switch ($op) {
// Delete imagecache presets when imagecache images are deleted.
case 'delete': imagecache_image_flush($file['filepath']); break;
- // Create imagecache derivatives when files are saved.
- case 'save':
- break;
+ // Create imagecache derivatives when files are saved.
+ case 'save':
+ break;
}
}
@@ -529,6 +600,7 @@ function imagecache_imagefield_file($op,
* integration.
*/
function imagecache_field_formatter_info() {
+ $formatters = array();
foreach (imagecache_presets() as $preset) {
$formatters[$preset['presetname'] .'_default'] = array(
'label' => $preset['presetname'],
@@ -554,12 +626,17 @@ function imagecache_field_formatter_info
return $formatters;
}
+function theme_imagecache_formatter($element) {
+ return imagecache_field_formatter($element['#field_name'], $element['#item'], $element['#formatter'], node_load($element['#item']['nid']));
+}
+
+
/**
* Implementation of hook_field_formatter().
*/
function imagecache_field_formatter($field, $item, $formatter, $node) {
if (empty($item['fid']) && $field['use_default_image']) {
- $item = $field['default_image'];
+ $item = $field['default_image'];
}
// Views does not load the file for us, while CCK display fields does.
if (!isset($item['filepath'])) {
@@ -577,13 +654,13 @@ function imagecache_field_formatter($fie
$item['filepath'] = $item['fid'] == 'upload' ? $item['preview'] : $item['filepath'];
switch ($style) {
case 'linked':
- $imagetag = theme('imagecache', $presetname, $item['filepath'], $item['alt'], $item['title']);
- return l($imagetag, 'node/'. $node->nid, array('class' => $class), null, null, false, true);
+ $imagetag = theme('imagecache', $presetname, $item['filepath'], $item['alt'], $item['title']);
+ return l($imagetag, 'node/'. $node->nid, array('attributes' => array('class' => $class), 'html' => true));
case 'imagelink':
$original_image_url = file_create_url($item['filepath']);
$imagetag = theme('imagecache', $presetname, $item['filepath'], $item['alt'], $item['title']);
- return l($imagetag, $original_image_url, array('class' => $class), null, null, false, true);
+ return l($imagetag, $original_image_url, array('attributes' => array('class' => $class), 'html' => true));
case 'url':
return imagecache_create_url($presetname, $item['filepath']);
@@ -695,8 +772,11 @@ function _imagecache_recursive_delete($d
* optional drupal attributes array. If attributes is set, the default imagecache classes
* will not be set automatically, you must do this manually.
*/
-
-function theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = null) {
+function theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = NULL) {
+ if ($image = image_get_info(imagecache_create_path($namespace, $path))) {
+ $attributes['width'] = $image['width'];
+ $attributes['height'] = $image['height'];
+ }
// check is_null so people can intentionally pass an empty array of attributes to override
// the defaults completely... if
if (is_null($attributes)) {
@@ -707,6 +787,11 @@ function theme_imagecache($namespace, $p
return '';
}
+function theme_imagecache_imagelink($namespace, $path, $alt = '', $title = '', $attributes = NULL) {
+ $image = theme('imagecache', $namespace, $path, $alt, $title);
+ $original_image_url = file_create_url($path);
+ return l($image, $original_image_url, array('absolute' => FALSE, 'html' => TRUE));
+}
/************************************************************************************
@@ -714,7 +799,7 @@ function theme_imagecache($namespace, $p
*/
function imagecache_resize_image(&$image, $data) {
if (!imageapi_image_resize($image, $data['width'], $data['height'])) {
- watchdog('imagecache', t('imagecache_resize_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, true))), WATCHDOG_ERROR);
+ watchdog('imagecache', 'imagecache_resize_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR);
return false;
}
return true;
@@ -724,13 +809,13 @@ function imagecache_resize_form($action)
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
- '#default_value' => $action['width'],
+ '#default_value' => isset($action['width']) ? $action['width'] : '100%',
'#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
);
$form['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
- '#default_value' => $action['height'],
+ '#default_value' => isset($action['height']) ? $action['height'] : '100%',
'#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
);
return $form;
@@ -746,10 +831,10 @@ function theme_imagecache_resize($elemen
/**
* ImageCache 2.x API
*
- * The API for imagecache has changed. There is a compatibility layer for
+ * The API for imagecache has changed. There is a compatibility layer for
* imagecache 1.x. Please see the imagecache_compat.module
- *
- * The 2.x API returns more structured data, has shorter function names, and
+ *
+ * The 2.x API returns more structured data, has shorter function names, and
* implements more aggressive metadata caching.
*
*/
@@ -759,7 +844,7 @@ function theme_imagecache_resize($elemen
*
* @param reset
* if set to true it will clear the preset cache
- *
+ *
* @return
* array of presets array( $preset_id => array('presetid' => integer, 'presetname' => string))
*/
@@ -783,7 +868,7 @@ function imagecache_presets($reset = fal
// Grab from cache or build the array.
if ($cache = cache_get('imagecache:presets', 'cache')) {
- $presets = unserialize($cache->data);
+ $presets = $cache->data;
}
else {
$result = db_query('SELECT * FROM {imagecache_preset} ORDER BY presetname');
@@ -791,7 +876,7 @@ function imagecache_presets($reset = fal
$presets[$preset['presetid']] = $preset;
$presets[$preset['presetid']]['actions'] = imagecache_preset_actions($preset);
}
- cache_set('imagecache:presets', 'cache', serialize($presets));
+ cache_set('imagecache:presets', $presets);
}
return $presets;
}
@@ -801,7 +886,7 @@ function imagecache_presets($reset = fal
*
* @param preset_id
* The numeric id of a preset.
- *
+ *
* @return
* preset array( 'presetname' => string, 'presetid' => integet)
* empty array if preset_id is an invalid preset
@@ -820,7 +905,7 @@ function imagecache_preset($preset_id, $
* preset array( 'presetname' => string, 'presetid' => integer)
* empty array if preset_name is an invalid preset
*/
-
+
function imagecache_preset_by_name($preset_name) {
static $presets_by_name = array();
if (!$presets_by_name && $presets = imagecache_presets()) {
@@ -828,7 +913,7 @@ function imagecache_preset_by_name($pres
$presets_by_name[$preset['presetname']] = $preset;
}
}
- return (isset($presets_by_name[$preset_name])) ? $presets_by_name[$preset_name] : array();
+ return (isset($presets_by_name[$preset_name])) ? $presets_by_name[$preset_name] : array();
}
/**
@@ -842,16 +927,19 @@ function imagecache_preset_by_name($pres
function imagecache_preset_save($preset) {
// @todo: CRUD level validation?
if (isset($preset['presetid']) && is_numeric($preset['presetid'])) {
- db_query('UPDATE {imagecache_preset} SET presetname =\'%s\' WHERE presetid = %d', $preset['presetname'], $preset['presetid']);
+ drupal_write_record('imagecache_preset', $preset, 'presetid');
}
else {
- $preset['presetid'] = db_next_id('{imagecache_preset}_presetid');
- db_query('INSERT INTO {imagecache_preset} (presetid, presetname) VALUES (%d, \'%s\')', $preset['presetid'], $preset['presetname']);
+ drupal_write_record('imagecache_preset', $preset);
}
// Reset presets cache.
imagecache_preset_flush($preset);
imagecache_presets(true);
+
+ // Rebuild Theme Registry
+ drupal_rebuild_theme_registry();
+
return $preset;
}
@@ -871,7 +959,7 @@ function imagecache_preset_actions($pres
while ($row = db_fetch_array($result)) {
$row['data'] = unserialize($row['data']);
$actions_cache[$preset['presetid']][] = $row;
- }
+ }
}
return isset($actions_cache[$preset['presetid']]) ? $actions_cache[$preset['presetid']] : array();
@@ -917,17 +1005,20 @@ function imagecache_action($actionid) {
$action = array_merge($definition, $action);
$actions[$actionid] = $action;
}
- }
+ }
return $actions[$actionid];
}
+function imagecache_action_load($actionid) {
+ return imagecache_action($actionid, TRUE);
+}
+
function imagecache_action_save($action) {
- if ($action['actionid']) {
- db_query('UPDATE {imagecache_action} SET weight=%d, data=\'%s\' WHERE actionid=%d', $action['weight'], serialize($action['data']), $action['actionid']);
+ if (!empty($action['actionid'])) {
+ drupal_write_record('imagecache_action', $action, 'actionid');
}
else {
- $action['actionid'] = db_next_id('{imagecache_action}_actionid');
- db_query('INSERT INTO {imagecache_action} (actionid, presetid, weight, action, data) VALUES (%d, %d, %d,\'%s\', \'%s\')', $action['actionid'], $action['presetid'], $action['weight'], $action['action'], serialize($action['data']));
+ drupal_write_record('imagecache_action', $action);
}
$preset = imagecache_preset($action['presetid']);
imagecache_preset_flush($preset);
diff -urp HEAD/imagecache_ui.info 6.x-2.x-dev/imagecache_ui.info
--- HEAD/imagecache_ui.info 2008-05-15 13:59:37.000000000 +1000
+++ 6.x-2.x-dev/imagecache_ui.info 2008-05-05 12:55:56.000000000 +1000
@@ -1,6 +1,7 @@
; $Id: imagecache_ui.info,v 1.2 2007/12/14 13:28:57 dopry Exp $
name = Imagecache UI
description = ImageCache User Interface.
-dependencies = imagecache imageapi
+dependencies[] = imagecache
+dependencies[] = imageapi
package = ImageCache
-
+core = 6.x
diff -urp HEAD/imagecache_ui.module 6.x-2.x-dev/imagecache_ui.module
--- HEAD/imagecache_ui.module 2008-05-15 13:59:56.000000000 +1000
+++ 6.x-2.x-dev/imagecache_ui.module 2008-05-05 12:55:56.000000000 +1000
@@ -6,103 +6,126 @@
*
*/
-function imagecache_ui_help($section) {
- switch ($section) {
+function imagecache_ui_help($path, $arg) {
+ switch($path) {
case 'admin/build/imagecache': return t('Manage imagecache preset.');
}
}
-function imagecache_ui_menu($may_cache) {
+function imagecache_ui_menu() {
$items = array();
- if ($may_cache) {
- $items[] = array(
- 'path' => 'admin/build/imagecache',
- 'title' => t('Imagecache'),
- 'description' => t('Administer imagecache presets and actions.'),
- 'callback' => 'imagecache_ui_presets',
- 'access' => user_access('administer imagecache'),
-
- );
- $items[] = array(
- 'path' => 'admin/build/imagecache/list',
- 'title' => t('List'),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
- );
- $items[] = array(
- 'path' => 'admin/build/imagecache/add',
- 'title' => t('Add New Preset'),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('imagecache_ui_preset_add_form'),
- 'access' => user_access('administer imagecache'),
- 'type' => MENU_LOCAL_TASK,
- );
- }
- // Use Dynamic menu items to get better breadcrumb trails by default.
- elseif (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'imagecache' && arg(3) == 'preset') {
- $preset = imagecache_preset(arg(4));
- if (empty($preset)) {
- return $items;
- }
- $t = array('!presetname' => $preset['presetname']);
- $items[] = array(
- 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/delete',
- 'title' => t('Delete Preset: !presetname', $t),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('imagecache_ui_preset_delete_form', arg(4)),
- 'type' => MENU_CALLBACK,
- );
- $items[] = array(
- 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/flush',
- 'title' => t('Flush Preset: !presetname', $t),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('imagecache_ui_preset_flush_form', arg(4)),
- 'access' => user_access('flush imagecache'),
- 'type' => MENU_CALLBACK,
- );
- $items[] = array(
- 'path' => 'admin/build/imagecache/preset/'. arg(4),
- 'title' => t('!presetname', $t),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('imagecache_ui_preset_form', arg(4)),
- 'type' => MENU_CALLBACK,
- );
-
- $definition = imagecache_action_definition(arg(7));
- if (!empty($definition)) {
- $t['!action'] = $definition['name'];
- $items[] = array(
- 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/action/add/'. arg(7),
- 'title' => t('Add !action to !presetname', $t),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('imagecache_ui_action_add_form', arg(4), arg(7)),
- 'type' => MENU_CALLBACK,
- );
- }
-
- $action = imagecache_action(arg(6));
- if ($action) {
- $t['!action'] = $action['name'];
- $items[] = array(
- 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/action/'. arg(6),
- 'title' => t('!action for preset !presetname', $t),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('imagecache_ui_action_form', arg(6)),
- 'type' => MENU_CALLBACK,
- );
-
- $items[] = array(
- 'path' => 'admin/build/imagecache/preset/'. arg(4) .'/action/'. arg(6) .'/delete',
- 'title' => t('Delete !action for preset !presetname', $t),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => array('imagecache_ui_action_delete_form', arg(4), arg(6)),
- 'type' => MENU_CALLBACK,
- );
- }
- }
+ $items['admin/build/imagecache'] = array(
+ 'title' => 'Imagecache Presets',
+ 'description' => 'Administer imagecache presets and actions.',
+ 'page callback' => 'imagecache_ui_presets',
+ 'access arguments' => array('administer imagecache'),
+ );
+ $items['admin/build/imagecache/list'] = array(
+ 'title' => 'List',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
+
+ $items['admin/build/imagecache/add'] = array(
+ 'title' => 'Add new preset',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('imagecache_ui_preset_add_form'),
+ 'access arguments' => array('administer imagecache'),
+ 'type' => MENU_LOCAL_TASK,
+ );
+
+ $items['admin/build/imagecache/preset/%imagecache_ui_preset'] = array(
+ 'title callback' => 'imagecache_preset_title_callback',
+ 'title arguments' => array('Edit preset: !presetname', 4),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('imagecache_ui_preset_form', 4),
+ 'access arguments' => array('administer imagecache'),
+ 'type' => MENU_CALLBACK,
+ );
+ $items['admin/build/imagecache/preset/%imagecache_ui_preset/delete'] = array(
+ 'title callback' => 'imagecache_preset_title_callback',
+ 'title arguments' => array('Delete preset: !presetname', 4),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('imagecache_ui_preset_delete_form', 4),
+ 'access arguments' => array('administer imagecache'),
+ 'type' => MENU_CALLBACK,
+ );
+ $items['admin/build/imagecache/preset/%imagecache_ui_preset/flush'] = array(
+ 'title callback' => 'imagecache_preset_title_callback',
+ 'title arguments' => array('Flush preset: !presetname', 4),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('imagecache_ui_preset_flush_form', 4),
+ 'access arguments' => array('flush imagecache'),
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['admin/build/imagecache/preset/%imagecache_ui_preset/action-add/%'] = array(
+ 'title callback' => 'imagecache_preset_title_callback',
+ 'title arguments' => array('Add !actionname to !presetname', 4, 6),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('imagecache_ui_action_add_form', 4, 6),
+ 'access arguments' => array('administer imagecache'),
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['admin/build/imagecache/preset/%imagecache_ui_preset/action/%imagecache_action'] = array(
+ 'title callback' => 'imagecache_preset_title_callback',
+ 'title arguments' => array('!action for preset !presetname', 4, 6),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('imagecache_ui_action_form', 4, 6),
+ 'access arguments' => array('administer imagecache'),
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['admin/build/imagecache/preset/%imagecache_ui_preset/action-delete/%imagecache_action'] = array(
+ 'title callback' => 'imagecache_preset_title_callback',
+ 'title arguments' => array('Delete !action for preset !presetname', 4, 6),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('imagecache_ui_action_delete_form', 4, 6),
+ 'access arguments' => array('administer imagecache'),
+ 'type' => MENU_CALLBACK,
+ );
return $items;
}
+function imagecache_preset_title_callback($title, $preset = array(), $action = array()) {
+ $replacements = array();
+ if (!empty($preset)) {
+ $replacements['!presetname'] = $preset['presetname'];
+ $replacements['!presetid'] = $preset['presetid'];
+ }
+ if (!empty($action) && !is_array($action)) {
+ $replacements['!actionname'] = $action;
+ }
+ elseif (!empty($action)) {
+ $replacements['!action'] = $action['action'];
+ }
+ return t($title, $replacements);
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function imagecache_ui_theme() {
+ return array(
+ 'imagecache_admin_title' => array(
+ 'arguments' => array(
+ 'element' => NULL,
+ )),
+ 'imagecache_ui_preset_actions' => array(
+ 'arguments' => array(
+ 'form' => NULL,
+ )),
+ );
+}
+
+/**
+ * Menu wildcard loader.
+ */
+function imagecache_ui_preset_load($preset_id) {
+ return imagecache_preset($preset_id, TRUE);
+}
+
/**
* Preset Admin callbacks and required functions.
*/
@@ -121,10 +144,11 @@ function imagecache_ui_presets() {
$rows[] = $row;
}
$output = theme('table', $header, $rows);
+
return $output;
}
-function imagecache_ui_preset_add_form($presetid = 0) {
+function imagecache_ui_preset_add_form($form_state) {
$form = array();
$form['presetname'] = array(
'#type' => 'textfield',
@@ -141,11 +165,11 @@ function imagecache_ui_preset_add_form($
return $form;
}
-function imagecache_ui_preset_add_form_submit($id, $form_values) {
- $preset = array('presetname' => $form_values['presetname']);
+function imagecache_ui_preset_add_form_submit($form, &$form_state) {
+ $preset = array('presetname' => $form_state['values']['presetname']);
$preset = imagecache_preset_save($preset);
drupal_set_message(t('Preset "%name" (ID: @id) Created.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
- return 'admin/build/imagecache/preset/'. $preset['presetid'];
+ $form_state['redirect'] = 'admin/build/imagecache/preset/'. $preset['presetid'];
}
function imagecache_element_presetname_validate($element) {
@@ -161,10 +185,8 @@ function imagecache_element_presetname_v
}
}
-function imagecache_ui_preset_delete_form($presetid) {
- $preset = imagecache_preset($presetid);
-
- if (!$preset) {
+function imagecache_ui_preset_delete_form($form_state, $preset = array()) {
+ if (empty($preset)) {
drupal_set_message(t('The specified preset was not found'), 'error');
drupal_goto('admin/build/imagecache');
}
@@ -173,58 +195,54 @@ function imagecache_ui_preset_delete_for
$form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']);
return confirm_form(
$form,
- t('Are you sure you want to delete the preset %preset?',
+ t('Are you sure you want to delete the preset %preset?',
array('%preset' => $preset['presetname'])
),
- 'admin/build/imagecache',
+ 'admin/build/imagecache',
t('This action cannot be undone.'),
- t('Delete'), t('Cancel')
+ t('Delete'), t('Cancel')
);
}
-function imagecache_ui_preset_delete_form_submit($form_id, $form_values) {
- $preset = imagecache_preset($form_values['presetid']);
- imagecache_preset_delete($preset);
+function imagecache_ui_preset_delete_form_submit($form, &$form_state) {
+ $preset = imagecache_preset($form_state['values']['presetid']);
+ imagecache_preset_delete($preset);
drupal_set_message(t('Preset "%name" (ID: @id) deleted.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
- return 'admin/build/imagecache';
+ $form_state['redirect'] = 'admin/build/imagecache';
}
-function imagecache_ui_preset_flush_form($presetid) {
- $preset = imagecache_preset($presetid);
-
- if (!$preset) {
+function imagecache_ui_preset_flush_form(&$form_state, $preset = array()) {
+ if (empty($preset)) {
drupal_set_message(t('The specified preset was not found'), 'error');
- drupal_goto('admin/build/imagecache');
+ $form_state['redirect'] = 'admin/build/imagecache';
}
$form = array();
$form['presetid'] = array('#type' => 'value', '#value' => $preset['presetid']);
return confirm_form(
$form,
- t('Are you sure you want to flush the preset %preset?',
+ t('Are you sure you want to flush the preset %preset?',
array('%preset' => $preset['presetname'])
),
- 'admin/build/imagecache',
+ 'admin/build/imagecache',
t('This action cannot be undone.'),
- t('Flush'), t('Cancel')
+ t('Flush'), t('Cancel')
);
}
-function imagecache_ui_preset_flush_form_submit($form_id, $form_values) {
- $preset = imagecache_preset($form_values['presetid']);
- imagecache_preset_flush($preset);
+function imagecache_ui_preset_flush_form_submit($form, &$form_state) {
+ $preset = imagecache_preset($form_state['values']['presetid']);
+ imagecache_preset_flush($preset);
drupal_set_message(t('Preset "%name" (ID: @id) flushed.', array('%name' => $preset['presetname'], '@id' => $preset['presetid'])));
- return 'admin/build/imagecache';
+ $form_state['redirect'] = 'admin/build/imagecache';
}
-function imagecache_ui_preset_form($presetid) {
- $preset = imagecache_preset($presetid, true);
-
- if (!$preset) {
+function imagecache_ui_preset_form($form_state, $preset = array()) {
+ if (empty($preset)) {
drupal_set_message(t('The specified preset was not found'), 'error');
drupal_goto('admin/build/imagecache');
}
@@ -250,7 +268,6 @@ function imagecache_ui_preset_form($pres
'#theme' => 'imagecache_ui_preset_actions',
);
-
foreach ($preset['actions'] as $i => $action) {
// skip unknown actions...
if (!$definition = imagecache_action_definition($action['action'])) {
@@ -290,11 +307,11 @@ function imagecache_ui_preset_form($pres
'#value' => l(t('Configure'), 'admin/build/imagecache/preset/'. $action['presetid'] .'/action/'. $action['actionid'] ),
);
$action_form['remove'] = array(
- '#value' => l(t('Delete'), 'admin/build/imagecache/preset/'. $action['presetid'] .'/action/'. $action['actionid'] .'/delete'),
+ '#value' => l(t('Delete'), 'admin/build/imagecache/preset/'. $action['presetid'] .'/action-delete/'. $action['actionid']),
);
- $form['actions'][$i] = $action_form;
- }
-
+ $form['actions'][$i] = $action_form;
+ }
+
$form['actions']['new'] = array(
'#tree' => false,
'#type' => 'fieldset',
@@ -309,8 +326,8 @@ function imagecache_ui_preset_form($pres
'#type' => 'markup',
'#prefix' => '