예제 #1
0
 /**
  * 
  * @global type $wpdb
  * @param WPFB_File $file
  * @param type $info
  * @return type
  */
 static function StoreFileInfo($file, $info)
 {
     global $wpdb;
     if (empty($file->file_thumbnail)) {
         if (!empty($info['comments']['picture'][0]['data'])) {
             $cover_img =& $info['comments']['picture'][0]['data'];
         } elseif (!empty($info['id3v2']['APIC'][0]['data'])) {
             $cover_img =& $info['id3v2']['APIC'][0]['data'];
         } else {
             $cover_img = null;
         }
         // TODO unset pic in info?
         if (!empty($cover_img)) {
             $cover = $file->GetLocalPath();
             $cover = substr($cover, 0, strrpos($cover, '.')) . '.jpg';
             file_put_contents($cover, $cover_img);
             $file->CreateThumbnail($cover, true);
             @unlink($cover);
             $cf_changed = true;
         }
     }
     self::cleanInfoByRef($info);
     // set encoding to utf8 (required for getKeywords)
     if (function_exists('mb_internal_encoding')) {
         $cur_enc = mb_internal_encoding();
         mb_internal_encoding('UTF-8');
     }
     $keywords = array();
     self::getKeywords($info, $keywords);
     $keywords = strip_tags(join(' ', $keywords));
     $keywords = str_replace(array('\\n', '
'), '', $keywords);
     $keywords = preg_replace('/\\s\\s+/', ' ', $keywords);
     if (!function_exists('mb_detect_encoding') || mb_detect_encoding($keywords, "UTF-8") != "UTF-8") {
         $keywords = utf8_encode($keywords);
     }
     // restore prev encoding
     if (function_exists('mb_internal_encoding')) {
         mb_internal_encoding($cur_enc);
     }
     // don't store keywords 2 times:
     unset($info['keywords']);
     self::removeLongData($info, 8000);
     $data = empty($info) ? '0' : base64_encode(serialize($info));
     $res = $wpdb->replace($wpdb->wpfilebase_files_id3, array('file_id' => (int) $file->GetId(), 'analyzetime' => time(), 'value' => &$data, 'keywords' => &$keywords));
     unset($data, $keywords);
     $cf_changed = false;
     // TODO: move this cleanup into a callback / should NOT be HERE!
     if ($file->file_rescan_pending) {
         $file->file_rescan_pending = 0;
         $cf_changed = true;
     }
     // delete local temp file
     if ($file->IsRemote() && file_exists($file->GetLocalPath())) {
         @unlink($file->GetLocalPath());
     }
     // TODO END;
     if ($cf_changed && !$file->IsLocked()) {
         $file->DbSave(true);
     }
     return $res;
 }