* @ingroup Media
*/
class IPTC {
-
/**
* This takes the results of iptcparse() and puts it into a
* form that can be handled by mediawiki. Generally called from
*/
static function parse( $rawData ) {
$parsed = iptcparse( $rawData );
- $data = Array();
+ $data = array();
if ( !is_array( $parsed ) ) {
- return $data;
+ return $data;
}
$c = '';
wfDebugLog( 'iptc', "IPTC tag $tag had only whitespace as its value." );
continue;
}
- switch( $tag ) {
+ switch ( $tag ) {
case '2#120': /*IPTC caption. mapped with exif ImageDescription*/
$data['ImageDescription'] = self::convIPTC( $val, $c );
break;
$titles = array();
}
- for ( $i = 0; $i < count( $titles ); $i++ ) {
+ $titleCount = count( $titles );
+ for ( $i = 0; $i < $titleCount; $i++ ) {
if ( isset( $bylines[$i] ) ) {
// theoretically this should always be set
// but doesn't hurt to be careful.
if ( isset( $parsed['2#060'] ) ) {
$time = $parsed['2#060'];
} else {
- $time = Array();
+ $time = array();
}
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
if ( isset( $parsed['2#063'] ) ) {
$time = $parsed['2#063'];
} else {
- $time = Array();
+ $time = array();
}
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
if ( isset( $parsed['2#035'] ) ) {
$time = $parsed['2#035'];
} else {
- $time = Array();
+ $time = array();
}
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
if ( isset( $parsed['2#038'] ) ) {
$time = $parsed['2#038'];
} else {
- $time = Array();
+ $time = array();
}
$timestamp = self::timeHelper( $val, $time, $c );
if ( $timestamp ) {
wfDebugLog( 'iptc', 'IPTC: '
. '2:04 too short. '
. 'Ignoring.' );
- break;
+ break;
}
$extracted = substr( $con[0], 4 );
$data['IntellectualGenre'] = $extracted;
foreach ( $codes as $ic ) {
$fields = explode( ':', $ic, 3 );
- if ( count( $fields ) < 2 ||
- $fields[0] !== 'IPTC' )
- {
+ if ( count( $fields ) < 2 || $fields[0] !== 'IPTC' ) {
wfDebugLog( 'IPTC', 'IPTC: '
. 'Invalid 2:12 - ' . $ic );
break;
break;
default:
- wfDebugLog( 'iptc', "Unsupported iptc tag: $tag. Value: " . implode( ',', $val ));
+ wfDebugLog( 'iptc', "Unsupported iptc tag: $tag. Value: " . implode( ',', $val ) );
break;
}
-
}
+
return $data;
}
// April, but the year and day is unknown. We don't process these
// types of incomplete dates atm.
wfDebugLog( 'iptc', "IPTC: invalid time ( $time ) or date ( $date )" );
+
return null;
}
- $unixTS = wfTimestamp( TS_UNIX, $date . substr( $time, 0, 6 ));
+ $unixTS = wfTimestamp( TS_UNIX, $date . substr( $time, 0, 6 ) );
if ( $unixTS === false ) {
wfDebugLog( 'iptc', "IPTC: can't convert date to TS_UNIX: $date $time." );
+
return null;
}
+ ( intval( substr( $time, 9, 2 ) ) * 60 );
if ( substr( $time, 6, 1 ) === '-' ) {
- $tz = - $tz;
+ $tz = -$tz;
}
$finalTimestamp = wfTimestamp( TS_EXIF, $unixTS + $tz );
if ( $finalTimestamp === false ) {
wfDebugLog( 'iptc', "IPTC: can't make final timestamp. Date: " . ( $unixTS + $tz ) );
+
return null;
}
if ( $dateOnly ) {
return $data;
}
+
/**
* Helper function of a helper function to convert charset for iptc values.
* @param $data Mixed String or Array: The iptc string
return self::convIPTCHelper( $oldData, 'Windows-1252' );
}
}
+
return trim( $data );
}