<?php
/**
-*Class for some IPTC functions.
+ * Class for some IPTC functions.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Media
+ */
-*/
+/**
+ * Class for some IPTC functions.
+ *
+ * @ingroup Media
+ */
class IPTC {
/**
*
* @see http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf
*
- * @param String $data app13 block from jpeg containing iptc/iim data
+ * @param $rawData String app13 block from jpeg containing iptc/iim data
* @return Array iptc metadata array
*/
static function parse( $rawData ) {
break;
case '2#115': /* source */
/* "Identifies the original owner of the intellectual content of the
- *objectdata. This could be an agency, a member of an agency or
+ *objectdata. This could be an agency, a member of an agency or
*an individual." */
$data['Source'] = self::convIPTC( $val, $c );
break;
} else {
$data['Software'] = $software;
}
-
-
break;
case '2#075':
/* Object cycle.
/**
* Convert an iptc date and time tags into the exif format
*
- * @todo Potentially this should also capture the timezone offset.
+ * @todo Potentially this should also capture the timezone offset.
* @param Array $date The date tag
* @param Array $time The time tag
+ * @param $c
* @return String Date in exif format.
*/
private static function timeHelper( $date, $time, $c ) {
$dateOnly = true;
}
- if ( ! ( preg_match('/\d\d\d\d\d\d[-+]\d\d\d\d/', $time)
+ if ( ! ( preg_match('/\d\d\d\d\d\d[-+]\d\d\d\d/', $time)
&& preg_match('/\d\d\d\d\d\d\d\d/', $date)
&& substr($date, 0, 4) !== '0000'
&& substr($date, 4, 2) !== '00'
} else {
return $finalTimestamp;
}
-
}
/**
* Helper function to convert charset for iptc values.
- * @param $data Mixed String or Array: The iptc string
+ * @param $data string|array The iptc string
* @param $charset String: The charset
+ *
+ * @return string|array
*/
private static function convIPTC ( $data, $charset ) {
- global $wgLang;
if ( is_array( $data ) ) {
foreach ($data as &$val) {
$val = self::convIPTCHelper( $val, $charset );
}
} else {
- $data = self::convIPTCHelper ( $data, $charset );
+ $data = self::convIPTCHelper( $data, $charset );
}
return $data;
* Helper function of a helper function to convert charset for iptc values.
* @param $data Mixed String or Array: The iptc string
* @param $charset String: The charset
+ *
+ * @return string
*/
private static function convIPTCHelper ( $data, $charset ) {
if ( $charset ) {
+ wfSuppressWarnings();
$data = iconv($charset, "UTF-8//IGNORE", $data);
+ wfRestoreWarnings();
if ($data === false) {
$data = "";
wfDebugLog('iptc', __METHOD__ . " Error converting iptc data charset $charset to utf-8");
// most of the time if there is no 1:90 tag, it is either ascii, latin1, or utf-8
$oldData = $data;
UtfNormal::quickIsNFCVerify( $data ); //make $data valid utf-8
- if ($data === $oldData) return $data; //if validation didn't change $data
- else return self::convIPTCHelper ( $oldData, 'Windows-1252' );
+ if ($data === $oldData) {
+ return $data; //if validation didn't change $data
+ } else {
+ return self::convIPTCHelper( $oldData, 'Windows-1252' );
+ }
}
return trim( $data );
}
/**
* take the value of 1:90 tag and returns a charset
- * @param String $tag 1:90 tag.
- * @return charset name or "?"
+ * @param String $tag 1:90 tag.
+ * @return string charset name or "?"
* Warning, this function does not (and is not intended to) detect
* all iso 2022 escape codes. In practise, the code for utf-8 is the
* only code that seems to have wide use. It does detect that code.
$c = "NS_4551-1";
break;
case "\x1b(f": //iso646-FR
- $c = "NF_Z_62-010";
+ $c = "NF_Z_62-010";
break;
case "\x1b(g":
$c = "PT2"; //iso646-PT2
$c = 'CSN_369103';
break;
default:
- wfDebugLog('iptc', __METHOD__ . 'Unknown charset in iptc 1:90: ' . bin2hex( $tag ) );
+ wfDebugLog('iptc', __METHOD__ . 'Unknown charset in iptc 1:90: ' . bin2hex( $tag ) );
//at this point just give up and refuse to parse iptc?
$c = false;
}