Esempio n. 1
0
 /**
  * Displays all albums from the site.
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function all($tpl = null)
 {
     // Check for user profile completeness
     FD::checkCompleteProfile();
     // Check if photos is enabled
     $this->checkFeature();
     // Set the page title
     $this->page->title(JText::_('COM_EASYSOCIAL_ALBUMS_ALL_ALBUMS'));
     // Set the breadcrumbs
     $this->page->breadcrumb(JText::_('COM_EASYSOCIAL_ALBUMS_ALL_ALBUMS'));
     // Get albums model
     $model = ES::model('Albums');
     $model->initStates();
     // Get the start limit from the request
     $startlimit = $this->input->get('limitstart', 0, 'int');
     // By default albums should be sorted by creation date.
     $sorting = $this->input->get('sort', 'created');
     if (!$startlimit) {
         $model->setState('limitstart', 0);
     }
     // Get a list of normal albums
     $options = array('pagination' => true, 'order' => 'a.assigned_date', 'direction' => 'DESC', 'core' => false);
     if ($sorting == 'alphabetical') {
         $options['order'] = 'a.title';
         $options['direction'] = 'ASC';
     }
     if ($sorting == 'popular') {
         $options['order'] = 'a.hits';
         $options['direction'] = 'DESC';
     }
     // Get the albums
     $albums = $model->getAlbums('', SOCIAL_TYPE_USER, $options);
     // Get the album pagination
     $pagination = $model->getPagination();
     $lib = FD::albums(FD::user()->id, SOCIAL_TYPE_USER);
     $this->set('sorting', $sorting);
     $this->set('lib', $lib);
     $this->set('albums', $albums);
     $this->set('pagination', $pagination);
     // Wrap it with the albums wrapper.
     echo parent::display('site/albums/all');
 }
Esempio n. 2
0
 /**
  * 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);
 }
Esempio n. 3
0
 /**
  * Retrieves a list of notification items.
  *
  * @since	1.0
  * @access	public
  * @param	bool	To aggregate the notification items or not.
  * @return	Array	An array of @SocialTableNotification
  */
 public function getItems($options = array())
 {
     $model = ES::model('Notifications');
     $items = $model->getItems($options);
     if (!$items) {
         return false;
     }
     // Retrieve applications and trigger onNotificationLoad
     $dispatcher = ES::dispatcher();
     $result = array();
     // Trigger apps
     foreach ($items as $item) {
         // Add a `since` column to the result so that user's could use the `since` time format.
         $item->since = FD::date($item->created)->toLapsed();
         $args = array(&$item);
         // @trigger onNotificationLoad
         $dispatcher->trigger(SOCIAL_APPS_GROUP_USER, 'onNotificationLoad', $args);
         // @trigger onNotificationLoad
         $dispatcher->trigger(SOCIAL_APPS_GROUP_GROUP, 'onNotificationLoad', $args);
         // @trigger onNotificationLoad
         $dispatcher->trigger(SOCIAL_APPS_GROUP_EVENT, 'onNotificationLoad', $args);
         // If an app lets us know that they want to exclude the stream, we should exclude it.
         if (isset($item->exclude) && $item->exclude) {
             continue;
         }
         // Let's format the item title.
         $this->formatItem($item);
         $result[] = $item;
     }
     // Group up items.
     if (isset($options['group']) && $options['group'] == SOCIAL_NOTIFICATION_GROUP_ITEMS) {
         $result = $this->group($result);
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Suggests a list of groups for a user.
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return
  */
 public function suggest()
 {
     // Check for request forgeries
     ES::checkToken();
     ES::requireLogin();
     // Get the search query
     $search = $this->input->get('search', '', 'word');
     // Get exclusion list
     $exclusion = $this->input->get('exclusion', array(), 'array');
     // Determines if the user is an admin
     $options = array('unpublished' => false, 'exclusion' => $exclusion);
     if ($this->my->isSiteAdmin()) {
         $options['unpublished'] = true;
     }
     // Load up the groups model
     $model = ES::model('Groups');
     $groups = $model->search($search, $options);
     return $this->view->call(__FUNCTION__, $groups);
 }
Esempio n. 5
0
 /**
  * Displays a the profile form when someone creates a new profile type or edits an existing profile.
  *
  * @since	1.0
  * @access	public
  * @param	SocialTableProfile	The profile object (Optional)
  * @return	null
  *
  * @author	Mark Lee <*****@*****.**>
  */
 public function form($profile = '')
 {
     // Get the profile id from the request.
     $id = $this->input->get('id', 0, 'int');
     // Add Joomla buttons here.
     $this->addButtons(__FUNCTION__);
     // Test if id is provided by the query string
     if (!$profile) {
         $profile = FD::table('Profile');
         if ($id) {
             $state = $profile->load($id);
             if (!$state) {
                 $this->info->set($this->getMessage());
                 return $this->redirect('index.php?option=com_easysocial&view=profiles');
             }
         }
     }
     // Set the structure heading here.
     $this->setHeading('COM_EASYSOCIAL_TOOLBAR_TITLE_NEW_PROFILE_TYPE');
     // If this is an edited profile, display the profile title.
     if (!empty($id)) {
         $this->setHeading($profile->get('title'));
     }
     $this->setDescription('COM_EASYSOCIAL_DESCRIPTION_PROFILES_FORM');
     // Default Values
     $defaultAvatars = array();
     // load frontend language so that the custom fields languages display properly.
     FD::language()->loadSite();
     // Only process the rest of the blocks of this is not a new item.
     if ($id) {
         // Get a list of users in this profile.
         $profilesModel = ES::model('Profiles');
         // Get default avatars for this profile type.
         $avatarsModel = ES::model('Avatars');
         $defaultAvatars = $avatarsModel->getDefaultAvatars($profile->id);
         // Get a list of available field apps
         $appsModel = ES::model('Apps');
         $defaultApps = $appsModel->getApps(array('type' => SOCIAL_APPS_TYPE_FIELDS, 'group' => SOCIAL_FIELDS_GROUP_USER, 'state' => SOCIAL_STATE_PUBLISHED));
         // Get a list of workflows for this profile type.
         $stepsModel = ES::model('Steps');
         $steps = $stepsModel->getSteps($profile->id, SOCIAL_TYPE_PROFILES);
         // Get a list of fields based on the id
         $fieldsModel = ES::model('Fields');
         $fields = $fieldsModel->getCustomFields(array('profile_id' => $profile->id, 'state' => 'all'));
         $data = array();
         // @field.triggers: onSample
         $lib = FD::fields();
         $lib->trigger('onSample', SOCIAL_FIELDS_GROUP_USER, $fields, $data, array($lib->getHandler(), 'getOutput'));
         // Create a temporary storage
         $tmpFields = array();
         // Group the fields to each workflow properly
         if ($steps) {
             foreach ($steps as $step) {
                 $step->fields = array();
                 if (!empty($fields)) {
                     foreach ($fields as $field) {
                         if ($field->step_id == $step->id) {
                             $step->fields[] = $field;
                         }
                         $tmpFields[$field->app_id] = $field;
                     }
                 }
             }
         }
         // We need to know the amount of core apps and used core apps
         // 1.3 Update, we split out unique apps as well
         $coreAppsCount = 0;
         $usedCoreAppsCount = 0;
         $uniqueAppsCount = 0;
         $usedUniqueAppsCount = 0;
         // hide the apps if it is a core app and it is used in the field
         if ($defaultApps) {
             foreach ($defaultApps as $app) {
                 $app->hidden = false;
                 // If app is core, increase the coreAppsCount counter
                 if ($app->core) {
                     $coreAppsCount++;
                 }
                 // If app is NOT core and unique, increase the coreAppsCount counter
                 // This is because core apps are definitely unique, so we do not want to include core apps here
                 if (!$app->core && $app->unique) {
                     $uniqueAppsCount++;
                 }
                 // Test if this app has already been assigned to the $tmpFields
                 if (isset($tmpFields[$app->id]) && $app->core) {
                     $usedCoreAppsCount++;
                     $app->hidden = true;
                 }
                 // Test if this app is NOT core and unique and has already been assigned
                 // This is because core apps are definitely unique, so we do not want to include core apps here
                 if (isset($tmpFields[$app->id]) && !$app->core && $app->unique) {
                     $usedUniqueAppsCount++;
                     $app->hidden = true;
                 }
             }
         }
         unset($tmpFields);
         // We need to know if there are any core apps remain
         $coreAppsRemain = $usedCoreAppsCount < $coreAppsCount;
         // We need to know if there are any unique apps remain
         $uniqueAppsRemain = $usedUniqueAppsCount < $uniqueAppsCount;
         // Render the access form.
         $accessModel = FD::model('Access');
         $accessForm = $accessModel->getForm($id, SOCIAL_TYPE_PROFILES, 'access', '', false);
         $this->set('accessForm', $accessForm);
         // Set the flag of coreAppsRemain
         $this->set('coreAppsRemain', $coreAppsRemain);
         // Set the flag of uniqueAppsRemain
         $this->set('uniqueAppsRemain', $uniqueAppsRemain);
         // Set the default apps to the template.
         $this->set('defaultApps', $defaultApps);
         // Set the steps for the template.
         $this->set('steps', $steps);
         // Set the fields to the template
         $this->set('fields', $fields);
         // Set the field group to the template
         $this->set('fieldGroup', SOCIAL_FIELDS_GROUP_USER);
         // Get the total number of users in the current profile.
         $membersCount = $profile->getMembersCount();
         // Set member's count to the template.
         $this->set('membersCount', $membersCount);
     }
     // Get a list of themes.
     $themesModel = FD::model('Themes');
     $themes = $themesModel->getThemes();
     // Get profile parameters
     $params = $profile->getParams();
     // Get default privacy
     $privacy = FD::get('Privacy', $profile->id, SOCIAL_PRIVACY_TYPE_PROFILES);
     // We need to hide the guest user group that is defined in com_users options.
     // Public group should also be hidden.
     $userOptions = JComponentHelper::getComponent('com_users')->params;
     $defaultRegistrationGroup = $userOptions->get('new_usertype');
     $guestGroup = array(1, $userOptions->get('guest_usergroup'));
     // Set the default registration group for new items
     if (!$id) {
         $profile->gid = $defaultRegistrationGroup;
     }
     // Get the active tab
     $activeTab = $this->input->get('activeTab', 'settings', 'word');
     // Get a list of default groups
     $defaultGroups = $profile->getDefaultGroups();
     // Exclude groups from being suggested
     $excludeGroups = array();
     if ($defaultGroups) {
         foreach ($defaultGroups as $group) {
             $excludeGroups[] = (int) $group->id;
         }
     }
     $this->set('excludeGroups', $excludeGroups);
     $this->set('defaultGroups', $defaultGroups);
     $this->set('activeTab', $activeTab);
     $this->set('defaultAvatars', $defaultAvatars);
     $this->set('guestGroup', $guestGroup);
     $this->set('id', $id);
     $this->set('themes', $themes);
     $this->set('param', $params);
     $this->set('profile', $profile);
     $this->set('privacy', $privacy);
     echo parent::display('admin/profiles/default.form');
 }
Esempio n. 6
0
 /**
  * Checks for new friend requests
  *
  * @since	1.0
  * @access	public
  */
 public function getSystemCounter()
 {
     // Check for request forgeries.
     FD::checkToken();
     // Ensure that user is logged in
     FD::requireLogin();
     $model = ES::model('Notifications');
     $options = array('unread' => true, 'target' => array('id' => $this->my->id, 'type' => SOCIAL_TYPE_USER));
     $total = $model->getCount($options);
     return $this->view->call(__FUNCTION__, $total);
 }