X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FIPTC.php;h=ee0233ecfaef11aa99a74238ba72afd746967e6b;hb=008c561245742cdff111d4821839c9242f75ecb0;hp=dc163ac6c535b022f059949bf9b0184e575861c7;hpb=166bba144384eb2f9815049b76a67746b0b70d86;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/IPTC.php b/includes/media/IPTC.php index dc163ac6c5..ee0233ecfa 100644 --- a/includes/media/IPTC.php +++ b/includes/media/IPTC.php @@ -27,7 +27,6 @@ * @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 @@ -42,7 +41,7 @@ class IPTC { $parsed = iptcparse( $rawData ); $data = array(); if ( !is_array( $parsed ) ) { - return $data; + return $data; } $c = ''; @@ -85,7 +84,8 @@ class IPTC { $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. @@ -300,7 +300,7 @@ class IPTC { wfDebugLog( 'iptc', 'IPTC: ' . '2:04 too short. ' . 'Ignoring.' ); - break; + break; } $extracted = substr( $con[0], 4 ); $data['IntellectualGenre'] = $extracted; @@ -315,9 +315,7 @@ class IPTC { 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; @@ -341,11 +339,11 @@ class IPTC { break; default: - wfDebugLog( 'iptc', "Unsupported iptc tag: $tag. Value: " . implode( ',', $val )); + wfDebugLog( 'iptc', "Unsupported iptc tag: $tag. Value: " . implode( ',', $val ) ); break; } - } + return $data; } @@ -387,12 +385,14 @@ class IPTC { // 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; } @@ -400,12 +400,13 @@ class IPTC { + ( 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 ) { @@ -434,6 +435,7 @@ class IPTC { return $data; } + /** * Helper function of a helper function to convert charset for iptc values. * @param $data Mixed String or Array: The iptc string @@ -461,6 +463,7 @@ class IPTC { return self::convIPTCHelper( $oldData, 'Windows-1252' ); } } + return trim( $data ); }