示例#1
0
 /**
  * This function will regenerate the thumbnail of videos
  * @param int $id
  * @param bool $returnThumb
  * @return bool
  */
 public function _fetchThumbnail($id = 0, $returnThumb = false)
 {
     if (!COwnerHelper::isRegisteredUser()) {
         return;
     }
     if (!$id) {
         return false;
     }
     $table = JTable::getInstance('Video', 'CTable');
     $table->load($id);
     $config = CFactory::getConfig();
     if ($table->type == 'file') {
         // We can only recreate the thumbnail for local video file only
         // it's not possible to process remote video file with ffmpeg
         if ($table->storage != 'file') {
             $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . 'FFmpeg cannot process remote video.');
             return false;
         }
         $videoLib = new CVideoLibrary();
         $videoFullPath = JPATH::clean(JPATH_ROOT . '/' . $table->path);
         if (!JFile::exists($videoFullPath)) {
             return false;
         }
         // Read duration
         $videoInfo = $videoLib->getVideoInfo($videoFullPath);
         if (!$videoInfo) {
             return false;
         } else {
             $videoFrame = CVideosHelper::formatDuration((int) ($videoInfo['duration']['sec'] / 2), 'HH:MM:SS');
             // Create thumbnail
             $oldThumb = $table->thumb;
             $thumbFolder = CVideoLibrary::getPath($table->creator, 'thumb');
             $thumbSize = CVideoLibrary::thumbSize();
             $thumbFilename = $videoLib->createVideoThumb($videoFullPath, $thumbFolder, $videoFrame, $thumbSize);
         }
         if (!$thumbFilename) {
             return false;
         }
     } else {
         if (!CRemoteHelper::curlExists()) {
             $this->setError(JText::_('COM_COMMUNITY_CURL_NOT_EXISTS'));
             return false;
         }
         $videoLib = new CVideoLibrary();
         $videoObj = $videoLib->getProvider($table->path);
         if ($videoObj == false) {
             $this->setError($videoLib->getError());
             return false;
         }
         if (!$videoObj->isValid()) {
             $this->setError($videoObj->getError());
             return false;
         }
         $remoteThumb = $videoObj->getThumbnail();
         $thumbData = CRemoteHelper::getContent($remoteThumb, true);
         if (empty($thumbData)) {
             $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $remoteThumb);
             return false;
         }
         // split the header and body
         list($headers, $body) = explode("\r\n\r\n", $thumbData, 2);
         preg_match('/Content-Type: image\\/(.*)/i', $headers, $matches);
         if (!empty($matches)) {
             $thumbPath = CVideoLibrary::getPath($table->creator, 'thumb');
             $thumbFileName = CFileHelper::getRandomFilename($thumbPath);
             $tmpThumbPath = $thumbPath . '/' . $thumbFileName;
             if (!JFile::write($tmpThumbPath, $body)) {
                 $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $thumbFileName);
                 return false;
             }
             // We'll remove the old or none working thumbnail after this
             $oldThumb = $table->thumb;
             // Get the image type first so we can determine what extensions to use
             $info = getimagesize($tmpThumbPath);
             $mime = image_type_to_mime_type($info[2]);
             $thumbExtension = CImageHelper::getExtension($mime);
             $thumbFilename = $thumbFileName . $thumbExtension;
             $thumbPath = $thumbPath . '/' . $thumbFilename;
             if (!JFile::move($tmpThumbPath, $thumbPath)) {
                 $this->setError(JText::_('WARNFS_ERR02') . ': ' . $thumbFileName);
                 return false;
             }
             // Resize the thumbnails
             //CImageHelper::resizeProportional( $thumbPath , $thumbPath , $mime , CVideoLibrary::thumbSize('width') , CVideoLibrary::thumbSize('height') );
             list($width, $height) = explode('x', $config->get('videosThumbSize'));
             CImageHelper::resizeAspectRatio($thumbPath, $thumbPath, $width, $height);
         } else {
             $this->setError(JText::_('COM_COMMUNITY_PHOTOS_IMAGE_NOT_PROVIDED_ERROR'));
             return false;
         }
     }
     // Update the DB with new thumbnail
     $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename;
     $table->set('thumb', $thumb);
     $table->store();
     // If this video storage is not on local, we move it to remote storage
     // and remove the old thumb if existed
     if ($table->storage != 'file') {
         // && ($table->storage == $storageType))
         $config = CFactory::getConfig();
         $storageType = $config->getString('videostorage');
         $storage = CStorage::getStorage($storageType);
         $storage->delete($oldThumb);
         $localThumb = JPATH::clean(JPATH_ROOT . '/' . $table->thumb);
         $tempThumbname = JPATH::clean(JPATH_ROOT . '/' . md5($table->thumb));
         if (JFile::exists($localThumb)) {
             JFile::copy($localThumb, $tempThumbname);
         }
         if (JFile::exists($tempThumbname)) {
             $storage->put($table->thumb, $tempThumbname);
             JFile::delete($localThumb);
             JFile::delete($tempThumbname);
         }
     } else {
         if (JFile::exists(JPATH_ROOT . '/' . $oldThumb)) {
             JFile::delete(JPATH_ROOT . '/' . $oldThumb);
         }
     }
     if ($returnThumb) {
         return $table->getThumbnail();
     }
     return true;
 }
示例#2
0
/**
 * Deprecated since 1.8
 */
function cIsCurlExists()
{
    return CRemoteHelper::curlExists();
}
示例#3
0
 function _remoteInstaller($url)
 {
     if (!$url) {
         return false;
     }
     $config =& JFactory::getConfig();
     require_once $this->frontendPath . 'helpers' . DS . 'remote.php';
     if (!CRemoteHelper::curlExists()) {
         // opst.. curl not installed
         return false;
     }
     $rawPackage = CRemoteHelper::getContent($url, true);
     // capture the header
     list($headers, $contents) = explode("\r\n\r\n", $rawPackage, 2);
     if (!JString::strpos($headers, '200 OK')) {
         // something went wrong with the server or the url
         return false;
     }
     $regex = '/filename="([a-zA-Z0-9].+?)"/';
     $count = preg_match($regex, $headers, $matches);
     if (isset($matches[1]) && !empty($matches[1])) {
         $filename = $matches[1];
     } else {
         $parts = explode('/', $url);
         $filename = $parts[count($parts) - 1];
     }
     $target = $config->getValue('config.tmp_path') . DS . basename($filename);
     // Write buffer to file
     JFile::write($target, $contents);
     jimport('joomla.installer.installer');
     jimport('joomla.installer.helper');
     // Unpack
     $package = JInstallerHelper::unpack($target);
     if (!$package) {
         // unable to find install package
     }
     // Install the package
     $msg = '';
     $installer =& JInstaller::getInstance();
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error'));
         $result = false;
     } else {
         // Package installed sucessfully
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success'));
         $result = true;
     }
     // Clean up the install files
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = $config->getValue('config.tmp_path') . DS . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     return $result;
 }