示例#1
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();
 }
示例#2
0
 /**
  *
  */
 public function ajaxSaveSettings($postvars)
 {
     // Check permissions
     $my =& JFactory::getUser();
     $filter = JFilterInput::getInstance();
     $postvars = $filter->clean($postvars, 'array');
     if ($my->id == 0) {
         return $this->ajaxBlockUnregister();
     }
     $objResponse = new JAXResponse();
     $appsModel = CFactory::getModel('apps');
     $appName = $postvars['appname'];
     $id = $postvars['appid'];
     // @rule: Test if app is core app as we need to add into the db
     $pluginId = $appsModel->getPluginId($appName);
     $appParam = new CParameter($appsModel->getPluginParams($pluginId));
     if ($pluginId && $my->id != 0 && $appParam->get('coreapp')) {
         // Add new app in the community plugins table
         $appsModel->addApp($my->id, $appName);
         // @rule: For core applications, the ID might be referring to Joomla's id. Get the correct id if needed.
         $id = $appsModel->getUserApplicationId($appName, $my->id);
     }
     // Make sure this is valid for current user
     if (!$appsModel->isOwned($my->id, $id)) {
         // It could be that the app is a core app.
         $objResponse->addAlert('COM_COMMUNITY_PERMISSION_ERROR');
         return $objResponse->sendResponse();
     }
     $post = array();
     // convert $postvars to normal post
     $pattern = "'params\\[(.*?)\\]'s";
     for ($i = 0; $i < count($postvars); $i++) {
         if (!empty($postvars[$i]) && is_array($postvars[$i])) {
             $key = $postvars[$i][0];
             // Blogger view
             preg_match($pattern, $key, $matches);
             if ($matches) {
                 $key = $matches[1];
             }
             $post[$key] = $postvars[$i][1];
         }
     }
     $xmlPath = JPATH_COMPONENT . DS . 'applications' . DS . $appName . DS . $appName . '.xml';
     $params = new CParameter($appsModel->getUserAppParams($id), $xmlPath);
     $params->bind($post);
     //echo $params->toString();
     $appsModel->storeParams($id, $params->toString());
     $objResponse->addScriptCall('cWindowHide');
     return $objResponse->sendResponse();
 }
示例#3
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();
 }
示例#4
0
 public function ajaxUpdateStatus($eventId, $status)
 {
     $filter = JFilterInput::getInstance();
     $eventId = $filter->clean($eventId, 'int');
     $status = $filter->clean($status, 'int');
     $target = NULL;
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     $my = CFactory::getUser();
     $objResponse = new JAXResponse();
     $memberId = $my->id;
     $modal =& $this->getModel('events');
     $event =& JTable::getInstance('Event', 'CTable');
     $event->load($eventId);
     CFactory::load('helpers', 'event');
     $handler = CEventHelper::getHandler($event);
     if (!$handler->isAllowed()) {
         $objResponse->addAlert(JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN'));
         return $objResponse->sendResponse();
     }
     if ($event->ticket && ($status == COMMUNITY_EVENT_STATUS_ATTEND && $event->confirmedcount + 1 > $event->ticket)) {
         $objResponse->addAlert(JText::_('COM_COMMUNITY_EVENTS_TICKET_FULL'));
         return $objResponse->sendResponse();
     }
     $eventMember =& JTable::getInstance('EventMembers', 'CTable');
     $eventMember->load($memberId, $eventId);
     if ($eventMember->permission != 1 && $eventMember->permission != 2) {
         $eventMember->permission = 3;
     }
     $date =& JFactory::getDate();
     $eventMember->created = $date->toMYSQL();
     $eventMember->status = $status;
     $eventMember->store();
     $event->updateGuestStats();
     $event->store();
     //activities stream goes here.
     $url = $handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false);
     CFactory::load('helpers', 'event');
     // We update the activity only if a user attend an event and the event was set to public event
     if ($status == COMMUNITY_EVENT_STATUS_ATTEND && $handler->isPublic()) {
         $command = 'events.attendence.attend';
         $actor = $my->id;
         $target = 0;
         $content = '';
         $cid = $event->id;
         $app = 'events';
         $act = $handler->getActivity($command, $actor, $target, $content, $cid, $app);
         $act->eventid = $event->id;
         $params = new CParameter('');
         $action_str = 'events.attendence.attend';
         $params->set('eventid', $event->id);
         $params->set('action', $action_str);
         $params->set('event_url', $url);
         // Add activity logging
         CFactory::load('libraries', 'activities');
         CActivityStream::add($act, $params->toString());
     }
     //trigger goes here.
     CFactory::load('libraries', 'apps');
     $appsLib =& CAppPlugins::getInstance();
     $appsLib->loadApplications();
     $params = array();
     $params[] =& $event;
     $params[] = $my->id;
     $params[] = $status;
     if (!is_null($target)) {
         $params[] = $target;
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_ACTIVITIES));
     CFactory::load('libraries', 'events');
     $html = CEvents::getEventMemberHTML($event->id);
     if ($status == COMMUNITY_EVENT_STATUS_ATTEND) {
         $RSVPmessage = JText::_('COM_COMMUNITY_EVENTS_ATTENDING_EVENT_MESSAGE');
     } else {
         $RSVPmessage = JText::_('COM_COMMUNITY_EVENTS_NOT_ATTENDING_EVENT_MESSAGE');
     }
     $objResponse->addScriptCall('__callback', $html);
     $objResponse->addScriptCall("joms.jQuery('#community-event-rsvp-alert .cdata').html('{$RSVPmessage}');");
     return $objResponse->sendResponse();
 }
示例#5
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();
 }
示例#6
0
文件: photos.php 项目: bizanto/Hooked
 /**
  * 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)
 {
     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::_('CC NOT ALLOWED TO POST COMMENT');
         return;
     }
     // If the content is false, the message might be empty.
     if (empty($message)) {
         $response->addAlert(JText::_('CC EMPTY WALL MESSAGE'));
     } else {
         $wall = CWallLibrary::saveWall($uniqueId, $message, 'photos', $my, $my->id == $photo->creator, 'photos,photo');
         $url = $handler->getPhotoURI($photo->albumid, $photo->id, false);
         $param = new JParameter('');
         $param->set('photoid', $uniqueId);
         $param->set('action', 'wall');
         $param->set('wallid', $wall->id);
         $param->set('url', $url);
         /** HTGMOD **/
         // trigger plugin event when a comment is posted to a photo
         CFactory::load('libraries', 'apps');
         $appsLib =& CAppPlugins::getInstance();
         $appsLib->loadApplications();
         $params = array();
         $params[] = $uniqueId;
         $params[] = $message;
         $appsLib->triggerEvent('onPhotoComment', $params);
         /** END HTGMOD **/
         // Get the album type
         $app = $album->type;
         // Add activity logging based on app's type
         switch ($app) {
             case 'user':
                 $user = CFactory::getUser($album->creator);
                 $params = $user->getParams();
                 $permission = $params->get('privacyPhotoView');
                 break;
             case 'event':
             case 'group':
                 CFactory::load('models', 'group');
                 $group =& JTable::getInstance('Group', 'CTable');
                 $group->load($album->groupid);
                 $permission = $group->approvals;
                 break;
         }
         if ($app == 'user' && $permission == '0' || $app == 'user' && $permission == PRIVACY_PUBLIC || $app == 'group' && $permission == COMMUNITY_PUBLIC_GROUP) {
             $this->_addActivity('photos.wall.create', $my->id, 0, JText::sprintf('CC ACTIVITIES WALL POST PHOTO', $url, $photo->caption), $message, 'photos', $uniqueId, $param->toString());
         }
         // @rule: Send notification to the photo owner.
         if ($my->id !== $photo->creator) {
             // Add notification
             CFactory::load('libraries', 'notification');
             $params = new JParameter('');
             $params->set('url', $handler->getPhotoURI($photo->albumid, $photo->id, false));
             $params->set('message', $message);
             CNotificationLibrary::add('photos.submit.wall', $my->id, $photo->creator, JText::sprintf('CC 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);
     }
     return $response->sendResponse();
 }
示例#7
0
文件: groups.php 项目: bizanto/Hooked
 /**
  * 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, $groupId)
 {
     $response = new JAXResponse();
     $my = CFactory::getUser();
     // Load necessary libraries
     CFactory::load('libraries', 'wall');
     CFactory::load('helpers', 'url');
     CFactory::load('libraries', 'activities');
     $groupModel = CFactory::getModel('groups');
     $group =& JTable::getInstance('Group', 'CTable');
     $group->load($groupId);
     $config = CFactory::getConfig();
     // @rule: If configuration is set for walls in group to be restricted to memebers only,
     // we need to respect this.
     if ($config->get('lockgroupwalls') && !$group->isMember($my->id)) {
         $response->addScriptCall('alert', JText::_('CC ACCESS FORBIDDEN'));
         return $response->sendResponse();
     }
     $message = strip_tags($message);
     // If the content is false, the message might be empty.
     if (empty($message)) {
         $response->addAlert(JText::_('CC EMPTY MESSAGE'));
     } else {
         $isAdmin = $groupModel->isAdmin($my->id, $group->id);
         // Save the wall content
         $wall = CWallLibrary::saveWall($groupId, $message, 'groups', $my, $isAdmin, 'groups,group');
         // Store event will update all stats count data
         $group->updateStats();
         $group->store();
         // @rule: only add the activities of the wall if the group is not private.
         if ($group->approvals == COMMUNITY_PUBLIC_GROUP) {
             $params = new JParameter('');
             $params->set('action', 'group.wall.create');
             $params->set('wallid', $wall->id);
             $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupId);
             $act = new stdClass();
             $act->cmd = 'group.wall.create';
             $act->actor = $my->id;
             $act->target = 0;
             $act->title = JText::sprintf('CC ACTIVITIES WALL POST GROUP', '{group_url}', $group->name);
             $act->content = $message;
             $act->app = 'groups';
             $act->cid = $groupId;
             CActivityStream::add($act, $params->toString());
         }
         // @rule: Add user points
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('group.wall.create');
         // @rule: Send email notification to members
         $groupParams = $group->getParams();
         if ($groupParams->get('wallnotification') == '1') {
             $model =& $this->getModel('groups');
             $members = $model->getMembers($groupId, null);
             $admins = $model->getAdmins($groupId, null);
             $membersArray = array();
             foreach ($members as $row) {
                 if ($my->id != $row->id) {
                     $membersArray[] = $row->id;
                 }
             }
             foreach ($admins as $row) {
                 if ($my->id != $row->id) {
                     $membersArray[] = $row->id;
                 }
             }
             unset($members);
             unset($admins);
             // Add notification
             CFactory::load('libraries', 'notification');
             $params = new JParameter('');
             $params->set('url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupId);
             $params->set('group', $group->name);
             $params->set('message', $message);
             CNotificationLibrary::add('groups.wall.create', $my->id, $membersArray, JText::sprintf('CC NEW WALL POST NOTIFICATION EMAIL SUBJECT', $my->getDisplayName(), $group->name), '', 'groups.wall', $params);
         }
         $response->addScriptCall('joms.walls.insert', $wall->content);
     }
     return $response->sendResponse();
 }
示例#8
0
文件: videos.php 项目: bizanto/Hooked
 public function ajaxRemoveWall($wallId)
 {
     CFactory::load('helpers', 'owner');
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     // Only allow wall removal by admin or owner of the video.
     $response = new JAXResponse();
     $wallsModel = $this->getModel('wall');
     $wall = $wallsModel->get($wallId);
     $video =& JTable::getInstance('Video', 'CTable');
     $video->load($wall->contentid);
     $my = CFactory::getUser();
     if (COwnerHelper::isCommunityAdmin() || $my->id == $video->creator) {
         if ($wallsModel->deletePost($wallId)) {
             $response->addAlert(JText::_('CC WALL REMOVED'));
             if ($wall->post_by != 0) {
                 CFactory::load('libraries', 'userpoints');
                 CUserPoints::assignPoint('wall.remove', $wall->post_by);
             }
         } else {
             $response->addAlert(JText::_('CC CANNOT REMOVE WALL'));
         }
     } else {
         $response->addAlert(JText::_('CC CANNOT REMOVE WALL'));
     }
     return $response->sendResponse();
 }
示例#9
0
 public function ajaxRemoveWall($wallId)
 {
     $filter = JFilterInput::getInstance();
     $wallId = $filter->clean($wallId, 'int');
     CError::assert($wallId, '', '!empty', __FILE__, __LINE__);
     $response = new JAXResponse();
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     //@rule: Check if user is really allowed to remove the current wall
     $my = CFactory::getUser();
     $wallModel = $this->getModel('wall');
     $wall = $wallModel->get($wallId);
     $eventModel = $this->getModel('events');
     $event = JTable::getInstance('Event', 'CTable');
     $event->load($wall->contentid);
     if (!COwnerHelper::isCommunityAdmin() && !$event->isAdmin($my->id)) {
         $response->addScriptCall('alert', JText::_('COM_COMMUNITY_NOT_ALLOWED_TO_REMOVE_WALL'));
     } else {
         if (!$wallModel->deletePost($wallId)) {
             $response->addAlert(JText::_('COM_COMMUNITY_GROUPS_REMOVE_WALL_ERROR'));
         } else {
             if ($wall->post_by != 0) {
                 //add user points
                 CUserPoints::assignPoint('wall.remove', $wall->post_by);
             }
         }
         // Substract the count
         $event->substractWallCount();
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_ACTIVITIES));
     return $response->sendResponse();
 }
示例#10
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
  * @deprecated since 2.4
  *
  **/
 public function ajaxSaveWall($message, $groupId)
 {
     $filter = JFilterInput::getInstance();
     $message = $filter->clean($message, 'string');
     $groupId = $filter->clean($groupId, 'int');
     $response = new JAXResponse();
     $my = CFactory::getUser();
     // Load necessary libraries
     CFactory::load('libraries', 'wall');
     CFactory::load('helpers', 'url');
     CFactory::load('libraries', 'activities');
     $groupModel = CFactory::getModel('groups');
     $group =& JTable::getInstance('Group', 'CTable');
     $group->load($groupId);
     $config = CFactory::getConfig();
     // @rule: If configuration is set for walls in group to be restricted to memebers only,
     // we need to respect this.
     if (!$my->authorise('community.save', 'groups.wall.' . $groupId, $group)) {
         $response->addScriptCall('alert', JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN'));
         return $response->sendResponse();
     }
     $message = strip_tags($message);
     // If the content is false, the message might be empty.
     if (empty($message)) {
         $response->addAlert(JText::_('COM_COMMUNITY_EMPTY_MESSAGE'));
     } else {
         $isAdmin = $groupModel->isAdmin($my->id, $group->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=groups&task=viewgroup&groupid=' . $groupId));
             $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($groupId, $message, 'groups', $my, $isAdmin, 'groups,group');
         // Store event will update all stats count data
         $group->updateStats();
         $group->store();
         // @rule: only add the activities of the wall if the group is not private.
         if ($group->approvals == COMMUNITY_PUBLIC_GROUP) {
             $params = new CParameter('');
             $params->set('action', 'group.wall.create');
             $params->set('wallid', $wall->id);
             $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupId);
             $act = new stdClass();
             $act->cmd = 'group.wall.create';
             $act->actor = $my->id;
             $act->target = 0;
             $act->title = JText::sprintf('COM_COMMUNITY_GROUPS_WALL_POST_GROUP', '{group_url}', $group->name);
             $act->content = $message;
             $act->app = 'groups.wall';
             $act->cid = $wall->id;
             $act->groupid = $group->id;
             // Allow comments
             $act->comment_type = 'groups.wall';
             $act->comment_id = $wall->id;
             CActivityStream::add($act, $params->toString());
         }
         // @rule: Add user points
         CFactory::load('libraries', 'userpoints');
         CUserPoints::assignPoint('group.wall.create');
         // @rule: Send email notification to members
         $groupParams = $group->getParams();
         if ($groupParams->get('wallnotification') == '1') {
             $model =& $this->getModel('groups');
             $members = $model->getMembers($groupId, null);
             $admins = $model->getAdmins($groupId, null);
             $membersArray = array();
             foreach ($members as $row) {
                 if ($my->id != $row->id) {
                     $membersArray[] = $row->id;
                 }
             }
             foreach ($admins as $row) {
                 if ($my->id != $row->id) {
                     $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=viewgroup&groupid=' . $groupId);
             $params->set('group', $group->name);
             $params->set('message', $message);
             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);
         }
         $response->addScriptCall('joms.walls.insert', $wall->content);
     }
     $this->cacheClean(array(COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_ACTIVITIES));
     return $response->sendResponse();
 }
示例#11
0
文件: system.php 项目: bizanto/Hooked
 public function ajaxEditWall($wallId, $editableFunc)
 {
     $objResponse = new JAXResponse();
     $wall =& JTable::getInstance('Wall', 'CTable');
     $wall->load($wallId);
     CFactory::load('libraries', 'wall');
     $isEditable = CWall::isEditable($editableFunc, $wall->id);
     if (!$isEditable) {
         $objResponse->addAlert(JText::_('CC NOT ALLOWED TO EDIT'));
         return $objResponse->sendResponse();
     }
     CFactory::load('libraries', 'comment');
     $tmpl = new CTemplate();
     $message = CComment::stripCommentData($wall->comment);
     $tmpl->set('message', $message);
     $tmpl->set('editableFunc', $editableFunc);
     $tmpl->set('id', $wall->id);
     $content = $tmpl->fetch('wall.edit');
     $objResponse->addScriptCall('joms.jQuery("#wall_' . $wallId . ' div.loading").hide();');
     $objResponse->addAssign('wall-edit-container-' . $wallId, 'innerHTML', $content);
     return $objResponse->sendResponse();
 }
示例#12
0
文件: events.php 项目: bizanto/Hooked
 public function ajaxRemoveWall($wallId)
 {
     CError::assert($wallId, '', '!empty', __FILE__, __LINE__);
     $response = new JAXResponse();
     CFactory::load('helpers', 'owner');
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     //@rule: Check if user is really allowed to remove the current wall
     $my = CFactory::getUser();
     $wallModel =& $this->getModel('wall');
     $wall = $wallModel->get($wallId);
     $eventModel =& $this->getModel('events');
     $event =& JTable::getInstance('Event', 'CTable');
     $event->load($wall->contentid);
     if (!COwnerHelper::isCommunityAdmin() && !$event->isAdmin($my->id)) {
         $response->addScriptCall('alert', JText::_('CC NOT ALLOWED TO REMOVE WALL'));
     } else {
         if (!$wallModel->deletePost($wallId)) {
             $response->addAlert(JText::_('CC CANNOT REMOVE WALL'));
         } else {
             if ($wall->post_by != 0) {
                 //add user points
                 CFactory::load('libraries', 'userpoints');
                 CUserPoints::assignPoint('wall.remove', $wall->post_by);
             }
         }
         // Substract the count
         $event->substractWallCount();
     }
     return $response->sendResponse();
 }
示例#13
0
 /**
  * Add comment to the stream
  *
  * @param int	$actid acitivity id
  * @param string $comment
  * @return obj
  */
 public function ajaxStreamAddComment($actid, $comment)
 {
     $filter = JFilterInput::getInstance();
     $actid = $filter->clean($actid, 'int');
     $comment = $filter->clean($comment, 'string');
     $my = CFactory::getUser();
     $config = CFactory::getConfig();
     $objResponse = new JAXResponse();
     $wallModel = CFactory::getModel('wall');
     CFactory::load('libraries', 'wall');
     CFactory::load('libraries', 'activities');
     CFactory::load('helpers', 'friends');
     CFactory::load('helper', 'owner');
     // Pull the activity record and find out the actor
     // only allow comment if the actor is a friend of current user
     $act =& JTable::getInstance('Activity', 'CTable');
     $act->load($actid);
     //who can add comment
     $obj = new stdClass();
     if ($act->groupid > 0) {
         $obj =& JTable::getInstance('Group', 'CTable');
         $obj->load($act->groupid);
     } else {
         if ($act->eventid > 0) {
             $obj =& JTable::getInstance('Event', 'CTable');
             $obj->load($act->eventid);
         }
     }
     if ($my->authorise('community.add', 'activities.comment.' . $act->actor, $obj)) {
         $table =& JTable::getInstance('Wall', 'CTable');
         $table->type = $act->comment_type;
         $table->contentid = $act->comment_id;
         $table->post_by = $my->id;
         $table->comment = $comment;
         $table->store();
         $cache = CFactory::getFastCache();
         $cache->clean(array('activities'));
         $comment = CWall::formatComment($table);
         $objResponse->addScriptCall('joms.miniwall.insert', $actid, $comment);
     } else {
         // Cannot comment on non-friend stream.
         $objResponse->addAlert('Permission denied');
     }
     return $objResponse->sendResponse();
 }