Index: node_images.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/node_images/node_images.module,v retrieving revision 1.11.2.16 diff -u -p -r1.11.2.16 node_images.module --- node_images.module 3 Feb 2009 13:45:50 -0000 1.11.2.16 +++ node_images.module 29 Dec 2009 02:38:33 -0000 @@ -982,5 +982,16 @@ function _node_images_translate(&$file, $context = _node_images_build_i18nstrings_context($file); if (module_exists('i18nstrings') && function_exists('tt')) { $file->description = tt($context, $file->description, NULL, $update); - } -} \ No newline at end of file + } +} + +/** +* Implementation of hook_views_api(). +* @return Array with Views API version. +*/ +function node_images_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'node_images') .'/views', + ); +} diff -Nup views/node_images.views.inc views/node_images.views.inc --- views/node_images.views.inc 1970-01-01 03:00:00.000000000 +0300 +++ views/node_images.views.inc 2009-12-29 04:38:18.000000000 +0300 @@ -0,0 +1,193 @@ + array( + 'left_field' => 'nid', + 'field' => 'nid', + 'type' => 'LEFT',// 'INNER' + ), + ); + // Relationship to the 'Node' table + /*$data['node_images']['nid'] = array( + 'title' => t('Node'), + 'help' => t('The particular node the Node Images is attached to'), + 'relationship' => array( + 'label' => t('Node'), + 'base' => 'node', + 'base field' => 'nid', + // This allows us to not show this relationship if the base is already + // node so users won't create circular relationships. + 'skip base' => array('node', 'node_revisions'), + ), + );*/ + + $data['node_images']['all_images'] = array( + 'title' => t('Display node images'), + 'help' => t('Display all node images in one field.'), + 'field' => array( + 'handler' => 'views_handler_field_node_images', + ), +/* 'filter' => array( + 'handler' => 'views_handler_filter_flat_status', + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + 'label' => t('State'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ),*/ + // Information for accepting a nid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_node_nid', + 'parent' => 'views_handler_argument_numeric', // make sure parent is included + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + 'validate type' => 'nid', + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a nid. + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + $data['node_images']['lightest_image'] = array( + 'title' => t('Display lightest image'), + 'help' => t('Display the lightest node image.'), + 'field' => array( + 'handler' => 'views_handler_field_node_images_lightest', + ), + // Information for accepting a nid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_node_nid', + 'parent' => 'views_handler_argument_numeric', // make sure parent is included + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + 'validate type' => 'nid', + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a nid. + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); +/* + $tables['node_images'] = array( + 'name' => 'node_images', + 'provider' => 'internal', + 'join' => array( + 'left' => array( + 'table' => 'node', + 'field' => 'nid' + ), + 'right' => array( + 'field' => 'nid' + ), + ), + 'fields' => array( + 'node_images_display' => array( + 'name' => t('Node Images: Display node images'), + 'notafield' => TRUE, + 'query_handler' => '_node_images_query_handler_display', + 'handler' => array( + '_node_images_views_handler_image_thumb' => t('Thumbnails'), + '_node_images_views_handler_image_fullsize' => t('Full size'), + ), + 'sortable' => false, + 'help' => t('Display all node images in one field.'), + ), + ), + 'filters' => array( + 'nid' => array( + 'name' => t('Node images: Has node images'), + 'operator' => array('=' => t('Exists')), + 'list' => 'views_handler_operator_yesno', + 'list-type' => 'select', + 'handler' => '_node_images_handler_images_exist', + 'help' => t('Filter whether the node has node images.'), + ), + ), + ); + return $tables;*/ + return $data; +} + +/** + * Implementation of hook_views_handlers(). + */ +function node_images_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'node_images') . '/views', + ), + 'handlers' => array( + 'views_handler_field_node_images' => array( + 'parent' => 'views_handler_field_node', + ), + 'views_handler_field_node_images_lightest' => array( + 'parent' => 'views_handler_field_node', + ), + ), + ); +} +/* +function _node_images_query_handler_display($field, $fieldinfo, &$query) { + $query->add_field('nid', 'node'); +} +*/ +/** + * Views handler for displaying images. + */ +/*function _node_images_views_handler_image_thumb($fieldinfo, $fielddata, $value, $data, $thumb = TRUE) { + $node = node_load(array('nid' => $data->nid)); + $format = ($thumb ? 'thumbs' :'fullsize'); + return theme('node_images_view', $node, TRUE, FALSE, $format); +} +*/ +/** + * Views handler for displaying images in links to a popup window + */ +/*function _node_images_views_handler_image_fullsize($fieldinfo, $fielddata, $value, $data) { + return _node_images_views_handler_image_thumb($fieldinfo, $fielddata, $value, $data, FALSE); +} +*/ +/** + * Views handler for filtering + */ +/*function _node_images_handler_images_exist($op, $filter, $filterdata, &$query) { + switch ($op) { + case 'handler': + $query->ensure_table('node_images'); + if ($filter['value']) { + $query->set_distinct(); + $table_data = _views_get_tables(); + $joins = array('type' => 'inner'); + $joins = array_merge($joins, $table_data['node_images']['join']); + $query->joins['node_images'][1] = $joins; + } + else { + $query->add_where('ISNULL(node_images.id)'); + } + } +}*/ diff -Nup views/views_handler_field_node_images.inc views/views_handler_field_node_images.inc --- views/views_handler_field_node_images.inc 1970-01-01 03:00:00.000000000 +0300 +++ views/views_handler_field_node_images.inc 2009-12-29 05:08:59.000000000 +0300 @@ -0,0 +1,64 @@ +additional_fields['nid'] = 'nid'; + } +*/ + function option_definition() { + $options = parent::option_definition(); + + $options['link_to_node'] = array('default' => FALSE); + $options['thumb'] = array('default' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['thumb'] = array( + '#type' => 'checkbox', + '#title' => t('Thumbnails'), + '#description' => t('If checked, Thumbmails will be displayed.'), + '#default_value' => $this->options['thumb'], + ); + } + + function element_type() { + return 'div'; + } + + function query() { + //$this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + $nid = $values->{$this->aliases['nid']}; + $value = '
'; + + $result = db_query("SELECT ni.* FROM {node_images} ni WHERE ni.nid = %d", $nid); + while ($image = db_fetch_object($result)) { + //$path = variable_get('node_images_path', 'node_images'); + if ($this->options['thumb']) { + //$path = file_create_path($path . $image->thumbpath); + $path = file_create_path($image->thumbpath); + } + else { + //$path = file_create_path($path . $image->filepath); + $path = file_create_path($image->filepath); + } + $description = check_plain($image->description); + + $value .= '
' . theme('image', $path, $description, $description) . '
'; + } + + return $value . '
'; + } +} diff -Nup views/views_handler_field_node_images_lightest.inc views/views_handler_field_node_images_lightest.inc --- views/views_handler_field_node_images_lightest.inc 1970-01-01 03:00:00.000000000 +0300 +++ views/views_handler_field_node_images_lightest.inc 2009-12-29 05:11:43.000000000 +0300 @@ -0,0 +1,53 @@ + TRUE); + $options['thumb'] = array('default' => TRUE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['thumb'] = array( + '#type' => 'checkbox', + '#title' => t('Thumbnails'), + '#description' => t('If checked, Thumbmails will be displayed.'), + '#default_value' => $this->options['thumb'], + ); + } + + function query() { + $this->add_additional_fields(); + } + + function render($values) { + $nid = $values->{$this->aliases['nid']}; + $value = '
'; + + $image = db_fetch_object(db_query_range("SELECT ni.* FROM {node_images} ni INNER JOIN {node} n ON n.nid = ni.nid WHERE ni.nid = %d ORDER BY ni.weight", $nid, 0, 1 )); + + if (isset($image->id)) { + //$path = variable_get('node_images_path', 'node_images'); + if ($this->options['thumb']) { + //$path = file_create_path($path . $image->thumbpath); + $path = file_create_path($image->thumbpath); + } + else { + //$path = file_create_path($path . $image->filepath); + $path = file_create_path($image->filepath); + } + $description = check_plain($image->description); + + $value .= theme('image', $path, $description, $description); + } + + return $value . '
'; + } +}