Beispiel #1
0
 /**
  * Displays the action for albums
  *
  * @since   1.3
  * @access  public
  * @param   SocialEvent $event
  * @return
  */
 public function eventAdminStart($event)
 {
     if ($this->app->state == SOCIAL_STATE_UNPUBLISHED) {
         return;
     }
     $category = $event->getCategory();
     if (!$category->getAcl()->get('photos.enabled', true) || !$event->getParams()->get('photo.albums', true)) {
         return;
     }
     $this->set('event', $event);
     $this->set('app', $this->app);
     echo parent::display('widgets/widget.menu');
 }
Beispiel #2
0
 public function prepareCreateMilestoneStream(SocialStreamItem $streamItem, $includePrivacy = true)
 {
     $params = FD::registry($streamItem->params);
     $milestone = FD::table('Milestone');
     $milestone->bind($params->get('milestone'));
     // Get the group data
     FD::load('event');
     $event = new SocialEvent();
     $event->bind($params->get('event'));
     // Get the actor
     $actor = $streamItem->actor;
     $app = $this->getApp();
     $permalink = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $event->getAlias(), 'type' => SOCIAL_TYPE_EVENT, 'id' => $app->getAlias(), 'milestoneId' => $milestone->id));
     $this->set('permalink', $permalink);
     $this->set('milestone', $milestone);
     $this->set('actor', $actor);
     $this->set('event', $event);
     $streamItem->title = parent::display('streams/create.milestone.title');
     $streamItem->content = parent::display('streams/create.milestone.content');
     $streamItem->opengraph->addDescription(JText::sprintf('APP_EVENT_TASKS_STREAM_OPENGRAPH_CREATE_MILESTONE', $streamItem->actor->getName(), $event->getName()));
 }
Beispiel #3
0
 /**
  * Processes mentions in a stream object
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function formatMentions(SocialStreamItem &$stream)
 {
     // Get the current view
     $view = JRequest::getCmd('view', '');
     // Get the stream's content
     $content = $stream->content;
     // Get tags for the stream
     $tags = isset($stream->tags) ? $stream->tags : array();
     // If there is no tags, just skip this and escape the content
     if (!$tags) {
         return FD::string()->escape($content);
     }
     // We need to store the changes in an array and replace it accordingly based on the counter.
     $items = array();
     // We need to merge the mentions and hashtags since we are based on the offset.
     $i = 0;
     foreach ($tags as $tag) {
         if ($tag->type == 'user') {
             $replace = '<a href="' . $tag->user->getPermalink() . '" data-popbox="module://easysocial/profile/popbox" data-popbox-position="top-left" data-user-id="' . $tag->user->id . '" class="mentions-user">' . $tag->user->getName() . '</a>';
         }
         if ($tag->type == 'hashtag') {
             // $alias = JFilterOutput::stringURLSafe($tag->title);
             $alias = $tag->title;
             $url = '';
             if ($view == 'groups') {
                 $clusterReg = FD::registry($stream->params);
                 $object = $clusterReg->get($stream->cluster_type);
                 switch ($stream->cluster_type) {
                     case SOCIAL_TYPE_GROUP:
                         // for now we assume all is group type.
                         $group = new SocialGroup();
                         $group->bind($object);
                         $url = FRoute::groups(array('layout' => 'item', 'id' => $group->getAlias(), 'tag' => $alias));
                         break;
                     case SOCIAL_TYPE_EVENT:
                         $event = new SocialEvent();
                         $event->bind($object);
                         $url = FRoute::events(array('layout' => 'item', 'id' => $event->getAlias(), 'tag' => $alias));
                         break;
                     default:
                         FRoute::dashboard(array('layout' => 'hashtag', 'tag' => $alias));
                         break;
                 }
             } else {
                 $url = FRoute::dashboard(array('layout' => 'hashtag', 'tag' => $alias));
             }
             $replace = '<a href="' . $url . '" class="mentions-hashtag">#' . $tag->title . '</a>';
         }
         $links[$i] = $replace;
         $replace = '[si:mentions]' . $i . '[/si:mentions]';
         $content = JString::substr_replace($content, $replace, $tag->offset, $tag->length);
         $i++;
     }
     // Once we have the content, escape it
     $content = FD::string()->escape($content);
     if ($links) {
         for ($x = 0; $x < count($links); $x++) {
             $content = str_ireplace('[si:mentions]' . $x . '[/si:mentions]', $links[$x], $content);
         }
     }
     return $content;
 }
Beispiel #4
0
 /**
  * Alias for FD::get('Event')
  *
  * @since	1.0
  * @access	public
  * @param	Mixed		$ids	The id to load.
  * @return	SocialEvent			The event object
  */
 public static function event($ids = null, $debug = false)
 {
     // Load the group library
     FD::load('event');
     if (is_null($ids)) {
         return new SocialEvent();
     }
     $state = SocialEvent::factory($ids, $debug);
     if ($state === false) {
         return new SocialEvent();
     }
     return $state;
 }
Beispiel #5
0
 /**
  * Prepares the upload avatar stream for a event
  *
  * @since	1.3
  * @access	public
  */
 public function prepareEventUploadAvatarStream(&$item, $privacy, $includePrivacy = true)
 {
     $element = $item->context;
     $uid = $item->contextId;
     // Load the photo
     $photo = $this->getPhotoFromParams($item);
     // Get the data of the group
     $registry = Foundry::registry($item->params);
     $event = new SocialEvent();
     $event->bind($registry->get($item->cluster_type));
     $this->set('event', $event);
     $this->set('photo', $photo);
     $this->set('actor', $item->actor);
     $item->title = parent::display('streams/event/upload.avatar.title');
     $item->content = parent::display('streams/event/upload.avatar.content');
     if ($includePrivacy) {
         $item->privacy = $privacy->form($uid, $element, $item->actor->id, 'core.view', false, $item->uid);
     }
 }
Beispiel #6
0
 public function createRecurring()
 {
     FD::checkToken();
     $eventId = $this->input->getInt('eventId');
     $schedule = $this->input->getString('datetime');
     $parentEvent = FD::event($eventId);
     $duration = $parentEvent->hasEventEnd() ? $parentEvent->getEventEnd()->toUnix() - $parentEvent->getEventStart()->toUnix() : false;
     $data = $this->input->getVar('postdata');
     // Because this comes form a form, the $data['id'] might be an existing id especially if the create recurring comes from "edit"
     unset($data['id']);
     // Because this comes from a form, $data['applyRecurring'] might be 1 for applying purposes, but for creation, we do not this flag
     unset($data['applyRecurring']);
     // Mark the data as createRecurring
     $data['createRecurring'] = true;
     // Manually change the start end time
     $data['startDatetime'] = FD::date($schedule)->toSql();
     if ($duration) {
         $data['endDatetime'] = FD::date($schedule + $duration)->toSql();
     } else {
         unset($data['endDatetime']);
     }
     $my = FD::user();
     $fieldsLib = FD::fields();
     $options = array();
     $options['uid'] = $parentEvent->category_id;
     $options['group'] = SOCIAL_FIELDS_GROUP_EVENT;
     $fields = FD::model('fields')->getCustomFields($options);
     $event = new SocialEvent();
     $event->category_id = $parentEvent->category_id;
     $event->creator_uid = $parentEvent->creator_uid;
     $event->creator_type = SOCIAL_TYPE_USER;
     $event->state = SOCIAL_STATE_PUBLISHED;
     $event->key = md5(FD::date()->toSql() . $my->password . uniqid());
     $event->parent_id = $parentEvent->id;
     $event->parent_type = SOCIAL_TYPE_EVENT;
     $args = array(&$data, &$event);
     $fieldsLib->trigger('onAdminEditBeforeSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
     $event->bind($data);
     $event->save();
     // Duplicate nodes from parent
     FD::model('Events')->duplicateGuests($parentEvent->id, $event->id);
     $args = array(&$data, &$event);
     $fieldsLib->trigger('onAdminEditAfterSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
     $event->bindCustomFields($data);
     $args = array(&$data, &$event);
     $fieldsLib->trigger('onAdminEditAfterSaveFields', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
     return $this->view->call(__FUNCTION__);
 }
Beispiel #7
0
 /**
  * Triggers when an event is created
  *
  * @since	1.3
  * @access	public
  * @param	SocialEvent	The event object
  * @param	SocialUser	The user object
  * @param	bool		Determines if the event is a new event
  * @return
  */
 public function onEventAfterSave(SocialEvent &$event, SocialUser &$author, $isNew)
 {
     // When a new event is created, we want to ensure that it's stored in the user's calendar
     if ($isNew) {
         $eventstart = $event->getEventStart();
         $eventend = $event->getEventEnd();
         // Ensure that the start and end date is set
         if (!$eventstart && !$eventend) {
             return;
         }
         $calendar = FD::table('Calendar');
         // Get the start and end date
         $calendar->title = $event->getName();
         $calendar->description = $event->description;
         $calendar->uid = $event->id;
         $calendar->type = SOCIAL_TYPE_EVENT;
         $calendar->date_start = $eventstart->toSql();
         $calendar->date_end = $eventend->toSql();
         $calendar->user_id = $author->id;
         $calendar->store();
     }
 }
Beispiel #8
0
 /**
  * Creates a new event based on the session.
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.3
  * @access public
  * @param  SocialTableStepSession $session The step session.
  * @return SocialEvent                     The SocialEvent object.
  */
 public function createEvent(SocialTableStepSession $session)
 {
     FD::import('admin:/includes/event/event');
     $event = new SocialEvent();
     $event->creator_uid = FD::user()->id;
     $event->creator_type = SOCIAL_TYPE_USER;
     $event->category_id = $session->uid;
     $event->cluster_type = SOCIAL_TYPE_EVENT;
     $event->created = FD::date()->toSql();
     $event->key = md5(JFactory::getDate()->toSql() . FD::user()->password . uniqid());
     $params = FD::registry($session->values);
     // Support for group event
     if ($params->exists('group_id')) {
         $group = FD::group($params->get('group_id'));
         $event->setMeta('group_id', $group->id);
     }
     $data = $params->toArray();
     $customFields = FD::model('Fields')->getCustomFields(array('visible' => SOCIAL_EVENT_VIEW_REGISTRATION, 'group' => SOCIAL_TYPE_EVENT, 'uid' => $session->uid));
     $fieldsLib = FD::fields();
     $args = array(&$data, &$event);
     $callback = array($fieldsLib->getHandler(), 'beforeSave');
     $errors = $fieldsLib->trigger('onRegisterBeforeSave', SOCIAL_FIELDS_GROUP_EVENT, $customFields, $args, $callback);
     if (!empty($errors)) {
         $this->setError($errors);
         return false;
     }
     // Get the current user.
     $my = FD::user();
     $event->state = SOCIAL_CLUSTER_PENDING;
     // If the event is created by site admin or user doesn't need to be moderated, publish event immediately.
     if ($my->isSiteAdmin() || !$my->getAccess()->get('events.moderate')) {
         $event->state = SOCIAL_CLUSTER_PUBLISHED;
     }
     // Trigger apps
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $triggerArgs = array(&$event, &$my, true);
     // @trigger: onEventBeforeSave
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onEventBeforeSave', $triggerArgs);
     $state = $event->save();
     if (!$state) {
         $this->setError($event->getError());
         return false;
     }
     // Notifies admin when a new event is created
     if ($event->state === SOCIAL_CLUSTER_PENDING || !$my->isSiteAdmin()) {
         $this->notifyAdmins($event);
     }
     // Recreate the event object
     SocialEvent::$instances[$event->id] = null;
     $event = FD::event($event->id);
     // Create a new owner object
     $event->createOwner($my->id);
     // Support for group event
     if ($event->isGroupEvent()) {
         // Check for transfer flag to insert group member as event guest
         $transferMode = isset($data['member_transfer']) ? $data['member_transfer'] : 'invite';
         if (!empty($transferMode) && $transferMode != 'none') {
             $nodeState = SOCIAL_EVENT_GUEST_INVITED;
             if ($transferMode == 'attend') {
                 $nodeState = SOCIAL_EVENT_GUEST_GOING;
             }
             /*
             insert into jos_social_clusters_nodes (cluster_id, uid, type, created, state, owner, admin, invited_by)
                             select $eventId as cluster_id, uid, type, $now as created, $nodeState as state, 0 as owner, admin, $userId as invited_by from jos_social_clusters_nodes
                             where cluster_id = $groupId
                             and state = 1
                             and type = 'user'
                             and uid not in (select uid from jos_social_clusters_nodes where cluster_id = $eventId and type = 'user')
             */
             $eventId = $event->id;
             $groupId = $event->getMeta('group_id');
             $userId = $my->id;
             $now = FD::date()->toSql();
             $query = "INSERT INTO `#__social_clusters_nodes` (`cluster_id`, `uid`, `type`, `created`, `state`, `owner`, `admin`, `invited_by`) SELECT '{$eventId}' AS `cluster_id`, `uid`, `type`, '{$now}' AS `created`, '{$nodeState}' AS `state`, '0' AS `owner`, `admin`, '{$userId}' AS `invited_by` FROM `#__social_clusters_nodes` WHERE `cluster_id` = '{$groupId}' AND `state` = '" . SOCIAL_GROUPS_MEMBER_PUBLISHED . "' AND `type` = '" . SOCIAL_TYPE_USER . "' AND `uid` NOT IN (SELECT `uid` FROM `#__social_clusters_nodes` WHERE `cluster_id` = '{$eventId}' AND `type` = '" . SOCIAL_TYPE_USER . "')";
             $db = FD::db();
             $sql = $db->sql();
             $sql->raw($query);
             $db->setQuery($sql);
             $db->query();
         }
     }
     // Trigger the fields again
     $args = array(&$data, &$event);
     $fieldsLib->trigger('onRegisterAfterSave', SOCIAL_FIELDS_GROUP_EVENT, $customFields, $args);
     $event->bindCustomFields($data);
     $fieldsLib->trigger('onRegisterAfterSaveFields', SOCIAL_FIELDS_GROUP_EVENT, $customFields, $args);
     if (empty($event->alias)) {
         $event->alias = $this->getUniqueAlias($event->getName());
         $event->save();
     }
     // @trigger: onEventAfterSave
     $triggerArgs = array(&$event, &$my, true);
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onEventAfterSave', $triggerArgs);
     return $event;
 }
Beispiel #9
0
 /**
  * Post process after the event avatar is removed
  *
  * @since   1.3
  * @access  public
  * @param   SocialEvent     The event object
  */
 public function removeAvatar(SocialEvent $event)
 {
     FD::info()->set($this->getMessage());
     $permalink = $event->getPermalink(false);
     $this->redirect($permalink);
 }
Beispiel #10
0
 /**
  * Post action after storing an event to redirect to the appropriate page according to the task.
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.3
  * @access public
  * @param  string       $task   The task action.
  * @param  SocialEvent  $event  The event object.
  */
 public function store($task, $event)
 {
     // Recurring support
     // If applies to all, we need to show a "progress update" page to update all childs through ajax.
     $applyAll = $event->hasRecurringEvents() && $this->input->getInt('applyRecurring');
     // Check if need to create recurring event
     $createRecurring = !empty($event->recurringData);
     if (!$applyAll && !$createRecurring) {
         FD::info()->set($this->getMessage());
         if ($task === 'apply') {
             $activeTab = JRequest::getWord('activeTab', 'event');
             return $this->redirect(FRoute::url(array('view' => 'events', 'layout' => 'form', 'id' => $event->id, 'activeTab' => $activeTab)));
         }
         if ($task === 'savenew') {
             return $this->redirect(FRoute::url(array('view' => 'events', 'layout' => 'form', 'category_id' => $event->category_id)));
         }
         return $this->redirect(FRoute::url(array('view' => 'events')));
     }
     $this->setHeading('COM_EASYSOCIAL_EVENTS_APPLYING_RECURRING_EVENT_CHANGES');
     $this->setDescription('COM_EASYSOCIAL_EVENTS_APPLYING_RECURRING_EVENT_CHANGES_DESCRIPTION');
     $post = JRequest::get('POST');
     $json = FD::json();
     $data = array();
     $disallowed = array(FD::token(), 'option', 'task', 'controller');
     foreach ($post as $key => $value) {
         if (in_array($key, $disallowed)) {
             continue;
         }
         if (is_array($value)) {
             $value = $json->encode($value);
         }
         $data[$key] = $value;
     }
     $string = $json->encode($data);
     $this->set('data', $string);
     $this->set('event', $event);
     $updateids = array();
     if ($applyAll) {
         $children = $event->getRecurringEvents();
         foreach ($children as $child) {
             $updateids[] = $child->id;
         }
     }
     $this->set('updateids', $json->encode($updateids));
     $schedule = array();
     if ($createRecurring) {
         // Get the recurring schedule
         $schedule = FD::model('Events')->getRecurringSchedule(array('eventStart' => $event->getEventStart(), 'end' => $event->recurringData->end, 'type' => $event->recurringData->type, 'daily' => $event->recurringData->daily));
     }
     $this->set('schedule', $json->encode($schedule));
     $this->set('task', $task);
     return parent::display('admin/events/store');
 }
Beispiel #11
0
 /**
  * Creates a new recurring event based on the post data and parent event.
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.3
  * @access public
  * @param  array        $data   The post data.
  * @param  SocialEvent  $parent The parent event object.
  * @return SocialEvent          The SocialEvent object.
  */
 public function createRecurringEvent($data, $parent)
 {
     FD::import('admin:/includes/event/event');
     $event = new SocialEvent();
     $event->creator_uid = $parent->creator_uid;
     $event->creator_type = SOCIAL_TYPE_USER;
     $event->category_id = $parent->category_id;
     $event->cluster_type = SOCIAL_TYPE_EVENT;
     $event->created = FD::date()->toSql();
     $event->parent_id = $parent->id;
     $event->parent_type = SOCIAL_TYPE_EVENT;
     $event->state = SOCIAL_CLUSTER_PUBLISHED;
     $event->key = md5(JFactory::getDate()->toSql() . FD::user()->password . uniqid());
     // Support for group event
     if (isset($data['group_id'])) {
         $group = FD::group($data['group_id']);
         $event->setMeta('group_id', $group->id);
     }
     $customFields = FD::model('Fields')->getCustomFields(array('visible' => SOCIAL_EVENT_VIEW_REGISTRATION, 'group' => SOCIAL_TYPE_EVENT, 'uid' => $parent->category_id));
     $fieldsLib = FD::fields();
     $args = array(&$data, &$event);
     $fieldsLib->trigger('onRegisterBeforeSave', SOCIAL_FIELDS_GROUP_EVENT, $customFields, $args, array($fieldsLib->getHandler(), 'beforeSave'));
     $state = $event->save();
     // Recreate the event object
     SocialEvent::$instances[$event->id] = null;
     $event = FD::event($event->id);
     // Support for group event
     if ($event->isGroupEvent()) {
         // Check for transfer flag to insert group member as event guest
         $transferMode = isset($data['member_transfer']) ? $data['member_transfer'] : 'invite';
         if (!empty($transferMode) && $transferMode != 'none') {
             $nodeState = SOCIAL_EVENT_GUEST_INVITED;
             if ($transferMode == 'attend') {
                 $nodeState = SOCIAL_EVENT_GUEST_GOING;
             }
             /*
             insert into jos_social_clusters_nodes (cluster_id, uid, type, created, state, owner, admin, invited_by)
                             select $eventId as cluster_id, uid, type, $now as created, $nodeState as state, 0 as owner, admin, $userId as invited_by from jos_social_clusters_nodes
                             where cluster_id = $groupId
                             and state = 1
                             and type = 'user'
                             and uid not in (select uid from jos_social_clusters_nodes where cluster_id = $eventId and type = 'user')
             */
             $eventId = $event->id;
             $groupId = $event->getMeta('group_id');
             $userId = $parent->creator_uid;
             $now = FD::date()->toSql();
             $query = "INSERT INTO `#__social_clusters_nodes` (`cluster_id`, `uid`, `type`, `created`, `state`, `owner`, `admin`, `invited_by`) SELECT '{$eventId}' AS `cluster_id`, `uid`, `type`, '{$now}' AS `created`, '{$nodeState}' AS `state`, '0' AS `owner`, `admin`, '{$userId}' AS `invited_by` FROM `#__social_clusters_nodes` WHERE `cluster_id` = '{$groupId}' AND `state` = '" . SOCIAL_GROUPS_MEMBER_PUBLISHED . "' AND `type` = '" . SOCIAL_TYPE_USER . "' AND `uid` NOT IN (SELECT `uid` FROM `#__social_clusters_nodes` WHERE `cluster_id` = '{$eventId}' AND `type` = '" . SOCIAL_TYPE_USER . "') AND `uid` != '{$userId}'";
             $db = FD::db();
             $sql = $db->sql();
             $sql->raw($query);
             $db->setQuery($sql);
             $db->query();
         }
     }
     // Trigger the fields again
     $args = array(&$data, &$event);
     $fieldsLib->trigger('onRegisterAfterSave', SOCIAL_FIELDS_GROUP_EVENT, $customFields, $args);
     $event->bindCustomFields($data);
     $fieldsLib->trigger('onRegisterAfterSaveFields', SOCIAL_FIELDS_GROUP_EVENT, $customFields, $args);
     if (empty($event->alias)) {
         $event->alias = $this->getUniqueAlias($event->getName());
         $event->save();
     }
     $dispatcher = FD::dispatcher();
     $my = FD::user();
     // @trigger: onEventAfterSave
     // Put the recurring events in the calendar
     $triggerArgs = array(&$event, &$my, true);
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onEventAfterSave', $triggerArgs);
     return $event;
 }