diff --git a/colorbox.install b/colorbox.install index e1c8adf..0508f79 100644 --- a/colorbox.install +++ b/colorbox.install @@ -40,6 +40,23 @@ function colorbox_requirements($phase) { 'description' => $t('You need to download a later version of the !colorbox and replace the old version located in the %path directory on your server.', array('!colorbox' => l($t('Colorbox plugin'), $library['download url']), '%path' => $library['library path'])), ); } + + if (!function_exists('iptcparse')) { + $requirements['iptcparse'] = array( + 'title' => $t('IPTC library is not available'), + 'description' => $t('The Function iptcparse is not available on the system. Please ensure the PHP module named GD has been installed.'), + 'value' => $t('GD library is not available'), + 'severity' => REQUIREMENT_ERROR, + ); + } + if (!function_exists('GetImageSize')) { + $requirements['GetImageSize'] = array( + 'title' => $t('Image library is not available'), + 'description' => $t('The Function GetImageSize is not available on the system. Please ensure the PHP module named GD has been installed.'), + 'value' => $t('GD library is not available'), + 'severity' => REQUIREMENT_ERROR, + ); + } } return $requirements; diff --git a/colorbox.module b/colorbox.module index 816aee0..becb89b 100644 --- a/colorbox.module +++ b/colorbox.module @@ -329,6 +329,9 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $ 'title' => t('Title text'), 'alt' => t('Alt text'), 'node_title' => t('Content title'), + 'iptc_title' => t('IPTC title'), + 'iptc_caption' => t('IPTC caption'), + 'iptc_copyright' => t('IPTC copyright'), 'custom' => t('Custom (with tokens)'), 'none' => t('None'), ); @@ -439,6 +442,9 @@ function colorbox_field_formatter_settings_summary($field, $instance, $view_mode 'title' => t('Title text'), 'alt' => t('Alt text'), 'node_title' => t('Content title'), + 'iptc_title' => t('IPTC title'), + 'iptc_caption' => t('IPTC caption'), + 'iptc_copyright' => t('IPTC copyright'), 'custom' => t('Custom (with tokens)'), 'none' => t('None'), ); @@ -502,3 +508,46 @@ function colorbox_insert_content($item, $style, $widget) { function colorbox_gallery_exists() { return FALSE; } + +/** +* Implements hook_token_info(). +*/ +function colorbox_token_info() { + $type = array( + 'name' => t('IPTC'), + 'description' => t('Tokens related to the IPTC record of an image'), + 'needs-data' => 'iptc', + ); + $iptc['title'] = array( + 'name' => t('IPTC title'), + 'description' => t('Title field from the IPTC record of an image'), + ); + $iptc['caption'] = array( + 'name' => t('IPTC caption'), + 'description' => t('Description field from the IPTC record of an image'), + ); + $iptc['copyright'] = array( + 'name' => t('IPTC copyright'), + 'description' => t('Copyright Notice field from the IPTC record of an image'), + ); + return array( + 'types' => array('iptc' => $type), + 'tokens' => array('iptc' => $iptc), + ); +} + +/** + * Implements hook_tokens(). + */ +function colorbox_tokens($type, $tokens, array $data = array(), array $options = array()) { + $replacements = array(); + + if ($type == 'iptc' && !empty($data['iptc'])) { + $iptc = $data['iptc']; + foreach ($tokens as $name => $original) { + $replacements[$original] = $iptc[$name]; + } + } + + return $replacements; +} diff --git a/colorbox.theme.inc b/colorbox.theme.inc index beafb1d..3100b1e 100644 --- a/colorbox.theme.inc +++ b/colorbox.theme.inc @@ -62,8 +62,21 @@ function theme_colorbox_image_formatter($variables) { case 'node_title': $caption = $entity_title; break; + case 'iptc_title': + $iptc_fields = _colorbox_get_iptc_fields($image); + $caption = $iptc_fields['title']; + break; + case 'iptc_caption': + $iptc_fields = _colorbox_get_iptc_fields($image); + $caption = $iptc_fields['caption']; + break; + case 'iptc_copyright': + $iptc_fields = _colorbox_get_iptc_fields($image); + $caption = $iptc_fields['copyright']; + break; case 'custom': - $caption = token_replace($settings['colorbox_caption_custom'], array($entity_type => $entity, 'file' => (object) $item), array('clear' => TRUE)); + $iptc_fields = _colorbox_get_iptc_fields($image); + $caption = token_replace($settings['colorbox_caption_custom'], array($entity_type => $entity, 'file' => (object) $item, 'iptc' => $iptc_fields), array('clear' => TRUE)); break; default: $caption = ''; @@ -110,6 +123,30 @@ function theme_colorbox_image_formatter($variables) { } /** + * Returns a list of common IPTC fields from an image. + * + * @param $image + * The Image data structure. + * + * @return + * An associative array of common IPTC field values from the image, + * keyed with the common English names of the IPTC fields. + */ +function _colorbox_get_iptc_fields($image) { + $size = getimagesize($image['path'], $imgInfo); + $iptc_data = $imgInfo["APP13"]; + $iptc_fields = array(); + if (!empty($iptc_data)) { + $iptc = iptcparse($iptc_data); + $iptc_fields['title'] = $iptc['2#005'][0]; + $iptc_fields['caption'] = $iptc['2#120'][0]; + $iptc_fields['copyright'] = $iptc['2#116'][0]; + } + + return $iptc_fields; +} + +/** * Returns HTML for an image using a specific Colorbox image style. * * @param $variables