/** * @return null */ public function testBuild() { $expected = '<base href="' . $this->href . '" target="' . $this->target . '">'; $this->assertEquals($expected, $this->base->build()); $base = new BaseTag($this->href); $expected = '<base href="' . $this->href . '">'; $this->assertEquals($expected, $base->build()); $base = new BaseTag(null, $this->target); $expected = '<base target="' . $this->target . '">'; $this->assertEquals($expected, $base->build()); }
/** * Obtains a SimpleID URL. URLs produced by SimpleID should use this function. * * @param string $path the FatFree path or alias * @param string $query a properly encoded query string * @param string $secure if $relative is false, either 'https' to force an HTTPS connection, 'http' to force * an unencrypted HTTP connection, 'detect' to base on the current connection, or NULL to vary based on SIMPLEID_BASE_URL * @return string the url * * @since 0.7 */ public function getCanonicalURL($path = '', $query = '', $secure = null) { $config = $this->f3->get('config'); $canonical_base_path = $config['canonical_base_path']; if (preg_match('/^(?:@(\\w+)(?:(\\(.+?)\\))*|https?:\\/\\/)/', $path, $parts)) { if (isset($parts[1])) { $aliases = $this->f3->get('ALIASES'); if (!empty($aliases[$parts[1]])) { $path = $aliases[$parts[1]]; $path = $this->f3->build($path, isset($parts[2]) ? $this->f3->parse($parts[2]) : array()); $path = ltrim($path, '/'); } } } // Make sure that the base has a trailing slash if (substr($config['canonical_base_path'], -1) == '/') { $url = $config['canonical_base_path']; } else { $url = $config['canonical_base_path'] . '/'; } if ($secure == 'https' && stripos($url, 'http:') === 0) { $url = 'https:' . substr($url, 5); } if ($secure == 'http' && stripos($url, 'https:') === 0) { $url = 'http:' . substr($url, 6); } if ($secure == 'detect' && $this->isHttps() && stripos($url, 'http:') === 0) { $url = 'https:' . substr($url, 5); } if ($secure == 'detect' && !$this->isHttps() && stripos($url, 'https:') === 0) { $url = 'http:' . substr($url, 6); } $url .= $path . ($query == '' ? '' : '?' . $query); return $url; }
/** * Assemble url from alias name * @param string $name * @param array $params * @param string $lang * @return string|FALSE */ function alias($name, $params = NULL, $lang = NULL) { if (in_array($name, $this->global_aliases)) { return $this->f3->alias($name, $params); } $params = $params ? $this->f3->parse($params) : array(); if (!$lang) { $lang = $this->current; } if (isset($this->rules[$lang][$name]) && $this->rules[$lang][$name] === FALSE) { return FALSE; } $url = isset($this->rules[$lang][$name]) ? $this->rules[$lang][$name] : @$this->_aliases[$name]; if (!$url) { user_error(sprintf(\Base::E_Named, $name), E_USER_ERROR); } return $this->f3->build(rtrim('/' . $lang . $url, '/'), $params); }
/** * redirect user to CCP SSO page and request authorization * -> cf. Controller->getCookieCharacters() ( equivalent cookie based login) * @param \Base $f3 */ public function requestAuthorization($f3) { if (!empty($ssoCcpClientId = Controller\Controller::getEnvironmentData('SSO_CCP_CLIENT_ID'))) { $params = $f3->get('GET'); if (isset($params['characterId']) && ($activeCharacter = $this->getCharacter(0))) { // authentication restricted to a characterId ----------------------------------------------- // restrict login to this characterId e.g. for character switch on map page $characterId = (int) trim($params['characterId']); /** * @var Model\CharacterModel $character */ $character = Model\BasicModel::getNew('CharacterModel'); $character->getById($characterId, 0); // check if character is valid and exists if (!$character->dry() && $character->hasUserCharacter() && $activeCharacter->getUser()->_id === $character->getUser()->_id) { // requested character belongs to current user // -> update character vom CREST (e.g. corp changed,..) $updateStatus = $character->updateFromCrest(); if (empty($updateStatus)) { // make sure character data is up2date! // -> this is not the case if e.g. userCharacters was removed "ownerHash" changed... $character->getById($character->_id); if ($character->hasUserCharacter() && $character->isAuthorized()) { $loginCheck = $this->loginByCharacter($character); if ($loginCheck) { // set "login" cookie $this->setLoginCookie($character); // route to "map" $f3->reroute('@map'); } } } } // redirect to map map page on successful login $f3->set(self::SESSION_KEY_SSO_FROM_MAP, true); } // redirect to CCP SSO ---------------------------------------------------------------------- // used for "state" check between request and callback $state = bin2hex(mcrypt_create_iv(12, MCRYPT_DEV_URANDOM)); $f3->set(self::SESSION_KEY_SSO_STATE, $state); $urlParams = ['response_type' => 'code', 'redirect_uri' => Controller\Controller::getEnvironmentData('URL') . $f3->build('/sso/callbackAuthorization'), 'client_id' => Controller\Controller::getEnvironmentData('SSO_CCP_CLIENT_ID'), 'scope' => implode(' ', $this->requestScopes), 'state' => $state]; $ssoAuthUrl = self::getAuthorizationEndpoint() . '?' . http_build_query($urlParams, '', '&', PHP_QUERY_RFC3986); $f3->status(302); $f3->reroute($ssoAuthUrl); } else { // SSO clientId missing $f3->set(self::SESSION_KEY_SSO_ERROR, self::ERROR_CCP_CLIENT_ID); self::getCrestLogger()->write(self::ERROR_CCP_CLIENT_ID); $f3->reroute('@login'); } }
/** * @return null */ public function testBuild() { $expected = '<meta name="' . $this->name . '" content="' . $this->content . '">'; $this->assertEquals($expected, $this->meta->build()); }