コード例 #1
0
ファイル: points.php プロジェクト: ppantilla/bbninja
 /**
  * Updates the cache copy of the user's points.
  *
  * @since	1.0
  * @access	public
  * @param	int		The user's id.
  * @param	int		The total number of points
  * @return	bool	True if success false otherwise.
  */
 public function updateUserPoints($userId, $points)
 {
     // Load user's app
     FD::apps()->load(SOCIAL_TYPE_USER);
     // Load the user
     $user = FD::user($userId);
     // Get the dispatcher
     $dispatcher = FD::dispatcher();
     // Construct the arguments to pass to the apps
     $args = array(&$user, &$points);
     // @trigger onBeforeAssignPoints
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onBeforeAssignPoints', $args);
     $user->addPoints($points);
     // @trigger onAfterAssignPoints
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onAfterAssignPoints', $args);
     return true;
 }
コード例 #2
0
ファイル: cron.php プロジェクト: ppantilla/bbninja
 /**
  * Triggers the cron service
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function execute()
 {
     $config = FD::config();
     // Check if we need a secure phrase.
     $requirePhrase = $config->get('general.cron.secure');
     $storedPhrase = $config->get('general.cron.key');
     $phrase = JRequest::getVar('phrase', '');
     if ($requirePhrase && empty($phrase) || $requirePhrase && $storedPhrase != $phrase) {
         $this->setStatus('failed');
         $this->output(JText::_('COM_EASYSOCIAL_CRONJOB_PASSPHRASE_INVALID'));
         return $this->render();
     }
     // Data to be passed to the triggers.
     $data = array();
     // Array of states
     $states = array();
     // @trigger: fields.onBeforeCronExecute
     // Retrieve custom fields for the current step
     $fieldsModel = FD::model('Fields');
     $customFields = $fieldsModel->getCustomFields(array('appgroup' => SOCIAL_TYPE_USER));
     $fields = FD::fields();
     $fields->trigger('onCronExecute', SOCIAL_TYPE_USER, $customFields, $data);
     // @trigger: apps.onBeforeCronExecute
     $apps = FD::apps();
     $dispatcher = FD::dispatcher();
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onCronExecute', $data);
     // Load up files in hooks
     $this->hook($states);
     if (!empty($states)) {
         foreach ($states as $state) {
             $this->output($state);
         }
     }
     // Perform maintenance
     $maintenance = FD::get('Maintenance');
     $maintenance->cleanup();
     $this->render();
 }
コード例 #3
0
ファイル: stream.php プロジェクト: knigherrant/decopatio
 private function getUnAccessilbleUserApps($userId = null, $group = SOCIAL_APPS_GROUP_USER)
 {
     static $_cache = array();
     if (!isset($_cache[$group])) {
         $db = FD::db();
         $sql = $db->sql();
         $apps = array();
         // if ($userId) {
         $query = "select `element` from `#__social_apps`";
         $query .= " where `type` = 'apps'";
         $query .= " and `state` = 0";
         $query .= ' and `group` = ' . $db->Quote($group);
         // $query .= " union ";
         // $query .= "select a.`element` from `#__social_apps` as a";
         // $query .= " left join `#__social_apps_map` as b on a.`id` = b.`app_id`";
         // $query .= "	and b.`type` = 'user'";
         // $query .= "	and b.`uid` = '$userId'";
         // $query .= " where a.`type` = 'apps'";
         // $query .= " and a.`group` = 'user'";
         // $query .= " and a.`default` = 0";
         // $query .= " and a.`system` = 0";
         // $query .= " and a.`state` = 1";
         // $query .= " and b.`app_id` is null";
         $sql->raw($query);
         $db->setQuery($sql);
         $results = $db->loadColumn();
         if ($results) {
             foreach ($results as $app) {
                 $apps[$app] = true;
             }
         }
         // }
         //now we need to triggers all the apps to see if there is any setting to exclude certain verb's item or not.
         $appLib = FD::getInstance('Apps');
         $appLib->load($group);
         // load user apps
         // Pass arguments by reference.
         $args = array(&$apps);
         // @trigger: onStreamVerbExclude
         $dispatcher = FD::dispatcher();
         $result = $dispatcher->trigger($group, 'onStreamVerbExclude', $args);
         $_cache[$group] = $apps;
     }
     return $_cache[$group];
 }
コード例 #4
0
ファイル: privacy.php プロジェクト: knigherrant/decopatio
 /**
  * Responsible to add / upate user privacy on an object
  *
  * @since	3.0
  * @access	public
  * @param	int		The user id.
  * @param	int 	The unique id form the object.
  * @param 	string 	The type of object.
  * @param	string	The privacy value from user.
  * @param	string	The custom user id.
  *
  */
 public function update($userId, $pid, $uId, $uType, $value, $custom = '')
 {
     // lets check if this user already has the record or not.
     // if not, we will add it here.
     // if exists, we will update the record.
     $db = FD::db();
     // check if user selected custom but there is no userids, then we do not do anything.
     if ($value == 'custom' && empty($custom)) {
         return false;
     }
     $query = 'select `id` from `#__social_privacy_items`';
     $query .= ' where `user_id` = ' . $db->Quote($userId);
     $query .= ' and `uid` = ' . $db->Quote($uId);
     $query .= ' and `type` = ' . $db->Quote($uType);
     $db->setQuery($query);
     $result = $db->loadResult();
     $privacy = FD::privacy($userId);
     $valueInInt = $privacy->toValue($value);
     $tbl = FD::table('PrivacyItems');
     if ($result) {
         // record exist. update here.
         $tbl->load($result);
         $tbl->value = $valueInInt;
     } else {
         // record not found. add new here.
         $tbl->user_id = $userId;
         $tbl->privacy_id = $pid;
         $tbl->uid = $uId;
         $tbl->type = $uType;
         $tbl->value = $valueInInt;
     }
     if (!$tbl->store()) {
         return false;
     }
     //clear the existing customized privacy data.
     $sql = FD::sql();
     $sql->delete('#__social_privacy_customize');
     $sql->where('uid', $tbl->id);
     $sql->where('utype', SOCIAL_PRIVACY_TYPE_ITEM);
     $db->setQuery($sql);
     $db->query();
     // if there is custom userids.
     if ($value == 'custom' && !empty($custom)) {
         $customList = explode(',', $custom);
         for ($i = 0; $i < count($customList); $i++) {
             $customUserId = $customList[$i];
             if (empty($customUserId)) {
                 continue;
             }
             $tblCustom = FD::table('PrivacyCustom');
             $tblCustom->uid = $tbl->id;
             $tblCustom->utype = SOCIAL_PRIVACY_TYPE_ITEM;
             $tblCustom->user_id = $customUserId;
             $tblCustom->store();
         }
     }
     // need to update the stream's ispublic flag.
     if ($uType != SOCIAL_TYPE_FIELD) {
         $context = $uType;
         $column = 'context_id';
         $updateId = $uId;
         $isPublic = $valueInInt == SOCIAL_PRIVACY_PUBLIC ? 1 : 0;
         $updateQuery = 'update #__social_stream set ispublic = ' . $db->Quote($isPublic);
         switch ($context) {
             case SOCIAL_TYPE_ACTIVITY:
                 $updateQuery .= ' where `id` = ( select `uid` from `#__social_stream_item` where `id` = ' . $db->Quote($uId) . ')';
                 break;
             case SOCIAL_TYPE_STORY:
             case SOCIAL_TYPE_LINKS:
                 $updateQuery .= ' where `id` = ' . $db->Quote($uId);
                 break;
             default:
                 $updateQuery .= ' where `id` IN ( select `uid` from `#__social_stream_item` where `context_type` = ' . $db->Quote($context) . ' and `context_id` = ' . $db->Quote($uId) . ')';
                 break;
         }
         $sql->clear();
         $sql->raw($updateQuery);
         $db->setQuery($sql);
         $db->query();
     }
     // lets trigger the onPrivacyChange event here so that apps can handle their items accordingly.
     $obj = new stdClass();
     $obj->user_id = $userId;
     $obj->privacy_id = $pid;
     $obj->uid = $uId;
     $obj->utype = $uType;
     $obj->value = $valueInInt;
     $obj->custom = $custom;
     // Get apps library.
     $apps = FD::getInstance('Apps');
     // Try to load user apps
     $state = $apps->load(SOCIAL_APPS_GROUP_USER);
     if ($state) {
         // Only go through dispatcher when there is some apps loaded, otherwise it's pointless.
         $dispatcher = FD::dispatcher();
         // Pass arguments by reference.
         $args = array($obj);
         // @trigger: onPrepareStream for the specific context
         $result = $dispatcher->trigger(SOCIAL_APPS_GROUP_USER, 'onPrivacyChange', $args, $uType);
     }
     return true;
 }
コード例 #5
0
ファイル: comments.php プロジェクト: ppantilla/bbninja
 /**
  * Function to return HTML of 1 comments block
  *
  * @since	1.0
  * @access	public
  * @param	array	$options	Various options to manipulate the comments
  *
  * @return	string	Html block of the comments
  */
 public function getHtml($options = array())
 {
     // Ensure that language file is loaded
     FD::language()->loadSite();
     // Construct mandatory options
     $options['uid'] = $this->uid;
     $options['element'] = $this->getElement();
     $options['hideEmpty'] = isset($options['hideEmpty']) ? $options['hideEmpty'] : false;
     $options['hideForm'] = isset($options['hideForm']) ? $options['hideForm'] : false;
     $options['deleteable'] = isset($options['deleteable']) ? $options['deleteable'] : false;
     if ($this->stream_id) {
         $options['stream_id'] = $this->stream_id;
     }
     // Super admins should always be able to delete comments
     $my = FD::user();
     if ($my->isSiteAdmin()) {
         $options['deleteable'] = true;
     }
     // Check view mode (with childs or not)
     if (empty($options['fullview'])) {
         $options['parentid'] = 0;
     }
     $model = FD::model('comments');
     // Get the total comments first
     $total = $model->getCommentCount($options);
     // Construct bounderies
     if (!isset($options['limit'])) {
         $options['limit'] = FD::config()->get('comments.limit', 5);
     }
     $options['start'] = max($total - $options['limit'], 0);
     // Construct ordering
     $options['order'] = 'created';
     $options['direction'] = 'asc';
     // Check if it is coming from a permalink
     $commentid = JRequest::getInt('commentid', 0);
     if ($commentid !== 0) {
         $options['commentid'] = $commentid;
         // If permalink is detected, then no limit is required
         $options['limit'] = 0;
     }
     $comments = array();
     $count = 0;
     if ($total) {
         $comments = $model->getComments($options);
         $count = count($comments);
     }
     // @trigger: onPrepareComments
     $dispatcher = FD::dispatcher();
     $args = array(&$comments);
     $dispatcher->trigger($this->group, 'onPrepareComments', $args);
     // Check for permalink
     if (!empty($options['url'])) {
         $this->options['url'] = $options['url'];
     }
     // Check for stream id
     if (!empty($options['streamid'])) {
         $this->options['streamid'] = $options['streamid'];
     } else {
         if ($this->stream_id) {
             $this->options['streamid'] = $this->stream_id;
         }
     }
     $themes = FD::themes();
     $themes->set('deleteable', $options['deleteable']);
     $themes->set('hideEmpty', $options['hideEmpty']);
     $themes->set('hideForm', $options['hideForm']);
     $themes->set('my', FD::user());
     $themes->set('element', $this->element);
     $themes->set('group', $this->group);
     $themes->set('verb', $this->verb);
     $themes->set('uid', $this->uid);
     $themes->set('total', $total);
     $themes->set('count', $count);
     $themes->set('comments', $comments);
     if (!empty($this->options['url'])) {
         $themes->set('url', $this->options['url']);
     }
     if (!empty($this->options['streamid'])) {
         $themes->set('streamid', $this->options['streamid']);
     }
     if (isset($this->options['hideForm'])) {
         $themes->set('hideForm', $this->options['hideForm']);
     }
     $html = $themes->output('site/comments/frame');
     return $html;
 }
コード例 #6
0
ファイル: profile.php プロジェクト: ppantilla/bbninja
 /**
  * Save user's information.
  *
  * @since	1.0
  * @access	public
  */
 public function save()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Ensure that the user is registered
     FD::requireLogin();
     // Clear previous session
     $session = JFactory::getSession();
     $session->clear('easysocial.profile.errors', SOCIAL_SESSION_NAMESPACE);
     // Get post data.
     $post = JRequest::get('POST');
     // Get the current view.
     $view = $this->getCurrentView();
     // Get all published fields apps that are available in the current form to perform validations
     $fieldsModel = FD::model('Fields');
     // Get current user.
     $my = FD::user();
     // Only fetch relevant fields for this user.
     $options = array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER);
     $fields = $fieldsModel->getCustomFields($options);
     // Load json library.
     $json = FD::json();
     // Initialize default registry
     $registry = FD::registry();
     // Get disallowed keys so we wont get wrong values.
     $disallowed = array(FD::token(), 'option', 'task', 'controller');
     // Process $_POST vars
     foreach ($post as $key => $value) {
         if (!in_array($key, $disallowed)) {
             if (is_array($value)) {
                 $value = $json->encode($value);
             }
             $registry->set($key, $value);
         }
     }
     // Convert the values into an array.
     $data = $registry->toArray();
     // Perform field validations here. Validation should only trigger apps that are loaded on the form
     // @trigger onRegisterValidate
     $fieldsLib = FD::fields();
     // Get the general field trigger handler
     $handler = $fieldsLib->getHandler();
     // Build arguments to be passed to the field apps.
     $args = array(&$data, &$my);
     // Ensure that there is no errors.
     // @trigger onEditValidate
     $errors = $fieldsLib->trigger('onEditValidate', SOCIAL_FIELDS_GROUP_USER, $fields, $args, array($handler, 'validate'));
     // If there are errors, we should be exiting here.
     if (is_array($errors) && count($errors) > 0) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
         // We need to set the proper vars here so that the es-wrapper contains appropriate class
         JRequest::setVar('view', 'profile', 'POST');
         JRequest::setVar('layout', 'edit', 'POST');
         // We need to set the data into the post again because onEditValidate might have changed the data structure
         JRequest::set($data, 'post');
         return $view->call('edit', $errors, $data);
     }
     // @trigger onEditBeforeSave
     $errors = $fieldsLib->trigger('onEditBeforeSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args, array($handler, 'beforeSave'));
     if (is_array($errors) && count($errors) > 0) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_ERRORS_IN_FORM'), SOCIAL_MSG_ERROR);
         // We need to set the proper vars here so that the es-wrapper contains appropriate class
         JRequest::setVar('view', 'profile');
         JRequest::setVar('layout', 'edit');
         // We need to set the data into the post again because onEditValidate might have changed the data structure
         JRequest::set($data, 'post');
         return $view->call('edit', $errors);
     }
     // Bind the my object with appropriate data.
     $my->bind($data);
     // Save the user object.
     $my->save();
     // Reconstruct args
     $args = array(&$data, &$my);
     // @trigger onEditAfterSave
     $fieldsLib->trigger('onEditAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     // Bind custom fields for the user.
     $my->bindCustomFields($data);
     // Reconstruct args
     $args = array(&$data, &$my);
     // @trigger onEditAfterSaveFields
     $fieldsLib->trigger('onEditAfterSaveFields', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     // Now we update the Facebook details if it is available
     $associatedFacebook = $this->input->get('associatedFacebook', 0, 'int');
     if (!empty($associatedFacebook)) {
         $facebookPull = $this->input->get('oauth_facebook_pull', null, 'default');
         $facebookPush = $this->input->get('oauth_facebook_push', null, 'default');
         $my = FD::user();
         $facebookTable = $my->getOAuth(SOCIAL_TYPE_FACEBOOK);
         if ($facebookTable) {
             $facebookTable->pull = $facebookPull;
             $facebookTable->push = $facebookPush;
             $facebookTable->store();
         }
     }
     // Add stream item to notify the world that this user updated their profile.
     $my->addStream('updateProfile');
     // Update indexer
     $my->syncIndex();
     // @points: profile.update
     // Assign points to the user when their profile is updated
     $points = FD::points();
     $points->assign('profile.update', 'com_easysocial', $my->id);
     // Prepare the dispatcher
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $args = array(&$user, &$fields, &$data);
     // @trigger: onUserProfileUpdate
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onUserProfileUpdate', $args);
     // @trigger onProfileCompleteCheck
     // This should return an array of booleans to state which field is filled in.
     // We count the returned result since it will be an array of trues that marks the field that have data for profile completeness checking.
     // We do this after all the data has been saved, and we reget the fields from the model again.
     // We also need to reset the cached field data
     SocialTableField::$_fielddata = array();
     $fields = $fieldsModel->getCustomFields(array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER));
     $args = array(&$my);
     $completedFields = $fieldsLib->trigger('onProfileCompleteCheck', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     $table = FD::table('Users');
     $table->load(array('user_id' => $my->id));
     $table->completed_fields = count($completedFields);
     $table->store();
     $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_ACCOUNT_UPDATED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS);
     return $view->call(__FUNCTION__, $my);
 }
コード例 #7
0
ファイル: avatar.php プロジェクト: BetterBetterBetter/B3App
 /**
  * Creates the necessary images to be used as an avatar.
  *
  * @since	1.0
  * @access	public
  * @param	SocialTablePhoto	The photo table
  * @param 	array 				options - createStream
  * @return
  */
 public function store(SocialTablePhoto &$photo, $options = array())
 {
     // setup the options.
     $createStream = isset($options['addstream']) ? $options['addstream'] : true;
     // default to true.
     // Check if there's a profile photos album that already exists.
     $model = FD::model('Albums');
     // Create default album if necessary
     $album = $model->getDefaultAlbum($this->uid, $this->type, SOCIAL_ALBUM_PROFILE_PHOTOS);
     // Load avatar table
     $avatarTable = FD::table('Avatar');
     $exists = $avatarTable->load(array('uid' => $this->uid, 'type' => $this->type));
     // Cleanup previous avatars only if they exist.
     if ($exists) {
         $this->cleanup($avatarTable);
     }
     // Create the images
     $this->create($avatarTable, $options);
     // Set the avatar composite indices.
     $avatarTable->uid = $this->uid;
     $avatarTable->type = $this->type;
     // Link the avatar to the photo
     $avatarTable->photo_id = $photo->id;
     // Unlink the avatar from gallery item
     $avatarTable->avatar_id = 0;
     // Set the last modified time to now.
     $avatarTable->modified = FD::date()->toMySQL();
     // We need to always reset the avatar back to "joomla"
     $avatarTable->storage = SOCIAL_STORAGE_JOOMLA;
     // Store the avatar now
     $avatarTable->store();
     // @points: profile.avatar.update
     // Assign points to the current user for uploading their avatar
     $photo->assignPoints('profile.avatar.update', $this->uid);
     // @Add stream item when a new profile avatar is uploaded
     if ($createStream) {
         $photo->addPhotosStream('uploadAvatar');
     }
     // Once the photo is finalized as the profile picture we need to update the state
     $photo->state = SOCIAL_STATE_PUBLISHED;
     // If album doesn't have a cover, set the current photo as the cover.
     if (!$album->hasCover()) {
         $album->cover_id = $photo->id;
         // Store the album
         $album->store();
     }
     // Prepare the dispatcher
     FD::apps()->load($this->type);
     if ($this->type == SOCIAL_TYPE_USER) {
         $node = FD::user($this->uid);
     } else {
         $node = FD::group($this->uid);
     }
     $args = array(&$photo, $node);
     $dispatcher = FD::dispatcher();
     // @trigger: onUserAvatarUpdate
     $dispatcher->trigger($this->type, 'onAvatarBeforeSave', $args);
     // Once it is created, store the photo as we need to update
     $state = $photo->store();
     // @trigger: onUserAvatarUpdate
     $dispatcher->trigger($this->type, 'onAvatarAfterSave', $args);
     return $state;
 }
コード例 #8
0
ファイル: events.php プロジェクト: BetterBetterBetter/B3App
 public function onBeforeStorySave(&$template, &$stream, &$content)
 {
     $params = $this->getParams();
     // Determine if we should attach ourselves here.
     if (!$params->get('story_event', true)) {
         return;
     }
     $in = FD::input();
     $title = $in->getString('event_title');
     $description = $in->getString('event_description');
     $categoryid = $in->getInt('event_category');
     $start = $in->getString('event_start');
     $end = $in->getString('event_end');
     $timezone = $in->getString('event_timezone');
     // If no category id, then we don't proceed
     if (empty($categoryid)) {
         return;
     }
     // Perhaps in the future we use FD::model('Event')->createEvent() instead.
     // For now just hardcode it here to prevent field triggering and figuring out how to punch data into the respective field data because the form is not rendered through field trigger.
     $my = FD::user();
     $event = FD::event();
     $event->title = $title;
     $event->description = $description;
     // Set a default params for this event first
     $event->params = '{"photo":{"albums":true},"news":true,"discussions":true,"allownotgoingguest":false,"allowmaybe":true,"guestlimit":0}';
     $event->type = SOCIAL_EVENT_TYPE_PUBLIC;
     $event->creator_uid = $my->id;
     $event->creator_type = SOCIAL_TYPE_USER;
     $event->category_id = $categoryid;
     $event->cluster_type = SOCIAL_TYPE_EVENT;
     $event->alias = FD::model('Events')->getUniqueAlias($title);
     $event->created = FD::date()->toSql();
     $event->key = md5($event->created . $my->password . uniqid());
     $event->state = SOCIAL_CLUSTER_PENDING;
     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();
     // Notifies admin when a new event is created
     if ($event->state === SOCIAL_CLUSTER_PENDING || !$my->isSiteAdmin()) {
         FD::model('Events')->notifyAdmins($event);
     }
     // Set the meta for start end timezone
     $meta = $event->meta;
     $meta->cluster_id = $event->id;
     $meta->start = FD::date($start)->toSql();
     $meta->end = FD::date($end)->toSql();
     $meta->timezone = $timezone;
     $meta->store();
     // Recreate the event object
     $event = FD::event($event->id);
     // Create a new owner object
     $event->createOwner($my->id);
     // @trigger: onEventAfterSave
     $triggerArgs = array(&$event, &$my, true);
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onEventAfterSave', $triggerArgs);
     // Due to inconsistency, we don't use SOCIAL_TYPE_EVENT.
     // Instead we use "events" because app elements are named with 's', namely users, groups, events.
     $template->context_type = 'events';
     $template->context_id = $event->id;
     $template->cluster_access = $event->type;
     $template->cluster_type = $event->cluster_type;
     $template->cluster_id = $event->id;
     $params = array('event' => $event);
     $template->setParams(FD::json()->encode($params));
 }
コード例 #9
0
ファイル: users.php プロジェクト: knigherrant/decopatio
 /**
  * Stores the user object
  *
  * @since	1.0
  * @access	public
  */
 public function store()
 {
     // Check for request forgeries
     FD::checkToken();
     // Load front end's language file
     FD::language()->loadSite();
     // Get the current task
     $task = $this->getTask();
     // Determine if this is an edited user.
     $id = $this->input->get('id', 0, 'int');
     $id = !$id ? null : $id;
     // Get the posted data
     $post = $this->input->getArray('post');
     // this should come from backend user management page only.
     $autoApproval = isset($post['autoapproval']) ? $post['autoapproval'] : 0;
     // Create an options array for custom fields
     $options = array();
     if (!$id) {
         $user = new SocialUser();
         // Get the profile id
         $profileId = $this->input->get('profileId');
     } else {
         // Here we assume that the user record already exists.
         $user = FD::user($id);
         // Get the profile id from the user
         $profileId = $user->getProfile()->id;
         $options['data'] = true;
         $options['dataId'] = $id;
         $options['dataType'] = SOCIAL_TYPE_USER;
     }
     // Set the profile id
     $options['profile_id'] = $profileId;
     // Set the group
     $options['group'] = SOCIAL_FIELDS_GROUP_USER;
     // Load the profile
     $profile = FD::table('Profile');
     $profile->load($profileId);
     // Set the visibility
     // since this is at backend so we assume admin is editing someone else.
     if (!$id) {
         $options['visible'] = SOCIAL_PROFILES_VIEW_REGISTRATION;
     }
     // Get fields model
     $fieldsModel = ES::model('Fields');
     // Get the custom fields
     $fields = $fieldsModel->getCustomFields($options);
     // Initialize default registry
     $registry = ES::registry();
     // Get disallowed keys so we wont get wrong values.
     $disallowed = array(ES::token(), 'option', 'task', 'controller', 'autoapproval');
     // Process $_POST vars
     foreach ($post as $key => $value) {
         if (!in_array($key, $disallowed)) {
             if (is_array($value)) {
                 $value = json_encode($value);
             }
             $registry->set($key, $value);
         }
     }
     // Test to see if the points has changed.
     $points = $this->input->get('points', 0, 'int');
     // Lets get the difference of the points
     $userPoints = $user->getPoints();
     // If there is a difference, the admin may have altered the user points
     if ($userPoints != $points) {
         // Insert a new points record for this new adjustments.
         if ($points > $userPoints) {
             // If the result points is larger, we always need to subtract and get the balance.
             $totalPoints = $points - $userPoints;
         } else {
             // If the result points is smaller, we always need to subtract.
             $totalPoints = -($userPoints - $points);
         }
         $pointsLib = FD::points();
         $pointsLib->assignCustom($user->id, $totalPoints, JText::_('COM_EASYSOCIAL_POINTS_ADJUSTMENTS'));
         $user->points = $points;
     }
     // Convert the values into an array.
     $data = $registry->toArray();
     // Get the fields lib
     $fieldsLib = FD::fields();
     // Build arguments to be passed to the field apps.
     $args = array(&$data, &$user);
     // @trigger onAdminEditValidate
     $errors = $fieldsLib->trigger('onAdminEditValidate', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     // If there are errors, we should be exiting here.
     if (is_array($errors) && count($errors) > 0) {
         $this->view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
         // We need to set the data into the post again because onEditValidate might have changed the data structure
         JRequest::set($data, 'post');
         return $this->view->call('form', $errors);
     }
     // @trigger onAdminEditBeforeSave
     $errors = $fieldsLib->trigger('onAdminEditBeforeSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     if (is_array($errors) && count($errors) > 0) {
         $this->view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_ERRORS_IN_FORM'), SOCIAL_MSG_ERROR);
         // We need to set the data into the post again because onEditValidate might have changed the data structure
         JRequest::set($data, 'post');
         return $this->view->call('form', $errors);
     }
     // Update the user's gid
     $gid = $this->input->get('gid', array(), 'array');
     $data['gid'] = $gid;
     // Bind the user object with the form data.
     $user->bind($data);
     // Create a new user record if the id don't exist yet.
     if (!$id) {
         $model = ES::model('Users');
         $user = $model->create($data, $user, $profile);
         if (!$user) {
             $this->view->setMessage($model->getError(), SOCIAL_MSG_ERROR);
             // We need to set the data into the post again because onEditValidate might have changed the data structure
             JRequest::set($data, 'post');
             return $this->view->call('form');
         }
         // If admin selected auto approval, automatically approve this user.
         if ($autoApproval) {
             $user->approve(false);
         }
         $message = $autoApproval ? JText::_('COM_EASYSOCIAL_USERS_CREATED_SUCCESSFULLY_AND_APPROVED') : JText::_('COM_EASYSOCIAL_USERS_CREATED_SUCCESSFULLY');
     } else {
         // If this was an edited user, save the user object.
         $user->save();
         $message = JText::_('COM_EASYSOCIAL_USERS_USER_UPDATED_SUCCESSFULLY');
     }
     // Reconstruct args
     $args = array(&$data, &$user);
     // @trigger onEditAfterSave
     $fieldsLib->trigger('onAdminEditAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     // Bind the custom fields for the user.
     $user->bindCustomFields($data);
     // Reconstruct args
     $args = array(&$data, &$user);
     // @trigger onEditAfterSaveFields
     $fieldsLib->trigger('onAdminEditAfterSaveFields', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     // Prepare the dispatcher
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $args = array(&$user, &$fields, &$data);
     // @trigger: onUserProfileUpdate
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onUserProfileUpdate', $args);
     // Process notifications
     if (isset($post['notifications']) && !empty($post['notifications'])) {
         $systemNotifications = $post['notifications']['system'];
         $emailNotifications = $post['notifications']['email'];
         // Store the notification settings for this user.
         $model = ES::model('Notifications');
         $model->saveNotifications($systemNotifications, $emailNotifications, $user);
     }
     // Process privacy items
     if (isset($post['privacy']) && !empty($post['privacy'])) {
         $resetPrivacy = isset($post['privacyReset']) ? true : false;
         $user->bindPrivacy($post['privacy'], $post['privacyID'], $post['privacyCustom'], $post['privacyOld'], $resetPrivacy);
     }
     $this->view->setMessage($message, SOCIAL_MSG_SUCCESS);
     return $this->view->call(__FUNCTION__, $task, $user);
 }
コード例 #10
0
ファイル: likes.php プロジェクト: knigherrant/decopatio
 public function delete($pk = null)
 {
     $state = parent::delete();
     if ($state) {
         // Get dispatcher library
         $dispatcher = FD::dispatcher();
         $args = array(&$this);
         $group = SOCIAL_APPS_GROUP_USER;
         $dispatcher->trigger($group, 'onAfterLikeDelete', $args);
     }
     return $state;
 }
コード例 #11
0
ファイル: group.php プロジェクト: knigherrant/decopatio
 /**
  * Approves the user application
  *
  * @since	1.2
  * @access	public
  * @param	int		The user id
  * @return
  */
 public function approveUser($userId)
 {
     $member = FD::table('GroupMember');
     $member->load(array('cluster_id' => $this->id, 'uid' => $userId));
     $member->state = SOCIAL_GROUPS_MEMBER_PUBLISHED;
     $state = $member->store();
     // Additional triggers to be processed when the page starts.
     FD::apps()->load(SOCIAL_TYPE_GROUP);
     $dispatcher = FD::dispatcher();
     // Trigger: onComponentStart
     $dispatcher->trigger('user', 'onJoinGroup', array($userId, $this));
     // @points: groups.join
     // Add points when user joins a group
     $points = FD::points();
     $points->assign('groups.join', 'com_easysocial', $userId);
     // Publish on the stream
     if ($state) {
         // Add stream item so the world knows that the user joined the group
         $this->createStream($userId, 'join');
     }
     // Notify the user that his request to join the group has been approved
     $this->notifyMembers('approved', array('targets' => array($userId)));
     // Send notifications to group members when a new member joined the group
     $this->notifyMembers('join', array('userId' => $userId));
     return $state;
 }
コード例 #12
0
ファイル: apps.php プロジェクト: knigherrant/decopatio
 /**
  * Responsible to attach the application into the SocialDispatcher object.
  * In short, it does the requiring of files here.
  *
  * @since	1.0
  * @access	private
  * @param	SocialTableApp	The application ORM.
  * @return	bool
  *
  * @author	Mark Lee <*****@*****.**>
  */
 private function loadApp(SocialTableApp &$app)
 {
     static $loadedApps = array();
     // Application type and element should always be in lowercase.
     $group = strtolower($app->group);
     $element = strtolower($app->element);
     if (!isset($loadedApps[$group][$element])) {
         // Get dispatcher object.
         $dispatcher = FD::dispatcher();
         // Application trigger file paths.
         $filePath = SOCIAL_APPS . '/' . $group . '/' . $element . '/' . $element . '.php';
         $fileExists = JFile::exists($filePath);
         // If file doesn't exist, skip the entire block.
         if (!$fileExists) {
             $loadedApps[$group][$element] = false;
             return $loadedApps[$group][$element];
         }
         // Assuming that the file exists here (It should)
         require_once $filePath;
         $className = 'Social' . ucfirst($group) . 'App' . ucfirst($element);
         // If the class doesn't exist in this context,
         // the application might be using a different class. Ignore this.
         if (!class_exists($className)) {
             $loadedApps[$group][$element] = false;
             return $loadedApps[$group][$element];
         }
         $appObj = new $className();
         $appObj->group = $group;
         $appObj->element = $app->element;
         self::$cachedApps[$group][$element] = $appObj;
         // Attach the application into the observer list.
         $dispatcher->attach($group, $app->element, $appObj);
         // Add a state for this because we know it has already been loaded.
         $loadedApps[$group][$element] = true;
     }
     return $loadedApps[$group][$element];
 }
コード例 #13
0
ファイル: events.php プロジェクト: ppantilla/bbninja
 /**
  * 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;
 }
コード例 #14
0
ファイル: notification.php プロジェクト: ppantilla/bbninja
 /**
  * Retrieves a list of notification items.
  *
  * @since	1.0
  * @access	public
  * @param	bool	To aggregate the notification items or not.
  * @return	Array	An array of @SocialTableNotification
  */
 public function getItems($options = array())
 {
     $model = FD::model('Notifications');
     $items = $model->getItems($options);
     if (!$items) {
         return false;
     }
     // Retrieve applications and trigger onNotificationLoad
     $dispatcher = FD::dispatcher();
     // Trigger apps
     foreach ($items as $item) {
         // Add a `since` column to the result so that user's could use the `since` time format.
         $item->since = FD::date($item->created)->toLapsed();
         $args = array(&$item);
         // @trigger onNotificationLoad
         $dispatcher->trigger(SOCIAL_APPS_GROUP_USER, 'onNotificationLoad', $args);
         // @trigger onNotificationLoad
         $dispatcher->trigger(SOCIAL_APPS_GROUP_GROUP, 'onNotificationLoad', $args);
         // @trigger onNotificationLoad
         $dispatcher->trigger(SOCIAL_APPS_GROUP_EVENT, 'onNotificationLoad', $args);
         // Let's format the item title.
         $this->formatItem($item);
     }
     // Group up items.
     if (isset($options['group']) && $options['group'] == SOCIAL_NOTIFICATION_GROUP_ITEMS) {
         $items = $this->group($items);
     }
     return $items;
 }
コード例 #15
0
ファイル: eventguest.php プロジェクト: knigherrant/decopatio
 /**
  * Performs trigger when user responds to an event.
  *
  * @since   1.3
  * @access  public
  * @param   string
  * @return
  */
 public function triggerResponse($method)
 {
     // Perform event trigger for this action
     // @onEventGuestResponse
     FD::apps()->load('user');
     $user = FD::user($this->uid);
     $args = array($method, &$user);
     $dispatcher = FD::dispatcher();
     $dispatcher->trigger('user', 'onEventGuestResponse', $args);
 }
コード例 #16
0
ファイル: comments.php プロジェクト: yalive/com_api-plugins
 public function post()
 {
     $app = JFactory::getApplication();
     $element = $app->input->get('element', '', 'string');
     $group = $app->input->get('group', '', 'string');
     $verb = $app->input->get('verb', '', 'string');
     $uid = $app->input->get('uid', 0, 'int');
     //element id
     $input = $app->input->get('comment', "", 'RAW');
     $params = $app->input->get('params', array(), 'ARRAY');
     //params
     $streamid = $app->input->get('stream_id', '', 'INT');
     //whole stream id
     $parent = $app->input->get('parent', 0, 'INT');
     //parent comment id
     $result = new stdClass();
     $valid = 1;
     if (!$uid) {
         $result->id = 0;
         $result->status = 0;
         $result->message = 'Empty element id not allowed';
         $valid = 0;
     }
     // Message should not be empty.
     if (empty($input)) {
         $result->id = 0;
         $result->status = 0;
         $result->message = 'Empty comment not allowed';
         $valid = 0;
     } else {
         if ($valid) {
             // Normalize CRLF (\r\n) to just LF (\n)
             $input = str_ireplace("\r\n", "\n", $input);
             $compositeElement = $element . '.' . $group . '.' . $verb;
             $table = FD::table('comments');
             $table->element = $compositeElement;
             $table->uid = $uid;
             $table->comment = $input;
             $table->created_by = FD::user()->id;
             $table->created = FD::date()->toSQL();
             $table->parent = $parent;
             $table->params = $params;
             $table->stream_id = $streamid;
             $state = $table->store();
             if ($streamid) {
                 $doUpdate = true;
                 if ($element == 'photos') {
                     $sModel = FD::model('Stream');
                     $totalItem = $sModel->getStreamItemsCount($streamid);
                     if ($totalItem > 1) {
                         $doUpdate = false;
                     }
                 }
                 if ($doUpdate) {
                     $stream = FD::stream();
                     $stream->updateModified($streamid, FD::user()->id, SOCIAL_STREAM_LAST_ACTION_COMMENT);
                 }
             }
             if ($state) {
                 $dispatcher = FD::dispatcher();
                 $comments = array(&$table);
                 $args = array(&$comments);
                 // @trigger: onPrepareComments
                 $dispatcher->trigger($group, 'onPrepareComments', $args);
                 //create result obj
                 $result->status = 1;
                 $result->message = 'comment saved successfully';
             } else {
                 //create result obj
                 $result->status = 0;
                 $result->message = 'Unable to save comment';
             }
         }
     }
     $this->plugin->setResponse($result);
 }
コード例 #17
0
ファイル: comments.php プロジェクト: knigherrant/decopatio
 public function delete()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Only registered users are allowed here.
     FD::requireLogin();
     // Get the view
     $view = FD::view('comments', false);
     // Check for permission first
     $access = FD::access();
     // Get the comment id
     $id = JRequest::getInt('id', 0);
     // Get the current logged in user
     $my = FD::user();
     // Load the comment object
     $table = FD::table('comments');
     $state = $table->load($id);
     if (!$state) {
         $view->setMessage($table->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // There are cases where the app may need to allow the user to delete the comments.
     $apps = FD::apps();
     $apps->load(SOCIAL_TYPE_USER);
     $args = array(&$table, &$my);
     $dispatcher = FD::dispatcher();
     $allowed = $dispatcher->trigger(SOCIAL_TYPE_USER, 'canDeleteComment', $args);
     if ($my->isSiteAdmin() || $access->allowed('comments.delete') || $table->isAuthor() && $access->allowed('comments.deleteown') || in_array(true, $allowed)) {
         $state = $table->delete();
         if (!$state) {
             $view->setMessage($table->getError(), SOCIAL_MSG_ERROR);
         }
     } else {
         $view->setMessage(JText::_('COM_EASYSOCIAL_COMMENTS_NOT_ALLOWED_TO_DELETE'), SOCIAL_MSG_ERROR);
     }
     return $view->call(__FUNCTION__);
 }
コード例 #18
0
ファイル: comments.php プロジェクト: knigherrant/decopatio
 public function like()
 {
     $dispatcher = FD::dispatcher();
     $likesLib = FD::likes($this->id, 'comments', 'like', SOCIAL_APPS_GROUP_USER);
     $hasLiked = $likesLib->hasLiked();
     $likesTable = FD::table('likes');
     $likesTable->load(array('type' => 'comments.user.like', 'uid' => $this->id));
     $beforeTrigger = $hasLiked ? 'onBeforeUnlikeComment' : 'onBeforeLikeComment';
     $dispatcher->trigger(SOCIAL_APPS_GROUP_USER, $beforeTrigger, array($this->element, $this->uid, $this, $likesTable));
     $state = $likesLib->toggle();
     if (!$state) {
         return false;
     }
     $afterTrigger = $hasLiked ? 'onAfterUnlikeComment' : 'onAfterLikeComment';
     $dispatcher->trigger(SOCIAL_APPS_GROUP_USER, $afterTrigger, array($this->element, $this->uid, $this, $likesTable));
     // Moved to story app where story app collectively handle for all like comments notification.
     // The app should render this
     // if (!$hasLiked && $this->created_by != FD::user()->id) {
     //  $emailOptions = array(
     //      'title'     => JText::sprintf('COM_EASYSOCIAL_COMMENTS_LIKE_EMAIL_TITLE', FD::user()->getName()),
     //      'template'  => 'site/comments/new.comment.like',
     //      'params'    => array(
     //          'actor'         => FD::user()->getName(),
     //          'posterName'    => FD::user()->getName(),
     //          'comment'       => $this->comment
     //      )
     //  );
     //  $systemOptions = array(
     //      'uid'       => $this->id,
     //      'actor_id'  => FD::user()->id,
     //      'type'      => 'comments',
     //      'url'       => $this->getParams()->get('url', ''),
     //      'title'     => JText::_('COM_EASYSOCIAL_COMMENTS_LIKE_SYSTEM_TITLE')
     //  );
     //  FD::notify('comments.like', array($this->created_by), $emailOptions, $systemOptions);
     // }
     return $likesLib;
 }
コード例 #19
0
ファイル: page.php プロジェクト: BetterBetterBetter/B3App
 /**
  * This is the starting point of the page library.
  *
  * @access	public
  * @param	null
  * @return 	null
  */
 public function start()
 {
     // Trigger profiler's start
     if ($this->config->get('general.profiler')) {
         FD::profiler()->start();
     }
     // Additional triggers to be processed when the page starts.
     $dispatcher = FD::dispatcher();
     // Trigger: onComponentStart
     $dispatcher->trigger('user', 'onComponentStart', array());
     // Run initialization codes for javascript side of things.
     $this->init();
 }
コード例 #20
0
ファイル: view.html.php プロジェクト: knigherrant/decopatio
 /**
  * When a conversation is marked as read.
  *
  * @since	1.0
  * @access	public
  * @param	null
  */
 public function read()
 {
     // Prevent unauthorized access.
     FD::requireLogin();
     // Check for user profile completeness
     FD::checkCompleteProfile();
     // Get the conversation id
     $id = $this->input->get('id', 0, 'int');
     $conversation = FD::table('Conversation');
     $loaded = $conversation->load($id);
     // Check if the conversation id provided is valid.
     if (!$id || !$loaded) {
         $this->info->set(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_INVALID_ID'), SOCIAL_MSG_ERROR);
         $url = FRoute::conversations(array(), false);
         return $this->redirect($url);
     }
     // Check if the user has access to read this discussion.
     if (!$conversation->isReadable($this->my->id)) {
         $this->info->set(JText::_('COM_EASYSOCIAL_CONVERSATIONS_NOT_ALLOWED_TO_READ'), SOCIAL_MSG_ERROR);
         $url = FRoute::conversations(array(), false);
         return $this->redirect($url);
     }
     // Retrieve conversations model.
     $model = FD::model('Conversations');
     // Always reset the limistart to 0 so that when the page refresh, system will not get the 'previous' saved limitstart.
     $model->setState('limitstart', 0);
     // Get list of files in this conversation
     $filesModel = FD::model('Files');
     // Get a list of all the message ids from this conversation.
     $files = $filesModel->getFiles($model->getMessageIds($conversation->id), SOCIAL_TYPE_CONVERSATIONS);
     // Get a list of participants for this particular conversation except myself.
     $participants = $model->getParticipants($conversation->id);
     // this flag is to indicate if there is only one participant and the participant is a ESAD.
     $isESADuser = false;
     if (count($participants) == 2) {
         foreach ($participants as $pUser) {
             if ($pUser->id != $this->my->id && !$pUser->hasCommunityAccess()) {
                 $isESADuser = true;
             }
         }
     }
     // Fetch a list of messages for this particular conversation
     $messages = $model->setLimit($this->themeConfig->get('messages_limit'))->getMessages($conversation->id, $this->my->id);
     // Beautify the names
     $participantNames = FD::string()->namesToStream($participants, false, 3, false);
     $title = JText::sprintf('COM_EASYSOCIAL_PAGE_TITLE_CONVERSATIONS_READ', $participantNames);
     // Set title
     FD::page()->title($title);
     // Set breadcrumbs
     FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_CONVERSATIONS_INBOX'), FRoute::conversations());
     FD::page()->breadcrumb($title);
     // @trigger: onPrepareConversations
     $dispatcher = FD::dispatcher();
     $args = array(&$messages);
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onPrepareConversations', $args);
     // Get pagination
     $pagination = $model->getPagination();
     // Determine if load previous messages should appear.
     $loadPrevious = $pagination->total > $pagination->limit;
     // Mark conversation as read because the viewer is already reading the conversation.
     $conversation->markAsRead($this->my->id);
     // Get total number of messages sent today
     $totalSentDaily = $model->getTotalSentDaily($this->my->id);
     // @points: conversation.read
     // Assign points when user reads a conversation
     $points = FD::points();
     $points->assign('conversation.read', 'com_easysocial', $this->my->id);
     $this->set('files', $files);
     $this->set('totalSentDaily', $totalSentDaily);
     $this->set('loadPrevious', $loadPrevious);
     $this->set('conversation', $conversation);
     $this->set('participants', $participants);
     $this->set('messages', $messages);
     $this->set('pagination', $pagination);
     $this->set('isESADuser', $isESADuser);
     echo parent::display('site/conversations/read');
 }
コード例 #21
0
 public function createAvatar($value, $uid, $createStream = true, $deleteImage = true)
 {
     $value = FD::makeObject($value);
     if (!empty($value->data)) {
         $value->data = FD::makeObject($value->data);
     }
     if ($value->type === 'remove') {
         $table = FD::table('avatar');
         $state = $table->load(array('uid' => $uid, 'type' => $this->group));
         if ($state) {
             $table->delete();
             if ($this->group == SOCIAL_TYPE_USER) {
                 $user = FD::user($uid);
                 // Prepare the dispatcher
                 FD::apps()->load(SOCIAL_TYPE_USER);
                 $dispatcher = FD::dispatcher();
                 $args = array(&$user, &$table);
                 // @trigger: onUserAvatarRemove
                 $dispatcher->trigger(SOCIAL_TYPE_USER, 'onUserAvatarRemove', $args);
             }
         }
         return true;
     }
     if ($value->type === 'gallery') {
         $table = FD::table('avatar');
         $state = $table->load(array('uid' => $uid, 'type' => $this->group));
         if (!$state) {
             $table->uid = $uid;
             $table->type = $this->group;
         }
         $table->avatar_id = $value->source;
         $table->store();
         return true;
     }
     if ($value->type === 'upload') {
         $data = new stdClass();
         if (!empty($value->path)) {
             $image = FD::image();
             $image->load($value->path);
             $avatar = FD::avatar($image, $uid, $this->group);
             // Check if there's a profile photos album that already exists.
             $albumModel = FD::model('Albums');
             // Retrieve the user's default album
             $album = $albumModel->getDefaultAlbum($uid, $this->group, SOCIAL_ALBUM_PROFILE_PHOTOS);
             $photo = FD::table('Photo');
             $photo->uid = $uid;
             $photo->type = $this->group;
             $photo->user_id = $this->group == SOCIAL_TYPE_USER ? $uid : FD::user()->id;
             $photo->album_id = $album->id;
             $photo->title = $value->name;
             $photo->caption = '';
             $photo->ordering = 0;
             // We need to set the photo state to "SOCIAL_PHOTOS_STATE_TMP"
             $photo->state = SOCIAL_PHOTOS_STATE_TMP;
             // Try to store the photo first
             $state = $photo->store();
             if (!$state) {
                 $this->setError(JText::_('PLG_FIELDS_AVATAR_ERROR_CREATING_PHOTO_OBJECT'));
                 return false;
             }
             // Push all the ordering of the photo down
             $photosModel = FD::model('photos');
             $photosModel->pushPhotosOrdering($album->id, $photo->id);
             // If album doesn't have a cover, set the current photo as the cover.
             if (!$album->hasCover()) {
                 $album->cover_id = $photo->id;
                 // Store the album
                 $album->store();
             }
             // Get the photos library
             $photoLib = FD::get('Photos', $image);
             $storage = $photoLib->getStoragePath($album->id, $photo->id);
             $paths = $photoLib->create($storage);
             // Create metadata about the photos
             foreach ($paths as $type => $fileName) {
                 $meta = FD::table('PhotoMeta');
                 $meta->photo_id = $photo->id;
                 $meta->group = SOCIAL_PHOTOS_META_PATH;
                 $meta->property = $type;
                 $meta->value = $storage . '/' . $fileName;
                 $meta->store();
             }
             // Synchronize Indexer
             $indexer = FD::get('Indexer');
             $template = $indexer->getTemplate();
             $template->setContent($photo->title, $photo->caption);
             //$url 	= FRoute::photos(array('layout' => 'item', 'id' => $photo->getAlias()));
             $url = $photo->getPermalink();
             $url = '/' . ltrim($url, '/');
             $url = str_replace('/administrator/', '/', $url);
             $template->setSource($photo->id, SOCIAL_INDEXER_TYPE_PHOTOS, $photo->uid, $url);
             $template->setThumbnail($photo->getSource('thumbnail'));
             $indexer->index($template);
             // Crop the image to follow the avatar format. Get the dimensions from the request.
             if (!empty($value->data) && is_object($value->data)) {
                 $width = $value->data->width;
                 $height = $value->data->height;
                 $top = $value->data->top;
                 $left = $value->data->left;
                 $avatar->crop($top, $left, $width, $height);
             }
             $options = array();
             // Create the avatars now
             if (!$createStream) {
                 $options = array('addstream' => false);
             }
             $options['deleteimage'] = false;
             $avatar->store($photo, $options);
         }
         return true;
     }
 }
コード例 #22
0
ファイル: user.php プロジェクト: ppantilla/bbninja
 /**
  * Allows caller to remove the user's avatar
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function removeAvatar()
 {
     $avatar = FD::table('Avatar');
     $state = $avatar->load(array('uid' => $this->id, 'type' => SOCIAL_TYPE_USER));
     if ($state) {
         $state = $avatar->delete();
         // Prepare the dispatcher
         FD::apps()->load(SOCIAL_TYPE_USER);
         $dispatcher = FD::dispatcher();
         $args = array(&$this, &$avatar);
         // @trigger: onUserAvatarRemove
         $dispatcher->trigger(SOCIAL_TYPE_USER, 'onUserAvatarRemove', $args);
     }
     return $state;
 }
コード例 #23
0
 private function triggerBeforeGetStream(&$options)
 {
     if (!$options) {
         return;
     }
     $view = JRequest::getCmd('view', '');
     // Get apps library.
     $apps = FD::getInstance('Apps');
     // Determine the app group
     $group = SOCIAL_APPS_GROUP_USER;
     // If it is in the group view we should render the apps based on the appropriate group
     if ($view && ($view == 'groups' || $view == 'events' || $view == 'stream') && (isset($options['clusterType']) && $options['clusterType'])) {
         $group = $options['clusterType'];
     }
     // Try to load user apps
     $state = $apps->load($group);
     // By default return true.
     $result = true;
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'STREAMS: No applications loaded.');
         return false;
     }
     // Only go through dispatcher when there is some apps loaded, otherwise it's pointless.
     $dispatcher = FD::dispatcher();
     // Pass arguments by reference.
     $args = array(&$options, $view);
     $dispatcher->trigger($group, 'onBeforeGetStream', $args);
 }
コード例 #24
0
ファイル: friends.php プロジェクト: ppantilla/bbninja
 /**
  * Allows caller to make a friend request from source to target
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return
  */
 public function request($sourceId, $targetId, $state = SOCIAL_FRIENDS_STATE_PENDING)
 {
     // Do not allow user to create a friend request to himself
     if ($sourceId == $targetId) {
         $this->setError(JText::_('COM_EASYSOCIAL_FRIENDS_UNABLE_TO_ADD_YOURSELF'));
         return false;
     }
     // If they are already friends, ignore this.
     if ($this->isFriends($sourceId, $targetId)) {
         $this->setError(JText::_('COM_EASYSOCIAL_FRIENDS_ERROR_ALREADY_FRIENDS'));
         return false;
     }
     // Check if user has already previously requested this.
     if ($this->isFriends($sourceId, $targetId, SOCIAL_FRIENDS_STATE_PENDING)) {
         $this->setError(JText::_('COM_EASYSOCIAL_FRIENDS_ERROR_ALREADY_REQUESTED'));
         return false;
     }
     // If everything is okay, we proceed to add this request to the friend table.
     $table = FD::table('Friend');
     $table->setActorId($sourceId);
     $table->setTargetId($targetId);
     $table->setState($state);
     // Save the request
     $state = $table->store();
     $my = FD::user($sourceId);
     $user = FD::user($targetId);
     // Prepare the dispatcher
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $args = array(&$table, $my, $user);
     // @trigger: onFriendRequest
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onFriendRequest', $args);
     // Send notification to the target when a user requests to be his / her friend.
     $params = array('requesterId' => $my->id, 'requesterAvatar' => $my->getAvatar(SOCIAL_AVATAR_LARGE), 'requesterName' => $my->getName(), 'requesterLink' => $my->getPermalink(true, true), 'requestDate' => FD::date()->toMySQL(), 'totalFriends' => $my->getTotalFriends(), 'totalMutualFriends' => $my->getTotalMutualFriends($user->id));
     // Email template
     $emailOptions = array('actor' => $my->getName(), 'title' => 'COM_EASYSOCIAL_EMAILS_FRIENDS_NEW_REQUEST_SUBJECT', 'template' => 'site/friends/request', 'params' => $params);
     FD::notify('friends.request', array($user->id), $emailOptions, false);
     // @badge: friends.create
     // Assign badge for the person that initiated the friend request.
     $badge = FD::badges();
     $badge->log('com_easysocial', 'friends.create', $my->id, JText::_('COM_EASYSOCIAL_FRIENDS_BADGE_REQUEST_TO_BE_FRIEND'));
     return $table;
 }
コード例 #25
0
ファイル: story.php プロジェクト: ppantilla/bbninja
 /**
  * Trigger to prepare the story item before being output.
  *
  * @since	1.0
  * @access	public
  */
 public function prepare()
 {
     // Load up the necessary apps
     FD::apps()->load($this->type);
     // Pass arguments by reference.
     $args = array(&$this);
     // Only go through dispatcher when there is some apps loaded, otherwise it's pointless.
     $dispatcher = FD::dispatcher();
     // StoryAttachment service
     $panels = $dispatcher->trigger($this->type, 'onPrepareStoryPanel', $args);
     if ($panels) {
         foreach ($panels as $panel) {
             if ($panel instanceof SocialStoryPanel) {
                 $this->panels[] = $panel;
                 $this->plugins[] = $panel;
             }
         }
     }
     return true;
 }
コード例 #26
0
ファイル: event.php プロジェクト: ppantilla/bbninja
 /**
  * Logics for deleting an event
  *
  * @since   1.3
  * @access  public
  * @return  boolean True if successful.
  */
 public function delete()
 {
     // @trigger onBeforeDelete
     $dispatcher = FD::dispatcher();
     // @points: groups.remove
     // Deduct points when a group is deleted
     FD::points()->assign('events.remove', 'com_easysocial', $this->getCreator()->id);
     // Set the arguments
     $args = array(&$this);
     // @trigger onBeforeStorySave
     $dispatcher->trigger(SOCIAL_TYPE_EVENT, 'onBeforeDelete', $args);
     // Delete any relations from the calendar table
     $this->deleteFromCalendar();
     // Delete all members from the cluster nodes.
     $this->deleteNodes();
     // Delete custom fields data for this cluster.
     $this->deleteCustomFields();
     // Delete photos albums for this cluster.
     $this->deletePhotoAlbums();
     // Delete stream items for this group
     $this->deleteStream();
     // Delete all group news
     $this->deleteNews();
     // delete all user notification associated with this group.
     $this->deleteNotifications();
     // Delete from the cluster
     $state = parent::delete();
     $args[] = $state;
     // @trigger onAfterDelete
     $dispatcher->trigger(SOCIAL_TYPE_EVENT, 'onAfterDelete', $args);
     return $state;
 }
コード例 #27
0
ファイル: easysocial.php プロジェクト: knigherrant/decopatio
 /**
  * Performs various clean ups when a user is deleted
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function onUserBeforeDelete($user)
 {
     // Include main file.
     jimport('joomla.filesystem.file');
     $path = JPATH_ROOT . '/administrator/components/com_easysocial/includes/foundry.php';
     if (!JFile::exists($path)) {
         return false;
     }
     // Include the foundry engine
     require_once $path;
     // Check if Foundry exists
     if (!FD::exists()) {
         FD::language()->loadSite();
         echo JText::_('COM_EASYSOCIAL_FOUNDRY_DEPENDENCY_MISSING');
         return;
     }
     $model = FD::model('Users');
     $state = $model->delete($user['id']);
     // Internal Trigger for onUserBeforeDelete
     $dispatcher = FD::dispatcher();
     $args = array(&$user);
     $dispatcher->trigger(SOCIAL_APPS_GROUP_USER, __FUNCTION__, $args);
     return true;
 }
コード例 #28
0
 /**
  * Removes a friend
  *
  * @since	1.0
  * @access	public
  */
 public function unfriend()
 {
     // Check for request forgeries
     FD::checkToken();
     // User needs to be logged in.
     FD::requireLogin();
     // Get the current view.
     $view = $this->getCurrentView();
     // Get the target user that will be removed.
     $id = JRequest::getInt('id');
     // Get the current user.
     $my = FD::user();
     // Try to load up the friend table
     $friend = FD::table('Friend');
     $state = $friend->load($id);
     if (!$state || !$id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Need to ensure that the target or source of the friend belongs to the current user.
     if ($friend->actor_id != $my->id && $friend->target_id != $my->id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_ERROR_NOT_YOUR_FRIEND'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Throw errors when there's a problem removing the friends
     if (!$friend->unfriend($my->id)) {
         $view->setMessage($friend->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Prepare the dispatcher
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $args = array(&$friend);
     // @trigger: onFriendRemoved
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onFriendRemoved', $args);
     return $view->call(__FUNCTION__);
 }
コード例 #29
0
ファイル: story.php プロジェクト: knigherrant/decopatio
 /**
  * Prepares the activity log for user's actions
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function onPrepareActivityLog(SocialStreamItem &$stream, $includePrivacy = true)
 {
     if ($stream->context != 'story') {
         return;
     }
     // Stories wouldn't be aggregated
     $actor = $stream->actor;
     $target = count($stream->targets) > 0 ? $stream->targets[0] : '';
     $stream->display = SOCIAL_STREAM_DISPLAY_MINI;
     // @triggers: onPrepareStoryContent
     // Processes any apps to process the content.
     FD::apps()->load(SOCIAL_TYPE_USER);
     $args = array(&$story, &$stream);
     $dispatcher = FD::dispatcher();
     $result = $dispatcher->trigger(SOCIAL_TYPE_USER, 'onPrepareStoryContent', $args);
     $this->set('actor', $actor);
     $this->set('target', $target);
     $this->set('stream', $stream);
     $this->set('result', $result);
     $stream->title = parent::display('logs/title.' . $stream->verb);
     $stream->content = parent::display('logs/content.' . $stream->verb);
     if ($includePrivacy) {
         $my = FD::user();
         // only activiy log can use stream->uid directly bcos now the uid is holding id from social_stream_item.id;
         $stream->privacy = FD::privacy($my->id)->form($stream->uid, SOCIAL_TYPE_STORY, $stream->actor->id, 'story.view', false, $stream->aggregatedItems[0]->uid);
     }
     return true;
 }
コード例 #30
0
ファイル: indexer.php プロジェクト: knigherrant/decopatio
 /**
  * perform item reindexing
  *
  * @since	1.0
  * @access	public
  */
 public function reindex()
 {
     // $coreType = array( 'users', 'photos', 'lists', 'albums', 'groups');
     $coreType = array(SOCIAL_INDEXER_TYPE_USERS, SOCIAL_INDEXER_TYPE_PHOTOS, SOCIAL_INDEXER_TYPE_LISTS, SOCIAL_INDEXER_TYPE_ALBUMS, SOCIAL_INDEXER_TYPE_GROUPS);
     //$coreType = array( 'photos');
     $model = FD::model('indexer');
     $total = 0;
     foreach ($coreType as $type) {
         $result = $model->getIndexingItem($type);
         if ($result->count) {
             $items = $result->data;
             if (count($items) > 0) {
                 foreach ($items as $item) {
                     if ($type == SOCIAL_INDEXER_TYPE_USERS) {
                         $user = FD::user($item->uid);
                         $user->syncIndex();
                     } else {
                         $url = '';
                         $thumbnail = '';
                         switch ($type) {
                             case SOCIAL_INDEXER_TYPE_ALBUMS:
                                 $album = FD::table('Album');
                                 $album->load($item->uid);
                                 $creator = FD::user($album->uid);
                                 $userAlias = $creator->getAlias();
                                 //$url 		= FRoute::albums( array( 'id' => $album->getAlias() , 'userid' => $userAlias , 'layout' => 'item' ) );
                                 $url = $album->getPermalink();
                                 $url = $this->removeAdminSegment($url);
                                 if ($album->cover_id) {
                                     $photo = FD::table('Photo');
                                     $photo->load($album->cover_id);
                                     $thumbnail = $photo->getSource('thumbnail');
                                 }
                                 break;
                             case SOCIAL_INDEXER_TYPE_PHOTOS:
                                 $photo = FD::table('Photo');
                                 $photo->load($item->uid);
                                 // $url 		= FRoute::photos( array( 'layout' => 'item', 'id' => $photo->getAlias() ) );
                                 $url = $photo->getPermalink();
                                 $url = $this->removeAdminSegment($url);
                                 $thumbnail = $photo->getSource('thumbnail');
                                 break;
                             case SOCIAL_INDEXER_TYPE_LISTS:
                                 $url = FRoute::friends(array('listid' => $item->uid));
                                 $url = $this->removeAdminSegment($url);
                                 break;
                             case SOCIAL_INDEXER_TYPE_GROUPS:
                                 $group = FD::group($item->uid);
                                 $url = $group->getPermalink();
                                 $url = $this->removeAdminSegment($url);
                                 $thumbnail = $group->getAvatar(SOCIAL_AVATAR_SQUARE);
                                 break;
                             case 'users':
                             default:
                                 break;
                         }
                         $tmpl = $this->getTemplate();
                         $tmpl->setContent($item->title, $item->content);
                         $tmpl->setSource($item->uid, $item->utype, $item->creatorid, $url);
                         if ($thumbnail) {
                             $tmpl->setThumbnail($thumbnail);
                         }
                         $this->index($tmpl);
                     }
                 }
                 //end foreach
             }
             //if count(items)
         }
         $total = $total + $result->count;
     }
     // now we need to trigger
     $indexerCount = 0;
     $dispatcher = FD::dispatcher();
     $args = array(&$indexerCount);
     // @trigger: onIndexerReIndex
     $dispatcher->trigger(SOCIAL_APPS_GROUP_USER, 'onIndexerReIndex', $args);
     $total = $total + $indexerCount;
     return $total;
 }