public function apply() { $result = $this->doSave(); $layout = Jstring::strtolower(JRequest::getString('active', '')); $child = Jstring::strtolower(JRequest::getString('activechild', '')); $component = JRequest::getString('target', ''); $mainframe = JFactory::getApplication(); $mainframe->redirect('index.php?option=com_komento&view=integrations&component=' . $component . '&active=' . $layout, $result['message'], $result['type']); }
public function apply() { $this->doSave(); $layout = Jstring::strtolower(JRequest::getString('active', '')); $child = Jstring::strtolower(JRequest::getString('activechild', '')); $advance = JRequest::getInt('advance', ''); $redirect = 'index.php?option=com_komento&view=system&active=' . $layout . '&activechild=' . $child; if ($advance) { $redirect .= '&advance=' . $advance; } $mainframe = JFactory::getApplication(); $mainframe->redirect($redirect); }
/** * Set the avatar for specific application. Caller must have a database table * that is named after the appType. E.g, users should have jos_community_users * * @param appType Application type. ( users , groups ) * @param path The relative path to the avatars. * @param type The type of Image, thumb or avatar. * **/ function setImage($id, $path, $type = 'thumb') { CError::assert($id, '', '!empty', __FILE__, __LINE__); CError::assert($path, '', '!empty', __FILE__, __LINE__); $db =& $this->getDBO(); // Fix the back quotes $path = JString::str_ireplace('\\', '/', $path); $type = JString::strtolower($type); // Test if the record exists. $query = 'SELECT ' . $db->nameQuote($type) . ' FROM ' . $db->nameQuote('#__community_users') . 'WHERE ' . $db->nameQuote('userid') . '=' . $db->Quote($id); $db->setQuery($query); $oldFile = $db->loadResult(); if ($db->getErrorNum()) { JError::raiseError(500, $db->stderr()); } if (!$oldFile) { $query = 'UPDATE ' . $db->nameQuote('#__community_users') . ' ' . 'SET ' . $db->nameQuote($type) . '=' . $db->Quote($path) . ' ' . 'WHERE ' . $db->nameQuote('userid') . '=' . $db->Quote($id); $db->setQuery($query); $db->query($query); if ($db->getErrorNum()) { JError::raiseError(500, $db->stderr()); } } else { $query = 'UPDATE ' . $db->nameQuote('#__community_users') . ' ' . 'SET ' . $db->nameQuote($type) . '=' . $db->Quote($path) . ' ' . 'WHERE ' . $db->nameQuote('userid') . '=' . $db->Quote($id); $db->setQuery($query); $db->query($query); if ($db->getErrorNum()) { JError::raiseError(500, $db->stderr()); } // If old file is default_thumb or default, we should not remove it. // Need proper way to test it if (!Jstring::stristr($oldFile, 'components/com_community/assets/default.jpg') && !Jstring::stristr($oldFile, 'components/com_community/assets/default_thumb.jpg')) { // File exists, try to remove old files first. $oldFile = JString::str_ireplace('/', DS, $oldFile); JFile::delete($oldFile); } } }
public function __construct($profile) { $config = Komento::getConfig(); $phpbbpath = $config->get('layout_phpbb_path'); $phpbburl = $config->get('layout_phpbb_url'); $phpbburl = Jstring::rtrim($phpbburl, '/', ''); $phpbbDB = $this->_getPhpbbDBO($phpbbpath); $phpbbConfig = $this->_getPhpbbConfig(); $phpbbuserid = 0; if (empty($phpbbConfig)) { return false; } $juser = JFactory::getUser($profile->id); $sql = 'SELECT `user_id`, `username`, `user_avatar`, `user_avatar_type` ' . 'FROM `#__users` WHERE LOWER(`username`) = ' . $phpbbDB->quote(strtolower($juser->username)) . ' ' . 'LIMIT 1'; $phpbbDB->setQuery($sql); $result = $phpbbDB->loadObject(); $phpbbuserid = empty($result->user_id) ? '0' : $result->user_id; if (!empty($result->user_avatar)) { switch ($result->user_avatar_type) { case '1': $subpath = $phpbbConfig->avatar_upload_path; $phpEx = JFile::getExt(__FILE__); $source = $phpbburl . '/download/file.' . $phpEx . '?avatar=' . $result->user_avatar; break; case '2': $source = $result->user_avatar; break; case '3': $subpath = $phpbbConfig->avatar_gallery_path; $source = $phpbburl . '/' . $subpath . '/' . $result->user_avatar; break; default: $subpath = ''; $source = ''; } } else { $sql = 'SELECT ' . $phpbbDB->nameQuote('theme_name') . ' ' . 'FROM ' . $phpbbDB->nameQuote('#__styles_theme') . ' ' . 'WHERE ' . $phpbbDB->nameQuote('theme_id') . ' = ' . $phpbbDB->quote($phpbbConfig->default_style); $phpbbDB->setQuery($sql); $theme = $phpbbDB->loadObject(); $defaultPath = 'styles/' . $theme->theme_name . '/theme/images/no_avatar.gif'; $source = $phpbburl . '/' . $defaultPath; } $this->avatar = $source; $this->link = $phpbburl . '/memberlist.php?mode=viewprofile&u=' . $phpbbuserid; return parent::__construct($profile); }
/** * 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; }
/** * 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; }
function uploadAndSetImage($file, $id, $what) { $mainframe =& JFactory::getApplication(); CFactory::load('helpers', 'image'); $config = CFactory::getConfig(); $uploadLimit = (double) $config->get('maxuploadsize'); $uploadLimit = $uploadLimit * 1024 * 1024; // @rule: Limit image size based on the maximum upload allowed. if (filesize($file['tmp_name']) > $uploadLimit) { $mainframe->enqueueMessage(XiptText::_('IMAGE_FILE_SIZE_EXCEEDED'), 'error'); $mainframe->redirect(CRoute::_('index.php?option=com_xipt&view=profiletypes&task=edit&id=' . $id, false)); } if (!cValidImage($file['tmp_name'])) { $mainframe->enqueueMessage(XiptText::_('IMAGE_FILE_NOT_SUPPORTED'), 'error'); } else { switch ($what) { case 'avatar': $imageMaxWidth = AVATAR_WIDTH; $thumbWidth = AVATAR_WIDTH_THUMB; $thumbHeight = AVATAR_HEIGHT_THUMB; $imgPrefix = 'avatar_'; break; case 'watermark': $imageMaxWidth = WATERMARK_WIDTH; $thumbWidth = WATERMARK_WIDTH_THUMB; $thumbHeight = WATERMARK_HEIGHT_THUMB; $imgPrefix = 'watermark_'; break; } $storage = PROFILETYPE_AVATAR_STORAGE_PATH; $storageImage = $storage . DS . $imgPrefix . $id . cImageTypeToExt($file['type']); $storageThumbnail = $storage . DS . $imgPrefix . $id . '_thumb' . cImageTypeToExt($file['type']); $image = PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . $imgPrefix . $id . cImageTypeToExt($file['type']); //$thumbnail = PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . $imgPrefix . $id.'_thumb' . cImageTypeToExt( $file['type'] ); //here check if folder exist or not. if not then create it. if (JFolder::exists($storage) == false) { JFolder::create($storage); } // Only resize when the width exceeds the max. if (!cImageResizePropotional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) { $mainframe->enqueueMessage(XiptText::sprintf('COM_XIPT_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error'); } // Generate thumbnail if (!cImageCreateThumb($file['tmp_name'], $storageThumbnail, $file['type'], $thumbWidth, $thumbHeight)) { $mainframe->enqueueMessage(XiptText::sprintf('COM_XIPT_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error'); } $oldFile = XiptLibProfiletypes::getProfiletypeData($id, $what); // If old file is default_thumb or default, we should not remove it. if (!Jstring::stristr($oldFile, DEFAULT_AVATAR) && !Jstring::stristr($oldFile, DEFAULT_AVATAR_THUMB) && $oldFile != $image && $oldFile != '') { // File exists, try to remove old files first. $oldFile = JString::str_ireplace('/', DS, $oldFile); //only delete when required if (JFile::exists($oldFile)) { JFile::delete($oldFile); } } //here due to extension mismatch we can break the functionality of avatar if ($what === 'avatar') { /* No need to update thumb here , script will update both avatar and thumb */ //$newThumb = XiptHelperImage::getThumbAvatarFromFull($newAvatar); $oldAvatar = XiptLibProfiletypes::getProfiletypeData($id, 'avatar'); $allUsers = XiptLibProfiletypes::getAllUsers($id); if ($allUsers) { $filter[] = 'avatar'; $newData['avatar'] = $image; $oldData['avatar'] = $oldAvatar; foreach ($allUsers as $userid) { XiptLibProfiletypes::updateUserProfiletypeFilteredData($userid, $filter, $oldData, $newData); } } } //now update profiletype with new avatar or watermark if (!XiptFactory::getInstance('profiletypes', 'model')->save(array($what => XiptHelperUtils::getUrlpathFromFilePath($image)), $id)) { XiptError::raiseError(__CLASS__ . '.' . __LINE__, XiptText::_("ERROR_IN_DATABASE")); } } }
/** * 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; }