Changeset 4998 for extensions/AMetaData/JpegMetaData/JpegMetaData.class.php
- Timestamp:
- Feb 28, 2010, 6:15:11 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/AMetaData/JpegMetaData/JpegMetaData.class.php
r4935 r4998 113 113 114 114 require_once(JPEG_METADATA_DIR."Readers/JpegReader.class.php"); 115 require_once(JPEG_METADATA_DIR."TagDefinitions/MagicTags.class.php"); 115 116 116 117 class JpegMetaData … … 123 124 const KEY_EXIF_EXIF = "exif.exif"; 124 125 const KEY_EXIF_GPS = "exif.gps"; 125 const KEY_EXIF = "exif"; 126 const KEY_IPTC = "iptc"; 127 const KEY_XMP = "xmp"; 126 const KEY_EXIF = "exif"; 127 const KEY_IPTC = "iptc"; 128 const KEY_XMP = "xmp"; 129 const KEY_MAGIC = "magic"; 128 130 129 131 private $jpeg = null; … … 157 159 * xmp | 158 160 * maker | maker => returns specifics tags from all the known 159 * 161 * magic | makers 160 162 * | 161 163 * ---------------------+--------------------------------------------------- … … 180 182 'iptc' => true, 181 183 'xmp' => true, 182 'maker' => true 184 'maker' => true, 185 'magic' => true, 183 186 ); 184 187 … … 211 214 $list[]="xmp"; 212 215 216 if($default['magic']) 217 $list[]="magic"; 218 213 219 foreach($list as $val) 214 220 { … … 232 238 $tmp=new XmpTags(); 233 239 $schema="xmp"; 240 break; 241 case "magic": 242 $tmp=new MagicTags(); 243 $schema="magic"; 234 244 break; 235 245 case MAKER_PENTAX: … … 281 291 } 282 292 } 293 294 ksort($returned); 283 295 284 296 return($returned); … … 332 344 * iptc | If set to true, the function returns all the tags 333 345 * xmp | known for the specified type tag 334 * 346 * magic | the exif parameter include the maker tags 335 347 * | 336 348 * ---------------------+--------------------------------------------------- … … 404 416 } 405 417 } 418 419 if($this->options['magic']) 420 { 421 $this->processMagicTags(); 422 } 423 424 ksort($this->tags); 406 425 } 407 426 } … … 468 487 'filter' => self::TAGFILTER_ALL, 469 488 'optimizeIptcDateTime' => false, 470 'exif' => true, 471 'iptc' => true, 472 'xmp' => true 489 'exif' => true, 490 'iptc' => true, 491 'xmp' => true, 492 'magic' => true 473 493 ); 474 494 … … 552 572 } 553 573 574 /** 575 * MagicTags are build with this function 576 */ 577 private function processMagicTags() 578 { 579 $magicTags=new MagicTags(); 580 581 foreach($magicTags->getTags() as $key => $val) 582 { 583 $tag=new Tag($key,0,$key); 584 585 for($i=0; $i<count($val['tagValues']); $i++) 586 { 587 $found=true; 588 preg_match_all('/{([a-z0-9:\.\s\/]*)(\[.*\])?}/i', $val['tagValues'][$i], $returned, PREG_PATTERN_ORDER); 589 foreach($returned[1] as $testKey) 590 { 591 $found=$found & array_key_exists($testKey, $this->tags); 592 } 593 if(count($returned[1])==0) $found=false; 594 595 if($found) 596 { 597 $returned=trim(preg_replace_callback( 598 '/{([a-z0-9:\.\s\/\[\]]*)}/i', 599 Array(&$this, "processMagicTagsCB"), 600 $val['tagValues'][$i] 601 )); 602 603 $tag->setValue($returned); 604 $tag->setLabel($returned); 605 $tag->setKnown(true); 606 $tag->setImplemented($val['implemented']); 607 $tag->setTranslatable($val['translatable']); 608 609 $i=count($val['tagValues']); 610 } 611 } 612 613 if($tag->isImplemented() and $found) 614 { 615 $this->tags["magic.".$key]=$tag; 616 } 617 618 unset($tag); 619 } 620 unset($magicTags); 621 } 622 623 /** 624 * this function is called by the processMagicTags to replace tagId by the 625 * tag values 626 * 627 * @param Array $matches : array[1] = the tagId 628 * @return String : the tag value 629 */ 630 private function processMagicTagsCB($matches) 631 { 632 $label=""; 633 preg_match_all('/([a-z0-9:\.\s\/]*)\[(.*)\]/i', $matches[1], $result, PREG_PATTERN_ORDER); 634 if(count($result[0])>0) 635 { 636 637 if(array_key_exists($result[1][0], $this->tags)) 638 { 639 $tag=$this->tags[$result[1][0]]->getLabel(); 640 641 preg_match_all('/([a-z0-9:\.\s\/]*)\[(.*)\]/i', $result[2][0], $result2, PREG_PATTERN_ORDER); 642 643 if(count($result2[0])>0) 644 { 645 if(array_key_exists($result2[2][0], $tag[$result2[1][0]] )) 646 $label=$tag[$result2[1][0]][$result2[2][0]]; 647 } 648 else 649 { 650 if(array_key_exists($result[2][0], $tag)) 651 $label=$tag[$result[2][0]]; 652 } 653 } 654 } 655 else 656 { 657 if(array_key_exists($matches[1], $this->tags)) 658 { 659 $label=$this->tags[$matches[1]]->getLabel(); 660 } 661 } 662 663 if($label instanceof DateTime) 664 return($label->format("Y-m-d H:i:s")); 665 666 $label=XmpTags::getAltValue($label, L10n::getLanguage()); 667 668 if(is_array($label)) 669 return(implode(", ", $label)); 670 671 return(trim($label)); 672 } 673 674 675 676 /** 677 * used by the destructor to clean variables 678 */ 554 679 private function unsetAll() 555 680 {
Note: See TracChangeset
for help on using the changeset viewer.