normalizeUrl() public static method

The function gets URL argument by reference and modifies it. It returns true on success and false of failure.
public static normalizeUrl ( &$id ) : boolean
return boolean
示例#1
0
 /**
  * Retrieve consumer's root URL from request query.
  * Returns URL or false in case of failure
  *
  * @param array $params query arguments
  * @return mixed
  */
 public function getSiteRoot($params)
 {
     $version = 1.1;
     if (isset($params['openid_ns']) && $params['openid_ns'] == Zend_OpenId::NS_2_0) {
         $version = 2.0;
     }
     if ($version >= 2.0 && isset($params['openid_realm'])) {
         $root = $params['openid_realm'];
     } else {
         if ($version < 2.0 && isset($params['openid_trust_root'])) {
             $root = $params['openid_trust_root'];
         } else {
             if (isset($params['openid_return_to'])) {
                 $root = $params['openid_return_to'];
             } else {
                 return false;
             }
         }
     }
     if (Zend_OpenId::normalizeUrl($root) && !empty($root)) {
         return $root;
     }
     return false;
 }
示例#2
0
    /**
     * testing testNormalizeUrl
     *
     */
    public function testNormalizeUrl()
    {
        $url = 'example://a/b/c/%7Bfoo%7D';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://a/b/c/%7Bfoo%7D', $url );

        $url = 'eXAMPLE://A/./b/../b/%63/%7bfoo%7d';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://a/b/c/%7Bfoo%7D', $url );

        $url = 'eXAMPLE://A/./b/../b/%63/%bbfoo%Bd';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://a/b/c/%BBfoo%BD', $url );

        $url = 'example://a/b/c/%1';
        $this->assertFalse( Zend_OpenId::normalizeUrl($url) );

        $url = 'example://a/b/c/%x1';
        $this->assertFalse( Zend_OpenId::normalizeUrl($url) );

        $url = 'example://a/b/c/%1x';
        $this->assertFalse( Zend_OpenId::normalizeUrl($url) );

        $url = 'eXAMPLE://A/b/c/x%20y';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://a/b/c/x%20y', $url );

        $url = 'example://host/.a/b/c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/.a/b/c', $url );

        $url = 'a/b/c';
        $this->assertFalse( Zend_OpenId::normalizeUrl($url) );

        $url = 'example://:80/a/b/c';
        $this->assertFalse( Zend_OpenId::normalizeUrl($url) );

        $url = 'example://host/a/.b/c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/.b/c', $url );

        $url = 'example://host/a/b/.c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b/.c', $url );

        $url = 'example://host/..a/b/c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/..a/b/c', $url );

        $url = 'example://host/a/..b/c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/..b/c', $url );

        $url = 'example://host/a/b/..c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b/..c', $url );

        $url = 'example://host/./b/c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/b/c', $url );

        $url = 'example://host/a/./c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/c', $url );

        $url = 'example://host/a/b/.';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b', $url );

        $url = 'example://host/a/b/./';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b/', $url );

        $url = 'example://host/../b/c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/b/c', $url );

        $url = 'example://host/a/../c';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/c', $url );

        $url = 'example://host/a/b/..';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a', $url );

        $url = 'example://host/a/b/../';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/', $url );

        $url = 'example://host/a/b/c/..';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b', $url );

        $url = 'example://host/a/b/c/../..';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a', $url );

        $url = 'example://host/a/b/c/../../..';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/', $url );

        $url = 'example://host///a///b///c///..///../d';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/d', $url );

        $url = 'example://host///a///b///c///.///./d';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b/c/d', $url );

        $url = 'example://host///a///b///c///..///./d';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b/d', $url );

        $url = 'example://host///a///b///c///.///../d';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'example://host/a/b/d', $url );

        $url = 'http://example.com';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'http://example.com/', $url );

        $url = 'http://example.com/';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'http://example.com/', $url );

        $url = 'http://example.com:';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'http://example.com/', $url );

        $url = 'http://example.com:80/';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'http://example.com/', $url );

        $url = 'https://example.com:443/';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'https://example.com/', $url );

        $url = 'http://example.com?';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'http://example.com/?', $url );

        $url = 'http://example.com/?';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'http://example.com/?', $url );

        $url = 'http://example.com/test.php?Foo=Bar#Baz';
        $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
        $this->assertSame( 'http://example.com/test.php?Foo=Bar#Baz', $url );
    }
示例#3
0
 /**
  * Map a specific OpenID url to its equivalent, valid OpenID url.
  * Example: flickr.com doesn't actually provide OpenID support, so we redirect to me.yahoo.com.
  *
  * @param  string  $url
  * @return null|string
  */
 protected function mapOpenIDUrl($url)
 {
     $urlmap = array('http://flickr.com/' => 'http://me.yahoo.com/');
     $normalizedUrl = $url;
     if (Zend_OpenId::normalizeUrl($normalizedUrl)) {
         foreach ($urlmap as $key => $val) {
             Zend_OpenId::normalizeUrl($key);
             if ($normalizedUrl == $key) {
                 $normalizedUrl = $val;
                 Zend_OpenId::normalizeUrl($normalizedUrl);
                 break;
             }
         }
         return $normalizedUrl;
     }
     return null;
 }
示例#4
0
 /**
  * Remove a pairing of an openid and user id.
  *
  * @param  string $openid
  * @param  int    $id
  */
 public function detachOpenID($openid, $id)
 {
     if (Zend_OpenId::normalizeUrl($openid)) {
         $table = $this->getTable();
         $this->getTable()->delete(array($table->getAdapter()->quoteInto('openid_url = ?', $openid), $table->getAdapter()->quoteInto('user_id = ?', $id)));
     }
 }
示例#5
0
 public function generateOpenId($baseUrl)
 {
     $config = Zend_Registry::get('config');
     if ($config->subdomain->enabled) {
         $openid = Monkeys_Controller_Action::getProtocol() . '://' . $this->username . '.' . $config->subdomain->hostname;
     } else {
         $openid = $baseUrl . '/identity/' . $this->username;
     }
     if ($config->SSL->enable_mixed_mode) {
         $openid = str_replace('http://', 'https://', $openid);
     }
     Zend_OpenId::normalizeUrl($openid);
     $this->openid = $openid;
 }
 private function _getTrustRoot(Auth_OpenID_Request $request)
 {
     $trustRoot = $request->trust_root;
     Zend_OpenId::normalizeUrl($trustRoot);
     return $trustRoot;
 }