/** * 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'); }