/** * Get the creator of this entry * * Accepts an optional property name. If provided * it will return that property value. Otherwise, * it returns the entire user object * * @return mixed */ public function creator($property = null) { if (!$this->_creator instanceof Member) { $this->_creator = Member::oneOrNew($this->get('addedBy')); } if ($property) { $property = $property == 'uidNumber' ? 'id' : $property; if ($property == 'picture') { return $this->_creator->picture(); } return $this->_creator->get($property); } return $this->_creator; }
/** * Show a form for sending a success story * * @param object $row * @return void */ public function storyTask($row = null) { if (User::isGuest()) { $here = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($here)), Lang::txt('COM_FEEDBACK_STORY_LOGIN'), 'warning'); } // Check to see if the user temp folder for holding pics is there, if so then remove it if (is_dir($this->tmpPath() . DS . User::get('id'))) { Filesystem::deleteDirectory($this->tmpPath() . DS . User::get('id')); } // Incoming $quote = array('long' => Request::getVar('quote', '', 'post'), 'short' => Request::getVar('short_quote', '', 'post')); // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Get the curent user's profile $user = Member::oneOrNew(User::get('id')); // Create the object if we weren't passed one if (!$row) { $row = Quote::oneOrNew(0); $row->set('org', $user->get('organization')); $row->set('fullname', $user->get('name')); } // Output HTML $this->view->set('title', $this->_title)->set('quote', $quote)->set('row', $row)->set('user', $user)->setErrors($this->getErrors())->setLayout('story')->display(); }
/** * Render the events * * @param array Array of group events * @return string */ private function renderMembers($group, $members) { $content = '<div class="member_browser">'; if (count($members) > 0) { include_once \Component::path('com_members') . DS . 'models' . DS . 'member.php'; foreach ($members as $member) { $profile = \Components\Members\Models\Member::oneOrNew($member); $link = \Route::url($profile->link()); $content .= '<a href="' . $link . '" class="member" title="Go to ' . stripslashes($profile->get('name')) . '\'s Profile.">'; $content .= '<img src="' . $profile->picture(0, true) . '" alt="' . stripslashes($profile->get('name')) . '" class="member-border" width="50px" height="50px" />'; $content .= '<span class="name">' . stripslashes($profile->get('name')) . '</span>'; $content .= '<span class="org">' . stripslashes($profile->get('organization')) . '</span>'; $content .= '</a>'; } } $content .= '</div><!-- /.member_browser -->'; return $content; }
?> <section class="below section"> <div class="subject"> <h3> <?php echo Lang::txt('COM_SUPPORT_COMMENT_FORM'); ?> </h3> <form action="<?php echo Route::url($this->row->link('update')); ?> " method="post" id="commentform" enctype="multipart/form-data"> <p class="comment-member-photo"> <span class="comment-anchor"></span> <?php $jxuser = \Components\Members\Models\Member::oneOrNew(User::get('id')); $anon = 1; if (!User::isGuest()) { $anon = 0; } ?> <img src="<?php echo $jxuser->picture($anon); ?> " alt="" /> </p> <fieldset> <input type="hidden" name="id" value="<?php echo $this->row->get('id'); ?> " />
/** * Constructor * * @param integer $id Member ID * @return void */ public function __construct($oid = null) { $this->_obj = \Components\Members\Models\Member::oneOrNew($oid); $this->_baselink = $this->_obj->link() . '&active=collections'; }
/** * Get the modifier of this entry * * Accepts an optional property name. If provided * it will return that property value. Otherwise, * it returns the entire user object * * @param string $property Property to retrieve * @param mixed $default Default value if property not set * @return mixed */ public function modifier($property = null, $default = null) { if (!$this->_modifier instanceof Member) { $this->_modifier = Member::oneOrNew($this->get('modified_by')); } if ($property) { $property = $property == 'id' ? 'uidNumber' : $property; return $this->_modifier->get($property, $default); } return $this->_modifier; }
/** * Static method for formatting results * * @param object $row Database row * @return string HTML */ public static function out($row) { require_once \Component::path('com_members') . DS . 'models' . DS . 'member.php'; $member = \Components\Members\Models\Member::oneOrNew($row->id); $row->href = Route::url($member->link()); $html = "\t" . '<li class="member">' . "\n"; $html .= "\t\t" . '<p class="photo"><img width="50" height="50" src="' . $member->picture() . '" alt="" /></p>' . "\n"; $html .= "\t\t" . '<p class="title"><a href="' . $row->href . '">' . stripslashes($row->title) . '</a></p>' . "\n"; if ($row->ftext) { $html .= "\t\t" . \Hubzero\Utility\String::truncate(\Hubzero\Utility\Sanitize::stripAll(stripslashes($row->ftext)), 200) . "\n"; } $html .= "\t\t" . '<p class="href">' . Request::base() . ltrim($row->href, '/') . '</p>' . "\n"; $html .= "\t" . '</li>' . "\n"; return $html; }
/** * Get the creator of this entry * * Accepts an optional property name. If provided * it will return that property value. Otherwise, * it returns the entire object * * @param string $property Property to retrieve * @param mixed $default Default value if property not set * @return mixed */ public function creator($property = null, $default = null) { if (!$this->_creator instanceof Member) { $this->_creator = Member::oneOrNew($this->get('created_by')); if (!trim($this->_creator->get('name'))) { $this->_creator->set('name', Lang::txt('(unknown)')); } } if ($property) { $property = $property == 'uidNumber' ? 'id' : $property; return $this->_creator->get($property, $default); } return $this->_creator; }
/** * Show a form for registering * * @return void */ 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'); } if (!isset($this->_taskMap[$this->_task])) { $this->_task = 'create'; Request::setVar('task', 'create'); } // If user registration is not allowed, show 403 not authorized. $usersConfig = Component::params('com_members'); 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 $result = $xregistration->check('create'); // Incoming profile edits $profile = Request::getVar('profile', array(), 'post', 'none', 2); // Compile profile data foreach ($profile as $key => $data) { if (isset($profile[$key]) && is_array($profile[$key])) { $profile[$key] = array_filter($profile[$key]); } if (isset($profile[$key . '_other']) && trim($profile[$key . '_other'])) { if (is_array($profile[$key])) { $profile[$key][] = $profile[$key . '_other']; } else { $profile[$key] = $profile[$key . '_other']; } unset($profile[$key . '_other']); } } // Validate profile data $fields = \Components\Members\Models\Profile\Field::all()->including(['options', function ($option) { $option->select('*'); }])->where('action_create', '!=', \Components\Members\Models\Profile\Field::STATE_HIDDEN)->ordered()->rows(); // Validate profile fields if ($fields->count()) { $form = new \Hubzero\Form\Form('profile', array('control' => 'profile')); $form->load(\Components\Members\Models\Profile\Field::toXml($fields, 'create', $profile)); $form->bind(new \Hubzero\Config\Registry($profile)); if (!$form->validate($profile)) { $result = false; foreach ($form->getErrors() as $key => $error) { if ($error instanceof \Hubzero\Form\Exception\MissingData) { $xregistration->_missing[$key] = $error; } $xregistration->_invalid[$key] = $error; } } } // Passed validation? if ($result) { // Get required system objects $user = clone User::getInstance(); // 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('givenName', $xregistration->get('givenName', '')); $user->set('middleName', $xregistration->get('middleName', '')); $user->set('surname', $xregistration->get('surname', '')); $user->set('email', $xregistration->get('email', '')); $user->set('usageAgreement', (int) $xregistration->get('usageAgreement', 0)); $user->set('sendEmail', -1); if ($xregistration->get('sendEmail') >= 0) { $user->set('sendEmail', (int) $xregistration->get('sendEmail')); } // Set home directory $hubHomeDir = rtrim($this->config->get('homedir'), '/'); if (!$hubHomeDir) { // try to deduce a viable home directory based on sitename or live_site $sitename = strtolower(Config::get('sitename')); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } if (empty($sitename)) { $sitename = strtolower(Request::base()); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } } $hubHomeDir = DS . 'home'; if (!empty($sitename)) { $hubHomeDir .= DS . $sitename; } } $user->set('homeDirectory', $hubHomeDir . DS . $user->get('username')); $user->set('loginShell', '/bin/bash'); $user->set('ftpShell', '/usr/lib/sftp-server'); // Set some initial user values $user->set('id', 0); $user->set('accessgroups', array($newUsertype)); $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); } $user->set('access', 5); $user->set('activation', -rand(1, pow(2, 31) - 1)); if (is_object($hzal)) { if ($user->get('email') == $hzal->email) { $user->set('activation', 3); } } else { if ($useractivation == 0) { $user->set('activation', 1); $user->set('access', (int) $this->config->get('privacy', 1)); } } $user->set('password', \Hubzero\User\Password::getPasshash($xregistration->get('password'))); // Do we have a return URL? $regReturn = Request::getVar('return', ''); if ($regReturn) { $user->setParam('return', $regReturn); } // If we managed to create a user if ($user->save()) { $access = array(); foreach ($fields as $field) { $access[$field->get('name')] = $field->get('access'); } $profile = $xregistration->_registration['_profile']; // Save profile data $member = Member::oneOrNew($user->get('id')); if (!$member->saveProfile($profile, $access)) { \Notify::error($member->getError()); // Don't stop the registration process! // At this point, the account was successfully created. // The profile info, however, may have issues. But, it's not crucial. //$result = false; } } else { \Notify::error($user->getError()); $result = false; } // If everything is OK so far... if ($result) { $result = \Hubzero\User\Password::changePassword($user->get('id'), $xregistration->get('password')); // Set password back here in case anything else down the line is looking for it $user->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')); } // Send confirmation email if ($user->get('activation') < 0) { \Components\Members\Helpers\Utility::sendConfirmEmail($user, $xregistration); } // Instantiate a new view $this->view->set('title', Lang::txt('COM_MEMBERS_REGISTER_CREATE_ACCOUNT'))->set('sitename', Config::get('sitename'))->set('xprofile', $user)->setErrors($this->getErrors())->setLayout('create')->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::getInstance()); $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); } } } // Set the pathway $this->_buildPathway(); // Set the page title $this->_buildTitle(); return $this->_show_registration_form($xregistration, 'create'); }
/** * Get the owner of this entry * * Accepts an optional property name. If provided * it will return that property value. Otherwise, * it returns the entire user object * * @param string $property User property to look up * @param mixed $default Value to return if property not found * @return mixed */ public function owner($property = null, $default = null) { if (!$this->_data->get('owner.profile') instanceof Member) { $user = Member::oneOrNew($this->get('owner')); $this->_data->set('owner.profile', $user); } if ($property) { $property = $property == 'uidNumber' ? 'id' : $property; return $this->_data->get('owner.profile')->get($property, $default); } return $this->_data->get('owner.profile'); }
/** * Save an entry and return to main listing * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); if (!User::authorise('core.manage', $this->_option) && !User::authorise('core.admin', $this->_option) && !User::authorise('core.create', $this->_option) && !User::authorise('core.edit', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming profile edits $fields = Request::getVar('fields', array(), 'post', 'none', 2); // Load the profile $user = Member::oneOrNew($fields['id']); // Get the user before changes so we can // compare how data changed later on $prev = clone $user; // Set the incoming data $user->set($fields); if ($user->isNew()) { $newUsertype = $this->config->get('new_usertype'); if (!$newUsertype) { $newUsertype = Accessgroup::oneByTitle('Registered')->get('id'); } $user->set('accessgroups', array($newUsertype)); // Check that username is filled if (!Validate::username($user->get('username'))) { Notify::error(Lang::txt('COM_MEMBERS_MEMBER_USERNAME_INVALID')); return $this->editTask($user); } // Check email is valid if (!Validate::email($user->get('email'))) { Notify::error(Lang::txt('COM_MEMBERS_MEMBER_EMAIL_INVALID')); return $this->editTask($user); } // Set home directory $hubHomeDir = rtrim($this->config->get('homedir'), '/'); if (!$hubHomeDir) { // try to deduce a viable home directory based on sitename or live_site $sitename = strtolower(Config::get('sitename')); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } if (empty($sitename)) { $sitename = strtolower(Request::base()); $sitename = preg_replace('/^http[s]{0,1}:\\/\\//', '', $sitename, 1); $sitename = trim($sitename, '/ '); $sitename_e = explode('.', $sitename, 2); if (isset($sitename_e[1])) { $sitename = $sitename_e[0]; } if (!preg_match("/^[a-zA-Z]+[\\-_0-9a-zA-Z\\.]+\$/i", $sitename)) { $sitename = ''; } } $hubHomeDir = DS . 'home'; if (!empty($sitename)) { $hubHomeDir .= DS . $sitename; } } $user->set('homeDirectory', $hubHomeDir . DS . $user->get('username')); $user->set('loginShell', '/bin/bash'); $user->set('ftpShell', '/usr/lib/sftp-server'); $user->set('registerDate', Date::toSql()); } // Set the new info $user->set('givenName', preg_replace('/\\s+/', ' ', trim($fields['givenName']))); $user->set('middleName', preg_replace('/\\s+/', ' ', trim($fields['middleName']))); $user->set('surname', preg_replace('/\\s+/', ' ', trim($fields['surname']))); $name = array($user->get('givenName'), $user->get('middleName'), $user->get('surname')); $name = implode(' ', $name); $name = preg_replace('/\\s+/', ' ', $name); $user->set('name', $name); $user->set('modifiedDate', Date::toSql()); if ($ec = Request::getInt('activation', 0, 'post')) { $user->set('activation', $ec); } else { $user->set('activation', Helpers\Utility::genemailconfirm()); } // Can't block yourself if ($user->get('block') && $user->get('id') == User::get('id') && !User::get('block')) { Notify::error(Lang::txt('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF')); return $this->editTask($user); } // Make sure that we are not removing ourself from Super Admin group $iAmSuperAdmin = User::authorise('core.admin'); if ($iAmSuperAdmin && User::get('id') == $user->get('id')) { // Check that at least one of our new groups is Super Admin $stillSuperAdmin = false; foreach ($fields['accessgroups'] as $group) { $stillSuperAdmin = $stillSuperAdmin ? $stillSuperAdmin : \JAccess::checkGroup($group, 'core.admin'); } if (!$stillSuperAdmin) { Notify::error(Lang::txt('COM_USERS_USERS_ERROR_CANNOT_DEMOTE_SELF')); return $this->editTask($user); } } // Save the changes if (!$user->save()) { Notify::error($user->getError()); return $this->editTask($user); } // Save profile data $profile = Request::getVar('profile', array(), 'post', 'none', 2); $access = Request::getVar('profileaccess', array(), 'post', 'none', 2); foreach ($profile as $key => $data) { if (isset($profile[$key]) && is_array($profile[$key])) { $profile[$key] = array_filter($profile[$key]); } if (isset($profile[$key . '_other']) && trim($profile[$key . '_other'])) { if (is_array($profile[$key])) { $profile[$key][] = $profile[$key . '_other']; } else { $profile[$key] = $profile[$key . '_other']; } unset($profile[$key . '_other']); } } if (!$user->saveProfile($profile, $access)) { Notify::error($user->getError()); return $this->editTask($user); } // Do we have a new pass? $newpass = trim(Request::getVar('newpass', '', 'post')); if ($newpass) { // Get password rules and validate $password_rules = \Hubzero\Password\Rule::all()->whereEquals('enabled', 1)->rows(); $validated = \Hubzero\Password\Rule::verify($newpass, $password_rules, $user->get('id')); if (!empty($validated)) { // Set error Notify::error(Lang::txt('COM_MEMBERS_PASSWORD_DOES_NOT_MEET_REQUIREMENTS')); $this->validated = $validated; $this->_task = 'apply'; } else { // Save password \Hubzero\User\Password::changePassword($user->get('username'), $newpass); } } $passinfo = \Hubzero\User\Password::getInstance($user->get('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(); } } // Check for spam count $reputation = Request::getVar('spam_count', null, 'post'); if (!is_null($reputation)) { $user->reputation->set('spam_count', $reputation); $user->reputation->save(); } // Email the user that their account has been approved if (!$prev->get('approved') && $this->config->get('useractivation_email')) { if (!$this->emailApprovedUser($user)) { Notify::error(Lang::txt('COM_MEMBERS_ERROR_EMAIL_FAILED')); } } // Set success message Notify::success(Lang::txt('COM_MEMBERS_MEMBER_SAVED')); // Drop through to edit form? if ($this->getTask() == 'apply') { return $this->editTask($user); } // Redirect $this->cancelTask(); }
/** * Format an entry * * @param object $row Database row * @param string $tbl Format type * @param number $txtLength Max text length to display * @param integer $getid Just return the ID or not * @return string HTML */ private function _composeEntry($row, $tbl, $txtLength = 100, $getid = 0) { $yearFormat = 'Y'; $monthFormat = 'm'; $out = ''; // Do we have a picture? $thumb = ''; switch ($tbl) { case 'profiles': if ($getid) { return $row->get('id'); } // Load their bio $title = $row->get('name'); if (!trim($title)) { $title = $row->get('givenName') . ' ' . $row->get('surname'); } $out .= '<span class="spotlight-img"><a href="' . Route::url($row->link()) . '"><img width="30" height="30" src="' . $row->picture() . '" alt="' . htmlentities($title) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . Route::url($row->link()) . '">' . $title . '</a></span>, ' . $row->get('organization') . "\n"; $out .= ' - ' . Lang::txt('Contributions') . ': ' . $this->_countContributions($row->get('id')) . "\n"; $out .= '<div class="clear"></div>' . "\n"; break; case 'blog': if ($getid) { return $row->id; } $thumb = trim($this->params->get('default_blogpic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } $profile = \Components\Members\Models\Member::oneOrNew($row->created_by); if (!$row->title) { $out = ''; } else { $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by . '&active=blog&task=' . Date::of($row->publish_up)->toLocal($yearFormat) . '/' . Date::of($row->publish_up)->toLocal($monthFormat) . '/' . $row->alias) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->title)) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by . '&active=blog&task=' . Date::of($row->publish_up)->toLocal($yearFormat) . '/' . Date::of($row->publish_up)->toLocal($monthFormat) . '/' . $row->alias) . '">' . $row->title . '</a></span> '; $out .= ' by <a href="' . Route::url('index.php?option=com_members&id=' . $row->created_by) . '">' . $profile->get('name') . '</a> - ' . Lang::txt('in Blogs') . "\n"; $out .= '<div class="clear"></div>' . "\n"; } break; case 'topics': if ($getid) { return $row->id; } $url = $row->group_cn && $row->scope ? 'groups' . DS . $row->scope . DS . $row->pagename : 'topics' . DS . $row->pagename; $thumb = trim($this->params->get('default_topicpic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_topics&pagename=' . $row->pagename) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->title)) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . $url . '">' . stripslashes($row->title) . '</a></span> '; $out .= ' - ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_topics') . '">' . Lang::txt('Topics') . '</a>' . "\n"; $out .= '<div class="clear"></div>' . "\n"; break; case 'answers': if ($getid) { return $row->id; } $thumb = trim($this->params->get('default_questionpic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } $name = Lang::txt('Anonymous'); if ($row->anonymous == 0) { $name = \Components\Members\Models\Member::oneOrNew($row->created_by)->get('name'); } $out .= '<span class="spotlight-img"><a href="' . Route::url('index.php?option=com_answers&task=question&id=' . $row->id) . '"><img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities(stripslashes($row->subject)) . '" /></a></span>' . "\n"; $out .= '<span class="spotlight-item"><a href="' . Route::url('index.php?option=com_answers&task=question&id=' . $row->id) . '">' . stripslashes($row->subject) . '</a></span> '; $out .= ' - ' . Lang::txt('asked by') . ' ' . $name . ', ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_answers') . '">' . Lang::txt('Answers') . '</a>' . "\n"; $out .= '<div class="clear"></div>' . "\n"; break; default: if ($getid) { return $row->id; } if ($tbl == 'itunes') { $thumb = trim($this->params->get('default_itunespic', '/core/modules/mod_spotlight/assets/img/default.gif')); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } } else { $rconfig = Component::params('com_resources'); $path = substr(PATH_APP, strlen(PATH_ROOT)) . DS . trim($rconfig->get('uploadpath', '/site/resources'), DS); $path = DS . trim($path, DS); $path = $this->_buildPath($row->created, $row->id, $path); if ($row->type == 7) { include_once Component::path('com_tools') . DS . 'tables' . DS . 'version.php'; $tv = new \Components\Tools\Tables\Version($this->database); $versionid = $tv->getVersionIdFromResource($row->id, 'current'); $picture = $this->_getToolImage($path, $versionid); } else { $picture = $this->_getImage($path); } $thumb = $path . DS . $picture; if (!is_file(PATH_ROOT . $thumb) or !$picture) { $thumb = DS . trim($rconfig->get('defaultpic', '/core/modules/mod_spotlight/assets/img/default.gif'), DS); if ($thumb == '/modules/mod_spotlight/default.gif') { $thumb = '/core/modules/mod_spotlight/assets/img/default.gif'; } } if (substr($thumb, 0, strlen('/modules')) == '/modules' || substr($thumb, 0, strlen('/components')) == '/components') { $thumb = '/core' . $thumb; } $thumb = str_replace('com_resources/assets', 'com_resources/site/assets', $thumb); } $normalized = preg_replace("/[^a-zA-Z0-9]/", '', strtolower($row->typetitle)); $row->typetitle = trim(stripslashes($row->typetitle)); $row->title = stripslashes($row->title); $chars = strlen($row->title . $row->typetitle); $remaining = $txtLength - $chars; $remaining = $remaining <= 0 ? 0 : $remaining; $titlecut = $remaining ? 0 : $txtLength - strlen($row->typetitle); if ($titlecut) { $title = \Hubzero\Utility\String::truncate($row->title, $titlecut); } else { $title = $row->title; } // resources $out .= '<span class="spotlight-img">'; $out .= "\t" . '<a href="' . Route::url('index.php?option=com_resources&id=' . $row->id) . '">' . "\n"; $out .= "\t\t" . '<img width="30" height="30" src="' . rtrim(Request::base(true), '/') . $thumb . '" alt="' . htmlentities($row->title) . '" />' . "\n"; $out .= "\t" . '</a>' . "\n"; $out .= '</span>' . "\n"; $out .= '<span class="spotlight-item">' . "\n"; $out .= "\t" . '<a href="' . Route::url('index.php?option=com_resources&id=' . $row->id) . '">' . $title . '</a>' . "\n"; $out .= '</span>' . "\n"; if ($row->type == 7 && $remaining > 30) { // Show bit of description for tools if ($row->introtext) { $out .= ': ' . \Hubzero\Utility\String::truncate($this->_encodeHtml(strip_tags($row->introtext)), $txtLength); } else { $out .= ': ' . \Hubzero\Utility\String::truncate($this->_encodeHtml(strip_tags($row->fulltxt)), $txtLength); } } if ($tbl == 'itunes') { $out .= ' - ' . Lang::txt('featured on') . ' <a href="/itunes">' . Lang::txt('iTunes') . ' U</a>' . "\n"; } else { $out .= ' - ' . Lang::txt('in') . ' <a href="' . Route::url('index.php?option=com_resources&type=' . $normalized) . '">' . $row->typetitle . '</a>' . "\n"; } $out .= '<div class="clear"></div>' . "\n"; break; } return $out; }
/** * Show the current user activity * * @return void */ public function activityTask() { // Set the page title Document::setTitle(Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt(strtoupper($this->_task))); // Set the pathway if (Pathway::count() <= 0) { Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option); } Pathway::append(Lang::txt(strtoupper($this->_task)), 'index.php?option=' . $this->_option . '&task=' . $this->_task); // 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)); } // Check authorization if (!User::authorise('core.manage', $this->_option)) { App::redirect(Route::url('index.php?option=' . $this->_option)); } // Get logged-in users $prevuser = ''; $user = array(); $users = array(); $guests = array(); // get sessions $result = SessionHelper::getAllSessions(array('guest' => 0)); if ($result && count($result) > 0) { foreach ($result as $row) { $row->idle = time() - $row->time; if ($prevuser != $row->username) { if ($user) { $profile = Member::oneOrNew($prevuser); $users[$prevuser] = $user; $users[$prevuser]['uidNumber'] = $profile->get('id'); $users[$prevuser]['name'] = $profile->get('name'); $users[$prevuser]['org'] = $profile->get('organization'); $users[$prevuser]['orgtype'] = $profile->get('orgtype'); $users[$prevuser]['countryresident'] = $profile->get('countryresident'); } $prevuser = $row->username; $user = array(); } array_push($user, array('ip' => $row->ip, 'idle' => $row->idle)); } if ($user) { $profile = Member::oneOrNew($prevuser); $users[$prevuser] = $user; $users[$prevuser]['uidNumber'] = $profile->get('id'); $users[$prevuser]['name'] = $profile->get('name'); $users[$prevuser]['org'] = $profile->get('organization'); $users[$prevuser]['orgtype'] = $profile->get('orgtype'); $users[$prevuser]['countryresident'] = $profile->get('countryresident'); } } // get sessions $result = SessionHelper::getAllSessions(array('guest' => 1)); if (count($result) > 0) { foreach ($result as $row) { $row->idle = time() - $row->time; array_push($guests, array('ip' => $row->ip, 'idle' => $row->idle)); } } // Output View $this->view->set('title', Lang::txt('Active Users and Guests'))->set('users', $users)->set('guests', $guests)->setErrors($this->getErrors())->display(); }
/** * Map raw data to profile object * * @return void */ private function _mapEntryData() { // Do we have an ID? // Either passed in the raw data or gotten from the title match if (isset($this->raw->uidNumber) && $this->raw->uidNumber > 1) { $this->record->entry = Member::oneOrNew($this->raw->uidNumber); } else { if (isset($this->raw->id) && $this->raw->id > 1) { $this->record->entry = Member::oneOrNew($this->raw->id); } else { if (isset($this->raw->username) && $this->raw->username) { $this->record->entry = Member::oneByUsername($this->raw->username); } } } $d = Date::of('now'); if (isset($this->raw->registerDate)) { try { $d = Date::of($this->raw->registerDate); } catch (Exception $e) { array_push($this->record->errors, $e->getMessage()); } $this->raw->registerDate = $d->toSql(); } if (!$this->record->entry->get('id') && !isset($this->raw->registerDate)) { $this->raw->registerDate = $d->toSql(); } // Set modified date/user $this->raw->modifiedDate = Date::of('now')->toSql(); $columns = $this->record->entry->getStructure()->getTableColumns($this->record->entry->getTableName()); foreach (get_object_vars($this->raw) as $key => $val) { // These two need some extra loving and care, so we skip them for now... if (substr($key, 0, 1) == '_' || $key == 'username' || $key == 'uidNumber' || $key == 'groups') { continue; } if (function_exists('mb_convert_encoding')) { $val = mb_convert_encoding($val, 'UTF-8'); } // In PATCH mode, skip fields with no values if ($this->_mode == 'PATCH' && !$val) { continue; } if (isset($columns[$key])) { $this->record->entry->set($key, $val); } else { $this->_profile[$key] = $val; } } // Set multi-value fields // // This will split a string based on delimiter(s) and turn the // values into an array. foreach (array('disability', 'race', 'hispanic') as $key) { if (isset($this->raw->{$key})) { // In PATCH mode, skip fields with no values if ($this->_mode == 'PATCH' && (!isset($this->_profile[$key]) || !$this->_profile[$key])) { continue; } $this->_profile[$key] = $this->_multiValueField($this->_profile[$key]); } } // If we have a name but no individual parts... if (!$this->record->entry->get('givenName') && !$this->record->entry->get('surame') && $this->record->entry->get('name')) { $name = explode(' ', $this->record->entry->get('name')); $this->record->entry->set('givenName', array_shift($name)); $this->record->entry->set('surname', array_pop($name)); $this->record->entry->set('middleName', implode(' ', $name)); } // If we have the individual name parts but not the combined whole... if (($this->record->entry->get('givenName') || $this->record->entry->get('surame')) && !$this->record->entry->get('name')) { $name = array($this->record->entry->get('givenName'), $this->record->entry->get('middleName'), $this->record->entry->get('surname')); $this->record->entry->set('name', implode(' ', $name)); } // If we're updating an existing record... if ($this->record->entry->get('id')) { // Check if the username passed if the same for the record we're updating $username = $this->record->entry->get('username'); if ($username && isset($this->raw->username) && $username != $this->raw->username) { // Uh-oh. Notify the user. array_push($this->record->notices, Lang::txt('Usernames for existing members cannot be changed at this time.')); } } else { if (isset($this->raw->username) && $this->raw->username) { $this->record->entry->set('username', $this->raw->username); } } }
/** * Get the creator of this entry * * Accepts an optional property name. If provided * it will return that property value. Otherwise, * it returns the entire User object * * @param string $property Property to retrieve * @param mixed $default Default value if property not set * @return mixed */ public function creator($property = null, $default = null) { if (!$this->_creator instanceof Member) { $this->_creator = Member::oneOrNew($this->get('created_by')); } if ($property) { $property = $property == 'uidNumber' ? 'id' : $property; if ($property == 'picture') { return $this->_creator->picture($this->_creator->get('id') ? 0 : 1); } return $this->_creator->get($property, $default); } return $this->_creator; }