Index: imagecache.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.info,v
retrieving revision 1.4
diff -u -p -r1.4 imagecache.info
--- imagecache.info	15 Apr 2008 15:12:23 -0000	1.4
+++ imagecache.info	27 Apr 2008 06:24:35 -0000
@@ -2,4 +2,5 @@
 name = ImageCache
 description = Dynamic image manipulator and cache.
 package = ImageCache
-dependencies = imageapi
+dependencies[] = imageapi
+core = 6.x
Index: imagecache.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.install,v
retrieving revision 1.12
diff -u -p -r1.12 imagecache.install
--- imagecache.install	25 Apr 2008 00:56:38 -0000	1.12
+++ imagecache.install	27 Apr 2008 06:24:35 -0000
@@ -68,74 +68,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.
@@ -157,7 +165,7 @@ function imagecache_update_2() {
       $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetname presetname VARCHAR(255) NOT NULL DEFAULT \'\'');
       $ret[] = update_sql('ALTER TABLE {imagecache_action} CHANGE rulesetid presetid  INTEGER NOT NULL DEFAULT 0');
       break;
-    
+
     case 'pgsql':
       $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetid TO presetid');
       $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetname TO presetname');
@@ -168,15 +176,15 @@ function imagecache_update_2() {
 }
 
 
-/** 
+/**
  * Remove auto-increment from tables, instead depending on the sequences table and db_next_id()
- */  
+ */
 function imagecache_update_3() {
   $ret = array();
-  
+
   $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_action}')) + 1;
   $count_preset = db_result(db_query('SELECT max(presetid) FROM {imagecache_preset}')) + 1;
-  
+
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
@@ -227,7 +235,7 @@ function imagecache_update_4() {
     if ($function == 'scale and crop') {
       $function = 'scale_and_crop';
     }
-    // Keep scale and crop and the old scale function seperate... I don't really want to break BC with 
+    // Keep scale and crop and the old scale function seperate... I don't really want to break BC with
     // the 2.x update. We'll deprecate this version.
     if ($function == 'scale') {
       $function = 'deprecated_scale';
@@ -244,4 +252,3 @@ function imagecache_update_4() {
   return $ret;
 }
 
-
Index: imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.69
diff -u -p -r1.69 imagecache.module
--- imagecache.module	25 Apr 2008 00:56:38 -0000	1.69
+++ imagecache.module	27 Apr 2008 06:24:36 -0000
@@ -49,40 +49,95 @@ 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() {
+  return 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_formatter' => array(
+      'arguments' => array(
+        'field' => NULL,
+        'item' => NULL,
+        'formatter' => NULL,
+    )),
+    '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),
+    ),
+    
+  );
+}
+
 /**
  * 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 +195,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;
@@ -173,14 +228,14 @@ function imagecache_action_definition($a
   if (!isset($definition_cache[$action])) {
     $definitions = imagecache_action_definitions();
     $definition = (isset($definitions[$action])) ? $definitions[$action] : array();
-    
+
     if ($definition && $definition['file']) {
       require_once($definition['file']);
     }
     $definition_cache[$action] = $definition;
   }
   return $definition_cache[$action];
-} 
+}
 
 /**
  * Return a URL that points to the location of a derivative of the
@@ -214,7 +269,7 @@ function _imagecache_strip_file_director
 }
 
 
-/** 
+/**
  * callback for handling public files imagecache requests.
  */
 function imagecache_cache() {
@@ -234,7 +289,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');
@@ -248,21 +303,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;
   
@@ -276,9 +332,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
@@ -287,15 +344,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)) {
@@ -315,8 +372,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;
   }
@@ -329,24 +386,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;
 }
 
@@ -422,24 +479,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.
@@ -452,7 +509,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;
   }
 
@@ -474,14 +531,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;
   }
@@ -489,16 +546,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;
   }
 
 }
@@ -515,6 +572,7 @@ function imagecache_imagefield_file($op,
  * integration.
  */
 function imagecache_field_formatter_info() {
+  $formatters = array();
   foreach (imagecache_presets() as $preset) {
     $formatters[$preset['presetname']] = array(
       'label' => $preset['presetname'],
@@ -545,7 +603,7 @@ function imagecache_field_formatter_info
  */
 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'])) {
@@ -681,8 +739,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)) {
@@ -693,6 +754,11 @@ function theme_imagecache($namespace, $p
   return '<img src="'. $imagecache_url .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
 }
 
+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));
+}
 
 
 /************************************************************************************
@@ -700,7 +766,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;
@@ -710,13 +776,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;
@@ -732,10 +798,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.
  *
  */
@@ -745,7 +811,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))
  */
@@ -769,7 +835,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');
@@ -777,7 +843,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;
 }
@@ -787,7 +853,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
@@ -806,7 +872,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()) {
@@ -814,7 +880,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();
 }
 
 /**
@@ -828,11 +894,10 @@ 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.
@@ -857,7 +922,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();
@@ -903,17 +968,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);
@@ -927,5 +995,3 @@ function imagecache_action_delete($actio
   imagecache_preset_flush($preset);
   imagecache_presets(true);
 }
-
-
Index: imagecache_actions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache_actions.inc,v
retrieving revision 1.12
diff -u -p -r1.12 imagecache_actions.inc
--- imagecache_actions.inc	24 Apr 2008 05:27:45 -0000	1.12
+++ imagecache_actions.inc	27 Apr 2008 06:24:36 -0000
@@ -2,7 +2,7 @@
 // $Id: imagecache_actions.inc,v 1.12 2008/04/24 05:27:45 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(
Index: imagecache_ui.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache_ui.info,v
retrieving revision 1.3
diff -u -p -r1.3 imagecache_ui.info
--- imagecache_ui.info	15 Apr 2008 15:12:23 -0000	1.3
+++ imagecache_ui.info	27 Apr 2008 06:24:36 -0000
@@ -1,6 +1,7 @@
 ; $Id: imagecache_ui.info,v 1.3 2008/04/15 15:12:23 dopry Exp $
 name = Imagecache UI
 description = ImageCache User Interface.
-dependencies = imagecache imageapi
+dependencies[] = imagecache
+dependencies[] = imageapi
 package = ImageCache
-
+core = 6.x
Index: imagecache_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache_ui.module,v
retrieving revision 1.11
diff -u -p -r1.11 imagecache_ui.module
--- imagecache_ui.module	24 Apr 2008 05:27:45 -0000	1.11
+++ imagecache_ui.module	27 Apr 2008 06:24:36 -0000
@@ -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' => '<div>',
       '#suffix' => '</div>',
-      '#value' => l(t('Add !action', array('!action' => $definition['name'])), 
-                    'admin/build/imagecache/preset/'.  $preset['presetid'] .'/action/add/'. $action) .
+      '#value' => l(t('Add !action', array('!action' => $definition['name'])),
+                    'admin/build/imagecache/preset/'.  $preset['presetid'] .'/action-add/'. $action) .
                     ' - '. $definition['description'],
     );
   }
@@ -318,7 +335,7 @@ function imagecache_ui_preset_form($pres
 /**
  @todo: 404/403 image per preset.
  @todo: global 404/403 image.
-    
+
   $form['files'] = array(
     '#type' => 'fieldset',
     '#collapsible' => true,
@@ -331,13 +348,13 @@ function imagecache_ui_preset_form($pres
     '#title' => t('403 Image'),
     '#description' => t('Image that will be used when access is denied to the source image.'),
   );
-  
+
   $path403 = imagecache/'. $preset['presetname'] .'/403.png';
   if (file_exists($path403)) {
     $url403 =  imagecache_create_url($preset['presetname'], $path403);
 
     $form['files']['403']['view'] = array(
-      '#value' => '<img src="'. $url403 .'">', 
+      '#value' => '<img src="'. $url403 .'">',
     );
   }
 
@@ -360,46 +377,54 @@ function theme_imagecache_admin_title($e
   return '<h2>'. $element['value'] .'</h2>';
 }
 
-function theme_imagecache_ui_preset_actions($element) {
-  $header = array(t('Action'), t('Settings'), t('Weight'), '', '');
+function theme_imagecache_ui_preset_actions($form) {
+  $header = array(t('Action'), t('Settings'), t('Weight'), '','');
   $rows = array();
-  foreach (element_children($element) as $key) {
+  foreach(element_children($form) as $key) {
+    if (!is_numeric($key)) {
+      continue;
+    }
     $row = array();
-    $row[] = drupal_render($element[$key]['name']);
-    $row[] = drupal_render($element[$key]['settings']);
-    $row[] = drupal_render($element[$key]['weight']);
-    $row[] = drupal_render($element[$key]['configure']);
-    $row[] = drupal_render($element[$key]['remove']);
-    $rows[] = $row; 
+    $form[$key]['weight']['#attributes']['class'] = 'imagecache-action-order-weight';
+    $row[] = drupal_render($form[$key]['name']);
+    $row[] = drupal_render($form[$key]['settings']);
+    $row[] = drupal_render($form[$key]['weight']);
+    $row[] = drupal_render($form[$key]['configure']);
+    $row[] = drupal_render($form[$key]['remove']);
+    $rows[] = array(
+      'data' => $row,
+      'class' => 'draggable',
+    );
   }
-  $output .= theme('table', $header, $rows); 
-  $output .= drupal_render($element);
+  $output = theme('table', $header, $rows, array('id' => 'imagecache-preset-actions'));
+  drupal_add_tabledrag('imagecache-preset-actions', 'order', 'sibling', 'imagecache-action-order-weight');
+  $output .= drupal_render($form);
   return $output;
 }
 
-function imagecache_ui_preset_form_submit($form_id, $form_values) {
-  if (isset($form_values['actions'])) {
-    foreach ($form_values['actions'] as $action) {
+function imagecache_ui_preset_form_submit($form, &$form_state) {
+  if (isset($form_state['values']['actions'])) {
+    foreach($form_state['values']['actions'] as $action) {
       imagecache_action_save($action);
     }
   }
-  imagecache_preset_save($form_values);
-  return 'admin/build/imagecache/preset/'. $form_values['presetid'];
+  imagecache_preset_save($form_state['values']);
+  $form_state['redirect'] = 'admin/build/imagecache/preset/'. $form_state['values']['presetid'];
 }
 
-function imagecache_ui_action_form($actionid) {
+function imagecache_ui_action_form($form_state, $preset, $action) {
   $definitions = imagecache_action_definitions();
-  
-  if (!$action = imagecache_action($actionid)) {
+
+  if (empty($action)) {
     drupal_set_message('Unknown Action.'. $actionid, 'error');
     drupal_goto('admin/build/imagecache');
-  } 
+  }
 
-  if (!$preset = imagecache_preset($action['presetid'])) {
+  if (empty($preset)) {
     drupal_set_message('Unknown Preset.');
     drupal_goto('admin/build/imagecache');
   }
-  
+
   $form = array(
     '#tree' => true,
   );
@@ -410,7 +435,7 @@ function imagecache_ui_action_form($acti
   );
 
 
-  if ($definitions[$action['action']]['file']) {
+  if (!empty($definitions[$action['action']]['file'])) {
     require_once($definitions[$action['action']]['file']);
   }
   $form['data'] = call_user_func($action['action'] .'_form', $action['data']);
@@ -418,26 +443,28 @@ function imagecache_ui_action_form($acti
     '#type' => 'submit',
     '#value' => t('Update Action'),
   );
-  return $form;  
+  return $form;
 }
 
-function imagecache_ui_action_form_submit($form_id, $form_values) {
-  if ($action = imagecache_action($form_values['actionid'])) {
-    $action = array_merge($action, $form_values);
+function imagecache_ui_action_form_submit($form, &$form_state) {
+  if ($action = imagecache_action($form_state['values']['actionid'])) {
+    $action = array_merge($action, $form_state['values']);
     imagecache_action_save($action);
     drupal_set_message('Action Updated');
-    return 'admin/build/imagecache/preset/'. $action['presetid'];
+    $form_state['redirect'] = 'admin/build/imagecache/preset/'. $action['presetid'];
+  }
+  else {
+    drupal_set_message('Unknown Action: '. $form_state['values']['actionid']);
+    $form_state['redirect'] = 'admin/build/imagecache';
   }
-  drupal_set_message('Unknown Action: '. $form_values['actionid']);
-  return 'admin/build/imagecache';
 }
 
-function imagecache_ui_action_delete_form($presetid, $actionid) {
-  if (!$action = imagecache_action($actionid)) {
+function imagecache_ui_action_delete_form($form_state, $preset = array(), $action = array()) {
+  if (empty($action)) {
     drupal_set_message('Unknown Action.'. $actionid, 'error');
     drupal_goto('admin/build/imagecache');
-  } 
-  if (!$preset = imagecache_preset($action['presetid'])) {
+  }
+  if (empty($preset)) {
     drupal_set_message('Unknown Preset.');
     drupal_goto('admin/build/imagecache');
   }
@@ -446,26 +473,26 @@ function imagecache_ui_action_delete_for
   $form['actionid'] = array('#type' => 'value', '#value' => $action['actionid']);
   return confirm_form(
     $form,
-    t('Are you sure you want to delete the !action action from preset !preset?', 
+    t('Are you sure you want to delete the !action action from preset !preset?',
       array('!preset' => $preset['presetname'], '!action' => $action['name'])
     ),
-    'admin/build/imagecache', 
+    'admin/build/imagecache',
     t('This action cannot be undone.'),
-    t('Delete'),  t('Cancel')  
+    t('Delete'),  t('Cancel')
   );
 }
 
 
-function imagecache_ui_action_delete_form_submit($form_id, $form_values) {
-  $action = imagecache_action($form_values['actionid']);
+function imagecache_ui_action_delete_form_submit($form, &$form_state) {
+  $action = imagecache_action($form_state['values']['actionid']);
   imagecache_action_delete($action);
   drupal_set_message(t('The action has been deleted.'));
-  return 'admin/build/imagecache/preset/'. $action['presetid'];
+  $form_state['redirect'] = 'admin/build/imagecache/preset/'. $action['presetid'];
 }
 
-function imagecache_ui_action_add_form($presetid, $actionname) {
+function imagecache_ui_action_add_form($form_state, $preset, $actionname) {
   $definition = imagecache_action_definition($actionname);
-  
+
   $form = array(
     '#tree' => true,
   );
@@ -475,23 +502,23 @@ function imagecache_ui_action_add_form($
   );
   $form['presetid'] = array(
     '#type' => 'value',
-    '#value' => $presetid,
+    '#value' => $preset['presetid'],
   );
   $form['weight'] = array(
     '#type' => 'weight',
     '#title' => t('Weight'),
-  );  
+  );
 
-  $form['data'] = call_user_func($actionname .'_form', $action['data']);
+  $form['data'] = call_user_func($actionname .'_form', array());
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Add Action'),
   );
-  return $form;  
+  return $form;
 }
 
 
-function imagecache_ui_action_add_form_submit($form_id, $form_values) {
-  imagecache_action_save($form_values);
-  return 'admin/build/imagecache/preset/'. $form_values['presetid'];
+function imagecache_ui_action_add_form_submit($form, &$form_state) {
+  imagecache_action_save($form_state['values']);
+  $form_state['redirect'] = 'admin/build/imagecache/preset/'. $form_state['values']['presetid'];
 }
