Пример #1
0
 /**
  * subscription toggle.
  *
  * @since 1.0
  * @access public
  */
 public function toggle()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Ensure that the user needs to be logged in.
     FD::requireLogin();
     $uid = JRequest::getInt('uid');
     $type = JRequest::getVar('type');
     $group = JRequest::getVar('group', SOCIAL_APPS_GROUP_USER);
     $notify = JRequest::getVar('notify', '0');
     $my = FD::user();
     $view = FD::view('Subscriptions', false);
     $subscribe = FD::get('Subscriptions');
     $isFollowed = $subscribe->isFollowing($uid, $type, $group, $my->id);
     $verb = $isFollowed ? 'unfollow' : 'follow';
     $state = '';
     if ($isFollowed) {
         // unsubscribe user.
         $state = $subscribe->unfollow($uid, $type, $group, $my->id);
     } else {
         $state = $subscribe->follow($uid, $type, $group, $my->id, $notify);
     }
     if (!$state) {
         FD::logError(__FILE__, __LINE__, 'Subscription: Unable to ' . $verb . ' the stream item because of the error message ' . $subscribe->getError());
         // Set the view with error
         $view->setMessage($subscribe->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, $verb);
     }
     return $view->call(__FUNCTION__, $verb);
 }
Пример #2
0
 /**
  * Renders a sample data given the application id.
  *
  * @since	1.0
  * @access	public
  * @return
  */
 public function renderSample()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Load the view
     $view = FD::view('Fields');
     // Get fields library.
     $lib = FD::fields();
     // Get the group from the query.
     $group = JRequest::getWord('group', SOCIAL_FIELDS_GROUP_USER);
     // Get the application id from the query.
     $id = JRequest::getInt('appid');
     // Get the profile id
     $profileId = JRequest::getInt('profileid');
     // If id is not passed in, we need to throw an error.
     if (!$id) {
         FD::logError(__FILE__, __LINE__, 'FIELDS: Application id $appid is invalid.');
         $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILES_FORM_FIELDS_INVALID_APPLICATION'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, false);
     }
     $field = FD::table('Field');
     $field->app_id = $id;
     $app = $field->getApp();
     if (!$app) {
         FD::logError(__FILE__, __LINE__, 'FIELDS: Application id $appid is invalid.');
         $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILES_FORM_FIELDS_INVALID_APPLICATION'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__, false);
     }
     // Manually push in the profile id
     $field->profile_id = $profileId;
     $field->element = $app->element;
     // Need to be placed in an array as it is being passed as reference.
     $fields = array(&$field);
     // Prepare the data to be passed to the application
     $data = array();
     // Load language string.
     FD::language()->loadSite();
     // Process onSample trigger
     $lib->trigger('onSample', $group, $fields, $data);
     $field = $fields[0];
     // Call the view.
     return $view->call(__FUNCTION__, $field);
 }
Пример #3
0
 /**
  * Processes the saving of the settings.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @author	Mark Lee <*****@*****.**>
  */
 public function save()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Since there are more than 1 tasks are linked here, get the appropriate task here.
     $task = $this->getTask();
     $method = $task;
     $page = JRequest::getVar('page', '');
     $view = FD::view('Settings');
     // Get the posted data.
     $post = JRequest::get('POST');
     // Only load the config that is already stored.
     // We don't want to store everything as we want to have hidden settings.
     $configTable = FD::table('Config');
     $config = FD::registry();
     if ($configTable->load('site')) {
         $config->load($configTable->value);
     }
     $token = FD::token();
     if (!$post) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_INVALID_POST_DATA'), SOCIAL_MSG_ERROR);
         return $view->call($method, $page);
     }
     // Some post vars are unwanted / unecessary because of the hidden inputs.
     $ignored = array('task', 'option', 'controller', 'view', $token, 'page');
     $updatedUserIndexing = false;
     foreach ($post as $key => $value) {
         if (!in_array($key, $ignored)) {
             // Replace all _ with .
             $key = str_ireplace('_', '.', $key);
             // If the value is an array, and there's only 1 index,
             // the input might need to be checked if it needs to be in an array form.
             // E.g: some,values,here,should,be,an,array
             if (is_array($value) && count($value) == 1) {
                 $value = FD::makeArray($value[0], ',');
             }
             if ($key == 'users.indexer.name' || $key == 'users.indexer.email') {
                 $previousVal = $config->get($key);
                 if ($previousVal != $value) {
                     $updatedUserIndexing = true;
                 }
             }
             $config->set($key, $value);
         }
     }
     // Convert the config object to a json string.
     $jsonString = $config->toString();
     $configTable = FD::table('Config');
     if (!$configTable->load('site')) {
         $configTable->type = 'site';
     }
     $configTable->set('value', $jsonString);
     // Try to store the configuration.
     if (!$configTable->store()) {
         $view->setMessage($configTable->getError(), SOCIAL_MSG_ERROR);
         return $view->call($method, $page);
     }
     // Check if any of the configurations are stored as non local
     if (($config->get('storage.photos') == 'amazon' || $config->get('storage.conversations') == 'amazon') && $config->get('storage.amazon.bucket') == '') {
         // Initialize the storage
         $bucket = FD::storage('Amazon')->init();
         $config->set('storage.amazon.bucket', $bucket);
         $configTable->set('value', $config->toString());
         $configTable->store();
     }
     $message = $updatedUserIndexing ? JText::_('COM_EASYSOCIAL_SETTINGS_SAVED_SUCCESSFULLY_WITH_USER_INDEXING_UPDATED') : JText::_('COM_EASYSOCIAL_SETTINGS_SAVED_SUCCESSFULLY');
     $view->setMessage($message, SOCIAL_MSG_SUCCESS);
     return $view->call($method, $page);
 }
Пример #4
0
 /**
  * Hides a stream item.
  *
  * @since	1.0
  * @access	public
  */
 public function unhideapp()
 {
     // Check for request forgeries!
     FD::checkToken();
     FD::requireLogin();
     $context = JRequest::getVar('context');
     $my = FD::user();
     $view = FD::view('Stream', false);
     // Get the view.
     $view = FD::view('Stream', false);
     if (empty($context)) {
         FD::logError(__FILE__, __LINE__, 'STREAM: Unable to unhide stream because app provided is invalid or not found.');
         $view->setErrors(JText::_('COM_EASYSOCIAL_ERROR_UNABLE_TO_LOCATE_APP'));
         return $view->call(__FUNCTION__);
     }
     $model = FD::model('Stream');
     $state = $model->unhideapp($context, $my->id);
     if (!$state) {
         $view->setErrors(JText::_('COM_EASYSOCIAL_STREAM_FAILED_UNHIDE'));
         return $view->call(__FUNCTION__);
     }
     return $view->call(__FUNCTION__);
 }
Пример #5
0
 public function unhideactor()
 {
     // Check for request forgeries!
     FD::checkToken();
     FD::requireLogin();
     $actor = JRequest::getVar('actor');
     $id = JRequest::getInt('id');
     // Get the view.
     $view = FD::view('Activities', false);
     $model = FD::model('Activities');
     $state = $model->unhideactor($actor, $id);
     if (!$state) {
         $view->setErrors(JText::_('COM_EASYSOCIAL_STREAM_FAILED_UNHIDE'));
         return $view->call(__FUNCTION__);
     }
     return $view->call(__FUNCTION__);
 }
Пример #6
0
 /**
  * Returns a list of conversations.
  *
  * @since	1.0
  * @access	public
  */
 public function getCount()
 {
     // 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 current view.
     $view = FD::view('Conversations', false);
     // Get the model
     $model = FD::model('Conversations');
     // Get the mail box from the request.
     $mailbox = JRequest::getWord('mailbox');
     // Get the conversations for this inbox type.
     $total = $model->getNewCount($my->id, $mailbox);
     return $view->call(__FUNCTION__, $total);
 }
Пример #7
0
 /**
  * Cancels a friend request.
  *
  * @since	1.0
  * @access	public
  */
 public function cancelRequest()
 {
     // Check for request forgeries
     FD::checkToken();
     // Guests shouldn't be here.
     FD::requireLogin();
     // Get the current logged in user.
     $my = FD::user();
     // Get the current view.
     $view = FD::view('Friends', false);
     // Get the friend id.
     $id = JRequest::getInt('id');
     // Get the model
     $friends = FD::model('Friends');
     $table = FD::table('Friend');
     $table->load($id);
     if (!$id || !$table->id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Check if the user is allowed to cancel the request.
     if (!$table->isInitiator()) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_FRIENDS_NOT_ALLOWED_TO_CANCEL_REQUEST'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Try to cancel the request.
     $state = $friends->cancel($id);
     if (!$state) {
         $view->setMessage($friends->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // Prepare the dispatcher
     FD::apps()->load(SOCIAL_TYPE_USER);
     $dispatcher = FD::dispatcher();
     $args = array(&$table);
     // @trigger: onFriendCancelRequest
     $dispatcher->trigger(SOCIAL_TYPE_USER, 'onFriendCancelRequest', $args);
     return $view->call(__FUNCTION__, $id);
 }
Пример #8
0
 /**
  * This adds information about the current profile that the user selected during registration.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	null
  */
 public function selectType()
 {
     $config = FD::config();
     $view = FD::view('Registration', false);
     // @task: Ensure that registrations is enabled.
     if (!$config->get('registrations.enabled')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_ERROR_REGISTRATION_DISABLED', SOCIAL_MSG_ERROR));
         return $view->call(__FUNCTION__);
     }
     $id = JRequest::getInt('profile_id', 0);
     // If there's no profile id selected, throw an error.
     if (!$id) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_ERROR_REGISTRATION_EMPTY_PROFILE_ID'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     // @task: Let's set some info about the profile into the session.
     $session = JFactory::getSession();
     $session->set('profile_id', $id, SOCIAL_SESSION_NAMESPACE);
     // @task: Try to load more information about the current registration procedure.
     $registration = FD::table('Registration');
     $registration->load($session->getId());
     $registration->profile_id = $id;
     // When user accesses this page, the following will be the first page
     $registration->set('step', 1);
     // Add the first step into the accessible list.
     $registration->addStepAccess(1);
     $registration->store();
     // After a profile type is selected, ensure that the cache are cleared.
     $cache = JFactory::getCache();
     $cache->clean();
     // Check in the session if quick is flagged as true
     if ($session->get('quick', false, SOCIAL_SESSION_NAMESPACE)) {
         return $this->quickRegister();
     }
     return $view->call(__FUNCTION__);
 }
Пример #9
0
 /**
  * Some desc
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function indexing()
 {
     $view = FD::view('Indexer', true);
     $max = JRequest::getVar('max', 0);
     $indexer = FD::get('Indexer');
     $tmax = $indexer->reindex();
     if (empty($max)) {
         $max = $tmax;
     }
     if (empty($max)) {
         $view->call('indexing', -1, '100');
         return;
     }
     $progress = ($max - $tmax) * 100 / $max;
     $progress = round($progress);
     if ($progress >= 100) {
         $progress = 100;
         $max = -1;
     }
     $view->call('indexing', $max, $progress);
 }
Пример #10
0
 /**
  * Scans for rules throughout the site.
  *
  * @since	1.0
  * @access	public
  */
 public function scan()
 {
     // Check for request forgeries
     FD::checkToken();
     // Get the allowed rule scan sections
     $config = FD::config();
     // Retrieve info lib.
     $info = FD::info();
     // Retrieve the view.
     $view = FD::view('Privacy', true);
     // Get the current path that we should be searching for.
     $file = JRequest::getVar('file', '');
     // Log errors when invalid data is passed in.
     if (empty($file)) {
         FD::logError(__FILE__, __LINE__, 'Privacy Scan: Invalid file path given to scan.');
     }
     // Retrieve the points model to scan for the path
     $model = FD::model('Privacy');
     $obj = new stdClass();
     // Format the output to display the relative path.
     $obj->file = str_ireplace(JPATH_ROOT, '', $file);
     $obj->rules = $model->install($file);
     return $view->call(__FUNCTION__, $obj);
 }
Пример #11
0
 public function getRawComment()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Only registered users are allowed here.
     FD::requireLogin();
     // Get the view
     $view = FD::view('comments', false);
     // Check for permission first
     $access = FD::access();
     if (!$access->allowed('comments.read')) {
         $view->setMessage(JText::_('COM_EASYSOCIAL_COMMENTS_NOT_ALLOWED_TO_READ'), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     $id = JRequest::getInt('id', 0);
     $table = FD::table('comments');
     $state = $table->load($id);
     if (!$state) {
         $view->setMessage($table->getError(), SOCIAL_MSG_ERROR);
         return $view->call(__FUNCTION__);
     }
     $comment = $table->comment;
     // IMPORTANT:
     // No escaping required here because JS side is doing .val to set the value, and .val is safe from xss
     $view->call(__FUNCTION__, $comment);
 }
Пример #12
0
 public function browse()
 {
     FD::checkToken();
     FD::requireLogin();
     $pid = JRequest::getInt('pid', 1);
     $pItemId = JRequest::getInt('pItemId', 0);
     $userIds = JRequest::getString('userIds', '');
     $users = array();
     if ($pItemId) {
         $model = FD::model('Privacy');
         $users = $model->getPrivacyCustom($pItemId, 'item');
     } else {
         if (empty($pItemId) && !empty($userIds)) {
             $tmpData = explode(',', $userIds);
             foreach ($tmpData as $data) {
                 if (!empty($data)) {
                     $user = new stdClass();
                     $user->user_id = $data;
                     $users[] = $user;
                 }
             }
         }
     }
     $view = FD::view('Privacy', false);
     return $view->call(__FUNCTION__, $users);
 }
Пример #13
0
 /**
  * Discover .points files from the site.
  *
  * @since	1.0
  * @access	public
  * @return
  */
 public function discoverFiles()
 {
     FD::checkToken();
     // Retrieve the view.
     $view = FD::view('Badges');
     // Retrieve the points model to scan for the path
     $model = FD::model('Badges');
     // Get the list of paths that may store points
     $config = FD::config();
     $paths = $config->get('badges.paths');
     // Result set.
     $files = array();
     foreach ($paths as $path) {
         $data = $model->scan($path);
         foreach ($data as $file) {
             $files[] = $file;
         }
     }
     // Return the data back to the view.
     return $view->call(__FUNCTION__, $files);
 }
Пример #14
0
 /**
  * Save the custom fields.
  *
  * @since	1.0
  * @access	public
  */
 public function createBlankProfile()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Create the new profile
     $newProfile = FD::table('Profile');
     $newProfile->title = 'temp';
     $newProfile->createBlank();
     $id = $newProfile->id;
     FD::view('Profiles')->call(__FUNCTION__, $id);
 }
Пример #15
0
 /**
  * Allows caller to retrieve saved search results
  *
  * @since	1.2
  * @access	public
  */
 public function getFilterResults()
 {
     // Check for request forgeries.
     FD::checkToken();
     // In order to access the dashboard apps, user must be logged in.
     FD::requireLogin();
     $showNew = false;
     $config = FD::config();
     $view = FD::view('Search', false);
     $fid = JRequest::getVar('fid', '');
     $fname = '';
     $data['criteria'] = '';
     $data['match'] = 'all';
     $data['avatarOnly'] = 0;
     $data['sort'] = $config->get('users.advancedsearch.sorting', 'default');
     $data['total'] = 0;
     $data['results'] = null;
     $data['nextlimit'] = null;
     $library = FD::get('AdvancedSearch');
     // this is doing new search
     $options = array();
     $options['showPlus'] = true;
     $displayOptions = array();
     if ($fid) {
         // lets get the criteria from db.
         $filter = FD::table('SearchFilter');
         $filter->load($fid);
         $fname = $filter->title;
         // data saved as json format. so we need to decode it.
         //
         // var_dump( $filter->filter  );
         $dataFilter = FD::json()->decode($filter->filter);
         $values = array();
         $values['criterias'] = isset($dataFilter->{'criterias[]'}) ? $dataFilter->{'criterias[]'} : '';
         $values['datakeys'] = isset($dataFilter->{'datakeys[]'}) ? $dataFilter->{'datakeys[]'} : '';
         $values['operators'] = isset($dataFilter->{'operators[]'}) ? $dataFilter->{'operators[]'} : '';
         $values['conditions'] = isset($dataFilter->{'conditions[]'}) ? $dataFilter->{'conditions[]'} : '';
         // we need check if the item passed in is array or not. if not, make it an array.
         if (!is_array($values['criterias'])) {
             $values['criterias'] = array($values['criterias']);
         }
         if (!is_array($values['datakeys'])) {
             $values['datakeys'] = array($values['datakeys']);
         }
         if (!is_array($values['operators'])) {
             $values['operators'] = array($values['operators']);
         }
         if (!is_array($values['conditions'])) {
             $values['conditions'] = array($values['conditions']);
         }
         // perform search
         $values['match'] = isset($dataFilter->matchType) ? $dataFilter->matchType : 'all';
         $values['avatarOnly'] = isset($dataFilter->avatarOnly) ? true : false;
         $values['sort'] = isset($dataFilter->sort) ? $dataFilter->sort : $config->get('users.advancedsearch.sorting', 'default');
         $results = null;
         $total = 0;
         $nextlimit = null;
         if ($values['criterias']) {
             $results = $library->search($values);
             $displayOptions = $library->getDisplayOptions();
             $total = $library->getTotal();
             $nextlimit = $library->getNextLimit();
         }
         $criteriaHTML = $library->getCriteriaHTML($options, $values);
         if (!$criteriaHTML) {
             // this is doing new search
             $showNew = true;
         }
         $data['criteria'] = $criteriaHTML;
         $data['match'] = $values['match'];
         $data['avatarOnly'] = $values['avatarOnly'];
         $data['sort'] = $values['sort'];
         $data['total'] = $total;
         $data['results'] = $results;
         $data['nextlimit'] = $nextlimit;
     } else {
         $showNew = true;
     }
     $data['displayOptions'] = $displayOptions;
     if ($showNew) {
         $criteriaHTML = $library->getCriteriaHTML($options);
         $data['criteria'] = $criteriaHTML;
     }
     return $view->call(__FUNCTION__, $fid, $data);
 }
Пример #16
0
 public function loadmore()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Ensure that user is logged in
     FD::requireLogin();
     $view = FD::view('Notifications', false);
     $user = FD::user();
     $config = FD::config();
     $paginationLimit = $config->get('notifications.general.pagination');
     $startlimit = JRequest::getInt('startlimit');
     // Get notifications model.
     $options = array('target_id' => $user->id, 'target_type' => SOCIAL_TYPE_USER, 'group' => SOCIAL_NOTIFICATION_GROUP_ITEMS, 'limit' => $paginationLimit, 'startlimit' => $startlimit);
     $lib = FD::notification();
     $items = $lib->getItems($options);
     $groupCnt = count($items);
     $recurvCnt = count($items, COUNT_RECURSIVE);
     $actualCnt = $recurvCnt - $groupCnt;
     $nextlimit = $startlimit + $paginationLimit;
     if ($actualCnt < $paginationLimit) {
         $nextlimit = -1;
     }
     return $view->call(__FUNCTION__, $items, $nextlimit);
 }