/** * Looks up a user's interests (tags) * * @param integer $cloud Output as tagcloud (defaults to no) * @return string List of tags as either a tagcloud or comma-delimitated string */ private function _getInterests($cloud = 0) { $database = \App::get('db'); require_once Component::path('com_members') . DS . 'models' . DS . 'tags.php'; // Get tags of interest $mt = new \Components\Members\Models\Tags(User::get('id')); if ($cloud) { $tags = $mt->render(); } else { $tags = $mt->render('string'); } return $tags; }
<?php } ?> <?php } ?> <?php if ($this->registration->Interests != REG_HIDE) { ?> <?php if ($this->params->get('access_tags') == 0 || $this->params->get('access_tags') == 1 && $loggedin || $this->params->get('access_tags') == 2 && $isUser) { ?> <?php include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'tags.php'; $mt = new \Components\Members\Models\Tags($this->profile->get('uidNumber')); $tags = $mt->render(); if ($tags) { ?> <li class="profile-interests field"> <div class="field-content"> <div class="key"><?php echo Lang::txt('PLG_GROUPS_PROFILE_INTERESTS'); ?> </div> <div class="value"> <?php echo $tags; ?> </div> </div>
/** * Intro Page * * @return void */ public function displayTask() { // set the neeced layout $this->view->setLayout('display'); // build the title $this->_buildTitle(); // build pathway $this->_buildPathway(); //vars $mytags = ''; $this->view->mygroups = array('members' => null, 'invitees' => null, 'applicants' => null); $this->view->populargroups = array(); $this->view->interestinggroups = array(); //get the users profile $profile = \Hubzero\User\Profile::getInstance(User::get("id")); //if we have a users profile load their groups and groups matching their tags if (is_object($profile)) { //get users tags include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'tags.php'; $mt = new \Components\Members\Models\Tags($profile->get("uidNumber")); $mytags = $mt->render('string'); //get users groups $this->view->mygroups['members'] = \Hubzero\User\Helper::getGroups($profile->get("uidNumber"), 'members', 1); $this->view->mygroups['invitees'] = \Hubzero\User\Helper::getGroups($profile->get("uidNumber"), 'invitees', 1); $this->view->mygroups['applicants'] = \Hubzero\User\Helper::getGroups($profile->get("uidNumber"), 'applicants', 1); $this->view->mygroups = array_filter($this->view->mygroups); //get groups user may be interested in $this->view->interestinggroups = Group\Helper::getGroupsMatchingTagString($mytags, \Hubzero\User\Helper::getGroups($profile->get("uidNumber"))); } //get the popular groups $this->view->populargroups = Group\Helper::getPopularGroups(3); //get featured groups $this->view->featuredgroups = Group\Helper::getFeaturedGroups($this->config->get('intro_featuredgroups_list', '')); //set some vars for view $this->view->config = $this->config; $this->view->title = $this->_title; // get view notifications $this->view->notifications = $this->getNotifications() ? $this->getNotifications() : array(); //display view $this->view->display(); }
/** * Save tags * * @return void */ private function _saveTagsData() { // save tags $tags = new \Components\Members\Models\Tags($this->_profile->get('uidNumber')); $tags->setTags($this->record->tags, $this->_user->get('id')); }
/** * Get module contents * * @return void */ public function run() { include_once Component::path('com_whatsnew') . DS . 'helpers' . DS . 'period.php'; $live_site = rtrim(Request::base(), '/'); // Get some initial parameters $count = intval($this->params->get('limit', 5)); $this->feed = $this->params->get('feed'); $this->cssId = $this->params->get('cssId'); $this->period = $this->params->get('period', 'resources:month'); $this->tagged = intval($this->params->get('tagged', 0)); $database = \App::get('db'); // Build the feed link if necessary if ($this->feed) { $this->feedlink = Route::url('index.php?option=com_whatsnew&task=feed.rss&period=' . $this->period); $this->feedlink = DS . trim($this->feedlink, DS); $this->feedlink = $live_site . $this->feedlink; if (substr($this->feedlink, 0, 5) == 'https') { $this->feedlink = ltrim($this->feedlink, 'https'); $this->feedlink = 'http' . $this->feedlink; } } // Get categories $areas = $this->_getAreas(); $area = ''; // Check the search string for a category prefix if ($this->period != NULL) { $searchstring = strtolower($this->period); foreach ($areas as $c => $t) { $regexp = "/" . $c . ":/"; if (strpos($searchstring, $c . ":") !== false) { // We found an active category // NOTE: this will override any category sent in the querystring $area = $c; // Strip it off the search string $searchstring = preg_replace($regexp, '', $searchstring); break; } // Does the category contain sub-categories? if (is_array($t) && !empty($t)) { // It does - loop through them and perform the same check foreach ($t as $sc => $st) { $regexp = "/" . $sc . ":/"; if (strpos($searchstring, $sc . ':') !== false) { // We found an active category // NOTE: this will override any category sent in the querystring $area = $sc; // Strip it off the search string $searchstring = preg_replace($regexp, '', $searchstring); break; } } } } $this->period = trim($searchstring); } $this->area = $area; // Get the active category $activeareas = array(); if ($area) { $activeareas[] = $area; } // Process the keyword for exact time period $p = new Period($this->period); // Get the search results $results = Event::trigger('whatsnew.onWhatsnew', array($p, $count, 0, $activeareas, array())); $rows = array(); if ($results) { foreach ($results as $result) { if (is_array($result) && !empty($result)) { $rows = $result; break; } } } $this->rows = $rows; $this->rows2 = null; if ($this->tagged) { include_once Component::path('com_members') . DS . 'models' . DS . 'tags.php'; $mt = new \Components\Members\Models\Tags(User::get('id')); $tags = $mt->tags(); $this->tags = $tags; if (count($tags) > 0) { $tagids = array(); foreach ($tags as $tag) { $tagids[] = $tag->get('id'); } // Get the search results $results2 = Event::trigger('onWhatsnew', array($p, $count, 0, $activeareas, $tagids)); $rows2 = array(); if ($results2) { foreach ($results2 as $result2) { if (is_array($result2) && !empty($result2)) { $rows2 = $result2; break; } } } $this->rows2 = $rows2; } } require $this->getLayoutPath($this->params->get('layout', 'default')); }
/** * Short description for 'create' * * Long description (if any) ... * * @return mixed Return description (if any) ... */ public function createTask() { if (!User::isGuest() && !User::get('tmp_user')) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=myaccount'), Lang::txt('COM_MEMBERS_REGISTER_ERROR_NONGUEST_SESSION_CREATION'), 'warning'); return; } if (!isset($this->_taskMap[$this->_task])) { $this->_task = 'create'; Request::setVar('task', 'create'); } // Set the pathway $this->_buildPathway(); // Set the page title $this->_buildTitle(); $usersConfig = Component::params('com_users'); if ($usersConfig->get('allowUserRegistration') == '0') { return App::abort(404, Lang::txt('JGLOBAL_RESOURCE_NOT_FOUND')); } $hzal = null; if (User::get('auth_link_id')) { $hzal = \Hubzero\Auth\Link::find_by_id(User::get('auth_link_id')); } // Instantiate a new registration object $xregistration = new \Components\Members\Models\Registration(); if (Request::getMethod() == 'POST') { // Check for request forgeries Request::checkToken(); // Load POSTed data $xregistration->loadPost(); // Perform field validation if ($xregistration->check('create')) { // Get required system objects $user = clone User::getRoot(); $authorize = \JFactory::getACL(); // If user registration is not allowed, show 403 not authorized. if ($usersConfig->get('allowUserRegistration') == '0') { App::abort(403, Lang::txt('Access Forbidden')); return; } // Initialize new usertype setting $newUsertype = $usersConfig->get('new_usertype'); if (!$newUsertype) { $db = App::get('db'); $query = $db->getQuery(true)->select('id')->from('#__usergroups')->where('title = "Registered"'); $db->setQuery($query); $newUsertype = $db->loadResult(); } $user->set('username', $xregistration->get('login')); $user->set('name', $xregistration->get('name')); $user->set('email', $xregistration->get('email')); /* // Bind the post array to the user object if (!$user->bind(Request::get('post'), 'usertype')) { App::abort(500, $user->getError()); } */ // Set some initial user values $user->set('id', 0); $user->set('groups', array($newUsertype)); $date = Date::of('now'); $user->set('registerDate', $date->toSql()); // Check user activation setting // 0 = automatically confirmed // 1 = require email confirmation (the norm) // 2 = require admin confirmation $useractivation = $usersConfig->get('useractivation', 1); // If requiring admin approval, set user to block if ($useractivation == 2) { $user->set('approved', 0); } // If there was an error with registration, set the message and display form if ($user->save()) { /* // Send registration confirmation mail $password = Request::getString('password', '', 'post', JREQUEST_ALLOWRAW); $password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email UserController::_sendMail($user, $password); // Everything went fine, set relevant message depending upon user activation state and display message if ($useractivation == 1) { $message = Lang::txt('REG_COMPLETE_ACTIVATE'); } else { $message = Lang::txt('REG_COMPLETE'); } App::redirect(Route::url('index.php'), $message); */ // Get some settings $params = Component::params('com_members'); $hubHomeDir = rtrim($params->get('homedir'), '/'); // Attempt to get the new user $xprofile = \Hubzero\User\Profile::getInstance($user->get('id')); $result = is_object($xprofile); // Did we successfully create an account? if ($result) { $xprofile->loadRegistration($xregistration); if (is_object($hzal)) { if ($xprofile->get('email') == $hzal->email) { $xprofile->set('emailConfirmed', 3); } else { $xprofile->set('emailConfirmed', -rand(1, pow(2, 31) - 1)); } } else { if ($useractivation == 0) { $xprofile->set('emailConfirmed', 1); } } $xprofile->set('public', 0); // Do we have a return URL? $regReturn = Request::getVar('return', ''); if ($regReturn) { $xprofile->setParam('return', $regReturn); } // Unset password here so that change password below can be in charge of setting it initially $xprofile->set('password', ''); $result = $xprofile->update(); } // add member interests $interests = $xregistration->get('interests'); $mt = new \Components\Members\Models\Tags($xprofile->get('uidNumber')); if (!empty($interests)) { $mt->setTags($interests, $xprofile->get('uidNumber')); } if ($result) { $result = \Hubzero\User\Password::changePassword($xprofile->get('uidNumber'), $xregistration->get('password')); // Set password back here in case anything else down the line is looking for it $xprofile->set('password', $xregistration->get('password')); } // Did we successfully create/update an account? if (!$result) { return App::abort(500, Lang::txt('COM_MEMBERS_REGISTER_ERROR_CREATING_ACCOUNT')); } if ($xprofile->get('emailConfirmed') < 0) { // Notify the user $subject = Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_CONFIRMATION'); $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'create')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->sitename = Config::get('sitename'); $eview->xprofile = $xprofile; $eview->baseURL = $this->baseURL; $eview->xregistration = $xregistration; $msg = new \Hubzero\Mail\Message(); $msg->setSubject($subject)->addTo($xprofile->get('email'), $xprofile->get('name'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', $this->_option); $message = $eview->loadTemplate(false); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/plain'); $eview->setLayout('create_html'); $message = $eview->loadTemplate(); $message = str_replace("\n", "\r\n", $message); $msg->addPart($message, 'text/html'); if (!$msg->send()) { $this->setError(Lang::txt('COM_MEMBERS_REGISTER_ERROR_EMAILING_CONFIRMATION')); // @FIXME: LOG ERROR SOMEWHERE } } // Notify administration if ($usersConfig->get('mail_to_admin', 0)) { $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'admincreate_plain')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->sitename = Config::get('sitename'); $eview->xprofile = $xprofile; $eview->baseUrl = $this->baseURL; $plain = $eview->loadTemplate(false); $plain = str_replace("\n", "\r\n", $plain); // HTML $eview->setLayout('admincreate_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); $hubMonitorEmail = Config::get('mailfrom'); $message = new \Hubzero\Mail\Message(); $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_MEMBERS_REGISTER_EMAIL_ACCOUNT_CREATION'))->addTo($hubMonitorEmail)->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' Administrator')->addHeader('X-Component', $this->_option)->addHeader('X-Component-Object', 'user_creation_admin_notification')->addPart($plain, 'text/plain')->addPart($html, 'text/html'); // Send mail if (!$message->send()) { \Log::error('Members admin notification email failed: ' . Lang::txt('Failed to mail %s', $hubMonitorEmail)); } } // Instantiate a new view $this->view->setLayout('create'); $this->view->title = Lang::txt('COM_MEMBERS_REGISTER_CREATE_ACCOUNT'); $this->view->sitename = Config::get('sitename'); $this->view->xprofile = $xprofile; if ($this->getError()) { $this->view->setError($this->getError()); } $this->view->display(); if (is_object($hzal)) { $hzal->user_id = $user->get('id'); if ($hzal->user_id > 0) { $hzal->update(); } } User::set('auth_link_id', null); User::set('tmp_user', null); User::set('username', $xregistration->get('login')); User::set('email', $xregistration->get('email')); User::set('id', $user->get('id')); return; } } } if (Request::method() == 'GET') { if (User::get('tmp_user')) { $xregistration->loadAccount(User::getRoot()); $username = $xregistration->get('login'); $email = $xregistration->get('email'); if (is_object($hzal)) { $xregistration->set('login', $hzal->username); $xregistration->set('email', $hzal->email); $xregistration->set('confirmEmail', $hzal->email); } } } return $this->_show_registration_form($xregistration, 'create'); }
} ?> </li> <?php } ?> <?php if ($this->registration->Interests != REG_HIDE) { ?> <?php if ($this->params->get('access_tags') == 0 || $this->params->get('access_tags') == 1 && $loggedin || $this->params->get('access_tags') == 2 && $isUser) { ?> <?php $cls = ''; $mt = new \Components\Members\Models\Tags($this->profile->get('uidNumber')); $tags = $mt->render(); $tag_string = $mt->render('string'); if ($this->params->get('access_tags') == 2) { $cls .= 'private'; } if ($tag_string == "") { $cls .= $isUser ? " hidden" : " hide"; } if (isset($update_missing) && in_array("interests", array_keys($update_missing))) { $cls = str_replace(' hide', '', $cls); $cls .= ' missing'; } ?> <li class="profile-interests section <?php echo $cls;
/** * Search entries * * @return void */ public function searchTask() { // Incoming $filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'tag' => Request::getVar('tags', ''), 'search' => Request::getVar('q', ''), 'filterby' => Request::getWord('filterby', ''), 'sortby' => Request::getWord('sortby', 'date'), 'sort_Dir' => strtolower(Request::getWord('sortdir', 'desc')), 'area' => Request::getVar('area', '')); // Validate inputs $filters['tag'] = $filters['tag'] ? $filters['tag'] : Request::getVar('tag', ''); if ($filters['filterby'] && !in_array($filters['filterby'], array('open', 'closed'))) { $filters['filterby'] = ''; } if (!in_array($filters['sortby'], array('date', 'votes', 'rewards'))) { $filters['sortby'] = 'date'; } if (!in_array($filters['sort_Dir'], array('desc', 'asc'))) { $filters['sort_Dir'] = 'desc'; } if ($filters['area'] && !in_array($filters['area'], array('mine', 'assigned', 'interest'))) { $filters['area'] = ''; } // Get questions of interest // @TODO: Remove reference to members. Add getTags() to user? if ($filters['area'] == 'interest') { require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'tags.php'; // Get tags of interest $mt = new \Components\Members\Models\Tags(User::get('id')); $filters['tag'] = $mt->render('string'); } // Get assigned questions // @TODO: Remove reference to tools. Turn into an event call? if ($filters['area'] == 'assigned') { require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php'; // What tools did this user contribute? $db = App::get('db'); $TA = new \Components\Tools\Tables\Author($db); $tools = $TA->getToolContributions(User::get('id')); $mytooltags = array(); if ($tools) { foreach ($tools as $tool) { $mytooltags[] = 'tool' . $tool->toolname; } } $filters['tag'] = implode(',', $mytooltags); } $records = Question::all()->including(['responses', function ($response) { $response->select('id')->select('question_id')->where('state', '!=', Question::STATE_DELETED); }]); if ($filters['tag'] || $filters['area'] == 'interest' || $filters['area'] == 'assigned') { $cloud = new Tags(); $tags = $cloud->parse($filters['tag']); $records->select('#__answers_questions.*')->join('#__tags_object', '#__tags_object.objectid', '#__answers_questions.id')->join('#__tags', '#__tags.id', '#__tags_object.tagid')->whereEquals('#__tags_object.tbl', 'answers')->whereIn('#__tags.tag', $tags); } if ($filters['search']) { $filters['search'] = strtolower((string) $filters['search']); $records->whereLike('subject', $filters['search'], 1)->orWhereLike('question', $filters['search'], 1)->resetDepth(); } if ($filters['filterby'] == 'open') { $records->whereEquals('state', 0); } if ($filters['filterby'] == 'closed') { $records->whereEquals('state', 1); } if (!$filters['filterby'] || $filters['filterby'] == 'both') { $records->where('state', '<', Question::STATE_DELETED); } if ($filters['area'] == 'mine') { $records->whereEquals('created_by', User::get('id')); } switch ($filters['sortby']) { case 'rewards': $order = 'reward'; break; case 'votes': $order = 'helpful'; break; case 'date': default: $order = 'created'; break; } $results = $records->order($order, $filters['sort_Dir'])->paginated()->rows(); // Output HTML $this->view->setError($this->getErrors())->set('results', $results)->set('filters', $filters)->set('config', $this->config)->setLayout('search')->display(); }
/** * Event call to determine if this plugin should return data * * @param array $fields Fields filled in * @param object $profile MembersProfile * @return integer */ public function getProfileCompleteness($fields, $profile) { //default vars $num_fields = 0; $num_filled_fields = 0; $_property_map = array('Fullname' => 'name', 'Email' => 'email', 'URL' => 'web', 'Phone' => 'phone', 'Employment' => 'orgtype', 'Organization' => 'org', 'Citizenship' => 'countryorigin', 'Residency' => 'countryresident', 'Sex' => 'sex', 'Disability' => 'disability', 'Hispanic' => 'hispanic', 'Race' => 'race', 'Bio' => 'bio', 'Interests' => 'tags', 'OptIn' => 'mailPreferenceOption', 'ORCID' => 'orcid'); //unset errors from the fields object $fields->setErrors(array()); //load the user profile $registration = new \Components\Members\Models\Registration(); $registration->loadProfile($profile); //add tags to the registration object $database = App::get('db'); $mt = new \Components\Members\Models\Tags($profile->get('uidNumber')); $registration->_registration['tags'] = $mt->render('string'); //add bio to the registration object $fields->Bio = REG_OPTIONAL; $registration->_registration['bio'] = $profile->get("bio"); //loop through each field to see if we want to count it foreach ($fields as $k => $v) { //if the field is anything button hidden we want to count it if (in_array($v, array(REG_REQUIRED, REG_OPTIONAL, REG_READONLY))) { //check if we have a mapping (excludes certain unused vars) if (isset($_property_map[$k])) { //add to the number of fields count $num_fields++; //check to see if we have it filled in $value = $registration->get($_property_map[$k]); $type = gettype($registration->get($_property_map[$k])); if ($type == 'array' && !empty($value) || $type == 'string' && $value != '') { $num_filled_fields++; } } } } //return percentage return number_format($num_filled_fields / $num_fields * 100, 0); }
/** * Get user profile info * * @apiMethod GET * @apiUri /members/{id} * @apiParameter { * "name": "id", * "description": "Member identifier", * "type": "integer", * "required": true, * "default": null * } * @return void */ public function readTask() { $userid = Request::getInt('id', 0); $result = Member::oneOrFail($userid); if (!$result || !$result->get('id')) { throw new Exception(Lang::txt('COM_MEMBERS_ERROR_USER_NOT_FOUND'), 404); } // Get any request vars $base = rtrim(Request::base(), '/'); $profile = array('id' => $result->get('id'), 'username' => $result->get('username'), 'name' => $result->get('name'), 'first_name' => $result->get('givenName'), 'middle_name' => $result->get('middleName'), 'last_name' => $result->get('surname'), 'email' => $result->get('email'), 'member_since' => $result->get('registerDate'), 'picture' => array('thumb' => $result->picture(0, true), 'full' => $result->picture(0, false)), 'interests' => array(), 'url' => str_replace('/api', '', $base . '/' . ltrim(Route::url($result->link()), '/'))); // Get custom fields $attribs = Field::all()->ordered()->rows(); foreach ($attribs as $attrib) { $key = $attrib->get('name'); if ($attrib->get('type') == 'tags') { $val = $result->tags('string'); } else { $val = $result->get($key); } if (is_array($val)) { $val = implode(';', $val); } $profile[$key] = $val; } require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'tags.php'; $cloud = new \Components\Members\Models\Tags($userid); foreach ($cloud->tags('list') as $i => $tag) { $obj = new stdClass(); $obj->id = $tag->get('id'); $obj->raw_tag = $tag->get('raw_tag'); $obj->tag = $tag->get('tag'); $obj->uri = str_replace('/api', '', $base . '/' . ltrim(Route::url($tag->link()), '/')); $obj->substitutes_count = $tag->get('substitutes'); $obj->objects_count = $tag->get('total'); $profile['interests'][] = $obj; } // Corrects image path, API application breaks Route::url() in the Helper::getMemberPhoto() method. $profile['picture']['thumb'] = str_replace('/api', '', $base . '/' . $profile['picture']['thumb']); $profile['picture']['full'] = str_replace('/api', '', $base . '/' . $profile['picture']['full']); // Encode and return result $object = new stdClass(); $object->profile = $profile; $this->send($object); }
/** * Save an entry and return to main listing * * @param integer $redirect Redirect to main listing? * @return void */ public function saveTask($redirect = 1) { // Check for request forgeries Request::checkToken(); // Incoming user ID $id = Request::getInt('id', 0, 'post'); // Do we have an ID? if (!$id) { App::abort(500, Lang::txt('COM_MEMBERS_NO_ID')); return; } // Incoming profile edits $p = Request::getVar('profile', array(), 'post', 'none', 2); // Load the profile $profile = new Profile(); $profile->load($id); // Set the new info $profile->set('givenName', preg_replace('/\\s+/', ' ', trim($p['givenName']))); $profile->set('middleName', preg_replace('/\\s+/', ' ', trim($p['middleName']))); $profile->set('surname', preg_replace('/\\s+/', ' ', trim($p['surname']))); $name = trim($p['givenName']) . ' '; $name .= trim($p['middleName']) != '' ? trim($p['middleName']) . ' ' : ''; $name .= trim($p['surname']); $name = preg_replace('/\\s+/', ' ', $name); $profile->set('name', $name); if (isset($p['vip'])) { $profile->set('vip', $p['vip']); } else { $profile->set('vip', 0); } $profile->set('orcid', trim($p['orcid'])); $profile->set('url', trim($p['url'])); $profile->set('phone', trim($p['phone'])); $profile->set('orgtype', trim($p['orgtype'])); $profile->set('organization', trim($p['organization'])); $profile->set('bio', trim($p['bio'])); if (isset($p['public'])) { $profile->set('public', $p['public']); } else { $profile->set('public', 0); } $profile->set('modifiedDate', Date::toSql()); $profile->set('homeDirectory', trim($p['homeDirectory'])); $profile->set('loginShell', trim($p['loginShell'])); $ec = Request::getInt('emailConfirmed', 0, 'post'); if ($ec) { $profile->set('emailConfirmed', $ec); } else { $confirm = Helpers\Utility::genemailconfirm(); $profile->set('emailConfirmed', $confirm); } if (isset($p['email'])) { $profile->set('email', trim($p['email'])); } if (isset($p['mailPreferenceOption'])) { $profile->set('mailPreferenceOption', trim($p['mailPreferenceOption'])); } else { $profile->set('mailPreferenceOption', -1); } if (!empty($p['gender'])) { $profile->set('gender', trim($p['gender'])); } if (!empty($p['disability'])) { if ($p['disability'] == 'yes') { if (!is_array($p['disabilities'])) { $p['disabilities'] = array(); } if (count($p['disabilities']) == 1 && isset($p['disabilities']['other']) && empty($p['disabilities']['other'])) { $profile->set('disability', array('no')); } else { $profile->set('disability', $p['disabilities']); } } else { $profile->set('disability', array($p['disability'])); } } if (!empty($p['hispanic'])) { if ($p['hispanic'] == 'yes') { if (!is_array($p['hispanics'])) { $p['hispanics'] = array(); } if (count($p['hispanics']) == 1 && isset($p['hispanics']['other']) && empty($p['hispanics']['other'])) { $profile->set('hispanic', array('no')); } else { $profile->set('hispanic', $p['hispanics']); } } else { $profile->set('hispanic', array($p['hispanic'])); } } if (isset($p['race']) && is_array($p['race'])) { $profile->set('race', $p['race']); } // Save the changes if (!$profile->update()) { App::abort(500, $profile->getError()); return false; } // Do we have a new pass? $newpass = trim(Request::getVar('newpass', '', 'post')); if ($newpass != '') { // Get password rules and validate $password_rules = \Hubzero\Password\Rule::getRules(); $validated = \Hubzero\Password\Rule::validate($newpass, $password_rules, $profile->get('uidNumber')); if (!empty($validated)) { // Set error $this->setError(Lang::txt('COM_MEMBERS_PASSWORD_DOES_NOT_MEET_REQUIREMENTS')); $this->validated = $validated; $redirect = false; } else { // Save password \Hubzero\User\Password::changePassword($profile->get('username'), $newpass); } } $passinfo = \Hubzero\User\Password::getInstance($id); if (is_object($passinfo)) { // Do we have shadow info to change? $shadowMax = Request::getInt('shadowMax', false, 'post'); $shadowWarning = Request::getInt('shadowWarning', false, 'post'); $shadowExpire = Request::getVar('shadowExpire', '', 'post'); if ($shadowMax || $shadowWarning || !is_null($passinfo->get('shadowExpire')) && empty($shadowExpire)) { if ($shadowMax) { $passinfo->set('shadowMax', $shadowMax); } if ($shadowExpire || !is_null($passinfo->get('shadowExpire')) && empty($shadowExpire)) { if (preg_match("/[0-9]{4}-[0-9]{2}-[0-9]{2}/", $shadowExpire)) { $shadowExpire = strtotime($shadowExpire) / 86400; $passinfo->set('shadowExpire', $shadowExpire); } elseif (preg_match("/[0-9]+/", $shadowExpire)) { $passinfo->set('shadowExpire', $shadowExpire); } elseif (empty($shadowExpire)) { $passinfo->set('shadowExpire', NULL); } } if ($shadowWarning) { $passinfo->set('shadowWarning', $shadowWarning); } $passinfo->update(); } } // Get the user's interests (tags) $tags = trim(Request::getVar('tags', '')); // Process tags include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'tags.php'; $mt = new \Components\Members\Models\Tags($id); $mt->setTags($tags, $id); // Make sure certain changes make it back to the user table $user = User::getInstance($id); $user->set('name', $name); $user->set('email', $profile->get('email')); if (!$user->save()) { App::abort('', Lang::txt($user->getError())); return false; } if ($redirect) { // Redirect App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_MEMBERS_MEMBER_SAVED')); } else { $this->editTask($id); } }
/** * Show a form for editing a profile * * @param object $profile Profile * @return void */ public function editTask($profile = null) { // Incoming $id = Request::getInt('id', 0); // Check if they're logged in if (User::isGuest()) { $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->_controller . '&task=activity', false, true), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn), false)); } // Ensure we have an ID if (!$id) { App::abort(404, Lang::txt('COM_MEMBERS_NO_ID')); } // Check authorization if (!User::authorise('core.manage', $this->_option) && $id != User::get('id')) { App::abort(403, Lang::txt('COM_MEMBERS_NOT_AUTH')); } // Initiate profile class if we don't already have one and load info // Note: if we already have one then we just came from $this->save() if (!is_object($profile)) { $profile = Member::oneOrFail($id); } // Ensure we have a member if (!$profile->get('id')) { App::abort(404, Lang::txt('COM_MEMBERS_NOT_FOUND')); } // Get the user's interests (tags) $mt = new \Components\Members\Models\Tags($id); $this->view->tags = $mt->render('string'); // Set the page title $title = Lang::txt(strtoupper($this->_option)); $title .= $this->_task ? ': ' . Lang::txt(strtoupper($this->_task)) : ''; Document::setTitle($title); // Set the pathway if (Pathway::count() <= 0) { Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option); } Pathway::append(stripslashes($profile->get('name')), 'index.php?option=' . $this->_option . '&id=' . $profile->get('id')); Pathway::append(Lang::txt(strtoupper($this->_task)), 'index.php?option=' . $this->_option . '&id=' . $profile->get('id') . '&task=' . $this->_task); foreach ($this->getErrors() as $error) { Notify::error($error); } $fields = Field::all()->including(['options', function ($option) { $option->select('*')->ordered(); }])->where('action_edit', '!=', Field::STATE_HIDDEN)->ordered()->rows(); // Ouput HTML $this->view->set('title', $title)->set('profile', $profile)->set('fields', $fields)->setLayout('edit')->display(); }
/** * Save tags * * @return void */ private function _saveTagsData() { if ($this->_mode == 'PATCH' && !$this->record->tags) { return; } // save tags $tags = new \Components\Members\Models\Tags($this->record->entry->get('id')); $tags->setTags($this->record->tags, User::get('id')); }
/** * Save changes to a profile * Outputs JSON when called via AJAX, redirects to profile otherwise * * @return string JSON */ public function saveTask() { // Check if they are logged in if (User::isGuest()) { return false; } Request::checkToken(array('get', 'post')); $no_html = Request::getVar("no_html", 0); // Incoming user ID $id = Request::getInt('id', 0, 'post'); // Do we have an ID? if (!$id) { App::abort(404, Lang::txt('MEMBERS_NO_ID')); return; } // Incoming profile edits $p = Request::getVar('profile', array(), 'post', 'none', 2); $n = Request::getVar('name', array(), 'post'); $a = Request::getVar('access', array(), 'post'); // Load the profile $profile = \Hubzero\User\Profile::getInstance($id); $oldemail = $profile->get('email'); if ($n) { $profile->set('givenName', trim($n['first'])); $profile->set('middleName', trim($n['middle'])); $profile->set('surname', trim($n['last'])); $name = trim($n['first']) . ' '; $name .= trim($n['middle']) != '' ? trim($n['middle']) . ' ' : ''; $name .= trim($n['last']); $profile->set('name', $name); } if (isset($p['bio'])) { $profile->set('bio', trim($p['bio'])); } if (is_array($a) && count($a) > 0) { foreach ($a as $k => $v) { $v = intval($v); if (!in_array($v, array(0, 1, 2, 3, 4))) { $v = 0; } $profile->setParam('access_' . $k, $v); } } if (isset($p['public'])) { $profile->set('public', $p['public']); } // Set some post data for the xregistration class $tags = trim(Request::getVar('tags', '')); if (isset($tags)) { Request::setVar('interests', $tags, 'post'); } // Instantiate a new \Components\Members\Models\Registration $xregistration = new \Components\Members\Models\Registration(); $xregistration->loadPOST(); // Push the posted data to the profile // Note: this is done before the required fields check so, if we need to display the edit form, it'll show all the new changes if (!is_null($xregistration->_registration['email'])) { $profile->set('email', $xregistration->_registration['email']); // Unconfirm if the email address changed if ($oldemail != $xregistration->_registration['email']) { // Get a new confirmation code $confirm = \Components\Members\Helpers\Utility::genemailconfirm(); $profile->set('emailConfirmed', $confirm); } } if (!is_null($xregistration->_registration['countryresident'])) { $profile->set('countryresident', $xregistration->_registration['countryresident']); } if (!is_null($xregistration->_registration['countryorigin'])) { $profile->set('countryorigin', $xregistration->_registration['countryorigin']); } if (!is_null($xregistration->_registration['nativetribe'])) { $profile->set('nativeTribe', $xregistration->_registration['nativetribe']); } if ($xregistration->_registration['org'] != '') { $profile->set('organization', $xregistration->_registration['org']); } elseif ($xregistration->_registration['orgtext'] != '') { $profile->set('organization', $xregistration->_registration['orgtext']); } if (!is_null($xregistration->_registration['web'])) { $profile->set('url', $xregistration->_registration['web']); } if (!is_null($xregistration->_registration['phone'])) { $profile->set('phone', $xregistration->_registration['phone']); } if (!is_null($xregistration->_registration['orgtype'])) { $profile->set('orgtype', $xregistration->_registration['orgtype']); } if (!is_null($xregistration->_registration['sex'])) { $profile->set('gender', $xregistration->_registration['sex']); } if (!is_null($xregistration->_registration['disability'])) { $profile->set('disability', $xregistration->_registration['disability']); } if (!is_null($xregistration->_registration['hispanic'])) { $profile->set('hispanic', $xregistration->_registration['hispanic']); } if (!is_null($xregistration->_registration['race'])) { $profile->set('race', $xregistration->_registration['race']); } if (!is_null($xregistration->_registration['mailPreferenceOption'])) { $profile->set('mailPreferenceOption', $xregistration->_registration['mailPreferenceOption']); } if (!is_null($xregistration->_registration['usageAgreement'])) { $profile->set('usageAgreement', $xregistration->_registration['usageAgreement']); } if (!is_null($xregistration->_registration['orcid'])) { $profile->set('orcid', $xregistration->_registration['orcid']); } $field_to_check = Request::getVar("field_to_check", array()); // Check that required fields were filled in properly if (!$xregistration->check('edit', $profile->get('uidNumber'), $field_to_check)) { if (!$no_html) { $this->_task = 'edit'; $this->editTask($xregistration, $profile); return; } else { echo json_encode($xregistration); exit; } } //are we declining the terms of use //if yes we want to set the usage agreement to 0 and profile to private $declineTOU = Request::getVar('declinetou', 0); if ($declineTOU) { $profile->set('public', 0); $profile->set('usageAgreement', 0); } // Set the last modified datetime $profile->set('modifiedDate', Date::toSql()); // Save the changes if (!$profile->update()) { App::abort(500, $profile->getError()); return false; } // Process tags if (isset($tags) && in_array('interests', $field_to_check)) { $mt = new \Components\Members\Models\Tags($id); $mt->setTags($tags, $id); } $email = $profile->get('email'); $name = $profile->get('name'); // Make sure certain changes make it back to the user table if ($id > 0) { $user = User::getInstance($id); $jname = $user->get('name'); $jemail = $user->get('email'); if ($name != trim($jname)) { $user->set('name', $name); } if ($email != trim($jemail)) { $user->set('email', $email); } if ($name != trim($jname) || $email != trim($jemail)) { if (!$user->save()) { App::abort(500, Lang::txt($user->getError())); return false; } } // Update session if name is changing if ($n && $user->get('name') != App::get('session')->get('user')->get('name')) { $suser = App::get('session')->get('user'); $user->set('name', $suser->get('name')); } // Update session if email is changing if ($user->get('email') != App::get('session')->get('user')->get('email')) { $suser = App::get('session')->get('user'); $user->set('email', $suser->get('email')); // add item to session to mark that the user changed emails // this way we can serve profile images for these users but not all // unconfirmed users $session = App::get('session'); $session->set('userchangedemail', 1); } } // Send a new confirmation code AFTER we've successfully saved the changes to the e-mail address if ($email != $oldemail) { $this->_message = $this->_sendConfirmationCode($profile->get('username'), $email, $confirm); } //if were declinging the terms we want to logout user and tell the javascript if ($declineTOU) { App::get('auth')->logout(); echo json_encode(array('loggedout' => true)); return; } if (!$no_html) { // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . ($id ? '&id=' . $id . '&active=profile' : '')), $this->_message); } else { // Output JSON echo json_encode(array('success' => true)); } }
/** * Search entries * * @return void */ public function searchTask() { $this->view->config = $this->config; $this->view->task = $this->_task; // Incoming $this->view->filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'tag' => Request::getVar('tags', ''), 'q' => Request::getVar('q', ''), 'filterby' => Request::getWord('filterby', ''), 'sortby' => Request::getWord('sortby', 'date'), 'sort_Dir' => Request::getWord('sortdir', 'DESC'), 'area' => Request::getVar('area', '')); // Validate inputs $this->view->filters['tag'] = $this->view->filters['tag'] ? $this->view->filters['tag'] : Request::getVar('tag', ''); if ($this->view->filters['filterby'] && !in_array($this->view->filters['filterby'], array('open', 'closed'))) { $this->view->filters['filterby'] = ''; } if (!in_array($this->view->filters['sortby'], array('date', 'votes', 'rewards'))) { $this->view->filters['sortby'] = 'date'; } if ($this->view->filters['area'] && !in_array($this->view->filters['area'], array('mine', 'assigned', 'interest'))) { $this->view->filters['area'] = ''; } // Get questions of interest if ($this->view->filters['area'] == 'interest') { require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'models' . DS . 'tags.php'; // Get tags of interest $mt = new \Components\Members\Models\Tags(User::get('id')); $mytags = $mt->render('string'); $this->view->filters['tag'] = $this->view->filters['tag'] ? $this->view->filters['tag'] : $mytags; $this->view->filters['mine'] = 0; } // Get assigned questions if ($this->view->filters['area'] == 'assigned') { require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'tables' . DS . 'author.php'; // What tools did this user contribute? $TA = new \Components\Tools\Tables\Author($this->database); $tools = $TA->getToolContributions(User::get('id')); $mytooltags = array(); if ($tools) { foreach ($tools as $tool) { $mytooltags[] = 'tool' . $tool->toolname; } } $this->view->filters['tag'] = $this->view->filters['tag'] ? $this->view->filters['tag'] : implode(',', $mytooltags); $this->view->filters['mine'] = 0; } if ($this->view->filters['area'] == 'mine') { $this->view->filters['mine'] = 1; } // Instantiate a Questions object $aq = new Tables\Question($this->database); if (($this->view->filters['area'] == 'interest' || $this->view->filters['area'] == 'assigned') && !$this->view->filters['tag']) { // Get a record count $this->view->total = 0; // Get records $this->view->results = array(); } else { // Get a record count $this->view->total = $aq->getCount($this->view->filters); // Get records $this->view->results = $aq->getResults($this->view->filters); } // Did we get any results? if (count($this->view->results) > 0) { // Do some processing on the results foreach ($this->view->results as $i => $result) { $this->view->results[$i] = new Question($result); } } // Set the page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Output HTML foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->setLayout('search')->display(); }