diff options
author | Silvio <s1lv10@uol.com.br> | 2010-08-17 18:18:54 -0300 |
---|---|---|
committer | Silvio <s1lv10@uol.com.br> | 2010-08-17 18:18:54 -0300 |
commit | c1159f9872aca3275af2a79b86692dc902726fcc (patch) | |
tree | ebce822f155bcdbabe510093868e3a1d150b0939 | |
parent | 4bbaad3b1b0bba584ea8b817e8b21801839256de (diff) | |
download | exif-c1159f9872aca3275af2a79b86692dc902726fcc.tar.gz exif-c1159f9872aca3275af2a79b86692dc902726fcc.tar.bz2 |
Syncing with CVS changes
-rw-r--r-- | CVS/Entries | 5 | ||||
-rw-r--r-- | exif.class.php | 45 | ||||
-rwxr-xr-x | exif.module | 157 |
3 files changed, 96 insertions, 111 deletions
diff --git a/CVS/Entries b/CVS/Entries index 1a9c77d..228d67b 100644 --- a/CVS/Entries +++ b/CVS/Entries @@ -1,11 +1,12 @@ /CHANGES.txt/1.1.2.13/Tue Apr 27 20:53:49 2010//TDRUPAL-6--1 /README.txt/1.6.2.3/Fri Mar 19 22:17:00 2010//TDRUPAL-6--1 -/exif.class.php/1.1.2.11/Tue Apr 27 20:53:13 2010//TDRUPAL-6--1 /exif.css/1.1.2.1/Fri Jan 23 11:13:15 2009//TDRUPAL-6--1 /exif.info/1.4.2.2/Thu Feb 5 20:11:54 2009//TDRUPAL-6--1 /exif.install/1.4.2.6/Tue Apr 27 20:53:13 2010//TDRUPAL-6--1 -/exif.module/1.9.2.15/Tue Apr 27 20:53:13 2010//TDRUPAL-6--1 /sample.jpg/1.1.2.1/Fri Jan 30 16:04:44 2009/-kb/TDRUPAL-6--1 D/exif_helper//// D/exif_location//// /.cvsignore/1.1.2.2/Tue Apr 27 21:34:24 2010//TDRUPAL-6--1 +/exif.admin.inc/1.1.2.1/Wed Jun 9 13:14:02 2010//TDRUPAL-6--1 +/exif.class.php/1.1.2.16/Result of merge//TDRUPAL-6--1 +/exif.module/1.9.2.18/Wed Aug 11 14:45:29 2010//TDRUPAL-6--1 diff --git a/exif.class.php b/exif.class.php index 045f28a..b5ad35b 100644 --- a/exif.class.php +++ b/exif.class.php @@ -67,14 +67,20 @@ Class Exif { } $exif = exif_read_data($file, 0); $arSmallExif = array(); - foreach ((array)$exif as $key => $value) { - $arSmallExif[strtolower($key)] = $value; - } + $arSmallExif = array_change_key_case((array)$exif, CASE_LOWER); + $arSmallExif['computed'] = array_change_key_case((array)$arSmallExif['computed'], CASE_LOWER); //why this function isn't recursive is beyond me + $arSmallExif['thumbnail'] = array_change_key_case((array)$arSmallExif['thumbnail'], CASE_LOWER); + $arSmallExif['comment'] = array_change_key_case((array)$arSmallExif['comment'], CASE_LOWER); $info = array(); foreach ($arTagNames as $tagName) { - if ($tagName['section'] != 'iptc' && !empty($arSmallExif[$tagName['tag']])) { - $info[$tagName['section'] .'_'. $tagName['tag']] = $arSmallExif[$tagName['tag']]; + if ($tagName['section'] != 'iptc') { + if (!empty($arSmallExif[$tagName['tag']])) { + $info[$tagName['section'] .'_'. $tagName['tag']] = $arSmallExif[$tagName['tag']]; + } + elseif (!empty($arSmallExif[$tagName['section']][$tagName['tag']])) { + $info[$tagName['section'] .'_'. $tagName['tag']] = $arSmallExif[$tagName['section']][$tagName['tag']]; + } } } return $info; @@ -86,17 +92,31 @@ Class Exif { return $ending; } - public function readIPTCTags($file, $arTagNames=array()) { + /** + * Read IPTC tags. + * + * @param String $file + * Path to image to read IPTC from + * + * @param array $arTagNames + * An array of Strings that contain the IPTC to read + * If you leave this empty nothing will be returned, unless you select a special + * return style in the $arOptions + * + * @param array $arOptions + * The following options are possible: + * style: fullSmall + * + */ + public function readIPTCTags($file, $arTagNames=array(), $arOptions=array()) { $humanReadableKey = $this->getHumanReadableIPTCkey(); $size = GetImageSize ($file, $infoImage); $iptc = empty($infoImage["APP13"]) ? array() : iptcparse($infoImage["APP13"]); $arSmallIPTC = array(); if (is_array($iptc)) { - foreach($iptc as $key => $value) - { + foreach ($iptc as $key => $value) { $resultTag = ""; - foreach($value as $innerkey => $innervalue) - { + foreach ($value as $innerkey => $innervalue) { if( ($innerkey+1) != count($value) ) { $resultTag .= $innervalue . ", "; } @@ -107,6 +127,11 @@ Class Exif { $arSmallIPTC[$humanReadableKey[$key]] = $resultTag; } } + + if ($arOptions['style'] == 'fullSmall') { + return $arSmallIPTC; + } + $info = array(); foreach ($arTagNames as $tagName) { if ($tagName['section'] == "iptc") { diff --git a/exif.module b/exif.module index 734ee92..ecbbd6e 100755 --- a/exif.module +++ b/exif.module @@ -1,5 +1,5 @@ <?php -// $Id: exif.module,v 1.9.2.15 2010/04/27 20:53:13 rapsli Exp $: +// $Id: exif.module,v 1.9.2.18 2010/07/23 17:47:46 rapsli Exp $: /** * @file implementing the drupal api @@ -15,6 +15,7 @@ function exif_menu() { 'access arguments' => array('administer site configuration'), 'description' => t('Display available fields'), 'access callback' => 'user_access', + 'file' => 'exif.admin.inc', 'type' => MENU_NORMAL_ITEM, ); $items['admin/settings/exif/general'] = array( @@ -23,6 +24,7 @@ function exif_menu() { 'access arguments' => array('administer site configuration'), 'description' => t('Display available fields'), 'access callback' => 'user_access', + 'file' => 'exif.admin.inc', 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items['admin/settings/exif/config'] = array( @@ -32,48 +34,13 @@ function exif_menu() { 'access arguments' => array('administer site configuration'), 'description' => t('Some Settings'), 'access callback' => 'user_access', + 'file' => 'exif.admin.inc', 'type' => MENU_LOCAL_TASK, ); return $items; } /** - * The form definition for the admin settings - * @return array - * form definition - */ -function exif_admin_settings_form() { - $forms = array(); - /*$forms['exif_granularity'] = array( - '#type' => 'select', - '#title' => t('Granularity'), - '#options' => array(0 => t('Default'), 1 => ('Day')), - '#default_value' => variable_get('exif_granularity', 0), - '#description' => t('If a timestamp is select (for example the date the picture was taken), you can specify here how granular the timestamp should be. If you select default it will just take whatever is available in the picture. If you select Day, the Date saved will look something like 13-12-2008. This can be useful if you want to use some kind of grouping on the data.'), - );*/ - - $all_nodetypes = node_get_types(); - $all_nt = array(); - foreach ($all_nodetypes as $item) { - $all_nt[$item->type] = $item->name; - } - $forms['exif_nodetypes'] = array( - '#type' => 'checkboxes', - '#title' => t('Nodetypes'), - '#options' => $all_nt, - '#default_value' => variable_get('exif_nodetypes', array()), - '#description' => t('Select nodetypes which should be checked for exif data. Incase the nodetypes contains more than one filefield, make sure that the imagefield is the first one!!!!'), - ); - - $forms['exif_update'] = array( - '#type' => 'checkbox', - '#title' => t('Refresh on node update'), - '#default_value' => variable_get('exif_update', TRUE), - '#description' => t('If you enable this option, Exif data is being updated when the node is being updated.'), - ); - return system_settings_form($forms); -} -/** * implementation of hook_nodeapi */ function exif_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { @@ -108,7 +75,7 @@ function exif_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { $data1 = _exif_reformat($exif->readExifTags($file, $ar_exif_fields)); $data2 = $exif->readIPTCTags($file, $ar_exif_fields); - + if (class_exists('SXMPFiles')) { $data3 = $exif->readXMPTags($file, $ar_exif_fields); $data = array_merge($data1, $data2, $data3); @@ -124,9 +91,12 @@ function exif_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { foreach ($ar_exif_fields as $ar_exif_field) { $exif_name = $ar_exif_field['section'] .'_'. $ar_exif_field['tag']; $exif_value = isset($data[$exif_name]) ? $data[$exif_name] : NULL; + $field_name = 'field_'. $exif_name; if (! $exif_value) { - $node->{$field_name}[0]['value'] = NULL; + if (variable_get('exif_empty_values', TRUE)) { + $node->{$field_name}[0]['value'] = NULL; + } continue; } $field = $fields[$field_name]; @@ -165,10 +135,10 @@ function exif_date_format_types() { */ function exif_date_formats() { return array( - array( + array( 'type' => 'exif', 'format' => 'Y:m:d H:i:s', - ), + ), ); } @@ -264,62 +234,6 @@ function _exif_get_image_path($fields, &$node) { return NULL; } -/** - * Just some help page. Gives you an overview over the available tags - * @return string html - */ -function exif_admin_settings() { - drupal_add_css(drupal_get_path('module', 'exif') .'/exif.css'); - $filepath = drupal_get_path('module', 'exif') .'/sample.jpg'; - $exif = _exif_get_class(); - $ar_exif = read_exif_data($filepath, 0, TRUE); - // CCK field names must be lowercase - $ar_exif = array_change_key_case($ar_exif, CASE_LOWER); - - $out = t('This is an overview over the most common data that is extracted with the exif module. How to read this table: The grey table header would be the key identifier and the following attributes would be the field to read.'); - $out .= ' ' . t('For example: If you want to import datetimeoriginal into an CCK field, you would name the CCK field field_exif_datetimeoriginal. Since this is a date field you can use a datetime field.'); - $rows1 = array(); - $help = t('This would be the keyword for your CCK field.'); - foreach ($ar_exif as $key => $value) { - if (is_array($value)) { - $value = _exif_reformat($value); - $rows1[] = array('data' => array($key, $help), 'class' => 'tag_type'); - foreach ($value as $key2 => $value2) { - $rows1[] = array('data' => array($key2, check_plain(utf8_encode($value2)))); - } - } - - } - $human_readable_key = $exif->getHumanReadableIPTCkey(); - $size = GetImageSize($filepath, $info_image); - $iptc = iptcparse($info_image["APP13"]); - $rows2 = array(); - $help = t('This would be the keyword for your CCK field.'); - if (is_array($iptc)) { - $rows2[] = array('data' => array('IPTC', $help), 'class' => 'tag_type'); - foreach ($iptc as $key => $value) { - $result_tag = ""; - foreach ($value as $innerkey => $innervalue) { - if ( ($innerkey+1) != count($value) ) { - $result_tag .= $innervalue .", "; - } - else { - $result_tag .= $innervalue; - } - } - $rows2[] = array('data' => array($human_readable_key[$key], check_plain(utf8_encode($result_tag)))); - } - } - - - $rows = array_merge($rows1, $rows2); - $header = array(t('Key'), t('Value')); - $out .= theme('table', $header, $rows, array('id' => 'exif-fields')); - // TODO Prevent binary data values from busting the page layout - return $out; -} - - /** * Helper function to reformat fields where required. @@ -336,7 +250,7 @@ function _exif_reformat($data) { if (is_array($value)) { $value = array_change_key_case($value, CASE_LOWER); } - + // Check for individual keys switch ($key) { case 'gpslatitude': @@ -354,7 +268,7 @@ function _exif_reformat($data) { case 'gps_gpslongitude': $value = _exif_DMS2D($value, $data['gps_gpslongituderef']); break; - + } } return $data; @@ -386,3 +300,48 @@ function _exif_get_class() { $exif = Exif::getInstance(); return $exif; } + +/** + * Implementation of hook_hoken_list + * @param array $type + */ +function fast_gallery_token_list($type = 'node') { + if ($type == 'node') { + $exif = _exif_get_class(); + $ar_iptc = $exif->getHumanReadableIPTCkey(); + foreach ($ar_iptc as $iptc) { + $tokens['iptc']['iptc_' . $iptc] = 'IPTC Field: ' . $iptc; + } + return $tokens; + } +} + +/** + * implementation of hook_token_values + * @param unknown_type $type + * @param unknown_type $object + * @param unknown_type $options + */ +function fast_gallery_token_values($type, $object = NULL, $options = array()) { + if ($type == 'node') { + $node = $object; + $exif = _exif_get_class(); + $ar_iptc = $exif->getHumanReadableIPTCkey(); + + $info = content_types($node->type); + $fields = $info['fields']; + //get the path to the image + $image_path = _exif_get_image_path($fields, $node); + + //dsm("start reading"); + $iptc_values = $exif->readIPTCTags($image_path, array(), array('style' => 'fullSmall')); + //dsm($iptc_values); + + // TODO: needs to be finished + foreach ($iptc_values as $key => $iptc) { + $tokens['iptc_' . $key] = 'IPTC Field: ' . utf8_encode($iptc); + } + //dsm($tokens); + return $tokens; + } +}
\ No newline at end of file |