Esempio n. 1
0
 private function _isSpam($user, $data)
 {
     $config = CFactory::getConfig();
     // @rule: Spam checks
     if ($config->get('antispam_akismet_messages')) {
         $filter = CSpamFilter::getFilter();
         $filter->setAuthor($user->getDisplayName());
         $filter->setMessage($data);
         $filter->setEmail($user->email);
         $filter->setURL(JURI::root());
         $filter->setType('message');
         $filter->setIP($_SERVER['REMOTE_ADDR']);
         if ($filter->isSpam()) {
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 function ajaxAddComment($response, $id, $cmt, $cacheId)
 {
     JPlugin::loadLanguage('plg_walls', JPATH_ADMINISTRATOR);
     ini_set('display_errors', 1);
     error_reporting(E_ALL);
     // Add the comment into the db
     CFactory::load('libraries', 'comment');
     $my = CFactory::getUser();
     // Extract thenumeric id from the wall-cmt-xxx
     $wallId = substr($id, 9);
     CFactory::load('models', 'wall');
     $wall =& JTable::getInstance('Wall', 'CTable');
     $wall->load($wallId);
     $cmt = trim($cmt);
     $config = CFactory::getConfig();
     if ($config->get('antispam_akismet_walls')) {
         CFactory::load('libraries', 'spamfilter');
         $filter = CSpamFilter::getFilter();
         $filter->setAuthor($my->getDisplayName());
         $filter->setMessage($cmt);
         $filter->setEmail($my->email);
         $filter->setURL(CRoute::_('index.php?option=com_community&view=profile&userid=' . $wall->contentid));
         $filter->setType('message');
         $filter->setIP($_SERVER['REMOTE_ADDR']);
         if ($filter->isSpam()) {
             $response->addScriptCall('joms.jQuery( "#' . $id . ' .wall-coc-errors" ).html("' . JText::_('COM_COMMUNITY_MARKED_SPAM') . '");');
             $response->addScriptCall('joms.jQuery( "#' . $id . ' .wall-coc-errors" ).show();');
             $response->addScriptCall('joms.jQuery( "#' . $id . ' .wall-coc-errors" ).css("color", "red");');
             $response->addScriptCall('joms.jQuery("#' . $id . ' .wall-coc-form-action.add").attr("disabled", false);');
             return $response->sendResponse();
         }
     }
     if (empty($cmt)) {
         $response->addScriptCall('joms.jQuery( "#' . $id . ' .wall-coc-errors" ).html("' . JText::_('PLG_WALLS_COMMENT_EMPTY') . '");');
         $response->addScriptCall('joms.jQuery( "#' . $id . ' .wall-coc-errors" ).show();');
         $response->addScriptCall('joms.jQuery( "#' . $id . ' .wall-coc-errors" ).css("color", "red");');
         $response->addScriptCall('joms.jQuery("#' . $id . ' .wall-coc-form-action.add").attr("disabled", false);');
     } else {
         $comment = new CComment();
         $wall->comment = $comment->add($my->id, $cmt, $wall->comment);
         $wall->store();
         $newComment = new stdClass();
         $date = new JDate();
         $newComment->creator = $my->id;
         $newComment->text = $cmt;
         $newComment->date = $date->toUnix();
         $handler = $comment->getCommentHandler($wall->type);
         if ($handler) {
             $handler->sendCommentNotification($wall, $newComment->text);
         }
         $html = $comment->renderComment($newComment, true);
         CFactory::load('helpers', 'string');
         $html = cReplaceThumbnails($html);
         $response->addScriptCall('joms.comments.insert', $id, $html);
         // Clear wall cache
         $cache =& JFactory::getCache('plgCommunityWalls');
         $cache->remove($cacheId);
         $cache =& JFactory::getCache('plgCommunityWalls_fullview');
         $cache->remove($cacheId);
     }
     return $response;
 }
Esempio n. 3
0
 /**
  * Ajax function to save a new wall entry
  *
  * @param message    A message that is submitted by the user
  * @param uniqueId    The unique id for this group
  *
  * */
 public function ajaxSaveWall($message, $uniqueId, $appId = null, $photoId = 0)
 {
     $filter = JFilterInput::getInstance();
     $message = $filter->clean($message, 'string');
     $uniqueId = $filter->clean($uniqueId, 'int');
     $appId = $filter->clean($appId, 'int');
     $photoId = $filter->clean($photoId, 'int');
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     $json = array();
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $message = strip_tags($message);
     $photo = JTable::getInstance('Photo', 'CTable');
     $photo->load($uniqueId);
     $album = JTable::getInstance('Album', 'CTable');
     $album->load($photo->albumid);
     $handler = $this->_getHandler($album);
     if (!$handler->isWallsAllowed($photo->id)) {
         echo JText::_('COM_COMMUNITY_NOT_ALLOWED_TO_POST_COMMENT');
         return;
     }
     // If the content is false, the message might be empty.
     if (empty($message) && $photoId == 0) {
         $json['error'] = JText::_('COM_COMMUNITY_WALL_EMPTY_MESSAGE');
     } else {
         // @rule: Spam checks
         if ($config->get('antispam_akismet_walls')) {
             $filter = CSpamFilter::getFilter();
             $filter->setAuthor($my->getDisplayName());
             $filter->setMessage($message);
             $filter->setEmail($my->email);
             $filter->setURL(CRoute::_('index.php?option=com_community&view=photos&task=photo&albumid=' . $photo->albumid) . '&photoid=' . $photo->id);
             $filter->setType('message');
             $filter->setIP($_SERVER['REMOTE_ADDR']);
             if ($filter->isSpam()) {
                 $json['error'] = JText::_('COM_COMMUNITY_WALLS_MARKED_SPAM');
                 die(json_encode($json));
             }
         }
         $wall = CWallLibrary::saveWall($uniqueId, $message, 'photos', $my, $my->id == $photo->creator, 'photos,photo', 'wall/content', 0, $photoId);
         $url = $photo->getRawPhotoURI();
         $param = new CParameter('');
         $param->set('photoid', $uniqueId);
         $param->set('action', 'wall');
         $param->set('wallid', $wall->id);
         $param->set('url', $url);
         // Get the album type
         $app = $album->type;
         // Add activity logging based on app's type
         $permission = $this->_getAppPremission($app, $album);
         /**
          * We don't need to check for permission to create activity
          * Activity will follow album privacy
          * @since 3.2
          */
         if ($app == 'user' || $app == 'group') {
             $group = JTable::getInstance('Group', 'CTable');
             $group->load($album->groupid);
             $event = null;
             $this->_addActivity('photos.wall.create', $my->id, 0, '', $message, 'photos.comment', $uniqueId, $group, $event, $param->toString(), $permission);
         }
         // Add notification
         $params = new CParameter('');
         $params->set('url', $photo->getRawPhotoURI());
         $params->set('message', CUserHelper::replaceAliasURL($message));
         $params->set('photo', JText::_('COM_COMMUNITY_SINGULAR_PHOTO'));
         $params->set('photo_url', $url);
         // @rule: Send notification to the photo owner.
         if ($my->id !== $photo->creator) {
             CNotificationLibrary::add('photos_submit_wall', $my->id, $photo->creator, JText::sprintf('COM_COMMUNITY_PHOTO_WALL_EMAIL_SUBJECT'), '', 'photos.wall', $params);
         } else {
             //for activity reply action
             //get relevent users in the activity
             $wallModel = CFactory::getModel('wall');
             $users = $wallModel->getAllPostUsers('photos', $photo->id, $photo->creator);
             if (!empty($users)) {
                 CNotificationLibrary::add('photos_reply_wall', $my->id, $users, JText::sprintf('COM_COMMUNITY_PHOTO_WALLREPLY_EMAIL_SUBJECT'), '', 'photos.wallreply', $params);
             }
         }
         //email and add notification if user are tagged
         $info = array('type' => 'image-comment', 'album_id' => $album->id, 'image_id' => $photo->id);
         CUserHelper::parseTaggedUserNotification($message, CFactory::getUser($photo->creator), $wall, $info);
         // Add user points
         CUserPoints::assignPoint('photos.wall.create');
         // Log user engagement
         CEngagement::log('photo.comment', $my->id);
         $json['success'] = true;
         $json['html'] = $wall->content;
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_ACTIVITIES));
     die(json_encode($json));
 }
Esempio n. 4
0
 /**
  * Ajax function to save a new wall entry
  *
  * @param message	A message that is submitted by the user
  * @param uniqueId	The unique id for this group
  *
  **/
 public function ajaxSaveWall($message, $uniqueId)
 {
     $response = new JAXResponse();
     $my = CFactory::getUser();
     $filter = JFilterInput::getInstance();
     $message = $filter->clean($message, 'string');
     $uniqueId = $filter->clean($uniqueId, 'int');
     // Load necessary libraries
     CFactory::load('libraries', 'wall');
     CFactory::load('helpers', 'url');
     CFactory::load('libraries', 'activities');
     $model =& $this->getModel('events');
     $event =& JTable::getInstance('Event', 'CTable');
     $event->load($uniqueId);
     $message = strip_tags($message);
     // Only those who response YES/NO/MAYBE can write on wall
     $eventMembers =& JTable::getInstance('EventMembers', 'CTable');
     $eventMembers->load($my->id, $uniqueId);
     $allowedStatus = array(COMMUNITY_EVENT_STATUS_ATTEND, COMMUNITY_EVENT_STATUS_WONTATTEND, COMMUNITY_EVENT_STATUS_MAYBE);
     CFactory::load('helpers', 'owner');
     $config = CFactory::getConfig();
     if (!in_array($eventMembers->status, $allowedStatus) && !COwnerHelper::isCommunityAdmin() && $config->get('lockeventwalls') || $my->id == 0) {
         // Should not even be here unless use try to manipulate ajax call
         JError::raiseError(500, 'PERMISSION DENIED');
     }
     // If the content is false, the message might be empty.
     if (empty($message)) {
         $response->addAlert(JText::_('COM_COMMUNITY_EMPTY_MESSAGE'));
     } else {
         $isAdmin = $event->isAdmin($my->id);
         // @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=events&task=viewevent&eventid=' . $uniqueId));
             $filter->setType('message');
             $filter->setIP($_SERVER['REMOTE_ADDR']);
             if ($filter->isSpam()) {
                 $response->addAlert(JText::_('COM_COMMUNITY_WALLS_MARKED_SPAM'));
                 return $response->sendResponse();
             }
         }
         // Save the wall content
         $wall = CWallLibrary::saveWall($uniqueId, $message, 'events', $my, $isAdmin, 'events,events');
         $event->addWallCount();
         CFactory::load('helpers', 'event');
         $handler = CEventHelper::getHandler($event);
         if ($handler->isPublic()) {
             $actor = $my->id;
             $target = 0;
             $content = $message;
             $cid = $uniqueId;
             $app = 'events';
             $act = $handler->getActivity('events.wall.create', $actor, $target, $content, $cid, $app);
             $act->eventid = $event->id;
             $params = new CParameter('');
             $params->set('event_url', $handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false, true, false));
             $params->set('action', 'events.wall.create');
             $params->set('wallid', $wall->id);
             CFactory::load('libraries', 'activities');
             CActivityStream::add($act, $params->toString());
         }
         // @rule: Add user points
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('events.wall.create');
         $response->addScriptCall('joms.walls.insert', $wall->content);
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_ACTIVITIES));
     return $response->sendResponse();
 }
Esempio n. 5
0
 /**
  * Called by status box to add new stream data
  *
  * @param type $message
  * @param type $attachment
  * @return type
  */
 public function ajaxStreamAdd($message, $attachment, $streamFilter = FALSE)
 {
     $streamHTML = '';
     // $attachment pending filter
     $cache = CFactory::getFastCache();
     $cache->clean(array('activities'));
     $my = CFactory::getUser();
     $userparams = $my->getParams();
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     //@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'));
     }
     $message = JString::trim($message);
     $objResponse = new JAXResponse();
     $rawMessage = $message;
     // @rule: Autolink hyperlinks
     // @rule: Autolink to users profile when message contains @username
     // $message     = CUserHelper::replaceAliasURL($message); // the processing is done on display side
     $emailMessage = CUserHelper::replaceAliasURL($rawMessage, true);
     // @rule: Spam checks
     if ($config->get('antispam_akismet_status')) {
         $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();
         }
     }
     $attachment = json_decode($attachment, true);
     switch ($attachment['type']) {
         case 'message':
             //if (!empty($message)) {
             switch ($attachment['element']) {
                 case 'profile':
                     //only update user status if share messgage is on his profile
                     if (COwnerHelper::isMine($my->id, $attachment['target'])) {
                         //save the message
                         $status = $this->getModel('status');
                         /* If no privacy in attachment than we apply default: Public */
                         if (!isset($attachment['privacy'])) {
                             $attachment['privacy'] = COMMUNITY_STATUS_PRIVACY_PUBLIC;
                         }
                         $status->update($my->id, $rawMessage, $attachment['privacy']);
                         //set user status for current session.
                         $today = JFactory::getDate();
                         $message2 = empty($message) ? ' ' : $message;
                         $my->set('_status', $rawMessage);
                         $my->set('_posted_on', $today->toSql());
                         // Order of replacement
                         $order = array("\r\n", "\n", "\r");
                         $replace = '<br />';
                         // Processes \r\n's first so they aren't converted twice.
                         $messageDisplay = str_replace($order, $replace, $message);
                         $messageDisplay = CKses::kses($messageDisplay, CKses::allowed());
                         //update user status
                         $objResponse->addScriptCall("joms.jQuery('#profile-status span#profile-status-message').html('" . addslashes($messageDisplay) . "');");
                     }
                     //if actor posted something to target, the privacy should be under target's profile privacy settings
                     if (!COwnerHelper::isMine($my->id, $attachment['target']) && $attachment['target'] != '') {
                         $attachment['privacy'] = CFactory::getUser($attachment['target'])->getParams()->get('privacyProfileView');
                     }
                     //push to activity stream
                     $act = new stdClass();
                     $act->cmd = 'profile.status.update';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'];
                     $act->title = $message;
                     $act->content = '';
                     $act->app = $attachment['element'];
                     $act->cid = $my->id;
                     $act->access = $attachment['privacy'];
                     $act->comment_id = CActivities::COMMENT_SELF;
                     $act->comment_type = 'profile.status';
                     $act->like_id = CActivities::LIKE_SELF;
                     $act->like_type = 'profile.status';
                     $activityParams = new CParameter('');
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $headMeta = new CParameter('');
                     if (isset($attachment['fetch'])) {
                         $headMeta->set('title', $attachment['fetch'][2]);
                         $headMeta->set('description', $attachment['fetch'][3]);
                         $headMeta->set('image', $attachment['fetch'][1]);
                         $headMeta->set('link', $attachment['fetch'][0]);
                         //do checking if this is a video link
                         $video = JTable::getInstance('Video', 'CTable');
                         $isValidVideo = @$video->init($attachment['fetch'][0]);
                         if ($isValidVideo) {
                             $headMeta->set('type', 'video');
                             $headMeta->set('video_provider', $video->type);
                             $headMeta->set('video_id', $video->getVideoId());
                             $headMeta->set('height', $video->getHeight());
                             $headMeta->set('width', $video->getWidth());
                         }
                         $activityParams->set('headMetas', $headMeta->toString());
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $activityParams->set('mood', $attachment['mood']);
                     }
                     $act->params = $activityParams->toString();
                     //CActivityStream::add($act);
                     //check if the user points is enabled
                     if (CUserPoints::assignPoint('profile.status.update')) {
                         /* Let use our new CApiStream */
                         $activityData = CApiActivities::add($act);
                         CTags::add($activityData);
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('actorName', $my->getDisplayName());
                         $params->set('recipientName', $recipient->getDisplayName());
                         $params->set('url', CUrlHelper::userLink($act->target, false));
                         $params->set('message', $message);
                         $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                         $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id));
                         CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::sprintf('COM_COMMUNITY_FRIEND_WALL_POST', $my->getDisplayName()), '', 'wall.post', $params);
                         //email and add notification if user are tagged
                         CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment'));
                     }
                     break;
                     // Message posted from Group page
                 // Message posted from Group page
                 case 'groups':
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     // Permission check, only site admin and those who has
                     // mark their attendance can post message
                     if (!COwnerHelper::isCommunityAdmin() && !$group->isMember($my->id) && $config->get('lockgroupwalls')) {
                         $objResponse->addScriptCall("alert('permission denied');");
                         return $objResponse->sendResponse();
                     }
                     $act = new stdClass();
                     $act->cmd = 'groups.wall';
                     $act->actor = $my->id;
                     $act->target = 0;
                     $act->title = $message;
                     $act->content = '';
                     $act->app = 'groups.wall';
                     $act->cid = $attachment['target'];
                     $act->groupid = $group->id;
                     $act->group_access = $group->approvals;
                     $act->eventid = 0;
                     $act->access = 0;
                     $act->comment_id = CActivities::COMMENT_SELF;
                     $act->comment_type = 'groups.wall';
                     $act->like_id = CActivities::LIKE_SELF;
                     $act->like_type = 'groups.wall';
                     $activityParams = new CParameter('');
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $headMeta = new CParameter('');
                     if (isset($attachment['fetch'])) {
                         $headMeta->set('title', $attachment['fetch'][2]);
                         $headMeta->set('description', $attachment['fetch'][3]);
                         $headMeta->set('image', $attachment['fetch'][1]);
                         $headMeta->set('link', $attachment['fetch'][0]);
                         //do checking if this is a video link
                         $video = JTable::getInstance('Video', 'CTable');
                         $isValidVideo = @$video->init($attachment['fetch'][0]);
                         if ($isValidVideo) {
                             $headMeta->set('type', 'video');
                             $headMeta->set('video_provider', $video->type);
                             $headMeta->set('video_id', $video->getVideoId());
                             $headMeta->set('height', $video->getHeight());
                             $headMeta->set('width', $video->getWidth());
                         }
                         $activityParams->set('headMetas', $headMeta->toString());
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $activityParams->set('mood', $attachment['mood']);
                     }
                     $act->params = $activityParams->toString();
                     $activityData = CApiActivities::add($act);
                     CTags::add($activityData);
                     CUserPoints::assignPoint('group.wall.create');
                     $recipient = CFactory::getUser($attachment['target']);
                     $params = new CParameter('');
                     $params->set('message', $emailMessage);
                     $params->set('group', $group->name);
                     $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id);
                     $params->set('url', CRoute::getExternalURL('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id, false));
                     //Get group member emails
                     $model = CFactory::getModel('Groups');
                     $members = $model->getMembers($attachment['target'], null, true, false, true);
                     $membersArray = array();
                     if (!is_null($members)) {
                         foreach ($members as $row) {
                             if ($my->id != $row->id) {
                                 $membersArray[] = $row->id;
                             }
                         }
                     }
                     $groupParams = new CParameter($group->params);
                     if ($groupParams->get('wallnotification')) {
                         CNotificationLibrary::add('groups_wall_create', $my->id, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_WALL_POST_NOTIFICATION_EMAIL_SUBJECT', $my->getDisplayName(), $group->name), '', 'groups.post', $params);
                     }
                     //@since 4.1 when a there is a new post in group, dump the data into group stats
                     $statsModel = CFactory::getModel('stats');
                     $statsModel->addGroupStats($group->id, 'post');
                     // Add custom stream
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     break;
                     // Message posted from Event page
                 // Message posted from Event page
                 case 'events':
                     $eventLib = new CEvents();
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     // Permission check, only site admin and those who has
                     // mark their attendance can post message
                     if (!COwnerHelper::isCommunityAdmin() && !$event->isMember($my->id) && $config->get('lockeventwalls')) {
                         $objResponse->addScriptCall("alert('permission denied');");
                         return $objResponse->sendResponse();
                     }
                     // If this is a group event, set the group object
                     $groupid = $event->type == 'group' ? $event->contentid : 0;
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($groupid);
                     $act = new stdClass();
                     $act->cmd = 'events.wall';
                     $act->actor = $my->id;
                     $act->target = 0;
                     $act->title = $message;
                     $act->content = '';
                     $act->app = 'events.wall';
                     $act->cid = $attachment['target'];
                     $act->groupid = $event->type == 'group' ? $event->contentid : 0;
                     $act->group_access = $group->approvals;
                     $act->eventid = $event->id;
                     $act->event_access = $event->permission;
                     $act->access = 0;
                     $act->comment_id = CActivities::COMMENT_SELF;
                     $act->comment_type = 'events.wall';
                     $act->like_id = CActivities::LIKE_SELF;
                     $act->like_type = 'events.wall';
                     $activityParams = new CParameter('');
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $headMeta = new CParameter('');
                     if (isset($attachment['fetch'])) {
                         $headMeta->set('title', $attachment['fetch'][2]);
                         $headMeta->set('description', $attachment['fetch'][3]);
                         $headMeta->set('image', $attachment['fetch'][1]);
                         $headMeta->set('link', $attachment['fetch'][0]);
                         //do checking if this is a video link
                         $video = JTable::getInstance('Video', 'CTable');
                         $isValidVideo = @$video->init($attachment['fetch'][0]);
                         if ($isValidVideo) {
                             $headMeta->set('type', 'video');
                             $headMeta->set('video_provider', $video->type);
                             $headMeta->set('video_id', $video->getVideoId());
                             $headMeta->set('height', $video->getHeight());
                             $headMeta->set('width', $video->getWidth());
                         }
                         $activityParams->set('headMetas', $headMeta->toString());
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $activityParams->set('mood', $attachment['mood']);
                     }
                     $act->params = $activityParams->toString();
                     $activityData = CApiActivities::add($act);
                     CTags::add($activityData);
                     // add points
                     CUserPoints::assignPoint('event.wall.create');
                     $params = new CParameter('');
                     $params->set('message', $emailMessage);
                     $params->set('event', $event->title);
                     $params->set('event_url', 'index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id);
                     $params->set('url', CRoute::getExternalURL('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false));
                     //Get event member emails
                     $members = $event->getMembers(COMMUNITY_EVENT_STATUS_ATTEND, 12, CC_RANDOMIZE);
                     $membersArray = array();
                     if (!is_null($members)) {
                         foreach ($members as $row) {
                             if ($my->id != $row->id) {
                                 $membersArray[] = $row->id;
                             }
                         }
                     }
                     CNotificationLibrary::add('events_wall_create', $my->id, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_WALL_POST_NOTIFICATION_EMAIL_SUBJECT_EVENTS', $my->getDisplayName(), $event->title), '', 'events.post', $params);
                     //@since 4.1 when a there is a new post in event, dump the data into event stats
                     $statsModel = CFactory::getModel('stats');
                     $statsModel->addEventStats($event->id, 'post');
                     // Reload the stream with new stream data
                     $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true));
                     break;
             }
             $objResponse->addScriptCall('__callback', '');
             // /}
             break;
         case 'photo':
             switch ($attachment['element']) {
                 case 'profile':
                     $photoIds = $attachment['id'];
                     //use User Preference for Privacy
                     //$privacy = $userparams->get('privacyPhotoView'); //$privacy = $attachment['privacy'];
                     $photo = JTable::getInstance('Photo', 'CTable');
                     if (!isset($photoIds[0]) || $photoIds[0] <= 0) {
                         //$objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                         exit;
                     }
                     //always get album id from the photo itself, do not let it assign by params from user post data
                     $photoModel = CFactory::getModel('photos');
                     $photo = $photoModel->getPhoto($photoIds[0]);
                     /* OK ! If album_id is not provided than we use album id from photo ( it should be default album id ) */
                     $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid;
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($albumid);
                     $privacy = $album->permissions;
                     //limit checking
                     //                        $photoModel = CFactory::getModel( 'photos' );
                     //                        $config       = CFactory::getConfig();
                     //                        $total        = $photoModel->getTotalToday( $my->id );
                     //                        $max      = $config->getInt( 'limit_photo_perday' );
                     //                        $remainingUploadCount = $max - $total;
                     $params = array();
                     foreach ($photoIds as $key => $photoId) {
                         if (CLimitsLibrary::exceedDaily('photos')) {
                             unset($photoIds[$key]);
                             continue;
                         }
                         $photo->load($photoId);
                         $photo->permissions = $privacy;
                         $photo->published = 1;
                         $photo->status = 'ready';
                         $photo->albumid = $albumid;
                         /* We must update this photo into correct album id */
                         $photo->store();
                         $params[] = clone $photo;
                     }
                     if ($config->get('autoalbumcover') && !$album->photoid) {
                         $album->photoid = $photoIds[0];
                         $album->store();
                     }
                     // Break if no photo added, which is likely because of daily limit.
                     if (count($photoIds) < 1) {
                         $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_PHOTO_UPLOAD_LIMIT_EXCEEDED'));
                         return $objResponse->sendResponse();
                     }
                     // Trigger onPhotoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $apps->triggerEvent('onPhotoCreate', array($params));
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $privacy;
                     //$attachment['privacy'];
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $albumid;
                     $act->location = $album->location;
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     $act->like_type = 'photo';
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     $params->set('photo_url', $photoUrl);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     $params->set('photosId', implode(',', $photoIds));
                     if (count($photoIds > 1)) {
                         $params->set('count', count($photoIds));
                         $params->set('batchcount', count($photoIds));
                     }
                     //Store mood in param
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     // Add activity logging
                     // CActivityStream::remove($act->app, $act->cid);
                     $activityData = CActivityStream::add($act, $params->toString());
                     // Add user points
                     CUserPoints::assignPoint('photo.upload');
                     //add a notification to the target user if someone posted photos on target's profile
                     if ($my->id != $attachment['target']) {
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('actorName', $my->getDisplayName());
                         $params->set('recipientName', $recipient->getDisplayName());
                         $params->set('url', CUrlHelper::userLink($act->target, false));
                         $params->set('message', $message);
                         $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                         $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id));
                         CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::sprintf('COM_COMMUNITY_NOTIFICATION_STREAM_PHOTO_POST', count($photoIds)), '', 'wall.post', $params);
                     }
                     //email and add notification if user are tagged
                     CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment'));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
                 case 'events':
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     $privacy = 0;
                     //if this is a group event, we need to follow the group privacy
                     if ($event->type == 'group' && $event->contentid) {
                         $group = JTable::getInstance('Group', 'CTable');
                         $group->load(${$event}->contentid);
                         $privacy = $group->approvals ? PRIVACY_GROUP_PRIVATE_ITEM : 0;
                     }
                     $photoIds = $attachment['id'];
                     $photo = JTable::getInstance('Photo', 'CTable');
                     $photo->load($photoIds[0]);
                     $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid;
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($albumid);
                     $params = array();
                     foreach ($photoIds as $photoId) {
                         $photo->load($photoId);
                         $photo->caption = $message;
                         $photo->permissions = $privacy;
                         $photo->published = 1;
                         $photo->status = 'ready';
                         $photo->albumid = $albumid;
                         $photo->store();
                         $params[] = clone $photo;
                     }
                     // Trigger onPhotoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $apps->triggerEvent('onPhotoCreate', array($params));
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $privacy;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name );
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $album->id;
                     $act->location = $album->location;
                     $act->eventid = $event->id;
                     $act->group_access = $privacy;
                     // just in case this event belongs to a group
                     //$act->access      = $attachment['privacy'];
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     $act->like_type = 'photo';
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     // this photo uploaded from status stream
                     $params->set('photo_url', $photoUrl);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     $params->set('photosId', implode(',', $photoIds));
                     // Add activity logging
                     if (count($photoIds > 1)) {
                         $params->set('count', count($photoIds));
                         $params->set('batchcount', count($photoIds));
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     // CActivityStream::remove($act->app, $act->cid);
                     $activityData = CActivityStream::add($act, $params->toString());
                     // Add user points
                     CUserPoints::assignPoint('photo.upload');
                     // Reload the stream with new stream data
                     $eventLib = new CEvents();
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
                 case 'groups':
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     $photoIds = $attachment['id'];
                     $privacy = $group->approvals ? PRIVACY_GROUP_PRIVATE_ITEM : 0;
                     $photo = JTable::getInstance('Photo', 'CTable');
                     $photo->load($photoIds[0]);
                     $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid;
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($albumid);
                     $params = array();
                     foreach ($photoIds as $photoId) {
                         $photo->load($photoId);
                         $photo->caption = $message;
                         $photo->permissions = $privacy;
                         $photo->published = 1;
                         $photo->status = 'ready';
                         $photo->albumid = $albumid;
                         $photo->store();
                         $params[] = clone $photo;
                     }
                     // Trigger onPhotoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $apps->triggerEvent('onPhotoCreate', array($params));
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $privacy;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name );
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $album->id;
                     $act->location = $album->location;
                     $act->groupid = $group->id;
                     $act->group_access = $group->approvals;
                     $act->eventid = 0;
                     //$act->access      = $attachment['privacy'];
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     $act->like_type = 'photo';
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     // this photo uploaded from status stream
                     $params->set('photo_url', $photoUrl);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     $params->set('photosId', implode(',', $photoIds));
                     // Add activity logging
                     if (count($photoIds > 1)) {
                         $params->set('count', count($photoIds));
                         $params->set('batchcount', count($photoIds));
                     }
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     // CActivityStream::remove($act->app, $act->cid);
                     $activityData = CActivityStream::add($act, $params->toString());
                     // Add user points
                     CUserPoints::assignPoint('photo.upload');
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
                     dafault:
                     return;
             }
             break;
         case 'video':
             switch ($attachment['element']) {
                 case 'profile':
                     // attachment id
                     $fetch = $attachment['fetch'];
                     $cid = $fetch[0];
                     $privacy = isset($attachment['privacy']) ? $attachment['privacy'] : COMMUNITY_STATUS_PRIVACY_PUBLIC;
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->set('creator_type', VIDEO_USER_TYPE);
                     $video->set('status', 'ready');
                     $video->set('permissions', $privacy);
                     $video->set('title', $fetch[3]);
                     $video->set('description', $fetch[4]);
                     $video->set('category_id', $fetch[5]);
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         $video->set('location', $attachment['location'][0]);
                         $video->set('latitude', $attachment['location'][1]);
                         $video->set('longitude', $attachment['location'][2]);
                     }
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.linking';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos.linking';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->location = $video->location;
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos.linking';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos.linking';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     //
                     $activityData = CActivityStream::add($act, $params->toString());
                     //this video must be public because it's posted on someone else's profile
                     if ($my->id != $attachment['target']) {
                         $video->set('permissions', COMMUNITY_STATUS_PRIVACY_PUBLIC);
                         $params = new CParameter();
                         $params->set('activity_id', $activityData->id);
                         // activity id is used to remove the activity if someone deleted this video
                         $params->set('target_id', $attachment['target']);
                         $video->params = $params->toString();
                         //also send a notification to the user
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('actorName', $my->getDisplayName());
                         $params->set('recipientName', $recipient->getDisplayName());
                         $params->set('url', CUrlHelper::userLink($act->target, false));
                         $params->set('message', $message);
                         $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                         $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id));
                         CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::_('COM_COMMUNITY_NOTIFICATION_STREAM_VIDEO_POST'), '', 'wall.post', $params);
                     }
                     $video->store();
                     // @rule: Add point when user adds a new video link
                     //
                     CUserPoints::assignPoint('video.add', $video->creator);
                     //email and add notification if user are tagged
                     CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment'));
                     // Trigger for onVideoCreate
                     //
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] = $video;
                     $apps->triggerEvent('onVideoCreate', $params);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     break;
                 case 'groups':
                     // attachment id
                     $fetch = $attachment['fetch'];
                     $cid = $fetch[0];
                     $privacy = 0;
                     //$attachment['privacy'];
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->set('status', 'ready');
                     $video->set('groupid', $attachment['target']);
                     $video->set('permissions', $privacy);
                     $video->set('creator_type', VIDEO_GROUP_TYPE);
                     $video->set('title', $fetch[3]);
                     $video->set('description', $fetch[4]);
                     $video->set('category_id', $fetch[5]);
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         $video->set('location', $attachment['location'][0]);
                         $video->set('latitude', $attachment['location'][1]);
                         $video->set('longitude', $attachment['location'][2]);
                     }
                     $video->store();
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.linking';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->groupid = $video->groupid;
                     $act->group_access = $group->approvals;
                     $act->location = $video->location;
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     $activityData = CActivityStream::add($act, $params->toString());
                     // @rule: Add point when user adds a new video link
                     CUserPoints::assignPoint('video.add', $video->creator);
                     // Trigger for onVideoCreate
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] = $video;
                     $apps->triggerEvent('onVideoCreate', $params);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     break;
                 case 'events':
                     //event videos
                     $fetch = $attachment['fetch'];
                     $cid = $fetch[0];
                     $privacy = 0;
                     //$attachment['privacy'];
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->set('status', 'ready');
                     $video->set('eventid', $attachment['target']);
                     $video->set('permissions', $privacy);
                     $video->set('creator_type', VIDEO_EVENT_TYPE);
                     $video->set('title', $fetch[3]);
                     $video->set('description', $fetch[4]);
                     $video->set('category_id', $fetch[5]);
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         $video->set('location', $attachment['location'][0]);
                         $video->set('latitude', $attachment['location'][1]);
                         $video->set('longitude', $attachment['location'][2]);
                     }
                     $video->store();
                     //
                     $eventLib = new CEvents();
                     $event = JTable::getInstance('Event', 'CTable');
                     $event->load($attachment['target']);
                     $group = new stdClass();
                     if ($event->type == 'group' && $event->contentid) {
                         // check if this a group event, and follow the permission
                         $group = JTable::getInstance('Group', 'CTable');
                         $group->load($event->contentid);
                     }
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.linking';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->groupid = 0;
                     $act->group_access = isset($group->approvals) ? $group->approvals : 0;
                     // if this is a group event
                     $act->location = $video->location;
                     /* Save cords if exists */
                     if (isset($attachment['location'])) {
                         /* Save geo name */
                         $act->location = $attachment['location'][0];
                         $act->latitude = $attachment['location'][1];
                         $act->longitude = $attachment['location'][2];
                     }
                     $act->eventid = $event->id;
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     $params->set('style', COMMUNITY_STREAM_STYLE);
                     // set stream style
                     //Store mood in paramm
                     if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') {
                         $params->set('mood', $attachment['mood']);
                     }
                     $activityData = CActivityStream::add($act, $params->toString());
                     // @rule: Add point when user adds a new video link
                     CUserPoints::assignPoint('video.add', $video->creator);
                     // Trigger for onVideoCreate
                     $apps = CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] = $video;
                     $apps->triggerEvent('onVideoCreate', $params);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     // Reload the stream with new stream data
                     $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true));
                     break;
                 default:
                     return;
             }
             break;
         case 'event':
             switch ($attachment['element']) {
                 case 'profile':
                     require_once COMMUNITY_COM_PATH . '/controllers/events.php';
                     $eventController = new CommunityEventsController();
                     // Assign default values where necessary
                     $attachment['description'] = $message;
                     $attachment['ticket'] = 0;
                     $attachment['offset'] = 0;
                     $event = $eventController->ajaxCreate($attachment, $objResponse);
                     $objResponse->addScriptCall('window.location="' . $event->getLink() . '";');
                     if (CFactory::getConfig()->get('event_moderation')) {
                         $objResponse->addAlert(JText::sprintf('COM_COMMUNITY_EVENTS_MODERATION_NOTICE', $event->title));
                     }
                     break;
                 case 'groups':
                     require_once COMMUNITY_COM_PATH . '/controllers/events.php';
                     $eventController = new CommunityEventsController();
                     //
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     // Assign default values where necessary
                     $attachment['description'] = $message;
                     $attachment['ticket'] = 0;
                     $attachment['offset'] = 0;
                     $event = $eventController->ajaxCreate($attachment, $objResponse);
                     CEvents::addGroupNotification($event);
                     $objResponse->addScriptCall('window.location="' . $event->getLink() . '";');
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true));
                     if (CFactory::getConfig()->get('event_moderation')) {
                         $objResponse->addAlert(JText::sprintf('COM_COMMUNITY_EVENTS_MODERATION_NOTICE', $event->title));
                     }
                     break;
             }
             break;
         case 'link':
             break;
     }
     //no matter what kind of message it is, always filter the hashtag if there's any
     if (!empty($act->title) && isset($activityData->id) && $activityData->id) {
         //use model to check if this has a tag in it and insert into the table if possible
         $hashtags = CContentHelper::getHashTags($act->title);
         if (count($hashtags)) {
             //$hashTag
             $hashtagModel = CFactory::getModel('hashtags');
             foreach ($hashtags as $tag) {
                 $hashtagModel->addActivityHashtag($tag, $activityData->id);
             }
         }
     }
     // Frontpage filter
     if ($streamFilter != false) {
         $streamFilter = json_decode($streamFilter);
         $filter = $streamFilter->filter;
         $value = $streamFilter->value;
         $extra = false;
         // Append added data to the list.
         if (isset($activityData) && $activityData->id) {
             $model = CFactory::getModel('Activities');
             $extra = $model->getActivity($activityData->id);
         }
         switch ($filter) {
             case 'privacy':
                 if ($value == 'me-and-friends' && $my->id != 0) {
                     $streamHTML = CActivities::getActivitiesByFilter('active-user-and-friends', $my->id, 'frontpage', true, array(), $extra);
                 } else {
                     $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array(), $extra);
                 }
                 break;
             case 'apps':
                 $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array('apps' => array($value)), $extra);
                 break;
             case 'hashtag':
                 $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array($filter => $value), $extra);
                 break;
             default:
                 $defaultFilter = $config->get('frontpageactivitydefault');
                 if ($defaultFilter == 'friends' && $my->id != 0) {
                     $streamHTML = CActivities::getActivitiesByFilter('active-user-and-friends', $my->id, 'frontpage', true, array(), $extra);
                 } else {
                     $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array(), $extra);
                 }
                 break;
         }
     }
     if (!isset($attachment['filter'])) {
         $attachment['filter'] = '';
         $filter = $config->get('frontpageactivitydefault');
         $filter = explode(':', $filter);
         $attachment['filter'] = isset($filter[1]) ? $filter[1] : $filter[0];
     }
     if (empty($streamHTML)) {
         if (!isset($attachment['target'])) {
             $attachment['target'] = '';
         }
         if (!isset($attachment['element'])) {
             $attachment['element'] = '';
         }
         $streamHTML = CActivities::getActivitiesByFilter($attachment['filter'], $attachment['target'], $attachment['element'], true, array('show_featured' => true, 'showLatestActivityOnTop' => true));
     }
     $objResponse->addAssign('activity-stream-container', 'innerHTML', $streamHTML);
     // Log user engagement
     CEngagement::log($attachment['type'] . '.share', $my->id);
     return $objResponse->sendResponse();
 }
Esempio n. 6
0
 /**
  * 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();
 }
Esempio n. 7
0
 /**
  * Ajax function to save a new wall entry
  * 	 
  * @param message	A message that is submitted by the user
  * @param uniqueId	The unique id for this group
  * 
  **/
 public function ajaxSaveWall($message, $uniqueId, $appId = null)
 {
     $filter = JFilterInput::getInstance();
     $message = $filter->clean($message, 'string');
     $uniqueId = $filter->clean($uniqueId, 'int');
     $appId = $filter->clean($appId, 'int');
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     $response = new JAXResponse();
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $message = strip_tags($message);
     // Load libraries
     CFactory::load('models', 'photos');
     CFactory::load('libraries', 'wall');
     CFactory::load('helpers', 'url');
     CFactory::load('libraries', 'activities');
     CFactory::load('helpers', 'owner');
     CFactory::load('helpers', 'friends');
     CFactory::load('helpers', 'group');
     $photo =& JTable::getInstance('Photo', 'CTable');
     $photo->load($uniqueId);
     $album =& JTable::getInstance('Album', 'CTable');
     $album->load($photo->albumid);
     $handler = $this->_getHandler($album);
     if (!$handler->isWallsAllowed($photo->id)) {
         echo JText::_('COM_COMMUNITY_NOT_ALLOWED_TO_POST_COMMENT');
         return;
     }
     // If the content is false, the message might be empty.
     if (empty($message)) {
         $response->addAlert(JText::_('COM_COMMUNITY_WALL_EMPTY_MESSAGE'));
     } else {
         // @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=photos&task=photo&albumid=' . $photo->albumid) . '#photoid=' . $photo->id);
             $filter->setType('message');
             $filter->setIP($_SERVER['REMOTE_ADDR']);
             if ($filter->isSpam()) {
                 $response->addAlert(JText::_('COM_COMMUNITY_WALLS_MARKED_SPAM'));
                 return $response->sendResponse();
             }
         }
         $wall = CWallLibrary::saveWall($uniqueId, $message, 'photos', $my, $my->id == $photo->creator, 'photos,photo');
         $url = $photo->getPhotoURI();
         $param = new CParameter('');
         $param->set('photoid', $uniqueId);
         $param->set('action', 'wall');
         $param->set('wallid', $wall->id);
         $param->set('url', $url);
         // Get the album type
         $app = $album->type;
         // Add activity logging based on app's type
         $permission = $this->_getAppPremission($app, $album);
         if ($app == 'user' && $permission == '0' || $app == 'user' && $permission == PRIVACY_PUBLIC) {
             $group = JTable::getInstance('Group', 'CTable');
             $group->load($album->groupid);
             $event = null;
             $this->_addActivity('photos.wall.create', $my->id, 0, JText::sprintf('COM_COMMUNITY_ACTIVITIES_WALL_POST_PHOTO', $url, $photo->caption), $message, 'photos', $uniqueId, $group, $event, $param->toString());
         }
         // @rule: Send notification to the photo owner.
         if ($my->id !== $photo->creator) {
             // Add notification
             CFactory::load('libraries', 'notification');
             $params = new CParameter('');
             $params->set('url', $url);
             $params->set('message', $message);
             CNotificationLibrary::add('etype_photos_submit_wall', $my->id, $photo->creator, JText::sprintf('COM_COMMUNITY_PHOTO_WALL_EMAIL_SUBJECT', $my->getDisplayName()), '', 'photos.wall', $params);
         }
         //add user points
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('photos.wall.create');
         $response->addScriptCall('joms.walls.insert', $wall->content);
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_ACTIVITIES));
     return $response->sendResponse();
 }
Esempio n. 8
0
 /**
  * @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));
 }
Esempio n. 9
0
 /**
  * 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;
 }
Esempio n. 10
0
 /**
  * Called by status box to add new stream data
  * 
  * @param type $message
  * @param type $attachment
  * @return type 
  */
 public function ajaxStreamAdd($message, $attachment)
 {
     //$filter = JFilterInput::getInstance();
     //$message = $filter->clean($message, 'string');
     $streamHTML = '';
     // $attachment pending filter
     $cache = CFactory::getFastCache();
     $cache->clean(array('activities'));
     $my = CFactory::getUser();
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     CFactory::load('libraries', 'activities');
     CFactory::load('libraries', 'userpoints');
     CFactory::load('helpers', 'linkgenerator');
     CFactory::load('libraries', 'notification');
     //@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 = JString::substr($message, 0, $config->get('statusmaxchar'));
     }
     $message = JString::trim($message);
     //$message	= CStringHelper::escape($message);
     //$inputFilter = CFactory::getInputFilter(true);
     //$message = $inputFilter->clean($message);
     $objResponse = new JAXResponse();
     $rawMessage = $message;
     // @rule: Autolink hyperlinks
     $message = CLinkGeneratorHelper::replaceURL($message);
     // @rule: Autolink to users profile when message contains @username
     $message = CLinkGeneratorHelper::replaceAliasURL($message);
     // @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();
         }
     }
     $attachment = json_decode($attachment, true);
     //respect wall setting before adding activity
     CFactory::load('helpers', 'friends');
     CFactory::load('helper', 'owner');
     //$objResponse->addScriptCall("alert('permission denied');");
     //return $objResponse->sendResponse();
     /*
     		$attachment['type'] = The content type, message/videos/photos/events
     		$attachment['element'] = The owner, profile, groups,events
     */
     switch ($attachment['type']) {
         case "message":
             if (!empty($message)) {
                 switch ($attachment['element']) {
                     case 'profile':
                         //only update user status if share messgage is on his profile
                         if (COwnerHelper::isMine($my->id, $attachment['target'])) {
                             //save the message
                             $status =& $this->getModel('status');
                             $status->update($my->id, $rawMessage, $attachment['privacy']);
                             //set user status for current session.
                             $today =& JFactory::getDate();
                             $message2 = empty($message) ? ' ' : $message;
                             $my->set('_status', $rawMessage);
                             $my->set('_posted_on', $today->toMySQL());
                             // Order of replacement
                             $order = array("\r\n", "\n", "\r");
                             $replace = '<br />';
                             // Processes \r\n's first so they aren't converted twice.
                             $messageDisplay = str_replace($order, $replace, $message);
                             $messageDisplay = CKses::kses($messageDisplay, CKses::allowed());
                             //update user status
                             $objResponse->addScriptCall("joms.jQuery('#profile-status span#profile-status-message').html('" . addslashes($messageDisplay) . "');");
                         }
                         //push to activity stream
                         $privacyParams = $my->getParams();
                         $act = new stdClass();
                         $act->cmd = 'profile.status.update';
                         $act->actor = $my->id;
                         $act->target = $attachment['target'];
                         $act->title = $message;
                         $act->content = '';
                         $act->app = $attachment['element'];
                         $act->cid = $my->id;
                         $act->access = $attachment['privacy'];
                         $act->comment_id = CActivities::COMMENT_SELF;
                         $act->comment_type = 'profile.status';
                         $act->like_id = CActivities::LIKE_SELF;
                         $act->like_type = 'profile.status';
                         CActivityStream::add($act);
                         CUserPoints::assignPoint('profile.status.update');
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('actorName', $my->getDisplayName());
                         $params->set('recipientName', $recipient->getDisplayName());
                         $params->set('url', CUrlHelper::userLink($act->target, false));
                         $params->set('message', $message);
                         CNotificationLibrary::add('etype_profile_status_update', $my->id, $attachment['target'], JText::sprintf('COM_COMMUNITY_FRIEND_WALL_POST', $my->getDisplayName()), '', 'wall.post', $params);
                         break;
                         // Message posted from Group page
                     // Message posted from Group page
                     case 'groups':
                         CFactory::load('libraries', 'groups');
                         $groupLib = new CGroups();
                         $group = JTable::getInstance('Group', 'CTable');
                         $group->load($attachment['target']);
                         // Permission check, only site admin and those who has
                         // mark their attendance can post message
                         if (!COwnerHelper::isCommunityAdmin() && !$group->isMember($my->id)) {
                             $objResponse->addScriptCall("alert('permission denied');");
                             return $objResponse->sendResponse();
                         }
                         $act = new stdClass();
                         $act->cmd = 'groups.wall';
                         $act->actor = $my->id;
                         $act->target = 0;
                         $act->title = $message;
                         $act->content = '';
                         $act->app = 'groups.wall';
                         $act->cid = $attachment['target'];
                         $act->groupid = $group->id;
                         $act->group_access = $group->approvals;
                         $act->eventid = 0;
                         $act->access = 0;
                         $act->comment_id = CActivities::COMMENT_SELF;
                         $act->comment_type = 'groups.wall';
                         $act->like_id = CActivities::LIKE_SELF;
                         $act->like_type = 'groups.wall';
                         CActivityStream::add($act);
                         CUserPoints::assignPoint('profile.status.update');
                         $recipient = CFactory::getUser($attachment['target']);
                         $params = new CParameter('');
                         $params->set('message', $message);
                         $params->set('group', $group->name);
                         $params->set('url', CRoute::getExternalURL('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id, false));
                         //Get group member emails
                         $model = CFactory::getModel('Groups');
                         $members = $model->getMembers($attachment['target'], null);
                         $membersArray = array();
                         if (!is_null($members)) {
                             foreach ($members as $row) {
                                 if ($my->id != $row->id) {
                                     $membersArray[] = $row->id;
                                 }
                             }
                         }
                         CNotificationLibrary::add('etype_groups_wall_create', $my->id, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_WALL_POST_NOTIFICATION_EMAIL_SUBJECT', $my->getDisplayName(), $group->name), '', 'groups.wall', $params);
                         // Add custom stream
                         // Reload the stream with new stream data
                         $streamHTML = $groupLib->getStreamHTML($group);
                         break;
                         // Message posted from Event page
                     // Message posted from Event page
                     case 'events':
                         CFactory::load('libraries', 'events');
                         $eventLib = new CEvents();
                         $event = JTable::getInstance('Event', 'CTable');
                         $event->load($attachment['target']);
                         // Permission check, only site admin and those who has
                         // mark their attendance can post message
                         if (!COwnerHelper::isCommunityAdmin() && !$event->isMember($my->id)) {
                             $objResponse->addScriptCall("alert('permission denied');");
                             return $objResponse->sendResponse();
                         }
                         // If this is a group event, set the group object
                         $groupid = $event->type == 'group' ? $event->contentid : 0;
                         CFactory::load('libraries', 'groups');
                         $groupLib = new CGroups();
                         $group = JTable::getInstance('Group', 'CTable');
                         $group->load($groupid);
                         $act = new stdClass();
                         $act->cmd = 'events.wall';
                         $act->actor = $my->id;
                         $act->target = 0;
                         $act->title = $message;
                         $act->content = '';
                         $act->app = 'events.wall';
                         $act->cid = $attachment['target'];
                         $act->groupid = $event->type == 'group' ? $event->contentid : 0;
                         $act->group_access = $group->approvals;
                         $act->eventid = $event->id;
                         $act->event_access = $event->permission;
                         $act->access = 0;
                         $act->comment_id = CActivities::COMMENT_SELF;
                         $act->comment_type = 'events.wall';
                         $act->like_id = CActivities::LIKE_SELF;
                         $act->like_type = 'events.wall';
                         CActivityStream::add($act);
                         // Reload the stream with new stream data
                         $streamHTML = $eventLib->getStreamHTML($event);
                         break;
                 }
                 $objResponse->addScriptCall('__callback', '');
             }
             break;
         case "photo":
             switch ($attachment['element']) {
                 case 'profile':
                     $photoId = $attachment['id'];
                     $privacy = $attachment['privacy'];
                     $photo = JTable::getInstance('Photo', 'CTable');
                     $photo->load($photoId);
                     $photo->caption = $message;
                     $photo->permissions = $privacy;
                     $photo->published = 1;
                     $photo->status = 'ready';
                     $photo->store();
                     // Trigger onPhotoCreate
                     CFactory::load('libraries', 'apps');
                     $apps =& CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] =& $photo;
                     $apps->triggerEvent('onPhotoCreate', $params);
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($photo->albumid);
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $attachment['privacy'];
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name );
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $album->id;
                     $act->location = $album->location;
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     //CActivities::COMMENT_SELF;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     //CActivities::LIKE_SELF;
                     $act->like_type = 'photo';
                     // like type is 'photo' not 'photos'
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '#photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     // this photo uploaded from status stream
                     $params->set('photo_url', $photoUrl);
                     // Add activity logging
                     CFactory::load('libraries', 'activities');
                     CActivityStream::add($act, $params->toString());
                     // Add user points
                     CFactory::load('libraries', 'userpoints');
                     CUserPoints::assignPoint('photo.upload');
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
                 case 'groups':
                     CFactory::load('libraries', 'groups');
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     $photoId = $attachment['id'];
                     $privacy = $group->approvals ? PRIVACY_GROUP_PRIVATE_ITEM : 0;
                     $photo = JTable::getInstance('Photo', 'CTable');
                     $photo->load($photoId);
                     $photo->caption = $message;
                     $photo->permissions = $privacy;
                     $photo->published = 1;
                     $photo->status = 'ready';
                     $photo->store();
                     // Trigger onPhotoCreate
                     CFactory::load('libraries', 'apps');
                     $apps =& CAppPlugins::getInstance();
                     $apps->loadApplications();
                     $params = array();
                     $params[] =& $photo;
                     $apps->triggerEvent('onPhotoCreate', $params);
                     $album = JTable::getInstance('Album', 'CTable');
                     $album->load($photo->albumid);
                     $act = new stdClass();
                     $act->cmd = 'photo.upload';
                     $act->actor = $my->id;
                     $act->access = $privacy;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->title = $message;
                     //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name );
                     $act->content = '';
                     // Generated automatically by stream. No need to add anything
                     $act->app = 'photos';
                     $act->cid = $album->id;
                     $act->location = $album->location;
                     $act->groupid = $group->id;
                     $act->group_access = $group->approvals;
                     $act->eventid = 0;
                     //$act->access		= $attachment['privacy'];
                     /* Comment and like for individual photo upload is linked
                      * to the photos itsel
                      */
                     $act->comment_id = $photo->id;
                     //CActivities::COMMENT_SELF;
                     $act->comment_type = 'photos';
                     $act->like_id = $photo->id;
                     //CActivities::LIKE_SELF;
                     $act->like_type = 'photo';
                     // like type is 'photo' not 'photos'
                     $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id;
                     $albumUrl = CRoute::_($albumUrl);
                     $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '#photoid=' . $photo->id;
                     $photoUrl = CRoute::_($photoUrl);
                     $params = new CParameter('');
                     $params->set('multiUrl', $albumUrl);
                     $params->set('photoid', $photo->id);
                     $params->set('action', 'upload');
                     $params->set('stream', '1');
                     // this photo uploaded from status stream
                     $params->set('photo_url', $photoUrl);
                     // Add activity logging
                     CFactory::load('libraries', 'activities');
                     CActivityStream::add($act, $params->toString());
                     // Add user points
                     CFactory::load('libraries', 'userpoints');
                     CUserPoints::assignPoint('photo.upload');
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group);
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption));
                     break;
             }
             break;
         case "video":
             switch ($attachment['element']) {
                 case 'profile':
                     // attachment id
                     $cid = $attachment['id'];
                     $privacy = $attachment['privacy'];
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->status = 'ready';
                     $video->permissions = $privacy;
                     $video->store();
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.upload';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->location = $video->location;
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     CFactory::load('libraries', 'activities');
                     CActivityStream::add($act, $params->toString());
                     // @rule: Add point when user adds a new video link
                     CFactory::load('libraries', 'userpoints');
                     CUserPoints::assignPoint('video.add', $video->creator);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     break;
                 case 'groups':
                     // attachment id
                     $cid = $attachment['id'];
                     $privacy = 0;
                     //$attachment['privacy'];
                     $video = JTable::getInstance('Video', 'CTable');
                     $video->load($cid);
                     $video->status = 'ready';
                     $video->groupid = $attachment['target'];
                     $video->permissions = $privacy;
                     $video->store();
                     CFactory::load('libraries', 'groups');
                     $groupLib = new CGroups();
                     $group = JTable::getInstance('Group', 'CTable');
                     $group->load($attachment['target']);
                     // Add activity logging
                     $url = $video->getViewUri(false);
                     $act = new stdClass();
                     $act->cmd = 'videos.upload';
                     $act->actor = $my->id;
                     $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target'];
                     $act->access = $privacy;
                     //filter empty message
                     $act->title = $message;
                     $act->app = 'videos';
                     $act->content = '';
                     $act->cid = $video->id;
                     $act->groupid = $video->groupid;
                     $act->group_access = $group->approvals;
                     $act->location = $video->location;
                     $act->comment_id = $video->id;
                     $act->comment_type = 'videos';
                     $act->like_id = $video->id;
                     $act->like_type = 'videos';
                     $params = new CParameter('');
                     $params->set('video_url', $url);
                     CFactory::load('libraries', 'activities');
                     CActivityStream::add($act, $params->toString());
                     // @rule: Add point when user adds a new video link
                     CFactory::load('libraries', 'userpoints');
                     CUserPoints::assignPoint('video.add', $video->creator);
                     $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES));
                     $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title));
                     // Reload the stream with new stream data
                     $streamHTML = $groupLib->getStreamHTML($group);
                     break;
             }
             break;
         case "event":
             switch ($attachment['element']) {
                 case 'profile':
                     require_once COMMUNITY_COM_PATH . DS . 'controllers' . DS . 'events.php';
                     $eventController = new CommunityEventsController();
                     // Assign default values where necessary
                     $attachment['description'] = $message;
                     $attachment['ticket'] = 0;
                     $attachment['offset'] = 0;
                     $event = $eventController->ajaxCreate($attachment, $objResponse);
                     $objResponse->addScriptCall('__callback', '');
                     break;
             }
         case 'group':
             require_once COMMUNITY_COM_PATH . DS . 'controllers' . DS . 'events.php';
             $eventController = new CommunityEventsController();
             CFactory::load('libraries', 'groups');
             $groupLib = new CGroups();
             $group = JTable::getInstance('Group', 'CTable');
             $group->load($attachment['target']);
             // Assign default values where necessary
             $attachment['description'] = $message;
             $attachment['ticket'] = 0;
             $attachment['offset'] = 0;
             $event = $eventController->ajaxCreate($attachment, $objResponse);
             $objResponse->addScriptCall('__callback', '');
             // Reload the stream with new stream data
             $streamHTML = $groupLib->getStreamHTML($group);
             break;
             break;
         case "link":
             break;
     }
     // If no filter specified, we can assume it is for all
     if (!isset($attachment['filter'])) {
         $attachment['filter'] = '';
     }
     if (empty($streamHTML)) {
         $streamHTML = CActivities::getActivitiesByFilter($attachment['filter'], $attachment['target'], $attachment['element']);
     }
     $objResponse->addAssign('activity-stream-container', 'innerHTML', $streamHTML);
     return $objResponse->sendResponse();
 }