Common subdirectories: Jcrop and Jcrop
diff -up imagefield_crop.module imagefield_crop.module
--- imagefield_crop.module	2009-11-11 03:12:53.000000000 -0500
+++ imagefield_crop.module	2010-05-16 09:53:03.000000000 -0400
@@ -84,7 +84,7 @@ function imagefield_crop_elements() {
  * Implementation of hook_theme().
  */
 function imagefield_crop_theme() {
-  return array(
+  $theme = array(
     // imagefield_crop_widget form element type theme function.
     'imagefield_crop_widget' => array(
       'arguments' => array('element' => NULL),
@@ -110,6 +110,75 @@ function imagefield_crop_theme() {
       'arguments' => array('element' => NULL),
     ),
   );
+
+  if (function_exists('imagecache_presets')) {
+    foreach (imagecache_presets() as $preset) {
+      $theme['imagefield_crop_formatter_'. $preset['presetname'] .'_default_uncropped'] = array(
+        'arguments' => array('element' => NULL, 'function' => 'theme_imagecache_formatter_default'), // Passing default value doesn't actually work! d'oh.
+        'function' => 'theme_imagefield_crop_formatter_uncropped',
+      );
+      $theme['imagefield_crop_formatter_'. $preset['presetname'] .'_linked_uncropped'] = array(
+        'arguments' => array('element' => NULL, 'function' => 'theme_imagecache_formatter_linked'),
+        'function' => 'theme_imagefield_crop_formatter_uncropped',
+      );
+      $theme['imagefield_crop_formatter_'. $preset['presetname'] .'_imagelink_uncropped'] = array(
+        'arguments' => array('element' => NULL, 'function' => 'theme_imagecache_formatter_imagelink'),
+        'function' => 'theme_imagefield_crop_formatter_uncropped',
+      );
+      $theme['imagefield_crop_formatter_'. $preset['presetname'] .'_path_uncropped'] = array(
+        'arguments' => array('element' => NULL, 'function' => 'theme_imagecache_formatter_path'),
+        'function' => 'theme_imagefield_crop_formatter_uncropped',
+      );
+      $theme['imagefield_crop_formatter_'. $preset['presetname'] .'_url_uncropped'] = array(
+        'arguments' => array('element' => NULL, 'function' => 'theme_imagecache_formatter_url'),
+        'function' => 'theme_imagefield_crop_formatter_uncropped',
+      );
+    }
+  }
+
+  return $theme;
+}
+
+/**
+ * Implementation of hook_field_formatter_info().
+ *
+ * imagecache formatters are named as $presetname_$style
+ * $style is used to determine how the preset should be rendered.
+ * If you are implementing custom imagecache formatters please treat _ as
+ * reserved.
+ *
+ * @todo: move the linking functionality up to imagefield and clean up the default image
+ * integration.
+ */
+function imagefield_crop_field_formatter_info() {
+  $formatters = array();
+
+  if (function_exists('imagecache_presets')) {
+    foreach (imagecache_presets() as $preset) {
+      $formatters[$preset['presetname'] .'_default_uncropped'] = array(
+        'label' => t('@preset image (uncropped)', array('@preset' => $preset['presetname'])),
+        'field types' => array('filefield'),
+      );
+      $formatters[$preset['presetname'] .'_linked_uncropped'] = array(
+        'label' => t('@preset image linked to node (uncropped)', array('@preset' => $preset['presetname'])),
+        'field types' => array('filefield'),
+      );
+      $formatters[$preset['presetname'] .'_imagelink_uncropped'] = array(
+        'label' => t('@preset image linked to image (uncropped)', array('@preset' => $preset['presetname'])),
+        'field types' => array('filefield'),
+      );
+      $formatters[$preset['presetname'] .'_path_uncropped'] = array(
+        'label' => t('@preset file path (uncropped)', array('@preset' => $preset['presetname'])),
+        'field types' => array('filefield'),
+      );
+      $formatters[$preset['presetname'] .'_url_uncropped'] = array(
+        'label' => t('@preset URL (uncropped)', array('@preset' => $preset['presetname'])),
+        'field types' => array('filefield'),
+      );
+    }
+  }
+
+  return $formatters;
 }
 
 function theme_imagefield_crop_widget_preview($item = NULL) {
@@ -127,3 +196,55 @@ function theme_imagefield_crop_widget_pr
   return '<img src="'. file_create_url($thumb_path) . $query_string . '" />';
 }
 
+/**
+ * Theme function to refactor the field element to use the uncropped
+ * file in the imagecache formatter.
+ *
+ * @param $element
+ *   The field element.
+ * @param $function
+ *   The theme function that should process the reformatted element.
+ * @return
+ *   The themed output from $function.
+ */
+function theme_imagefield_crop_formatter_uncropped($element, $function = '') {
+  // Get the appropriate theme function name, if empty. Can't do anything
+  // if there is no function name.
+  if ($function || ($function = _imagefield_crop_formatter_theme_function($element['#formatter']))) {
+    // Change the filepath for the item.
+    $element['#item']['filepath'] = imagefield_crop_file_admin_crop_display_path($element['#item']);
+    // Remove '_uncropped' from the formatter.
+    $element['#formatter'] = substr($element['#formatter'], 0, -10);
+    // Use function if specified, otherwise hack together the imagecache one.
+    $element['#theme'] = $function ? $function : 'theme_imagecache_'. $element['#formatter'];
+  
+    // Should this call via 'theme($function, ...)' instead?
+    return $function($element);
+  }
+}
+
+/**
+ * Helper function to return the appropriate theme function from a formatter.
+ *
+ * @param $formatter
+ *   String formatter to derive the theme function to handle the element.
+ * @return
+ *   String function name.
+ */
+function _imagefield_crop_formatter_theme_function($formatter) {
+  if (strpos($formatter, '_default_uncropped')) {
+    return 'theme_imagecache_formatter_default';
+  }
+  if (strpos($formatter, '_linked_uncropped')) {
+    return 'theme_imagecache_formatter_linked';
+  }
+  if (strpos($formatter, '_imagelink_uncropped')) {
+    return 'theme_imagecache_formatter_imagelink';
+  }
+  if (strpos($formatter, '_path_uncropped')) {
+    return 'theme_imagecache_formatter_path';
+  }
+  if (strpos($formatter, '_url_uncropped')) {
+    return 'theme_imagecache_formatter_url';
+  }
+}
\ No newline at end of file
diff -up imagefield_crop_widget.inc imagefield_crop_widget.inc
--- imagefield_crop_widget.inc	2009-11-11 03:12:54.000000000 -0500
+++ imagefield_crop_widget.inc	2010-05-16 09:57:54.000000000 -0400
@@ -219,7 +219,7 @@ function imagefield_crop_widget_value($e
     if ($field['widget']['resolution']) {
       list($scale['width'], $scale['height']) = explode('x', $field['widget']['resolution']);
     }
-    if ($crop['changed']) {
+    if ($crop['changed'] || !file_exists(imagefield_crop_file_admin_crop_display_path($file))) {
       // save crop time, for preview
       variable_set('imagefield_crop_query_string', REQUEST_TIME);
       _imagefield_crop_resize(imagefield_crop_file_admin_original_path($file),
Common subdirectories: images and images
Common subdirectories: po and po
