public static function filesBulletinAdd($userId, $bulletinId) { if ($userId == 0) { CAccess::setError('blockUnregister'); return false; } $table = JTable::getInstance('Bulletin', 'CTable'); $table->load($bulletinId); //CFactory::load( 'libraries' , 'limits' ); $groupModel = CFactory::getModel('groups'); $bulletinParams = $table->getParams(); if (!CLimitsHelper::exceededGroupFileUpload($table->groupid)) { return false; } if (CLimitsLibrary::exceedDaily('files', $userId)) { return false; } if (COwnerHelper::isCommunityAdmin() || $groupModel->isAdmin($userId, $table->groupid) || $groupModel->isMember($userId, $table->groupid) && $bulletinParams->get('filepermission-member')) { return true; } return false; }
public function isExceedUploadLimit() { if (CLimitsHelper::exceededPhotoUpload($this->groupid, PHOTOS_GROUP_TYPE)) { $config = CFactory::getConfig(); $photoLimit = $config->get('groupphotouploadlimit'); echo JText::sprintf('COM_COMMUNITY_GROUPS_PHOTO_LIMIT', $photoLimit); return TRUE; } return FALSE; }
public function isExceedUploadLimit($display = true) { if (CLimitsHelper::exceededPhotoUpload($this->groupid, PHOTOS_GROUP_TYPE)) { $config = CFactory::getConfig(); $photoLimit = $config->get('groupphotouploadlimit'); if ($display) { echo JText::sprintf('COM_COMMUNITY_GROUPS_PHOTO_LIMIT', $photoLimit); return true; } else { return true; } } return false; }
public static function groupsAdd($userId) { $config = CFactory::getConfig(); $my = CFactory::getUser(); if ($userId == 0) { CAccess::setError('blockUnregister'); return false; } else { if (!$config->get('enablegroups')) { CACCESS::setError(JText::_('COM_COMMUNITY_GROUPS_DISABLE')); return false; } else { if (!$config->get('creategroups') || !(COwnerHelper::isCommunityAdmin() || COwnerHelper::isRegisteredUser() && $my->canCreateGroups())) { CACCESS::setError(JText::_('COM_COMMUNITY_GROUPS_DISABLE_CREATE_MESSAGE')); return false; } else { if (CLimitsHelper::exceededGroupCreation($userId)) { $groupLimit = $config->get('groupcreatelimit'); CACCESS::setError(JText::sprintf('COM_COMMUNITY_GROUPS_LIMIT', $groupLimit)); return false; } else { return true; } } } } }
/** * Deprecated since 1.8 * Use CLimitsHelper::exceededPhotoUpload instead. */ function cExceededVideoUploadLimit($userId, $type = VIDEO_USER_TYPE) { return CLimitsHelper::exceededVideoUpload($userId, $type); }
public function ajaxCreate($postData, $objResponse) { $objResponse = new JAXResponse(); $filter = JFilterInput::getInstance(); $postData = $filter->clean($postData, 'array'); //prevent XSS injection foreach ($postData as &$data) { $data = strip_tags($data); } $config = CFactory::getConfig(); $my = CFactory::getUser(); if (!JRequest::checkToken()) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_INVALID_TOKEN')); $objResponse->sendResponse(); } CFactory::load('helpers', 'limits'); if (CLimitsHelper::exceededEventCreation($my->id)) { $eventLimit = $config->get('eventcreatelimit'); $objResponse->addScriptCall('__throwError', JText::sprintf('COM_COMMUNITY_EVENTS_LIMIT', $eventLimit)); $objResponse->sendResponse(); } CFactory::load('helpers', 'event'); $event = JTable::getInstance('Event', 'CTable'); $event->load(); $event->bind($postData); if ($postData['element'] == 'groups') { $event->contentid = $postData['target']; } $handler = CEventHelper::getHandler($event); if (!$handler->creatable()) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN')); $objResponse->sendResponse(); } // Format startdate and eendate with time before we bind into event object $this->_formatStartEndDate($postData); if (empty($event->title)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_TITLE_ERROR')); $objResponse->sendResponse(); } if (empty($event->location)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_LOCATION_ERR0R')); $objResponse->sendResponse(); } // @rule: Start date cannot be empty if (empty($event->startdate)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR')); $objResponse->sendResponse(); } // @rule: End date cannot be empty if (empty($event->enddate)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR')); $objResponse->sendResponse(); } require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'time.php'; if (CTimeHelper::timeIntervalDifference($event->startdate, $event->enddate) > 0) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_STARTDATE_GREATER_ERROR')); $objResponse->sendResponse(); } // @rule: Event must not end in the past $now = new JDate(); $jConfig = JFactory::getConfig(); $now->setOffset($jConfig->getValue('offset') + -COMMUNITY_DAY_HOURS); if (CTimeHelper::timeIntervalDifference($now->toMySQL(true), $event->enddate) > 0) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_GREATER_ERROR')); $objResponse->sendResponse(); } $event->creator = $my->id; //@rule: If event moderation is enabled, event should be unpublished by default $event->published = $config->get('event_moderation') ? 0 : 1; $event->created = JFactory::getDate()->toMySQL(); $event->contentid = $handler->getContentId(); $event->type = $handler->getType(); $event->store(); // Since this is storing event, we also need to store the creator / admin // into the events members table $member = JTable::getInstance('EventMembers', 'CTable'); $member->eventid = $event->id; $member->memberid = $event->creator; // Creator should always be 1 as approved as they are the creator. $member->status = COMMUNITY_EVENT_STATUS_ATTEND; // @todo: Setup required permissions in the future $member->permission = '1'; $member->store(); // Increment the member count $event->updateGuestStats(); $event->store(); $actor = $my->id; $target = 0; $content = ''; $cid = $event->id; $app = 'events'; $act = $handler->getActivity('events.create', $actor, $target, $content, $cid, $app); $url = $handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false, true, false); $act->groupid = $event->type == 'group' ? $event->contentid : null; $act->eventid = $event->id; $act->location = $event->location; $act->comment_id = $event->id; $act->comment_type = 'groups.event'; $act->like_id = $event->id; $act->like_type = 'group.event'; $cat_url = $handler->getFormattedLink('index.php?option=com_community&view=events&task=display&categoryid=' . $event->catid, false, true, false); $params = new CParameter(''); $action_str = 'events.create'; $params->set('action', $action_str); $params->set('event_url', $url); $params->set('event_category_url', $cat_url); // Add activity logging CFactory::load('libraries', 'activities'); CActivityStream::add($act, $params->toString()); // add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint($action_str); $this->triggerEvents('onEventCreate', $event); $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_EVENTS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); return $event; }
public function multiUpload() { $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $my = CFactory::getUser(); $config = CFactory::getConfig(); $type = $jinput->get('type', NULL, 'NONE'); $id = $jinput->get('id', '0', 'Int'); if ($my->id == 0) { $tokenId = $jinput->request->get('token', '', 'STRING'); $userId = $jinput->request->get('uploaderid', '', 'INT'); $my = CFactory::getUserFromTokenId($tokenId, $userId); $session = JFactory::getSession(); $session->set('user', $my); } $parentTable = JTable::getInstance(ucfirst($type), 'CTable'); $parentTable->load($id); $table = JTable::getInstance('File', 'CTable'); $_file = $jinput->files->get('file'); $fileLib = new CFilesLibrary(); if (CLimitsLibrary::exceedDaily('files', $my->id)) { $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED')); echo json_encode($json); exit; } if ($type == 'discussion' && !CLimitsHelper::exceededGroupFileUpload($parentTable->groupid)) { $json = array('msg' => JText::_('COM_COMMUNITY_FILES_LIMIT_REACHED')); echo json_encode($json); exit; } $now = new JDate(); $ext = pathinfo($_file['name']); $file = new stdClass(); $file->creator = $my->id; $file->filesize = sprintf("%u", $_file['size']); $file->name = JString::substr($_file['name'], 0, JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1)); $file->created = $now->toSql(); $file->type = CFileHelper::getExtensionIcon(CFileHelper::getFileExtension($_file['name'])); $fileName = JApplication::getHash($_file['name'] . time()) . JString::substr($_file['name'], JString::strlen($_file['name']) - (JString::strlen($ext['extension']) + 1)); if ($_file['error'] > 0 && $_file['error'] !== 'UPLOAD_ERR_OK') { $json = array('msg' => JText::sprintf('COM_COMMUNITY_PHOTOS_UPLOAD_ERROR', $_file['error'])); echo json_encode($json); exit; } if (!$fileLib->checkType($_file['name'])) { $json = array('msg' => JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED')); echo json_encode($json); exit; } switch ($type) { case 'discussion': $file->discussionid = $parentTable->id; $file->groupid = $parentTable->groupid; $file->filepath = 'images/files' . '/' . $type . '/' . $file->discussionid . '/' . $fileName; break; case 'bulletin': $file->bulletinid = $parentTable->id; $file->groupid = $parentTable->groupid; $file->filepath = 'images/files' . '/' . $type . '/' . $file->bulletinid . '/' . $fileName; break; case 'message': $file->messageid = -1; // set as -1 just in case this is not used and cron can clear it later if ($id) { $file->filepath = 'images/files/' . $type . '/' . $id . '/' . $fileName; if (!JFolder::exists(JPATH_ROOT . '/images/files/' . $type . '/' . $id)) { JFolder::create(JPATH_ROOT . '/images/files/' . $type . '/' . $id, (int) octdec($config->get('folderpermissionsphoto'))); JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/images/files/' . $type . '/' . $id . '/index.html'); } JFile::copy($_file['tmp_name'], JPATH_ROOT . '/' . $file->filepath); } else { //this could be from new message, and there is no id given $file->filepath = 'images/files/' . $type . '/temp/' . $fileName; //create the folder here as the logic for bulletin and discussion is not the same if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/temp')) { JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/temp', (int) octdec($config->get('folderpermissionsphoto'))); JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/temp/index.html'); } JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/temp/' . $fileName); } break; } if ($type != 'message') { if (!JFolder::exists(JPATH_ROOT . '/' . $type . '/' . $parentTable->id)) { JFolder::create(JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id, (int) octdec($config->get('folderpermissionsphoto'))); JFile::copy(JPATH_ROOT . '/components/com_community/index.html', JPATH_ROOT . '/files' . '/' . $type . '/' . $parentTable->id . '/index.html'); } JFile::copy($_file['tmp_name'], JPATH_ROOT . '/images/files' . '/' . $type . '/' . $parentTable->id . '/' . $fileName); } $table->bind($file); $table->store(); $params = new CParameter(''); switch ($type) { case 'discussion': // Get repliers for this discussion and notify the discussion creator too $discussionModel = CFactory::getModel('Discussions'); $discussion = JTable::getInstance('Discussion', 'CTable'); $discussion->load($parentTable->id); $users = $discussionModel->getRepliers($discussion->id, $discussion->groupid); $users[] = $discussion->creator; // The person who post this, should not be getting notification email $key = array_search($my->id, $users); if ($key !== false && isset($users[$key])) { unset($users[$key]); } $params->set('url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $discussion->groupid . '&topicid=' . $discussion->id); $params->set('filename', $_file['name']); $params->set('discussion', $discussion->title); $params->set('discussion_url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $discussion->groupid . '&topicid=' . $discussion->id); CNotificationLibrary::add('groups_discussion_newfile', $my->id, $users, JText::sprintf('COM_COMMUNITY_GROUP_DISCUSSION_NEW_FILE_SUBJECT'), '', 'groups.discussion.newfile', $params); break; case 'bulletin': break; } $json = array('id' => $table->id); die(json_encode($json)); }
public function isExceedUploadLimit() { CFactory::load('helpers', 'limits'); if (CLimitsHelper::exceededPhotoUpload($this->groupid, PHOTOS_GROUP_TYPE)) { $config = CFactory::getConfig(); $photoLimit = $config->get('groupphotouploadlimit'); echo JText::sprintf('CC GROUP PHOTO UPLOAD LIMIT REACHED', $photoLimit); return true; } return false; }
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() { // 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)); }
/** * Method to display the create group form **/ public function create() { $my = CFactory::getUser(); if ($my->id == 0) { return $this->blockUnregister(); } $config = CFactory::getConfig(); if (!$config->get('enablegroups')) { echo JText::_('CC GROUPS DISABLED'); return; } CFactory::load('helpers', 'owner'); if ($config->get('creategroups') && (COwnerHelper::isCommunityAdmin() || COwnerHelper::isRegisteredUser() && $my->canCreateGroups())) { CFactory::load('helpers', 'limits'); if (CLimitsHelper::exceededGroupCreation($my->id)) { $groupLimit = $config->get('groupcreatelimit'); echo JText::sprintf('CC GROUPS CREATION REACH LIMIT', $groupLimit); return; } $document =& JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view =& $this->getView($viewName, '', $viewType); $model =& $this->getModel('groups'); $data = new stdClass(); $data->categories = $model->getCategories(); if (JRequest::getVar('action', '', 'POST') == 'save') { CFactory::load('libraries', 'apps'); $appsLib =& CAppPlugins::getInstance(); $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-forms')); if (empty($saveSuccess) || !in_array(false, $saveSuccess)) { $gid = $this->save(); if ($gid !== FALSE) { $mainframe =& JFactory::getApplication(); $group =& JTable::getInstance('Group', 'CTable'); $group->load($gid); //trigger for onGroupCreate $this->triggerGroupEvents('onGroupCreate', $group); $url = CRoute::_('index.php?option=com_community&view=groups&task=created&groupid=' . $gid, false); $mainframe->redirect($url, JText::sprintf('CC GROUP CREATED NOTICE', $group->name)); return; } } } } else { echo JText::_('CC GROUPS CREATION DISABLED'); return; } echo $view->get(__FUNCTION__, $data); }
public function ajaxCreate($postData, $objResponse) { $objResponse = new JAXResponse(); $filter = JFilterInput::getInstance(); $postData = $filter->clean($postData, 'array'); $config = CFactory::getConfig(); $my = CFactory::getUser(); if (!JSession::checkToken('post')) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_INVALID_TOKEN')); $objResponse->sendResponse(); } //check for user daily limit first, then check for the total limit if (CFactory::getConfig()->get("limit_events_perday") <= CFactory::getModel("events")->getTotalToday($my->id)) { $eventLimit = CFactory::getConfig()->get("limit_events_perday"); $objResponse->addScriptCall('__throwError', JText::sprintf('COM_COMMUNITY_EVENTS_DAILY_LIMIT', $eventLimit)); $objResponse->sendResponse(); } else { if (CLimitsHelper::exceededEventCreation($my->id)) { $eventLimit = $config->get('eventcreatelimit'); $objResponse->addScriptCall('__throwError', JText::sprintf('COM_COMMUNITY_EVENTS_LIMIT', $eventLimit)); $objResponse->sendResponse(); } } //CFactory::load( 'helpers' , 'event' ); $event = JTable::getInstance('Event', 'CTable'); $event->load(); if ($postData['element'] == 'groups') { $event->contentid = $postData['target']; } $handler = CEventHelper::getHandler($event); if (!$handler->creatable() || !$my->canCreateEvents()) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN')); $objResponse->sendResponse(); } // Format startdate and eendate with time before we bind into event object $postData = $this->_formatStartEndDate($postData); $event->bind($postData); if (empty($event->title)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_TITLE_ERROR')); $objResponse->sendResponse(); } if (empty($event->location)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_LOCATION_ERR0R')); $objResponse->sendResponse(); } // @rule: Start date cannot be empty if (empty($event->startdate)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR')); $objResponse->sendResponse(); } // @rule: End date cannot be empty if (empty($event->enddate)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR')); $objResponse->sendResponse(); } require_once JPATH_COMPONENT . '/helpers/time.php'; if (!isset($postData['allday'])) { $postData['allday'] = 0; } if (CTimeHelper::timeIntervalDifference($event->startdate, $event->enddate) > 0) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_STARTDATE_GREATER_ERROR')); $objResponse->sendResponse(); } // @rule: Event must not end in the past $now = CTimeHelper::getLocaleDate(); // if all day event. $isToday = false; if ($postData['allday'] == '1') { $isToday = date("Y-m-d", strtotime($event->enddate)) == date("Y-m-d", strtotime($now->toSql(true))) ? true : $isToday; } if (CTimeHelper::timeIntervalDifference($now->toSql(true), $event->enddate) > 0 && !$isToday) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_GREATER_ERROR')); $objResponse->sendResponse(); } $eventChild = array(); // check event recurrence limit. if (!empty($event->repeat)) { $repeatLimit = 'COMMUNITY_EVENT_RECURRING_LIMIT_' . strtoupper($event->repeat); if (defined($repeatLimit)) { $eventChild = $this->_generateRepeatList($event, $postData); if (count($eventChild) > constant($repeatLimit)) { $objResponse->addScriptCall('__throwError', $event->title . ' - ' . sprintf(JText::_('COM_COMMUNITY_EVENTS_REPEAT_LIMIT_ERROR'), constant($repeatLimit))); } } } $event->creator = $my->id; //@rule: If event moderation is enabled, event should be unpublished by default $event->published = $this->isPublished(); $event->created = JFactory::getDate()->toSql(); $event->contentid = $handler->getContentId(); $event->type = $handler->getType(); $event->store(); if (!$event->isRecurring()) { $this->_saveMember($event); // Increment the member count. $event->updateGuestStats(); // Apparently the updateGuestStats does not store the item. Need to store it again. $event->store(); } else { $event->parent = $event->id; } // Save recurring event's child. $this->_saveRepeatChild($event, $eventChild, true, $postData); CEvents::addEventStream($event); // add user points CUserPoints::assignPoint('events.create'); $this->triggerEvents('onEventCreate', $event); $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_EVENTS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); return $event; }
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; }