public function create_report() { $app = JFactory::getApplication(); $msg = $app->input->get('message', '', 'STRING'); $title = $app->input->get('user_title', '', 'STRING'); $item_id = $app->input->get('itemId', 0, 'INT'); $log_user = $this->plugin->get('user')->id; $data = array(); $data['message'] = $msg; $data['uid'] = $item_id; $data['type'] = 'stream'; $data['title'] = $title; $data['extension'] = 'com_easysocial'; //build share url use for share post through app $sharing = FD::get('Sharing', array('url' => FRoute::stream(array('layout' => 'item', 'id' => $item_id, 'external' => true, 'xhtml' => true)), 'display' => 'dialog', 'text' => JText::_('COM_EASYSOCIAL_STREAM_SOCIAL'), 'css' => 'fd-small')); $url = $sharing->url; $data['url'] = $url; // Get the reports model $model = FD::model('Reports'); // Determine if this user has the permissions to submit reports. $access = FD::access(); // Determine if this user has exceeded the number of reports that they can submit $total = $model->getCount(array('created_by' => $log_user)); if ($access->exceeded('reports.limit', $total)) { $final_result['message'] = "Limit exceeds"; $final_result['status'] = true; return $final_result; } // Create the report $report = FD::table('Report'); $report->bind($data); // Set the creator id. $report->created_by = $log_user; // Set the default state of the report to new $report->state = 0; // Try to store the report. $state = $report->store(); // If there's an error, throw it if (!$state) { $final_result['message'] = "Can't save report"; $final_result['status'] = true; return $final_result; } // @badge: reports.create // Add badge for the author when a report is created. $badge = FD::badges(); $badge->log('com_easysocial', 'reports.create', $log_user, JText::_('COM_EASYSOCIAL_REPORTS_BADGE_CREATED_REPORT')); // @points: reports.create // Add points for the author when a report is created. $points = FD::points(); $points->assign('reports.create', 'com_easysocial', $log_user); // Determine if we should send an email $config = FD::config(); if ($config->get('reports.notifications.moderators')) { $report->notify(); } $final_result['message'] = "Report logged successfully!"; $final_result['status'] = true; return $final_result; }
/** * Deletes reports * * @since 1.0 * @access public */ public function remove() { // Check for request forgeries FD::checkToken(); // Get the current view. $view = $this->getCurrentView(); // Get the id from the request $ids = JRequest::getVar('cid'); // If the user is deleting with the checkbox, find similar reports $model = FD::model('Reports'); foreach ($ids as $id) { $tmpReport = FD::table('Report'); $tmpReport->load($id); // Load all related reports $reports = $model->getReporters($tmpReport->extension, $tmpReport->uid, $tmpReport->type); foreach ($reports as $report) { $report->delete(); // @points: reports.delete // Deduct points from the author when their report is deleted. $points = FD::points(); $points->assign('reports.delete', 'com_easysocial', $report->created_by); } } $view->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_REPORT_ITEM_HAS_BEEN_DELETED'), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__); }
/** * 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); }
/** * Submits a reply * * @since 1.2 * @access public * @return */ public function submit() { // Check for request forgeriess FD::checkToken(); // Ensure that the user is logged in. FD::requireLogin(); // Load up ajax lib $ajax = FD::ajax(); // Get the group $groupId = JRequest::getInt('groupId'); $group = FD::group($groupId); // Get the discussion $id = JRequest::getInt('id'); $discussion = FD::table('Discussion'); $discussion->load($id); // Get the current user $my = FD::user(); // Check whether the viewer can really reply to the discussion if (!$group->isMember()) { return $this->reject(); } // Test for locked discussion. if ($discussion->lock && !$group->isAdmin()) { $obj = new stdClass(); $obj->message = JText::_('APP_GROUP_DISCUSSIONS_DISCUSSION_IS_LOCKED'); $obj->type = SOCIAL_MSG_ERROR; return $ajax->reject($obj); } // Get the content // $content = JRequest::getVar( 'content' , '' ); $content = JRequest::getVar('content', '', 'post', 'none', JREQUEST_ALLOWRAW); if (empty($content)) { $obj = new stdClass(); $obj->message = JText::_('APP_GROUP_DISCUSSIONS_EMPTY_REPLY_ERROR'); $obj->type = SOCIAL_MSG_ERROR; return $ajax->reject($obj); } $reply = FD::table('Discussion'); $reply->uid = $discussion->uid; $reply->type = $discussion->type; $reply->content = $content; $reply->created_by = $my->id; $reply->parent_id = $discussion->id; $reply->state = SOCIAL_STATE_PUBLISHED; // Save the reply. $reply->store(); if (!$id) { // @points: groups.discussion.reply // Earn points when posting a reply $points = FD::points(); $points->assign('groups.discussion.reply', 'com_easysocial', $reply->created_by); } // Create a new stream item for this discussion $stream = FD::stream(); // Get the stream template $tpl = $stream->getTemplate(); // Someone just joined the group $tpl->setActor($my->id, SOCIAL_TYPE_USER); // Set the context $tpl->setContext($discussion->id, 'discussions'); // Set the cluster $tpl->setCluster($group->id, SOCIAL_TYPE_GROUP, $group->type); // Set the verb $tpl->setVerb('reply'); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $group); $registry->set('reply', $reply); $registry->set('discussion', $discussion); $tpl->setParams($registry); $tpl->setAccess('core.view'); // Add the stream $stream->add($tpl); // Update the parent's reply counter. $discussion->sync($reply); // Before we populate the output, we need to format it according to the theme's specs. $reply->author = $my; // Load the contents $theme = FD::themes(); // Since this reply is new, we don't have an answer for this item. $answer = false; $theme->set('question', $discussion); $theme->set('group', $group); $theme->set('answer', $answer); $theme->set('reply', $reply); $contents = $theme->output('apps/group/discussions/canvas/item.reply'); // Send notification to group members $options = array(); $options['permalink'] = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $this->getApp()->getAlias(), 'discussionId' => $discussion->id, 'external' => true), false); $options['title'] = $discussion->title; $options['content'] = $reply->getContent(); $options['discussionId'] = $reply->id; $options['userId'] = $reply->created_by; $options['targets'] = $discussion->getParticipants(array($reply->created_by)); $group->notifyMembers('discussion.reply', $options); return $ajax->resolve($contents); }
/** * Creates a new discussion * * @since 1.2 * @access public * @param string * @return */ public function save() { // Check for request forgeriess FD::checkToken(); // Ensure that the user is logged in. FD::requireLogin(); // Load up ajax lib $ajax = FD::ajax(); // Load the discussion $id = JRequest::getInt('id'); $discussion = FD::table('Discussion'); $discussion->load($id); // Get the current logged in user. $my = FD::user(); // Get the group $groupId = JRequest::getInt('cluster_id', 0); $group = FD::group($groupId); // Only allow owner and admin to modify the if ($discussion->id) { if ($discussion->created_by != $my->id && !$group->isAdmin() && !$my->isSiteAdmin()) { return $this->redirect($group->getPermalink(false)); } } // Check if the user is allowed to create a discussion if (!$group->isMember()) { FD::info()->set(JText::_('APP_GROUP_DISCUSSIONS_NOT_ALLOWED_CREATE'), SOCIAL_MSG_ERROR); // Perform a redirection return JFactory::getApplication()->redirect(FRoute::dashboard()); } // Assign discussion properties $discussion->uid = $group->id; $discussion->type = SOCIAL_TYPE_GROUP; $discussion->title = JRequest::getVar('title', ''); $discussion->content = JRequest::getVar('content', '', 'POST', 'none', JREQUEST_ALLOWRAW); // If discussion is edited, we don't want to modify the following items if (!$discussion->id) { $discussion->created_by = $my->id; $discussion->parent_id = 0; $discussion->hits = 0; $discussion->state = SOCIAL_STATE_PUBLISHED; $discussion->votes = 0; $discussion->lock = false; } $app = $this->getApp(); // Ensure that the title is valid if (!$discussion->title) { Foundry::info()->set(JText::_('APP_GROUP_DISCUSSIONS_INVALID_TITLE'), SOCIAL_MSG_ERROR); // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'create', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias()), false); return $this->redirect($url); } // Lock the discussion $state = $discussion->store(); if (!$state) { FD::info()->set(JText::_('APP_GROUP_DISCUSSIONS_DISCUSSION_CREATED_FAILED')); // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'form', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias()), false); return $this->redirect($url); } // Process any files that needs to be created. $discussion->mapFiles(); // Get the app $app = $this->getApp(); // If it is a new discussion, we want to run some other stuffs here. if (!$id) { // @points: groups.discussion.create // Add points to the user that updated the group $points = FD::points(); $points->assign('groups.discussion.create', 'com_easysocial', $my->id); // Create a new stream item for this discussion $stream = FD::stream(); // Get the stream template $tpl = $stream->getTemplate(); // Someone just joined the group $tpl->setActor($my->id, SOCIAL_TYPE_USER); // Set the context $tpl->setContext($discussion->id, 'discussions'); // Set the cluster $tpl->setCluster($group->id, SOCIAL_TYPE_GROUP, $group->type); // Set the verb $tpl->setVerb('create'); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $group); $registry->set('discussion', $discussion); $tpl->setParams($registry); $tpl->setAccess('core.view'); // Add the stream $stream->add($tpl); // Set info message FD::info()->set(false, JText::_('APP_GROUP_DISCUSSIONS_DISCUSSION_CREATED_SUCCESS'), SOCIAL_MSG_SUCCESS); // Send notification to group members only if it is new discussion $options = array(); $options['permalink'] = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias(), 'discussionId' => $discussion->id, 'external' => true), false); $options['discussionId'] = $discussion->id; $options['discussionTitle'] = $discussion->title; $options['discussionContent'] = $discussion->getContent(); $options['userId'] = $discussion->created_by; $group->notifyMembers('discussion.create', $options); } // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $group->getAlias(), 'type' => SOCIAL_TYPE_GROUP, 'id' => $app->getAlias(), 'discussionId' => $discussion->id), false); // Perform a redirection $this->redirect($url); }
/** * Allows a user to unfollow an object. * * @since 1.0 * @access public */ public function unfollow() { // Check for request forgeries. FD::checkToken(); // Ensure that the user needs to be logged in. FD::requireLogin(); // Get current logged in user. $my = FD::user(); // Get the current view. $view = $this->getCurrentView(); // Get the object identifier. $id = JRequest::getInt('id'); // Get the target that is being unfollowed $user = FD::user($id); $type = JRequest::getVar('type'); $group = JRequest::getVar('group', SOCIAL_APPS_GROUP_USER); $subscribe = FD::get('Subscriptions'); $state = $subscribe->unfollow($id, $type, $group, $my->id); if (!$state) { $view->setMessage('COM_EASYSOCIAL_UNFOLLOW_ERROR', SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // @points: profile.unfollow // Assign points when user starts new conversation $points = FD::points(); $points->assign('profile.unfollow', 'com_easysocial', $my->id); // @points: profile.unfollowed // Assign points when user starts new conversation $points->assign('profile.unfollowed', 'com_easysocial', $user->id); return $view->call(__FUNCTION__); }
public function post() { $app = JFactory::getApplication(); //$share_for = $app->input->get('share_for','','CMD'); $type = $app->input->get('type', 'story', 'STRING'); $content = $app->input->get('content', '', 'RAW'); //$targetId = $app->input->get('target_user','All','raw'); $targetId = $app->input->get('target_user', 0, 'INT'); $cluster = $app->input->get('cluster_id', null, 'INT'); $clusterType = $app->input->get('cluster_type', null, 'STRING'); $friends_tags = $app->input->get('friends_tags', null, 'ARRAY'); $log_usr = intval($this->plugin->get('user')->id); //now take login user stream for target $targetId = $targetId != $log_usr ? $targetId : $log_usr; $valid = 1; $result = new stdClass(); $story = FD::story(SOCIAL_TYPE_USER); // Check whether the user can really post something on the target if ($targetId) { $tuser = FD::user($targetId); $allowed = $tuser->getPrivacy()->validate('profiles.post.status', $targetId, SOCIAL_TYPE_USER); if (!$allowed) { $result->id = 0; $result->status = 0; $result->message = 'User not allowed any post in share'; $valid = 0; } } if (empty($type)) { $result->id = 0; $result->status = 0; $result->message = 'Empty type not allowed'; $valid = 0; } else { if ($valid) { // Determines if the current posting is for a cluster $cluster = isset($cluster) ? $cluster : 0; //$clusterType = ($cluster) ? 'group' : null; $isCluster = $cluster ? true : false; if ($isCluster) { $group = FD::group($cluster); $permissions = $group->getParams()->get('stream_permissions', null); if ($permissions != null) { // If the user is not an admin, ensure that permissions has member if ($group->isMember() && !in_array('member', $permissions) && !$group->isOwner() && !$group->isAdmin()) { $result->message = 'This group memder do not have share data permission'; } // If the user is an admin, ensure that permissions has admin if ($group->isAdmin() && !in_array('admin', $permissions) && !$group->isOwner()) { $result->message = 'This group admin do not have share data permission'; } $result->id = 0; $result->status = 0; $this->plugin->setResponse($result); return; } } //validate friends $friends = array(); if (!empty($friends_tags)) { // Get the friends model $model = FD::model('Friends'); // Check if the user is really a friend of him / her. foreach ($friends_tags as $id) { if (!$model->isFriends($log_usr, $id)) { continue; } $friends[] = $id; } } else { $friends = null; } $privacyRule = $type == 'photos' ? 'photos.view' : 'story.view'; //for hashtag mentions $mentions = null; //if($type == 'hashtag' || !empty($content)) if (!empty($content)) { //$type = 'story'; $start = 0; $posn = array(); //code adjust for 0 position hashtag $content = 'a ' . $content; while ($pos = strpos($content, '#', $start)) { //echo 'Found # at position '.$pos."\n"; $posn[] = $pos - 2; $start = $pos + 1; } $content = substr($content, 2); // //$pos = strpos(($content),'#',$start); $cont_arr = explode(' ', $content); $indx = 0; foreach ($cont_arr as $val) { if (preg_match('/[\'^#,|=_+¬-]/', $val)) { //$vsl = substr_count($val,'#'); $val_arr = array_filter(explode('#', $val)); foreach ($val_arr as $subval) { $subval = '#' . $subval; $mention = new stdClass(); $mention->start = $posn[$indx++]; $mention->length = strlen($subval) - 0; $mention->value = str_replace('#', '', $subval); $mention->type = 'hashtag'; $mentions[] = $mention; } } } //print_r( $mentions );die("in share api"); } $contextIds = 0; if ($type == 'photos') { $photo_obj = $this->uploadPhoto($log_usr, 'user'); $photo_ids[] = $photo_obj->id; $contextIds = count($photo_ids) ? $photo_ids : null; } else { $type = 'story'; } // Process moods here $mood = FD::table('Mood'); // Options that should be sent to the stream lib $args = array('content' => $content, 'actorId' => $log_usr, 'targetId' => $targetId, 'location' => null, 'with' => $friends, 'mentions' => $mentions, 'cluster' => $cluster, 'clusterType' => $clusterType, 'mood' => null, 'privacyRule' => $privacyRule, 'privacyValue' => 'public', 'privacyCustom' => ''); $photo_ids = array(); $args['actorId'] = $log_usr; $args['contextIds'] = $contextIds; $args['contextType'] = $type; // Create the stream item $stream = $story->create($args); // Privacy is only applicable to normal postings if (!$isCluster) { $privacyLib = FD::privacy(); if ($type == 'photos') { $photoIds = FD::makeArray($contextIds); foreach ($photoIds as $photoId) { $privacyLib->add($privacyRule, $photoId, $type, 'public', null, ''); } } else { $privacyLib->add($privacyRule, $stream->uid, $type, 'public', null, ''); } } // Add badge for the author when a report is created. $badge = FD::badges(); $badge->log('com_easysocial', 'story.create', $log_usr, JText::_('Posted a new update')); // @points: story.create // Add points for the author when a report is created. $points = FD::points(); $points->assign('story.create', 'com_easysocial', $log_usr); if ($stream->id) { $result->id = $stream->id; $result->status = 1; $result->message = 'data share successfully'; } } } $this->plugin->setResponse($result); }
/** * Assign points * * @since 1.0 * @access public * @param string * @return */ private function assignPoints($command, $userId = null) { if (is_null($userId)) { $userId = FD::user()->id; } return FD::points()->assign($command, 'com_content', $userId); }
/** * This is the registration API for modules. We allow modules to allow quick registration * * @since 1.2 * @access public * @param string * @return */ public function quickRegister() { // Get the current view $view = $this->getCurrentView(); // Get current user's session $session = JFactory::getSession(); // Get necessary info about the current registration process. $registration = FD::table('Registration'); $registration->load($session->getId()); // Get a new registry object $params = FD::get('Registry'); if (!empty($registration->values)) { $params->load($registration->values); } // The profile id is definitely required otherwise we will skip this. $profileId = $registration->profile_id; if (empty($profileId)) { $view->setMessage(JText::_('COM_EASYSOCIAL_REGISTRATIONS_MODULE_PROFILE_TYPE_REQUIRED'), SOCIAL_MSG_ERROR); return $view->call('selectProfile'); } $data = $params->toArray(); // Trigger onRegisterValidate first // Get the fields $fieldsModel = FD::model('Fields'); $fields = $fieldsModel->getCustomFields(array('profile_id' => $profileId, 'visible' => SOCIAL_PROFILES_VIEW_MINI_REGISTRATION)); $fieldsLib = FD::fields(); // Get the trigger handler $handler = $fieldsLib->getHandler(); $args = array(&$data, &$registration); // Get error messages $errors = $fieldsLib->trigger('onRegisterMiniValidate', SOCIAL_FIELDS_GROUP_USER, $fields, $args); $registration->setErrors($errors); // The values needs to be stored in a JSON notation. $registration->values = FD::json()->encode($data); // Store registration into the temporary table. $registration->store(); // Saving was intercepted by one of the field applications. if (is_array($errors) && count($errors) > 0) { $view->setMessage(JText::_('COM_EASYSOCIAL_REGISTRATION_FORM_ERROR_PROCEED_WITH_REGISTRATION'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Load up the registration model $model = FD::model('Registration'); $user = $model->createUser($registration); if (!$user) { $view->setMessage($model->getError(), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Redirection will be dependent on the profile type's registration behavior. // If the profile type is auto login, we need to log the user in $profile = FD::table('Profile'); $profile->load($profileId); // Force unset on the user first to reload the user object SocialUser::$userInstances[$user->id] = null; // Get the current registered user data. $my = FD::user($user->id); // We need to send the user an email with their password $my->password_clear = $user->password_clear; // Send notification to admin if necessary. if ($profile->getParams()->get('email.moderators', true)) { $model->notifyAdmins($data, $my, $profile); } // If everything goes through fine, we need to send notification emails out now. $model->notify($data, $my, $profile); // add new registered user into indexer $my->syncIndex(); // We need to log the user in after they have successfully registered. if ($profile->getRegistrationType() == 'auto') { // @points: user.register // Assign points when user registers on the site. $points = FD::points(); $points->assign('user.registration', 'com_easysocial', $my->id); // @badge: registration.create // Assign badge for the person that initiated the friend request. $badge = FD::badges(); $badge->log('com_easysocial', 'registration.create', $my->id, JText::_('COM_EASYSOCIAL_REGISTRATION_BADGE_REGISTERED')); // Get configuration object. $config = FD::config(); // Add activity logging when a uer registers on the site. if ($config->get('registrations.stream.create')) { $stream = FD::stream(); $streamTemplate = $stream->getTemplate(); // Set the actor $streamTemplate->setActor($my->id, SOCIAL_TYPE_USER); // Set the context $streamTemplate->setContext($my->id, SOCIAL_TYPE_PROFILES); // Set the verb $streamTemplate->setVerb('register'); $streamTemplate->setSiteWide(); $streamTemplate->setAccess('core.view'); // Add stream template. $stream->add($streamTemplate); } $app = JFactory::getApplication(); $credentials = array('username' => $my->username, 'password' => $my->password_clear); // Try to log the user in $app->login($credentials); // TODO: Trigger the apps to check if fields are complete // If not complete then we call view to redirect this user to the edit profile page // $view->setMessage(JText::_('COM_EASYSOCIAL_REGISTRATIONS_COMPLETE_REGISTRATION'), SOCIAL_MSG_INFO); } // Store the user's custom fields data now. return $view->complete($my, $profile); }
/** * Approves a user's registration application * * @since 1.0 * @access public * @param string * @return */ public function approve($sendEmail = true) { // Check if the user already approved or not. if ($this->block == 0 && $this->state == SOCIAL_USER_STATE_ENABLED) { //already approved. return true; } // Update the JUser object. $this->block = 0; // Update the current state property. $this->state = SOCIAL_USER_STATE_ENABLED; // If set to admin approve, user should be activated regardless of whether user activates or not. $this->activation = 0; // Store the block status $this->save(); // Activity logging. // Announce to the world when a new user registered on the site. $config = FD::config(); // Get the application params $app = FD::table('App'); $options = array('element' => 'profiles', 'group' => SOCIAL_TYPE_USER); $app->load($options); $params = $app->getParams(); // If not allowed, we will not want to proceed here. if ($params->get('stream_register', true)) { $stream = FD::stream(); // Get stream template $streamTemplate = $stream->getTemplate(); // Set the actors. $streamTemplate->setActor($this->id, SOCIAL_TYPE_USER); // Set the context for the stream. $streamTemplate->setContext($this->id, SOCIAL_TYPE_PROFILES); // Set the verb for this action as this is some sort of identifier. $streamTemplate->setVerb('register'); $streamTemplate->setSiteWide(); $streamTemplate->setAccess('core.view'); // Add the stream item. $stream->add($streamTemplate); } // add user into com_finder index $this->syncIndex(); // @points: user.register // Assign points when user registers on the site. $points = FD::points(); $points->assign('user.registration', 'com_easysocial', $this->id); // @badge: registration.create // Assign badge for the person that initiated the friend request. $badge = FD::badges(); $badge->log('com_easysocial', 'registration.create', $this->id, JText::_('COM_EASYSOCIAL_REGISTRATION_BADGE_REGISTERED')); // If we need to send email to the user, we need to process this here. if ($sendEmail) { // Get the application data. $jConfig = FD::jConfig(); // Get the current profile this user has registered on. $profile = $this->getProfile(); // Push arguments to template variables so users can use these arguments $params = array('site' => $jConfig->getValue('sitename'), 'username' => $this->username, 'name' => $this->getName(), 'avatar' => $this->getAvatar(SOCIAL_AVATAR_LARGE), 'email' => $this->email, 'profileType' => $profile->get('title'), 'manageAlerts' => false); JFactory::getLanguage()->load('com_easysocial', JPATH_ROOT); // Get the email title. $title = JText::_('COM_EASYSOCIAL_EMAILS_REGISTRATION_APPLICATION_APPROVED'); // Immediately send out emails $mailer = FD::mailer(); $mailTemplate = $mailer->getTemplate(); $mailTemplate->setTitle($title); $mailTemplate->setRecipient($this->getName(), $this->email); $mailTemplate->setTemplate('site/registration/approved', $params); $mailTemplate->setLanguage($this->getLanguage()); // Set the priority. We need it to be sent out immediately since this is user registrations. $mailTemplate->setPriority(SOCIAL_MAILER_PRIORITY_IMMEDIATE); // Try to send out email now. $mailer->create($mailTemplate); } return true; }
/** * Allows the caller to uninstall the app from the user. * * @since 1.0 * @access public * @param string * @return */ public function uninstallUserApp($userId = null) { $config = FD::config(); $user = FD::user($userId); $userId = $user->id; // Delete user mapping $map = FD::table('appsmap'); $map->load(array('app_id' => $this->id, 'uid' => $userId)); $state = $map->delete(); // Give points to the author when uninstalling apps if ($state) { $points = FD::points(); $points->assign('apps.uninstall', 'com_easysocial', $userId); } // Delete any stream that's related to the user installing this app $stream = FD::stream(); $stream->delete($this->id, SOCIAL_TYPE_APPS, $userId); return $state; }
/** * Allows caller to response to invitation * * @since 1.2 * @access public */ public function respondInvitation() { $email = JRequest::getVar('email', ''); if (!$email) { // Check for request forgeries FD::checkToken(); } // Only registered users are allowed to do this FD::requireLogin(); // Get the current view $view = $this->getCurrentView(); // Get the current user $my = FD::user(); // Get the group $id = JRequest::getInt('id'); $group = FD::group($id); if (!$id || !$group) { $view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } $member = FD::table('GroupMember'); $member->load(array('cluster_id' => $group->id, 'uid' => $my->id)); if (!$member->id) { $view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_NOT_INVITED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Get the response action $action = JRequest::getWord('action'); // If user rejected, just delete the invitation record. if ($action == 'reject') { $member->delete(); $message = JText::sprintf('COM_EASYSOCIAL_GROUPS_REJECT_RESPONSE_SUCCESS', $group->getName()); } if ($action == 'accept') { $member->state = SOCIAL_GROUPS_MEMBER_PUBLISHED; $member->store(); // Create stream when user accepts the invitation $group->createStream($my->id, 'join'); // @points: groups.join // Add points when user joins a group $points = FD::points(); $points->assign('groups.join', 'com_easysocial', $my->id); // Notify members when a new member is added $group->notifyMembers('join', array('userId' => $my->id)); $message = JText::sprintf('COM_EASYSOCIAL_GROUPS_ACCEPT_RESPONSE_SUCCESS', $group->getName()); } $view->setMessage($message, SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__, $group, $action); }
/** * Mass assign points for users * * @since 1.0 * @access public * @param string * @return */ public function massAssign() { // Check for request forgeries FD::checkToken(); // Get the current view $view = $this->getCurrentView(); // Get the file from the request $file = JRequest::getVar('package', '', 'FILES'); // Format the csv data now. $data = FD::parseCSV($file['tmp_name'], false, false); if (!$data) { $view->setMessage(JText::_('COM_EASYSOCIAL_POINTS_INVALID_CSV_FILE'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Load up the points library $points = FD::points(); // Collect the list of failed and successfull items $failed = array(); $success = array(); foreach ($data as $row) { $userId = isset($row[0]) ? $row[0] : false; $value = isset($row[1]) ? $row[1] : false; $message = isset($row[2]) ? $row[2] : false; $obj = (object) $row; // Skip this if (!$userId || !$points) { $failed[] = $obj; continue; } $points->assignCustom($userId, $value, $message); $success[] = $obj; } $view->setMessage(JText::_('COM_EASYSOCIAL_POINTS_CSV_FILE_PARSED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__, $success, $failed); }
public function addbadges($user, $log_user, $sub_id) { $my = FD::user($log_user); // @badge: followers.follow $badge = FD::badges(); $badge->log('com_easysocial', 'followers.follow', $my->id, JText::_('COM_EASYSOCIAL_FOLLOWERS_BADGE_FOLLOWING_USER')); // @badge: followers.followed $badge->log('com_easysocial', 'followers.followed', $user->id, JText::_('COM_EASYSOCIAL_FOLLOWERS_BADGE_FOLLOWED')); // @points: profile.follow // Assign points when user follows another person $points = FD::points(); $points->assign('profile.follow', 'com_easysocial', $my->id); // @points: profile.followed // Assign points when user is being followed by another person $points->assign('profile.followed', 'com_easysocial', $user->id); // check if admin want to add stream on following a user or not. $config = FD::config(); if ($config->get('users.stream.following')) { // Share this on the stream. $stream = FD::stream(); $streamTemplate = $stream->getTemplate(); // Set the actor. $streamTemplate->setActor($my->id, SOCIAL_TYPE_USER); // Set the context. $streamTemplate->setContext($sub_id, SOCIAL_TYPE_FOLLOWERS); // Set the verb. $streamTemplate->setVerb('follow'); $streamTemplate->setAccess('followers.view'); // Create the stream data. $stream->add($streamTemplate); } // Set the email options $emailOptions = array('title' => 'COM_EASYSOCIAL_EMAILS_NEW_FOLLOWER_SUBJECT', 'template' => 'site/followers/new.followers', 'actor' => $my->getName(), 'actorAvatar' => $my->getAvatar(SOCIAL_AVATAR_SQUARE), 'actorLink' => $my->getPermalink(true, true), 'target' => $user->getName(), 'targetLink' => $user->getPermalink(true, true), 'totalFriends' => $my->getTotalFriends(), 'totalFollowing' => $my->getTotalFollowing(), 'totalFollowers' => $my->getTotalFollowers()); $state = FD::notify('profile.followed', array($user->id), $emailOptions, array('url' => $my->getPermalink(false, false, false), 'actor_id' => $my->id, 'uid' => $user->id)); return $state; }
/** * Stores a submitted report * * @since 1.0 * @access public * @param string * @return */ public function store() { // Check for request forgeries FD::checkToken(); // Get data from $_POST $post = JRequest::get('post'); // Get current view. $view = $this->getCurrentView(); // Get the current logged in user $my = FD::user(); // Determine if the user is a guest $config = FD::config(); if (!$my->id && !$config->get('reports.guests', false)) { return; } // Determine if this user has the permissions to submit reports. $access = FD::access(); if (!$access->allowed('reports.submit')) { $view->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_NOT_ALLOWED_TO_SUBMIT_REPORTS'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Get the reports model $model = FD::model('Reports'); // Determine if this user has exceeded the number of reports that they can submit $total = $model->getCount(array('created_by' => $my->id)); if ($access->exceeded('reports.limit', $total)) { $view->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_LIMIT_EXCEEDED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Create the report $report = FD::table('Report'); $report->bind($post); // Try to get the user's ip address. $report->ip = JRequest::getVar('REMOTE_ADDR', '', 'SERVER'); // Set the creator id. $report->created_by = $my->id; // Set the default state of the report to new $report->state = 0; // Try to store the report. $state = $report->store(); // If there's an error, throw it if (!$state) { $view->setMessage($report->getError(), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // @badge: reports.create // Add badge for the author when a report is created. $badge = FD::badges(); $badge->log('com_easysocial', 'reports.create', $my->id, JText::_('COM_EASYSOCIAL_REPORTS_BADGE_CREATED_REPORT')); // @points: reports.create // Add points for the author when a report is created. $points = FD::points(); $points->assign('reports.create', 'com_easysocial', $my->id); // Determine if we should send an email $config = FD::config(); if ($config->get('reports.notifications.moderators')) { $report->notify(); } $view->setMessage(JText::_('COM_EASYSOCIAL_REPORTS_STORED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__); }
/** * Allows viewer to download a file from the group * * @since 1.2 * @access public * @param string * @return */ public function downloadFile() { // Currently only registered users are allowed to view a file. FD::requireLogin(); // Load the file object $id = $this->input->get('fileid', 0, 'int'); $file = FD::table('File'); $file->load($id); if (!$file->id || !$id) { // Throw error message here. $this->redirect(FRoute::dashboard(array(), false)); $this->close(); } // Add points for the user when they upload a file. FD::points()->assign('files.download', 'com_easysocial', $this->my->id); // @TODO: Check for the privacy. $file->download(); exit; }
/** * Logics to create a new conversations. * * @since 1.0 * @access public */ public function store() { // Check for request forgeries. FD::checkToken(); // Ensure that the user is logged in. FD::requireLogin(); // Get the current logged in user. $my = FD::user(); // Get list of recipients. $recipients = JRequest::getVar('uid'); // Ensure that the recipients is an array. $recipients = FD::makeArray($recipients); // The user might be writing to a friend list. $lists = JRequest::getVar('list_id'); // Go through each of the list and find the member id's. if ($lists) { $ids = array(); $listModel = FD::model('Lists'); foreach ($lists as $listId) { $members = $listModel->getMembers($listId, true); // Merge the result set. $ids = array_merge($ids, $members); } if ($recipients === false) { $recipients = array(); } // Merge the id's with the recipients and ensure that they are all unique $recipients = array_merge($ids, $recipients); $recipients = array_unique($recipients); } // Get the view. $view = $this->getCurrentView(); // Get configuration $config = FD::config(); // Check if user is allowed to create new conversations $access = FD::access(); if (!$access->allowed('conversations.create')) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_NOT_ALLOWED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // If recipients is not provided, we need to throw an error. if (empty($recipients)) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_EMPTY_RECIPIENTS'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Get the total number of message sent in a day $model = FD::model('Conversations'); $totalSent = $model->getTotalSentDaily($my->id); // We need to calculate the amount of users they are sending to $totalSent = $totalSent + count($recipients); if ($access->exceeded('conversations.send.daily', $totalSent)) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_EXCEEDED_DAILY_SEND_LIMIT'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Check if the creator is allowed to send a message to the target $privacy = $my->getPrivacy(); // Ensure that the recipients is not only itself. foreach ($recipients as $recipient) { // When user tries to enter it's own id, we should just break out of this function. if ($recipient == $my->id) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_CANNOT_SEND_TO_SELF'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Check if the creator is allowed if (!$privacy->validate('profiles.post.message', $recipient, SOCIAL_TYPE_USER)) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_CANNOT_SEND_TO_USER_DUE_TO_PRIVACY'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } } // Get the message that is being posted. $msg = JRequest::getVar('message', '', 'REQUEST', 'none', JREQUEST_ALLOWHTML); // Normalize CRLF (\r\n) to just LF (\n) $msg = str_ireplace("\r\n", "\n", $msg); // Message should not be empty. if (empty($msg)) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_EMPTY_MESSAGE'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Filter recipients and ensure all the user id's are proper! $total = count($recipients); // If there is more than 1 recipient and group conversations is disabled, throw some errors if ($total > 1 && !$config->get('conversations.multiple')) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_GROUP_CONVERSATIONS_DISABLED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Go through all the recipient and make sure that they are valid. for ($i = 0; $i < $total; $i++) { $userId = $recipients[$i]; $user = FD::user($userId); if (!$user || empty($userId)) { unset($recipients[$i]); } } // After processing the recipients list, and no longer has any recipients, stop the user. if (empty($recipients)) { $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_ERROR_EMPTY_RECIPIENTS'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Get the conversation table. $conversation = FD::table('Conversation'); // Determine the type of message this is by the number of recipients. $type = count($recipients) > 1 ? SOCIAL_CONVERSATION_MULTIPLE : SOCIAL_CONVERSATION_SINGLE; // For single recipients, we try to reuse back previous conversations // so that it will be like a long chat of history. if ($type == SOCIAL_CONVERSATION_SINGLE) { // We know that the $recipients[0] is always the target user. $state = $conversation->loadByRelation($my->id, $recipients[0], SOCIAL_CONVERSATION_SINGLE); } // @points: conversation.create.group // Assign points when user starts new group conversation if (count($recipients) > 1) { $points = FD::points(); $points->assign('conversation.create.group', 'com_easysocial', $my->id); } // Set the conversation creator. $conversation->created_by = $my->id; // Set the last replied date. $conversation->lastreplied = FD::date()->toMySQL(); // Set the conversation type. $conversation->type = $type; // Let's try to create the conversation now. $state = $conversation->store(); // If there's an error storing the conversation, break. if (!$state) { $view->setMessage(JText::_($conversation->getError()), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // @rule: Store conversation message $message = FD::table('ConversationMessage'); $post = JRequest::get('POST'); // Bind the message data. $message->bind($post); // Set the message because we normalized the CRLF (\r\n) to LF (\n) $message->message = $msg; // Set the conversation id since we have the conversation id now. $message->conversation_id = $conversation->id; // Sets the message type. $message->type = SOCIAL_CONVERSATION_TYPE_MESSAGE; // Set the creation date. $message->created = FD::date()->toMySQL(); // Set the creator. $message->created_by = $my->id; // Try to store the message now. $state = $message->store(); // Once the message is saved, we need to process any tags $tags = JRequest::getVar('tags'); if ($tags) { foreach ($tags as $raw) { $object = FD::json()->decode($raw); $tag = FD::table('Tag'); $tag->offset = $object->start; $tag->length = $object->length; $tag->type = $object->type; if ($tag->type == 'hashtag') { $tag->title = $object->value; } if ($tag->type == 'entity') { list($entityType, $entityId) = explode(':', $object->value); $tag->item_id = $entityId; $tag->item_type = $entityType; } $tag->creator_id = $my->id; $tag->creator_type = SOCIAL_TYPE_USER; $tag->target_id = $message->id; $tag->target_type = 'conversations'; $tag->store(); } } if (!$state) { $view->setMessage(JText::_($message->getError()), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Add users to the message maps. array_unshift($recipients, $my->id); $model = FD::model('Conversations'); // Add the recipient as a participant of this conversation. $model->addParticipants($conversation->id, $recipients); // Add the message maps so that the recipient can view the message $model->addMessageMaps($conversation->id, $message->id, $recipients, $my->id); // Process attachments here. if ($config->get('conversations.attachments.enabled')) { $attachments = JRequest::getVar('upload-id'); // If there are attachments, store them appropriately. if ($attachments) { $message->bindTemporaryFiles($attachments); } } // Bind message location if necessary. if ($config->get('conversations.location')) { $address = JRequest::getVar('address', ''); $latitude = JRequest::getVar('latitude', ''); $longitude = JRequest::getVar('longitude', ''); if (!empty($address) && !empty($latitude) && !empty($longitude)) { $location = FD::table('Location'); $location->loadByType($message->id, SOCIAL_TYPE_CONVERSATIONS, $my->id); $location->address = $address; $location->latitude = $latitude; $location->longitude = $longitude; $location->user_id = $this->created_by; $location->type = SOCIAL_TYPE_CONVERSATIONS; $location->uid = $message->id; $state = $location->store(); } } // Send notification email to recipients foreach ($recipients as $recipientId) { // We should not send a notification to ourself. if ($recipientId != $my->id) { $recipient = FD::user($recipientId); // Add new notification item $mailParams = array(); $mailParams['title'] = 'COM_EASYSOCIAL_EMAILS_NEW_CONVERSATION_SUBJECT'; $mailparams['actor'] = $my->getName(); $mailParams['authorName'] = $my->getName(); $mailParams['authorAvatar'] = $my->getAvatar(); $mailParams['authorLink'] = $my->getPermalink(true, true); $mailParams['message'] = $message->message; $mailParams['messageDate'] = $message->created; $mailParams['conversationLink'] = $conversation->getPermalink(true, true); // Send a notification for all participants in this thread. $state = FD::notify('conversations.new', array($recipientId), $mailParams, false); } } $view->setMessage(JText::_('COM_EASYSOCIAL_CONVERSATIONS_MESSAGE_SENT'), SOCIAL_MSG_SUCCESS); // Pass this back to the view. return $view->call(__FUNCTION__, $conversation); }
/** * Processes after the story is saved so that we can generate a stream item for this * * @since 1.3 * @access public * @param string * @return */ public function onAfterStorySave(SocialStream &$stream, SocialTableStreamItem $streamItem, &$template) { $files = $this->input->get('files', array(), 'array'); if (!$files) { return; } // Add points for the user when they upload a file. FD::points()->assign('files.upload', 'com_easysocial', $this->my->id); // We need to set the context id's for the files shared in this stream. $params = FD::registry(); $params->set('files', $files); $streamItem->params = $params->toString(); $streamItem->store(); }
/** * Adds a participant into an existing conversation * * @since 1.0 * @access public * @param int The creator's user id. * @param int The recipient's user id. * @return boolean True on success, false otherwise. */ public function addParticipant($created_by, $userId) { // Create a new participant record. $participant = FD::table('ConversationParticipant'); // Try to load and see if the participant has already been added to the system. $participant->load(array('user_id' => $userId, 'conversation_id' => $this->id)); $participant->conversation_id = $this->id; $participant->user_id = $userId; $participant->state = SOCIAL_STATE_PUBLISHED; // Try to save the participant $state = $participant->store(); if (!$state) { $this->setError($participant->getError()); return $state; } // @badge: conversation.invite $badge = FD::badges(); $badge->log('com_easysocial', 'conversation.invite', $created_by, JText::_('COM_EASYSOCIAL_CONVERSATIONS_BADGE_INVITED_USER_TO_CONVERSATION')); // @points: conversation.invite // Assign points when user starts new conversation $points = FD::points(); $points->assign('conversation.invite', 'com_easysocial', $created_by); // Once the participant is created, we need to create a // a new conversation message with the type of join so that others would know // that a new user is added to the conversation. $message = FD::table('ConversationMessage'); $message->conversation_id = $this->id; $message->message = $userId; $message->type = SOCIAL_CONVERSATION_TYPE_JOIN; $message->created_by = $created_by; // Try to store the new message $state = $message->store(); if (!$state) { $this->setError($message->getError()); return $state; } // Get conversation model $model = FD::model('Conversations'); // Get existing participants. $participants = $model->getParticipants($this->id); // Finally, we need to add the message maps $model->addMessageMaps($this->id, $message->id, $participants, $created_by); return true; }
/** * 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'); }
/** * Creates a new milestone for tasks * * @since 1.2 * @access public */ public function save() { // Check for request forgeries. FD::checkToken(); // Ensure that the user is logged in. FD::requireLogin(); // Get the current logged in user. $my = FD::user(); // Get the event $eventId = JRequest::getInt('cluster_id', 0); $event = FD::event($eventId); // Check if the user is allowed to create a discussion if (!$event->getGuest()->isGuest() && !$my->isSiteAdmin()) { FD::info()->set(JText::_('APP_EVENT_TASKS_NOT_ALLOWED_HERE'), SOCIAL_MSG_ERROR); // Perform a redirection return JFactory::getApplication()->redirect(FRoute::dashboard()); } // Get the milestone data $id = JRequest::getInt('id'); $milestone = FD::table('Milestone'); $milestone->load($id); $milestone->title = JRequest::getVar('title'); $milestone->uid = (int) $event->id; $milestone->type = SOCIAL_TYPE_EVENT; $milestone->state = SOCIAL_TASK_UNRESOLVED; if ($event->getGuest()->isGuest()) { $milestone->user_id = JRequest::getInt('user_id'); } $milestone->description = JRequest::getVar('description'); $milestone->due = JRequest::getVar('due'); $milestone->owner_id = (int) $my->id; $milestone->store(); // Get the app $app = $this->getApp(); // Get the application params $params = $app->getParams(); // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $event->getAlias(), 'type' => SOCIAL_TYPE_EVENT, 'id' => $app->getAlias(), 'milestoneId' => $milestone->id), false); // If this is new milestone, perform some tasks if (!$id) { // Generate a new stream if ($params->get('stream_milestone', true)) { $milestone->createStream('createMilestone'); } if ($params->get('notify_milestone', true)) { $event->notifyMembers('milestone.create', array('userId' => $my->id, 'id' => $milestone->id, 'title' => $milestone->title, 'content' => $milestone->getContent(), 'permalink' => $url)); } // @points: events.milestone.create // Add points to the user that updated the event $points = FD::points(); $points->assign('events.milestone.create', 'com_easysocial', $my->id); } FD::info()->set(JText::_('APP_EVENT_TASKS_MILESTONE_CREATED')); // Perform a redirection $this->redirect($url); }
/** * Stores a new story item * * @since 1.0 * @access public * @param string * @return */ public function create() { // Check for request forgeries FD::checkToken(); // Check for valid users. FD::requireLogin(); // Load our story library $story = FD::story(SOCIAL_TYPE_USER); // Get posted data. $post = $this->input->getArray('post'); // Check if the user being viewed the same user or other user. $id = $post['target']; $targetId = $this->my->id != $id ? $id : ''; // Determine the post types. $type = isset($post['attachment']) && !empty($post['attachment']) ? $post['attachment'] : SOCIAL_TYPE_STORY; // Check if the content is empty only for story based items. if ((!isset($post['content']) || empty($post['content'])) && $type == SOCIAL_TYPE_STORY) { $this->view->setMessage('COM_EASYSOCIAL_STORY_PLEASE_POST_MESSAGE', SOCIAL_MSG_ERROR); return $this->view->call(__FUNCTION__); } // Check if the content is empty and there's no photos. if ((!isset($post['photos']) || empty($post['photos'])) && $type == 'photos') { $this->view->setMessage('COM_EASYSOCIAL_STORY_PLEASE_ADD_PHOTO', SOCIAL_MSG_ERROR); return $this->view->call(__FUNCTION__); } // We need to allow raw because we want to allow <,> in the text but it should be escaped during display $content = $this->input->get('content', '', 'raw'); // Check whether the user can really post something on the target if ($targetId) { $allowed = $this->my->getPrivacy()->validate('profiles.post.status', $targetId, SOCIAL_TYPE_USER); if (!$allowed) { $this->view->setMessage('COM_EASYSOCIAL_STORY_NOT_ALLOW_TO_POST', SOCIAL_MSG_ERROR); return $this->view->call(__FUNCTION__); } } // Store the location for this story $shortAddress = $this->input->get('locations_short_address', '', 'default'); $address = $this->input->get('locations_formatted_address', '', 'default'); $lat = $this->input->get('locations_lat', '', 'default'); $lng = $this->input->get('locations_lng', '', 'default'); $locationData = $this->input->get('locations_data', '', 'default'); $location = null; // Only store location when there is location data if (!empty($address) && !empty($lat) && !empty($lng)) { $location = FD::table('Location'); $location->short_address = $shortAddress; $location->address = $address; $location->longitude = $lng; $location->latitude = $lat; $location->uid = $story->id; $location->type = $type; $location->user_id = $this->my->id; $location->params = $locationData; // Try to save the location data. $state = $location->store(); } // Get which users are tagged in this post. $friendIds = $this->input->get('friends_tags', '', 'default'); $friends = array(); if (!empty($friendIds)) { // Get the friends model $model = FD::model('Friends'); // Check if the user is really a friend of him / her. foreach ($friendIds as $id) { if (!$model->isFriends($this->my->id, $id)) { continue; } $friends[] = $id; } } $contextIds = 0; // For photos that are posted on the story form if ($type == 'photos' && isset($post['photos'])) { $contextIds = $post['photos']; } // Check if there are mentions provided from the post. $mentions = isset($post['mentions']) ? $post['mentions'] : array(); // Format the json string to array if (isset($post['mentions'])) { $mentions = $post['mentions']; foreach ($mentions as &$mention) { $mention = json_decode($mention); } } // Process moods here $mood = FD::table('Mood'); $hasMood = $mood->bindPost($post); // If this exists, we need to store them if ($hasMood) { $mood->user_id = $this->my->id; $mood->store(); } // Set the privacy for the album $privacy = $this->input->get('privacy', '', 'default'); $customPrivacy = $this->input->get('privacyCustom', '', 'string'); $privacyRule = $type == 'photos' ? 'photos.view' : 'story.view'; // Determines if the current posting is for a cluster $cluster = isset($post['cluster']) ? $post['cluster'] : ''; $clusterType = isset($post['clusterType']) ? $post['clusterType'] : ''; $isCluster = $cluster ? true : false; $postPermission = true; if ($isCluster) { $postPermission = $this->checkClusterPermissions($cluster, $clusterType); } // Ensure only permitted user can post the story if (!$postPermission) { return $this->view->call(__FUNCTION__); } else { // Options that should be sent to the stream lib $args = array('content' => $content, 'contextIds' => $contextIds, 'contextType' => $type, 'actorId' => $this->my->id, 'targetId' => $targetId, 'location' => $location, 'with' => $friends, 'mentions' => $mentions, 'cluster' => $cluster, 'clusterType' => $clusterType, 'mood' => $mood, 'privacyRule' => $privacyRule, 'privacyValue' => $privacy, 'privacyCustom' => $customPrivacy); // Create the stream item $stream = $story->create($args); if ($hasMood) { $mood->namespace = 'story.user.create'; $mood->namespace_uid = $stream->id; $mood->store(); } // Update with the stream's id. after the stream is created. if (!empty($address) && !empty($lat) && !empty($lng)) { $location->uid = $stream->id; // Try to save the location data. $state = $location->store(); } // @badge: story.create // Add badge for the author when a report is created. $badge = FD::badges(); $badge->log('com_easysocial', 'story.create', $this->my->id, JText::_('COM_EASYSOCIAL_STORY_BADGE_CREATED_STORY')); // @points: story.create // Add points for the author when a report is created. $points = FD::points(); $points->assign('story.create', 'com_easysocial', $this->my->id); // Privacy is only applicable to normal postings if (!$isCluster) { $privacyLib = FD::privacy(); if ($type == 'photos') { $photoIds = FD::makeArray($contextIds); foreach ($photoIds as $photoId) { $privacyLib->add($privacyRule, $photoId, $type, $privacy, null, $customPrivacy); } } else { $privacyLib->add($privacyRule, $stream->uid, $type, $privacy, null, $customPrivacy); } } return $this->view->call(__FUNCTION__, $stream, $cluster, $clusterType); } }
/** * Allows caller to create a new task given the milestone id and the event id. * * @since 1.2 * @access public */ public function save() { // Check for request forgeries FD::checkToken(); // Only allow logged in users FD::requireLogin(); // Load up ajax library $ajax = FD::ajax(); // Get the current event and logged in user $eventId = JRequest::getInt('eventId'); $event = FD::event($eventId); $my = FD::user(); if (!$event || !$eventId) { return $ajax->reject(); } // Test if the current user is a member of this event. if (!$event->getGuest()->isGuest()) { return $ajax->reject(); } // Determines if this is a new record $id = JRequest::getInt('id'); $task = FD::table('Task'); $task->load($id); $milestoneId = JRequest::getInt('milestoneId'); $title = JRequest::getVar('title'); $due = JRequest::getVar('due'); $assignee = JRequest::getVar('assignee'); // Save task $task->milestone_id = $milestoneId; $task->uid = $event->id; $task->type = SOCIAL_TYPE_EVENT; $task->title = $title; $task->due = $due; $task->user_id = !$assignee ? $my->id : $assignee; $task->state = SOCIAL_TASK_UNRESOLVED; if (!$task->title) { return $ajax->reject(); } $task->store(); if (!$id) { // @points: events.task.create $points = FD::points(); $points->assign('events.task.create', 'com_easysocial', $my->id); // Get the app $app = $this->getApp(); // Get the application params $params = $app->getParams(); // Send notification if ($params->get('notify_new_task', true)) { $milestone = FD::table('Milestone'); $milestone->load($milestoneId); // Get the redirection url $url = FRoute::apps(array('layout' => 'canvas', 'customView' => 'item', 'uid' => $event->getAlias(), 'type' => SOCIAL_TYPE_EVENT, 'id' => $app->getAlias(), 'milestoneId' => $milestoneId), false); $event->notifyMembers('task.create', array('userId' => $my->id, 'id' => $task->id, 'title' => $task->title, 'content' => $milestone->description, 'permalink' => $url, 'milestone' => $milestone->title)); } // Create stream $task->createStream('createTask'); } // Get the contents $theme = FD::themes(); $theme->set('event', $event); $theme->set('task', $task); $theme->set('user', $my); $output = $theme->output('apps/event/tasks/views/item.task'); return $ajax->resolve($output); }
/** * Overrides the parent's implementation of store * * @since 1.3 * @access public * @param string * @return */ public function store($pk = null) { $isNew = !$this->id; // Save this into the table first parent::store($pk); // Add this into the mail queue if ($isNew) { $jconfig = FD::jconfig(); $mailer = FD::mailer(); $template = $mailer->getTemplate(); $sender = FD::user($this->user_id); $params = new stdClass(); $params->senderName = $sender->getName(); $params->message = $this->message; $params->siteName = $jconfig->getValue('sitename'); $params->manageAlerts = false; $params->link = FRoute::registration(array('invite' => $this->id, 'external' => true)); $template->setSender($sender->getName(), $sender->email); $template->setReplyTo($sender->email); $template->setRecipient('', $this->email); $template->setTitle(JText::sprintf('COM_EASYSOCIAL_FRIENDS_INVITE_MAIL_SUBJECT', $jconfig->getValue('sitename'))); $template->setTemplate('site/friends/invite', $params); $mailer->create($template); // Assign points to the user that created this invite $points = FD::points(); $points->assign('friends.invite', 'com_easysocial', $this->user_id); } }
/** * Override parent's delete method * * @since 1.0 * @access public * @param string * @return */ public function delete($pk = null) { // Delete the record from the database first. $state = parent::delete(); // Now, try to delete the folder that houses this photo. $config = FD::config(); // Check if this photo is used as a profile cover if ($this->isProfileCover()) { $cover = FD::table('Cover'); $cover->load(array('photo_id' => $this->id)); $cover->delete(); } // Needs to create an instance of image to create // and instnance of photos $image = FD::image(); $photoLib = FD::get('Photos', $image); $basePath = $photoLib->getStoragePath($this->album_id, $this->id); // Construct the base path to the photos folder $container = FD::cleanPath($config->get('photos.storage.container')); $basePath = '/' . $container . '/' . $this->album_id . '/' . $this->id; // @legacy // @since 1.2.7 // To fix older version issues where the full path is stored for the photo $relative = str_ireplace(JPATH_ROOT, '', $basePath); // below checking is to make sure the computed relative path is not pointing to photos root folder. $photoContainer = FD::cleanPath($config->get('photos.storage.container')); $photoContainer = '/' . ltrim($photoContainer, '/'); $photoContainer = rtrim($photoContainer, '/'); $photoContainer = JPath::clean($photoContainer); $photoRelPath = '/' . ltrim($relative, '/'); $photoRelPath = rtrim($photoRelPath, '/'); $photoRelPath = JPath::clean($photoRelPath); if ($photoContainer != $photoRelPath) { $storage = FD::storage($this->storage); $storage->delete($relative, true); } $model = FD::model('Photos'); // Delete the meta's related to this photo $model->deleteMeta($this->id); // Delete all tags associated with this photo $model->deleteTags($this->id); // Delete all comments associated with this photo $comments = FD::comments($this->id, SOCIAL_TYPE_PHOTO, 'upload', SOCIAL_APPS_GROUP_USER); $comments->delete(); // Delete all likes associated with this photo $likes = FD::get('Likes'); $likes->delete($this->id, SOCIAL_TYPE_PHOTO, 'upload'); // @points: photos.remove // Deduct points for the author $points = FD::points(); $points->assign('photos.remove', 'com_easysocial', $this->uid); // Push the ordering of other photos $model->pushPhotosOrdering($this->album_id, 0, $this->ordering, '-'); // Need to set cover to another photo if ($this->isCover()) { $album = $this->getAlbum(); if ($album->hasPhotos()) { $result = $album->getPhotos(array('limit' => 1)); $album->cover_id = $result['photos'][0]->id; } else { $album->cover_id = 0; } $album->store(); } return $state; }
/** * Invites a user to the event and does the appropriate follow actions. * * @author Jason Rey <*****@*****.**> * @since 1.3 * @access public * @param integer $target The invited user id. * @param integer $actor The actor user id. * @return boolean True if successful. */ public function invite($target, $actor = null) { $actor = FD::user($actor); $target = FD::user($target); $guest = FD::table('EventGuest'); $guest->cluster_id = $this->id; $guest->uid = $target->id; $guest->type = SOCIAL_TYPE_USER; $guest->state = SOCIAL_EVENT_GUEST_INVITED; $guest->invited_by = $actor->id; $guest->store(); FD::points()->assign('events.guest.invite', 'com_easysocial', $actor->id); $emailOptions = (object) array('title' => 'COM_EASYSOCIAL_EMAILS_EVENT_GUEST_INVITED_SUBJECT', 'template' => 'site/event/guest.invited', 'event' => $this->getName(), 'eventName' => $this->getName(), 'eventAvatar' => $this->getAvatar(), 'eventLink' => $this->getPermalink(false, true), 'invitorName' => $actor->getName(), 'invitorLink' => $actor->getPermalink(false, true), 'invitorAvatar' => $actor->getAvatar()); $systemOptions = (object) array('uid' => $this->id, 'actor_id' => $actor->id, 'target_id' => $target->id, 'context_type' => 'events', 'type' => 'events', 'url' => $this->getPermalink(true, false, 'item', false), 'eventId' => $this->id); FD::notify('events.guest.invited', array($target->id), $emailOptions, $systemOptions); return true; }
public function assignPoints($command, $target = null) { $user = FD::user($target); $points = FD::points(); return $points->assign($command, 'com_kunena', $user->id); }
/** * Logs a user action. * * Example: * <code> * <?php * $badges = FD::badges(); * $my = FD::user(); * * $badges->log( 'com_easyblog' , 'blog.create' , $my->id , 'Created a new blog post Hello World'); * * ?> * </code> * * @since 1.0 * @access public * @param string The unique extension name. * @param string The unique command string. */ public function log($extension, $command, $userId, $message) { // If user id is not provided we shouldn't log anything if (!$userId) { return false; } // Check if badges is enabled $config = FD::config(); if (!$config->get('badges.enabled')) { return; } $badge = FD::table('Badge'); // Try to load the badge rule for this extension $state = $badge->load(array('extension' => $extension, 'command' => $command)); // If the extension / command does not exist, quit this. if (!$state) { return false; } // Badge needs to be published. if (!$badge->state) { return false; } // Load badges model $model = FD::model('Badges'); // Check if the user reached the specified frequency already or not. $achieving = $model->hasReachedFrequency($badge->id, $userId); $achieved = $model->hasAchieved($badge->id, $userId); // If the frequency of the badge is only 1, the achieving will not return anything. if ($badge->frequency == 1 && !$achieved) { $achieving = true; } $log = FD::table('BadgeHistory'); $log->badge_id = $badge->id; $log->user_id = $userId; $log->achieved = $achieving && !$achieved; // Try to store the history action. $state = $log->store(); // Only add a badge for this user when they have never achieved it before. if ($achieving && !$achieved) { // Create the new badge maps $user = FD::user($userId); $state = $this->create($badge, $user); // Only announce to the world when the badge is really achieved. if ($state) { // @notifications: Send a notification to the user when they achieved a badge. $this->sendNotification($badge, $user->id); // @stream: Log stream here that the user achieved a new badge. $this->addStream($badge, $user->id); // Add points for the user when they achieve a badge. $points = FD::points(); $points->assign('badges.achieve', 'com_easysocial', $user->id); } } if (!$state) { return false; } }
/** * Inserts a new reply into an existing conversation. * * @since 1.0 * @access public * @param int The conversation id. * @param string Content of the message * @param int The user id (owner) of the message * * @return SocialTableConversationMessage The message object */ public function addReply($conversationId, $msg, $creatorId) { // Try to load the conversation id first. $conversation = FD::table('Conversation'); $conversation->load($conversationId); // Now, we need to create a new record for the conversation message. $message = FD::table('ConversationMessage'); $message->conversation_id = $conversation->id; $message->message = $msg; $message->created_by = $creatorId; $message->type = SOCIAL_CONVERSATION_TYPE_MESSAGE; $message->store(); // @badge: conversation.reply $badge = FD::badges(); $badge->log('com_easysocial', 'conversation.reply', $creatorId, JText::_('COM_EASYSOCIAL_CONVERSATIONS_BADGE_REPLIED_IN_A_CONVERSATION')); // @points: conversation.reply // Assign points when user replies in a conversation $points = FD::points(); $points->assign('conversation.reply', 'com_easysocial', $creatorId); // Since a new message is added, add the visibility of this new message to the participants. $users = $this->getParticipants($conversation->id, null, true); if ($users) { foreach ($users as $user) { $map = FD::table('ConversationMessageMap'); $map->user_id = $user->id; $map->conversation_id = $conversation->id; $map->state = SOCIAL_STATE_PUBLISHED; $map->isread = SOCIAL_CONVERSATION_UNREAD; $map->message_id = $message->id; $map->store(); // If the same person created a reply, reset all as viewed since they are already viewing the message. if ($user->id == $creatorId) { $this->markAsRead($conversation->id, $user->id); } else { $this->markAsUnread($conversation->id, $user->id); } } } // In case a message has been archived by the creator, and the creator added a reply to this // conversation, automatically unarchive all messages. $db = FD::db(); $query = 'UPDATE ' . $db->nameQuote('#__social_conversations_message_maps') . ' ' . 'SET ' . $db->nameQuote('state') . ' = ' . $db->Quote(SOCIAL_CONVERSATION_STATE_PUBLISHED) . ' ' . 'WHERE ' . $db->nameQuote('conversation_id') . ' = ' . $db->Quote($conversationId) . ' ' . 'AND ' . $db->nameQuote('user_id') . ' = ' . $db->Quote($creatorId); $db->setQuery($query); $db->Query(); // Every time a reply is added, we need to ensure that the last replied is updated so that we can order them later. $conversation->set('lastreplied', FD::date()->toMysQL()); $conversation->store(); return $message; }
private function processPoints() { $db = FD::db(); $sql = $db->sql(); $query = 'select a.*'; $query .= ' from `#__community_users` as a'; $query .= ' where not exists ( '; $query .= ' select b.`id` from `#__social_migrators` as b'; $query .= ' where a.`userid` = b.`oid` and b.`element` = ' . $db->Quote('points') . ' and b.`component` = ' . $db->Quote($this->name); $query .= ' )'; $query .= ' ORDER BY a.`userid` ASC'; $query .= ' LIMIT ' . $this->limit; $sql->raw($query); $db->setQuery($sql); $jsUsers = $db->loadObjectList(); if (count($jsUsers) <= 0) { return null; } $points = FD::points(); foreach ($jsUsers as $jsUser) { $points->assignCustom($jsUser->userid, $jsUser->points, 'Points transfered from JomSocial'); // log into mgirator $this->log('points', $jsUser->userid, $jsUser->userid); $this->info->setInfo('Points from user ' . $jsUser->userid . ' is now migrated into EasySocial.'); } return $this->info; }