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; }
/** * 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_BADGES_INVALID_CSV_FILE'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } // Load up the points library $badges = FD::badges(); // Collect the list of failed and successfull items $failed = array(); $success = array(); foreach ($data as $row) { $userId = isset($row[0]) ? $row[0] : false; $badgeId = isset($row[1]) ? $row[1] : false; $dateAchieved = isset($row[2]) ? $row[2] : false; $message = isset($row[3]) ? $row[3] : false; $publishStream = isset($row[4]) && $row[4] == 1 ? true : false; $obj = (object) $row; $badge = FD::table('Badge'); $badge->load($badgeId); // Skip this if (!$userId || !$badgeId || !$badge->id) { $failed[] = $obj; continue; } $user = FD::user($userId); $badges->create($badge, $user, $message, $dateAchieved); if ($publishStream) { $badges->addStream($badge, $user->id); } $success[] = $obj; } $view->setMessage(JText::_('COM_EASYSOCIAL_BADGES_CSV_FILE_PARSED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS); return $view->call(__FUNCTION__, $success, $failed); }
/** * Assign points to a specific user. * * @since 1.0 * @access public * @param int The command to be executed. Refer to `#__social_points_commands`.`command` * @param string The extension or app name. Refer to `#__social_points_commands`.`extension` * @param int The target user's id. * @return bool True if point is given. False otherwise. */ public function assign($command, $extension, $userId) { $config = FD::config(); // Check if points system is enabled. if (!$config->get('points.enabled')) { return false; } // If user id is empty or 0, we shouldn't assign anything if (!$userId) { return false; } // Retrieve the points table. $points = FD::table('Points'); $state = $points->load(array('command' => $command, 'extension' => $extension)); // Check the command and extension and see if it is valid. if (!$state) { return false; } // Check the rule and see if it is published. if ($points->state != SOCIAL_STATE_PUBLISHED) { return false; } // @TODO: Check points threshold. if ($points->threshold) { } // @TODO: Check the interval to see if the user has achieved this for how many times. if ($points->interval != SOCIAL_POINTS_EVERY_TIME) { } // @TODO: Customizable point system where only users from specific profile type may achieve this point. // Add history. $history = FD::table('PointsHistory'); $history->points_id = $points->id; $history->user_id = $userId; $history->points = $points->points; $history->state = SOCIAL_STATE_PUBLISHED; $history->store(); $this->updateUserPoints($userId, $points->points); // Assign a badge to the user for earning points. $badge = FD::badges(); $badge->log('com_easysocial', 'points.achieve', $userId, JText::_('COM_EASYSOCIAL_POINTS_BADGE_EARNED_POINT')); return true; }
/** * Displays a user profile to a 3rd person perspective. * * @since 1.0 * @access public * @param null * @return null **/ public function display($tpl = null) { // Get the user's id. $id = $this->input->get('id', 0, 'int'); // The current logged in user might be viewing their own profile. if ($id == 0) { $id = FD::user()->id; } // When the user tries to view his own profile but if he isn't logged in, throw a login page. if ($id == 0) { return FD::requireLogin(); } // Check for user profile completeness FD::checkCompleteProfile(); // Get the user's object. $user = FD::user($id); // If the user still don't exist, throw a 404 if (!$user->id) { return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER')); } if (Foundry::user()->id != $user->id) { if (FD::user()->isBlockedBy($user->id)) { return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER')); } } if ($user->isBlock()) { FD::info()->set(JText::sprintf('COM_EASYSOCIAL_PROFILE_USER_NOT_EXIST', $user->getName()), SOCIAL_MSG_ERROR); return $this->redirect(FRoute::dashboard(array(), false)); } // Set the page title FD::page()->title(FD::string()->escape($user->getName())); // Set the page breadcrumb FD::page()->breadcrumb(FD::string()->escape($user->getName())); // Apply opengraph tags. FD::opengraph()->addProfile($user); // Get the current logged in user's object. $my = FD::user(); // Do not assign badge if i view myself. if ($user->id != $my->id && $my->id) { // @badge: profile.view $badge = FD::badges(); $badge->log('com_easysocial', 'profile.view', $my->id, JText::_('COM_EASYSOCIAL_PROFILE_VIEWED_A_PROFILE')); } $startlimit = JRequest::getInt('limitstart', 0); // Determine if the current request is to load an app $appId = JRequest::getInt('appId'); // Get site configuration $config = FD::config(); // Get the apps library. $appsLib = FD::apps(); $contents = ''; if ($appId) { // Load the app $app = FD::table('App'); $app->load($appId); // Check if the user has access to this app if (!$app->accessible($user->id)) { FD::info()->set(null, JText::_('COM_EASYSOCIAL_PROFILE_APP_IS_NOT_INSTALLED_BY_USER'), SOCIAL_MSG_ERROR); return $this->redirect(FRoute::profile(array('id' => $user->getAlias()), false)); } // Set the page title FD::page()->title(FD::string()->escape($user->getName()) . ' - ' . $app->get('title')); $contents = $appsLib->renderView(SOCIAL_APPS_VIEW_TYPE_EMBED, 'profile', $app, array('userId' => $user->id)); } $layout = JRequest::getCmd('layout'); // @since 1.3.7 // If layout is empty, means we want to get the default view // Previously timeline is always the default if (empty($appId) && empty($layout)) { $defaultDisplay = FD::config()->get('users.profile.display', 'timeline'); $layout = $defaultDisplay; } if ($layout === 'about') { FD::language()->loadAdmin(); $currentStep = JRequest::getInt('step', 1); $steps = FD::model('Steps')->getSteps($user->profile_id, SOCIAL_TYPE_PROFILES, SOCIAL_PROFILES_VIEW_DISPLAY); $fieldsLib = FD::fields(); $fieldsModel = FD::model('Fields'); $index = 1; foreach ($steps as $step) { $step->fields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $user->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_DISPLAY)); if (!empty($step->fields)) { $args = array($user); $fieldsLib->trigger('onDisplay', SOCIAL_FIELDS_GROUP_USER, $step->fields, $args); } $step->hide = true; foreach ($step->fields as $field) { // As long as one of the field in the step has an output, then this step shouldn't be hidden // If step has been marked false, then no point marking it as false again // We don't break from the loop here because there is other checking going on if (!empty($field->output) && $step->hide === true) { $step->hide = false; } } if ($index === 1) { $step->url = FRoute::profile(array('id' => $user->getAlias(), 'layout' => 'about'), false); } else { $step->url = FRoute::profile(array('id' => $user->getAlias(), 'layout' => 'about', 'step' => $index), false); } $step->title = $step->get('title'); $step->active = !$step->hide && $currentStep == $index; if ($step->active) { $theme = FD::themes(); $theme->set('fields', $step->fields); $contents = $theme->output('site/events/item.info'); } $step->index = $index; $index++; } $this->set('infoSteps', $steps); } // If contents is still empty at this point, then we just get the stream items as the content if (empty($contents)) { // Mark timeline item as the active one $this->set('timeline', true); // Retrieve user's stream $theme = FD::themes(); // Get story $story = FD::get('Story', SOCIAL_TYPE_USER); $story->target = $user->id; $stream = FD::stream(); $stream->get(array('userId' => $user->id, 'startlimit' => $startlimit)); if (FD::user()->id) { // only logged in user can submit story. $stream->story = $story; } // Set stream to theme $theme->set('stream', $stream); $contents = $theme->output('site/profile/default.stream'); } $this->set('contents', $contents); $privacy = $my->getPrivacy(); // Let's test if the current viewer is allowed to view this profile. if ($my->id != $user->id) { if (!$privacy->validate('profiles.view', $user->id, SOCIAL_TYPE_USER)) { $this->set('user', $user); parent::display('site/profile/restricted'); return; } } // Get user's cover object $cover = $user->getCoverData(); $this->set('cover', $cover); // If we're setting a cover $coverId = JRequest::getInt('cover_id', null); if ($coverId) { // Load cover photo $newCover = FD::table('Photo'); $newCover->load($coverId); // If the cover photo belongs to the user if ($newCover->isMine()) { // Then allow replacement of cover $this->set('newCover', $newCover); } } $photosModel = FD::model('Photos'); $photos = array(); // $photos = $photosModel->getPhotos( array( 'uid' => $user->id ) ); // not using? it seems like no one is referencing this photos. $totalPhotos = 0; // Retrieve list of apps for this user $appsModel = FD::model('Apps'); $options = array('view' => 'profile', 'uid' => $user->id, 'key' => SOCIAL_TYPE_USER); $apps = $appsModel->getApps($options); // Set the apps lib $this->set('appsLib', $appsLib); $this->set('totalPhotos', $totalPhotos); $this->set('photos', $photos); $this->set('apps', $apps); $this->set('activeApp', $appId); $this->set('privacy', $privacy); $this->set('user', $user); // Load the output of the profile. echo parent::display('site/profile/default'); }
/** * Creates a badge record * * @since 1.0 * @access public * @param string * @return */ public function assignBadge($rule, $actorId) { if ($rule == 'photos.create') { // @badge: photos.create $badge = FD::badges(); $badge->log('com_easysocial', 'photos.create', $actorId, JText::_('COM_EASYSOCIAL_PHOTOS_BADGE_UPLOADED')); } if ($rule == 'photos.browse') { // @badge: photos.browse $badge = FD::badges(); $badge->log('com_easysocial', 'photos.browse', $actorId, JText::_('COM_EASYSOCIAL_PHOTOS_BADGE_BROWSE')); } if ($rule == 'photos.tag') { // @badge: photos.tag $badge = FD::badges(); $badge->log('com_easysocial', 'photos.tag', $actorId, JText::_('COM_EASYSOCIAL_PHOTOS_BADGE_TAG')); } if ($rule == 'photos.superstar') { // @badge: photos.tag $badge = FD::badges(); $badge->log('com_easysocial', 'photos.tag', $actorId, JText::_('COM_EASYSOCIAL_PHOTOS_BADGE_TAG')); } }
/** * get activity logs. * * @since 1.0 * @access public */ public function getItems() { // Check for request forgeries! FD::checkToken(); // search controller do not need to check islogin. // Get the current view $view = $this->getCurrentView(); // Get current logged in user $my = FD::user(); // 7:EasyBlog $type = JRequest::getInt('type', 0); $keywords = JRequest::getVar('q', ''); $next_limit = JRequest::getVar('next_limit', ''); $last_type = JRequest::getVar('last_type', ''); $isloadmore = JRequest::getVar('loadmore', false); $ismini = JRequest::getVar('mini', false); $highlight = $ismini ? false : true; $limit = $ismini ? FD::themes()->getConfig()->get('search_toolbarlimit') : FD::themes()->getConfig()->get('search_limit'); // @badge: search.create // Assign badge for the person that initiated the friend request. if (!$isloadmore) { $badge = FD::badges(); $badge->log('com_easysocial', 'search.create', $my->id, JText::_('COM_EASYSOCIAL_SEARCH_BADGE_SEARCHED_ITEM')); } $results = array(); $pagination = null; $count = 0; $data = array(); $isFinderEnabled = JComponentHelper::isEnabled('com_finder'); if ($isFinderEnabled) { jimport('joomla.application.component.model'); $searchAdapter = FD::get('Search'); $path = JPATH_ROOT . '/components/com_finder/models/search.php'; require_once $path; $jModel = new FinderModelSearch(); $state = $jModel->getState(); $query = $jModel->getQuery(); // this line need to be here. so that the indexer can get the correct value if (!$query->terms) { // if there is no terms match. lets check if smart search suggested any terms or not. if yes, lets use it. if (isset($query->included) && count($query->included) > 0) { $suggestion = ''; foreach ($query->included as $item) { if (isset($item->suggestion) && !empty($item->suggestion)) { $suggestion = $item->suggestion; } } if ($suggestion) { //reset the query string. $app = JFactory::getApplication(); $input = $app->input; $input->request->set('q', $suggestion); //refresh $jModel = new FinderModelSearch(); $state = $jModel->getState(); $query = $jModel->getQuery(); // this line need to be here. so that the indexer can get the correct value } } } //reset the pagination state. $state->{'list.start'} = $next_limit; $state->{'list.limit'} = $limit; if ($type) { // 7:EasyBlog $typeAlias = JRequest::getVar('type', ''); $typeAlias = explode(':', $typeAlias); $typeAlias = $typeAlias[1]; $typeArr['Type'] = array($typeAlias => $type); $query->filters = $typeArr; } $results = $jModel->getResults(); $count = $jModel->getTotal(); $pagination = $jModel->getPagination(); if (FD::isJoomla30()) { $pagination->{'pages.total'} = $pagination->pagesTotal; $pagination->{'pages.current'} = $pagination->pagesCurrent; } if ($results) { $data = $searchAdapter->format($results, $query, $highlight); if ($pagination->{'pages.total'} == 1 || $pagination->{'pages.total'} == $pagination->{'pages.current'}) { $next_limit = '-1'; } else { $next_limit = $pagination->limitstart + $pagination->limit; } } } return $view->call(__FUNCTION__, $data, $last_type, $next_limit, $isloadmore, $ismini, $count); }
public function assignBadge($command, $message, $target = null) { $user = FD::user($target); $badge = FD::badges(); return $badge->log('com_kunena', $command, $user->id, $user->id); }
/** * 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; }
/** * Installs the app * * @since 1.0 * @access public * @param int User id * @return bool Result */ public function install($userId = null) { $user = FD::user($userId); $userId = $user->id; $config = FD::config(); $map = FD::table('appsmap'); $map->app_id = $this->id; $map->uid = $userId; $map->type = SOCIAL_APPS_GROUP_USER; $map->created = FD::date()->toSql(); $state = $map->store(); if (!$state) { return false; } // @badge: apps.install // Assign a badge to the user when they install apps. $badge = FD::badges(); $badge->log('com_easysocial', 'apps.install', $userId, JText::_('COM_EASYSOCIAL_APPS_BADGE_INSTALLED')); // Give points to the author when installing apps $points = FD::points(); $points->assign('apps.install', 'com_easysocial', $userId); // Get the application settings $app = FD::table('App'); $app->load(array('type' => SOCIAL_TYPE_APPS, 'group' => SOCIAL_TYPE_USER, 'element' => SOCIAL_TYPE_APPS)); $params = $app->getParams(); // If configured to publish on the stream, share this to the world. if ($app->id && $params->get('stream_install', true)) { // lets add a stream item here. $stream = FD::stream(); $template = $stream->getTemplate(); $template->setActor($user->id, SOCIAL_TYPE_USER); $template->setContext($this->id, SOCIAL_TYPE_APPS); $template->setVerb('install'); $template->setType(SOCIAL_STREAM_DISPLAY_MINI); $template->setAggregate(false); $template->setParams($this); $template->setAccess('core.view'); $stream->add($template); } return true; }
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 caller to remove a badge * * @since 1.0 * @access public * @param string * @return */ public function removeBadge() { // Check for request forgeries FD::checkToken(); // Get the current view $view = $this->getCurrentView(); // Get the badge id. $id = JRequest::getInt('id'); $userId = JRequest::getInt('userid'); // Load up the badge library $badge = FD::badges(); $badge->remove($id, $userId); $view->setMessage(JText::_('Achievement removed from user successfully.')); $view->call(__FUNCTION__); }
/** * Displays a user profile to a 3rd person perspective. * * @since 1.0 * @access public * @param null * @return null **/ public function display($tpl = null) { // Get the user's id. $id = $this->input->get('id', 0, 'int'); // Check if there is any stream filtering or not. $filter = $this->input->get('type', '', 'word'); // The current logged in user might be viewing their own profile. if ($id == 0) { $id = FD::user()->id; } // When the user tries to view his own profile but if he isn't logged in, throw a login page. if ($id == 0) { return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER')); } // Check for user profile completeness FD::checkCompleteProfile(); // Get the user's object. $user = FD::user($id); // If the user doesn't exist throw an error if (!$user->id) { return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER')); } // If the user is blocked or the user doesn't have community access if ($this->my->id != $user->id && $this->my->isBlockedBy($user->id) || !$user->hasCommunityAccess()) { return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER')); } // If the user is blocked, they should not be accessible if ($user->isBlock()) { return JError::raiseError(404, JText::_('COM_EASYSOCIAL_PROFILE_INVALID_USER')); } // Set the page properties $this->page->title($this->string->escape($user->getName())); $this->page->breadcrumb($this->string->escape($user->getName())); // Get the current user's privacy object $privacy = $this->my->getPrivacy(); // Let's test if the current viewer is allowed to view this profile. if ($this->my->id != $user->id && !$privacy->validate('profiles.view', $user->id, SOCIAL_TYPE_USER)) { $this->set('user', $user); return parent::display('site/profile/restricted'); } // Apply opengraph tags. FD::opengraph()->addProfile($user); // Do not assign badge if i view myself. if ($user->id != $this->my->id && $this->my->id) { // @badge: profile.view $badge = FD::badges(); $badge->log('com_easysocial', 'profile.view', $this->my->id, JText::_('COM_EASYSOCIAL_PROFILE_VIEWED_A_PROFILE')); } // Get the limit start $startLimit = $this->input->get('limitstart', 0, 'int'); // Determine if the current request is to load an app $appId = $this->input->get('appId', 0, 'int'); // Get the apps library. $appsLib = FD::apps(); // Default contents $contents = ''; // Load the app when necessary if ($appId) { $app = FD::table('App'); $app->load($appId); // Check if the user has access to this app if (!$app->accessible($user->id)) { FD::info()->set(false, JText::_('COM_EASYSOCIAL_PROFILE_APP_IS_NOT_INSTALLED_BY_USER'), SOCIAL_MSG_ERROR); $redirect = FRoute::profile(array('id' => $user->getAlias()), false); return $this->redirect($redirect); } // Set the page title $this->page->title(FD::string()->escape($user->getName()) . ' - ' . $app->get('title')); // Render the app contents $contents = $appsLib->renderView(SOCIAL_APPS_VIEW_TYPE_EMBED, 'profile', $app, array('userId' => $user->id)); } // Get the layout $layout = $this->input->get('layout', '', 'cmd'); // @since 1.3.7 // If layout is empty, means we want to get the default view // Previously timeline is always the default if (empty($appId) && empty($layout) && $filter != 'appFilter') { $defaultDisplay = $this->config->get('users.profile.display', 'timeline'); $layout = $defaultDisplay; } // Default variables $timeline = null; $newCover = false; // Viewing info of a user. if ($layout === 'about') { $showTimeline = false; $usersModel = FD::model('Users'); $steps = $usersModel->getAbout($user); // We should generate a canonical link if user is viewing the about section and the default page is about if ($this->config->get('users.profile.display') == 'about') { $this->page->canonical($user->getPermalink(false, true)); } if ($steps) { foreach ($steps as $step) { if ($step->active) { $theme = FD::themes(); $theme->set('fields', $step->fields); $contents = $theme->output('site/events/item.info'); } } } $this->set('infoSteps', $steps); } // Should we filter stream items by specific app types $appType = $this->input->get('filterid', '', 'string'); // If contents is still empty at this point, then we just get the stream items as the content if (empty($contents) || $filter == 'appFilter') { // Should the timeline be active $timeline = true; // Retrieve user's stream $theme = FD::themes(); // Get story $story = FD::story(SOCIAL_TYPE_USER); $story->target = $user->id; // Get the stream $stream = FD::stream(); //lets get the sticky posts 1st $stickies = $stream->getStickies(array('userId' => $user->id, 'limit' => 0)); if ($stickies) { $stream->stickies = $stickies; } $streamOptions = array('userId' => $user->id, 'nosticky' => true, 'startlimit' => $startLimit); if ($filter == 'appFilter') { $timeline = false; $streamOptions['actorId'] = $user->id; } if ($appType) { $streamOptions['context'] = $appType; // Should this be set now or later $stream->filter = 'custom'; } $stream->get($streamOptions); // Only registered users can access the story form if (!$this->my->guest) { $stream->story = $story; } // Set stream to theme $theme->set('stream', $stream); $contents = $theme->output('site/profile/default.stream'); } // Get user's cover object $cover = $user->getCoverData(); // If we're setting a cover $coverId = $this->input->get('cover_id', 0, 'int'); // Load cover photo if ($coverId) { $coverTable = FD::table('Photo'); $coverTable->load($coverId); // If the cover photo belongs to the user if ($coverTable->isMine()) { $newCover = $coverTable; } } $streamModel = FD::model('Stream'); // Get a list of application filters $appFilters = $streamModel->getAppFilters(SOCIAL_TYPE_USER); // Retrieve list of apps for this user $appsModel = FD::model('Apps'); $options = array('view' => 'profile', 'uid' => $user->id, 'key' => SOCIAL_TYPE_USER); $apps = $appsModel->getApps($options); $this->set('appFilters', $appFilters); $this->set('filterId', $appType); $this->set('timeline', $timeline); $this->set('newCover', $newCover); $this->set('cover', $cover); $this->set('contents', $contents); $this->set('appsLib', $appsLib); $this->set('apps', $apps); $this->set('activeApp', $appId); $this->set('privacy', $privacy); $this->set('user', $user); // Load the output of the profile. return parent::display('site/profile/default'); }
/** * Function post for create user record. * * @return void */ public function post() { $error_messages = array(); $fieldname = array(); $response = null; $validated = true; $userid = null; $data = array(); //$log_user = $this->plugin->get('user')->id; $app = JFactory::getApplication(); $data['username'] = $app->input->get('username', '', 'STRING'); $data['password'] = $app->input->get('password', '', 'STRING'); $data['name'] = $app->input->get('name', '', 'STRING'); $data['email'] = $app->input->get('email', '', 'STRING'); $data['enabled'] = $app->input->get('enabled', 1, 'INT'); $data['activation'] = $app->input->get('activation', 0, 'INT'); $data['app'] = $app->input->get('app_name', 'Easysocial App', 'STRING'); global $message; $eobj = new stdClass(); if ($data['username'] == '' || $data['password'] == '' || $data['name'] == '' || $data['email'] == '') { $eobj->status = false; $eobj->id = 0; $eobj->code = '403'; $eobj->message = 'Required data is empty'; $this->plugin->setResponse($eobj); return; } jimport('joomla.user.helper'); $authorize = JFactory::getACL(); $user = clone JFactory::getUser(); $user->set('username', $data['username']); $user->set('password', $data['password']); $user->set('name', $data['name']); $user->set('email', $data['email']); $user->set('block', $data['enabled']); $user->set('activation', $data['activation']); // Password encryption $salt = JUserHelper::genRandomPassword(32); $crypt = JUserHelper::getCryptedPassword($user->password, $salt); $user->password = "******"; // User group/type $user->set('id', ''); $user->set('usertype', 'Registered'); if (JVERSION >= '1.6.0') { $userConfig = JComponentHelper::getParams('com_users'); // Default to Registered. $defaultUserGroup = $userConfig->get('new_usertype', 2); $user->set('groups', array($defaultUserGroup)); } else { $user->set('gid', $authorize->get_group_id('', 'Registered', 'ARO')); } $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); //print_r($_POST);die("in api after save"); // True on success, false otherwise if (!$user->save()) { //$message = "not created because of " . $user->getError(); $message = $user->getError(); $eobj->status = false; $eobj->id = 0; $eobj->code = '403'; $eobj->message = $message; $this->plugin->setResponse($eobj); return; } else { /* // Auto registration if( $data['activation'] == 0) { $emailSubject = 'Email Subject for registration successfully'; $emailBody = 'Email body for registration successfully'; $return = JFactory::getMailer()->sendMail('sender email', 'sender name', $user->email, $emailSubject, $emailBody); } else if( $data['activation'] == 1) { $emailSubject = 'Email Subject for activate the account'; $emailBody = 'Email body for for activate the account'; $user_activation_url = JURI::base().JRoute::_('index.php?option=com_users&task=registration.activate&token=' . $user->activation, false); // Append this URL in your email body $return = JFactory::getMailer()->sendMail('sender email', 'sender name', $user->email, $emailSubject, $emailBody); } */ $mail_sent = $this->sendRegisterEmail($data); $easysocial = JPATH_ADMINISTRATOR . '/components/com_easysocial/easysocial.php'; //eb version if (JFile::exists($easysocial)) { $pobj = $this->createEsprofile($user->id); //$message = "created of username-" . $user->username .",send mail of details please check"; $message = "Congratulations! Your account has been created successfully"; } else { $message = "Congratulations! Your account has been created successfully"; } // Assign badge for the person. $badge = FD::badges(); $badge->log('com_easysocial', 'registration.create', $user->id, JText::_('COM_EASYSOCIAL_REGISTRATION_BADGE_REGISTERED')); } // #$this->plugin->setResponse($user->id); $userid = $user->id; // Result message //$result = array('user id ' => $userid, 'message' => $message); //$result = ($userid) ? $result : $message; $eobj->status = true; $eobj->id = $userid; $eobj->code = '200'; $eobj->message = $message; $this->plugin->setResponse($eobj); return; }
/** * Responsible to output the search layout. * * @access public * @return null * */ public function display($tpl = null) { // Check for user profile completeness FD::checkCompleteProfile(); // Get the current logged in user. $query = $this->input->get('q', '', 'default'); $q = $query; // Get the search type $type = $this->input->get('type', '', 'cmd'); // Load up the model $indexerModel = FD::model('Indexer'); // Retrieve a list of supported types $allowedTypes = $indexerModel->getSupportedType(); if (!in_array($type, $allowedTypes)) { $type = ''; } // Options $data = null; $types = null; $count = 0; $next_limit = ''; $limit = FD::themes()->getConfig()->get('search_limit'); // Get the search model $model = FD::model('Search'); $searchAdapter = FD::get('Search'); // Determines if finder is enabled $isFinderEnabled = JComponentHelper::isEnabled('com_finder'); if (!empty($query) && $isFinderEnabled) { jimport('joomla.application.component.model'); $lib = JPATH_ROOT . '/components/com_finder/models/search.php'; require_once $lib; if ($type) { JRequest::setVar('t', $type); } // Load up finder's model $finderModel = new FinderModelSearch(); $state = $finderModel->getState(); // Get the query // this line need to be here. so that the indexer can get the correct value $query = $finderModel->getQuery(); // When there is no terms match, check if smart search suggested any terms or not. if yes, lets use it. if (!$query->terms) { if (isset($query->included) && count($query->included) > 0) { $suggestion = ''; foreach ($query->included as $item) { if (isset($item->suggestion) && !empty($item->suggestion)) { $suggestion = $item->suggestion; } } if ($suggestion) { $app = JFactory::getApplication(); $input = $app->input; $input->request->set('q', $suggestion); // Load up the new model $finderModel = new FinderModelSearch(); $state = $finderModel->getState(); // this line need to be here. so that the indexer can get the correct value $query = $finderModel->getQuery(); } } } //reset the pagination state. $state->{'list.start'} = 0; $state->{'list.limit'} = $limit; $results = $finderModel->getResults(); $count = $finderModel->getTotal(); $pagination = $finderModel->getPagination(); if ($results) { $data = $searchAdapter->format($results, $query); $query = $finderModel->getQuery(); if (FD::isJoomla30()) { $pagination->{'pages.total'} = $pagination->pagesTotal; } if ($pagination->{'pages.total'} == 1) { $next_limit = '-1'; } else { $next_limit = $pagination->limitstart + $pagination->limit; } } // @badge: search.create // Assign badge for the person that initiated the friend request. $badge = FD::badges(); $badge->log('com_easysocial', 'search.create', $this->my->id, JText::_('COM_EASYSOCIAL_SEARCH_BADGE_SEARCHED_ITEM')); // get types $types = $searchAdapter->getTaxonomyTypes(); } // Set the page title FD::page()->title(JText::_('COM_EASYSOCIAL_PAGE_TITLE_SEARCH')); // Set the page breadcrumb FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_SEARCH')); $this->set('types', $types); $this->set('data', $data); $this->set('query', $q); $this->set('total', $count); $this->set('totalcount', $count); $this->set('next_limit', $next_limit); echo parent::display('site/search/default'); }
/** * 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); }
/** * Assign badges * * @since 1.0 * @access public * @param string * @return */ private function assignBadge($rule, $message, $creatorId = null) { $creator = FD::user($creatorId); $badge = FD::badges(); $state = $badge->log('com_content', $rule, $creator->id, $message); return $state; }
/** * 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); } }
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); }
/** * 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'); $app->load(array('element' => 'profiles', 'group' => SOCIAL_TYPE_USER)); $params = $app->getParams(); // If not allowed, we will not want to proceed here. if ($params->get('stream_register', true)) { // Get the stream library. $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 = Foundry::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')); 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(); // Get the email template. $mailTemplate = $mailer->getTemplate(); // Set recipient $mailTemplate->setRecipient($this->getName(), $this->email); // Set title $mailTemplate->setTitle($title); // Set the contents $mailTemplate->setTemplate('site/registration/approved', $params); // 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 a user to follow another user. * * @since 1.0 * @access public */ public function follow() { // Check for request forgeries. FD::checkToken(); // Ensure that the user needs to be logged in. FD::requireLogin(); // Get the current view. $view = $this->getCurrentView(); // Get the object identifier. $id = JRequest::getInt('id'); // Get the user that is being followed $user = FD::user($id); $type = JRequest::getVar('type'); $group = JRequest::getVar('group', SOCIAL_APPS_GROUP_USER); // Get the current logged in user. $my = FD::user(); // Load subscription table. $subscription = FD::table('Subscription'); // Get subscription library $subscriptionLib = FD::get('Subscriptions'); // User should never be allowed to follow themselves. if ($my->id == $id) { $view->setMessage(JText::_('COM_EASYSOCIAL_FOLLOWERS_NOT_ALLOWED_TO_FOLLOW_SELF'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__, $subscription); } // Determine if the current user is already a follower $isFollowing = $subscriptionLib->isFollowing($id, $type, $group, $my->id); // If it's already following, throw proper message if ($isFollowing) { $view->setMessage(JText::_('COM_EASYSOCIAL_SUBSCRIPTIONS_ERROR_ALREADY_FOLLOWING_USER'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__, $subscription); } // If the user isn't alreayd following, create a new subscription record. $subscription->uid = $id; $subscription->type = $type . '.' . $group; $subscription->user_id = $my->id; $state = $subscription->store(); if (!$state) { $view->setMessage($subscription->getError(), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__, $subscription); } // @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($subscription->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' => $id)); return $view->call(__FUNCTION__, $subscription); }
/** * 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; }
/** * 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; }
/** * Override parent's store method. * * @access public * @param bool $updateModified Update modified time if this is true. Default true. * @return bool True on success, false on error. */ public function store($updateModified = true) { if (empty($this->title)) { return false; } $isNew = empty($this->id) ? true : false; $now = FD::get('Date')->toMySQL(); // If script needs us to alter the modified date or if it's a new record, // ensure that the modified column contains proper values. if ($updateModified || empty($this->modified)) { $this->modified = $now; } if ($isNew) { // @badge: friends.list.create $badge = FD::badges(); $badge->log('com_easysocial', 'friends.list.create', $this->user_id, JText::_('COM_EASYSOCIAL_FRIENDS_BADGE_CREATED_FRIEND_LIST')); // @points: friends.list.create // Assign points when the user creates a new list. $points = FD::points(); $points->assign('friends.list.create', 'com_easysocial', $this->user_id); } return parent::store(); }