array( 'arguments' => array('file' => null, 'alt' => '', 'title' => '', 'attributes' => null, 'getsize' => TRUE), ), // Theme an ImageField field item. It calls imagefied_image with the proper // item properties as arguments. 'imagefield_item' => array( 'arguments' => array('item' => null), ), // imagefield_widget form element type theme function. 'imagefield_widget' => array( 'arguments' => array('element' => null), 'file' => 'imagefield_widget.inc', ), // Use to generate a preview (admin view) of an imagefield item for use in // field item forms and filefield widgets. Invoked by filefield_widget_process. 'imagefield_widget_preview' => array( 'arguments' => array('item' => null), ), // Theme function for the field item elements. allows you to place children // within the context of the parent. 'imagefield_widget_item' => array( 'arguments' => array('element' => null), ), // Generates and img tag to the admin thumbnail of an ImageField upload. 'imagefield_admin_thumbnail' => array( 'arguments' => array('item' => null), ), // ImageField formatter theme functions. 'imagefield_formatter_image_plain' => array( 'arguments' => array('element' => null), 'file' => 'imagefield_formatter.inc', ), 'imagefield_formatter_image_nodelink' => array( 'arguments' => array('element' => null), 'file' => 'imagefield_formatter.inc', ), 'imagefield_formatter_image_imagelink' => array( 'arguments' => array('element' => null), 'file' => 'imagefield_formatter.inc', ), 'imagefield_formatter_url_plain' => array( 'arguments' => array('element' => null), 'file' => 'imagefield_formatter.inc', ), 'imagefield_formatter_path_plain' => array( 'arguments' => array('element' => null), 'file' => 'imagefield_formatter.inc', ), ); } /** * Implementation of hook_elements(). */ function imagefield_elements() { $elements = array(); $elements['imagefield_widget'] = array( // Indicate to FormAPI that this element needs processing and is not simply a render element. '#input' => TRUE, // Delegate element processing to FileField, then call ImageField. '#process' => array('filefield_widget_process', 'imagefield_widget_process'), // See imagefield_widget[#process] documentation. '#value_callback' => 'imagefield_widget_value', // Delegate element validation to FileField, then call ImageField. '#element_validate' => array('filefield_widget_validate', 'imagefield_widget_validate'), '#description' => t('Changes made to the attachments are not permanent until you save this post.'), ); return $elements; } /** * Implementation of hook_file_download. */ function imagefield_file_download($filepath) { // Return headers for admin thumbnails if private files are enabled. if (strpos($filepath, '.thumb.')) { $original_path = str_replace('.thumb', '', $filepath); $original_full_path = file_create_path($original_path); $thumb_full_path = file_create_path($filepath); // Allow access to temporary thumbnails, since they're not yet associated // with a node. If not temporary, check access on the original file. $temporary = db_result(db_query("SELECT status FROM {files} WHERE filepath = '%s'", $original_full_path)); $access = ($temporary == 0 || module_invoke_all('file_download', $original_path)); if ($access && $info = getimagesize($thumb_full_path)) { return array( 'Content-Type: ' . $info['mime'], 'Content-Length: ' . filesize($thumb_full_path) ); } } } /** * Implementation of CCK's hook_widget_info(). */ function imagefield_widget_info() { $module_path = drupal_get_path('module', 'imagefield'); return array( 'imagefield_widget' => array( 'label' => t('Image'), 'field types' => array('filefield'), 'multiple values' => CONTENT_HANDLE_CORE, 'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM), 'description' => t('An edit widget for image files, including a preview of the image.'), ), ); } /** * Implementation of CCK's hook_widget_settings(). */ function imagefield_widget_settings($op, $widget) { switch ($op) { case 'form': return imagefield_widget_settings_form($widget); case 'validate': return imagefield_widget_settings_validate($widget); case 'save': return imagefield_widget_settings_save($widget); } } /** * Implementation of hook_widget(). * * Assign default properties to item and delegate to FileField. */ function imagefield_widget(&$form, &$form_state, $field, $items, $delta = 0) { // Add default values to items. // TODO: use CCK's default value callback. if (empty($items[$delta])) { $items[$delta] = array('alt' => '', 'title' => ''); } // Start with the FileField widget as a basic start. $element = module_invoke('filefield', 'widget', $form, $form_state, $field, $items, $delta); // Ensure that only web images are supported. $web_extensions = array('jpg', 'jpeg', 'gif', 'png'); $extensions = array_filter(explode(' ', $element['#upload_validators']['filefield_validate_extensions'][0])); if (empty($extensions)) { $extensions = $web_extensions; } $element['#upload_validators']['filefield_validate_extensions'][0] = implode(' ', array_intersect($extensions, $web_extensions)); // Add validators for resolutions. if (!empty($field['widget']['max_resolution']) || !empty($field['widget']['min_resolution'])) { $element['#upload_validators']['filefield_validate_image_resolution'] = array( $field['widget']['max_resolution'], $field['widget']['min_resolution'], ); } return $element; } /** * Implementation of CCK's hook_field_formatter_info(). */ function imagefield_field_formatter_info() { $module_path = drupal_get_path('module','imagefield'); $formatters = array( 'image_plain' => array( 'label' => t('Image'), 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'image_nodelink' => array( 'label' => t('Image linked to node'), 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'image_imagelink' => array( 'label' => t('Image linked to file'), 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'path_plain' => array( 'label' => t('Path to file'), 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), 'url_plain' => array( 'label' => t('URL to file'), 'field types' => array('filefield'), 'css' => array($module_path .'/imagefield.css'), 'description' => t('Displays image files in their original size.'), ), ); return $formatters; } /** * @defgroup "Theme Callbacks" * @{ * @see imagefield_theme(). */ function theme_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) { $file = (array)$file; if (!is_file($file['filepath'])) { return ''; } if ($getsize && (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath']))) { $attributes['width'] = $width; $attributes['height'] = $height; } if (!empty($title)) { $attributes['title'] = $title; } if (!empty($alt)) { $attributes['alt'] = $alt; } $url = file_create_url($file['filepath']) . '?' . $file['timestamp']; $attributes['src'] = $url; $attributes = drupal_attributes($attributes); return ''; } function theme_imagefield_item($item) { return theme('imagefield_image', $item, $item['alt'], $item['title']); } function theme_imagefield_widget_preview($item = null) { return '
' . theme('imagefield_admin_thumbnail', $item) . '
'; } function theme_imagefield_widget_item($element) { return theme('filefield_widget_item', $element); } function theme_imagefield_admin_thumbnail($item = null) { if (is_null($item) || empty($item['filepath'])) { return ''; } $thumb_path = imagefield_file_admin_thumb_path($item); return ''; } /** * @} End defgroup "Theme Callbacks". */