41 static function parse( $rawData ) {
42 $parsed = iptcparse( $rawData );
44 if ( !is_array( $parsed ) ) {
50 if ( isset( $parsed[
'1#090'] ) && isset( $parsed[
'1#090'][0] ) ) {
58 unset( $parsed[
'1#090'] );
61 foreach ( $parsed as $tag => $val ) {
62 if ( isset( $val[0] ) && trim( $val[0] ) ==
'' ) {
63 wfDebugLog(
'iptc',
"IPTC tag $tag had only whitespace as its value." );
82 if ( isset( $parsed[
'2#085'] ) ) {
88 $titleCount = count( $titles );
89 for ( $i = 0; $i < $titleCount; $i++ ) {
90 if ( isset( $bylines[$i] ) ) {
93 $bylines[$i] = $titles[$i] .
', ' . $bylines[$i];
96 $data[
'Artist'] = $bylines;
168 if ( count( $software ) !== 1 ) {
172 wfDebugLog(
'iptc',
'IPTC: Wrong count on 2:65 Software field' );
176 if ( isset( $parsed[
'2#070'] ) ) {
179 unset( $parsed[
'2#070'] );
180 $data[
'Software'] = [ [ $software[0], $softwareVersion[0] ] ];
182 $data[
'Software'] = $software;
226 $time = $parsed[
'2#060'] ?? [];
229 $data[
'DateTimeOriginal'] = $timestamp;
236 $time = $parsed[
'2#063'] ?? [];
239 $data[
'DateTimeDigitized'] = $timestamp;
245 $time = $parsed[
'2#035'] ?? [];
248 $data[
'DateTimeReleased'] = $timestamp;
254 $time = $parsed[
'2#038'] ?? [];
257 $data[
'DateTimeExpires'] = $timestamp;
265 if ( strlen( $val[0] ) == 2 ) {
267 $versionValue = ord( substr( $val[0], 0, 1 ) ) * 256;
268 $versionValue += ord( substr( $val[0], 1, 1 ) );
269 $data[
'iimVersion'] = $versionValue;
284 if ( strlen( $con[0] ) < 5 ) {
290 $extracted = substr( $con[0], 4 );
291 $data[
'IntellectualGenre'] = $extracted;
300 foreach ( $codes as $ic ) {
301 $fields = explode(
':', $ic, 3 );
303 if ( count( $fields ) < 2 || $fields[0] !==
'IPTC' ) {
305 .
'Invalid 2:12 - ' . $ic );
308 $data[
'SubjectNewsCode'] = $fields[1];
327 wfDebugLog(
'iptc',
"Unsupported iptc tag: $tag. Value: " . implode(
',', $val ) );
344 private static function timeHelper( $date, $time, $charset ) {
345 if ( count( $date ) === 1 ) {
353 if ( count( $time ) === 1 ) {
357 $time =
'000000+0000';
361 if ( !( preg_match(
'/\d\d\d\d\d\d[-+]\d\d\d\d/', $time )
362 && preg_match(
'/\d\d\d\d\d\d\d\d/', $date )
363 && substr( $date, 0, 4 ) !==
'0000'
364 && substr( $date, 4, 2 ) !==
'00'
365 && substr( $date, 6, 2 ) !==
'00'
372 wfDebugLog(
'iptc',
"IPTC: invalid time ( $time ) or date ( $date )" );
377 $unixTS =
wfTimestamp( TS_UNIX, $date . substr( $time, 0, 6 ) );
378 if ( $unixTS ===
false ) {
379 wfDebugLog(
'iptc',
"IPTC: can't convert date to TS_UNIX: $date $time." );
384 $tz = ( intval( substr( $time, 7, 2 ) ) * 60 * 60 )
385 + ( intval( substr( $time, 9, 2 ) ) * 60 );
387 if ( substr( $time, 6, 1 ) ===
'-' ) {
391 $finalTimestamp =
wfTimestamp( TS_EXIF, $unixTS + $tz );
392 if ( $finalTimestamp ===
false ) {
393 wfDebugLog(
'iptc',
"IPTC: can't make final timestamp. Date: " . ( $unixTS + $tz ) );
399 return substr( $finalTimestamp, 0, 10 );
401 return $finalTimestamp;
412 private static function convIPTC( $data, $charset ) {
413 if ( is_array( $data ) ) {
414 foreach ( $data as &$val ) {
433 Wikimedia\suppressWarnings();
434 $data = iconv( $charset,
"UTF-8//IGNORE", $data );
435 Wikimedia\restoreWarnings();
436 if ( $data ===
false ) {
438 wfDebugLog(
'iptc', __METHOD__ .
" Error converting iptc data charset $charset to utf-8" );
444 UtfNormal\Validator::quickIsNFCVerify( $data );
445 if ( $data === $oldData ) {
452 return trim( $data );
539 $c =
"CSA_Z243.4-1985-1";
542 $c =
"CSA_Z243.4-1985-2";
546 case "\x1b&@\x1b\$B":
547 case "\x1b&@\x1b\$(B":
548 $c =
"JIS_C6226-1983";
580 wfDebugLog(
'iptc', __METHOD__ .
'Unknown charset in iptc 1:90: ' . bin2hex( $tag ) );