コード例 #1
0
 public function executeTabs()
 {
     $this->navSetup();
     $this->options = array('depth' => isset($this->depth) ? $this->depth : 1);
     $this->navigation = new aNavigationTabs($this->rootPage, $this->activePage, $this->options);
     $this->depth = $this->options['depth'];
     $this->nav = $this->navigation->getNav();
     $this->extras = isset($this->extras) ? $this->extras : array();
     $i = 0;
     $urlValidator = new sfValidatorUrl();
     foreach ($this->extras as $slug => $title) {
         $external = false;
         try {
             $urlValidator->clean($slug);
             $external = true;
         } catch (sfValidatorError $e) {
         }
         $item = array('title' => $title, 'slug' => $slug, 'id' => $i, 'view_is_secure' => false, 'archived' => false, 'extra' => true, 'external' => $external);
         array_unshift($this->nav, $item);
     }
 }
コード例 #2
0
 /**
  * Auth form & redirect to OpenID provider
  */
 public function executeLogin(sfWebRequest $request)
 {
     if ($this->getUser()->isAuthenticated()) {
         $this->redirect(sfConfig::get('app_open_auth_redirect_signin'));
     }
     if ($request->isMethod('post') && $request->hasParameter('openid_identifier')) {
         $identity = $request->getPostParameter('openid_identifier');
         // TODO: use form instead
         $validator = new sfValidatorUrl(array('protocols' => array('http', 'https')));
         try {
             $identity = $validator->clean($request->getPostParameter('openid_identifier'));
         } catch (sfValidatorError $e) {
             $this->error = 'Некорректно указан идентификатор.';
             $this->getResponse()->setStatusCode(400);
             return sfView::SUCCESS;
         }
         $response = new sfOpenAuthZendResponse();
         $consumer = $this->_makeConsumer();
         $sreg = $this->_makeSreg();
         $urlVerify = $this->getController()->genUrl('open_auth_verify', true);
         $urlTrust = $this->getController()->genUrl('homepage', true);
         if (!$consumer->login($identity, $urlVerify, $urlTrust, $sreg, $response)) {
             // $consumer->getError();
             $this->error = 'Ошибка! Возможно указанный аккаунт не существует.';
             $this->getResponse()->setStatusCode(400);
             return sfView::SUCCESS;
         }
         // Get "Location" header from Zend
         foreach ($response->getHeaders() as $item) {
             $this->getResponse()->setHttpHeader($item['name'], $item['value'], $item['replace']);
         }
         // Show auth form
     } else {
         $this->getResponse()->setStatusCode(401);
     }
 }
コード例 #3
0
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../bootstrap/unit.php';
$t = new lime_test(15);
$v = new sfValidatorUrl();
// ->clean()
$t->diag('->clean()');
foreach (array('http://www.google.com', 'https://google.com/', 'https://google.com:80/', 'http://www.symfony-project.com/', 'http://127.0.0.1/', 'http://127.0.0.1:80/', 'ftp://google.com/foo.tgz', 'ftps://google.com/foo.tgz') as $url) {
    $t->is($v->clean($url), $url, '->clean() checks that the value is a valid URL');
}
foreach (array('google.com', 'http:/google.com', 'http://google.com::aa') as $nonUrl) {
    try {
        $v->clean($nonUrl);
        $t->fail('->clean() throws an sfValidatorError if the value is not a valid URL');
        $t->skip('', 1);
    } catch (sfValidatorError $e) {
        $t->pass('->clean() throws an sfValidatorError if the value is not a valid URL');
        $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
    }
}
$v = new sfValidatorUrl(array('protocols' => array('http', 'https')));
try {
    $v->clean('ftp://google.com/foo.tgz');
    $t->fail('->clean() only allows protocols specified in the protocols option');
} catch (sfValidatorError $e) {
    $t->pass('->clean() only allows protocols specified in the protocols option');
}
コード例 #4
0
ファイル: sfValidatorUrlTest.php プロジェクト: mediasadc/alba
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(14, new lime_output_color());
$v = new sfValidatorUrl();
// ->clean()
$t->diag('->clean()');
foreach (array('http://www.google.com', 'https://google.com/', 'https://google.com:80/', 'http://www.symfony-project.com/', 'http://127.0.0.1/', 'http://127.0.0.1:80/', 'ftp://google.com/foo.tgz', 'ftps://google.com/foo.tgz') as $url) {
    $t->is($v->clean($url), $url, '->clean() checks that the value is a valid URL');
}
foreach (array('google.com', 'http:/google.com', 'http://google.com::aa') as $nonUrl) {
    try {
        $v->clean($nonUrl);
        $t->fail('->clean() throws an sfValidatorError if the value is not a valid URL');
        $t->skip('', 1);
    } catch (sfValidatorError $e) {
        $t->pass('->clean() throws an sfValidatorError if the value is not a valid URL');
        $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
    }
}