Beispiel #1
0
 /**
  * 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));
 }
Beispiel #2
0
 /**
  * @param $uniqueId
  * @param $message
  * @param $appType
  * @param $creator
  * @param $isOwner
  * @param string $processFunc
  * @param string $templateFile
  * @param int $wallId
  * @param int $photoId to attach photoid in the wall if exists
  * @return stdClass
  */
 public static function saveWall($uniqueId, $message, $appType, &$creator, $isOwner, $processFunc = '', $templateFile = 'wall/content', $wallId = 0, $photoId = 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($my->id, '', '!empty', __FILE__, __LINE__);
     // Load the models
     $wall = JTable::getInstance('Wall', 'CTable');
     $wall->load($wallId);
     if ($wallId == 0) {
         // Get current date
         $now = JFactory::getDate();
         $now = $now->toSql();
         // 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'];
     }
     //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);
         //save the data into the wall table
         $wallParam = new CParameter($wall->params);
         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();
         }
         $wall->params = $wallParam->toString();
     } elseif ($photoId == -1) {
         //if there is nothing, remove the param if applicable
         $wallParam = new CParameter($wall->params);
         //delete from db and files
         $photoModel = CFactory::getModel('photos');
         if ($wallParam->get('attached_photo_id') > 0) {
             $photoTable = $photoModel->getPhoto($wallParam->get('attached_photo_id'));
             $photoTable->delete();
         }
         $wallParam->set('attached_photo_id', 0);
         $wall->params = $wallParam->toString();
     }
     /* URL fetch */
     $graphObject = CParsers::linkFetch($message);
     if ($graphObject) {
         $graphObject->merge(new CParameter($wall->params));
         $wall->params = $graphObject->toString();
     }
     $wall->comment = $message;
     // 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
     $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);
     $wallData->content = CStringHelper::replaceThumbnails($wallData->content);
     CTags::add($wall);
     return $wallData;
 }
Beispiel #3
0
 /**
  *
  * 
  */
 public function ajaxAddTag($element, $id, $tagString)
 {
     $filter = JFilterInput::getInstance();
     $id = $filter->clean($id, 'int');
     $tagString = $filter->clean($tagString, 'string');
     $element = $filter->clean($element, 'string');
     $objResponse = new JAXResponse();
     // @todo: make sure user has the permission
     CFactory::load('libraries', 'tags');
     $tags = new CTags();
     $tagString = JString::trim($tagString);
     // If there is only 1 word, add a space so thet the next 'explode' call works
     $tagStrings = explode(',', $tagString);
     // @todo: limit string lenght
     foreach ($tagStrings as $row) {
         // Need to trim unwanted char
         $row = JString::trim($row, " ,;:");
         // For each tag, we ucwords them for consistency
         $row = ucwords($row);
         // @todo: Send out warning or error message that the string is too short
         if (JString::strlen($row) >= CTags::MIN_LENGTH) {
             // Only add to the tag list if add is successful
             if ($tags->add($element, $id, $row)) {
                 // @todo: get last tag id inserted
                 $tagid = $tags->lastInsertId();
                 // urlescape the string
                 $row = CTemplate::escape($row);
                 $objResponse->addScriptCall("joms.jQuery('#tag-list').append", "<li id=\"tag-" . $tagid . "\"><span class=\"tag-token\"><a href=\"javascript:void(0);\" onclick=\"joms.tag.list('" . $row . "')\">{$row}</a><a href=\"javascript:void(0);\" style=\"display:block\" class=\"tag-delete\" onclick=\"joms.tag.remove('" . $tagid . "')\">x</a></span></li>");
             }
         }
     }
     $objResponse->addScriptCall('joms.jQuery(\'#tag-addbox\').val', '');
     return $objResponse->sendResponse();
 }