/** * 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; }
/** * 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 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; }
/** * Serve up an example CSV file * * @return void */ public function sampleTask() { $skip = array('gid', 'gidnumber', 'regIP', 'regHost', 'modifiedDate', 'proxypassword', 'loginshell', 'ftpshell', 'shadowexpire', 'params', 'proxyuidnumber'); $fields = array(); $row = array(); $member = Member::blank(); $attribs = $member->getStructure()->getTableColumns($member->getTableName()); foreach ($attribs as $key => $desc) { if (in_array(strtolower($key), $skip)) { continue; } $example = 'Example'; $desc = preg_replace('/\\(.*\\)/', '', $desc); if (in_array($desc, array('int', 'tinyint', 'float'))) { $example = '1'; } array_push($row, $example); array_push($fields, $key); } $attribs = Field::all()->including(['options', function ($option) { $option->select('*'); }])->ordered()->rows(); foreach ($attribs as $field) { $key = $field->get('name'); if (in_array(strtolower($key), $skip)) { continue; } $example = 'Example'; if ($field->options->count() || in_array($field->get('type'), array('select', 'dropdown', 'list', 'radio', 'radios', 'checkbox', 'checkboxes'))) { $example = 'example;example;example'; } array_push($row, $example); array_push($fields, $key); } // Output header @ob_end_clean(); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Expires: 0"); header("Content-Transfer-Encoding: binary"); header('Content-type: text/comma-separated-values'); header('Content-disposition: attachment; filename="members.csv"'); echo $this->quoteCsvRow($fields); //array_map('ucfirst', $fields)); echo $this->quoteCsvRow($row); exit; }
/** * 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; }
/** * 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; }
/** * Run Export * * @return void */ public function runTask() { $skip = array('password', 'params', 'usertype'); $keys = array(); $tags = array(); $members = Member::blank(); $attribs = $members->getStructure()->getTableColumns($members->getTableName()); foreach ($attribs as $key => $desc) { if (in_array(strtolower($key), $skip)) { continue; } $keys[$key] = $key; //array_push($keys, $key); } $attribs = Field::all()->ordered()->rows(); foreach ($attribs as $attrib) { if ($attrib->get('type') == 'tags') { array_push($tags, $attrib->get('name')); } if ($attrib->get('type') == 'address') { $keys[$attrib->get('name')] = $attrib->get('name') . ' Street 1'; $keys['_' . $attrib->get('name') . '_address2'] = $attrib->get('name') . ' Street 2'; $keys['_' . $attrib->get('name') . '_city'] = $attrib->get('name') . ' City'; $keys['_' . $attrib->get('name') . '_postal'] = $attrib->get('name') . ' Post Code'; $keys['_' . $attrib->get('name') . '_region'] = $attrib->get('name') . ' Region'; $keys['_' . $attrib->get('name') . '_country'] = $attrib->get('name') . ' Country'; $keys['_' . $attrib->get('name') . '_latitude'] = $attrib->get('name') . ' Latitude'; $keys['_' . $attrib->get('name') . '_longitude'] = $attrib->get('name') . ' Longitude'; continue; } $keys[$attrib->get('name')] = $attrib->get('name'); //array_push($keys, $attrib->get('name')); } // Get request vars $delimiter = Request::getVar('delimiter', ','); $csv = array(); $rows = $members->ordered()->rows(); // Convert to array and bind to object below // This may seem counter-intuitive but it's for // performance reasons. Otherwise, all the circular // references eat up memery. $rows = $rows->toArray(); // Gather up member information foreach ($rows as $row) { $member = Member::blank()->set($row); $tmp = array(); foreach ($keys as $key => $label) { if (substr($key, 0, 1) == '_') { if (!isset($tmp[$key])) { $tmp[$key] = ''; } continue; } if (in_array($key, $tags)) { $val = $member->tags('string'); } else { $val = $member->get($key); } if (is_array($val)) { $val = implode(';', $val); } else { if (strstr($val, '{')) { $v = json_decode((string) $val, true); if (!$v || json_last_error() !== JSON_ERROR_NONE) { // Nothing else to do } else { $i = 0; foreach ($v as $nm => $vl) { $k = '_' . $key . '_' . $nm; if ($i == 0) { $k = $key; } $tmp[$k] = $vl; $i++; } continue; } } } $tmp[$key] = $val; } unset($member); array_push($csv, $tmp); } //output csv directly as a download @ob_end_clean(); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Expires: 0"); header("Content-Transfer-Encoding: binary"); header('Content-type: text/comma-separated-values'); header('Content-disposition: attachment; filename="members.csv"'); $out = fopen('php://output', 'w'); fputcsv($out, $keys); foreach ($csv as $row) { fputcsv($out, $row, $delimiter); } exit; }
/** * Display notes for a user * * @return void */ public function modalTask() { Request::setVar('hidemainmenu', 1); $user = Member::oneOrFail(Request::getInt('id', 0)); $rows = Note::all()->including(['category', function ($category) { $category->select('id')->select('title'); }])->whereEquals('user_id', (int) $user->get('id'))->ordered()->rows(); // Output the HTML $this->view->set('user', $user)->set('rows', $rows)->setErrors($this->getErrors())->display(); }
/** * 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); }
/** * Debug user permissions * * @return void */ public function debuguserTask() { include_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'debug.php'; // Get filters $filters = array('search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'lft'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'level_start' => Request::getState($this->_option . '.' . $this->_controller . '.filter_level_start', 'filter_level_start', 0, 'int'), 'level_end' => Request::getState($this->_option . '.' . $this->_controller . '.filter_level_end', 'filter_level_end', 0, 'int'), 'component' => Request::getState($this->_option . '.' . $this->_controller . '.filter_component', 'filter_component', '')); if ($filters['level_end'] > 0 && $filters['level_end'] < $filters['level_start']) { $filters['level_end'] = $filters['level_start']; } $id = Request::getInt('id', 0); // Load member $member = Member::oneOrFail($id); // Select the required fields from the table. $entries = \Hubzero\Access\Asset::all(); if ($filters['search']) { $entries->whereLike('name', $filters['search'], 1)->orWhereLike('title', $filters['search'], 1)->resetDepth(); } if ($filters['level_start'] > 0) { $entries->where('level', '>=', $filters['level_start']); } if ($filters['level_end'] > 0) { $entries->where('level', '<=', $filters['level_end']); } // Filter the items over the component if set. if ($filters['component']) { $entries->whereEquals('name', $filters['component'], 1)->orWhereLike('name', $filters['component'], 1)->resetDepth(); } $assets = $entries->order($filters['sort'], $filters['sort_Dir'])->paginated()->rows(); $actions = \Components\Members\Helpers\Debug::getActions($filters['component']); $data = $assets->raw(); $assets->clear(); foreach ($data as $key => $asset) { $checks = array(); foreach ($actions as $action) { $name = $action[0]; $level = $action[1]; // Check that we check this action for the level of the asset. if ($action[1] === null || $action[1] >= $asset->get('level')) { // We need to test this action. $checks[$name] = \JAccess::check($id, $action[0], $asset->get('name')); } else { // We ignore this action. $checks[$name] = 'skip'; } } $asset->set('checks', $checks); $assets->push($asset); } $levels = \Components\Members\Helpers\Debug::getLevelsOptions(); $components = \Components\Members\Helpers\Debug::getComponents(); // Output the HTML $this->view->set('user', $member)->set('filters', $filters)->set('assets', $assets)->set('actions', $actions)->set('levels', $levels)->set('components', $components)->display(); }
/** * 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(); }
/** * Save an ORCID to a profile * * @param string $orcid * @return boolean */ private function _save($orcid) { // Instantiate a new profile object $profile = Member::oneOrFail(User::get('id')); if ($profile) { $profile->set('orcid', $orcid); return $profile->save(); } return false; }
/** * Download a file * * @return void */ public function downloadTask() { //get vars $id = Request::getInt('id', 0); //check to make sure we have an id if (!$id || $id == 0) { return; } //Load member profile $member = Member::oneOrFail($id); // check to make sure we have member profile if (!$member) { return; } //get the file name // make sure to leave out any query params (ex. ?v={timestamp}) $uri = Request::getVar('SCRIPT_URL', '', 'server'); if (strstr($uri, 'Image:')) { $file = str_replace('Image:', '', strstr($uri, 'Image:')); } elseif (strstr($uri, 'File:')) { $file = str_replace('File:', '', strstr($uri, 'File:')); } //decode file name $file = urldecode($file); // build base path $base_path = $this->filespace() . DS . \Hubzero\Utility\String::pad($member->get('id'), 5); //if we are on the blog if (Request::getVar('active', 'profile') == 'blog') { // @FIXME Check still needs to occur for non-public entries //authorize checks /*if ($this->_authorize() != 'admin') { if (User::get('id') != $member->get('id')) { App::abort(403, Lang::txt('You are not authorized to download the file: ') . ' ' . $file); } }*/ //get the params from the members blog plugin $blog_params = Plugin::params('members', 'blog'); //build the base path to file based of upload path param $base_path = str_replace('{{uid}}', \Hubzero\Utility\String::pad($member->get('id'), 5), $blog_params->get('uploadpath')); } //build file path $file_path = $base_path . DS . $file; // Ensure the file exist if (!file_exists(PATH_APP . DS . $file_path)) { App::abort(404, Lang::txt('The requested file could not be found: ') . ' ' . $file); return; } // Serve up the image $xserver = new \Hubzero\Content\Server(); $xserver->filename(PATH_APP . DS . $file_path); $xserver->disposition('attachment'); $xserver->acceptranges(false); // @TODO fix byte range support //serve up file if (!$xserver->serve()) { // Should only get here on error App::abort(404, Lang::txt('An error occured while trying to output the file')); } exit; }
/** * Check if a username exists * * @return integer */ private function _usernameExists($username) { return Member::oneByUsername($username)->get('id'); }
/** * 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; }
/** * Display host entries for a member * * @param object $profile * @return void */ public function displayTask($profile = null) { // Incoming if (!$profile) { $id = Request::getInt('id', 0); $profile = Member::oneOrFail($id); } // Output the HTML $this->view->set('id', $profile->get('id'))->set('rows', $profile->purgeCache()->hosts)->setErrors($this->getErrors())->setLayout('display')->display(); }
/** * 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'); }
/** * Check for registered users without quota entries and add them * * @return void */ public function importMissingTask() { // Query for all members in the CMS $results = Member::all()->select('id')->rows(); if ($results->count() > 0) { $updates = 0; $class = Category::defaultEntry(); if (!$class->get('id')) { // Output message and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=import', false), Lang::txt('COM_MEMBERS_QUOTA_MISSING_DEFAULT_CLASS'), 'error'); } foreach ($results as $r) { $quota = Quota::all()->whereEquals('user_id', $r->get('id'))->row(); if ($quota->get('id')) { continue; } $quota->set('user_id', $r->get('id')); $quota->set('class_id', $class->get('id')); $quota->set('soft_blocks', $class->get('soft_blocks')); $quota->set('hard_blocks', $class->get('hard_blocks')); $quota->set('soft_files', $class->get('soft_files')); $quota->set('hard_files', $class->get('hard_files')); $quota->save(); $updates++; } } // Output message and redirect Notify::success(Lang::txt('COM_MEMBERS_QUOTA_MISSING_USERS_IMPORT_SUCCESSFUL', $updates)); $this->cancelTask(); }
?> <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'); ?> " />
/** * 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; }
/** * 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(); }
/** * Edit an entry * * @param object $row * @return void */ public function editTask($row = null) { if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } Request::setVar('hidemainmenu', 1); if (!is_object($row)) { // Incoming ID $id = Request::getVar('id', array(0)); $id = is_array($id) ? $id[0] : $id; // Initiate database class and load info $row = Quote::oneOrNew($id); } if (!$row->get('id')) { if ($username = Request::getVar('username', '')) { $profile = Member::oneByUsername($username); $row->set('fullname', $profile->get('name')); $row->set('org', $profile->get('organization')); $row->set('user_id', $profile->get('uidNumber')); } } // Output the HTML $this->view->set('row', $row)->setLayout('edit')->display(); }