/** * Displays the photo * * */ public function photo() { $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view = $this->getView($viewName, '', $viewType); $my = CFactory::getUser(); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $albumid = $jinput->get->get('albumid', '', 'INT'); //JRequest::getVar('albumid', '', 'GET'); if (!$albumid) { $photoid = JRequest::getCmd('photoid', null); $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoid); $albumid = $photo->albumid; } if ($this->checkPhotoAccess($albumid)) { // Log user engagement CEngagement::log('photo.display', $my->id); echo $view->get(__FUNCTION__); } }
/** * 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)); }
/** * @param $message A message that is submitted by the user * @param $uniqueId The unique id for this group * @param int $photoId */ public function ajaxSaveWall($message, $uniqueId, $photoId = 0) { $filter = JFilterInput::getInstance(); $uniqueId = $filter->clean($uniqueId, 'int'); $photoId = $filter->clean($photoId, 'int'); if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $response = new JAXResponse(); $json = array(); $my = CFactory::getUser(); $video = JTable::getInstance('Video', 'CTable'); $video->load($uniqueId); // If the content is false, the message might be empty. if (empty($message) && $photoId == 0) { $json['error'] = JText::_('COM_COMMUNITY_WALL_EMPTY_MESSAGE'); } else { $config = CFactory::getConfig(); // @rule: Spam checks if ($config->get('antispam_akismet_walls')) { //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=videos&task=video&videoid=' . $uniqueId)); $filter->setType('message'); $filter->setIP($_SERVER['REMOTE_ADDR']); if ($filter->isSpam()) { $json['error'] = JText::_('COM_COMMUNITY_WALLS_MARKED_SPAM'); die(json_encode($json)); } } //CFactory::load( 'libraries' , 'wall' ); $wall = CWallLibrary::saveWall($uniqueId, $message, 'videos', $my, $my->id == $video->creator, 'videos,video', 'wall/content', 0, $photoId); // Add activity logging $url = $video->getViewUri(false); $params = new CParameter(''); $params->set('videoid', $uniqueId); $params->set('action', 'wall'); $params->set('wallid', $wall->id); $params->set('video_url', $url); $act = new stdClass(); $act->cmd = 'videos.wall.create'; $act->actor = $my->id; $act->access = $video->permissions; $act->target = 0; $act->title = JText::sprintf('COM_COMMUNITY_VIDEOS_ACTIVITIES_WALL_POST_VIDEO', '{video_url}', $video->title); $act->app = 'videos.comment'; $act->cid = $uniqueId; $act->params = $params->toString(); $act->groupid = $video->groupid; $act->eventid = $video->eventid; CActivityStream::add($act); // Add notification //CFactory::load( 'libraries' , 'notification' ); $params = new CParameter(''); $params->set('url', $url); $params->set('message', CUserHelper::replaceAliasURL($message)); $params->set('video', $video->title); $params->set('video_url', $url); if ($my->id !== $video->creator) { CNotificationLibrary::add('videos_submit_wall', $my->id, $video->creator, JText::sprintf('COM_COMMUNITY_VIDEO_WALL_EMAIL_SUBJECT'), '', 'videos.wall', $params); } else { //for activity reply action //get relevent users in the activity $wallModel = CFactory::getModel('wall'); $users = $wallModel->getAllPostUsers('videos', $video->id, $video->creator); if (!empty($users)) { CNotificationLibrary::add('videos_reply_wall', $my->id, $users, JText::sprintf('COM_COMMUNITY_VIDEO_WALLREPLY_EMAIL_SUBJECT'), '', 'videos.wallreply', $params); } } //email and add notification if user are tagged $info = array('type' => 'video-comment', 'video_id' => $video->id); CUserHelper::parseTaggedUserNotification($message, CFactory::getUser($video->creator), $wall, $info); // Add user points CUserPoints::assignPoint('videos.comment'); //@since 4.1 we dump the info into photo stats $statsModel = CFactory::getModel('stats'); $statsModel->addVideoStats($video->id, 'comment'); // Log user engagement CEngagement::log('video.comment', $my->id); $json['html'] = $wall->content; $json['success'] = true; } $this->cacheClean(array(COMMUNITY_CACHE_TAG_ACTIVITIES)); die(json_encode($json)); }
public function addLike($element, $itemId) { $my = CFactory::getUser(); $like = JTable::getInstance('Like', 'CTable'); $like->loadInfo($element, $itemId); $like->element = $element; $like->uid = $itemId; // Check if user already like $likesInArray = explode(',', trim($like->like, ',')); /* Like once time */ if (in_array($my->id, $likesInArray)) { return; } array_push($likesInArray, $my->id); $likesInArray = array_unique($likesInArray); $like->like = ltrim(implode(',', $likesInArray), ','); // Check if the user already dislike $dislikesInArray = explode(',', trim($like->dislike, ',')); if (in_array($my->id, $dislikesInArray)) { // Remove user dislike from array $key = array_search($my->id, $dislikesInArray); unset($dislikesInArray[$key]); $like->dislike = implode(',', $dislikesInArray); } switch ($element) { case 'comment': //get the instance of the wall $wall = JTable::getInstance('Wall', 'CTable'); $wall->load($itemId); if (!$wall->id) { break; } if ($wall->type == "profile.status") { $wall->type = "profile"; } //load the stream id from activity stream $stream = JTable::getInstance('Activity', 'CTable'); $stream->load(array('comment_id' => $wall->contentid, 'app' => $wall->type)); if ($stream->id) { $profile = CFactory::getUser($stream->actor); $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id . '#activity-stream-container'; $params = new CParameter(''); $params->set('url', $url); $params->set('comment', JText::_('COM_COMMUNITY_SINGULAR_COMMENT')); $params->set('comment_url', $url); $params->set('actor', $my->getDisplayName()); //add to notifications CNotificationLibrary::add('comments_like', $my->id, $wall->post_by, JText::sprintf('COM_COMMUNITY_PROFILE_WALL_LIKE_EMAIL_SUBJECT'), '', 'comments.like', $params); } break; case 'photo': $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($itemId); if ($photo->id) { $url = $photo->getRawPhotoURI(); $params = new CParameter(''); $params->set('url', $url); $params->set('photo', JText::_('COM_COMMUNITY_SINGULAR_PHOTO')); $params->set('photo_url', $url); CNotificationLibrary::add('photos_like', $my->id, $photo->creator, JText::sprintf('COM_COMMUNITY_PHOTO_LIKE_EMAIL_SUBJECT'), '', 'photos.like', $params); /* Adding user points */ CUserPoints::assignPoint('photos.like'); } break; case 'album': $album = JTable::getInstance('Album', 'CTable'); $album->load($itemId); if ($album->id) { if ($album->groupid) { $url = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&groupid=' . $album->groupid; } else { $url = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id; } $params = new CParameter(''); $params->set('url', $url); $params->set('album', $album->name); $params->set('album_url', $url); CNotificationLibrary::add('photos_like', $my->id, $album->creator, JText::sprintf('COM_COMMUNITY_ALBUM_LIKE_EMAIL_SUBJECT'), '', 'album.like', $params); /* Adding user points */ CUserPoints::assignPoint('album.like'); } break; case 'videos': $video = JTable::getInstance('Video', 'CTable'); $video->load($itemId); if ($video->id) { if ($video->groupid) { $url = 'index.php?option=com_community&view=videos&task=video&groupid=' . $video->groupid . '&videoid=' . $video->id; } else { $url = 'index.php?option=com_community&view=videos&task=video&videoid=' . $video->id; } $params = new CParameter(''); $params->set('url', $url); $params->set('video', $video->title); $params->set('video_url', $url); CNotificationLibrary::add('videos_like', $my->id, $video->creator, JText::sprintf('COM_COMMUNITY_VIDEO_LIKE_EMAIL_SUBJECT'), '', 'videos.like', $params); /* Adding user points */ CUserPoints::assignPoint('videos.like'); } break; case 'profile': $profile = CFactory::getUser($itemId); if ($profile->id) { $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id; $params = new CParameter(''); $params->set('url', $url); $params->set('profile', strtolower(JText::_('COM_COMMUNITY_NOTIFICATIONGROUP_PROFILE'))); $params->set('profile_url', $url); CNotificationLibrary::add('profile_like', $my->id, $profile->id, JText::sprintf('COM_COMMUNITY_PROFILE_LIKE_EMAIL_SUBJECT'), '', 'profile.like', $params); /* Adding user points */ CUserPoints::assignPoint('profile.like'); } break; case 'profile.status': $stream = JTable::getInstance('Activity', 'CTable'); $stream->load($itemId); if ($stream->id) { $profile = CFactory::getUser($stream->actor); $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id; $params = new CParameter(''); $params->set('url', $url); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', $url); CNotificationLibrary::add('profile_stream_like', $my->id, $profile->id, JText::sprintf('COM_COMMUNITY_PROFILE_STREAM_LIKE_EMAIL_SUBJECT'), '', 'profile.stream.like', $params); /* Adding user points */ CUserPoints::assignPoint('profile.stream.like'); } break; case 'cover.upload': $photo = JTable::getInstance('Photo', 'CTable'); $photo->load(CPhotosHelper::getPhotoOfStream($itemId)); if ($photo->id) { $url = $photo->getRawPhotoURI(); $params = new CParameter(''); $params->set('url', $url); $params->set('photo', JText::_('COM_COMMUNITY_SINGULAR_PHOTO')); $params->set('photo_url', $url); CNotificationLibrary::add('photos_like', $my->id, $photo->creator, JText::sprintf('COM_COMMUNITY_COVER_LIKE_EMAIL_SUBJECT'), '', 'photos.like', $params); /* Adding user points */ CUserPoints::assignPoint('photos.like'); } break; case 'profile.avatar.upload': $stream = JTable::getInstance('Activity', 'CTable'); $stream->load($itemId); if ($stream->id) { $profile = CFactory::getUser($stream->actor); $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id; $params = new CParameter(''); $params->set('url', $url); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', $url); CNotificationLibrary::add('profile_stream_like', $my->id, $profile->id, JText::sprintf('COM_COMMUNITY_PROFILE_AVATAR_LIKE_EMAIL_SUBJECT'), '', 'profile.stream.like', $params); /* Adding user points */ CUserPoints::assignPoint('profile.stream.like'); } break; case 'album.self.share': $stream = JTable::getInstance('Activity', 'CTable'); $stream->load($itemId); $profile = CFactory::getUser($stream->actor); //get total photo(s) uploaded and determine the string $actParam = new CParameter($stream->params); if ($actParam->get('batchcount') > 1) { $content = JText::sprintf('COM_COMMUNITY_ACTIVITY_ALBUM_PICTURES_LIKE_SUBJECT'); } else { $content = JText::sprintf('COM_COMMUNITY_ACTIVITY_ALBUM_PICTURE_LIKE_SUBJECT'); } $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id; $params = new CParameter(''); $params->set('url', $url); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', $url); CNotificationLibrary::add('profile_stream_like', $my->id, $profile->id, $content, '', 'profile.stream.like', $params); default: CUserPoints::assignPoint($element . '.like'); } // Log user engagement CEngagement::log($element . '.like', $my->id); $like->store(); }
public function getEngagementJs($type, $time) { $actionsArr = array('message' => array('like' => 'profile.status.like', 'comment' => 'profile.comment', 'share' => 'message.share'), 'photo' => array('like' => 'photo.like', 'comment' => 'photo.comment', 'share' => 'photo.share'), 'video' => array('like' => 'videos.like', 'comment' => 'video.comment', 'share' => 'video.share'), 'event' => array('like' => 'events.like', 'comment' => 'event.comment', 'share' => 'event.share'), 'group' => array('like' => 'groups.like', 'comment' => 'group.comment', 'share' => 'group.share')); $like = $this->jsonFormat(CEngagement::getData(array($actionsArr[$type]['like']), $time), $time, JText::_('COM_COMMUNITY_ENGAGEMENT_LIKES')); $comment = $this->jsonFormat(CEngagement::getData(array($actionsArr[$type]['comment']), $time), $time, JText::_('COM_COMMUNITY_ENGAGEMENT_COMMENTS')); $share = $this->jsonFormat(CEngagement::getData(array($actionsArr[$type]['share']), $time), $time, $type == 'message' ? JText::_('COM_COMMUNITY_ENGAGEMENT_STATUSES') : JText::_('COM_COMMUNITY_ENGAGEMENT_SHARES')); $js = <<<ENDSCRIPT var engDatasets = { \t"{$like->label}": { \t label: "{$like->count} {$like->label}", \t data: {$like->json} \t}, \t"{$comment->label}": { \t label: "{$comment->count} {$comment->label}", \t data: {$comment->json} \t}, \t"{$share->label}": { \t label: "{$share->count} {$share->label}", \t data: {$share->json} \t}, }; var i = 0; \$.each(engDatasets, function(key, val) { val.color = i; ++i; }); var engChoiceContainer = jQuery("#eng-{$type}-choices"); \$.each(engDatasets, function(key, val) { engChoiceContainer.append("<label><input type='checkbox' name='" + key + \t"' checked='checked' id='id" + key + "'></input>" + \t"<span class='lbl' for='id" + key + "'>" \t+ key + "</span></label>"); }); engPlotAccordingToChoices = function() { \tvar checkedChoices = engChoiceContainer.find("input:checked"); \tif(checkedChoices.length == 1) { \t\tcheckedChoices.attr("disabled", true); \t} else { \t\tcheckedChoices.removeAttr("disabled"); \t} \tvar data = []; \tengChoiceContainer.find("input:checked").each(function () { \t\tvar key = jQuery(this).attr("name"); \t\tif (key && engDatasets[key]) { \t\t data.push(engDatasets[key]); \t\t} \t\t}); \t\tif (data.length > 0) { \t\t\$.plot("#eng-{$type}-plot", data, { \t\t yaxis: { \t\t\tmin: 0 \t\t }, \t\t xaxis: { \t\t\ttickDecimals: 0, \t\t\tmode: 'categories' \t\t } \t\t}); \t} }; engChoiceContainer.find("input").click(window.engPlotAccordingToChoices); engPlotAccordingToChoices(); ENDSCRIPT; return $js; }