40 public static function parse( $rawData ) {
41 $parsed = iptcparse( $rawData );
43 if ( !is_array( $parsed ) ) {
49 if ( isset( $parsed[
'1#090'] ) && isset( $parsed[
'1#090'][0] ) ) {
57 unset( $parsed[
'1#090'] );
60 foreach ( $parsed as $tag => $val ) {
61 if ( isset( $val[0] ) && trim( $val[0] ) ==
'' ) {
62 wfDebugLog(
'iptc',
"IPTC tag $tag had only whitespace as its value." );
81 if ( isset( $parsed[
'2#085'] ) ) {
87 $titleCount = count( $titles );
88 for ( $i = 0; $i < $titleCount; $i++ ) {
89 if ( isset( $bylines[$i] ) ) {
92 $bylines[$i] = $titles[$i] .
', ' . $bylines[$i];
95 $data[
'Artist'] = $bylines;
167 if ( count( $software ) !== 1 ) {
171 wfDebugLog(
'iptc',
'IPTC: Wrong count on 2:65 Software field' );
175 if ( isset( $parsed[
'2#070'] ) ) {
178 unset( $parsed[
'2#070'] );
179 $data[
'Software'] = [ [ $software[0], $softwareVersion[0] ] ];
181 $data[
'Software'] = $software;
225 $time = $parsed[
'2#060'] ?? [];
228 $data[
'DateTimeOriginal'] = $timestamp;
235 $time = $parsed[
'2#063'] ?? [];
238 $data[
'DateTimeDigitized'] = $timestamp;
244 $time = $parsed[
'2#035'] ?? [];
247 $data[
'DateTimeReleased'] = $timestamp;
253 $time = $parsed[
'2#038'] ?? [];
256 $data[
'DateTimeExpires'] = $timestamp;
264 if ( strlen( $val[0] ) == 2 ) {
266 $versionValue = ord( substr( $val[0], 0, 1 ) ) * 256;
267 $versionValue += ord( substr( $val[0], 1, 1 ) );
268 $data[
'iimVersion'] = $versionValue;
283 if ( strlen( $con[0] ) < 5 ) {
289 $extracted = substr( $con[0], 4 );
290 $data[
'IntellectualGenre'] = $extracted;
299 foreach ( $codes as $ic ) {
300 $fields = explode(
':', $ic, 3 );
302 if ( count( $fields ) < 2 || $fields[0] !==
'IPTC' ) {
304 .
'Invalid 2:12 - ' . $ic );
307 $data[
'SubjectNewsCode'] = $fields[1];
326 wfDebugLog(
'iptc',
"Unsupported iptc tag: $tag. Value: " . implode(
',', $val ) );
343 private static function timeHelper( $date, $time, $charset ) {
344 if ( count( $date ) === 1 ) {
352 if ( count( $time ) === 1 ) {
356 $time =
'000000+0000';
360 if ( !( preg_match(
'/\d\d\d\d\d\d[-+]\d\d\d\d/', $time )
361 && preg_match(
'/\d\d\d\d\d\d\d\d/', $date )
362 && substr( $date, 0, 4 ) !==
'0000'
363 && substr( $date, 4, 2 ) !==
'00'
364 && substr( $date, 6, 2 ) !==
'00'
371 wfDebugLog(
'iptc',
"IPTC: invalid time ( $time ) or date ( $date )" );
376 $unixTS =
wfTimestamp( TS_UNIX, $date . substr( $time, 0, 6 ) );
377 if ( $unixTS ===
false ) {
378 wfDebugLog(
'iptc',
"IPTC: can't convert date to TS_UNIX: $date $time." );
383 $tz = ( intval( substr( $time, 7, 2 ) ) * 60 * 60 )
384 + ( intval( substr( $time, 9, 2 ) ) * 60 );
386 if ( substr( $time, 6, 1 ) ===
'-' ) {
390 $finalTimestamp =
wfTimestamp( TS_EXIF, $unixTS + $tz );
391 if ( $finalTimestamp ===
false ) {
392 wfDebugLog(
'iptc',
"IPTC: can't make final timestamp. Date: " . ( $unixTS + $tz ) );
398 return substr( $finalTimestamp, 0, 10 );
400 return $finalTimestamp;