Index: image.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/image/image.module,v retrieving revision 1.197.2.2 diff -u -F^f -r1.197.2.2 image.module --- image.module 18 Jul 2006 14:00:52 -0000 1.197.2.2 +++ image.module 14 Aug 2006 00:05:36 -0000 @@ -334,6 +334,39 @@ function image_delete($node) { } /** + * Implementation of hook_views_tables() + */ +function image_views_tables() { + $tables['image'] = array( + 'name' => 'node', + 'fields' => array( + 'nid' => array( + 'name' => t('Image: Display Image'), + 'handler' => array( + 'views_handler_image_img' => t('Image'), + 'views_handler_image_img_link' => t('Image with link'), + ), + 'query_handler' => 'views_query_handler_display_image', + 'notafield' => true, + 'sortable' => false, + ), + ), + 'filters' => array( + 'filename' => array( + 'name' => t('Image: Size'), + 'list' => 'views_handler_filter_image_size', + 'list-type' => 'list', + 'operator' => 'views_handler_operator_or', + 'value-type' => 'string', + 'handler' => 'views_handler_image_filter_size', + 'help' => t('Include or Exclude these image sizes.'), + ), + ), + ); + return $tables; +} + +/** * Create an tag for an image. */ function image_display(&$node, $label = 'preview', $attributes = array()) { @@ -429,6 +462,51 @@ function image_get_latest($count = 1, $t } /** + * Views handler for displaying the image. + */ +function views_handler_image_img($fieldinfo, $fielddata, $value, $data) { + $node = node_load($data->nid); + return theme('image_display', $node, '', file_create_url($data->filepath), array()); +} + +/** + * Views handler for displaying the image in a link to the the image node + */ +function views_handler_image_img_link($fieldinfo, $fielddata, $value, $data) { + $node = node_load($data->nid); + return l(theme('image_display', $node, '', file_create_url($data->filepath), array()), "node/{$node->nid}", array(), NULL, NULL, FALSE, TRUE); +} + +/** + * Views - Generate a list of all the valid sizes that are available + */ +function views_handler_filter_image_size($op) { + foreach (_image_get_sizes() as $size) { + $a[$size['label']] = $size['label']; + } + $a['_original'] = 'original'; + return $a; +} + +/** + * Views filter based on size of the image + */ +function views_handler_image_filter_size($op, $filter, $filterdata, &$query) { + switch ($op) { + case 'handler': + $query->add_field('filename', 'files'); + $query->add_where("files.filename IN ('". implode("','", $filter['value']) ."')"); + } +} + +/** + * Views - Add the filepath field to the query + */ +function views_query_handler_display_image($field, $fieldinfo, &$query) { + $query->add_field('filepath', 'files'); +} + +/** * Verify the image module and toolkit settings. */ function _image_check_settings() {