/** * Get the plugin data of a specific type if no specific plugin is specified * otherwise only the specific plugin data is returned. * * @param string $type The plugin type, relates to the sub-directory in the plugins directory. * @param string $plugin The plugin name. * * @return mixed An array of plugin data objects, or a plugin data object. * * @since 11.1 */ public static function getPlugin($type, $plugin = null) { // [!] Hubzero if (class_exists('\\Plugin')) { return \Plugin::byType($type, $plugin); } $result = array(); $plugins = self::_load(); // Find the correct plugin(s) to return. if (!$plugin) { foreach ($plugins as $p) { // Is this the right plugin? if ($p->type == $type) { $result[] = $p; } } } else { foreach ($plugins as $p) { // Is this plugin in the right group? if ($p->type == $type && $p->name == $plugin) { $result = $p; break; } } } return $result; }
/** * Display module contents * * @return void */ public function display() { if (!App::isAdmin()) { return; } $return = self::getReturnURI(); $freturn = base64_encode('index.php?' . Request::getQueryString()); $returnQueryString = !empty($return) ? "&return={$return}" : ''; $authenticators = []; $plugins = \Plugin::byType('authentication'); foreach ($plugins as $p) { $pparams = new Registry($p->params); // Make sure it supports admin login if (!$pparams->get('admin_login', false)) { continue; } // If it's the default hubzero plugin, don't include it in the list (we'll include it separately) if ($p->name == 'hubzero') { $site_display = $pparams->get('display_name', \Config::get('sitename')); $basic = true; } else { $display = $pparams->get('display_name', ucfirst($p->name)); $authenticators[$p->name] = array('name' => $p->name, 'display' => $display); } } require $this->getLayoutPath($this->params->get('layout', 'default')); }
function display($tpl = null) { $user = User::getRoot(); // If this is an auth_link account update, carry on, otherwise raise an error if (!is_object($user) || !array_key_exists('auth_link_id', $user) || !is_numeric($user->get('username')) || !$user->get('username') < 0) { App::abort('405', 'Method not allowed'); return; } // Get and add the js and extra css to the page \Hubzero\Document\Assets::addComponentStylesheet('com_users', 'link.css'); \Hubzero\Document\Assets::addComponentStylesheet('com_users', 'providers.css'); \Hubzero\Document\Assets::addComponentScript('com_users', 'link'); // Import a few things jimport('joomla.user.helper'); // Look up a few things $hzal = \Hubzero\Auth\Link::find_by_id($user->get("auth_link_id")); $hzad = \Hubzero\Auth\Domain::find_by_id($hzal->auth_domain_id); $plugins = Plugin::byType('authentication'); // Get the display name for the current plugin being used Plugin::import('authentication', $hzad->authenticator); $plugin = Plugin::byType('authentication', $hzad->authenticator); $pparams = new \Hubzero\Config\Registry($plugin->params); $refl = new ReflectionClass("plgAuthentication{$plugin->name}"); $display_name = $pparams->get('display_name', $refl->hasMethod('onGetLinkDescription') ? $refl->getMethod('onGetLinkDescription')->invoke(NULL) : ucfirst($plugin->name)); // Look for conflicts - first check in the hub accounts $profile_conflicts = \Hubzero\User\Profile\Helper::find_by_email($hzal->email); // Now check the auth_link table $link_conflicts = \Hubzero\Auth\Link::find_by_email($hzal->email, array($hzad->id)); $conflict = array(); if ($profile_conflicts) { foreach ($profile_conflicts as $p) { $user_id = JUserHelper::getUserId($p); $juser = User::getInstance($user_id); $auth_link = \Hubzero\Auth\Link::find_by_user_id($juser->id); $dname = is_object($auth_link) && $auth_link->auth_domain_name ? $auth_link->auth_domain_name : 'hubzero'; $conflict[] = array("auth_domain_name" => $dname, "name" => $juser->name, "email" => $juser->email); } } if ($link_conflicts) { foreach ($link_conflicts as $l) { $juser = User::getInstance($l['user_id']); $conflict[] = array("auth_domain_name" => $l['auth_domain_name'], "name" => $juser->name, "email" => $l['email']); } } // Make sure we don't somehow have any duplicate conflicts $conflict = array_map("unserialize", array_unique(array_map("serialize", $conflict))); // @TODO: Could also check for high probability of name matches??? // Get the site name $sitename = Config::get('sitename'); // Assign variables to the view $this->assign('hzal', $hzal); $this->assign('hzad', $hzad); $this->assign('plugins', $plugins); $this->assign('display_name', $display_name); $this->assign('conflict', $conflict); $this->assign('sitename', $sitename); $this->assignref('juser', $user); parent::display($tpl); }
/** * Method to get the field options for category * * @return array */ protected function getOptions() { $options = []; $options[] = Html::select('option', '', Lang::txt('Site default')); foreach (Plugin::byType('mail') as $plugin) { $options[] = Html::select('option', $plugin->name, ucfirst($plugin->name)); } return $options; }
function display($tpl = null) { // Assign variables to the view $authenticator = \Request::getWord('authenticator', false); \Hubzero\Document\Assets::addComponentStylesheet('com_user', 'login.css'); // Get the site name $sitename = \Config::get('sitename'); // Get the display name for the current plugin being used $plugin = Plugin::byType('authentication', $authenticator); $pparams = new \Hubzero\Config\Registry($plugin->params); $display_name = $pparams->get('display_name', ucfirst($plugin->name)); $this->assign('authenticator', $authenticator); $this->assign('sitename', $sitename); $this->assign('display_name', $display_name); parent::display($tpl); }
/** * Up **/ public function up() { // If a plugin is enabled, we'll assume that it should also be enabled for site login if not already saved // We changed the CMS to enforce the configuration option of site_login enabled. Prior to this, it was // assuming true. We need to default the database to emulate current behavior. $plugins = Plugin::byType('authentication'); if (count($plugins) > 0) { foreach ($plugins as $plugin) { $params = json_decode($plugin->params); if (is_null($params)) { $params = new \stdClass(); } if (!isset($params->site_login)) { $params->site_login = "******"; $this->saveParams('plg_authentication_' . $plugin->name, (array) $params); } } } }
break; default: break; } ?> <form action="<?php echo Route::url('index.php?option=' . $this->option . '&' . ($this->task == 'create' ? 'return=' . $form_redirect : 'task=' . $this->task)); ?> " method="post" id="hubForm"> <?php if ($this->task == 'create' && empty($this->xregistration->_invalid) && empty($this->xregistration->_missing)) { // Check to see if third party auth plugins are enabled Plugin::import('authentication'); $plugins = Plugin::byType('authentication'); $authenticators = array(); foreach ($plugins as $p) { if ($p->name != 'hubzero') { $pparams = new \Hubzero\Config\Registry($p->params); $display = $pparams->get('display_name', ucfirst($p->name)); $authenticators[] = array('name' => $p->name, 'display' => $display); } } // There are third party plugins, so show them on the registration form if (!empty($authenticators)) { $this->css('providers.css', 'com_users'); ?> <div class="explaination"> <p class="info">You can choose to log in via one of these services, and we'll help you fill in the info below!</p> <p>Already have an account? <a href="<?php
/** * This method should handle any login logic and report back to the subject * * @param array $user holds the user data * @param array $options array holding options (remember, autoregister, group) * @return boolean True on success */ public function onLoginUser($user, $options = array()) { jimport('joomla.user.helper'); $xuser = User::getRoot(); // get user from session (might be tmp_user, can't fetch from db) if ($xuser->get('guest')) { // joomla user plugin hasn't run or something went very badly $plugins = Plugin::byType('user'); $xuser_order = false; $joomla_order = false; $i = 0; foreach ($plugins as $plugin) { if ($plugin->name == 'xusers') { $xuser_order = $i; } if ($plugin->name == 'joomla') { $joomla_order = $i; } $i++; } if ($joomla_order === false) { return new Exception(Lang::txt('E_JOOMLA_USER_PLUGIN_MISCONFIGURED'), 500); } if ($xuser_order <= $joomla_order) { return new Exception(Lang::txt('E_HUBZERO_USER_PLUGIN_MISCONFIGURED'), 500); } return new Exception(Lang::txt('E_JOOMLA_USER_PLUGIN_FAILED'), 500); } // log login to auth log Log::auth($xuser->get('id') . ' [' . $xuser->get('username') . '] ' . $_SERVER['REMOTE_ADDR'] . ' login'); // correct apache log data apache_note('auth', 'login'); // Log attempt to the database Hubzero\User\User::oneOrFail($xuser->get('id'))->logger()->auth()->save(['username' => $xuser->get('username'), 'status' => 'success']); // update session tracking with new data $session = App::get('session'); $session->set('tracker.user_id', $xuser->get('id')); $session->set('tracker.username', $xuser->get('username')); if ($session->get('tracker.sid') == '') { $session->set('tracker.sid', $session->getId()); } $session->set('tracker.psid', $session->get('tracker.sid')); if ($session->get('tracker.rsid') == '') { $session->set('tracker.rsid', $session->getId()); } if ($session->get('tracker.user_id') != $xuser->get('id') || $session->get('tracker.ssid') == '') { $session->set('tracker.ssid', $session->getId()); } if (empty($user['type'])) { $session->clear('session.authenticator'); } else { $session->set('session.authenticator', $user['type']); } if (isset($options['silent']) && $options['silent']) { $session->set('session.source', 'cookie'); } else { $session->set('session.source', 'user'); } // update tracking data with changes related to login jimport('joomla.utilities.utility'); $hash = App::hash(App::get('client')->name . ':tracker'); $key = \App::hash(''); $crypt = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key)); $tracker = array(); $tracker['user_id'] = $session->get('tracker.user_id'); $tracker['username'] = $session->get('tracker.username'); $tracker['sid'] = $session->getId(); $tracker['rsid'] = $session->get('tracker.rsid', $tracker['sid']); $tracker['ssid'] = $session->get('tracker.ssid', $tracker['sid']); $cookie = $crypt->encrypt(serialize($tracker)); $lifetime = time() + 365 * 24 * 60 * 60; // Determine whether cookie should be 'secure' or not $secure = false; $forceSsl = \Config::get('force_ssl', false); if (\App::isAdmin() && $forceSsl >= 1) { $secure = true; } else { if (\App::isSite() && $forceSsl == 2) { $secure = true; } } setcookie($hash, $cookie, $lifetime, '/', '', $secure, true); /* Mark registration as incomplete so it gets checked on next page load */ $username = $xuser->get('username'); if (isset($user['auth_link']) && is_object($user['auth_link'])) { $hzal = $user['auth_link']; } else { $hzal = null; } if ($xuser->get('tmp_user')) { $email = $xuser->get('email'); if ($username[0] == '-') { $username = trim($username, '-'); if ($hzal) { $xuser->set('username', 'guest;' . $username); $xuser->set('email', $hzal->email); } } } else { if ($username[0] == '-') { $username = trim($username, '-'); if ($hzal) { $hzal->user_id = $xuser->get('id'); $hzal->update(); } } } if ($hzal) { $xuser->set('auth_link_id', $hzal->id); $session->set('linkaccount', true); } $session->set('registration.incomplete', true); // Check if quota exists for the user $params = Component::params('com_members'); if ($params->get('manage_quotas', false)) { require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'users_quotas.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'quotas_classes.php'; $quota = new \Components\Members\Tables\UsersQuotas($this->database); $quota->load(array('user_id' => $xuser->get('id'))); if (!$quota->id) { $class = new \Components\Members\Tables\QuotasClasses($this->database); $class->load(array('alias' => 'default')); if ($class->id) { $quota->set('user_id', $xuser->get('id')); $quota->set('class_id', $class->id); $quota->set('soft_blocks', $class->soft_blocks); $quota->set('hard_blocks', $class->hard_blocks); $quota->set('soft_files', $class->soft_files); $quota->set('hard_files', $class->hard_files); $quota->store(); } } else { if ($quota->class_id) { // Here, we're checking to make sure their class matches their actual quota values $class = new \Components\Members\Tables\QuotasClasses($this->database); $class->load($quota->class_id); if ($quota->get('soft_blocks') != $class->get('soft_blocks') || $quota->get('hard_blocks') != $class->get('hard_blocks') || $quota->get('soft_files') != $class->get('soft_files') || $quota->get('hard_files') != $class->get('hard_files')) { $quota->set('user_id', $xuser->get('id')); $quota->set('class_id', $class->id); $quota->set('soft_blocks', $class->soft_blocks); $quota->set('hard_blocks', $class->hard_blocks); $quota->set('soft_files', $class->soft_files); $quota->set('hard_files', $class->hard_files); $quota->store(); } } } } return true; }
/** * Hook for after parsing route * * @return void */ public function onAfterRoute() { if (App::isSite() && !User::isGuest()) { $exceptions = ['com_users.logout', 'com_users.userlogout', 'com_support.tickets.save.index', 'com_support.tickets.new.index', 'com_members.media.download.profiles', 'com_members.save.profiles', 'com_members.profiles.save', 'com_members.profiles.save.profiles', 'com_members.changepassword', 'com_content.article', '/legal/terms']; if ($allowed = trim($this->params->get('exceptions'))) { $allowed = str_replace("\r", '', $allowed); $allowed = str_replace('\\n', "\n", $allowed); $allowed = explode("\n", $allowed); $allowed = array_map('trim', $allowed); $allowed = array_map('strtolower', $allowed); $exceptions = array_merge($exceptions, $allowed); $exceptions = array_unique($exceptions); } $current = Request::getWord('option', ''); $current .= ($controller = Request::getWord('controller', false)) ? '.' . $controller : ''; $current .= ($task = Request::getWord('task', false)) ? '.' . $task : ''; $current .= ($view = Request::getWord('view', false)) ? '.' . $view : ''; // If exception not found, let's try by raw URL path if (!in_array($current, $exceptions)) { $current = Request::path(); } if (!in_array($current, $exceptions) && Session::get('registration.incomplete')) { // First check if we're heading to the registration pages, and allow that through if (Request::getWord('option') == 'com_members' && (Request::getWord('controller') == 'register' || Request::getWord('view') == 'register')) { // Set linkaccount far to false at this point, otherwise we'd get stuck in a loop Session::set('linkaccount', false); $this->event->stop(); return; } // Tmp users if (User::get('tmp_user')) { Request::setVar('option', 'com_members'); Request::setVar('controller', 'register'); Request::setVar('task', 'create'); Request::setVar('act', ''); $this->event->stop(); } else { if (substr(User::get('email'), -8) == '@invalid') { $usersConfig = Component::params('com_users'); $simpleRegistration = $usersConfig->get('simple_registration', false); if (Session::get('linkaccount', true) && !$simpleRegistration) { Request::setVar('option', 'com_users'); Request::setVar('view', 'link'); } else { Request::setVar('option', 'com_members'); Request::setVar('controller', 'register'); Request::setVar('task', 'update'); Request::setVar('act', ''); } $this->event->stop(); } else { // Does the user even have access to the profile plugin? // If not, then we can't redirect them there $plugin = Plugin::byType('members', 'profile'); if (!empty($plugin)) { Request::setVar('option', 'com_members'); Request::setVar('task', 'view'); Request::setVar('id', User::get('id')); Request::setVar('active', 'profile'); $this->event->stop(); } else { // Nothing else we can do, so let them go // and mark the incompleteness state so we don't // keep checking on every page load Session::get('registration.incomplete', false); } } } } } }
public function link() { $user = User::getInstance(); // First, they should already be logged in, so check for that if ($user->get('guest')) { App::abort(403, Lang::txt('You must be logged in to perform this function')); return; } // Do we have a return $return = ''; $options = array(); if ($return = Request::getVar('return', '', 'method', 'base64')) { $return = base64_decode($return); if (!JURI::isInternal($return)) { $return = ''; } else { $options['return'] = base64_encode($return); } } $authenticator = Request::getVar('authenticator', '', 'method'); // If a specific authenticator is specified try to call the link method for that plugin if (!empty($authenticator)) { Plugin::import('authentication'); $plugin = Plugin::byType('authentication', $authenticator); $className = 'plg' . $plugin->type . $plugin->name; if (class_exists($className)) { if (method_exists($className, 'link')) { $myplugin = new $className($this, (array) $plugin); $myplugin->link($options); } else { // No Link method is availble App::redirect(Route::url('index.php?option=com_members&id=' . $user->get('id') . '&active=account'), 'Linked accounts are not currently available for this provider.', 'error'); } } } else { // No authenticator provided... App::abort(400, Lang::txt('Missing authenticator')); return; } // Success! Redict with message App::redirect(Route::url('index.php?option=com_members&id=' . $user->get('id') . '&active=account'), 'Your account has been successfully linked!'); }
/** * Primary/default view function * * @return object Return */ private function _view() { // Setup our view $view = $this->view('default', 'overview'); // Get linked accounts, if any Plugin::import('authentication'); $view->domains_avail = Plugin::byType('authentication'); $view->hzalaccounts = \Hubzero\Auth\Link::find_by_user_id($this->user->get("id")); // Put the used domains into an array with details available from the providers (if applicable) $view->domains_used = array(); $view->domain_names = array(); if ($view->hzalaccounts) { Plugin::import('authentication'); $i = 0; foreach ($view->hzalaccounts as $authenticators) { $plugin = Plugin::byType('authentication', $authenticators['auth_domain_name']); // Make sure we got the plugin if (!is_object($plugin)) { unset($view->hzalaccounts[$i]); continue; } $className = 'plg' . $plugin->type . $plugin->name; $details = array(); if (class_exists($className)) { if (method_exists($className, 'getInfo')) { $details = $className::getInfo($plugin->params); } } $view->domains_used[] = array('name' => $authenticators['auth_domain_name'], 'details' => $details); $view->domain_names[] = $authenticators['auth_domain_name']; // Increment index $i++; } } // Get unused domains $view->domains_unused = array(); foreach ($view->domains_avail as $domain) { if ($domain->name != 'hubzero' && !in_array($domain->name, $view->domain_names)) { $view->domains_unused[] = $domain; } } // Determine what type of password change the user needs $hzup = \Hubzero\User\Password::getInstance($this->member->get('uidNumber')); if (!empty($hzup->passhash)) { // A password has already been set, now check if they're logged in with a linked account if (array_key_exists('auth_link_id', $this->user)) { // Logged in with linked account $view->passtype = 'changelocal'; } else { // Logged in with hub $view->passtype = 'changehub'; } } else { // No password has been set... $view->passtype = 'set'; } // Get password expiration information $view->passinfo = $this->getPassInfo(); // Get the ssh key if it exists $view->key = $this->readKey(); // Get the password rules $password_rules = \Hubzero\Password\Rule::getRules(); // Get the password rule descriptions $view->password_rules = array(); foreach ($password_rules as $rule) { if (!empty($rule['description'])) { $view->password_rules[] = $rule['description']; } } // A few more things... $view->option = $this->option; $view->member = $this->member; $view->params = $this->params; $view->notifications = $this->getPluginMessage() ? $this->getPluginMessage() : array(); // Set any errors foreach ($this->getErrors() as $error) { $view->setError($error); } return $view->loadTemplate(); }
/** * Processes file annotations * * @return void */ public function annotateit() { // Check permission if (!$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Get the file entity $file = trim($this->subdir, '/') . '/' . trim(Request::getVar('item', '')); $entity = Entity::fromPath($file, $this->connection->adapter()); // Grab annotations $keys = Request::getVar('key', []); $values = Request::getVar('value', []); $metadata = []; foreach ($keys as $idx => $key) { $key = trim($key); $value = trim($values[$idx]); if (!empty($key) && !empty($value)) { $metadata[$key] = $value; } } // Look for plugins that know how to handle them $plugins = Plugin::byType('metadata'); if (count($plugins) == 0) { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_ANNOTATION_PLUGINS'), 'error', 'projects'); } else { // Send the data off to the plugins $response = Event::trigger('metadata.onMetadataSave', [$entity, $metadata]); if (empty($response)) { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ANNOTATED_SUCCESS'), 'success', 'projects'); } else { \Notify::message(Lang::txt('PLG_PROJECTS_FILES_ERROR_ANNOTATE_FAILED'), 'error', 'projects'); } } // Redirect to file list $url = $this->model->link('files') . '&action=browse&connection=' . $this->connection->id; $url .= $this->subdir ? '&subdir=' . urlencode($this->subdir) : ''; // Redirect App::redirect(Route::url($url, false)); }
private static function getInstitutions() { static $inst = NULL; if ($inst === NULL) { $plugin = Plugin::byType('authentication', 'shibboleth'); $inst = json_decode(json_decode($plugin->params)->institutions, TRUE); $inst = $inst['activeIdps']; } return $inst; }
if ($ag->get('state') == 1) { echo ' selected="selected"'; } ?> ><?php echo Lang::txt('JYes'); ?> </option> </select> </p> <?php if ($plugins = Event::trigger('courses.onAssetgroupEdit')) { $data = $ag->get('params'); foreach ($plugins as $plugin) { $p = Plugin::byType('courses', $plugin['name']); $default = new \Hubzero\Config\Registry($p->params); $param = new JParameter(is_object($data) ? $data->toString() : $data, PATH_CORE . DS . 'plugins' . DS . 'courses' . DS . $plugin['name'] . DS . $plugin['name'] . '.xml'); foreach ($default->toArray() as $k => $v) { if (substr($k, 0, strlen('default_')) == 'default_') { $param->def(substr($k, strlen('default_')), $default->get($k, $v)); } } $out = $param->render('params', 'onAssetgroupEdit'); if (!$out) { continue; } ?> <fieldset class="eventparams" id="params-<?php echo $plugin['name']; ?>
/** * Calculate point royalties for members * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function onPointRoyalties(\Components\Cron\Models\Job $job) { $this->database = App::get('db'); $action = 'royalty'; // What month/year is it now? $curmonth = Date::format("F"); $curyear = Date::format("Y-m"); $ref = strtotime($curyear); $this->_message = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_DISTRIBUTED_ANSWERS', $curyear); $rmsg = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_DISTRIBUTED_REVIEWS', $curyear); $resmsg = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_DISTRIBUTED_RESOURCES', $curyear); // Make sure we distribute royalties only once/ month $royaltyAnswers = \Hubzero\Bank\MarketHistory::getRecord('', $action, 'answers', $curyear, $this->_message); $royaltyReviews = \Hubzero\Bank\MarketHistory::getRecord('', $action, 'reviews', $curyear, $rmsg); $royaltyResources = \Hubzero\Bank\MarketHistory::getRecord('', $action, 'resources', $curyear, $resmsg); // Include economy classes if (is_file(PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'helpers' . DS . 'economy.php')) { require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'helpers' . DS . 'economy.php'; } if (is_file(PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'economy.php')) { require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'economy.php'; } $AE = new \Components\Answers\Helpers\Economy($this->database); $accumulated = 0; // Get Royalties on Answers if (!$royaltyAnswers) { $rows = $AE->getQuestions(); if ($rows) { foreach ($rows as $r) { $AE->distribute_points($r->id, $r->q_owner, $r->a_owner, $action); $accumulated = $accumulated + $AE->calculate_marketvalue($r->id, $action); } // make a record of royalty payment if (intval($accumulated) > 0) { $MH = \Hubzero\Bank\MarketHistory::blank()->set(array('itemid' => $ref, 'date' => Date::toSql(), 'market_value' => $accumulated, 'category' => 'answers', 'action' => $action, 'log' => $this->_message)); if (!$MH->save()) { $err = $MH->getError(); } } } else { $this->_message = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_NO_QUESTIONS'); } } else { $this->_message = Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_ALREADY_DISTRIBUTED_ANSWERS', $curyear); } // Get Royalties on Resource Reviews if (!$royaltyReviews) { // get eligible $RE = new \Components\Resources\Helpers\Economy\Reviews($this->database); $reviews = $RE->getReviews(); // do we have ratings on reviews enabled? $param = Plugin::byType('resources', 'reviews'); $plparam = new \Hubzero\Config\Registry($param->params); $voting = $plparam->get('voting'); $accumulated = 0; if ($reviews && $voting) { foreach ($reviews as $r) { $RE->distribute_points($r, $action); $accumulated = $accumulated + $RE->calculate_marketvalue($r, $action); } $this->_message .= $rmsg; } else { $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_NO_REVIEWS'); } // make a record of royalty payment if (intval($accumulated) > 0) { $MH = \Hubzero\Bank\MarketHistory::blank()->set(array('itemid' => $ref, 'date' => Date::toSql(), 'market_value' => $accumulated, 'category' => 'reviews', 'action' => $action, 'log' => $rmsg)); if (!$MH->save()) { $err = $MH->getError(); } } } else { $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_ALREADY_DISTRIBUTED_REVIEWS', $curyear); } // Get Royalties on Resources if (!$royaltyResources) { // get eligible $ResE = new \Components\Resources\Helpers\Economy($this->database); $cons = $ResE->getCons(); $accumulated = 0; if ($cons) { foreach ($cons as $con) { $ResE->distribute_points($con, $action); $accumulated = $accumulated + $con->ranking; } $this->_message .= $resmsg; } else { $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_NO_RESOURCES'); } // make a record of royalty payment if (intval($accumulated) > 0) { $MH = \Hubzero\Bank\MarketHistory::blank()->set(array('itemid' => $ref, 'date' => Date::toSql(), 'market_value' => $accumulated, 'category' => 'resources', 'action' => $action, 'log' => $resmsg)); if (!$MH->save()) { $err = $MH->getError(); } } } else { $this->_message .= Lang::txt('PLG_CRON_MEMBERS_POINT_ROYALTIES_ALREADY_DISTRIBUTED_RESOURCES', $curyear); } return true; }
/** * Method to display the view. * * @param string The template file to include * @since 1.5 */ public function display($tpl = null) { // Get the view data. $this->user = User::getInstance(); $this->form = $this->get('Form'); $this->state = $this->get('State'); $this->params = $this->state->get('params'); // Make sure we're using a secure connection if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') { App::redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); die('insecure connection and redirection failed'); } // Check for errors. if (count($errors = $this->get('Errors'))) { App::abort(500, implode('<br />', $errors)); return false; } // Check for layout override $active = \App::get('menu')->getActive(); if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->prepareDocument(); $furl = base64_encode(Request::current(true)); $this->freturn = $furl; // HUBzero: If we have a return set with an authenticator in it, we're linking an existing account // Parse the return to retrive the authenticator, and remove it from the list below $auth = ''; if ($return = Request::getVar('return', null, 'GET', 'BASE64')) { $decoded_return = base64_decode($return); $query = parse_url($decoded_return); if (is_array($query) && isset($query['query'])) { $query = $query['query']; $query = explode('&', $query); $auth = ''; foreach ($query as $q) { $n = explode('=', $q); if ($n[0] == 'authenticator') { $auth = $n[1]; } } } } // Set return if is isn't already if (is_null($return) && is_object($active)) { $return = $active->params->get('login_redirect_url', Route::url('index.php?option=com_members&task=myaccount')); $return = base64_encode($return); } // Figure out whether or not any of our third party auth plugins are turned on // Don't include the 'hubzero' plugin, or the $auth plugin as described above $multiAuth = false; $plugins = Plugin::byType('authentication'); $authenticators = array(); $remember_me_default = 0; foreach ($plugins as $p) { $client = App::get('client')->alias . '_login'; $pparams = new \Hubzero\Config\Registry($p->params); // Make sure plugin is enabled for a given client if (!$pparams->get($client, false)) { continue; } if ($p->name != 'hubzero' && $p->name != $auth) { $display = $pparams->get('display_name', ucfirst($p->name)); $authenticators[$p->name] = array('name' => $p->name, 'display' => $display); $multiAuth = true; } else { if ($p->name == 'hubzero') { $remember_me_default = $pparams->get('remember_me_default', 0); $this->site_display = $pparams->get('display_name', Config::get('sitename')); $this->local = true; } } } // Override $multiAuth if authenticator is set to hubzero if (Request::getWord('authenticator') == 'hubzero') { $multiAuth = false; } // Set the return if we have it... $this->returnQueryString = !empty($return) ? "&return={$return}" : ''; $this->multiAuth = $multiAuth; $this->return = $return; $this->authenticators = $authenticators; $this->totalauths = count($plugins); $this->remember_me_default = $remember_me_default; // if authenticator is specified call plugin display method, otherwise (or if method does not exist) use default $authenticator = Request::getVar('authenticator', '', 'method'); Plugin::import('authentication'); foreach ($plugins as $plugin) { $className = 'plg' . $plugin->type . $plugin->name; if (class_exists($className)) { $myplugin = new $className($this, (array) $plugin); if (method_exists($className, 'status')) { $status[$plugin->name] = $myplugin->status(); $this->status = $status; } if ($plugin->name != $authenticator) { continue; } if (method_exists($className, 'display')) { $result = $myplugin->display($this, $tpl); return $result; } } } parent::display($tpl); }
/** * Return a list of categories * * @return array */ public function &onMembersContributionsAreas() { $areas = array(); // Load contributions plugin parameters $this->_cPlugin = Plugin::byType('members', 'contributions'); $this->_cParams = new JParameter($this->_cPlugin->params); if ($this->_cParams->get('include_publications', 0) == 1) { $areas = array('impact' => Lang::txt('PLG_MEMBERS_IMPACT_PUBLICATIONS')); } $this->_areas = $areas; return $areas; }
?> : <?php echo $display_name; ?> </div> </div> </div> <?php } } echo '<div class="clear"></div>'; if ($this->domains_unused) { echo '<h5>' . Lang::txt('PLG_MEMBERS_ACCOUNT_AVAILABLE_PROVIDERS') . ':</h5>'; foreach ($this->domains_unused as $domain) { // Get the display name for the current plugin being used $plugin = Plugin::byType('authentication', $domain->name); $pparams = new \Hubzero\Config\Registry($plugin->params); $display_name = $pparams->get('display_name', ucfirst($domain->name)); $refl = new \ReflectionClass('plgauthentication' . $domain->name); ?> <?php if ($refl->hasMethod('onRenderOption') && ($html = $refl->getMethod('onRenderOption')->invoke(NULL))) { ?> <?php echo is_array($html) ? implode("\n", $html) : $html; ?> <?php } else { ?> <a href="<?php
/** * Send a message to one or more users * * @param string $type Message type (maps to #__xmessage_component table) * @param string $subject Message subject * @param string $message Message to send * @param array $from Message 'from' data (e.g., name, address) * @param array $to List of user IDs * @param string $component Component name * @param integer $element ID of object that needs an action item * @param string $description Action item description * @param integer $group_id Parameter description (if any) ... * @return mixed True if no errors else error message */ public function onSendMessage($type, $subject, $message, $from = array(), $to = array(), $component = '', $element = null, $description = '', $group_id = 0, $bypassGroupsCheck = false) { // Do we have a message? if (!$message) { return false; } $database = App::get('db'); // Create the message object $xmessage = Hubzero\Message\Message::blank(); if ($type == 'member_message') { $time_limit = intval($this->params->get('time_limit', 30)); $daily_limit = intval($this->params->get('daily_limit', 100)); // First, let's see if they've surpassed their daily limit for sending messages $filters = array('created_by' => User::get('id'), 'daily_limit' => $daily_limit); $number_sent = $xmessage->getSentMessagesCount($filters); if ($number_sent >= $daily_limit) { return false; } // Next, we see if they've passed the time limit for sending consecutive messages $filters['limit'] = 1; $filters['start'] = 0; $sent = $xmessage->getSentMessages($filters); if ($sent->count() > 0) { $last_sent = $sent->first(); $last_time = 0; if ($last_sent->created) { $last_time = Date::of($last_sent->created)->toUnix(); } $time_difference = Date::toUnix() + $time_limit - $last_time; if ($time_difference < $time_limit) { return false; } } } // Store the message in the database $xmessage->set('message', is_array($message) && isset($message['plaintext']) ? $message['plaintext'] : $message); // Do we have a subject line? If not, create it from the message if (!$subject && $xmessage->get('message')) { $subject = substr($xmessage->get('message'), 0, 70); if (strlen($subject) >= 70) { $subject .= '...'; } } $xmessage->set('subject', $subject); $xmessage->set('created', Date::toSql()); $xmessage->set('created_by', User::get('id')); $xmessage->set('component', $component); $xmessage->set('type', $type); $xmessage->set('group_id', $group_id); if (!$xmessage->save()) { return $xmessage->getError(); } if (is_array($message)) { $xmessage->set('message', $message); } // Do we have any recipients? if (count($to) > 0) { $mconfig = Component::params('com_members'); // Get all the sender's groups if ($mconfig->get('user_messaging', 1) == 1 && !$bypassGroupsCheck) { $xgroups = User::groups('all'); $usersgroups = array(); if (!empty($xgroups)) { foreach ($xgroups as $group) { if ($group->regconfirmed) { $usersgroups[] = $group->cn; } } } } // Loop through each recipient foreach ($to as $uid) { // Create a recipient object that ties a user to a message $recipient = Hubzero\Message\Recipient::blank(); $recipient->set('uid', $uid); $recipient->set('mid', $xmessage->get('id')); $recipient->set('created', Date::toSql()); $recipient->set('expires', Date::of(time() + 168 * 24 * 60 * 60)->toSql()); $recipient->set('actionid', 0); //(is_object($action)) ? $action->id : 0; [zooley] Phasing out action items // Get the user's methods for being notified $notify = Hubzero\Message\Notify::blank(); $methods = $notify->getRecords($uid, $type); $user = User::getInstance($uid); if (!is_object($user) || !$user->get('username')) { continue; } if ($mconfig->get('user_messaging', 1) == 1 && ($type == 'member_message' || $type == 'group_message')) { $pgroups = \Hubzero\User\Helper::getGroups($user->get('id'), 'all', 1); $profilesgroups = array(); if (!empty($pgroups)) { foreach ($pgroups as $group) { if ($group->regconfirmed) { $profilesgroups[] = $group->cn; } } } // Find the common groups if (!$bypassGroupsCheck) { $common = array_intersect($usersgroups, $profilesgroups); if (count($common) <= 0) { continue; } } } // Do we have any methods? if ($methods->count()) { // Loop through each method foreach ($methods as $method) { $action = strtolower($method->method); if ($action == 'internal') { if (!$recipient->save()) { $this->setError($recipient->getError()); } } else { if (!Event::trigger('onMessage', array($from, $xmessage, $user, $action))) { $this->setError(Lang::txt('PLG_XMESSAGE_HANDLER_ERROR_UNABLE_TO_MESSAGE', $uid, $action)); } } } } else { // First check if they have ANY methods saved (meaning they've changed their default settings) // If They do have some methods, then they simply turned off everything for this $type $methods = $notify->getRecords($uid); if (!$methods || $methods->count() <= 0) { // Load the default method $p = Plugin::byType('members', 'messages'); $pp = new \Hubzero\Config\Registry(is_object($p) ? $p->params : ''); $d = $pp->get('default_method', 'email'); if (!$recipient->save()) { $this->setError($recipient->getError()); } // Use the Default in the case the user has no methods if (!Event::trigger('onMessage', array($from, $xmessage, $user, $d))) { $this->setError(Lang::txt('PLG_XMESSAGE_HANDLER_ERROR_UNABLE_TO_MESSAGE', $uid, $d)); } } } } } return true; }
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * HUBzero is a registered trademark of Purdue University. * * @package hubzero-cms * @author Sam Wilson <*****@*****.**> * @copyright Copyright 2005-2015 HUBzero Foundation, LLC. * @license http://opensource.org/licenses/MIT MIT */ // No direct access defined('_HZEXEC_') or die; $this->css()->css('uploader')->js(); $metadata = Plugin::byType('metadata'); $subdirlink = $this->subdir ? '&subdir=' . urlencode($this->subdir) : ''; $sortbyDir = $this->sortdir == 'ASC' ? 'DESC' : 'ASC'; ?> <div id="preview-window"></div> <form action="<?php echo Route::url($this->model->link('files')); ?> " method="post" enctype="multipart/form-data" id="plg-form" class="file-browser submit-ajax"> <div id="plg-header"> <h3 class="files"> <a href="<?php echo Route::url($this->model->link('files')); ?>