Example #1
0
 /**
  * Displays the edit stream form
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function edit()
 {
     $ajax = FD::ajax();
     $id = JRequest::getInt('id');
     $stream = FD::table('Stream');
     $stream->load($id);
     $mentions = $stream->getTags(array('user', 'hashtag'));
     $story = FD::story();
     $story->setContent($stream->content);
     $story->setMentions($mentions);
     $contents = $story->getMentionsForm();
     return $ajax->resolve($contents);
 }
Example #2
0
 /**
  * Restful api to share a new story
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function share()
 {
     // Validate the user first
     $userId = $this->validateAuth();
     // Get the content for the story
     $content = $this->input->get('content', '', 'default');
     // The target item to comment on
     $target = $this->input->get('target_user', 0, 'int');
     if (!$content) {
         $this->set('code', '403');
         $this->set('message', JText::_('Please enter some contents.'));
         return parent::display();
     }
     // Load up story library
     $story = FD::story(SOCIAL_TYPE_USER);
     // Create the story
     $args = array('content' => $content, 'contextIds' => $target, 'contextType' => SOCIAL_TYPE_STORY, 'actorId' => $userId);
     $result = $story->create($args);
     $this->set('status', 1);
     parent::display();
 }
Example #3
0
 public function post()
 {
     $app = JFactory::getApplication();
     //$share_for = $app->input->get('share_for','','CMD');
     $type = $app->input->get('type', 'story', 'STRING');
     $content = $app->input->get('content', '', 'RAW');
     //$targetId = $app->input->get('target_user','All','raw');
     $targetId = $app->input->get('target_user', 0, 'INT');
     $cluster = $app->input->get('cluster_id', null, 'INT');
     $clusterType = $app->input->get('cluster_type', null, 'STRING');
     $friends_tags = $app->input->get('friends_tags', null, 'ARRAY');
     $log_usr = intval($this->plugin->get('user')->id);
     //now take login user stream for target
     $targetId = $targetId != $log_usr ? $targetId : $log_usr;
     $valid = 1;
     $result = new stdClass();
     $story = FD::story(SOCIAL_TYPE_USER);
     // Check whether the user can really post something on the target
     if ($targetId) {
         $tuser = FD::user($targetId);
         $allowed = $tuser->getPrivacy()->validate('profiles.post.status', $targetId, SOCIAL_TYPE_USER);
         if (!$allowed) {
             $result->id = 0;
             $result->status = 0;
             $result->message = 'User not allowed any post in share';
             $valid = 0;
         }
     }
     if (empty($type)) {
         $result->id = 0;
         $result->status = 0;
         $result->message = 'Empty type not allowed';
         $valid = 0;
     } else {
         if ($valid) {
             // Determines if the current posting is for a cluster
             $cluster = isset($cluster) ? $cluster : 0;
             //$clusterType = ($cluster) ? 'group' : null;
             $isCluster = $cluster ? true : false;
             if ($isCluster) {
                 $group = FD::group($cluster);
                 $permissions = $group->getParams()->get('stream_permissions', null);
                 if ($permissions != null) {
                     // If the user is not an admin, ensure that permissions has member
                     if ($group->isMember() && !in_array('member', $permissions) && !$group->isOwner() && !$group->isAdmin()) {
                         $result->message = 'This group memder do not have share data permission';
                     }
                     // If the user is an admin, ensure that permissions has admin
                     if ($group->isAdmin() && !in_array('admin', $permissions) && !$group->isOwner()) {
                         $result->message = 'This group admin do not have share data permission';
                     }
                     $result->id = 0;
                     $result->status = 0;
                     $this->plugin->setResponse($result);
                     return;
                 }
             }
             //validate friends
             $friends = array();
             if (!empty($friends_tags)) {
                 // Get the friends model
                 $model = FD::model('Friends');
                 // Check if the user is really a friend of him / her.
                 foreach ($friends_tags as $id) {
                     if (!$model->isFriends($log_usr, $id)) {
                         continue;
                     }
                     $friends[] = $id;
                 }
             } else {
                 $friends = null;
             }
             $privacyRule = $type == 'photos' ? 'photos.view' : 'story.view';
             //for hashtag mentions
             $mentions = null;
             //if($type == 'hashtag' || !empty($content))
             if (!empty($content)) {
                 //$type = 'story';
                 $start = 0;
                 $posn = array();
                 //code adjust for 0 position hashtag
                 $content = 'a ' . $content;
                 while ($pos = strpos($content, '#', $start)) {
                     //echo 'Found # at position '.$pos."\n";
                     $posn[] = $pos - 2;
                     $start = $pos + 1;
                 }
                 $content = substr($content, 2);
                 //
                 //$pos = strpos(($content),'#',$start);
                 $cont_arr = explode(' ', $content);
                 $indx = 0;
                 foreach ($cont_arr as $val) {
                     if (preg_match('/[\'^#,|=_+¬-]/', $val)) {
                         //$vsl = substr_count($val,'#');
                         $val_arr = array_filter(explode('#', $val));
                         foreach ($val_arr as $subval) {
                             $subval = '#' . $subval;
                             $mention = new stdClass();
                             $mention->start = $posn[$indx++];
                             $mention->length = strlen($subval) - 0;
                             $mention->value = str_replace('#', '', $subval);
                             $mention->type = 'hashtag';
                             $mentions[] = $mention;
                         }
                     }
                 }
                 //print_r( $mentions );die("in share api");
             }
             $contextIds = 0;
             if ($type == 'photos') {
                 $photo_obj = $this->uploadPhoto($log_usr, 'user');
                 $photo_ids[] = $photo_obj->id;
                 $contextIds = count($photo_ids) ? $photo_ids : null;
             } else {
                 $type = 'story';
             }
             // Process moods here
             $mood = FD::table('Mood');
             // Options that should be sent to the stream lib
             $args = array('content' => $content, 'actorId' => $log_usr, 'targetId' => $targetId, 'location' => null, 'with' => $friends, 'mentions' => $mentions, 'cluster' => $cluster, 'clusterType' => $clusterType, 'mood' => null, 'privacyRule' => $privacyRule, 'privacyValue' => 'public', 'privacyCustom' => '');
             $photo_ids = array();
             $args['actorId'] = $log_usr;
             $args['contextIds'] = $contextIds;
             $args['contextType'] = $type;
             // Create the stream item
             $stream = $story->create($args);
             // Privacy is only applicable to normal postings
             if (!$isCluster) {
                 $privacyLib = FD::privacy();
                 if ($type == 'photos') {
                     $photoIds = FD::makeArray($contextIds);
                     foreach ($photoIds as $photoId) {
                         $privacyLib->add($privacyRule, $photoId, $type, 'public', null, '');
                     }
                 } else {
                     $privacyLib->add($privacyRule, $stream->uid, $type, 'public', null, '');
                 }
             }
             // Add badge for the author when a report is created.
             $badge = FD::badges();
             $badge->log('com_easysocial', 'story.create', $log_usr, JText::_('Posted a new update'));
             // @points: story.create
             // Add points for the author when a report is created.
             $points = FD::points();
             $points->assign('story.create', 'com_easysocial', $log_usr);
             if ($stream->id) {
                 $result->id = $stream->id;
                 $result->status = 1;
                 $result->message = 'data share successfully';
             }
         }
     }
     $this->plugin->setResponse($result);
 }
Example #4
0
 /**
  * Stores a new story item
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function create()
 {
     // Check for request forgeries
     FD::checkToken();
     // Check for valid users.
     FD::requireLogin();
     // Load our story library
     $story = FD::story(SOCIAL_TYPE_USER);
     // Get posted data.
     $post = $this->input->getArray('post');
     // Check if the user being viewed the same user or other user.
     $id = $post['target'];
     $targetId = $this->my->id != $id ? $id : '';
     // Determine the post types.
     $type = isset($post['attachment']) && !empty($post['attachment']) ? $post['attachment'] : SOCIAL_TYPE_STORY;
     // Check if the content is empty only for story based items.
     if ((!isset($post['content']) || empty($post['content'])) && $type == SOCIAL_TYPE_STORY) {
         $this->view->setMessage('COM_EASYSOCIAL_STORY_PLEASE_POST_MESSAGE', SOCIAL_MSG_ERROR);
         return $this->view->call(__FUNCTION__);
     }
     // Check if the content is empty and there's no photos.
     if ((!isset($post['photos']) || empty($post['photos'])) && $type == 'photos') {
         $this->view->setMessage('COM_EASYSOCIAL_STORY_PLEASE_ADD_PHOTO', SOCIAL_MSG_ERROR);
         return $this->view->call(__FUNCTION__);
     }
     // We need to allow raw because we want to allow <,> in the text but it should be escaped during display
     $content = $this->input->get('content', '', 'raw');
     // Check whether the user can really post something on the target
     if ($targetId) {
         $allowed = $this->my->getPrivacy()->validate('profiles.post.status', $targetId, SOCIAL_TYPE_USER);
         if (!$allowed) {
             $this->view->setMessage('COM_EASYSOCIAL_STORY_NOT_ALLOW_TO_POST', SOCIAL_MSG_ERROR);
             return $this->view->call(__FUNCTION__);
         }
     }
     // Store the location for this story
     $shortAddress = $this->input->get('locations_short_address', '', 'default');
     $address = $this->input->get('locations_formatted_address', '', 'default');
     $lat = $this->input->get('locations_lat', '', 'default');
     $lng = $this->input->get('locations_lng', '', 'default');
     $locationData = $this->input->get('locations_data', '', 'default');
     $location = null;
     // Only store location when there is location data
     if (!empty($address) && !empty($lat) && !empty($lng)) {
         $location = FD::table('Location');
         $location->short_address = $shortAddress;
         $location->address = $address;
         $location->longitude = $lng;
         $location->latitude = $lat;
         $location->uid = $story->id;
         $location->type = $type;
         $location->user_id = $this->my->id;
         $location->params = $locationData;
         // Try to save the location data.
         $state = $location->store();
     }
     // Get which users are tagged in this post.
     $friendIds = $this->input->get('friends_tags', '', 'default');
     $friends = array();
     if (!empty($friendIds)) {
         // Get the friends model
         $model = FD::model('Friends');
         // Check if the user is really a friend of him / her.
         foreach ($friendIds as $id) {
             if (!$model->isFriends($this->my->id, $id)) {
                 continue;
             }
             $friends[] = $id;
         }
     }
     $contextIds = 0;
     // For photos that are posted on the story form
     if ($type == 'photos' && isset($post['photos'])) {
         $contextIds = $post['photos'];
     }
     // Check if there are mentions provided from the post.
     $mentions = isset($post['mentions']) ? $post['mentions'] : array();
     // Format the json string to array
     if (isset($post['mentions'])) {
         $mentions = $post['mentions'];
         foreach ($mentions as &$mention) {
             $mention = json_decode($mention);
         }
     }
     // Process moods here
     $mood = FD::table('Mood');
     $hasMood = $mood->bindPost($post);
     // If this exists, we need to store them
     if ($hasMood) {
         $mood->user_id = $this->my->id;
         $mood->store();
     }
     // Set the privacy for the album
     $privacy = $this->input->get('privacy', '', 'default');
     $customPrivacy = $this->input->get('privacyCustom', '', 'string');
     $privacyRule = $type == 'photos' ? 'photos.view' : 'story.view';
     // Determines if the current posting is for a cluster
     $cluster = isset($post['cluster']) ? $post['cluster'] : '';
     $clusterType = isset($post['clusterType']) ? $post['clusterType'] : '';
     $isCluster = $cluster ? true : false;
     $postPermission = true;
     if ($isCluster) {
         $postPermission = $this->checkClusterPermissions($cluster, $clusterType);
     }
     // Ensure only permitted user can post the story
     if (!$postPermission) {
         return $this->view->call(__FUNCTION__);
     } else {
         // Options that should be sent to the stream lib
         $args = array('content' => $content, 'contextIds' => $contextIds, 'contextType' => $type, 'actorId' => $this->my->id, 'targetId' => $targetId, 'location' => $location, 'with' => $friends, 'mentions' => $mentions, 'cluster' => $cluster, 'clusterType' => $clusterType, 'mood' => $mood, 'privacyRule' => $privacyRule, 'privacyValue' => $privacy, 'privacyCustom' => $customPrivacy);
         // Create the stream item
         $stream = $story->create($args);
         if ($hasMood) {
             $mood->namespace = 'story.user.create';
             $mood->namespace_uid = $stream->id;
             $mood->store();
         }
         // Update with the stream's id. after the stream is created.
         if (!empty($address) && !empty($lat) && !empty($lng)) {
             $location->uid = $stream->id;
             // Try to save the location data.
             $state = $location->store();
         }
         // @badge: story.create
         // Add badge for the author when a report is created.
         $badge = FD::badges();
         $badge->log('com_easysocial', 'story.create', $this->my->id, JText::_('COM_EASYSOCIAL_STORY_BADGE_CREATED_STORY'));
         // @points: story.create
         // Add points for the author when a report is created.
         $points = FD::points();
         $points->assign('story.create', 'com_easysocial', $this->my->id);
         // Privacy is only applicable to normal postings
         if (!$isCluster) {
             $privacyLib = FD::privacy();
             if ($type == 'photos') {
                 $photoIds = FD::makeArray($contextIds);
                 foreach ($photoIds as $photoId) {
                     $privacyLib->add($privacyRule, $photoId, $type, $privacy, null, $customPrivacy);
                 }
             } else {
                 $privacyLib->add($privacyRule, $stream->uid, $type, $privacy, null, $customPrivacy);
             }
         }
         return $this->view->call(__FUNCTION__, $stream, $cluster, $clusterType);
     }
 }
Example #5
0
 /**
  * Displays a user profile to a 3rd person perspective.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	null
  **/
 public function display($tpl = null)
 {
     // Get the user's id.
     $id = $this->input->get('id', 0, 'int');
     // Check if there is any stream filtering or not.
     $filter = $this->input->get('type', '', 'word');
     // The current logged in user might be viewing their own profile.
     if ($id == 0) {
         $id = FD::user()->id;
     }
     // When the user tries to view his own profile but if he isn't logged in, throw a login page.
     if ($id == 0) {
         return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER'));
     }
     // Check for user profile completeness
     FD::checkCompleteProfile();
     // Get the user's object.
     $user = FD::user($id);
     // If the user doesn't exist throw an error
     if (!$user->id) {
         return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER'));
     }
     // If the user is blocked or the user doesn't have community access
     if ($this->my->id != $user->id && $this->my->isBlockedBy($user->id) || !$user->hasCommunityAccess()) {
         return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER'));
     }
     // If the user is blocked, they should not be accessible
     if ($user->isBlock()) {
         return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER'));
     }
     // Set the page properties
     $this->page->title($this->string->escape($user->getName()));
     $this->page->breadcrumb($this->string->escape($user->getName()));
     // Get the current user's privacy object
     $privacy = $this->my->getPrivacy();
     // Let's test if the current viewer is allowed to view this profile.
     if ($this->my->id != $user->id && !$privacy->validate('profiles.view', $user->id, SOCIAL_TYPE_USER)) {
         $this->set('user', $user);
         return parent::display('site/profile/restricted');
     }
     // Apply opengraph tags.
     FD::opengraph()->addProfile($user);
     // Do not assign badge if i view myself.
     if ($user->id != $this->my->id && $this->my->id) {
         // @badge: profile.view
         $badge = FD::badges();
         $badge->log('com_easysocial', 'profile.view', $this->my->id, JText::_('COM_EASYSOCIAL_PROFILE_VIEWED_A_PROFILE'));
     }
     // Get the limit start
     $startLimit = $this->input->get('limitstart', 0, 'int');
     // Determine if the current request is to load an app
     $appId = $this->input->get('appId', 0, 'int');
     // Get the apps library.
     $appsLib = FD::apps();
     // Default contents
     $contents = '';
     // Load the app when necessary
     if ($appId) {
         $app = FD::table('App');
         $app->load($appId);
         // Check if the user has access to this app
         if (!$app->accessible($user->id)) {
             FD::info()->set(false, JText::_('COM_EASYSOCIAL_PROFILE_APP_IS_NOT_INSTALLED_BY_USER'), SOCIAL_MSG_ERROR);
             $redirect = FRoute::profile(array('id' => $user->getAlias()), false);
             return $this->redirect($redirect);
         }
         // Set the page title
         $this->page->title(FD::string()->escape($user->getName()) . ' - ' . $app->get('title'));
         // Render the app contents
         $contents = $appsLib->renderView(SOCIAL_APPS_VIEW_TYPE_EMBED, 'profile', $app, array('userId' => $user->id));
     }
     // Get the layout
     $layout = $this->input->get('layout', '', 'cmd');
     // @since 1.3.7
     // If layout is empty, means we want to get the default view
     // Previously timeline is always the default
     if (empty($appId) && empty($layout) && $filter != 'appFilter') {
         $defaultDisplay = $this->config->get('users.profile.display', 'timeline');
         $layout = $defaultDisplay;
     }
     // Default variables
     $timeline = null;
     $newCover = false;
     // Viewing info of a user.
     if ($layout === 'about') {
         $showTimeline = false;
         $usersModel = FD::model('Users');
         $steps = $usersModel->getAbout($user);
         // We should generate a canonical link if user is viewing the about section and the default page is about
         if ($this->config->get('users.profile.display') == 'about') {
             $this->page->canonical($user->getPermalink(false, true));
         }
         if ($steps) {
             foreach ($steps as $step) {
                 if ($step->active) {
                     $theme = FD::themes();
                     $theme->set('fields', $step->fields);
                     $contents = $theme->output('site/events/item.info');
                 }
             }
         }
         $this->set('infoSteps', $steps);
     }
     // Should we filter stream items by specific app types
     $appType = $this->input->get('filterid', '', 'string');
     // If contents is still empty at this point, then we just get the stream items as the content
     if (empty($contents) || $filter == 'appFilter') {
         // Should the timeline be active
         $timeline = true;
         // Retrieve user's stream
         $theme = FD::themes();
         // Get story
         $story = FD::story(SOCIAL_TYPE_USER);
         $story->target = $user->id;
         // Get the stream
         $stream = FD::stream();
         //lets get the sticky posts 1st
         $stickies = $stream->getStickies(array('userId' => $user->id, 'limit' => 0));
         if ($stickies) {
             $stream->stickies = $stickies;
         }
         $streamOptions = array('userId' => $user->id, 'nosticky' => true, 'startlimit' => $startLimit);
         if ($filter == 'appFilter') {
             $timeline = false;
             $streamOptions['actorId'] = $user->id;
         }
         if ($appType) {
             $streamOptions['context'] = $appType;
             // Should this be set now or later
             $stream->filter = 'custom';
         }
         $stream->get($streamOptions);
         // Only registered users can access the story form
         if (!$this->my->guest) {
             $stream->story = $story;
         }
         // Set stream to theme
         $theme->set('stream', $stream);
         $contents = $theme->output('site/profile/default.stream');
     }
     // Get user's cover object
     $cover = $user->getCoverData();
     // If we're setting a cover
     $coverId = $this->input->get('cover_id', 0, 'int');
     // Load cover photo
     if ($coverId) {
         $coverTable = FD::table('Photo');
         $coverTable->load($coverId);
         // If the cover photo belongs to the user
         if ($coverTable->isMine()) {
             $newCover = $coverTable;
         }
     }
     $streamModel = FD::model('Stream');
     // Get a list of application filters
     $appFilters = $streamModel->getAppFilters(SOCIAL_TYPE_USER);
     // Retrieve list of apps for this user
     $appsModel = FD::model('Apps');
     $options = array('view' => 'profile', 'uid' => $user->id, 'key' => SOCIAL_TYPE_USER);
     $apps = $appsModel->getApps($options);
     $this->set('appFilters', $appFilters);
     $this->set('filterId', $appType);
     $this->set('timeline', $timeline);
     $this->set('newCover', $newCover);
     $this->set('cover', $cover);
     $this->set('contents', $contents);
     $this->set('appsLib', $appsLib);
     $this->set('apps', $apps);
     $this->set('activeApp', $appId);
     $this->set('privacy', $privacy);
     $this->set('user', $user);
     // Load the output of the profile.
     return parent::display('site/profile/default');
 }
Example #6
0
 /**
  * Retrieves the group's stream items.
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function getStream()
 {
     // Check for request forgeries
     FD::checkToken();
     // Load up the group
     $id = $this->input->get('id', 0, 'int');
     $group = FD::group($id);
     // Check if the group can be seen by this user
     if ($group->isClosed() && !$group->isMember() && !$my->isSiteAdmin()) {
         $this->view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_NO_ACCESS'), SOCIAL_MSG_ERROR);
         return $this->view->call(__FUNCTION__);
     }
     // Retrieve the stream
     $stream = FD::stream();
     $stickies = $stream->getStickies(array('clusterId' => $group->id, 'clusterType' => SOCIAL_TYPE_GROUP, 'limit' => 0));
     if ($stickies) {
         $stream->stickies = $stickies;
     }
     // Determines if the user should see the story form
     if ($group->isMember() || $this->my->isSiteAdmin()) {
         $story = FD::story(SOCIAL_TYPE_GROUP);
         $story->setCluster($group->id, SOCIAL_TYPE_GROUP);
         $story->showPrivacy(false);
         $stream->story = $story;
         // Get the group params
         $params = $group->getParams();
         // Ensure that the user has permissions to see the story form
         $permissions = $params->get('stream_permissions', null);
         // If permissions has been configured before.
         if (!is_null($permissions)) {
             // If the user is not an admin, ensure that permissions has member
             if (!$group->isAdmin() && !in_array('member', $permissions)) {
                 unset($stream->story);
             }
             // If the user is an admin, ensure that permissions has admin
             if ($group->isAdmin() && !in_array('admin', $permissions) && !$group->isOwner()) {
                 unset($stream->story);
             }
         }
     }
     // lets get stream items for this group
     $options = array('clusterId' => $group->id, 'clusterType' => SOCIAL_TYPE_GROUP, 'nosticky' => true);
     // Determines if we should only display moderated stream items
     $options['onlyModerated'] = $this->input->get('moderation', false, 'bool');
     // Determines if we should filter stream items by specific filters
     $filterId = $this->input->get('filterId', 0, 'int');
     if ($filterId) {
         $streamFilter = FD::table('StreamFilter');
         $streamFilter->load($filterId);
         // Get a list of hashtags
         $hashtags = $streamFilter->getHashTag();
         $tags = explode(',', $hashtags);
         if ($tags) {
             $options['tag'] = $tags;
         }
     }
     // Retrieving stream items by app element
     $appElement = $this->input->get('app', '', 'word');
     if ($appElement) {
         $options['context'] = $appElement;
     }
     $stream->get($options);
     return $this->view->call(__FUNCTION__, $stream);
 }
Example #7
0
 /**
  * Displays the event item page.
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.3
  * @access public
  */
 public function item()
 {
     // Check if events is enabled.
     $this->checkFeature();
     // Check for profile completeness
     FD::checkCompleteProfile();
     // Get the event id
     $id = $this->input->get('id', 0, 'int');
     // Load up the event
     $event = FD::event($id);
     // Set the default redirect url
     $defaultRedirect = FRoute::events(array(), false);
     if (empty($event) || empty($event->id)) {
         FD::info()->set(false, JText::_('COM_EASYSOCIAL_EVENTS_INVALID_EVENT_ID'), SOCIAL_MSG_ERROR);
         return $this->redirect($defaultRedirect);
     }
     if (!$event->isPublished()) {
         FD::info()->set(false, JText::_('COM_EASYSOCIAL_EVENTS_EVENT_UNAVAILABLE'), SOCIAL_MSG_ERROR);
         return $this->redirect($defaultRedirect);
     }
     // Determines if the current user is a guest of this event
     $guest = $event->getGuest($this->my->id);
     if (!$this->my->isSiteAdmin() && $event->isInviteOnly() && !$guest->isParticipant()) {
         FD::info()->set(false, JText::_('COM_EASYSOCIAL_EVENTS_NO_ACCESS_TO_EVENT'), SOCIAL_MSG_ERROR);
         return $this->redirect($defaultRedirect);
     }
     // check if the current logged in user blocked by the event creator or not.
     if ($this->my->id != $event->creator_uid) {
         if (FD::user()->isBlockedBy($event->creator_uid)) {
             return JError::raiseError(404, JText::_('COM_EASYSOCIAL_EVENTS_EVENT_UNAVAILABLE'));
         }
     }
     // Support for group event
     // If user is not a group member, then redirect to group page
     if ($event->isGroupEvent()) {
         $group = FD::group($event->getMeta('group_id'));
         if (!$this->my->isSiteAdmin() && !$group->isMember()) {
             FD::info()->set(false, JText::_('COM_EASYSOCIAL_GROUPS_EVENTS_NO_PERMISSION_TO_VIEW_EVENT'), SOCIAL_MSG_ERROR);
             return $this->redirect($group->getPermailnk());
         }
         $this->set('group', $group);
     }
     // Set the page title
     FD::page()->title($event->getName());
     // Set the breadcrumbs
     FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_EVENTS'), FRoute::events());
     FD::page()->breadcrumb($event->getName());
     $this->set('guest', $guest);
     $this->set('event', $event);
     if (!$this->my->isSiteAdmin() && !$event->isOpen() && !$guest->isGuest()) {
         return parent::display('site/events/restricted');
     }
     // Increment the hit counter
     $event->hit();
     // stream pagination
     $startlimit = JRequest::getInt('limitstart', 0);
     // Filter stream item by specific context type
     $context = $this->input->get('app', '', 'cmd');
     $this->set('context', $context);
     // Get a list of filters
     $filters = $event->getFilters($this->my->id);
     $this->set('filters', $filters);
     // Load up the stream model
     $streamModel = FD::model('Stream');
     $appFilters = $streamModel->getAppFilters(SOCIAL_TYPE_EVENT);
     $this->set('appFilters', $appFilters);
     // Get all apps for the event
     $appsModel = FD::model('Apps');
     $apps = $appsModel->getEventApps($event->id);
     // Load css files for the apps
     foreach ($apps as $app) {
         $app->loadCss();
     }
     $contents = '';
     $isAppView = false;
     // Determines if the current page is loading a specific app item
     $appId = $this->input->get('appId', 0, 'int');
     if ($appId) {
         $app = FD::table('App');
         $app->load($appId);
         $app->loadCss();
         FD::page()->title($event->getName() . ' - ' . $app->get('title'));
         $appsLib = FD::apps();
         $contents = $appsLib->renderView(SOCIAL_APPS_VIEW_TYPE_EMBED, 'events', $app, array('eventId' => $event->id));
         $isAppView = true;
     }
     // Type can be info or timeline
     // If type is info, then we load the info tab first instead of showing timleine first
     $type = $this->input->get('type', '', 'cmd');
     // @since 1.3.7
     // If type is empty, means we want to get the default view
     // Previously timeline is always the default
     if (!$isAppView && empty($type)) {
         $type = FD::config()->get('events.item.display', 'timeline');
     }
     // Determines if the current request is to filter specific items
     $filterId = $this->input->get('filterId', 0, 'int');
     // Load Stream filter table
     $streamFilter = FD::table('StreamFilter');
     if ($filterId) {
         $streamFilter->load($filterId);
     }
     $this->set('filterId', $filterId);
     // If the current view is to display filters form
     if ($type == 'filterForm' && $guest->isGuest()) {
         $theme = FD::themes();
         $theme->set('controller', 'events');
         $theme->set('filter', $streamFilter);
         $theme->set('uid', $event->id);
         $contents = $theme->output('site/stream/form.edit');
     }
     if ($type == 'info') {
         FD::language()->loadAdmin();
         $currentStep = JRequest::getInt('step', 1);
         $steps = FD::model('Steps')->getSteps($event->category_id, SOCIAL_TYPE_CLUSTERS, SOCIAL_EVENT_VIEW_DISPLAY);
         $fieldsLib = FD::fields();
         $fieldsLib->init(array('privacy' => false));
         $fieldsModel = FD::model('Fields');
         $index = 1;
         foreach ($steps as $step) {
             $step->fields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $event->id, 'dataType' => SOCIAL_TYPE_EVENT, 'visible' => SOCIAL_EVENT_VIEW_DISPLAY));
             if (!empty($step->fields)) {
                 $args = array($event);
                 $fieldsLib->trigger('onDisplay', SOCIAL_FIELDS_GROUP_EVENT, $step->fields, $args);
             }
             $step->hide = true;
             foreach ($step->fields as $field) {
                 // As long as one of the field in the step has an output, then this step shouldn't be hidden
                 // If step has been marked false, then no point marking it as false again
                 // We don't break from the loop here because there is other checking going on
                 if (!empty($field->output) && $step->hide === true) {
                     $step->hide = false;
                 }
             }
             if ($index === 1) {
                 $step->url = FRoute::events(array('layout' => 'item', 'id' => $event->getAlias(), 'type' => 'info'), false);
             } else {
                 $step->url = FRoute::events(array('layout' => 'item', 'id' => $event->getAlias(), 'type' => 'info', 'infostep' => $index), false);
             }
             $step->title = $step->get('title');
             $step->active = !$step->hide && $currentStep == $index;
             if ($step->active) {
                 $theme = FD::themes();
                 $theme->set('fields', $step->fields);
                 $contents = $theme->output('site/events/item.info');
             }
             $step->index = $index;
             $index++;
         }
         $this->set('infoSteps', $steps);
     }
     $this->set('appId', $appId);
     $this->set('apps', $apps);
     $this->set('type', $type);
     $this->set('contents', $contents);
     if (!empty($contents)) {
         return parent::display('site/events/item');
     }
     // If no content then only we proceed to get the stream
     $stream = FD::stream();
     $streamOptions = array('clusterId' => $event->id, 'clusterType' => $event->cluster_type);
     // Load the story
     $story = FD::story($event->cluster_type);
     $story->setCluster($event->id, $event->cluster_type);
     $story->showPrivacy(false);
     // Determines if this is a hashtag
     $hashtag = $this->input->get('tag', 0, 'int');
     $hashtagAlias = $this->input->get('tag', '', 'default');
     if (!empty($hashtag)) {
         $tag = $stream->getHashTag($hashtag);
         if (!empty($tag->id)) {
             $this->set('hashtag', $tag->title);
             $this->set('hashtagAlias', $hashtagAlias);
             $story->setHashtags(array($tag->title));
             $streamOptions['tag'] = array($tag->title);
         }
     }
     if (!empty($streamFilter->id)) {
         $tags = $streamFilter->getHashtag();
         $tags = explode(',', $tags);
         $streamOptions['tag'] = $tags;
     }
     if ($guest->isGuest()) {
         $stream->story = $story;
     }
     $streamOptions['startlimit'] = $startlimit;
     if ($context) {
         $streamOptions['context'] = $context;
     }
     $stream->get($streamOptions);
     $this->set('stream', $stream);
     parent::display('site/events/item');
 }