コード例 #1
0
ファイル: videos.php プロジェクト: joshjim27/jobsglobal
 public function ajaxLinkVideoPreview($videoUrl)
 {
     $filter = JFilterInput::getInstance();
     $videoUrl = $filter->clean($videoUrl, 'string');
     $objResponse = new JAXResponse();
     if (!JRequest::checkToken()) {
         $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_INVALID_TOKEN'));
         $objResponse->sendResponse();
     }
     $config = CFactory::getConfig();
     if (!$config->get('enablevideos')) {
         $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_VIDEOS_DISABLED'));
         $objResponse->sendResponse();
     }
     $my = CFactory::getUser();
     // @rule: Do not allow users to add more videos than they are allowed to
     if (CLimitsLibrary::exceedDaily('videos')) {
         $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_VIDEOS_LIMIT_REACHED'));
         $objResponse->sendResponse();
     }
     // Without CURL library, there's no way get the video information
     // remotely
     if (!CRemoteHelper::curlExists()) {
         $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_CURL_NOT_EXISTS'));
         $objResponse->sendResponse();
     }
     // Determine if the video belongs to group or user and
     // assign specify value for checking accordingly
     $creatorType = VIDEO_USER_TYPE;
     $videoLimit = $config->get('videouploadlimit');
     if (CLimitsHelper::exceededVideoUpload($my->id, $creatorType)) {
         $objResponse->addScriptCall('__throwError', JText::sprintf('COM_COMMUNITY_VIDEOS_CREATION_LIMIT_ERROR', $videoLimit));
         $objResponse->sendResponse();
     }
     // Create the video object and save
     if (empty($videoUrl)) {
         $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_VIDEOS_INVALID_VIDEO_LINKS'));
         $objResponse->sendResponse();
     }
     $videoLib = new CVideoLibrary();
     $video = JTable::getInstance('Video', 'CTable');
     $isValid = $video->init($videoUrl);
     if (!$isValid) {
         $objResponse->addScriptCall('__throwError', $video->getProvider()->getError());
         $objResponse->sendResponse();
     }
     $video->set('creator', $my->id);
     $video->set('creator_type', $creatorType);
     $video->set('category_id', 1);
     $video->set('status', 'temp');
     if (!$video->store()) {
         $objResponse->addScript('__throwError', JText::_('COM_COMMUNITY_VIDEOS_ADD_LINK_FAILED'));
         $objResponse->sendResponse();
     }
     // Fetch the thumbnail and store it locally,
     // else we'll use the thumbnail remotely
     CError::assert($video->thumb, '', '!empty');
     $this->_fetchThumbnail($video->id);
     $model = CFactory::getModel('videos');
     $category = $model->getAllCategories();
     $category = CCategoryHelper::getCategories($category);
     $attachment = new stdClass();
     $attachment->video = $video;
     $attachment->category = $category;
     $objResponse->addScriptCall('__callback', $attachment);
     $objResponse->sendResponse();
 }