From 0d60e32584aeb64d0f4b8844c5ef49e57a0eada2 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 27 Apr 2010 18:10:58 -0300 Subject: Checking namespace availability before asking for metadata --- exif.class.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/exif.class.php b/exif.class.php index 62f01c5..3913927 100644 --- a/exif.class.php +++ b/exif.class.php @@ -173,6 +173,9 @@ Class Exif { // Get XMP metadata into the object. if ($xmpfiles->GetXMP($xmpmeta)) { + // Sort metadata. + $xmpmeta->Sort(); + return array('files' => $xmpfiles, 'meta' => $xmpmeta); } @@ -210,18 +213,17 @@ Class Exif { $xmpfiles = $xmp['files']; $xmpmeta = $xmp['meta']; - // Sort. - $xmpmeta->Sort(); - - // Read XMP data. - if ($config['type'] == 'property') { - $value = @$xmpmeta->GetProperty($config['name'], $config['ns']); - } - elseif ($config['type'] == 'array') { - $value = @$xmpmeta->GetArrayItem($config['name'], $key, $config['ns']); - } - elseif ($config['type'] == 'struct') { - $value = @$xmpmeta->GetStructField($config['ns'], $config['struct'], $config['ns'], $config['name']); + // Try to read XMP data if the namespace is available. + if(@$xmpmeta->GetNamespacePrefix($config['ns'])) { + if ($config['type'] == 'property') { + $value = @$xmpmeta->GetProperty($config['name'], $config['ns']); + } + elseif ($config['type'] == 'array') { + $value = @$xmpmeta->GetArrayItem($config['name'], $key, $config['ns']); + } + elseif ($config['type'] == 'struct') { + $value = @$xmpmeta->GetStructField($config['ns'], $config['struct'], $config['ns'], $config['name']); + } } return $value; -- cgit v1.2.3