Conditions | 360 |
Paths | 6532 |
Total Lines | 885 |
Code Lines | 671 |
Lines | 171 |
Ratio | 19.32 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
100 | public function makeFormattedData( $tags ) { |
||
101 | $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3; |
||
102 | unset( $tags['ResolutionUnit'] ); |
||
103 | |||
104 | foreach ( $tags as $tag => &$vals ) { |
||
105 | // This seems ugly to wrap non-array's in an array just to unwrap again, |
||
106 | // especially when most of the time it is not an array |
||
107 | if ( !is_array( $tags[$tag] ) ) { |
||
108 | $vals = [ $vals ]; |
||
109 | } |
||
110 | |||
111 | // _type is a special value to say what array type |
||
112 | if ( isset( $tags[$tag]['_type'] ) ) { |
||
113 | $type = $tags[$tag]['_type']; |
||
114 | unset( $vals['_type'] ); |
||
115 | } else { |
||
116 | $type = 'ul'; // default unordered list. |
||
117 | } |
||
118 | |||
119 | // This is done differently as the tag is an array. |
||
120 | if ( $tag == 'GPSTimeStamp' && count( $vals ) === 3 ) { |
||
121 | // hour min sec array |
||
122 | |||
123 | $h = explode( '/', $vals[0] ); |
||
124 | $m = explode( '/', $vals[1] ); |
||
125 | $s = explode( '/', $vals[2] ); |
||
126 | |||
127 | // this should already be validated |
||
128 | // when loaded from file, but it could |
||
129 | // come from a foreign repo, so be |
||
130 | // paranoid. |
||
131 | if ( !isset( $h[1] ) |
||
132 | || !isset( $m[1] ) |
||
133 | || !isset( $s[1] ) |
||
134 | || $h[1] == 0 |
||
135 | || $m[1] == 0 |
||
136 | || $s[1] == 0 |
||
137 | ) { |
||
138 | continue; |
||
139 | } |
||
140 | $tags[$tag] = str_pad( intval( $h[0] / $h[1] ), 2, '0', STR_PAD_LEFT ) |
||
141 | . ':' . str_pad( intval( $m[0] / $m[1] ), 2, '0', STR_PAD_LEFT ) |
||
142 | . ':' . str_pad( intval( $s[0] / $s[1] ), 2, '0', STR_PAD_LEFT ); |
||
143 | |||
144 | try { |
||
145 | $time = wfTimestamp( TS_MW, '1971:01:01 ' . $tags[$tag] ); |
||
146 | // the 1971:01:01 is just a placeholder, and not shown to user. |
||
147 | if ( $time && intval( $time ) > 0 ) { |
||
148 | $tags[$tag] = $this->getLanguage()->time( $time ); |
||
149 | } |
||
150 | } catch ( TimestampException $e ) { |
||
151 | // This shouldn't happen, but we've seen bad formats |
||
152 | // such as 4-digit seconds in the wild. |
||
153 | // leave $tags[$tag] as-is |
||
154 | } |
||
155 | continue; |
||
156 | } |
||
157 | |||
158 | // The contact info is a multi-valued field |
||
159 | // instead of the other props which are single |
||
160 | // valued (mostly) so handle as a special case. |
||
161 | if ( $tag === 'Contact' ) { |
||
162 | $vals = $this->collapseContactInfo( $vals ); |
||
163 | continue; |
||
164 | } |
||
165 | |||
166 | foreach ( $vals as &$val ) { |
||
167 | switch ( $tag ) { |
||
168 | View Code Duplication | case 'Compression': |
|
169 | switch ( $val ) { |
||
170 | case 1: |
||
171 | case 2: |
||
172 | case 3: |
||
173 | case 4: |
||
174 | case 5: |
||
175 | case 6: |
||
176 | case 7: |
||
177 | case 8: |
||
178 | case 32773: |
||
179 | case 32946: |
||
180 | case 34712: |
||
181 | $val = $this->exifMsg( $tag, $val ); |
||
182 | break; |
||
183 | default: |
||
184 | /* If not recognized, display as is. */ |
||
185 | break; |
||
186 | } |
||
187 | break; |
||
188 | |||
189 | View Code Duplication | case 'PhotometricInterpretation': |
|
190 | switch ( $val ) { |
||
191 | case 0: |
||
192 | case 1: |
||
193 | case 2: |
||
194 | case 3: |
||
195 | case 4: |
||
196 | case 5: |
||
197 | case 6: |
||
198 | case 8: |
||
199 | case 9: |
||
200 | case 10: |
||
201 | case 32803: |
||
202 | case 34892: |
||
203 | $val = $this->exifMsg( $tag, $val ); |
||
204 | break; |
||
205 | default: |
||
206 | /* If not recognized, display as is. */ |
||
207 | break; |
||
208 | } |
||
209 | break; |
||
210 | |||
211 | case 'Orientation': |
||
212 | switch ( $val ) { |
||
213 | case 1: |
||
214 | case 2: |
||
215 | case 3: |
||
216 | case 4: |
||
217 | case 5: |
||
218 | case 6: |
||
219 | case 7: |
||
220 | case 8: |
||
221 | $val = $this->exifMsg( $tag, $val ); |
||
222 | break; |
||
223 | default: |
||
224 | /* If not recognized, display as is. */ |
||
225 | break; |
||
226 | } |
||
227 | break; |
||
228 | |||
229 | case 'PlanarConfiguration': |
||
230 | switch ( $val ) { |
||
231 | case 1: |
||
232 | case 2: |
||
233 | $val = $this->exifMsg( $tag, $val ); |
||
234 | break; |
||
235 | default: |
||
236 | /* If not recognized, display as is. */ |
||
237 | break; |
||
238 | } |
||
239 | break; |
||
240 | |||
241 | // TODO: YCbCrSubSampling |
||
242 | case 'YCbCrPositioning': |
||
243 | switch ( $val ) { |
||
244 | case 1: |
||
245 | case 2: |
||
246 | $val = $this->exifMsg( $tag, $val ); |
||
247 | break; |
||
248 | default: |
||
249 | /* If not recognized, display as is. */ |
||
250 | break; |
||
251 | } |
||
252 | break; |
||
253 | |||
254 | case 'XResolution': |
||
255 | case 'YResolution': |
||
256 | switch ( $resolutionunit ) { |
||
257 | case 2: |
||
258 | $val = $this->exifMsg( 'XYResolution', 'i', $this->formatNum( $val ) ); |
||
259 | break; |
||
260 | case 3: |
||
261 | $val = $this->exifMsg( 'XYResolution', 'c', $this->formatNum( $val ) ); |
||
262 | break; |
||
263 | default: |
||
264 | /* If not recognized, display as is. */ |
||
265 | break; |
||
266 | } |
||
267 | break; |
||
268 | |||
269 | // TODO: YCbCrCoefficients #p27 (see annex E) |
||
270 | case 'ExifVersion': |
||
271 | case 'FlashpixVersion': |
||
272 | $val = "$val" / 100; |
||
273 | break; |
||
274 | |||
275 | case 'ColorSpace': |
||
276 | switch ( $val ) { |
||
277 | case 1: |
||
278 | case 65535: |
||
279 | $val = $this->exifMsg( $tag, $val ); |
||
280 | break; |
||
281 | default: |
||
282 | /* If not recognized, display as is. */ |
||
283 | break; |
||
284 | } |
||
285 | break; |
||
286 | |||
287 | case 'ComponentsConfiguration': |
||
288 | switch ( $val ) { |
||
289 | case 0: |
||
290 | case 1: |
||
291 | case 2: |
||
292 | case 3: |
||
293 | case 4: |
||
294 | case 5: |
||
295 | case 6: |
||
296 | $val = $this->exifMsg( $tag, $val ); |
||
297 | break; |
||
298 | default: |
||
299 | /* If not recognized, display as is. */ |
||
300 | break; |
||
301 | } |
||
302 | break; |
||
303 | |||
304 | case 'DateTime': |
||
305 | case 'DateTimeOriginal': |
||
306 | case 'DateTimeDigitized': |
||
307 | case 'DateTimeReleased': |
||
308 | case 'DateTimeExpires': |
||
309 | case 'GPSDateStamp': |
||
310 | case 'dc-date': |
||
311 | case 'DateTimeMetadata': |
||
312 | if ( $val == '0000:00:00 00:00:00' || $val == ' : : : : ' ) { |
||
313 | $val = $this->msg( 'exif-unknowndate' )->text(); |
||
314 | } elseif ( preg_match( |
||
315 | '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/D', |
||
316 | $val |
||
317 | ) ) { |
||
318 | // Full date. |
||
319 | $time = wfTimestamp( TS_MW, $val ); |
||
320 | if ( $time && intval( $time ) > 0 ) { |
||
321 | $val = $this->getLanguage()->timeanddate( $time ); |
||
322 | } |
||
323 | } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d)$/D', $val ) ) { |
||
324 | // No second field. Still format the same |
||
325 | // since timeanddate doesn't include seconds anyways, |
||
326 | // but second still available in api |
||
327 | $time = wfTimestamp( TS_MW, $val . ':00' ); |
||
328 | if ( $time && intval( $time ) > 0 ) { |
||
329 | $val = $this->getLanguage()->timeanddate( $time ); |
||
330 | } |
||
331 | } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d)$/D', $val ) ) { |
||
332 | // If only the date but not the time is filled in. |
||
333 | $time = wfTimestamp( TS_MW, substr( $val, 0, 4 ) |
||
334 | . substr( $val, 5, 2 ) |
||
335 | . substr( $val, 8, 2 ) |
||
336 | . '000000' ); |
||
337 | if ( $time && intval( $time ) > 0 ) { |
||
338 | $val = $this->getLanguage()->date( $time ); |
||
339 | } |
||
340 | } |
||
341 | // else it will just output $val without formatting it. |
||
342 | break; |
||
343 | |||
344 | View Code Duplication | case 'ExposureProgram': |
|
345 | switch ( $val ) { |
||
346 | case 0: |
||
347 | case 1: |
||
348 | case 2: |
||
349 | case 3: |
||
350 | case 4: |
||
351 | case 5: |
||
352 | case 6: |
||
353 | case 7: |
||
354 | case 8: |
||
355 | $val = $this->exifMsg( $tag, $val ); |
||
356 | break; |
||
357 | default: |
||
358 | /* If not recognized, display as is. */ |
||
359 | break; |
||
360 | } |
||
361 | break; |
||
362 | |||
363 | case 'SubjectDistance': |
||
364 | $val = $this->exifMsg( $tag, '', $this->formatNum( $val ) ); |
||
365 | break; |
||
366 | |||
367 | View Code Duplication | case 'MeteringMode': |
|
368 | switch ( $val ) { |
||
369 | case 0: |
||
370 | case 1: |
||
371 | case 2: |
||
372 | case 3: |
||
373 | case 4: |
||
374 | case 5: |
||
375 | case 6: |
||
376 | case 7: |
||
377 | case 255: |
||
378 | $val = $this->exifMsg( $tag, $val ); |
||
379 | break; |
||
380 | default: |
||
381 | /* If not recognized, display as is. */ |
||
382 | break; |
||
383 | } |
||
384 | break; |
||
385 | |||
386 | case 'LightSource': |
||
387 | switch ( $val ) { |
||
388 | case 0: |
||
389 | case 1: |
||
390 | case 2: |
||
391 | case 3: |
||
392 | case 4: |
||
393 | case 9: |
||
394 | case 10: |
||
395 | case 11: |
||
396 | case 12: |
||
397 | case 13: |
||
398 | case 14: |
||
399 | case 15: |
||
400 | case 17: |
||
401 | case 18: |
||
402 | case 19: |
||
403 | case 20: |
||
404 | case 21: |
||
405 | case 22: |
||
406 | case 23: |
||
407 | case 24: |
||
408 | case 255: |
||
409 | $val = $this->exifMsg( $tag, $val ); |
||
410 | break; |
||
411 | default: |
||
412 | /* If not recognized, display as is. */ |
||
413 | break; |
||
414 | } |
||
415 | break; |
||
416 | |||
417 | case 'Flash': |
||
418 | $flashDecode = [ |
||
419 | 'fired' => $val & 0b00000001, |
||
420 | 'return' => ( $val & 0b00000110 ) >> 1, |
||
421 | 'mode' => ( $val & 0b00011000 ) >> 3, |
||
422 | 'function' => ( $val & 0b00100000 ) >> 5, |
||
423 | 'redeye' => ( $val & 0b01000000 ) >> 6, |
||
424 | // 'reserved' => ( $val & 0b10000000 ) >> 7, |
||
425 | ]; |
||
426 | $flashMsgs = []; |
||
427 | # We do not need to handle unknown values since all are used. |
||
428 | foreach ( $flashDecode as $subTag => $subValue ) { |
||
429 | # We do not need any message for zeroed values. |
||
430 | if ( $subTag != 'fired' && $subValue == 0 ) { |
||
431 | continue; |
||
432 | } |
||
433 | $fullTag = $tag . '-' . $subTag; |
||
434 | $flashMsgs[] = $this->exifMsg( $fullTag, $subValue ); |
||
435 | } |
||
436 | $val = $this->getLanguage()->commaList( $flashMsgs ); |
||
437 | break; |
||
438 | |||
439 | case 'FocalPlaneResolutionUnit': |
||
440 | switch ( $val ) { |
||
441 | case 2: |
||
442 | $val = $this->exifMsg( $tag, $val ); |
||
443 | break; |
||
444 | default: |
||
445 | /* If not recognized, display as is. */ |
||
446 | break; |
||
447 | } |
||
448 | break; |
||
449 | |||
450 | case 'SensingMethod': |
||
451 | switch ( $val ) { |
||
452 | case 1: |
||
453 | case 2: |
||
454 | case 3: |
||
455 | case 4: |
||
456 | case 5: |
||
457 | case 7: |
||
458 | case 8: |
||
459 | $val = $this->exifMsg( $tag, $val ); |
||
460 | break; |
||
461 | default: |
||
462 | /* If not recognized, display as is. */ |
||
463 | break; |
||
464 | } |
||
465 | break; |
||
466 | |||
467 | case 'FileSource': |
||
468 | switch ( $val ) { |
||
469 | case 3: |
||
470 | $val = $this->exifMsg( $tag, $val ); |
||
471 | break; |
||
472 | default: |
||
473 | /* If not recognized, display as is. */ |
||
474 | break; |
||
475 | } |
||
476 | break; |
||
477 | |||
478 | case 'SceneType': |
||
479 | switch ( $val ) { |
||
480 | case 1: |
||
481 | $val = $this->exifMsg( $tag, $val ); |
||
482 | break; |
||
483 | default: |
||
484 | /* If not recognized, display as is. */ |
||
485 | break; |
||
486 | } |
||
487 | break; |
||
488 | |||
489 | case 'CustomRendered': |
||
490 | switch ( $val ) { |
||
491 | case 0: |
||
492 | case 1: |
||
493 | $val = $this->exifMsg( $tag, $val ); |
||
494 | break; |
||
495 | default: |
||
496 | /* If not recognized, display as is. */ |
||
497 | break; |
||
498 | } |
||
499 | break; |
||
500 | |||
501 | case 'ExposureMode': |
||
502 | View Code Duplication | switch ( $val ) { |
|
503 | case 0: |
||
504 | case 1: |
||
505 | case 2: |
||
506 | $val = $this->exifMsg( $tag, $val ); |
||
507 | break; |
||
508 | default: |
||
509 | /* If not recognized, display as is. */ |
||
510 | break; |
||
511 | } |
||
512 | break; |
||
513 | |||
514 | case 'WhiteBalance': |
||
515 | switch ( $val ) { |
||
516 | case 0: |
||
517 | case 1: |
||
518 | $val = $this->exifMsg( $tag, $val ); |
||
519 | break; |
||
520 | default: |
||
521 | /* If not recognized, display as is. */ |
||
522 | break; |
||
523 | } |
||
524 | break; |
||
525 | |||
526 | case 'SceneCaptureType': |
||
527 | View Code Duplication | switch ( $val ) { |
|
528 | case 0: |
||
529 | case 1: |
||
530 | case 2: |
||
531 | case 3: |
||
532 | $val = $this->exifMsg( $tag, $val ); |
||
533 | break; |
||
534 | default: |
||
535 | /* If not recognized, display as is. */ |
||
536 | break; |
||
537 | } |
||
538 | break; |
||
539 | |||
540 | case 'GainControl': |
||
541 | View Code Duplication | switch ( $val ) { |
|
542 | case 0: |
||
543 | case 1: |
||
544 | case 2: |
||
545 | case 3: |
||
546 | case 4: |
||
547 | $val = $this->exifMsg( $tag, $val ); |
||
548 | break; |
||
549 | default: |
||
550 | /* If not recognized, display as is. */ |
||
551 | break; |
||
552 | } |
||
553 | break; |
||
554 | |||
555 | case 'Contrast': |
||
556 | View Code Duplication | switch ( $val ) { |
|
557 | case 0: |
||
558 | case 1: |
||
559 | case 2: |
||
560 | $val = $this->exifMsg( $tag, $val ); |
||
561 | break; |
||
562 | default: |
||
563 | /* If not recognized, display as is. */ |
||
564 | break; |
||
565 | } |
||
566 | break; |
||
567 | |||
568 | case 'Saturation': |
||
569 | View Code Duplication | switch ( $val ) { |
|
570 | case 0: |
||
571 | case 1: |
||
572 | case 2: |
||
573 | $val = $this->exifMsg( $tag, $val ); |
||
574 | break; |
||
575 | default: |
||
576 | /* If not recognized, display as is. */ |
||
577 | break; |
||
578 | } |
||
579 | break; |
||
580 | |||
581 | case 'Sharpness': |
||
582 | View Code Duplication | switch ( $val ) { |
|
583 | case 0: |
||
584 | case 1: |
||
585 | case 2: |
||
586 | $val = $this->exifMsg( $tag, $val ); |
||
587 | break; |
||
588 | default: |
||
589 | /* If not recognized, display as is. */ |
||
590 | break; |
||
591 | } |
||
592 | break; |
||
593 | |||
594 | case 'SubjectDistanceRange': |
||
595 | View Code Duplication | switch ( $val ) { |
|
596 | case 0: |
||
597 | case 1: |
||
598 | case 2: |
||
599 | case 3: |
||
600 | $val = $this->exifMsg( $tag, $val ); |
||
601 | break; |
||
602 | default: |
||
603 | /* If not recognized, display as is. */ |
||
604 | break; |
||
605 | } |
||
606 | break; |
||
607 | |||
608 | // The GPS...Ref values are kept for compatibility, probably won't be reached. |
||
609 | case 'GPSLatitudeRef': |
||
610 | case 'GPSDestLatitudeRef': |
||
611 | switch ( $val ) { |
||
612 | case 'N': |
||
613 | case 'S': |
||
614 | $val = $this->exifMsg( 'GPSLatitude', $val ); |
||
615 | break; |
||
616 | default: |
||
617 | /* If not recognized, display as is. */ |
||
618 | break; |
||
619 | } |
||
620 | break; |
||
621 | |||
622 | case 'GPSLongitudeRef': |
||
623 | case 'GPSDestLongitudeRef': |
||
624 | switch ( $val ) { |
||
625 | case 'E': |
||
626 | case 'W': |
||
627 | $val = $this->exifMsg( 'GPSLongitude', $val ); |
||
628 | break; |
||
629 | default: |
||
630 | /* If not recognized, display as is. */ |
||
631 | break; |
||
632 | } |
||
633 | break; |
||
634 | |||
635 | case 'GPSAltitude': |
||
636 | if ( $val < 0 ) { |
||
637 | $val = $this->exifMsg( 'GPSAltitude', 'below-sealevel', $this->formatNum( -$val, 3 ) ); |
||
638 | } else { |
||
639 | $val = $this->exifMsg( 'GPSAltitude', 'above-sealevel', $this->formatNum( $val, 3 ) ); |
||
640 | } |
||
641 | break; |
||
642 | |||
643 | case 'GPSStatus': |
||
644 | switch ( $val ) { |
||
645 | case 'A': |
||
646 | case 'V': |
||
647 | $val = $this->exifMsg( $tag, $val ); |
||
648 | break; |
||
649 | default: |
||
650 | /* If not recognized, display as is. */ |
||
651 | break; |
||
652 | } |
||
653 | break; |
||
654 | |||
655 | case 'GPSMeasureMode': |
||
656 | switch ( $val ) { |
||
657 | case 2: |
||
658 | case 3: |
||
659 | $val = $this->exifMsg( $tag, $val ); |
||
660 | break; |
||
661 | default: |
||
662 | /* If not recognized, display as is. */ |
||
663 | break; |
||
664 | } |
||
665 | break; |
||
666 | |||
667 | case 'GPSTrackRef': |
||
668 | case 'GPSImgDirectionRef': |
||
669 | case 'GPSDestBearingRef': |
||
670 | switch ( $val ) { |
||
671 | case 'T': |
||
672 | case 'M': |
||
673 | $val = $this->exifMsg( 'GPSDirection', $val ); |
||
674 | break; |
||
675 | default: |
||
676 | /* If not recognized, display as is. */ |
||
677 | break; |
||
678 | } |
||
679 | break; |
||
680 | |||
681 | case 'GPSLatitude': |
||
682 | case 'GPSDestLatitude': |
||
683 | $val = $this->formatCoords( $val, 'latitude' ); |
||
684 | break; |
||
685 | case 'GPSLongitude': |
||
686 | case 'GPSDestLongitude': |
||
687 | $val = $this->formatCoords( $val, 'longitude' ); |
||
688 | break; |
||
689 | |||
690 | case 'GPSSpeedRef': |
||
691 | View Code Duplication | switch ( $val ) { |
|
692 | case 'K': |
||
693 | case 'M': |
||
694 | case 'N': |
||
695 | $val = $this->exifMsg( 'GPSSpeed', $val ); |
||
696 | break; |
||
697 | default: |
||
698 | /* If not recognized, display as is. */ |
||
699 | break; |
||
700 | } |
||
701 | break; |
||
702 | |||
703 | case 'GPSDestDistanceRef': |
||
704 | View Code Duplication | switch ( $val ) { |
|
705 | case 'K': |
||
706 | case 'M': |
||
707 | case 'N': |
||
708 | $val = $this->exifMsg( 'GPSDestDistance', $val ); |
||
709 | break; |
||
710 | default: |
||
711 | /* If not recognized, display as is. */ |
||
712 | break; |
||
713 | } |
||
714 | break; |
||
715 | |||
716 | case 'GPSDOP': |
||
717 | // See https://en.wikipedia.org/wiki/Dilution_of_precision_(GPS) |
||
718 | if ( $val <= 2 ) { |
||
719 | $val = $this->exifMsg( $tag, 'excellent', $this->formatNum( $val ) ); |
||
720 | } elseif ( $val <= 5 ) { |
||
721 | $val = $this->exifMsg( $tag, 'good', $this->formatNum( $val ) ); |
||
722 | } elseif ( $val <= 10 ) { |
||
723 | $val = $this->exifMsg( $tag, 'moderate', $this->formatNum( $val ) ); |
||
724 | } elseif ( $val <= 20 ) { |
||
725 | $val = $this->exifMsg( $tag, 'fair', $this->formatNum( $val ) ); |
||
726 | } else { |
||
727 | $val = $this->exifMsg( $tag, 'poor', $this->formatNum( $val ) ); |
||
728 | } |
||
729 | break; |
||
730 | |||
731 | // This is not in the Exif standard, just a special |
||
732 | // case for our purposes which enables wikis to wikify |
||
733 | // the make, model and software name to link to their articles. |
||
734 | case 'Make': |
||
735 | case 'Model': |
||
736 | $val = $this->exifMsg( $tag, '', $val ); |
||
737 | break; |
||
738 | |||
739 | case 'Software': |
||
740 | if ( is_array( $val ) ) { |
||
741 | // if its a software, version array. |
||
742 | $val = $this->msg( 'exif-software-version-value', $val[0], $val[1] )->text(); |
||
743 | } else { |
||
744 | $val = $this->exifMsg( $tag, '', $val ); |
||
745 | } |
||
746 | break; |
||
747 | |||
748 | case 'ExposureTime': |
||
749 | // Show the pretty fraction as well as decimal version |
||
750 | $val = $this->msg( 'exif-exposuretime-format', |
||
751 | $this->formatFraction( $val ), $this->formatNum( $val ) )->text(); |
||
752 | break; |
||
753 | case 'ISOSpeedRatings': |
||
754 | // If its = 65535 that means its at the |
||
755 | // limit of the size of Exif::short and |
||
756 | // is really higher. |
||
757 | if ( $val == '65535' ) { |
||
758 | $val = $this->exifMsg( $tag, 'overflow' ); |
||
759 | } else { |
||
760 | $val = $this->formatNum( $val ); |
||
761 | } |
||
762 | break; |
||
763 | case 'FNumber': |
||
764 | $val = $this->msg( 'exif-fnumber-format', |
||
765 | $this->formatNum( $val ) )->text(); |
||
766 | break; |
||
767 | |||
768 | case 'FocalLength': |
||
769 | case 'FocalLengthIn35mmFilm': |
||
770 | $val = $this->msg( 'exif-focallength-format', |
||
771 | $this->formatNum( $val ) )->text(); |
||
772 | break; |
||
773 | |||
774 | case 'MaxApertureValue': |
||
775 | if ( strpos( $val, '/' ) !== false ) { |
||
776 | // need to expand this earlier to calculate fNumber |
||
777 | list( $n, $d ) = explode( '/', $val ); |
||
778 | if ( is_numeric( $n ) && is_numeric( $d ) ) { |
||
779 | $val = $n / $d; |
||
780 | } |
||
781 | } |
||
782 | if ( is_numeric( $val ) ) { |
||
783 | $fNumber = pow( 2, $val / 2 ); |
||
784 | if ( $fNumber !== false ) { |
||
785 | $val = $this->msg( 'exif-maxaperturevalue-value', |
||
786 | $this->formatNum( $val ), |
||
787 | $this->formatNum( $fNumber, 2 ) |
||
788 | )->text(); |
||
789 | } |
||
790 | } |
||
791 | break; |
||
792 | |||
793 | case 'iimCategory': |
||
794 | switch ( strtolower( $val ) ) { |
||
795 | // See pg 29 of IPTC photo |
||
796 | // metadata standard. |
||
797 | case 'ace': |
||
798 | case 'clj': |
||
799 | case 'dis': |
||
800 | case 'fin': |
||
801 | case 'edu': |
||
802 | case 'evn': |
||
803 | case 'hth': |
||
804 | case 'hum': |
||
805 | case 'lab': |
||
806 | case 'lif': |
||
807 | case 'pol': |
||
808 | case 'rel': |
||
809 | case 'sci': |
||
810 | case 'soi': |
||
811 | case 'spo': |
||
812 | case 'war': |
||
813 | case 'wea': |
||
814 | $val = $this->exifMsg( |
||
815 | 'iimcategory', |
||
816 | $val |
||
817 | ); |
||
818 | } |
||
819 | break; |
||
820 | case 'SubjectNewsCode': |
||
821 | // Essentially like iimCategory. |
||
822 | // 8 (numeric) digit hierarchical |
||
823 | // classification. We decode the |
||
824 | // first 2 digits, which provide |
||
825 | // a broad category. |
||
826 | $val = $this->convertNewsCode( $val ); |
||
827 | break; |
||
828 | case 'Urgency': |
||
829 | // 1-8 with 1 being highest, 5 normal |
||
830 | // 0 is reserved, and 9 is 'user-defined'. |
||
831 | $urgency = ''; |
||
832 | if ( $val == 0 || $val == 9 ) { |
||
833 | $urgency = 'other'; |
||
834 | } elseif ( $val < 5 && $val > 1 ) { |
||
835 | $urgency = 'high'; |
||
836 | } elseif ( $val == 5 ) { |
||
837 | $urgency = 'normal'; |
||
838 | } elseif ( $val <= 8 && $val > 5 ) { |
||
839 | $urgency = 'low'; |
||
840 | } |
||
841 | |||
842 | if ( $urgency !== '' ) { |
||
843 | $val = $this->exifMsg( 'urgency', |
||
844 | $urgency, $val |
||
845 | ); |
||
846 | } |
||
847 | break; |
||
848 | |||
849 | // Things that have a unit of pixels. |
||
850 | case 'OriginalImageHeight': |
||
851 | case 'OriginalImageWidth': |
||
852 | case 'PixelXDimension': |
||
853 | case 'PixelYDimension': |
||
854 | case 'ImageWidth': |
||
855 | case 'ImageLength': |
||
856 | $val = $this->formatNum( $val ) . ' ' . $this->msg( 'unit-pixel' )->text(); |
||
857 | break; |
||
858 | |||
859 | // Do not transform fields with pure text. |
||
860 | // For some languages the formatNum() |
||
861 | // conversion results to wrong output like |
||
862 | // foo,bar@example,com or foo٫bar@example٫com. |
||
863 | // Also some 'numeric' things like Scene codes |
||
864 | // are included here as we really don't want |
||
865 | // commas inserted. |
||
866 | case 'ImageDescription': |
||
867 | case 'UserComment': |
||
868 | case 'Artist': |
||
869 | case 'Copyright': |
||
870 | case 'RelatedSoundFile': |
||
871 | case 'ImageUniqueID': |
||
872 | case 'SpectralSensitivity': |
||
873 | case 'GPSSatellites': |
||
874 | case 'GPSVersionID': |
||
875 | case 'GPSMapDatum': |
||
876 | case 'Keywords': |
||
877 | case 'WorldRegionDest': |
||
878 | case 'CountryDest': |
||
879 | case 'CountryCodeDest': |
||
880 | case 'ProvinceOrStateDest': |
||
881 | case 'CityDest': |
||
882 | case 'SublocationDest': |
||
883 | case 'WorldRegionCreated': |
||
884 | case 'CountryCreated': |
||
885 | case 'CountryCodeCreated': |
||
886 | case 'ProvinceOrStateCreated': |
||
887 | case 'CityCreated': |
||
888 | case 'SublocationCreated': |
||
889 | case 'ObjectName': |
||
890 | case 'SpecialInstructions': |
||
891 | case 'Headline': |
||
892 | case 'Credit': |
||
893 | case 'Source': |
||
894 | case 'EditStatus': |
||
895 | case 'FixtureIdentifier': |
||
896 | case 'LocationDest': |
||
897 | case 'LocationDestCode': |
||
898 | case 'Writer': |
||
899 | case 'JPEGFileComment': |
||
900 | case 'iimSupplementalCategory': |
||
901 | case 'OriginalTransmissionRef': |
||
902 | case 'Identifier': |
||
903 | case 'dc-contributor': |
||
904 | case 'dc-coverage': |
||
905 | case 'dc-publisher': |
||
906 | case 'dc-relation': |
||
907 | case 'dc-rights': |
||
908 | case 'dc-source': |
||
909 | case 'dc-type': |
||
910 | case 'Lens': |
||
911 | case 'SerialNumber': |
||
912 | case 'CameraOwnerName': |
||
913 | case 'Label': |
||
914 | case 'Nickname': |
||
915 | case 'RightsCertificate': |
||
916 | case 'CopyrightOwner': |
||
917 | case 'UsageTerms': |
||
918 | case 'WebStatement': |
||
919 | case 'OriginalDocumentID': |
||
920 | case 'LicenseUrl': |
||
921 | case 'MorePermissionsUrl': |
||
922 | case 'AttributionUrl': |
||
923 | case 'PreferredAttributionName': |
||
924 | case 'PNGFileComment': |
||
925 | case 'Disclaimer': |
||
926 | case 'ContentWarning': |
||
927 | case 'GIFFileComment': |
||
928 | case 'SceneCode': |
||
929 | case 'IntellectualGenre': |
||
930 | case 'Event': |
||
931 | case 'OrginisationInImage': |
||
932 | case 'PersonInImage': |
||
933 | |||
934 | $val = htmlspecialchars( $val ); |
||
935 | break; |
||
936 | |||
937 | case 'ObjectCycle': |
||
938 | switch ( $val ) { |
||
939 | case 'a': |
||
940 | case 'p': |
||
941 | case 'b': |
||
942 | $val = $this->exifMsg( $tag, $val ); |
||
943 | break; |
||
944 | default: |
||
945 | $val = htmlspecialchars( $val ); |
||
946 | break; |
||
947 | } |
||
948 | break; |
||
949 | case 'Copyrighted': |
||
950 | switch ( $val ) { |
||
951 | case 'True': |
||
952 | case 'False': |
||
953 | $val = $this->exifMsg( $tag, $val ); |
||
954 | break; |
||
955 | } |
||
956 | break; |
||
957 | case 'Rating': |
||
958 | if ( $val == '-1' ) { |
||
959 | $val = $this->exifMsg( $tag, 'rejected' ); |
||
960 | } else { |
||
961 | $val = $this->formatNum( $val ); |
||
962 | } |
||
963 | break; |
||
964 | |||
965 | case 'LanguageCode': |
||
966 | $lang = Language::fetchLanguageName( strtolower( $val ), $this->getLanguage()->getCode() ); |
||
967 | if ( $lang ) { |
||
968 | $val = htmlspecialchars( $lang ); |
||
969 | } else { |
||
970 | $val = htmlspecialchars( $val ); |
||
971 | } |
||
972 | break; |
||
973 | |||
974 | default: |
||
975 | $val = $this->formatNum( $val ); |
||
976 | break; |
||
977 | } |
||
978 | } |
||
979 | // End formatting values, start flattening arrays. |
||
980 | $vals = $this->flattenArrayReal( $vals, $type ); |
||
981 | } |
||
982 | |||
983 | return $tags; |
||
984 | } |
||
985 | |||
1889 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.