示例#1
0
 /**
  * Singleton pattern
  *
  * @return pspSEOImages Singleton instance
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#2
0
 private function getVideosInfo($videos = array(), $post = null, $extrainfo = array(), $recheckVideos = false)
 {
     if (empty($videos) || is_null($post) || !isset($post->ID)) {
         return array();
     }
     $post_id = (int) $post->ID;
     $ret = array();
     require $this->module_folder_path . 'video_info.php';
     $pspVideoInfo = new pspVideoInfo(array('vzaar_domain' => $this->settings['vzaar_domain'], 'viddler_key' => $this->settings['viddler_key'], 'flickr_key' => $this->settings['flickr_key']));
     $current_metas = array_merge(array(), $this->getVideoMetas($post_id));
     // try to retrieve attachment details (for localhost) based on guid!
     if (isset($videos['localhost']) && !empty($videos['localhost'])) {
         foreach ($videos['localhost'] as $key => $val) {
             if (!empty($extrainfo) && isset($extrainfo["localhost"]["{$key}"])) {
             } else {
                 $extrainfo["localhost"]["{$key}"] = $this->get_video_dbinfo($val);
             }
         }
     }
     foreach ($videos as $k => $v) {
         if (is_array($v) && !empty($v)) {
             foreach ($v as $key => $val) {
                 $videoLocalDetails = array();
                 if ($k == 'localhost' && !empty($extrainfo) && isset($extrainfo["{$k}"]["{$key}"])) {
                     $videoLocalDetails = $extrainfo["{$k}"]["{$key}"];
                 }
                 if ($k != 'localhost') {
                     $__vidalias = $val;
                 } else {
                     if ($k == 'localhost' && isset($videoLocalDetails->ID)) {
                         $__vidalias = 'post_' . (int) $videoLocalDetails->ID;
                     }
                 }
                 if (empty($__vidalias)) {
                     $__vidalias = 'rand_' . $this->the_plugin->generateRandomString(10);
                 }
                 $current_alias = $k . '_' . $this->setVideoAlias($__vidalias);
                 $meta_alias = 'psp_videos_' . $current_alias;
                 $vid_meta = isset($current_metas["{$meta_alias}"]) ? $current_metas["{$meta_alias}"] : array();
                 $__doRequestInfo = false;
                 if (isset($vid_meta['status']) && isset($vid_meta['created'])) {
                     srand();
                     $__rand = rand(0, count(self::$metaRandomLifetime) - 1);
                     $__lifetime = (int) (self::$metaLifetime + self::$metaRandomLifetime[$__rand]);
                     if ($recheckVideos || $vid_meta['status'] != 'valid' || (int) ($vid_meta['created'] + $__lifetime) < time()) {
                         $__doRequestInfo = true;
                     } else {
                         $ret["{$k}"]["{$key}"] = $vid_meta;
                     }
                 } else {
                     $__doRequestInfo = true;
                 }
                 if ($__doRequestInfo) {
                     $ret["{$k}"]["{$key}"] = $pspVideoInfo->getVideoInfo($val, $k, array('post' => $post, 'extrainfo' => $videoLocalDetails));
                     $remoteThumb = $this->saveVideoThumbnail($post_id, $current_alias, $ret["{$k}"]["{$key}"]['thumbnail']);
                     if ($remoteThumb['status'] == 'valid') {
                         // update with remote thumb
                         $ret["{$k}"]["{$key}"]['thumbnail'] = $remoteThumb['resp'];
                     }
                     update_post_meta($post_id, $meta_alias, $ret["{$k}"]["{$key}"]);
                     update_post_meta($post_id, $meta_alias . '_stat', $ret["{$k}"]["{$key}"]['status']);
                 }
                 $ret["{$k}"]["{$key}"] = array_merge($ret["{$k}"]["{$key}"], $this->video_info_check($ret["{$k}"]["{$key}"]));
             }
         }
     }
     return $ret;
 }