summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--imagecache.module118
1 files changed, 69 insertions, 49 deletions
diff --git a/imagecache.module b/imagecache.module
index 402f62b..807d270 100644
--- a/imagecache.module
+++ b/imagecache.module
@@ -147,23 +147,23 @@ function imagecache_theme() {
foreach (imagecache_presets() as $preset) {
$theme['imagecache_formatter_'. $preset['presetname'] .'_default'] = array(
'arguments' => array('element' => NULL),
- 'function' => 'theme_imagecache_formatter',
+ 'function' => 'theme_imagecache_formatter_default',
);
$theme['imagecache_formatter_'. $preset['presetname'] .'_linked'] = array(
'arguments' => array('element' => NULL),
- 'function' => 'theme_imagecache_formatter',
+ 'function' => 'theme_imagecache_formatter_linked',
);
$theme['imagecache_formatter_'. $preset['presetname'] .'_imagelink'] = array(
'arguments' => array('element' => NULL),
- 'function' => 'theme_imagecache_formatter',
+ 'function' => 'theme_imagecache_formatter_imagelink',
);
$theme['imagecache_formatter_'. $preset['presetname'] .'_path'] = array(
'arguments' => array('element' => NULL),
- 'function' => 'theme_imagecache_formatter',
+ 'function' => 'theme_imagecache_formatter_path',
);
$theme['imagecache_formatter_'. $preset['presetname'] .'_url'] = array(
'arguments' => array('element' => NULL),
- 'function' => 'theme_imagecache_formatter',
+ 'function' => 'theme_imagecache_formatter_url',
);
}
@@ -647,57 +647,77 @@ function imagecache_field_formatter_info() {
return $formatters;
}
-function theme_imagecache_formatter($element) {
- if (isset($element['#item']['nid']) && $node = node_load($element['#item']['nid'])) {
- return imagecache_field_formatter($element['#field_name'], $element['#item'], $element['#formatter'], $node);
+function theme_imagecache_formatter_default($element) {
+ // Inside a view $element may contain NULL data. In that case, just return.
+ if (empty($element['#item']['fid'])) {
+ return '';
}
-}
+ list($presetname, $style) = explode('_', $element['#formatter'], 2);
+ $item = $element['#item'];
+ $item['data']['alt'] = isset($item['data']['alt']) ? $item['data']['alt'] : '';
+ $item['data']['title'] = isset($item['data']['title']) ? $item['data']['title'] : NULL;
-/**
- * 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'];
+ $class = "imagecache imagecache-$presetname imagecache-$style imagecache-{$element['#formatter']}";
+ return theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title'], array('class' => $class));
+}
+
+function theme_imagecache_formatter_linked($element) {
+ // Inside a view $element may contain NULL data. In that case, just return.
+ if (empty($element['#item']['fid'])) {
+ return '';
}
- // Views does not load the file for us, while CCK display fields does.
- if (empty($item['filepath'])) {
- $item = array_merge($item, field_file_load($item['fid']));
+
+ list($presetname, $style) = explode('_', $element['#formatter'], 2);
+ $item = $element['#item'];
+ $item['data']['alt'] = isset($item['data']['alt']) ? $item['data']['alt'] : '';
+ $item['data']['title'] = isset($item['data']['title']) ? $item['data']['title'] : NULL;
+
+ $imagetag = theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title']);
+ $path = empty($item['nid']) ? '' : 'node/'. $item['nid'];
+ $class = "imagecache imagecache-$presetname imagecache-$style imagecache-{$element['#formatter']}";
+ return l($imagetag, $path, array('attributes' => array('class' => $class), 'html' => TRUE));
+}
+
+function theme_imagecache_formatter_imagelink($element) {
+ // Inside a view $element may contain NULL data. In that case, just return.
+ if (empty($element['#item']['fid'])) {
+ return '';
}
- if (is_string($item['data'])) {
- $item['data'] = unserialize($item['data']);
+
+ list($presetname, $style) = explode('_', $element['#formatter'], 2);
+ $item = $element['#item'];
+ $item['data']['alt'] = isset($item['data']['alt']) ? $item['data']['alt'] : '';
+ $item['data']['title'] = isset($item['data']['title']) ? $item['data']['title'] : NULL;
+
+ $imagetag = theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title']);
+ $path = file_create_url($item['filepath']);
+ $class = "imagecache imagecache-$presetname imagecache-$style imagecache-{$element['#formatter']}";
+ return l($imagetag, $path, array('attributes' => array('class' => $class), 'html' => TRUE));
+}
+
+function theme_imagecache_formatter_path($element) {
+ // Inside a view $element may contain NULL data. In that case, just return.
+ if (empty($element['#item']['fid'])) {
+ return '';
}
- $alt = empty($item['data']['alt']) ? '' : $item['data']['alt'];
- $title = empty($item['data']['title']) ? '' : $item['data']['title'];
- $parts = explode('_', $formatter);
- $style = array_pop($parts);
- $presetname = implode('_', $parts);
-
- $class = "imagecache imagecache-$presetname imagecache-$style imagecache-$formatter";
- if ($preset = imagecache_preset_by_name($presetname)) {
- $item['filepath'] = $item['fid'] == 'upload' ? $item['preview'] : $item['filepath'];
- switch ($style) {
- case 'linked':
- $imagetag = theme('imagecache', $presetname, $item['filepath'], $alt, $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'], $alt, $title);
- return l($imagetag, $original_image_url, array('attributes' => array('class' => $class), 'html' => TRUE));
-
- case 'url':
- return imagecache_create_url($presetname, $item['filepath']);
-
- case 'path':
- return imagecache_create_path($presetname, $item['filepath']);
-
- default:
- return theme('imagecache', $presetname, $item['filepath'], $alt, $title, array('class' => $class));
- }
+
+ list($presetname, $style) = explode('_', $element['#formatter'], 2);
+ $item = $element['#item'];
+
+ return imagecache_create_path($presetname, $item['filepath']);
+}
+
+function theme_imagecache_formatter_url($element) {
+ // Inside a view $element may contain NULL data. In that case, just return.
+ if (empty($element['#item']['fid'])) {
+ return '';
}
- return '<!-- imagecache formatter preset('. $presetname .') not found! -->';
+
+ list($presetname, $style) = explode('_', $element['#formatter'], 2);
+ $item = $element['#item'];
+
+ return imagecache_create_url($presetname, $item['filepath']);
}
/**