aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_metadata.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/functions_metadata.inc.php')
-rw-r--r--include/functions_metadata.inc.php117
1 files changed, 98 insertions, 19 deletions
diff --git a/include/functions_metadata.inc.php b/include/functions_metadata.inc.php
index 4549ca7c6..fc74e2aec 100644
--- a/include/functions_metadata.inc.php
+++ b/include/functions_metadata.inc.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -22,14 +22,21 @@
// +-----------------------------------------------------------------------+
/**
- * returns informations from IPTC metadata, mapping is done at the beginning
- * of the function
+ * @package functions\metadata
+ */
+
+
+/**
+ * returns informations from IPTC metadata, mapping is done in this function.
*
* @param string $filename
+ * @param array $map
* @return array
*/
function get_iptc_data($filename, $map)
{
+ global $conf;
+
$result = array();
$imginfo = array();
@@ -60,10 +67,15 @@ function get_iptc_data($filename, $map)
foreach (array_keys($map, $iptc_key) as $pwg_key)
{
- // in case the origin of the photo is unsecure (user upload), we
- // remove HTML tags to avoid XSS (malicious execution of
- // javascript)
- $result[$pwg_key] = strip_tags($value);
+ $result[$pwg_key] = $value;
+
+ if (!$conf['allow_html_in_metadata'])
+ {
+ // in case the origin of the photo is unsecure (user upload), we
+ // remove HTML tags to avoid XSS (malicious execution of
+ // javascript)
+ $result[$pwg_key] = strip_tags($result[$pwg_key]);
+ }
}
}
}
@@ -73,9 +85,9 @@ function get_iptc_data($filename, $map)
}
/**
- * return a cleaned IPTC value
+ * return a cleaned IPTC value.
*
- * @param string value
+ * @param string $value
* @return string
*/
function clean_iptc_value($value)
@@ -95,23 +107,41 @@ function clean_iptc_value($value)
$value = trigger_event('clean_iptc_value', $value);
if ( ($qual = qualify_utf8($value)) != 0)
{// has non ascii chars
- $value = convert_charset( $value,
- $qual>0 ? 'utf-8' : 'iso-8859-1',
- get_pwg_charset() );
+ if ($qual>0)
+ {
+ $input_encoding = 'utf-8';
+ }
+ else
+ {
+ $input_encoding = 'iso-8859-1';
+ if (function_exists('iconv') or function_exists('mb_convert_encoding'))
+ {
+ // using windows-1252 because it supports additional characters
+ // such as "oe" in a single character (ligature). About the
+ // difference between Windows-1252 and ISO-8859-1: the characters
+ // 0x80-0x9F will not convert correctly. But these are control
+ // characters which are almost never used.
+ $input_encoding = 'windows-1252';
+ }
+ }
+
+ $value = convert_charset($value, $input_encoding, get_pwg_charset());
}
}
return $value;
}
/**
- * returns informations from EXIF metadata, mapping is done at the beginning
- * of the function
+ * returns informations from EXIF metadata, mapping is done in this function.
*
* @param string $filename
+ * @param array $map
* @return array
*/
function get_exif_data($filename, $map)
{
+ global $conf;
+
$result = array();
if (!function_exists('read_exif_data'))
@@ -122,7 +152,9 @@ function get_exif_data($filename, $map)
// Read EXIF data
if ($exif = @read_exif_data($filename))
{
- $exif = trigger_event('format_exif_data', $exif, $filename, $map );
+ $exif = trigger_event('format_exif_data', $exif, $filename, $map);
+
+ // configured fields
foreach ($map as $key => $field)
{
if (strpos($field, ';') === false)
@@ -141,15 +173,62 @@ function get_exif_data($filename, $map)
}
}
}
+
+ // GPS data
+ $gps_exif = array_intersect_key($exif, array_flip(array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude')));
+ if (count($gps_exif) == 4)
+ {
+ if (
+ is_array($gps_exif['GPSLatitude']) and in_array($gps_exif['GPSLatitudeRef'], array('S', 'N')) and
+ is_array($gps_exif['GPSLongitude']) and in_array($gps_exif['GPSLongitudeRef'], array('W', 'E'))
+ )
+ {
+ $result['latitude'] = parse_exif_gps_data($gps_exif['GPSLatitude'], $gps_exif['GPSLatitudeRef']);
+ $result['longitude'] = parse_exif_gps_data($gps_exif['GPSLongitude'], $gps_exif['GPSLongitudeRef']);
+ }
+ }
}
- foreach ($result as $key => $value)
+ if (!$conf['allow_html_in_metadata'])
{
- // in case the origin of the photo is unsecure (user upload), we remove
- // HTML tags to avoid XSS (malicious execution of javascript)
- $result[$key] = strip_tags($value);
+ foreach ($result as $key => $value)
+ {
+ // in case the origin of the photo is unsecure (user upload), we remove
+ // HTML tags to avoid XSS (malicious execution of javascript)
+ $result[$key] = strip_tags($value);
+ }
}
return $result;
}
+
+
+/**
+ * Converts EXIF GPS format to a float value.
+ * @since 2.6
+ *
+ * @param string[] $raw eg:
+ * - 41/1
+ * - 54/1
+ * - 9843/500
+ * @param string $ref 'S', 'N', 'E', 'W'. eg: 'N'
+ * @return float eg: 41.905468
+ */
+function parse_exif_gps_data($raw, $ref)
+{
+ foreach ($raw as &$i)
+ {
+ $i = explode('/', $i);
+ $i = $i[1]==0 ? 0 : $i[0]/$i[1];
+ }
+ unset($i);
+
+ $v = $raw[0] + $raw[1]/60 + $raw[2]/3600;
+
+ $ref = strtoupper($ref);
+ if ($ref == 'S' or $ref == 'W') $v= -$v;
+
+ return $v;
+}
+
?> \ No newline at end of file