X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fmedia%2FIPTC.php;h=06cbc3b04bba8618dee33a209c2c0eb28700b8c8;hb=82f2fcfb125a091cf97ead05bb0e7c485c559ec5;hp=666ce40175e6f135dc8d957f405418a58646a6ac;hpb=e59109e750a88c786683c661a3aea47055c6757b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/IPTC.php b/includes/media/IPTC.php index 666ce40175..06cbc3b04b 100644 --- a/includes/media/IPTC.php +++ b/includes/media/IPTC.php @@ -1,8 +1,31 @@ $val ) { - if ( isset( $val[0] ) && trim($val[0]) == '' ) { - wfDebugLog('iptc', "IPTC tag $tag had only whitespace as its value."); + if ( isset( $val[0] ) && trim( $val[0] ) == '' ) { + wfDebugLog( 'iptc', "IPTC tag $tag had only whitespace as its value." ); continue; } switch( $tag ) { @@ -152,7 +175,7 @@ class IPTC { if ( isset( $parsed['2#070'] ) ) { //if a version is set for the software. $softwareVersion = self::convIPTC( $parsed['2#070'], $c ); - unset($parsed['2#070']); + unset( $parsed['2#070'] ); $data['Software'] = array( array( $software[0], $softwareVersion[0] ) ); } else { $data['Software'] = $software; @@ -204,8 +227,8 @@ class IPTC { } else { $time = Array(); } - $timestamp = self::timeHelper( $val, $time, $c ); - if ($timestamp) { + $timestamp = self::timeHelper( $val, $time, $c ); + if ( $timestamp ) { $data['DateTimeOriginal'] = $timestamp; } break; @@ -218,8 +241,8 @@ class IPTC { } else { $time = Array(); } - $timestamp = self::timeHelper( $val, $time, $c ); - if ($timestamp) { + $timestamp = self::timeHelper( $val, $time, $c ); + if ( $timestamp ) { $data['DateTimeDigitized'] = $timestamp; } break; @@ -231,8 +254,8 @@ class IPTC { } else { $time = Array(); } - $timestamp = self::timeHelper( $val, $time, $c ); - if ($timestamp) { + $timestamp = self::timeHelper( $val, $time, $c ); + if ( $timestamp ) { $data['DateTimeReleased'] = $timestamp; } break; @@ -244,8 +267,8 @@ class IPTC { } else { $time = Array(); } - $timestamp = self::timeHelper( $val, $time, $c ); - if ($timestamp) { + $timestamp = self::timeHelper( $val, $time, $c ); + if ( $timestamp ) { $data['DateTimeExpires'] = $timestamp; } break; @@ -290,7 +313,7 @@ class IPTC { // describing the subject matter of the content. $codes = self::convIPTC( $val, $c ); foreach ( $codes as $ic ) { - $fields = explode(':', $ic, 3 ); + $fields = explode( ':', $ic, 3 ); if ( count( $fields ) < 2 || $fields[0] !== 'IPTC' ) @@ -339,31 +362,31 @@ class IPTC { if ( count( $date ) === 1 ) { //the standard says this should always be 1 //just double checking. - list($date) = self::convIPTC( $date, $c ); + list( $date ) = self::convIPTC( $date, $c ); } else { return null; } if ( count( $time ) === 1 ) { - list($time) = self::convIPTC( $time, $c ); + list( $time ) = self::convIPTC( $time, $c ); $dateOnly = false; } else { $time = '000000+0000'; //placeholder $dateOnly = true; } - 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' - && substr($date, 6, 2) !== '00' - ) ) { + 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' + && substr( $date, 6, 2 ) !== '00' + ) ) { //something wrong. // Note, this rejects some valid dates according to iptc spec // for example: the date 00000400 means the photo was taken in // 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 )"); + wfDebugLog( 'iptc', "IPTC: invalid time ( $time ) or date ( $date )" ); return null; } @@ -402,7 +425,7 @@ class IPTC { */ private static function convIPTC ( $data, $charset ) { if ( is_array( $data ) ) { - foreach ($data as &$val) { + foreach ( $data as &$val ) { $val = self::convIPTCHelper( $val, $charset ); } } else { @@ -421,18 +444,18 @@ class IPTC { private static function convIPTCHelper ( $data, $charset ) { if ( $charset ) { wfSuppressWarnings(); - $data = iconv($charset, "UTF-8//IGNORE", $data); + $data = iconv( $charset, "UTF-8//IGNORE", $data ); wfRestoreWarnings(); - if ($data === false) { + if ( $data === false ) { $data = ""; - wfDebugLog('iptc', __METHOD__ . " Error converting iptc data charset $charset to utf-8"); + wfDebugLog( 'iptc', __METHOD__ . " Error converting iptc data charset $charset to utf-8" ); } } else { //treat as utf-8 if is valid utf-8. otherwise pretend its windows-1252 // 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) { + if ( $data === $oldData ) { return $data; //if validation didn't change $data } else { return self::convIPTCHelper( $oldData, 'Windows-1252' ); @@ -449,7 +472,7 @@ class IPTC { * 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. */ - static function getCharset($tag) { + static function getCharset( $tag ) { //According to iim standard, charset is defined by the tag 1:90. //in which there are iso 2022 escape sequences to specify the character set. @@ -567,7 +590,7 @@ class IPTC { $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; }