/** * Deprecated since 1.8 * Use CLimitsHelper::exceededPhotoUpload instead. */ function cExceededVideoUploadLimit($userId, $type = VIDEO_USER_TYPE) { return CLimitsHelper::exceededVideoUpload($userId, $type); }
public function upload() { // Check for request forgeries JRequest::checkToken() or jexit(JText::_('CC INVALID TOKEN')); if ($this->blockUnregister()) { return; } $this->checkVideoAccess(); $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view = $this->getView($viewName, '', $viewType); $mainframe = JFactory::getApplication(); $my = CFactory::getUser(); $creatorType = JRequest::getVar('creatortype', VIDEO_USER_TYPE); $groupid = $creatorType == VIDEO_GROUP_TYPE ? JRequest::getInt('groupid', 0) : 0; $config = CFactory::getConfig(); CFactory::load('helpers', 'videos'); CFactory::load('libraries', 'videos'); $redirect = CVideosHelper::getVideoReturnUrlFromRequest(); // Process according to video creator type if (!empty($groupid)) { CFactory::load('helpers', 'group'); $allowManageVideos = CGroupHelper::allowManageVideo($groupid); $creatorType = VIDEO_GROUP_TYPE; $videoLimit = $config->get('groupvideouploadlimit'); CError::assert($allowManageVideos, '', '!empty', __FILE__, __LINE__); } else { $creatorType = VIDEO_USER_TYPE; $videoLimit = $config->get('videouploadlimit'); } // Check is video upload is permitted CFactory::load('helpers', 'limits'); if (CLimitsHelper::exceededVideoUpload($my->id, $creatorType)) { $message = JText::sprintf('CC VIDEOS CREATION REACH LIMIT', $videoLimit); $mainframe->redirect($redirect, $message); exit; } if (!$config->get('enablevideos')) { $mainframe->enqueueMessage(JText::_('CC VIDEO DISABLED', 'notice')); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=frontpage', false)); exit; } if (!$config->get('enablevideosupload')) { $mainframe->enqueueMessage(JText::_('CC VIDEO UPLOAD DISABLED', 'notice')); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=videos', false)); exit; } // Check if the video file is valid $files = JRequest::get('files'); $videoFile = !empty($files['videoFile']) ? $files['videoFile'] : array(); if (empty($files) || empty($videoFile['name']) && $videoFile['size'] < 1) { $mainframe->enqueueMessage(JText::_('CC VIDEO UPLOAD ERROR', 'error')); $mainframe->redirect($redirect, false); exit; } // Check file type. $fileType = $videoFile['type']; $allowable = CVideosHelper::getValidMIMEType(); if (!in_array($fileType, $allowable)) { $mainframe->redirect($redirect, JText::sprintf('CC VIDEO FILE TYPE NOT SUPPORTED', $fileType)); exit; } // Check if the video file exceeds file size limit $uploadLimit = $config->get('maxvideouploadsize') * 1024 * 1024; $videoFileSize = sprintf("%u", filesize($videoFile['tmp_name'])); if ($uploadLimit > 0 && $videoFileSize > $uploadLimit) { $mainframe->redirect($redirect, JText::sprintf('CC VIDEO FILE SIZE EXCEEDED', $uploadLimit)); } // Passed all checking, attempt to save the video file CFactory::load('helpers', 'file'); $folderPath = CVideoLibrary::getPath($my->id, 'original'); $randomFileName = CFileHelper::getRandomFilename($folderPath, $videoFile['name'], ''); $destination = JPATH::clean($folderPath . DS . $randomFileName); if (!CFileHelper::upload($videoFile, $destination)) { $mainframe->enqueueMessage(JText::_('CC VIDEO UPLOAD FAILED', 'error')); $mainframe->redirect($redirect, false); exit; } $config = CFactory::getConfig(); $videofolder = $config->get('videofolder'); CFactory::load('models', 'videos'); $video = JTable::getInstance('Video', 'CTable'); $video->set('path', $videofolder . '/originalvideos/' . $my->id . '/' . $randomFileName); $video->set('title', JRequest::getVar('title')); $video->set('description', JRequest::getVar('description')); $video->set('category_id', JRequest::getInt('category', 0, 'post')); $video->set('permissions', JRequest::getInt('privacy', 0, 'post')); $video->set('creator', $my->id); $video->set('creator_type', $creatorType); $video->set('groupid', $groupid); $video->set('filesize', $videoFileSize); if (!$video->store()) { $mainframe->enqueueMessage(JText::_('CC VIDEO SAVE ERROR', 'error')); $mainframe->redirect($redirect, false); exit; } // Trigger for onVideoCreate $this->_triggerEvent('onVideoCreate', $video); // Video saved, redirect $redirect = CVideosHelper::getVideoReturnUrlFromRequest('pending'); $mainframe->redirect($redirect, JText::sprintf('CC VIDEO UPLOAD SUCCESS', $video->title)); }
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(); }
public function upload() { $document = JFactory::getDocument(); $mainframe = JFactory::getApplication(); $my = $this->plugin->get('user'); $creatorType = JRequest::getVar('creatortype', VIDEO_USER_TYPE); $groupid = $creatorType == VIDEO_GROUP_TYPE ? JRequest::getInt('groupid', 0) : 0; $config = CFactory::getConfig(); CFactory::load('helpers', 'videos'); CFactory::load('libraries', 'videos'); $redirect = CVideosHelper::getVideoReturnUrlFromRequest(); // Process according to video creator type if (!empty($groupid)) { CFactory::load('helpers', 'group'); $allowManageVideos = CGroupHelper::allowManageVideo($groupid); $creatorType = VIDEO_GROUP_TYPE; $videoLimit = $config->get('groupvideouploadlimit'); CError::assert($allowManageVideos, '', '!empty', __FILE__, __LINE__); } else { $creatorType = VIDEO_USER_TYPE; $videoLimit = $config->get('videouploadlimit'); } // Check is video upload is permitted CFactory::load('helpers', 'limits'); if (CLimitsHelper::exceededVideoUpload($my->id, $creatorType)) { $message = JText::sprintf('CC VIDEOS CREATION REACH LIMIT', $videoLimit); $this->setError($message); return false; } if (!$config->get('enablevideos')) { $this->setError(JText::_('CC VIDEO DISABLED', 'notice')); return false; } if (!$config->get('enablevideosupload')) { $this->setError(JText::_('CC VIDEO UPLOAD DISABLED', 'notice')); return false; } // Check if the video file is valid $files = JRequest::get('files'); $videoFile = !empty($files['video']) ? $files['video'] : array(); if (empty($files) || empty($videoFile['name']) && $videoFile['size'] < 1) { $this->setError(JText::_('CC VIDEO UPLOAD ERROR', 'error')); return false; } // Check file type. $fileType = $videoFile['type']; // Override from iphone $fileType = 'video/quicktime'; $allowable = CVideosHelper::getValidMIMEType(); if (!in_array($fileType, $allowable)) { $this->setError(JText::sprintf('CC VIDEO FILE TYPE NOT SUPPORTED', $fileType)); return false; } // Check if the video file exceeds file size limit $uploadLimit = $config->get('maxvideouploadsize') * 1024 * 1024; $videoFileSize = sprintf("%u", filesize($videoFile['tmp_name'])); if ($uploadLimit > 0 && $videoFileSize > $uploadLimit) { $this->setError(JText::sprintf('CC VIDEO FILE SIZE EXCEEDED', $uploadLimit)); return false; } // Passed all checking, attempt to save the video file CFactory::load('helpers', 'file'); $folderPath = CVideoLibrary::getPath($my->id, 'original'); $randomFileName = CFileHelper::getRandomFilename($folderPath, $videoFile['name'], ''); $destination = JPATH::clean($folderPath . DS . $randomFileName); if (!CFileHelper::upload($videoFile, $destination)) { $this->setError(JText::_('CC VIDEO UPLOAD FAILED', 'error')); return false; } $config = CFactory::getConfig(); $videofolder = $config->get('videofolder'); CFactory::load('models', 'videos'); $video = JTable::getInstance('Video', 'CTable'); $video->set('path', $videofolder . '/originalvideos/' . $my->id . '/' . $randomFileName); $video->set('title', JRequest::getVar('title')); $video->set('description', JRequest::getVar('description')); $video->set('category_id', JRequest::getInt('category', 0, 'post')); $video->set('permissions', JRequest::getInt('privacy', 0, 'post')); $video->set('creator', $my->id); $video->set('creator_type', $creatorType); $video->set('groupid', $groupid); $video->set('filesize', $videoFileSize); if (!$video->store()) { $this->setError(JText::_('CC VIDEO SAVE ERROR', 'error')); return false; } // Trigger for onVideoCreate $this->_triggerEvent('onVideoCreate', $video); // Video saved, redirect return $video; }