public function check() { // Santinise data $safeHtmlFilter = CFactory::getInputFilter(); $this->caption = $safeHtmlFilter->clean($this->caption); return true; }
/** * Pre-store sanitization & check * * @access public * @return bool */ public function check() { // Santinize data $safeHtmlFilter = CFactory::getInputFilter(); $this->title = $safeHtmlFilter->clean($this->title); $this->points = (int) $safeHtmlFilter->clean($this->points); return true; }
public function check() { //CFactory::load( 'helpers', 'string'); // Santinise data $safeHtmlFilter = CFactory::getInputFilter(); $this->caption = CStringHelper::nl2br($safeHtmlFilter->clean($this->caption)); return true; }
function check() { $config = CFactory::getConfig(); $safeHtmlFilter = CFactory::getInputFilter($config->get('allowhtml')); $this->title = $safeHtmlFilter->clean($this->title); $this->message = $safeHtmlFilter->clean($this->message); return true; }
public function check() { // Santinise data $safeHtmlFilter = CFactory::getInputFilter(); $this->name = $safeHtmlFilter->clean($this->name); $this->description = $safeHtmlFilter->clean($this->description); $this->email = $safeHtmlFilter->clean($this->email); $this->website = $safeHtmlFilter->clean($this->website); return true; }
public function check() { // Filter the discussion $config = CFactory::getConfig(); //$clean = ('none' != $config->get('htmleditor')); $safeHtmlFilter = CFactory::getInputFilter(); $this->title = $safeHtmlFilter->clean($this->title); $safeHtmlFilter = CFactory::getInputFilter($config->getBool('allowhtml')); $this->message = $safeHtmlFilter->clean($this->message); return true; }
public function check() { // Santinise data $safeHtmlFilter = CFactory::getInputFilter(); $this->name = $safeHtmlFilter->clean($this->name); $this->email = $safeHtmlFilter->clean($this->email); $this->website = $safeHtmlFilter->clean($this->website); // Allow html tags $config = CFactory::getConfig(); $safeHtmlFilter = CFactory::getInputFilter($config->get('allowhtml')); $this->description = $safeHtmlFilter->clean($this->description); return true; }
function saveWall($uniqueId, $message, $appType, &$creator, $isOwner, $processFunc = '', $templateFile = 'wall.content', $wallId = 0) { $my = CFactory::getUser(); // Add some required parameters, otherwise assert here CError::assert($uniqueId, '', '!empty', __FILE__, __LINE__); CError::assert($appType, '', '!empty', __FILE__, __LINE__); CError::assert($message, '', '!empty', __FILE__, __LINE__); CError::assert($my->id, '', '!empty', __FILE__, __LINE__); // Load the models CFactory::load('models', 'wall'); CFactory::load('helpers', 'url'); $wall =& JTable::getInstance('Wall', 'CTable'); $wall->load($wallId); if ($wallId == 0) { // Get current date $now =& JFactory::getDate(); $now = $now->toMySQL(); // Set the wall properties $wall->type = $appType; $wall->contentid = $uniqueId; $wall->post_by = $creator->id; $wall->date = $now; $wall->published = 1; // @todo: set the ip address $wall->ip = $_SERVER['REMOTE_ADDR']; } $wall->comment = $message; $filter = CFactory::getInputFilter(); $wall->comment = $filter->clean($wall->comment); // Store the wall message $wall->store(); // Convert it to array so that the walls can be processed by plugins $args = array(); $args[0] =& $wall; //Process wall comments CFactory::load('libraries', 'comment'); $comment = new CComment(); $wallComments = $wall->comment; $wall->comment = $comment->stripCommentData($wall->comment); // Trigger the wall comments CWall::triggerWallComments($args); $wallData = new stdClass(); $wallData->id = $wall->id; $wallData->content = CWallLibrary::_getWallHTML($wall, $wallComments, $appType, $isOwner, $processFunc, $templateFile); CFactory::load('helpers', 'string'); $wallData->content = CStringHelper::replaceThumbnails($wallData->content); return $wallData; }
function deletegroupdiscussion($data) { require_once JPATH_SITE . '/components/com_community/libraries/core.php'; CFactory::load('libraries', 'apps'); $error_messages = array(); $response = NULL; $validated = true; if ("" == $data['groupid'] || 0 == $data['groupid']) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "groupid", "message" => "Groupid cannot be blank"); } $inputFilter = CFactory::getInputFilter(true); $validated = true; if (true == $validated) { if ($data['discuss_id'] == "" || $data['discuss_id'] == "0") { $error_messages[] = array("id" => 1, "fieldname" => "discussid", "message" => "Discuss id cannot be blank"); } else { CFactory::load('helpers', 'owner'); CFactory::load('models', 'discussions'); $groupsModel =& CFactory::getModel('groups'); $wallModel =& CFactory::getModel('wall'); $discussion =& JTable::getInstance('Discussion', 'CTable'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupid); //$isGroupAdmin = $groupsModel->isAdmin( $my->id , $group->id ); $discussion->set('id', strip_tags($data['discuss_id'])); if ($discussion->delete()) { // Remove the replies to this discussion as well since we no longer need them $wallModel->deleteAllChildPosts($data['discuss_id'], 'discussions'); // Substract the count from the groups table $groupsModel->substractDiscussCount($groupid); //$success_message = "Group discussion id[" . $discussion->id . "] deleted successfully."; } } } if (true == isset($error_messages) && 0 < sizeof($error_messages)) { $res = array(); foreach ($error_messages as $key => $error_message) { $res[] = $error_message; } $response = array("id" => 0, 'errors' => $res); } else { $response = array('id' => $discussion->id); } return $response; }
function createnewgroupdiscussion($data) { require_once JPATH_SITE . '/components/com_community/libraries/core.php'; CFactory::load('libraries', 'apps'); $error_messages = array(); $response = NULL; $validated = true; $db =& JFactory::getDBO(); $survey_filepath = JPATH_ROOT . DS . 'configuration' . DS . 'surveyfiles' . DS . $data['survey_filename']; if ("" == $data['creator'] || 0 == $data['creator']) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "creator", "message" => "Creator cannot be blank"); } if ("" == $data['groupid'] || 0 == $data['groupid']) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "groupid", "message" => "Groupid cannot be blank"); } if ($data['title'] == "" || 0 == strlen($data['title'])) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "title", "message" => "Title cannot be blank"); } if ($data['message'] == "" || 0 == strlen($data['message'])) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "message", "message" => "Message cannot be blank"); } $inputFilter = CFactory::getInputFilter(true); $validated = true; if (true == $validated) { // Bind the data with the table first $discussion =& JTable::getInstance('Discussion', 'CTable'); $discussion->set('title', strip_tags($data['title'])); $discussion->set('message', $inputFilter->clean($data['message'])); $discussion->set('groupid', $data['groupid']); $discussion->set('creator', $data['creator']); $discussion->set('created', gmdate('Y-m-d H:i:s')); $discussion->set('lastreplied', $discussion->created); $isNew = is_null($discussion->id) || !$discussion->id ? true : false; $query = "SELECT id FROM #__users WHERE id =" . $data['creator']; $db->setQuery($query); $creator = $db->LoadResult(); $query = "SELECT id FROM #__community_groups WHERE id =" . $data['groupid']; $db->setQuery($query); $isgroup = $db->LoadResult(); if (!$creator) { $error_messages[] = array("id" => 1, "fieldname" => "creator", "message" => "Invalid discussion creator id. Check 'creator' field in request"); } if (!$isgroup) { $error_messages[] = array("id" => 1, "fieldname" => "groupid", "message" => "Invalid group id. Check 'groupid' field in request"); } else { if (!file_exists($survey_filepath)) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "survey_filename", "message" => "Invalid Survey File Name"); } else { // Save the discussion. $discussion->store(); $survey = new stdClass(); $survey->group_id = $data['groupid']; $survey->discussion_id = $discussion->id; $survey->status = 0; $survey->timestamp = date('Y-m-d H:i:s'); $survey->filename = $data['survey_filename']; $db->insertObject('#__myhsclosure_survey', $survey, 'discussion_id'); } } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('group.discussion.create'); if (!$creator) { } if (!$isgroup) { } else { if ($data['isqm'] != '') { $db =& JFactory::getDBO(); $row = new stdClass(); $row->id = NULL; $row->discussion_id = $discussion->id; $row->qm_flag = $data['isqm']; $db->insertObject('#__myhs_qmflag', $row, 'id'); } } } if (true == isset($error_messages) && 0 < sizeof($error_messages)) { $res = array(); foreach ($error_messages as $key => $error_message) { $res[] = $error_message; } $response = array("id" => 0, 'errors' => $res); } else { $response = array('id' => $discussion->id); } return $response; }
/** * Method to save the group * @return false if create fail, return the group id if create is successful * */ public function save($event, $isDuplicate = false) { // Check for request forgeries JSession::checkToken('post') or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN')); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = $jinput->get('view', $this->getName(), 'String'); $view = $this->getView($viewName, '', $viewType); if (JString::strtoupper($jinput->getMethod()) != 'POST') { $view->addWarning(JText::_('COM_COMMUNITY_PERMISSION_DENIED_WARNING')); return false; } // Get my current data. $my = CFactory::getUser(); $validated = true; $model = $this->getModel('events'); $eventId = $jinput->get->get('eventid', 0, 'Int'); $isNew = $eventId == 0 ? true : false; $postData = JRequest::get('post'); $repeataction = $jinput->get('repeataction', null, 'NONE'); $inviteAllMembers = $jinput->get('invitegroupmembers', 0, 'INT'); if (!isset($postData['allday'])) { $postData['allday'] = 0; } //format startdate and eendate with time before we bind into event object $postData = $this->_formatStartEndDate($postData); $event->load($eventId); // record event original start and end date $postData['oldstartdate'] = $event->startdate; $postData['oldenddate'] = $event->enddate; $postData['unlisted'] = JRequest::getVar('unlisted', 0, 'post', 'int', JREQUEST_ALLOWRAW); if (CFactory::getConfig()->get('eventshowtimezone')) { $timezoneName = $postData['offset']; $postData['offset'] = CTimeHelper::getOffsetByTimezone($postData['offset']); //update offset before binding } $event->bind($postData); if (!array_key_exists('permission', $postData)) { $event->permission = 0; } if (!array_key_exists('allowinvite', $postData)) { $event->allowinvite = 0; } elseif (isset($postData['endtime-ampm']) && $postData['endtime-ampm'] == 'AM' && $postData['endtime-hour'] == 12) { $postData['endtime-hour'] = 00; } $inputFilter = CFactory::getInputFilter(true); // Despite the bind, we would still need to capture RAW description $event->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $event->description = $inputFilter->clean($event->description); // binding the params $params = new CParameter(''); $photoPermissionAdmin = $jinput->get('photopermission-admin', 0, 'STRING'); $photoPermissionMember = $jinput->get('photopermission-member', 0, 'STRING'); $videoPermissionAdmin = $jinput->get('videopermission-admin', 0, 'STRING'); $videoPermissionMember = $jinput->get('videopermission-member', 0, 'STRING'); $eventRecentPhotos = $jinput->get('eventrecentphotos', 6, 'STRING'); $eventRecentVideos = $jinput->get('eventrecentvideos', 6, 'STRING'); $params->set('eventrecentphotos', $eventRecentPhotos); $params->set('eventrecentvideos', $eventRecentVideos); $params->set('timezone', $timezoneName); if ($photoPermissionAdmin) { $params->set('photopermission', EVENT_PHOTO_PERMISSION_ADMINS); if ($photoPermissionMember) { $params->set('photopermission', EVENT_PHOTO_PERMISSION_ALL); } } else { $params->set('photopermission', EVENT_PHOTO_PERMISSION_DISABLE); } if ($videoPermissionAdmin) { $params->set('videopermission', EVENT_VIDEO_PERMISSION_ADMINS); if ($videoPermissionMember) { $params->set('videopermission', EVENT_VIDEO_PERMISSION_ALL); } } else { $params->set('videopermission', EVENT_VIDEO_PERMISSION_DISABLE); } $event->params = $params->toString(); // @rule: Test for emptyness if (empty($event->title)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_TITLE_ERROR'), 'error'); } if (empty($event->location)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_LOCATION_ERR0R'), 'error'); } // @rule: Test if the event is exists if ($model->isEventExist($event->title, $event->location, $event->startdate, $event->enddate, $eventId, $event->parent)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_TAKEN_ERROR'), 'error'); } // @rule: Start date cannot be empty if (empty($event->startdate)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_STARTDATE_ERROR'), 'error'); } // @rule: End date cannot be empty if (empty($event->enddate)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR'), 'error'); } // @rule: Number of ticket must at least be 0 if (Jstring::strlen($event->ticket) <= 0) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_TICKET_EMPTY_ERROR'), 'error'); } if (!is_numeric($event->ticket)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_TICKET_INVALID_ERROR'), 'error'); } $now = CTimeHelper::getLocaleDate(); require_once JPATH_COMPONENT . '/helpers/time.php'; if (CTimeHelper::timeIntervalDifference($event->startdate, $event->enddate) > 0) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_STARTDATE_GREATER_ERROR'), 'error'); } // 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; } // @rule: Event must not end in the past if (CTimeHelper::timeIntervalDifference($now->toSql(true), $event->enddate) > 0 && !$isToday && $isNew) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_ENDDATE_GREATER_ERROR'), 'error'); } $eventChild = array(); // check event recurrence limit. if (!empty($event->repeat) && ($isNew || $postData['repeataction'] == 'future')) { $repeatLimit = 'COMMUNITY_EVENT_RECURRING_LIMIT_' . strtoupper($event->repeat); if (defined($repeatLimit)) { $eventChild = $this->_generateRepeatList($event); if (count($eventChild) > constant($repeatLimit)) { $validated = false; $mainframe->enqueueMessage(sprintf(JText::_('COM_COMMUNITY_EVENTS_REPEAT_LIMIT_ERROR'), constant($repeatLimit)), 'error'); } } } if ($validated) { // If show event timezone is disabled, we need to set the event offset to 0. $config = CFactory::getConfig(); if (!$config->get('eventshowtimezone')) { $event->offset = 0; } if ($isDuplicate) { $event->id = 0; $isNew = 1; } // Set the default thumbnail and avatar for the event just in case // the user decides to skip this if ($isNew) { $event->creator = $my->id; $config = CFactory::getConfig(); //@rule: If event moderation is enabled, event should be unpublished by default $event->published = $this->isPublished(); $event->created = JFactory::getDate()->toSql(); $handler = CEventHelper::getHandler($event); $event->contentid = $handler->getContentId(); $event->type = $handler->getType(); } $event->store(); // Save event members if ($isNew && !$event->isRecurring()) { $this->_saveMember($event); // Increment the member count $event->updateGuestStats(); $event->store(); } if ($isNew) { $event->parent = !empty($event->repeat) ? $event->id : 0; } // Save recurring event's child. $this->_saveRepeatChild($event, $eventChild, $isNew, $postData); // Stream and notification if ($isNew) { // add activity stream $this->_addActivityStream($event); //add user points $action_str = 'events.create'; CUserPoints::assignPoint($action_str); //add notification: New group event is added $this->_addGroupNotification($event); } $validated = $event->id; $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_EVENTS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); } //if saved and we should invite all members of the group if ($inviteAllMembers && $event->id && $event->contentid) { $groupid = $event->contentid; $groupsModel = CFactory::getModel('groups'); $members = $groupsModel->getMembers($groupid, 0, true, false, SHOW_GROUP_ADMIN); $membersArr = array(); foreach ($members as $member) { if ($member->id == $my->id) { continue; } $membersArr[] = $member->id; } $inviteMail = $this->inviteUsers($event->id, $membersArr, '', ''); if ($inviteMail instanceof CInvitationMail) { // Once stored, we need to store selected user so they wont be invited again $callback = "events,inviteUsers"; $invitation = JTable::getInstance('Invitation', 'CTable'); $invitation->load($callback, $event->id); if ($membersArr) { if (!$invitation->id) { // If the record doesn't exists, we need add them into the $invitation->cid = $event->id; $invitation->callback = $callback; } $invitation->users = implode(',', $membersArr); $invitation->store(); } //start sending email and notification CNotificationLibrary::add($inviteMail->getCommand(), $my->id, $membersArr, $inviteMail->getTitle(), $inviteMail->getContent(), '', $inviteMail->getParams()); } } return $validated; }
public function check() { // Santinise data $safeHtmlFilter = CFactory::getInputFilter(); $this->name = $safeHtmlFilter->clean($this->name); $this->description = $safeHtmlFilter->clean($this->description); if (empty($this->creator)) { return false; } return true; }
private function _saveDiscussion(&$discussion) { $topicId = JRequest::getVar('topicid', 'POST'); $postData = JRequest::get('post'); $inputFilter = CFactory::getInputFilter(true); $groupid = JRequest::getVar('groupid', '', 'REQUEST'); $my = CFactory::getUser(); $mainframe = JFactory::getApplication(); $groupid = JRequest::getVar('groupid', '', 'REQUEST'); $groupsModel =& $this->getModel('groups'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupid); $discussion->bind($postData); CFactory::load('helpers', 'owner'); $creator = CFactory::getUser($discussion->creator); if ($my->id != $creator->id && !empty($discussion->creator) && !$groupsModel->isAdmin($my->id, $discussion->groupid) && !COwnerHelper::isCommunityAdmin()) { $mainframe->enqueueMessage(JText::_('CC ACCESS FORBIDDEN'), 'error'); return false; } $isNew = is_null($discussion->id) || !$discussion->id ? true : false; if ($isNew) { $discussion->creator = $my->id; } $discussion->groupid = $groupid; $discussion->created = gmdate('Y-m-d H:i:s'); $discussion->lastreplied = $discussion->created; $discussion->message = JRequest::getVar('message', '', 'post', 'string', JREQUEST_ALLOWRAW); $discussion->message = $inputFilter->clean($discussion->message); // @rule: do not allow html tags in the title $discussion->title = strip_tags($discussion->title); CFactory::load('libraries', 'apps'); $appsLib =& CAppPlugins::getInstance(); $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-discussionform')); $validated = true; if (empty($saveSuccess) || !in_array(false, $saveSuccess)) { if (empty($discussion->title)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC DISCUSSION TOPIC CANNOT BE EMPTY'), 'error'); } if (empty($discussion->message)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC DISCUSSION CANNOT BE EMPTY'), 'error'); } if ($validated) { CFactory::load('models', 'discussions'); $discussion->store(); if ($isNew) { $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupid); // @rule: only add the activities of the discussion if the group is not private. if ($group->approvals == COMMUNITY_PUBLIC_GROUP) { // Add logging. $url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid); CFactory::load('libraries', 'activities'); $act = new stdClass(); $act->cmd = 'group.discussion.create'; $act->actor = $my->id; $act->target = 0; $act->title = JText::sprintf('CC ACTIVITIES NEW GROUP DISCUSSION', '{group_url}', $group->name); $act->content = $message; $act->app = 'groups'; $act->cid = $group->id; $params = new JParameter(''); $params->set('action', 'group.discussion.create'); $params->set('topic_id', $discussion->id); $params->set('topic', $discussion->title); $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id); $params->set('topic_url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $group->id . '&topicid=' . $discussion->id); CActivityStream::add($act, $params->toString()); } //@rule: Add notification for group members whenever a new discussion created. $config = CFactory::getConfig(); if ($config->get('groupdiscussnotification') == 1) { $model =& $this->getModel('groups'); $members = $model->getMembers($groupid, null); $admins = $model->getAdmins($groupid, null); $membersArray = array(); foreach ($members as $row) { $membersArray[] = $row->id; } foreach ($admins as $row) { $membersArray[] = $row->id; } unset($members); unset($admins); // Add notification CFactory::load('libraries', 'notification'); $params = new JParameter(''); $params->set('url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $group->id . '&topicid=' . $discussion->id); $params->set('group', $group->name); $params->set('user', $my->getDisplayName()); $params->set('subject', $discussion->title); $params->set('message', $discussion->message); CNotificationLibrary::add('groups.create.discussion', $discussion->creator, $membersArray, JText::sprintf('CC NEW DISCUSSION NOTIFICATION EMAIL SUBJECT', $group->name), '', 'groups.discussion', $params); } } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('group.discussion.create'); } } else { $validated = false; } return $validated; }
function updategroupdiscussion($data) { require_once JPATH_SITE . '/components/com_community/libraries/core.php'; CFactory::load('libraries', 'apps'); $error_messages = array(); $response = NULL; $validated = true; $db =& JFactory::getDBO(); if ("" == $data['creator'] || 0 == $data['creator']) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "creator", "message" => "Creator cannot be blank"); } if ("" == $data['discuss_id'] || 0 == $data['discuss_id']) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "discussid", "message" => "Discuss_id cannot be blank"); } if ("" == $data['groupid'] || 0 == $data['groupid']) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "groupid", "message" => "Groupid cannot be blank"); } if ($data['title'] == "") { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "title", "message" => "Title cannot be blank"); } if ($data['message'] == "") { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "message", "message" => "Message cannot be blank"); } $inputFilter = CFactory::getInputFilter(true); $validated = true; if (true == $validated) { // Bind the data with the table first $survey_filepath = JPATH_ROOT . DS . 'polltxtfiles/' . $data['survey_filename']; $discussion =& JTable::getInstance('Discussion', 'CTable'); $discussion->set('id', strip_tags($data['discuss_id'])); $discussion->set('title', strip_tags($data['title'])); $discussion->set('message', $inputFilter->clean($data['message'])); $discussion->set('groupid', $data['groupid']); $discussion->set('creator', $data['creator']); $discussion->set('created', gmdate('Y-m-d H:i:s')); $discussion->set('lastreplied', $discussion->created); $isNew = is_null($discussion->id) || !$discussion->id ? true : false; // Save the discussion. $query = "SELECT id FROM #__users WHERE id =" . $data['creator']; $db->setQuery($query); $creator = $db->LoadResult(); $query = "SELECT id FROM #__community_groups WHERE id =" . $data['groupid']; $db->setQuery($query); $isgroup = $db->LoadResult(); if (!$creator) { $error_messages[] = array("id" => 1, "fieldname" => "creator", "message" => "Invalid discussion creator id. Check 'creator' field in request"); } if (!$isgroup) { $error_messages[] = array("id" => 1, "fieldname" => "groupid", "message" => "Invalid group id. Check 'groupid' field in request"); } else { $query = "SELECT id,alert_filename FROM #__myhsclosure_survey WHERE group_id = '" . $data['groupid'] . "' AND discussion_id ='" . $data['discuss_id'] . "'"; $db->setQuery($query); $res = $db->LoadObjectList(); if ($data['survey_filename'] != "") { //if($res[0]->alert_filename == "") //{ if (!file_exists($survey_filepath)) { $validated = false; $error_messages[] = array("id" => 1, "fieldname" => "survey_filename", "message" => "Invalid Survey File Name"); } else { // Save the discussion. $discussion->store(); $survey = new stdClass(); $survey->id = $res[0]->id; $survey->group_id = $data['groupid']; $survey->discussion_id = $data['discuss_id']; $survey->status = 0; $survey->discussion_created_date = gmdate('Y-m-d H:i:s'); $survey->alert_filename = $data['survey_filename']; $db->updateObject('#__myhsclosure_survey', $survey, 'id'); } //} } } if (true == isset($error_messages) && 0 < sizeof($error_messages)) { $res = array(); foreach ($error_messages as $key => $error_message) { $res[] = $error_message; } $response = array("id" => 0, 'errors' => $res); } else { $response = array('id' => $discussion->id); } return $response; } }
public static function parseSettings($settings, $saveKey) { $settingsArray = array(); $safeHtmlFilter = CFactory::getInputFilter(); foreach ($settings as $key => $value) { if (!strlen($key)) { continue; } // Build result array if (strlen($value)) { $key = $safeHtmlFilter->clean($key); $value = $safeHtmlFilter->clean($value); $settingsArray[$key] = $value; } } // Store SCSS override JSON encoded in the database $themeTable = JTable::getInstance('Theme', 'CommunityTable'); $themeTable->load('settings'); $themeTable->key = 'settings'; // needed for new record if (strlen($themeTable->value)) { $oldSettings = json_decode($themeTable->value, true); } else { $oldSettings = array('profile' => array(), 'general' => array()); } $oldSettings[$saveKey] = $settingsArray; $themeTable->value = json_encode($oldSettings); $themeTable->store(); }
/** * Save a new discussion * @param type $discussion * @return boolean * */ private function _saveDiscussion(&$discussion) { $topicId = JRequest::getVar('topicid', 'POST'); $postData = JRequest::get('post'); $inputFilter = CFactory::getInputFilter(true); $groupid = JRequest::getVar('groupid', '', 'REQUEST'); $my = CFactory::getUser(); $mainframe = JFactory::getApplication(); $groupid = JRequest::getVar('groupid', '', 'REQUEST'); $groupsModel =& $this->getModel('groups'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupid); $discussion->bind($postData); CFactory::load('helpers', 'owner'); $creator = CFactory::getUser($discussion->creator); if ($my->id != $creator->id && !empty($discussion->creator) && !$groupsModel->isAdmin($my->id, $discussion->groupid) && !COwnerHelper::isCommunityAdmin()) { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN'), 'error'); return false; } $isNew = is_null($discussion->id) || !$discussion->id ? true : false; if ($isNew) { $discussion->creator = $my->id; } $discussion->groupid = $groupid; $discussion->created = gmdate('Y-m-d H:i:s'); $discussion->lastreplied = $discussion->created; $discussion->message = JRequest::getVar('message', '', 'post', 'string', JREQUEST_ALLOWRAW); $discussion->message = $inputFilter->clean($discussion->message); // @rule: do not allow html tags in the title $discussion->title = strip_tags($discussion->title); CFactory::load('libraries', 'apps'); $appsLib =& CAppPlugins::getInstance(); $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-groups-discussionform')); $validated = true; if (empty($saveSuccess) || !in_array(false, $saveSuccess)) { $config = CFactory::getConfig(); // @rule: Spam checks if ($config->get('antispam_akismet_discussions')) { CFactory::load('libraries', 'spamfilter'); $filter = CSpamFilter::getFilter(); $filter->setAuthor($my->getDisplayName()); $filter->setMessage($discussion->title . ' ' . $discussion->message); $filter->setEmail($my->email); $filter->setURL(CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id)); $filter->setType('message'); $filter->setIP($_SERVER['REMOTE_ADDR']); if ($filter->isSpam()) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_DISCUSSIONS_MARKED_SPAM'), 'error'); } } if (empty($discussion->title)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_GROUPS_DISCUSSION_TITLE_EMPTY'), 'error'); } if (empty($discussion->message)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_GROUPS_DISCUSSION_BODY_EMPTY'), 'error'); } if ($validated) { CFactory::load('models', 'discussions'); $discussion->store(); if ($isNew) { $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupid); // Add logging. $url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupid); CFactory::load('libraries', 'activities'); $act = new stdClass(); $act->cmd = 'group.discussion.create'; $act->actor = $my->id; $act->target = 0; $act->title = JText::sprintf('COM_COMMUNITY_GROUPS_NEW_GROUP_DISCUSSION', '{group_url}', $group->name); $act->content = $discussion->message; $act->app = 'groups.discussion'; $act->cid = $discussion->id; $act->groupid = $group->id; $act->group_access = $group->approvals; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'groups.discussion'; $params = new CParameter(''); $params->set('action', 'group.discussion.create'); $params->set('topic_id', $discussion->id); $params->set('topic', $discussion->title); $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id); $params->set('topic_url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $group->id . '&topicid=' . $discussion->id); CActivityStream::add($act, $params->toString()); //@rule: Add notification for group members whenever a new discussion created. $config = CFactory::getConfig(); if ($config->get('groupdiscussnotification') == 1) { $model =& $this->getModel('groups'); $members = $model->getMembers($groupid, null); $admins = $model->getAdmins($groupid, null); $membersArray = array(); foreach ($members as $row) { $membersArray[] = $row->id; } foreach ($admins as $row) { $membersArray[] = $row->id; } unset($members); unset($admins); // Add notification CFactory::load('libraries', 'notification'); $params = new CParameter(''); $params->set('url', 'index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $group->id . '&topicid=' . $discussion->id); $params->set('group', $group->name); $params->set('user', $my->getDisplayName()); $params->set('subject', $discussion->title); $params->set('message', $discussion->message); CNotificationLibrary::add('etype_groups_create_discussion', $discussion->creator, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_DISCUSSION_NOTIFICATION_EMAIL_SUBJECT', $group->name), '', 'groups.discussion', $params); } } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('group.discussion.create'); } } else { $validated = false; } return $validated; }
public function check() { // Santinise data $safeHtmlFilter = CFactory::getInputFilter(); $this->title = $safeHtmlFilter->clean($this->title); $this->description = $safeHtmlFilter->clean($this->description); $this->category_id = JString::trim((int) $this->category_id); $this->permissions = JString::trim((int) $this->permissions); // Validate user information if ($this->title == '') { $this->title = JText::_('COM_COMMUNITY_VIDEOS_TITLE_EMPTY'); } // if ($this->description == '') // $this->description = JText::_('COM_COMMUNITY_VIDEOS_NO_DESCRIPTION'); if ($this->created == null) { $now = JFactory::getDate(); $this->created = $now->toSql(); } if ($this->published == null) { $this->published = 1; } return true; }
/** * Method to save the group * @return false if create fail, return the group id if create is successful **/ public function save(&$event) { // Check for request forgeries JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN')); $mainframe = JFactory::getApplication(); $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view = $this->getView($viewName, '', $viewType); if (JString::strtoupper(JRequest::getMethod()) != 'POST') { $view->addWarning(JText::_('COM_COMMUNITY_PERMISSION_DENIED_WARNING')); return false; } // Get my current data. $my = CFactory::getUser(); $validated = true; $model = $this->getModel('events'); $eventId = JRequest::getInt('eventid', '0'); $isNew = $eventId == '0' ? true : false; $postData = JRequest::get('post'); //format startdate and eendate with time before we bind into event object $this->_formatStartEndDate($postData); // if( !empty($postData['coordinate']) ) // { // $coord = explode( ',', $postData['coordinate'] ); // $postData['latitude'] = trim($coord[0]); // $postData['longitude'] = trim($coord[1]); // } $event->load($eventId); $event->bind($postData); if (!array_key_exists('permission', $postData)) { $event->permission = 0; } if (!array_key_exists('allowinvite', $postData)) { $event->allowinvite = 0; } elseif (isset($postData['endtime-ampm']) && $postData['endtime-ampm'] == 'AM' && $postData['endtime-hour'] == 12) { $postData['endtime-hour'] = 00; } $inputFilter = CFactory::getInputFilter(true); // Despite the bind, we would still need to capture RAW description $event->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $event->description = $inputFilter->clean($event->description); // @rule: Test for emptyness if (empty($event->title)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_TITLE_ERROR'), 'error'); } if (empty($event->location)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_LOCATION_ERR0R'), 'error'); } // @rule: Test if the event is exists if ($model->isEventExist($event->title, $event->location, $event->startdate, $event->enddate, $eventId)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_TAKEN_ERROR'), 'error'); } // @rule: Description cannot be empty /*if( empty( $event->description ) ) { $validated = false; $mainframe->enqueueMessage( JText::_('COM_COMMUNITY_EVENTS_TAKEN_ERROR'), 'error'); }*/ // @rule: Start date cannot be empty if (empty($event->startdate)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_STARTDATE_ERROR'), 'error'); } // @rule: End date cannot be empty if (empty($event->enddate)) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR'), 'error'); } // @rule: Number of ticket must at least be 0 if (Jstring::strlen($event->ticket) <= 0) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_TICKET_EMPTY_ERROR'), 'error'); } require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'time.php'; if (CTimeHelper::timeIntervalDifference($event->startdate, $event->enddate) > 0) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_STARTDATE_GREATER_ERROR'), 'error'); } // @rule: Event must not end in the past $now = CTimeHelper::getLocaleDate(); if (CTimeHelper::timeIntervalDifference($now->toMySQL(true), $event->enddate) > 0) { $validated = false; $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_EVENTS_ENDDATE_GREATER_ERROR'), 'error'); } if ($validated) { // If show event timezone is disabled, we need to set the event offset to 0. $config = CFactory::getConfig(); if (!$config->get('eventshowtimezone')) { $event->offset = 0; } // Set the default thumbnail and avatar for the event just in case // the user decides to skip this if ($isNew) { $event->creator = $my->id; $config = CFactory::getConfig(); //@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->store(); if ($isNew) { CFactory::load('helpers', 'event'); $handler = CEventHelper::getHandler($event); $event->contentid = $handler->getContentId(); $event->type = $handler->getType(); // 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(); CFactory::load('helpers', 'event'); $handler = CEventHelper::getHandler($event); // Activity stream purpose if the event is a public event if ($handler->isPublic()) { $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); // Set activity group id if the event is in group $act->groupid = $event->type == 'group' ? $event->contentid : null; $act->eventid = $event->id; $act->location = $event->location; $act->comment_id = $event->id; $act->comment_type = 'events'; $act->like_id = $event->id; $act->like_type = 'events'; $params = new CParameter(''); $action_str = 'events.create'; $cat_url = $handler->getFormattedLink('index.php?option=com_community&view=events&task=display&categoryid=' . $event->catid, false, true, false); $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); //add notification: New group event is added CFactory::load('helpers', 'event'); if ($event->type == CEventHelper::GROUP_TYPE && $event->contentid != 0) { CFactory::load('libraries', 'notification'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($event->contentid); $modelGroup =& $this->getModel('groups'); $groupMembers = array(); $groupMembers = $modelGroup->getMembersId($event->contentid, true); $subject = JText::sprintf('COM_COMMUNITY_GROUP_NEW_EVENT_NOTIFICATION', $my->getDisplayName(), $group->name); $params = new CParameter(''); $params->set('title', $event->title); $params->set('group', $group->name); $params->set('subject', $subject); $params->set('url', 'index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id); CNotificationLibrary::add('etype_groups_create_event', $my->id, $groupMembers, $subject, '', 'groups.event', $params); } } $validated = $event->id; $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_EVENTS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); } return $validated; }
/** * @todo: user should be loaded from library or other model */ public function write() { CFactory::setActiveProfile(); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $my = CFactory::getUser(); $view = $this->getView('inbox'); $data = new stdClass(); if ($my->id == 0) { return $this->blockUnregister(); } $inputFilter = CFactory::getInputFilter(true); $data->to = $jinput->post->get('friends', array(), 'array'); $data->subject = $inputFilter->clean($jinput->post->get('subject', '', 'STRING')); $data->body = $inputFilter->clean($jinput->post->get('body', '', 'STRING')); $data->photo = $jinput->post->get('photo', '', 'INT'); $data->sent = 0; $model = $this->getModel('user'); $actualTo = array(); // are we saving ?? if ($saving = $jinput->post->get('action', '', 'STRING')) { $appsLib = CAppPlugins::getInstance(); $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-inbox-write')); if (empty($saveSuccess) || !in_array(false, $saveSuccess)) { // @rule: Check if user exceeded limit $inboxModel = $this->getModel('inbox'); $config = CFactory::getConfig(); $useRealName = $config->get('displayname') == 'name' ? true : false; $maxSent = $config->get('pmperday'); $totalSent = $inboxModel->getTotalMessageSent($my->id); if ($totalSent >= $maxSent && $maxSent != 0) { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=inbox', false), JText::_('COM_COMMUNITY_PM_LIMIT_REACHED')); } $validated = true; // @rule: Spam checks if ($this->_isSpam($my, $data->subject . ' ' . $data->body)) { $view->addWarning(JText::_('COM_COMMUNITY_INBOX_MESSAGE_MARKED_SPAM')); $validated = false; } // Block users $getBlockStatus = new blockUser(); // Enable multiple recipients // @since 2.4 $actualTo = $data->to; $actualTo = array_unique($actualTo); if (!(count($actualTo) > 0)) { $view->addWarning(JText::_('COM_COMMUNITY_INBOX_RECEIVER_MISSING')); $validated = false; } $tempUser = array(); foreach ($actualTo as $recepientId) { // Get name for error message show $user = CFactory::getUser($recepientId); $name = $user->getDisplayName(); $thumb = $user->getThumbAvatar(); if ($getBlockStatus->isUserBlocked($recepientId, 'inbox') && !COwnerHelper::isCommunityAdmin()) { $view->addWarning(JText::_('COM_COMMUNITY_YOU_ARE_BLOCKED_BY_USER') . ' - ' . $name); $validated = false; } // restrict user to send message to themselve if ($my->id == $recepientId) { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=inbox&task=write', false), JText::_('COM_COMMUNITY_INBOX_MESSAGE_CANNOT_SEND_TO_SELF'), 'error'); return; } $tempUser[] = array('rid' => $recepientId, 'avatar' => $thumb, 'name' => $name); //since 2.4, to keep track previous 'to' info } $data->toUsersInfo = $tempUser; if (empty($data->subject)) { $view->addWarning(JText::_('COM_COMMUNITY_INBOX_SUBJECT_MISSING')); $validated = false; } if (empty($data->body)) { $view->addWarning(JText::_('COM_COMMUNITY_INBOX_MESSAGE_EMPTY')); $validated = false; } // store message if ($validated) { $model = $this->getModel('inbox'); $msgData = JRequest::get('POST'); $msgData['to'] = $actualTo; $msgid = $model->send($msgData); $data->sent = 1; //add user points CUserPoints::assignPoint('inbox.message.send'); // Add notification $params = new CParameter(''); $params->set('url', 'index.php?option=com_community&view=inbox&task=read&msgid=' . $msgid); $params->set('message', $data->body); $params->set('title', $data->subject); $params->set('msg_url', CRoute::_('index.php?option=com_community&view=inbox&task=read&msgid=' . $msgid)); $params->set('msg', JText::_('COM_COMMUNITY_PRIVATE_MESSAGE')); foreach ($actualTo as $recepientId) { CNotificationLibrary::add('inbox_create_message', $my->id, $recepientId, JText::sprintf('COM_COMMUNITY_SENT_YOU_MESSAGE'), '', 'inbox.sent', $params); } $mainframe->redirect(CRoute::_('index.php?option=com_community&view=inbox&task=read&msgid=' . $msgid, false), JText::_('COM_COMMUNITY_INBOX_MESSAGE_SENT')); return; } } } $inModel = $this->getModel('inbox'); $newFilter['user_id'] = $my->id; $data->inbox = $inModel->countUnRead($newFilter); $this->_icon = 'compose'; echo $view->get('write', $data); }
/** * Method to save the group * @return false if create fail, return the group id if create is successful **/ public function save(&$event) { // Check for request forgeries JRequest::checkToken() or jexit(JText::_('CC INVALID TOKEN')); $mainframe = JFactory::getApplication(); $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view = $this->getView($viewName, '', $viewType); if (JString::strtoupper(JRequest::getMethod()) != 'POST') { $view->addWarning(JText::_('CC PERMISSION DENIED')); return false; } // Get my current data. $my = CFactory::getUser(); $validated = true; $model = $this->getModel('events'); $eventId = JRequest::getInt('eventid', '0'); $isNew = $eventId == '0' ? true : false; $postData = JRequest::get('post'); //format startdate and eendate with time before we bind into event object if (isset($postData['starttime-ampm']) && $postData['starttime-ampm'] == 'PM' && $postData['starttime-hour'] != 12) { $postData['starttime-hour'] = $postData['starttime-hour'] + 12; } if (isset($postData['endtime-ampm']) && $postData['endtime-ampm'] == 'PM' && $postData['endtime-hour'] != 12) { $postData['endtime-hour'] = $postData['endtime-hour'] + 12; } $postData['startdate'] = $postData['startdate'] . ' ' . $postData['starttime-hour'] . ':' . $postData['starttime-min'] . ':00'; $postData['enddate'] = $postData['enddate'] . ' ' . $postData['endtime-hour'] . ':' . $postData['endtime-min'] . ':00'; unset($postData['startdatetime']); unset($postData['enddatetime']); unset($postData['starttime-hour']); unset($postData['starttime-min']); unset($postData['starttime-ampm']); unset($postData['endtime-hour']); unset($postData['endtime-min']); unset($postData['endtime-ampm']); $event->load($eventId); $event->bind($postData); $inputFilter = CFactory::getInputFilter(true); // Despite the bind, we would still need to capture RAW description $event->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $event->description = $inputFilter->clean($event->description); // @rule: Test for emptyness if (empty($event->title)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC EVENTS TITLE CANNOT BE EMPTY'), 'error'); } if (empty($event->location)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC EVENTS LOCATION CANNOT BE EMPTY'), 'error'); } // @rule: Test if group exists if ($model->isEventExist($event->title, $event->location, $eventId)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC EVENTS TAKEN'), 'error'); } // @rule: Description cannot be empty if (empty($event->description)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC EVENTS DESCRIPTION CANNOT BE EMPTY'), 'error'); } // @rule: Start date cannot be empty if (empty($event->startdate)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC STARTDATE CANNOT BE EMPTY'), 'error'); } // @rule: End date cannot be empty if (empty($event->enddate)) { $validated = false; $mainframe->enqueueMessage(JText::_('CC ENDATE CANNOT BE EMPTY'), 'error'); } // @rule: Number of ticket must at least be 0 if (Jstring::strlen($event->ticket) <= 0) { $validated = false; $mainframe->enqueueMessage(JText::_('CC EVENTS TICKET CANNOT BE EMPTY'), 'error'); } require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'time.php'; if (CTimeHelper::timeIntervalDifference($event->startdate, $event->enddate) > 0) { $validated = false; $mainframe->enqueueMessage(JText::_('CC EVENT STARTDATE GREATER THAN ENDDATE'), 'error'); } // @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) { $validated = false; $mainframe->enqueueMessage(JText::_('CC EVENT ENDDATE GREATER THAN NOW'), 'error'); } if ($validated) { // If event offset is disabled, we need to set it to 0. if ($event->offset == null) { $event->offset = 0; } // Set the default thumbnail and avatar for the event just in case // the user decides to skip this if ($isNew) { $event->creator = $my->id; $config = CFactory::getConfig(); //@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->store(); if ($isNew) { CFactory::load('helpers', 'event'); $handler = CEventHelper::getHandler($event); $event->contentid = $handler->getContentId(); $event->type = $handler->getType(); // 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(); CFactory::load('helpers', 'event'); $handler = CEventHelper::getHandler($event); // Activity stream purpose if the event is a public event if ($handler->isPublic()) { $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); $params = new JParameter(''); $action_str = 'events.create'; $params->set('action', $action_str); $params->set('event_url', $url); // Add activity logging CFactory::load('libraries', 'activities'); CActivityStream::add($act, $params->toString()); } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint($action_str); } $validated = $event->id; } return $validated; }