/** * Deprecated since 1.8.x * Use CFileHelper::upload instead **/ function cUploadFile($source, $destination) { return CFileHelper::upload($source, $destination); }
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 upload() { // Check for request forgeries JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_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(); $jinput = $mainframe->input; $my = CFactory::getUser(); $creatorType = $jinput->get('creatortype', VIDEO_USER_TYPE, 'NONE'); //JRequest::getVar('creatortype', VIDEO_USER_TYPE); $groupid = $jinput->get('groupid', 0, 'INT'); $eventid = $jinput->get('eventid', 0, 'INT'); $config = CFactory::getConfig(); $redirect = CVideosHelper::getVideoReturnUrlFromRequest(); // @rule: Do not allow users to add more videos than they are allowed to //CFactory::load( 'libraries' , 'limits' ); if (CLimitsLibrary::exceedDaily('videos')) { $mainframe->redirect($redirect, JText::_('COM_COMMUNITY_VIDEOS_LIMIT_REACHED'), 'error'); } // Process according to video creator type list($creatorType, $videoLimit) = $this->_manipulateParameter($groupid, $eventid, $config); $group = JTable::getInstance('Group', 'CTable'); $group->load($groupid); if ($group->approvals) { $permission = 40; } $permission = JRequest::getInt('permissions', 0, 'post'); // Check is video upload is permitted if (CLimitsHelper::exceededVideoUpload($my->id, $creatorType)) { $message = JText::sprintf('COM_COMMUNITY_VIDEOS_CREATION_LIMIT_ERROR', $videoLimit); $mainframe->redirect($redirect, $message); exit; } if (!$config->get('enablevideos')) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_VIDEO_DISABLED', 'notice')); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=frontpage', false)); exit; } if (!$config->get('enablevideosupload')) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_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::_('COM_COMMUNITY_VIDEOS_UPLOAD_ERROR', 'error')); $mainframe->redirect($redirect, false); exit; } // Check file type. $fileType = CVideosHelper::getMIMEType($videoFile); $allowable = CVideosHelper::getValidMIMEType(); if (!in_array(strtolower($fileType), $allowable)) { $mainframe->redirect($redirect, JText::sprintf('COM_COMMUNITY_VIDEOS_FILETYPE_ERROR', $fileType)); exit; } $fileExtension = pathinfo($videoFile['name']); $allowextension = CVideosHelper::getValidExtensionType(); if (!in_array(strtolower($fileExtension['extension']), $allowextension)) { $mainframe->redirect($redirect, JText::sprintf('COM_COMMUNITY_VIDEOS_FILETYPE_ERROR', $fileExtension['extension'])); exit; } // Check if the video file exceeds file size limit $uploadLimit = $config->get('maxvideouploadsize'); /* MB unit */ $videoFileSize = sprintf("%u", filesize($videoFile['tmp_name'])); //convert to MB $videoFileSize = number_format($videoFileSize / 1048576, 2); if ($uploadLimit > 0 && $videoFileSize > $uploadLimit) { $mainframe->redirect($redirect, JText::sprintf('COM_COMMUNITY_VIDEOS_FILE_SIZE_EXCEEDED', $uploadLimit)); } // Passed all checking, attempt to save the video file $folderPath = CVideoLibrary::getPath($my->id, 'original'); $randomFileName = CFileHelper::getRandomFilename($folderPath, $videoFile['name'], ''); $destination = JPATH::clean($folderPath . '/' . $randomFileName); if (!CFileHelper::upload($videoFile, $destination)) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_UPLOAD_ERROR', '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', $jinput->get('title', '', 'STRING')); $video->set('description', $jinput->get('description', '', 'STRING')); $video->set('category_id', JRequest::getInt('category_id', 0, 'post')); $video->set('permissions', $permission); $video->set('creator', $my->id); $video->set('creator_type', $creatorType); $video->set('groupid', $groupid); $video->set('eventid', $eventid); $video->set('location', $jinput->get('location', '', 'STRING')); $video->set('filesize', $videoFileSize); if (!$video->store()) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_VIDEOS_SAVE_ERROR', 'error')); $mainframe->redirect($redirect, false); exit; } //add notification: New group album is added if ($video->groupid != 0) { $group = JTable::getInstance('Group', 'CTable'); $group->load($video->groupid); $modelGroup = $this->getModel('groups'); $groupMembers = array(); $groupMembers = $modelGroup->getMembersId($video->groupid, true); $params = new CParameter(''); $params->set('title', $video->title); $params->set('group', $group->name); $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id); $params->set('url', 'index.php?option=com_community&view=videos&task=video&videoid=' . $video->id); CNotificationLibrary::add('groups_create_video', $my->id, $groupMembers, JText::sprintf('COM_COMMUNITY_GROUP_NEW_VIDEO_NOTIFICATION', '{actor}', '{group}'), '', 'groups.video', $params); } // Trigger for onVideoCreate $this->_triggerEvent('onVideoCreate', $video); $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES, COMMUNITY_CACHE_TAG_GROUPS_DETAIL)); // Video saved, redirect $redirect = CVideosHelper::getVideoReturnUrlFromRequest('pending'); $mainframe->redirect($redirect, JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title)); }
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; }