Esempio n. 1
0
 /**
  * @staticvar array $tags
  *
  * @return bool
  */
 public function HandleAllTags()
 {
     // key name => array (tag name, character encoding)
     static $tags;
     if (empty($tags)) {
         $tags = array('asf' => array('asf', 'UTF-16LE'), 'midi' => array('midi', 'ISO-8859-1'), 'nsv' => array('nsv', 'ISO-8859-1'), 'ogg' => array('vorbiscomment', 'UTF-8'), 'png' => array('png', 'UTF-8'), 'tiff' => array('tiff', 'ISO-8859-1'), 'quicktime' => array('quicktime', 'UTF-8'), 'real' => array('real', 'ISO-8859-1'), 'vqf' => array('vqf', 'ISO-8859-1'), 'zip' => array('zip', 'ISO-8859-1'), 'riff' => array('riff', 'ISO-8859-1'), 'lyrics3' => array('lyrics3', 'ISO-8859-1'), 'id3v1' => array('id3v1', $this->encoding_id3v1), 'id3v2' => array('id3v2', 'UTF-8'), 'ape' => array('ape', 'UTF-8'), 'cue' => array('cue', 'ISO-8859-1'), 'matroska' => array('matroska', 'UTF-8'), 'flac' => array('vorbiscomment', 'UTF-8'));
     }
     // loop through comments array
     foreach ($tags as $comment_name => $tagname_encoding_array) {
         list($tag_name, $encoding) = $tagname_encoding_array;
         // fill in default encoding type if not already present
         if (isset($this->info[$comment_name]) && !isset($this->info[$comment_name]['encoding'])) {
             $this->info[$comment_name]['encoding'] = $encoding;
         }
         // copy comments if key name set
         if (!empty($this->info[$comment_name]['comments'])) {
             foreach ($this->info[$comment_name]['comments'] as $tag_key => $valuearray) {
                 foreach ($valuearray as $key => $value) {
                     if (is_string($value)) {
                         $value = trim($value, " \r\n\t");
                         // do not trim nulls from $value!! Unicode characters will get mangled if trailing nulls are removed!
                     }
                     if ($value) {
                         $this->info['tags'][trim($tag_name)][trim($tag_key)][] = $value;
                     }
                 }
                 if ($tag_key == 'picture') {
                     unset($this->info[$comment_name]['comments'][$tag_key]);
                 }
             }
             if (!isset($this->info['tags'][$tag_name])) {
                 // comments are set but contain nothing but empty strings, so skip
                 continue;
             }
             if ($this->getOptionTagsHtml()) {
                 foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
                     foreach ($valuearray as $key => $value) {
                         if (is_string($value)) {
                             //$this->info['tags_html'][$tag_name][$tag_key][$key] = GetId3_lib::MultiByteCharString2HTML($value, $encoding);
                             $this->info['tags_html'][$tag_name][$tag_key][$key] = str_replace('�', '', trim(Helper::MultiByteCharString2HTML($value, $encoding)));
                         } else {
                             $this->info['tags_html'][$tag_name][$tag_key][$key] = $value;
                         }
                     }
                 }
             }
             $this->CharConvert($this->info['tags'][$tag_name], $encoding);
             // only copy gets converted!
         }
     }
     // pictures can take up a lot of space, and we don't need multiple copies of them
     // let there be a single copy in [comments][picture], and not elsewhere
     if (!empty($this->info['tags'])) {
         $unset_keys = array('tags', 'tags_html');
         foreach ($this->info['tags'] as $tagtype => $tagarray) {
             foreach ($tagarray as $tagname => $tagdata) {
                 if ($tagname == 'picture') {
                     foreach ($tagdata as $key => $tagarray) {
                         $this->info['comments']['picture'][] = $tagarray;
                         if (isset($tagarray['data']) && isset($tagarray['image_mime'])) {
                             if (isset($this->info['tags'][$tagtype][$tagname][$key])) {
                                 unset($this->info['tags'][$tagtype][$tagname][$key]);
                             }
                             if (isset($this->info['tags_html'][$tagtype][$tagname][$key])) {
                                 unset($this->info['tags_html'][$tagtype][$tagname][$key]);
                             }
                         }
                     }
                 }
             }
             foreach ($unset_keys as $unset_key) {
                 // remove possible empty keys from (e.g. [tags][id3v2][picture])
                 if (empty($this->info[$unset_key][$tagtype]['picture'])) {
                     unset($this->info[$unset_key][$tagtype]['picture']);
                 }
                 if (empty($this->info[$unset_key][$tagtype])) {
                     unset($this->info[$unset_key][$tagtype]);
                 }
                 if (empty($this->info[$unset_key])) {
                     unset($this->info[$unset_key]);
                 }
             }
             // remove duplicate copy of picture data from (e.g. [id3v2][comments][picture])
             if (isset($this->info[$tagtype]['comments']['picture'])) {
                 unset($this->info[$tagtype]['comments']['picture']);
             }
             if (empty($this->info[$tagtype]['comments'])) {
                 unset($this->info[$tagtype]['comments']);
             }
             if (empty($this->info[$tagtype])) {
                 unset($this->info[$tagtype]);
             }
         }
     }
     return true;
 }