/** * Add comment to the stream * * @param int $actid acitivity id * @param string $comment * @return obj */ public function ajaxStreamAddComment($actid, $comment, $photoId = 0) { $filter = JFilterInput::getInstance(); $actid = $filter->clean($actid, 'int'); $my = CFactory::getUser(); $wallModel = CFactory::getModel('wall'); $rawComment = $comment; $json = array(); $photoId = $filter->clean($photoId, 'int'); // Pull the activity record and find out the actor // only allow comment if the actor is a friend of current user $act = JTable::getInstance('Activity', 'CTable'); $act->load($actid); //who can add comment $obj = $act; if ($act->groupid > 0) { $obj = JTable::getInstance('Group', 'CTable'); $obj->load($act->groupid); } else { if ($act->eventid > 0) { $obj = JTable::getInstance('Event', 'CTable'); $obj->load($act->eventid); } } //link the actual comment from video page itself to the stream if (isset($obj->comment_type) && $obj->comment_type == 'videos.linking') { $obj->comment_type = 'videos'; } $params = new CParameter($act->params); $batchcount = $params->get('batchcount', 0); $wallParam = new CParameter(''); if ($act->app == 'photos' && $batchcount > 1) { $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($params->get('photoid')); $act->comment_type = 'albums'; $act->comment_id = $photo->albumid; $wallParam->set('activityId', $act->id); } //if photo id is not 0, this wall is appended with a picture if ($photoId > 0) { //lets check if the photo belongs to the uploader $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoId); if ($photo->creator == $my->id && $photo->albumid == '-1') { $wallParam->set('attached_photo_id', $photoId); //sets the status to ready so that it wont be deleted on cron run $photo->status = 'ready'; $photo->store(); } } // Allow comment for system post $allowComment = false; if ($act->app == 'system') { $allowComment = !empty($my->id); } if ($my->authorise('community.add', 'activities.comment.' . $act->actor, $obj) || $allowComment) { $table = JTable::getInstance('Wall', 'CTable'); $table->type = $act->comment_type; $table->contentid = $act->comment_id; $table->post_by = $my->id; $table->comment = $comment; $table->params = $wallParam->toString(); if (preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $comment)) { $graphObject = CParsers::linkFetch($comment); if ($graphObject) { $graphObject->merge($wallParam); $table->params = $graphObject->toString(); } } $table->store(); $cache = CFactory::getFastCache(); $cache->clean(array('activities')); if ($act->app == 'photos') { $table->contentid = $act->id; } $table->params = new CParameter($table->get('params')); $args[] = $table; CWall::triggerWallComments($args, false); $comment = CWall::formatComment($table); $json['html'] = $comment; //notification for activity comment //case 1: user's activity //case 2 : group's activity //case 3 : event's activity if ($act->groupid == 0 && $act->eventid == 0) { // //CFactory::load( 'libraries' , 'notification' ); $params = new CParameter(''); $params->set('message', $table->comment); $url = 'index.php?option=com_community&view=profile&userid=' . $act->actor . '&actid=' . $actid; $params->set('url', $url); $params->set('actor', $my->getDisplayName()); $params->set('actor_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id)); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', $url); if ($my->id != $act->actor) { $command = 'profile_activity_add_comment'; /* Notifications to all poster in this activity except myself */ $users = $wallModel->getAllPostUsers($act->comment_type, $act->id, $my->id); if (!empty($users)) { if (!in_array($act->actor, $users)) { array_push($users, $act->actor); } $commenters = array_diff($users, array($act->actor)); // this will sent notification to the participant only CNotificationLibrary::add('profile_activity_add_comment', $my->id, $commenters, JText::sprintf('COM_COMMUNITY_ACTIVITY_WALL_PARTICIPANT_EMAIL_SUBJECT'), '', 'profile.activityreply', $params); // this will sent a notification to the poster, reason is that the title should be different CNotificationLibrary::add('profile_activity_add_comment', $my->id, $act->actor, JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_EMAIL_SUBJECT'), '', 'profile.activityreply', $params); } else { CNotificationLibrary::add('profile_activity_add_comment', $my->id, $act->actor, JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_EMAIL_SUBJECT'), '', 'profile.activitycomment', $params); } } else { //for activity reply action //get relevent users in the activity $users = $wallModel->getAllPostUsers($act->comment_type, $act->id, $act->actor); if (!empty($users)) { CNotificationLibrary::add('profile_activity_reply_comment', $my->id, $users, JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_USER_REPLY_EMAIL_SUBJECT'), '', 'profile.activityreply', $params); } } } elseif ($act->groupid != 0 && $act->eventid == 0) { /* Group activity */ $params = new CParameter(''); $params->set('message', $table->comment); $url = 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $act->groupid . '&actid=' . $actid; $params->set('url', $url); $params->set('actor', $my->getDisplayName()); $params->set('actor_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id)); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', $url); if ($my->id != $act->actor) { /** * Adds notification data into the mailq table * @uses Make sure your provide body parameter or email content will be empty * @param type $command * @param null $actorId * @param type $recipients * @param type $subject * @param type $body * @param type $templateFile * @param type $mailParams * @param type $sendEmail * @param type $favicon * @param type $altSubject * @return type */ CNotificationLibrary::add('groups_activity_add_comment', $my->id, $act->actor, JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_GROUP_EMAIL_SUBJECT'), $table->comment, 'group.activitycomment', $params); $users = $wallModel->getAllPostUsers($act->comment_type, $act->id, $act->actor); } else { //for activity reply action //get relevent users in the activity $users = $wallModel->getAllPostUsers($act->comment_type, $act->id, $act->actor); if (!empty($users)) { CNotificationLibrary::add('groups_activity_add_comment', $my->id, $users, JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_USER_REPLY_EMAIL_SUBJECT'), $table->comment, 'group.activityreply', $params); } } } elseif ($act->eventid != 0) { $event = JTable::getInstance('Event', 'CTable'); $event->load($act->eventid); $params = new CParameter(''); $params->set('message', $table->comment); $url = 'index.php?option=com_community&view=events&task=viewevent&eventid=' . $act->eventid . '&actid=' . $actid; $params->set('url', $url); $params->set('actor', $my->getDisplayName()); $params->set('actor_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id)); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', $url); $params->set('event', $event->title); if ($my->id != $act->actor) { CNotificationLibrary::add('events_submit_wall_comment', $my->id, $act->actor, JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_EVENT_EMAIL_SUBJECT'), '', 'events.wallcomment', $params); } else { //for activity reply action //get relevent users in the activity $users = $wallModel->getAllPostUsers($act->comment_type, $act->id, $act->actor); if (!empty($users)) { CNotificationLibrary::add('events_activity_reply_comment', $my->id, $users, JText::sprintf('COM_COMMUNITY_ACITIVY_WALL_USER_REPLY_EMAIL_SUBJECT'), '', 'event.activityreply', $params); } } } //notifications CUserHelper::parseTaggedUserNotification($rawComment, $my, $act, array('type' => 'post-comment')); //Add tag CTags::add($table); // Log user engagement CEngagement::log($act->app . '.comment', $my->id); } else { $json['error'] = 'Permission denied.'; } if (!isset($json['error'])) { $json['success'] = true; } die(json_encode($json)); }
/** * Gets the count of wall entries for specific item * * @params uniqueId The unique id for the speicific item * @params type The unique type for the specific item **/ public function getCount($uniqueId, $type) { $cache = CFactory::getFastCache(); $cacheid = __FILE__ . __LINE__ . serialize(func_get_args()) . serialize(JRequest::get()); if ($data = $cache->get($cacheid)) { return $data; } CError::assert($uniqueId, '', '!empty', __FILE__, __LINE__); $db =& $this->getDBO(); $query = 'SELECT COUNT(*) FROM ' . $db->nameQuote('#__community_wall') . 'WHERE ' . $db->nameQuote('contentid') . '=' . $db->Quote($uniqueId) . 'AND ' . $db->nameQuote('type') . '=' . $db->Quote($type); $db->setQuery($query); $count = $db->loadResult(); $cache->store($count, $cacheid); return $count; }
/** * Return the HTML formatted activity content */ static function getActivityContent($act) { $cache = CFactory::getFastCache(); $cacheid = __FILE__ . __LINE__ . serialize(func_get_args()); if ($data = $cache->get($cacheid)) { return $data; } // Return empty content or content with old, invalid data // In some old version, some content might have 'This is the body' if ($act->content == 'This is the body') { return ''; } $html = $act->content; // For known core, apps, we can simply call the content command switch ($act->app) { case 'videos': CFactory::load('libraries', 'videos'); $html = CVideos::getActivityContentHTML($act); break; case 'photos': CFactory::load('libraries', 'photos'); $html = CPhotos::getActivityContentHTML($act); break; case 'events': CFactory::load('libraries', 'events'); $html = CEvents::getActivityContentHTML($act); break; case 'groups.wall': case 'groups': CFactory::load('libraries', 'groups'); $html = CGroups::getActivityContentHTML($act); break; case 'groups.discussion.reply': case 'groups.discussion': CFactory::load('libraries', 'groups'); $html = CGroups::getActivityContentHTML($act); break; case 'groups.bulletin': CFactory::load('libraries', 'groups'); $html = CGroups::getActivityContentHTML($act); case 'system': CFactory::load('libraries', 'adminstreams'); $html = CAdminstreams::getActivityContentHTML($act); break; case 'walls': // If a wall does not have any content, do not // display the summary if ($act->app == 'walls' && $act->cid == 0) { $html = ''; return $html; } if ($act->cid != 0) { CFactory::load('libraries', 'wall'); $html = CWall::getActivityContentHTML($act); } break; default: // for other unknown apps, we include the plugin see if it is is callable // we call the onActivityContentDisplay(); CFactory::load('libraries', 'apps'); $apps =& CAppPlugins::getInstance(); $plugin =& $apps->get($act->app); $method = 'onActivityContentDisplay'; if (is_callable(array($plugin, $method))) { $args = array(); $args[] = $act; $html = call_user_func_array(array($plugin, $method), $args); } else { $html = $act->content; } } $cache->store($html, $cacheid, array('activities')); return $html; }
public function cacheClean($cacheId) { $cache = CFactory::getFastCache(); $cache->clean($cacheId); }
/** * Update the status of current user */ public function ajaxUpdate($message = '') { $filter = JFilterInput::getInstance(); $message = $filter->clean($message, 'string'); $cache = CFactory::getFastCache(); $cache->clean(array('activities')); if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $objResponse = new JAXResponse(); //@rule: In case someone bypasses the status in the html, we enforce the character limit. $config = CFactory::getConfig(); if (JString::strlen($message) > $config->get('statusmaxchar')) { $message = JHTML::_('string.truncate', $message, $config->get('statusmaxchar')); } //trim it here so that it wun go into activities stream. $message = JString::trim($message); $my = CFactory::getUser(); $status = $this->getModel('status'); // @rule: Spam checks if ($config->get('antispam_akismet_status')) { //CFactory::load( 'libraries' , 'spamfilter' ); $filter = CSpamFilter::getFilter(); $filter->setAuthor($my->getDisplayName()); $filter->setMessage($message); $filter->setEmail($my->email); $filter->setURL(CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id)); $filter->setType('message'); $filter->setIP($_SERVER['REMOTE_ADDR']); if ($filter->isSpam()) { $objResponse->addAlert(JText::_('COM_COMMUNITY_STATUS_MARKED_SPAM')); return $objResponse->sendResponse(); } } $status->update($my->id, $message); //set user status for current session. $today = JFactory::getDate(); $message2 = empty($message) ? ' ' : $message; $my->set('_status', $message2); $my->set('_posted_on', $today->toSql()); $profileid = $jinput->get->get('userid', 0, 'INT'); //JRequest::getVar('userid' , 0 , 'GET'); if (COwnerHelper::isMine($my->id, $profileid)) { $objResponse->addScriptCall("joms.jQuery('#profile-status span#profile-status-message').html('" . addslashes($message) . "');"); } //CFactory::load( 'helpers' , 'string' ); // $message = CStringHelper::escape( $message ); if (!empty($message)) { $act = new stdClass(); $act->cmd = 'profile.status.update'; $act->actor = $my->id; $act->target = $my->id; //CFactory::load( 'helpers' , 'linkgenerator' ); // @rule: Autolink hyperlinks $message = CLinkGeneratorHelper::replaceURL($message); // @rule: Autolink to users profile when message contains @username $message = CUserHelper::replaceAliasURL($message); $privacyParams = $my->getParams(); $act->title = $message; $act->content = ''; $act->app = 'profile'; $act->cid = $my->id; $act->access = $privacyParams->get('privacyProfileView'); $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'profile.status'; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'profile.status'; //add user points //CFactory::load( 'libraries' , 'userpoints' ); if (CUserPoints::assignPoint('profile.status.update')) { //only assign act if user points is set to true CActivityStream::add($act); } //now we need to reload the activities streams (since some report regarding update status from hello me we disabled update the stream, cuz hellome usually called out from jomsocial page) $friendsModel = CFactory::getModel('friends'); $memberSince = CTimeHelper::getDate($my->registerDate); $friendIds = $friendsModel->getFriendIds($my->id); //include_once(JPATH_COMPONENT .'/libraries/activities.php'); $act = new CActivityStream(); $params = $my->getParams(); $limit = !empty($params) ? $params->get('activityLimit', '') : ''; //$html = $act->getHTML($my->id, $friendIds, $memberSince, $limit ); $status = $my->getStatus(); $status = str_replace(array("\r\n", "\n", "\r"), "", $status); $status = addslashes($status); // also update hellome module if available $script = "joms.jQuery('.joms-js--mod-hellome-label').html('" . $status . "');"; $script .= "joms.jQuery('.joms-js--mod-hellome-loading').hide();"; $objResponse->addScriptCall($script); } return $objResponse->sendResponse(); }
/** * Wrapper to JRoute to handle itemid * We need to try and capture the correct itemid for different view */ static function _($url, $xhtml = true, $ssl = null) { global $Itemid; $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $cache = CFactory::getFastCache(); $cacheid = __FILE__ . __LINE__ . serialize(func_get_args()) . $Itemid; if ($data = $cache->get($cacheid)) { $data = JRoute::_($data, $xhtml, $ssl); return $data; } static $itemid = array(); parse_str(JString::str_ireplace('index.php?', '', $url)); if (empty($view)) { $view = 'frontpage'; } if (isset($option) && $option != 'com_community') { if (!$Itemid) { $db = JFactory::getDBO(); $query = 'SELECT ' . $db->quoteName('id') . ' FROM ' . $db->quoteName('#__menu') . ' ' . 'WHERE ' . $db->quoteName('link') . ' LIKE ' . $db->Quote('%' . $url . '%'); $db->setQuery($query); $id = $db->loadResult(); $url .= '&Itemid=' . $id; } return JRoute::_($url, $xhtml, $ssl); } if (empty($itemid[$view])) { global $Itemid; $isValid = false; $currentView = $jinput->get('view', 'frontpage', 'NONE'); //JRequest::getVar('view', 'frontpage'); $currentOption = $jinput->get('option', '', 'STRING'); //JRequest::getVar('option'); // If the current Itemid match the expected Itemid based on view // we'll just use it $db = JFactory::getDBO(); $viewId = CRoute::_getViewItemid($view); // if current itemid if ($currentOption == 'com_community' && $currentView == $view && $Itemid != 0) { $itemid[$view] = $Itemid; $isValid = true; } else { if ($viewId === $Itemid && !is_null($viewId) && $Itemid != 0) { $itemid[$view] = $Itemid; $isValid = true; } else { if ($viewId !== 0 && !is_null($viewId)) { $itemid[$view] = $viewId; $isValid = true; } } } if (!$isValid) { $id = CRoute::_getDefaultItemid(); if ($id !== 0 && !is_null($id)) { $itemid[$view] = $id; } $isValid = true; } // Search the mainmenu for the 1st itemid of jomsocial we can find, that match the current language code if (!$isValid) { $db = JFactory::getDBO(); $query = 'SELECT ' . $db->quoteName('id') . ' FROM ' . $db->quoteName('#__menu') . ' WHERE ' . $db->quoteName('link') . ' LIKE ' . $db->Quote('%com_community%') . 'AND ' . $db->quoteName('published') . '=' . $db->Quote(1) . ' ' . 'AND ' . $db->quoteName('menutype') . '=' . $db->Quote('{CRoute::menuname}') . 'AND ' . $db->quoteName('menutype') . '!=' . $db->Quote($config->get('toolbar_menutype')) . ' ' . 'AND ' . $db->quoteName('type') . '=' . $db->Quote('component'); $db->setQuery($query); $isValid = $db->loadResult(); if (!empty($isValid)) { $itemid[$view] = $isValid; } } // If not in mainmenu, seach in any menu if (!$isValid) { $query = 'SELECT ' . $db->quoteName('id') . ' FROM ' . $db->quoteName('#__menu') . ' WHERE ' . $db->quoteName('link') . ' LIKE ' . $db->Quote('%com_community%') . 'AND ' . $db->quoteName('published') . '=' . $db->Quote(1) . ' ' . 'AND ' . $db->quoteName('menutype') . '!=' . $db->Quote($config->get('toolbar_menutype')) . ' ' . 'AND ' . $db->quoteName('type') . '=' . $db->Quote('component'); $db->setQuery($query); $isValid = $db->loadResult(); if (!empty($isValid)) { $itemid[$view] = $isValid; } } } $pos = strpos($url, '#'); if ($pos === false) { if (isset($itemid[$view])) { if (strpos($url, 'Itemid=') === false && strpos($url, 'com_community') !== false) { $url .= '&Itemid=' . $itemid[$view]; } } } else { if (isset($itemid[$view])) { $url = str_ireplace('#', '&Itemid=' . $itemid[$view] . '#', $url); } } $data = JRoute::_($url, $xhtml, $ssl); $cache->store($url, $cacheid); return $data; }
/** * Cached the function call */ protected function _cachedCall($func, $params, $id, $tags) { $jConfig =& JFactory::getConfig(); // Check if the caching is enabled if ($jConfig->getValue('caching')) { $cache = CFactory::getFastCache(); $cacheid = __FILE__ . __LINE__ . $func . md5(serialize($params) . serialize($id)); if ($result = $cache->get($cacheid)) { return $result; } $result = call_user_func_array(array($this, $func), $params); $cache->store($result, $cacheid, $tags); } else { $result = call_user_func_array(array($this, $func), $params); } return $result; }
/** * Loads the categories * * @access public * @return array An array of categories object * @since 1.2 */ public function getCategories($categoryId = null) { $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $cache = CFactory::getFastCache(); $cacheid = serialize(func_get_args()) . serialize(JRequest::get()); if ($data = $cache->get($cacheid)) { return $data; } $my = CFactory::getUser(); $permissions = $my->id == 0 ? 0 : 20; $groupId = $jinput->get->get('groupid', '', 'INT'); //JRequest::getVar('groupid' , '' , 'GET'); $conditions = ''; $db = $this->getDBO(); if (!empty($groupId)) { $conditions = ' AND v.' . $db->quoteName('creator_type') . ' = ' . $db->quote(VIDEO_GROUP_TYPE); //$conditions .= ' AND b.groupid = ' . $groupId; $conditions .= ' AND g.' . $db->quoteName('id') . ' = ' . $db->Quote($groupId); } else { $conditions .= ' AND (g.' . $db->quoteName('approvals') . ' = ' . $db->Quote('0') . ' OR g.' . $db->quoteName('approvals') . ' IS NULL)'; } $allcats = $this->getAllCategories($categoryId); $allCatsNoFilter = $this->getAllCategories(); $result = array(); foreach ($allcats as $cat) { $categoryIds = CCategoryHelper::getCategoryChilds($allCatsNoFilter, $cat->id); if ((int) $cat->id > 0) { $categoryIds[] = (int) $cat->id; } if (is_array($categoryIds)) { $categoryIds = implode($categoryIds, ','); $categoryCondition = $db->quoteName('category_id') . ' IN (' . $categoryIds . ') '; } else { $categoryCondition = $db->quoteName('category_id') . ' = ' . $db->Quote($cat->id); } $query = ' SELECT COUNT(v.' . $db->quoteName('id') . ') AS count' . ' FROM ' . $db->quoteName('#__community_videos') . ' AS v' . ' LEFT JOIN ' . $db->quoteName('#__community_groups') . ' AS g ON g.' . $db->quoteName('id') . ' = v.' . $db->quoteName('groupid') . ' WHERE v.' . $categoryCondition . ' AND v.' . $db->quoteName('status') . ' = ' . $db->Quote('ready') . ' AND v.' . $db->quoteName('published') . ' = ' . $db->Quote(1) . ' AND v.' . $db->quoteName('permissions') . ' <= ' . $db->Quote($permissions) . $conditions; $db->setQuery($query); $cat->count = $db->loadResult(); $result[] = $cat; } if ($db->getErrorNum()) { JError::raiseError(500, $db->stderr()); } $cache->store($result, $cacheid, array(COMMUNITY_CACHE_TAG_VIDEOS_CAT)); return $result; }
/** * Add comment to the stream * * @param int $actid acitivity id * @param string $comment * @return obj */ public function ajaxStreamAddComment($actid, $comment) { $filter = JFilterInput::getInstance(); $actid = $filter->clean($actid, 'int'); $comment = $filter->clean($comment, 'string'); $my = CFactory::getUser(); $config = CFactory::getConfig(); $objResponse = new JAXResponse(); $wallModel = CFactory::getModel('wall'); CFactory::load('libraries', 'wall'); CFactory::load('libraries', 'activities'); CFactory::load('helpers', 'friends'); CFactory::load('helper', 'owner'); // Pull the activity record and find out the actor // only allow comment if the actor is a friend of current user $act =& JTable::getInstance('Activity', 'CTable'); $act->load($actid); //who can add comment $obj = new stdClass(); if ($act->groupid > 0) { $obj =& JTable::getInstance('Group', 'CTable'); $obj->load($act->groupid); } else { if ($act->eventid > 0) { $obj =& JTable::getInstance('Event', 'CTable'); $obj->load($act->eventid); } } if ($my->authorise('community.add', 'activities.comment.' . $act->actor, $obj)) { $table =& JTable::getInstance('Wall', 'CTable'); $table->type = $act->comment_type; $table->contentid = $act->comment_id; $table->post_by = $my->id; $table->comment = $comment; $table->store(); $cache = CFactory::getFastCache(); $cache->clean(array('activities')); $comment = CWall::formatComment($table); $objResponse->addScriptCall('joms.miniwall.insert', $actid, $comment); } else { // Cannot comment on non-friend stream. $objResponse->addAlert('Permission denied'); } return $objResponse->sendResponse(); }