/** * Return memcached connection object * * @return object memcached connection object * * @since 12.1 * @throws RuntimeException */ protected function getConnection() { if ((extension_loaded('memcached') && class_exists('Memcached')) != true) { return false; } $config = Factory::getConfig(); $this->_persistent = $config->get('memcache_persist', true); $this->_compress = $config->get('memcache_compress', false) == false ? 0 : Memcached::OPT_COMPRESSION; /* * This will be an array of loveliness * @todo: multiple servers * $servers = (isset($params['servers'])) ? $params['servers'] : array(); */ $server = array(); $server['host'] = $config->get('memcache_server_host', 'localhost'); $server['port'] = $config->get('memcache_server_port', 11211); // Create the memcache connection if ($this->_persistent) { $session = Factory::getSession(); self::$_db = new \Memcached($session->getId()); } else { self::$_db = new \Memcached(); } $memcachedtest = self::$_db->addServer($server['host'], $server['port']); if ($memcachedtest == false) { throw new RuntimeException('Could not connect to memcached server', 404); } self::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress); // Memcached has no list keys, we do our own accounting, initialise key index if (self::$_db->get($this->_hash . '-index') === false) { $empty = array(); self::$_db->set($this->_hash . '-index', $empty, 0); } return; }
/** * After the session has been started we need to populate it with some default values. * * @return void * * @since 12.2 */ public function afterSessionStart() { $session = Factory::getSession(); if ($session->isNew()) { $session->set('registry', new Registry('session')); $session->set('user', new User()); } }
/** * Method to determine if client login credentials are present * * @param string $client Client name, currently only 'ftp' is supported * * @return boolean True if login credentials are available * * @since 11.1 */ public static function hasCredentials($client) { $return = false; $client = strtolower($client); // Get (unmodified) credentials for this client switch ($client) { case 'ftp': $config = Factory::getConfig(); $options = array('enabled' => $config->get('ftp_enable'), 'user' => $config->get('ftp_user'), 'pass' => $config->get('ftp_pass')); break; default: $options = array('enabled' => false, 'user' => '', 'pass' => ''); break; } if ($options['enabled'] == false) { // The client is disabled in global config, so let's pretend we are OK $return = true; } elseif ($options['user'] != '' && $options['pass'] != '') { // Login credentials are available in global config $return = true; } else { // Check if login credentials are available in the session $session = Factory::getSession(); $user = $session->get($client . '.user', null, 'JClientHelper'); $pass = $session->get($client . '.pass', null, 'JClientHelper'); if ($user != '' && $pass != '') { $return = true; } } return $return; }
/** * Checks for a form token in the request. * * Use in conjunction with JHtml::_('form.token') or JSession::getFormToken. * * @param string $method The request method in which to look for the token key. * * @return boolean True if found and valid, false otherwise. * * @since 12.1 */ public static function checkToken($method = 'post') { $token = self::getFormToken(); $app = Factory::getApplication(); if (!$app->input->{$method}->get($token, '', 'alnum')) { $session = Factory::getSession(); if ($session->isNew()) { // Redirect to login screen. $app->redirect(Route::_('index.php'), Text::_('JLIB_ENVIRONMENT_SESSION_EXPIRED')); $app->close(); } else { return false; } } else { return true; } }