Exemplo n.º 1
0
 /**
  * Saves a thumbnail locally
  *
  * @param $thumbnailUrl
  */
 public function saveThumbnail()
 {
     $this->_videoId = XenGallery_Helper_String::cleanVideoId($this->_videoId);
     $this->_mediaSiteId = preg_replace('#[^a-zA-Z0-9_]#', '', $this->_mediaSiteId);
     if (!$this->_mediaSiteId || !$this->_videoId || !$this->_thumbnailUrl) {
         return false;
     }
     $options = XenForo_Application::getOptions();
     $this->_thumbnailPath = XenForo_Application::$externalDataPath . '/xengallery/' . $this->_mediaSiteId;
     try {
         $thumbnailPath = $this->_thumbnailPath . '/' . $this->_mediaSiteId . '_' . $this->_videoId . '.jpg';
         $client = XenForo_Helper_Http::getClient($this->_thumbnailUrl);
         XenForo_Helper_File::createDirectory(dirname($thumbnailPath), true);
         $fp = @fopen($thumbnailPath, 'w');
         if (!$fp) {
             return false;
         }
         fwrite($fp, $client->request('GET')->getBody());
         fclose($fp);
     } catch (Zend_Http_Client_Exception $e) {
         return false;
     }
     $image = new XenGallery_Helper_Image($thumbnailPath);
     $image->resize($options->xengalleryThumbnailDimension['width'], $options->xengalleryThumbnailDimension['height'], 'crop');
     return $image->save($this->_mediaSiteId . '_' . $this->_videoId . '_thumb', $this->_thumbnailPath, 'jpg');
 }
Exemplo n.º 2
0
 public function getVideoThumbnailUrlFromParts(array $parts, $force = false)
 {
     if (!isset($parts[1]) || !isset($parts[2])) {
         return false;
     }
     $serviceId = preg_replace('#[^a-zA-Z0-9_]#', '', $parts[1]);
     $videoId = $parts[2];
     $cleanVideoId = XenGallery_Helper_String::cleanVideoId($videoId);
     if (!strlen($serviceId) || !strlen($cleanVideoId)) {
         return false;
     }
     $videoThumbnail = sprintf('%s/xengallery/%s/%s_%s_thumb.jpg', XenForo_Application::$externalDataUrl, $serviceId, $serviceId, $cleanVideoId);
     $videoThumbnailPath = sprintf('%s/xengallery/%s/%s_%s.jpg', XenForo_Application::$externalDataPath, $serviceId, $serviceId, $cleanVideoId);
     if (!file_exists($videoThumbnailPath) || !is_readable($videoThumbnailPath) || $force) {
         $mediaSiteOptions = XenForo_Application::getOptions()->xengalleryMediaThumbs;
         if (empty($mediaSiteOptions[$serviceId])) {
             return false;
         }
         $mediaSite = $mediaSiteOptions[$serviceId];
         if (strpos($mediaSite, '_')) {
             if (class_exists($mediaSite)) {
                 /** @var $thumbnailObj XenGallery_Thumbnail_Abstract */
                 $thumbnailObj = XenGallery_Thumbnail_Abstract::create($mediaSite);
                 if ($mediaSite == 'XenGallery_Thumbnail_NoThumb') {
                     $videoThumbnailPath = $thumbnailObj->getNoThumbnailUrl($videoId, $serviceId);
                 } else {
                     $videoThumbnailPath = $thumbnailObj->getThumbnailUrl($videoId);
                 }
             } else {
                 $videoThumbnailPath = $mediaSite;
             }
         } else {
             $videoThumbnailPath = $mediaSite;
         }
         if (strpos($videoThumbnailPath, '{$id}')) {
             $this->_thumbnailPath = XenForo_Application::$externalDataPath . '/xengallery/' . $parts[0];
             XenForo_Helper_File::createDirectory($this->_thumbnailPath, true);
             $videoThumbnailPath = str_replace('{$id}', rawurldecode($cleanVideoId), $videoThumbnailPath);
             XenGallery_Thumbnail_Abstract::saveThumbnailFromUrl($serviceId, $videoId, $videoThumbnailPath);
         } else {
             $this->_thumbnailPath = XenForo_Application::$externalDataPath . '/xengallery/' . $serviceId;
             XenForo_Helper_File::createDirectory($this->_thumbnailPath, true);
             XenGallery_Thumbnail_Abstract::saveThumbnailFromPath($serviceId, $videoId, $videoThumbnailPath);
         }
         if (!$mediaSite) {
             /** @var $thumbnailObj XenGallery_Thumbnail_Abstract */
             $thumbnailObj = XenGallery_Thumbnail_Abstract::create('XenGallery_Thumbnail_NoThumb');
             $thumbnailObj->getNoThumbnailUrl($videoId, $serviceId);
         }
     }
     return $videoThumbnail;
 }