/** * Displays the registration request * * @since 1.3 * @access public * @param string * @return */ public function request() { $id = $this->input->getInt('id'); $table = JTable::getInstance('Module'); $table->load($id); FD::language()->load('mod_easysocial_registration_requester', JPATH_SITE); $params = FD::registry($table->params); $profileId = $params->get('profile_id'); // If there's no profile id, then we automatically assign the default profile id if (empty($profileId)) { $profileModel = FD::model('profiles'); $defaultProfile = $profileModel->getDefaultProfile(); $profileId = $defaultProfile->id; } $fieldsModel = FD::model('fields'); $options = array('visible' => SOCIAL_PROFILES_VIEW_MINI_REGISTRATION, 'profile_id' => $profileId); $fields = $fieldsModel->getCustomFields($options); if (!empty($fields)) { FD::language()->loadAdmin(); $fieldsLib = FD::fields(); $session = JFactory::getSession(); $registration = FD::table('Registration'); $registration->load($session->getId()); $data = $registration->getValues(); $args = array(&$data, &$registration); $fieldsLib->trigger('onRegisterMini', SOCIAL_FIELDS_GROUP_USER, $fields, $args); } $theme = FD::themes(); $theme->set('params', $params); $theme->set('config', FD::config()); $theme->set('fields', $fields); $output = $theme->output('site/registration/dialog.request'); return $this->ajax->resolve($output); }
public function display($tpl = null) { $auth = JRequest::getString('auth'); // Get the current logged in user's information $model = FD::model('Users'); $id = $model->getUserIdFromAuth($auth); $userId = JRequest::getInt('userid'); // If user id is not passed in, return logged in user if (!$userId) { $userId = $id; } // If we still can't find user's details, throw an error if (!$userId) { $this->set('code', 403); $this->set('message', JText::_('Invalid user id provided.')); return parent::display(); } $me = FD::user($id); $user = FD::user($userId); $this->set('id', $userId); $this->set('isself', $id == $userId); $this->set('isfriend', $user->isFriends($id)); $this->set('isfollower', $user->isFollowed($id)); $this->set('username', $user->username); $this->set('friend_count', $user->getTotalFriends()); $this->set('follower_count', $user->getTotalFollowing()); $this->set('badges', $user->getTotalBadges()); $this->set('points', $user->getPoints()); $this->set('avatar_thumb', $user->getAvatar()); $birthday = $user->getFieldValue('BIRTHDAY'); if (!empty($birthday)) { $this->set('age', $birthday->value->toAge()); } $gender = $user->getFieldValue('GENDER'); $this->set('gender', !empty($gender) ? $gender->data : 0); // Prepare DISPLAY custom fields FD::language()->loadAdmin(); // FD::apps()->loadAllLanguages(); $steps = FD::model('steps')->getSteps($user->profile_id, SOCIAL_TYPE_PROFILES, SOCIAL_PROFILES_VIEW_DISPLAY); $fields = FD::model('fields')->getCustomFields(array('profile_id' => $user->profile_id, 'data' => true, 'dataId' => $user->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_DISPLAY)); $library = FD::fields(); $args = array(&$user); $library->trigger('onGetValue', SOCIAL_FIELDS_GROUP_USER, $fields, $args); // Get the step mapping first $profileSteps = array(); foreach ($steps as $step) { $profileSteps[$step->id] = JText::_($step->title); } $profileFields = array(); foreach ($fields as $field) { $value = (string) $field->value; if (!empty($value)) { $data = array('group_id' => $field->step_id, 'group_name' => $profileSteps[$field->step_id], 'field_id' => $field->id, 'field_name' => JText::_($field->title), 'field_value' => (string) $field->value); $profileFields[] = $data; } } $this->set('more_info', $profileFields); $this->set('code', 200); parent::display(); }
/** * Responsible to display the generic login form. * * @since 1.0 * @access public */ public function display($tpl = null) { $my = FD::user(); // If user is already logged in, they should not see this page. if ($my->id > 0) { return $this->redirect(FRoute::dashboard(array(), false)); } // Add page title FD::page()->title(JText::_('COM_EASYSOCIAL_LOGIN_PAGE_TITLE')); // Add breadcrumb FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_LOGIN_PAGE_BREADCRUMB')); // Facebook codes. $facebook = FD::oauth('Facebook'); $config = FD::config(); $loginMenu = $config->get('general.site.login'); // Get any callback urls. $return = FD::getCallback(); // If return value is empty, always redirect back to the dashboard if (!$return) { // Determine if there's a login redirection $urlFromCaller = FD::input()->getVar('return', ''); if ($urlFromCaller) { $return = $urlFromCaller; } else { if ($loginMenu != 'null') { $return = FRoute::getMenuLink($loginMenu); } else { $return = FRoute::dashboard(array(), false); } $return = base64_encode($return); } } else { $return = base64_encode($return); } if ($config->get('registrations.enabled')) { $profileId = $config->get('registrations.mini.profile', 'default'); if ($profileId === 'default') { $profileId = Foundry::model('profiles')->getDefaultProfile()->id; } $options = array('visible' => SOCIAL_PROFILES_VIEW_MINI_REGISTRATION, 'profile_id' => $profileId); $fieldsModel = Foundry::model('fields'); $fields = $fieldsModel->getCustomFields($options); if (!empty($fields)) { FD::language()->loadAdmin(); $fieldsLib = FD::fields(); $session = JFactory::getSession(); $registration = FD::table('Registration'); $registration->load($session->getId()); $data = $registration->getValues(); $args = array(&$data, &$registration); $fieldsLib->trigger('onRegisterMini', SOCIAL_FIELDS_GROUP_USER, $fields, $args); $this->set('fields', $fields); } } $this->set('return', $return); $this->set('facebook', $facebook); return parent::display('site/login/default'); }
public function verifyFieldsData($keywords, $userId) { // return variable $content = ''; // get customfields. $fieldsLib = FD::fields(); $fieldModel = FD::model('Fields'); $fieldsResult = array(); $options = array(); $options['data'] = true; $options['dataId'] = $userId; $options['dataType'] = SOCIAL_TYPE_USER; $options['searchable'] = 1; //todo: get customfields. $fields = $fieldModel->getCustomFields($options); if (count($fields) > 0) { //foreach( $fields as $item ) foreach ($fields as $field) { $userFieldData = isset($field->data) ? $field->data : ''; $args = array($userId, $keywords, $userFieldData); $f = array(&$field); $dataResult = $fieldsLib->trigger('onIndexerSearch', SOCIAL_FIELDS_GROUP_USER, $f, $args); if ($dataResult !== false && count($dataResult) > 0) { $fieldsResult[] = $dataResult[0]; } } $contentSnapshot = array(); $totalReturnFields = count($fieldsResult); $invalidCnt = 0; if ($fieldsResult) { // we need to go through each one to see if any of the result returned is a false or not. // false mean, the user canot view the fields. // this also mean, the user canot view the searched item. foreach ($fieldsResult as $fr) { if ($fr == -1) { $invalidCnt++; } else { if (!empty($fr)) { $contentSnapshot[] = $fr; } } } if ($invalidCnt == $totalReturnFields) { return -1; } } if ($contentSnapshot) { $content = implode('<br />', $contentSnapshot); } } return $content; }
/** * Responsible to display the generic login form via ajax * * @since 1.0 * @access public */ public function form($tpl = null) { $ajax = FD::ajax(); $my = FD::user(); // If user is already logged in, they should not see this page. if ($my->id > 0) { $this->setMessage(JText::_('COM_EASYSOCIAL_LOGIN_ALREADY_LOGGED_IN'), SOCIAL_MSG_ERROR); return $ajax->reject($this->getMessage()); } // Facebook codes. $facebook = FD::oauth('Facebook'); // Get any callback urls. $return = FD::getCallback(); // If return value is empty, always redirect back to the dashboard if (!$return) { $return = FRoute::dashboard(array(), false); } // Determine if there's a login redirection $config = FD::config(); $loginMenu = $config->get('general.site.login'); if ($loginMenu != 'null') { $return = FD::get('toolbar')->getRedirectionUrl($loginMenu); } $return = base64_encode($return); $this->set('return', $return); $this->set('facebook', $facebook); if ($config->get('registrations.enabled')) { $profileId = $config->get('registrations.mini.profile', 'default'); if ($profileId === 'default') { $profileId = Foundry::model('profiles')->getDefaultProfile()->id; } $options = array('visible' => SOCIAL_PROFILES_VIEW_MINI_REGISTRATION, 'profile_id' => $profileId); $fieldsModel = FD::model('Fields'); $fields = $fieldsModel->getCustomFields($options); if (!empty($fields)) { FD::language()->loadAdmin(); $fieldsLib = FD::fields(); $session = JFactory::getSession(); $registration = FD::table('Registration'); $registration->load($session->getId()); $data = $registration->getValues(); $args = array(&$data, &$registration); $fieldsLib->trigger('onRegisterMini', SOCIAL_FIELDS_GROUP_USER, $fields, $args); $this->set('fields', $fields); } } $contents = parent::display('site/login/dialog.login'); return $ajax->resolve($contents); }
/** * Triggers the cron service * * @since 1.0 * @access public * @param string * @return */ public function execute() { $config = FD::config(); // Check if we need a secure phrase. $requirePhrase = $config->get('general.cron.secure'); $storedPhrase = $config->get('general.cron.key'); $phrase = JRequest::getVar('phrase', ''); if ($requirePhrase && empty($phrase) || $requirePhrase && $storedPhrase != $phrase) { $this->setStatus('failed'); $this->output(JText::_('COM_EASYSOCIAL_CRONJOB_PASSPHRASE_INVALID')); return $this->render(); } // Data to be passed to the triggers. $data = array(); // Array of states $states = array(); // @trigger: fields.onBeforeCronExecute // Retrieve custom fields for the current step $fieldsModel = FD::model('Fields'); $customFields = $fieldsModel->getCustomFields(array('appgroup' => SOCIAL_TYPE_USER)); $fields = FD::fields(); $fields->trigger('onCronExecute', SOCIAL_TYPE_USER, $customFields, $data); // @trigger: apps.onBeforeCronExecute $apps = FD::apps(); $dispatcher = FD::dispatcher(); $dispatcher->trigger(SOCIAL_TYPE_USER, 'onCronExecute', $data); // Load up files in hooks $this->hook($states); if (!empty($states)) { foreach ($states as $state) { $this->output($state); } } // Perform maintenance $maintenance = FD::get('Maintenance'); $maintenance->cleanup(); $this->render(); }
/** * Resolve a given POSIX path. * * <code> * <?php * // This would translate to administrator/components/com_easysocial/controllers/fields.php * FD::resolve( 'ajax:/admin/controllers/fields/renderSample' ); * * // This would translate to components/com_easysocial/controllers/dashboard.php * FD::resolve( 'ajax:/site/controllers/dashboard/someMethod' ); * ?> * </code> * * @since 1.0 * @access public * @param string The posix path to lookup for. * @return string The translated path */ public static function resolveNamespace($namespace) { // Split the paths. $parts = explode('/', $namespace); $location = $parts[0]; $config = FD::config(); // Remove the location from parts. array_shift($parts); // Get the absolute path of the initial location $path = $location == 'admin' ? SOCIAL_ADMIN : SOCIAL_SITE; // Get the method to be invoked. $method = array_pop($parts); if ($location == 'site' || $location == 'admin') { // Determine if this is a view or controller. if ($parts[0] == 'controllers') { $path = $path . '/' . implode('/', $parts) . '.php'; } else { $path = $path . '/' . implode('/', $parts) . '/view.ajax.php'; } } if ($location == 'apps') { $group = $parts[0]; $element = $parts[1]; $type = $parts[2]; $typeFile = $parts[3]; // E.g: apps:/user/tasks/views/viewName/functionName if ($type == 'views') { $path = SOCIAL_APPS . '/' . $group . '/' . $element . '/views/' . $typeFile . '/view.ajax.php'; } // E.g: apps:/user/tasks/controllers/tasks/functionName if ($type == 'controllers') { // Import dependencies. FD::import('admin:/includes/apps/dependencies'); $path = SOCIAL_APPS . '/' . $group . '/' . $element . '/controllers/' . $typeFile . '.php'; } } if ($location == 'fields') { // This is the field group. E.g: users , groups etc. $group = $parts[0]; // This is the field element. $element = $parts[1]; $path = SOCIAL_FIELDS . '/' . $group . '/' . $element . '/ajax.php'; } // Get the arguments from the query string if there is any. $args = JRequest::getVar('args', ''); $ajax = FD::ajax(); // Check that the file exists. jimport('joomla.filesystem.file'); if (!JFile::exists($path)) { $ajax->reject(JText::sprintf('The file %1s does not exist.', $namespace)); return $ajax->send(); } // Include the path. include_once $path; // We need to know the name of the class before we can instantiate it. switch ($location) { case 'fields': // This is the group $group = $parts[0]; // We know the second segment is always the element. $element = $parts[1]; // Construct parameters $config = array('group' => $group, 'element' => $element, 'field' => null, 'inputName' => SOCIAL_FIELDS_PREFIX . '0'); // Detect if there is an id passed in. $id = JRequest::getInt('id', 0); // If there is an id, it should also create a copy of the field. if ($id) { $field = FD::table('Field'); $field->load($id); $step = FD::table('fieldstep'); $step->load($field->step_id); $uid = $step->uid; $params = FD::fields()->getFieldConfigValues($field); $config['params'] = $params; $config['uid'] = $uid; $config['field'] = $field; $config['inputName'] = SOCIAL_FIELDS_PREFIX . $field->id; } // Determine the class name $class = 'SocialFields' . ucfirst($group) . ucfirst($element); // Let's instantiate the new object now. $obj = new $class($config); // Call the ajax method $obj->{$method}(); break; case 'apps': // We know the second segment is always the element. $group = $parts[0]; $element = $parts[1]; $type = $parts[2]; // If this is a view call, it should use the method. $classType = $parts[3]; if ($type == 'controllers') { // Construct the classname $class = ucfirst($element) . 'Controller' . ucfirst($classType); // Let's instantiate the new object now. $obj = new $class($group, $element); } if ($type == 'views') { $app = FD::table('App'); $app->load(JRequest::getInt('id')); $class = ucfirst($element) . 'View' . ucfirst($classType); $obj = new $class($app, $classType); } // If the method doesn't exist in this object, we know something is wrong. if (!method_exists($obj, $method)) { $ajax->reject(JText::sprintf('Method %1s does not exist', $method)); return $ajax->send(); } if (!empty($args)) { call_user_func_array(array($obj, $method), FD::json()->decode($args)); } else { $obj->{$method}(); } break; case 'site': case 'admin': default: // Currently only supports access to view and controller. $type = $parts[0]; $name = $parts[1]; if ($type == 'views') { $class = 'EasySocialView' . preg_replace('/[^A-Z0-9_]/i', '', $name); // Create the new view object. $obj = new $class(); } if ($type == 'controllers') { $class = 'EasySocialController' . preg_replace('/[^A-Z0-9_]/i', '', $name); // Create the new view object. $obj = new $class(); } if ($config->get('general.site.lockdown.enabled') && !JFactory::getUser()->id) { if (method_exists($obj, 'lockdown') && $obj->lockdown()) { $ajax->reject(JText::_('You are not allowed here.')); return $ajax->send(); } } // For controllers we need to use the standard `execute` method. if ($type == 'controllers') { $obj->execute($method); } else { // If the method doesn't exist in this object, we know something is wrong. if (!method_exists($obj, $method)) { $ajax->reject(JText::sprintf('Method %1s does not exist', $method)); return $ajax->send(); } if (!empty($args)) { call_user_func_array(array($obj, $method), FD::json()->decode($args)); } else { $obj->{$method}(); } } break; } // Terminate the output. $ajax->send(); return $path; }
public function getSuggestedFriends($userId = null, $limit = '0', $countOnly = false) { $config = FD::config(); $db = FD::db(); $sql = $db->sql(); $user = FD::user($userId); $result = array(); $total = 0; // retrieve friends of friends, who isn't your friend yet. $query = "select `tfid` as `ffriend_id`, count(`score`) as `score` from ("; $query .= " select f1.`target_id` as `tfid`, f1.`actor_id` as `score` from ("; $query .= "\tselect a.`actor_id` as `mfid` from `#__social_friends` as a where a.`target_id` = {$user->id} and a.`state` = " . SOCIAL_FRIENDS_STATE_FRIENDS; $query .= "\tunion "; $query .= "\tselect a1.`target_id` as `mfid` from #__social_friends as a1 where a1.`actor_id` = {$user->id} and a1.`state` = " . SOCIAL_FRIENDS_STATE_FRIENDS; $query .= " ) as fm"; $query .= "\tinner join #__social_friends as f1 on fm.mfid = f1.actor_id and f1.state = " . SOCIAL_FRIENDS_STATE_FRIENDS; $query .= "\twhere f1.target_id not in (\tselect a.actor_id as `mfid` from #__social_friends as a where a.target_id = {$user->id} and a.state != " . SOCIAL_FRIENDS_STATE_REJECTED; $query .= "\tunion"; $query .= "\tselect a1.target_id as `mfid` from #__social_friends as a1 where a1.actor_id = {$user->id} and a1.state != " . SOCIAL_FRIENDS_STATE_REJECTED . ")"; $query .= "\tand f1.target_id != {$user->id}"; $query .= " union"; $query .= " select f2.actor_id as `tfid`, f2.target_id as score from ("; $query .= "\tselect b.actor_id as `mfid` from #__social_friends as b where b.target_id = {$user->id} and b.state = " . SOCIAL_FRIENDS_STATE_FRIENDS; $query .= "\tunion"; $query .= "\tselect b1.target_id as `mfid` from #__social_friends as b1 where b1.actor_id = {$user->id} and b1.state = " . SOCIAL_FRIENDS_STATE_FRIENDS; $query .= " ) as fm2"; $query .= "\tinner join #__social_friends as f2 on fm2.mfid = f2.target_id and f2.state = " . SOCIAL_FRIENDS_STATE_FRIENDS; $query .= "\twhere f2.actor_id not in (\tselect a.actor_id as `mfid` from #__social_friends as a where a.target_id = {$user->id} and a.state != " . SOCIAL_FRIENDS_STATE_REJECTED; $query .= "\tunion"; $query .= "\tselect a1.target_id as `mfid` from #__social_friends as a1 where a1.actor_id = {$user->id} and a1.state != " . SOCIAL_FRIENDS_STATE_REJECTED . ")"; $query .= "\tand f2.actor_id != {$user->id}"; $query .= ") as x"; $query .= " INNER JOIN `#__users` AS uu ON uu.`id` = x.`tfid` AND uu.`block` = '0'"; if ($config->get('users.blocking.enabled') && !JFactory::getUser()->guest) { // user block $query .= ' LEFT JOIN ' . $db->nameQuote('#__social_block_users') . ' as bus'; $query .= ' ON uu.' . $db->nameQuote('id') . ' = bus.' . $db->nameQuote('user_id'); $query .= ' AND bus.' . $db->nameQuote('target_id') . ' = ' . $db->Quote(JFactory::getUser()->id); $query .= ' WHERE bus.' . $db->nameQuote('id') . ' IS NULL'; } $query .= " group by x.tfid"; $query .= " order by score desc"; $sql->raw($query); // echo $sql;exit; if (!empty($limit) && $limit > 0) { $this->setState('limit', $limit); // Get the limitstart. $limitstart = $this->getUserStateFromRequest('limitstart', 0); $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0; $this->setState('limitstart', $limitstart); // Set the total number of items. $this->setTotal($sql->getSQL(), true); $total = $this->getTotal(); // Get the list of users $result = $this->getData($sql->getSQL()); } else { $db->setQuery($sql->getSQL()); $result = $db->loadObjectList(); $total = count($result); } $runTrigger = true; if ($limit && $total >= $limit) { $runTrigger = false; } // now we trigger custom fields to search users which has the similar // data. $fieldsLib = FD::fields(); $fieldModel = FD::model('Fields'); $fieldsResult = array(); if ($runTrigger) { $fieldSQL = 'select a.*, b.' . $db->nameQuote('type') . ', b.' . $db->nameQuote('element') . ', b.' . $db->nameQuote('group'); $fieldSQL .= ', c.' . $db->nameQuote('uid') . ' as ' . $db->nameQuote('profile_id'); $fieldSQL .= ' FROM ' . $db->nameQuote('#__social_fields') . ' as a'; $fieldSQL .= ' INNER JOIN ' . $db->nameQuote('#__social_apps') . ' as b'; $fieldSQL .= ' ON a.app_id = b.id'; $fieldSQL .= ' LEFT JOIN ' . $db->nameQuote('#__social_fields_steps') . ' as c'; $fieldSQL .= ' ON a.step_id = c.id'; $fieldSQL .= ' where a.' . $db->nameQuote('friend_suggest') . ' = ' . $db->Quote('1'); $db->setQuery($fieldSQL); $fields = $db->loadObjectList(); if (count($fields) > 0) { foreach ($fields as $item) { $field = FD::table('Field'); $field->bind($item); $field->profile_id = $item->profile_id; $field->data = isset($item->data) ? $item->data : ''; $userFieldData = $fieldModel->getCustomFieldsValue($field->id, $user->id, SOCIAL_FIELDS_GROUP_USER); $args = array($user, $userFieldData); $f = array(&$field); $dataResult = $fieldsLib->trigger('onFriendSuggestSearch', SOCIAL_FIELDS_GROUP_USER, $f, $args); $fieldsResult = array_merge($fieldsResult, $dataResult); } } } $tmpResult = array_merge($result, $fieldsResult); //reset $result $result = array(); foreach ($tmpResult as $tmpItem) { if (!array_key_exists($tmpItem->ffriend_id, $result)) { $result[$tmpItem->ffriend_id] = $tmpItem; } } if ($countOnly) { return count($result); } $friends = array(); if ($result) { //preload users. $tmp = array(); foreach ($result as $item) { $tmp[] = $item->ffriend_id; } FD::user($tmp); // getting the result. foreach ($result as $item) { $obj = new stdClass(); $obj->friend = FD::user($item->ffriend_id); $obj->count = $item->score; $friends[] = $obj; } } return $friends; }
/** * Retrieve additional information for a specific user * * @since 1.3 * @access public * @param string * @return */ public function getInfo() { // Check for request forgeries FD::checkToken(); $view = $this->getCurrentView(); $id = $this->input->get('id', 0, 'int'); $user = FD::user($id); if (empty($user) || empty($user->id) || $user->isBlock()) { $view->setMessage(JText::_('COM_EASYSOCIAL_USERS_NO_SUCH_USER'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } $my = FD::user(); $privacy = $my->getPrivacy(); // @privacy: Let's test if the current viewer is allowed to view this profile. if ($my->id != $user->id && !$privacy->validate('profiles.view', $user->id, SOCIAL_TYPE_USER)) { $view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_PRIVACY_NOT_ALLOWED'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } FD::language()->loadAdmin(); $index = JRequest::getInt('index'); $profile = $user->getProfile(); $sequence = $profile->getSequenceFromIndex($index, SOCIAL_PROFILES_VIEW_DISPLAY); $step = FD::table('FieldStep'); $state = $step->load(array('uid' => $profile->id, 'type' => SOCIAL_TYPE_PROFILES, 'sequence' => $sequence, 'visible_display' => 1)); if (!$state) { $view->setMessage(JText::sprintf('COM_EASYSOCIAL_PROFILE_USER_NOT_EXIST', $user->getName()), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } $fields = FD::model('Fields')->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $user->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_DISPLAY)); $fieldsLib = FD::fields(); if (!empty($fields)) { $args = array($user); $fieldsLib->trigger('onDisplay', SOCIAL_FIELDS_GROUP_USER, $fields, $args); } return $view->call(__FUNCTION__, $fields); }
function CreateGroup() { $app = JFactory::getApplication(); $log_user = JFactory::getUser($this->plugin->get('user')->id); $user = FD::user($log_user->id); $config = FD::config(); //create group post structure $grp_data = array(); $result = new stdClass(); $valid = 1; $title = $app->input->get('title', null, 'STRING'); $parmalink = $app->input->get('parmalink', null, 'STRING'); $description = $app->input->get('description', null, 'STRING'); $type = $app->input->get('type', 0, 'INT'); $categoryId = $app->input->get('category_id', 0, 'INT'); $avtar_pth = ''; $avtar_scr = ''; $avtar_typ = ''; $phto_obj = null; if (!empty($_FILES['file']['name'])) { $upload_obj = new EasySocialApiUploadHelper(); //ckecking upload cover //$phto_obj = $upload_obj->uploadPhoto($log_user->id,'group'); $phto_obj = $upload_obj->ajax_avatar($_FILES['file']); $avtar_pth = $phto_obj['temp_path']; $avtar_scr = $phto_obj['temp_uri']; $avtar_typ = 'upload'; $avatar_file_name = $_FILES['file']['name']; } $cover_data = null; if (!empty($_FILES['cover_file']['name'])) { $upload_obj = new EasySocialApiUploadHelper(); //ckecking upload cover $cover_data = $upload_obj->ajax_cover($_FILES['cover_file'], 'cover_file'); //$phtomod = FD::model( 'Photos' ); //$cover_obj = $upload_obj->uploadCover($log_user->id,'group'); //$cover_data = $phtomod->getMeta($cover_obj->id, SOCIAL_PHOTOS_META_PATH); // } // //check title if (empty($title) || $title == null) { $valid = 0; $result->status = 0; $result->message[] = "Invalid group name"; } //check parmalink if (empty($parmalink) || $parmalink == null) { $valid = 0; $result->status = 0; $result->message[] = "Invalid parmalink"; } //check description if (empty($description) || $description == null) { $valid = 0; $result->status = 0; $result->message[] = "Empty description not allowed"; } //check group type if (empty($type) || $type == 0) { $valid = 0; $result->status = 0; $result->message[] = "Please Add group type"; } if (!$valid) { return $result; } else { // create steps $db = FD::db(); $group = FD::table('Group'); FD::import('admin:/includes/group/group'); $group = new SocialGroup(); // Load front end's language file FD::language()->loadSite(); $category = FD::table('GroupCategory'); $category->load($categoryId); // Get the steps $stepsModel = FD::model('Steps'); $steps = $stepsModel->getSteps($categoryId, SOCIAL_TYPE_CLUSTERS); // Get the fields $lib = FD::fields(); $fieldsModel = FD::model('Fields'); /*$post = $this->input->post->getArray(); $args = array(&$post, &$group, &$errors);*/ // query written due to commented function not working $query = "SELECT a.id,a.unique_key\tFROM `#__social_fields` AS `a` \n\t\t\t\t\t\tLEFT JOIN `#__social_apps` AS `b` ON `b`.`id` = `a`.`app_id`\n\t\t\t\t\t\tLEFT JOIN `#__social_fields_steps` AS `d` ON `a`.`step_id` = `d`.`id` \n\t\t\t\t\t\tWHERE `a`.`step_id` = '" . $steps[0]->id . "' ORDER BY `d`.`sequence` ASC,`a`.`ordering` ASC"; $db->setQuery($query); $field_ids = $db->loadAssocList(); /*foreach ($steps as $step) { if ($group->id) { $step->fields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $group->id, 'dataType' => SOCIAL_TYPE_GROUP)); } else { $step->fields = $fieldsModel->getCustomFields(array('step_id' => $step->id)); } }*/ foreach ($field_ids as $field) { $grp_data['cid'][] = $field['id']; switch ($field['unique_key']) { case 'HEADER': break; case 'TITLE': $grp_data['es-fields-' . $field['id']] = $title; break; case 'PERMALINK': $grp_data['es-fields-' . $field['id']] = $parmalink; break; case 'DESCRIPTION': $grp_data['es-fields-' . $field['id']] = $description; break; case 'TYPE': $grp_data['group_type'] = $type; break; case 'URL': $grp_data['es-fields-' . $field['id']] = $app->input->get('website', 0, 'STRING'); break; case 'PHOTOS': $grp_data['photo_albums'] = $app->input->get('photo_album', 0, 'INT'); break; case 'NEWS': $grp_data['es-fields-' . $field['id']] = $app->input->get('announcements', 0, 'INT'); break; case 'DISCUSSIONS': $grp_data['es-fields-' . $field['id']] = $app->input->get('discussions', 0, 'INT'); break; case 'AVATAR': $grp_data['es-fields-' . $field['id']] = array('source' => $avtar_scr, 'path' => $avtar_pth, 'data' => '', 'type' => $avtar_typ, 'name' => $avatar_file_name); break; case 'COVER': $grp_data['es-fields-' . $field['id']] = array('data' => $cover_data, 'position' => '{"x":0.5,"y":0.5}'); break; } } //for check group exceed limit if (!$user->getAccess()->allowed('groups.create') && !$user->isSiteAdmin()) { $valid = 0; $result->status = 0; $result->message[] = "You are not allow to create the group"; return $result; } // Ensure that the user did not exceed their group creation limit if ($user->getAccess()->intervalExceeded('groups.limit', $user->id) && !$user->isSiteAdmin()) { $valid = 0; $result->status = 0; $result->message[] = "Group creation limit exceeds"; return $result; } // Get current user's info $session = JFactory::getSession(); // Get necessary info about the current registration process. $stepSession = FD::table('StepSession'); $stepSession->load($session->getId()); $stepSession->uid = $categoryId; // Load the group category $category = FD::table('GroupCategory'); $category->load($stepSession->uid); $sequence = $category->getSequenceFromIndex($stepSession->step, SOCIAL_GROUPS_VIEW_REGISTRATION); // Load the current step. $step = FD::table('FieldStep'); $step->load(array('uid' => $category->id, 'type' => SOCIAL_TYPE_CLUSTERS, 'sequence' => $sequence)); // Merge the post values $registry = FD::get('Registry'); $registry->load($stepSession->values); // Load up groups model $groupsModel = FD::model('Groups'); // Get all published fields apps that are available in the current form to perform validations $fieldsModel = FD::model('Fields'); $fields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'visible' => SOCIAL_GROUPS_VIEW_REGISTRATION)); // Load json library. $json = FD::json(); // Retrieve all file objects if needed //$files = JRequest::get( 'FILES' ); $token = FD::token(); $disallow = array($token, 'option', 'cid', 'controller', 'task', 'option', 'currentStep'); foreach ($grp_data as $key => $value) { if (!in_array($key, $disallow)) { if (is_array($value)) { $value = FD::json()->encode($value); } $registry->set($key, $value); } } // Convert the values into an array. $data = $registry->toArray(); $args = array(&$data, &$stepSession); // Perform field validations here. Validation should only trigger apps that are loaded on the form // @trigger onRegisterValidate $fieldsLib = FD::fields(); // Get the trigger handler $handler = $fieldsLib->getHandler(); // Get error messages $errors = $fieldsLib->trigger('onRegisterValidate', SOCIAL_FIELDS_GROUP_GROUP, $fields, $args, array($handler, 'validate')); // The values needs to be stored in a JSON notation. $stepSession->values = $json->encode($data); $stepSession->created = FD::date()->toMySQL(); $group = $groupsModel->createGroup($stepSession); if ($group->id) { $result->status = 1; $result->id = $group->id; $this->addTostream($user, $group); } else { $result->status = 0; $result->id = 0; $result->message = 'unable to create group'; } return $result; } }
/** * 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); }
/** * Responsible to output the edit profile layout * * @since 1.0 * @access public * @param string The name of the template file to parse; automatically searches through the template paths. * @return null * @author Mark Lee <*****@*****.**> */ public function edit($errors = null) { // Unauthorized users should not be allowed to access this page. FD::requireLogin(); // Set any messages here. FD::info()->set($this->getMessage()); // Load the language file from the back end. FD::language()->loadAdmin(); // Get list of steps for this user's profile type. $profile = $this->my->getProfile(); // Get user's installed apps $appsModel = FD::model('Apps'); $userApps = $appsModel->getUserApps($this->my->id); // Get the steps model $stepsModel = FD::model('Steps'); $steps = $stepsModel->getSteps($profile->id, SOCIAL_TYPE_PROFILES, SOCIAL_PROFILES_VIEW_EDIT); // Get custom fields model. $fieldsModel = FD::model('Fields'); // Get custom fields library. $fields = FD::fields(); // Set page title FD::page()->title(JText::_('COM_EASYSOCIAL_PAGE_TITLE_ACCOUNT_SETTINGS')); // Set the page breadcrumb FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_PROFILE'), FRoute::profile()); FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_ACCOUNT_SETTINGS')); // Check if there are any errors in the session // If session contains error, means that this is from the FD::fields()->checkCompleteProfile(); if (empty($errors)) { $session = JFactory::getSession(); $errors = $session->get('easysocial.profile.errors', '', SOCIAL_SESSION_NAMESPACE); if (!empty($errors)) { FD::info()->set(false, JText::_('COM_EASYSOCIAL_PROFILE_PLEASE_COMPLETE_YOUR_PROFILE'), SOCIAL_MSG_ERROR); } } // Set the callback for the triggered custom fields $callback = array($fields->getHandler(), 'getOutput'); // Get the custom fields for each of the steps. foreach ($steps as &$step) { $step->fields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $this->my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => 'edit')); // Trigger onEdit for custom fields. if (!empty($step->fields)) { $post = JRequest::get('post'); $args = array(&$post, &$this->my, $errors); $fields->trigger('onEdit', SOCIAL_FIELDS_GROUP_USER, $step->fields, $args, $callback); } } // Determines if we should show the social tabs on the left. $showSocialTabs = false; // Determines if the user has associated $associatedFacebook = $this->my->isAssociated('facebook'); $facebookClient = false; $facebookMeta = array(); $fbOAuth = false; $fbUserMeta = array(); if ($associatedFacebook) { // We want to show the tabs $showSocialTabs = true; $facebookToken = $this->my->getOAuthToken('facebook'); $facebookClient = FD::oauth('facebook'); // Set the access for the client. $facebookClient->setAccess($facebookToken); try { $fbUserMeta = $facebookClient->getUserMeta(); } catch (Exception $e) { $message = (object) array('message' => JText::sprintf('COM_EASYSOCIAL_OAUTH_FACEBOOK_ERROR_MESSAGE', $e->getMessage()), 'type' => SOCIAL_MSG_ERROR); FD::info()->set($message); } $fbUserMeta = false; $fbOAuth = $this->my->getOAuth(SOCIAL_TYPE_FACEBOOK); $facebookMeta = FD::registry($fbOAuth->params); $facebookPermissions = FD::makeArray($fbOAuth->permissions); } $this->set('fbUserMeta', $fbUserMeta); $this->set('fbOAuth', $fbOAuth); $this->set('showSocialTabs', $showSocialTabs); $this->set('facebookMeta', $facebookMeta); $this->set('facebookClient', $facebookClient); $this->set('associatedFacebook', $associatedFacebook); $this->set('profile', $profile); $this->set('steps', $steps); $this->set('apps', $userApps); return parent::display('site/profile/default.edit.profile'); }
/** * Retrieves the custom field raw data from this user. * * @since 1.0 * @access public * @param string * @return */ public function getFieldData($key, $default = '') { static $processed = array(); if (!isset($processed[$this->id])) { $processed[$this->id] = array(); } if (!isset($processed[$this->id][$key])) { if (!isset(SocialUserStorage::$fields[$this->id][$key])) { $result = FD::model('Fields')->getCustomFields(array('group' => SOCIAL_TYPE_USER, 'uid' => $this->profile_id, 'data' => true, 'dataId' => $this->id, 'dataType' => SOCIAL_TYPE_USER, 'key' => $key)); SocialUserStorage::$fields[$this->id][$key] = isset($result[0]) ? $result[0] : false; } $field = SocialUserStorage::$fields[$this->id][$key]; // Initialize a default property $processed[$this->id][$key] = ''; if ($field) { // Trigger the getFieldValue to obtain data from the field. $value = FD::fields()->getData($field); $processed[$this->id][$key] = $value; } } return $processed[$this->id][$key]; }
/** * Creates a user in the system for users who logged in via oauth * * Example: * <code> * <?php * $model = FD::model( 'Registration' ); * $model->createUser( $registrationTable ); * * ?> * </code> * * @since 1.0 * @access public * @param SocialTableRegistration The registration object. * @return int The last sequence for the profile type. * * @author Mark Lee <*****@*****.**> */ public function createOAuthUser($accessToken, $data, $client, $import = true, $sync = true) { $config = FD::config(); // Registrations needs to be enabled. if (!$config->get('registrations.enabled')) { $this->setError(JText::_('COM_EASYSOCIAL_REGISTRATIONS_DISABLED')); return false; } // Load profile type. $profile = FD::table('Profile'); $profile->load($data['profileId']); // Get all published fields apps. $fieldsModel = FD::model('Fields'); $fields = $fieldsModel->getCustomFields(array('profile_id' => $profile->id, 'state' => SOCIAL_STATE_PUBLISHED)); $args = array(&$data, &$client); // Perform field validations here. Validation should only trigger apps that are loaded on the form // Get the fields library $lib = FD::fields(); // Get the trigger handler $handler = $lib->getHandler(); // Trigger onRegisterOAuthBeforeSave $errors = $lib->trigger('onRegisterOAuthBeforeSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args, array($handler, 'beforeSave')); // Get a list of user groups this profile is assigned to $json = FD::json(); $groups = $json->decode($profile->gid); // Need to bind the groups under the `gid` column from Joomla. $data['gid'] = $groups; // Bind the posted data for the user. $user = FD::user(); $user->bind($data, SOCIAL_POSTED_DATA); // Detect the profile type's registration type. $type = $profile->getRegistrationType(false, true); // We need to generate an activation code for the user. if ($type == 'verify') { $user->activation = FD::getHash(JUserHelper::genRandomPassword()); } // If the registration type requires approval or requires verification, the user account need to be blocked first. if ($type == 'approvals' || $type == 'verify') { $user->block = 1; } // Get registration type and set the user's state accordingly. $user->set('state', constant('SOCIAL_REGISTER_' . strtoupper($type))); // Set the account type. $user->set('type', $client->getType()); // Let's try to save the user now. $state = $user->save(); // If there's a problem saving the user object, set error message. if (!$state) { $this->setError($user->getError()); return false; } // Set the user with proper `profile_id` $user->profile_id = $profile->id; // Once the user is saved successfully, add them into the profile mapping. $profile->addUser($user->id); // Assign user object back into the data. $data['user'] = $user; // Bind custom fields for this user. if ($import) { $user->bindCustomFields($data); } // Allow field applications to manipulate custom fields data $args = array(&$data, &$client, &$user); // Allow fields app to make necessary changes if necessary. At this point, we wouldn't want to allow // the field to stop the registration process already. // @trigger onRegisterAfterSave $lib->trigger('onRegisterOAuthAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args); // Create a new oauth record on the `#__social_oauth` table so we can simulate the user. $oauth = FD::table('OAuth'); $oauth->uid = $user->id; $oauth->type = SOCIAL_TYPE_USER; $oauth->client = $client->getType(); $oauth->oauth_id = $data['oauth_id']; $oauth->token = $accessToken->token; $oauth->secret = $accessToken->secret; $oauth->expires = $accessToken->expires; $oauth->pull = $sync; $oauth->push = $sync; // Store oauth record $oauth->store(); // @TODO: Send notification email to admin // @OTOD: Send registration confirmation email to user. return $user; }
public function createRecurring() { FD::checkToken(); $eventId = $this->input->getInt('eventId'); $schedule = $this->input->getString('datetime'); $parentEvent = FD::event($eventId); $duration = $parentEvent->hasEventEnd() ? $parentEvent->getEventEnd()->toUnix() - $parentEvent->getEventStart()->toUnix() : false; $data = $this->input->getVar('postdata'); // Because this comes form a form, the $data['id'] might be an existing id especially if the create recurring comes from "edit" unset($data['id']); // Because this comes from a form, $data['applyRecurring'] might be 1 for applying purposes, but for creation, we do not this flag unset($data['applyRecurring']); // Mark the data as createRecurring $data['createRecurring'] = true; // Manually change the start end time $data['startDatetime'] = FD::date($schedule)->toSql(); if ($duration) { $data['endDatetime'] = FD::date($schedule + $duration)->toSql(); } else { unset($data['endDatetime']); } $my = FD::user(); $fieldsLib = FD::fields(); $options = array(); $options['uid'] = $parentEvent->category_id; $options['group'] = SOCIAL_FIELDS_GROUP_EVENT; $fields = FD::model('fields')->getCustomFields($options); $event = new SocialEvent(); $event->category_id = $parentEvent->category_id; $event->creator_uid = $parentEvent->creator_uid; $event->creator_type = SOCIAL_TYPE_USER; $event->state = SOCIAL_STATE_PUBLISHED; $event->key = md5(FD::date()->toSql() . $my->password . uniqid()); $event->parent_id = $parentEvent->id; $event->parent_type = SOCIAL_TYPE_EVENT; $args = array(&$data, &$event); $fieldsLib->trigger('onAdminEditBeforeSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args); $event->bind($data); $event->save(); // Duplicate nodes from parent FD::model('Events')->duplicateGuests($parentEvent->id, $event->id); $args = array(&$data, &$event); $fieldsLib->trigger('onAdminEditAfterSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args); $event->bindCustomFields($data); $args = array(&$data, &$event); $fieldsLib->trigger('onAdminEditAfterSaveFields', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args); return $this->view->call(__FUNCTION__); }
public function getInfo() { FD::checkToken(); $view = $this->getCurrentView(); $groupId = JRequest::getInt('groupId'); $group = FD::group($groupId); if (empty($group) || empty($group->id)) { $view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_INVALID_GROUP_ID'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } $my = FD::user(); if (!$my->isSiteAdmin() && !$group->isOpen() && !$group->isMember()) { $view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_NO_ACCESS'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } FD::language()->loadAdmin(); $index = JRequest::getInt('index'); $category = $group->getCategory(); $sequence = $category->getSequenceFromIndex($index, SOCIAL_GROUPS_VIEW_DISPLAY); $step = FD::table('FieldStep'); $state = $step->load(array('uid' => $category->id, 'type' => SOCIAL_TYPE_CLUSTERS, 'sequence' => $sequence, 'visible_display' => 1)); if (!$state) { $view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_NO_ACCESS'), SOCIAL_MSG_ERROR); return $view->call(__FUNCTION__); } $fields = FD::model('Fields')->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $group->id, 'dataType' => SOCIAL_TYPE_GROUP, 'visible' => SOCIAL_GROUPS_VIEW_DISPLAY)); $fieldsLib = FD::fields(); $fieldsLib->init(array('privacy' => false)); if (!empty($fields)) { $args = array($group); $fieldsLib->trigger('onDisplay', SOCIAL_FIELDS_GROUP_GROUP, $fields, $args); } return $view->call(__FUNCTION__, $fields); }
/** * Render's field configuration. * * @since 1.0 * @access public */ public function renderConfiguration() { // Check for request forgeries FD::checkToken(); // Get the application id. $appId = $this->input->get('appid', 0, 'int'); // Get the field id. If this is empty, it is a new field item that's being added to the form. $fieldId = $this->input->get('fieldid', 0, 'int'); // Application id should never be empty. if (!$appId) { $this->view->setMessage(JText::_('COM_EASYSOCIAL_PROFILES_FORM_FIELDS_INVALID_APP_ID_PROVIDED'), SOCIAL_MSG_ERROR); return $this->view->call(__FUNCTION__); } FD::language()->loadSite(); $fields = FD::fields(); // getFieldConfigParameters is returning a stdClass object due to deep level data $config = $fields->getFieldConfigParameters($appId, true); // getFieldConfigValues is returning a JRegistry object $params = $fields->getFieldConfigValues($appId, $fieldId); // Get the html content $html = $fields->getConfigHtml($appId, $fieldId); return $this->view->call(__FUNCTION__, $config, $params, $html); }
private function onEvent($fieldGroup, &$fields, &$data = array(), $callback = null) { // If there is no event assigned, then don't proceed if (empty($this->event)) { return false; } // If no fields are given, then don't proceed if (!$fields) { return false; } // Init the user if no target user is provided if (empty($this->user)) { $this->user = FD::user(); } $this->load($fieldGroup, $fields); $lib = FD::fields(); $result = array(); foreach ($fields as &$field) { if (empty($this->loaded[$field->element])) { // Show error if this app is not found FD::info()->set(false, JText::sprintf('COM_EASYSOCIAL_FIELDS_INVALID_APP_FOR_FIELD', $field->id), SOCIAL_MSG_ERROR); continue; } $fieldApp = $this->loaded[$field->element]; $params = $lib->getFieldConfigValues($field); // Manually check for parameters enforcemnet foreach ($this->params as $key => $val) { $params->set($key, $val); } $properties = array('event' => $this->event, 'params' => $params, 'element' => $field->element, 'group' => $fieldGroup, 'field' => $field, 'inputName' => SOCIAL_FIELDS_PREFIX . $field->id, 'user' => $this->user, 'unique_key' => $field->unique_key); if (isset($field->profile_id)) { $properties['profileId'] = $field->profile_id; } if (isset($field->data)) { $properties['value'] = $field->data; } $fieldApp->init($properties); $handler = $callback; $arguments = array($this->event, &$fieldApp, &$data, &$result); // If callback is not callable, then we fallback to internal handler class with the event name as the method if (!is_callable($handler)) { // Remove the first parameter, event, from the arguments array_shift($arguments); $handler = array($this->handler, $this->event); } call_user_func_array($handler, $arguments); } return $result; }
/** * 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); }
$layout = $params->get('layout', 'default'); $suffix = $params->get('suffix', ''); $config = FD::config(); $facebook = FD::oauth('Facebook'); // Get any callback urls. $return = EasySocialModLogBoxHelper::getReturnURL($params); // Get the profile id $profileId = $params->get('profile_id'); // If there's no profile id, then we automatically assign the default profile id if (empty($profileId)) { $profileModel = FD::model('profiles'); $defaultProfile = $profileModel->getDefaultProfile(); $profileId = $defaultProfile->id; } if ($params->get('show_quick_registration', true)) { $fieldsModel = FD::model('fields'); $options = array('visible' => SOCIAL_PROFILES_VIEW_MINI_REGISTRATION, 'profile_id' => $profileId); $fields = $fieldsModel->getCustomFields($options); if (!empty($fields)) { FD::language()->loadAdmin(); $fieldsLib = FD::fields(); $session = JFactory::getSession(); $registration = FD::table('Registration'); $registration->load($session->getId()); $data = $registration->getValues(); $args = array(&$data, &$registration); $fieldsLib->trigger('onRegisterMini', SOCIAL_FIELDS_GROUP_USER, $fields, $args); } } $facebook = FD::oauth('facebook'); require JModuleHelper::getLayoutPath('mod_easysocial_logbox', $layout);
/** * Retrieves the authorization url * * @since 1.0 * @access public * @param Array * @return */ public function getAuthorizeURL($params) { // Check if there are custom scope passed in $scopes = isset($params['scope']) ? $params['scope'] : array(); $permissions = array(); if ($scopes) { // Ensure that it's in an array $scopes = FD::makeArray($scopes); $permissions = array_merge($permissions, $scopes); } // Add in permissions based on settings $config = FD::config(); if ($config->get('oauth.facebook.push')) { $permissions[] = 'publish_actions'; } // We let fields add in permissions $args = array(&$permissions); $profile = $this->getDefaultProfile(); $fields = $profile->getCustomFields(); $fieldsLib = FD::fields(); $fieldsLib->trigger('onOAuthGetUserPermission', SOCIAL_FIELDS_GROUP_USER, $fields, $args); // Reset the scope $params['scope'] = array_unique((array) $permissions); if (!isset($params['display'])) { $params['display'] = 'popup'; } // Encode the return_to if exists if (isset($params['return_to'])) { $params['return_to'] = base64_encode($params['return_to']); } // Determine and fix the redirect uri if necessary. if (isset($params['redirect_uri'])) { $uri = $params['redirect_uri']; // Check if there is http:// or https:// in the url. if (stristr($uri, 'http://') === false && stristr($uri, 'https://') === false) { // If it doesn't exist, always pull from the site. $uri = rtrim(JURI::root(), '/') . $uri; $params['redirect_uri'] = $uri; } } $url = $this->getLoginUrl($params); return $url; }
/** * Stores a group category ( Cluster category ) * * @since 1.0 * @access public * @param string * @return */ public function saveCategory() { // Check for request forgeries FD::checkToken(); // Get the posted data $post = $this->input->getArray('post'); // Get the id if there is any $id = $this->input->get('id', 0, 'int'); // Try to load up the category $category = FD::table('GroupCategory'); $category->load($id); $category->bind($post); // Try to store the category $state = $category->store(); // Bind the group creation access if ($state) { $categoryAccess = $this->input->get('create_access', '', 'default'); $category->bindCategoryAccess('create', $categoryAccess); } // Store the avatar for this profile. $file = $this->input->files->get('avatar', ''); // Try to upload the profile's avatar if required if (!empty($file['tmp_name'])) { $category->uploadAvatar($file); } // Get fields data separately as we need allowraw here $fields = $this->input->get('fields', null, 'raw'); // $postfields = JRequest::getVar( 'fields', $default = null, $hash = 'POST', $type = 'none', $mask = JREQUEST_ALLOWRAW ); // Set the fields for this group category. if (!empty($fields)) { $data = FD::json()->decode($fields); $lib = FD::fields(); $lib->saveFields($category->id, SOCIAL_TYPE_CLUSTERS, $data); } // Bind the access if (isset($post['access']) && !empty($post['access'])) { $category->bindAccess($post['access']); } // Set the message $this->view->setMessage('COM_EASYSOCIAL_GROUPS_CATEGORY_SAVED_SUCCESS', SOCIAL_MSG_SUCCESS); return $this->view->call(__FUNCTION__, $category); }
/** * Displays the edit form of user * * @since 1.0 * @access public * @param int The id of the user that is being edited. */ public function editForm($id, $errors = null) { // Get the user object $user = FD::user($id); // Get the user's profile $profile = $user->getProfile(); $this->setHeading($user->getName() . ' (' . $profile->get('title') . ')'); $this->setIconUrl($user->getAvatar(SOCIAL_AVATAR_LARGE)); // Set page description $this->setDescription(JText::_('COM_EASYSOCIAL_DESCRIPTION_EDIT_USER')); // Load up language file from the front end. FD::language()->loadSite(); // Get a list of access rules that are defined for this $accessModel = FD::model('Access'); // Get user's privacy $privacyLib = FD::get('Privacy', $user->id); $privacyData = $privacyLib->getData(); $privacy = array(); // Update the privacy data with proper properties. if ($privacyData) { foreach ($privacyData as $group => $items) { // We do not want to show field privacy rules here because it does not make sense for user to set a default value // Most of the fields only have 1 and it is set in Edit Profile page if ($group === 'field') { continue; } foreach ($items as &$item) { $rule = strtoupper(JString::str_ireplace('.', '_', $item->rule)); $groupKey = strtoupper($group); $item->groupKey = $groupKey; $item->label = JText::_('COM_EASYSOCIAL_PRIVACY_LABEL_' . $groupKey . '_' . $rule); $item->tips = JText::_('COM_EASYSOCIAL_PRIVACY_TIPS_' . $groupKey . '_' . $rule); } $privacy[$group] = $items; } } // Get the steps model $stepsModel = FD::model('Steps'); $steps = $stepsModel->getSteps($user->profile_id, SOCIAL_TYPE_PROFILES); // Get custom fields model. $fieldsModel = FD::model('Fields'); // Get custom fields library. $fields = FD::fields(); // Manually set the user here because admin edit might be editing a different user $fields->setUser($user); // Get the custom fields for each of the steps. foreach ($steps as &$step) { $step->fields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $user->id, 'dataType' => SOCIAL_TYPE_USER)); // Trigger onEdit for custom fields. if (!empty($step->fields)) { $post = JRequest::get('post'); $args = array(&$post, &$user, $errors); $fields->trigger('onAdminEdit', SOCIAL_FIELDS_GROUP_USER, $step->fields, $args); } } // Get user badges $badges = $user->getBadges(); // Get the user notification settings $alertLib = FD::alert(); $alerts = $alertLib->getUserSettings($user->id); // Get stats $stats = $this->getStats($user); // Get user points history $pointsModel = FD::model('Points'); $pointsHistory = $pointsModel->getHistory($user->id, array('limit' => 20)); $pointsPagination = $pointsModel->getPagination(); // Get user's groups $userGroups = array_keys($user->groups); // 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')); $this->set('userGroups', $userGroups); $this->set('guestGroup', $guestGroup); $this->set('stats', $stats); $this->set('pointsHistory', $pointsHistory); $this->set('alerts', $alerts); $this->set('privacy', $privacy); $this->set('badges', $badges); $this->set('steps', $steps); $this->set('user', $user); return parent::display('admin/users/form'); }
/** * Initialises the field view * * @access public * @param SocialFieldItem $field */ public function init($field) { $this->field = $field; $this->params = FD::fields()->getFieldConfigValues($field); $this->inputName = SOCIAL_FIELDS_PREFIX . $field->id; }
public static function checkCompleteProfile() { $config = FD::config(); $my = FD::user(); // If user is not registered, or no profile id, or settings is not enabled, we cannot do anything to check if (empty($my->id) || empty($my->profile_id) || !$config->get('user.completeprofile.required', false)) { return true; } $total = $my->getProfile()->getTotalFields(SOCIAL_PROFILES_VIEW_EDIT); $filled = $my->completed_fields; // Avoid using maintenance script to do this because it is possible that a site might have >1000 users // Using this method instead so that every user will at least get executed once during login // Won't happen on subsequent logins if (empty($filled)) { $fields = FD::model('Fields')->getCustomFields(array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER)); $args = array(&$my); $completedFields = FD::fields()->trigger('onProfileCompleteCheck', SOCIAL_FIELDS_GROUP_USER, $fields, $args); $table = FD::table('Users'); $table->load(array('user_id' => $my->id)); $table->completed_fields = count($completedFields); $table->store(); $filled = $table->completed_fields; } if ($total == $filled) { return true; } $percentage = (int) ($filled / $total * 100); if ($percentage < 100) { $action = $config->get('user.completeprofile.action', 'info'); if ($action === 'redirect') { $mainframe = JFactory::getApplication(); $mainframe->redirect(FRoute::profile(array('layout' => 'edit'))); } if ($action === 'info' || $action === 'infoprofile' && JRequest::getVar('view') === 'profile') { $incompleteMessage = JText::sprintf('COM_EASYSOCIAL_PROFILE_YOUR_PROFILE_IS_INCOMPLETE', $percentage, FRoute::profile(array('layout' => 'edit'))); FD::info()->set(false, $incompleteMessage, SOCIAL_MSG_WARNING, 'easysocial.profilecompletecheck'); } return false; } return true; }
/** * Renders custom field output on a theme file. * * @since 1.0 * @access public * @param string * @return */ public function renderFields($group, $view, $position) { $fields = FD::fields(); $args = func_get_args(); $args = isset($args[3]) ? $args[3] : array(); return $fields->renderWidgets($group, $view, $position, $args); }
/** * Displays the category form for groups * * @since 1.0 * @access public * @param string * @return */ public function categoryForm($tpl = null) { // Perhaps this is an edited category $id = JRequest::getInt('id'); $category = FD::table('GroupCategory'); $category->load($id); // Set the structure heading here. if ($category->id) { $this->setHeading($category->get('title')); $this->setDescription(JText::_('COM_EASYSOCIAL_TOOLBAR_TITLE_EDIT_GROUP_CATEGORY_DESC')); } else { $this->setHeading(JText::_('COM_EASYSOCIAL_TOOLBAR_TITLE_CREATE_GROUP_CATEGORY')); $this->setDescription(JText::_('COM_EASYSOCIAL_TOOLBAR_TITLE_CREATE_GROUP_CATEGORY_DESC')); // By default the published state should be published. $category->state = SOCIAL_STATE_PUBLISHED; } // Set page icon. $this->setIcon('ies-folder-3'); // Load front end's language file Foundry::language()->loadSite(); JToolbarHelper::apply('applyCategory', JText::_('COM_EASYSOCIAL_TOOLBAR_TITLE_BUTTON_SAVE'), false, false); JToolbarHelper::save('saveCategory', JText::_('COM_EASYSOCIAL_TOOLBAR_TITLE_BUTTON_SAVE_AND_CLOSE')); JToolbarHelper::save2new('saveCategoryNew', JText::_('COM_EASYSOCIAL_TOOLBAR_TITLE_BUTTON_SAVE_AND_NEW')); JToolbarHelper::divider(); JToolbarHelper::cancel('cancel', JText::_('COM_EASYSOCIAL_TOOLBAR_TITLE_BUTTON_CANCEL')); $activeTab = JRequest::getWord('activeTab', 'settings'); $createAccess = ''; // Set properties for the template. $this->set('activeTab', $activeTab); $this->set('category', $category); if ($category->id) { $options = array('type' => SOCIAL_APPS_TYPE_FIELDS, 'group' => SOCIAL_TYPE_GROUP, 'state' => SOCIAL_STATE_PUBLISHED); // Get the available custom fields for groups $appsModel = FD::model('Apps'); $defaultApps = $appsModel->getApps($options); // Get the steps for this id $stepsModel = FD::model('Steps'); $steps = $stepsModel->getSteps($category->id, SOCIAL_TYPE_CLUSTERS); // Get the fields for this id $fieldsModel = FD::model('Fields'); $fields = $fieldsModel->getCustomFields(array('uid' => $category->id, 'state' => 'all', 'group' => SOCIAL_TYPE_GROUP)); // Empty array to pass to the trigger. $data = array(); // Get the fields sample output $lib = FD::fields(); $lib->trigger('onSample', SOCIAL_TYPE_GROUP, $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); // Get the creation access $createAccess = $category->getAccess('create'); // 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; // Set the profiles allowed to create groups $this->set('createAccess', $createAccess); // 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 type to the template $this->set('fieldGroup', SOCIAL_FIELDS_GROUP_GROUP); // Render the access form. $accessModel = FD::model('Access'); $accessForm = $accessModel->getForm($category->id, SOCIAL_TYPE_CLUSTERS, 'access'); $this->set('accessForm', $accessForm); } // Set the profiles allowed to create groups $this->set('createAccess', $createAccess); echo parent::display('admin/groups/form.category'); }
/** * Deprecated in 1.3. Use layout=item&type=info instead. * Displays the information about a group. * * @since 1.2 * @access public * @param string * @return */ public function info() { // Check if this feature is enabled. $this->checkFeature(); $id = $this->input->get('id', 0, 'int'); $group = FD::group($id); // Check if the group is valid if (!$id || !$group->id) { $this->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_INVALID_GROUP_ID'), SOCIAL_MSG_ERROR); FD::info()->set($this->getMessage()); return $this->redirect(FRoute::dashboard(array(), false)); } // Deprecated and just redirect to the item page with type=info return $this->redirect(FRoute::groups(array('layout' => 'item', 'type' => 'info', 'id' => $group->getAlias()))); // Check if the group is accessible if ($group->type == SOCIAL_GROUPS_INVITE_TYPE && !$group->isMember()) { $this->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_NOT_ALLOWED'), SOCIAL_MSG_ERROR); FD::info()->set($this->getMessage()); return $this->redirect(FRoute::dashboard(array(), false)); } // Set the page title. FD::page()->title($group->getName()); // Set the breadcrumbs FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_GROUPS_PAGE_TITLE'), FRoute::groups()); FD::page()->breadcrumb($group->getName()); // Determine if the user shouldn't be able to view the group's content if ($group->type == SOCIAL_GROUPS_PRIVATE_TYPE && !$group->isMember()) { // Display private group contents; return; } // Load language file from back end. FD::language()->loadAdmin(); // Get the custom fields steps. // Get the steps model $stepsModel = FD::model('Steps'); $steps = $stepsModel->getSteps($group->category_id, SOCIAL_TYPE_CLUSTERS, SOCIAL_PROFILES_VIEW_DISPLAY); // Get the fields library $fields = FD::fields(); // Enforce privacy to be false for groups $fields->init(array('privacy' => false)); $fieldsModel = FD::model('Fields'); $incomplete = false; // Get the custom fields for each of the steps. foreach ($steps as &$step) { $step->fields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'data' => true, 'dataId' => $group->id, 'dataType' => SOCIAL_TYPE_GROUP, 'visible' => SOCIAL_PROFILES_VIEW_DISPLAY)); // Trigger onDisplay for custom fields. if (!empty($step->fields)) { $args = array($group); $fields->trigger('onDisplay', SOCIAL_FIELDS_GROUP_GROUP, $step->fields, $args); } $step->hide = true; foreach ($step->fields as $field) { // If the key output is set but is empty, means that the field does have an output, but there is no data to show // In this case, we mark this profile as incomplete // Incomplete profile will have a info displayed above saying "complete your profile now" // If incomplete has been marked true, then no point marking it as true again // We don't break from the loop here because there is other checking going on if (isset($field->output) && empty($field->output) && $incomplete === false) { $incomplete = true; } // 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; } } } // Set template variables $this->set('incomplete', $incomplete); $this->set('steps', $steps); $this->set('group', $group); parent::display('site/groups/info'); }
return; } $modules = FD::modules('mod_easysocial_profile_completeness'); // We need foundryjs here $modules->loadComponentScripts(); $modules->loadComponentStylesheets(); // We need these packages $modules->addDependency('css', 'javascript'); $layout = $params->get('layout', 'default'); $suffix = $params->get('suffix', ''); $my = FD::user(); $total = $my->getProfile()->getTotalFields(SOCIAL_PROFILES_VIEW_EDIT); $filled = (int) $my->completed_fields; // Avoid using maintenance script to do this because it is possible that a site might have >1000 users // Using this method instead so that every user will at least get executed once during login // Won't happen on subsequent logins if (empty($filled)) { $fields = FD::model('Fields')->getCustomFields(array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER)); $args = array(&$my); $completedFields = FD::fields()->trigger('onProfileCompleteCheck', SOCIAL_FIELDS_GROUP_USER, $fields, $args); $table = FD::table('Users'); $table->load(array('user_id' => $my->id)); $table->completed_fields = count($completedFields); $table->store(); $filled = $table->completed_fields; } $percentage = (int) ($filled / $total * 100); if ($percentage >= 100) { return; } require JModuleHelper::getLayoutPath('mod_easysocial_profile_completeness', $layout);
public function syncIndexOLD() { $config = FD::config(); $indexer = FD::get('Indexer'); $idxTemplate = $indexer->getTemplate(); // should get the story, and customfields. $contentSnapshot = array(); $contentSnapshot[] = $this->getName($config->get('users.indexer.name')); if ($config->get('users.indexer.email')) { $contentSnapshot[] = $this->email; } // get customfields. $fieldsLib = FD::fields(); $fieldModel = FD::model('Fields'); $fieldsResult = array(); $options = array(); $options['data'] = true; $options['dataId'] = $this->id; $options['dataType'] = SOCIAL_TYPE_USER; $options['searchable'] = 1; //todo: get customfields. $fields = $fieldModel->getCustomFields($options); if (count($fields) > 0) { //foreach( $fields as $item ) foreach ($fields as $field) { //var_dump( $field ); $userFieldData = isset($field->data) ? $field->data : ''; $args = array($userFieldData); $f = array(&$field); $dataResult = $fieldsLib->trigger('onIndexer', SOCIAL_FIELDS_GROUP_USER, $f, $args); if ($dataResult !== false && count($dataResult) > 0) { $fieldsResult[] = $dataResult[0]; } } if ($fieldsResult) { $customFieldsContent = implode(' ', $fieldsResult); $contentSnapshot[] = $customFieldsContent; } } $content = implode(' ', $contentSnapshot); $idxTemplate->setContent($this->getName($config->get('users.indexer.name')), $content); //$url = FRoute::_( 'index.php?option=com_easysocial&view=profile&id=' . $this->id ); $url = ''; $idxTemplate->setSource($this->id, SOCIAL_INDEXER_TYPE_USERS, $this->id, $url); $date = FD::date(); $idxTemplate->setLastUpdate($date->toMySQL()); $state = $indexer->index($idxTemplate); return $state; }