protected function doClean($value)
 {
     // Getting URL
     $url = parent::doClean($value);
     // Getting key
     $urlExp = explode('/', $url);
     $id = $urlExp[count($urlExp) - 1];
     // Building URL
     $jHeberg = "http://www.jheberg.net/api/check-link";
     $jHeberg .= "?id=" . $id;
     if ($this->getOption('key') != null) {
         $jHeberg .= "&key=" . $this->getOption('key');
     }
     // Calling URL (getting JSON string)
     $json = file_get_contents($jHeberg);
     // If calling fails again
     if ($json === false) {
         throw new sfValidatorError($this, 'calling');
     }
     // Decoding JSON in array
     $json = json_decode($json, true);
     // Declaring size
     define('SIZE', $json['fileSize']);
     // AntiLeech mode
     if ($this->getOption('antileech')) {
         $q = Doctrine_Query::create()->select('COUNT(*)')->from('Ips')->where('ip = ?', $json['ownerIp'])->andWhere('uid = ?', sfContext::getInstance()->getUser()->getAttribute("id"))->execute(array(), Doctrine::HYDRATE_SINGLE_SCALAR);
         // If owner IP doesn't match
         if ($q == 0) {
             throw new sfValidatorError($this, 'antileech');
         }
     }
     return $url;
 }
示例#2
0
 protected function doClean($value)
 {
     if (preg_match('/^[\\w\\+-]+\\./', $value)) {
         $value = 'http://' . $value;
     }
     return parent::doClean($value);
 }
 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);
     }
 }
示例#4
0
 /**
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorRegex
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->setOption('pattern', '~^
   ((https?|ftps?)://)?                       # http or ftp (+SSL)
   (
     ([a-z0-9-]+\\.)+[a-z]{2,6}             # a domain name
       |                                   #  or
     \\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}    # a IP address
   )
   (:[0-9]+)?                              # a port (optional)
   (/?|/\\S+)                               # a /, nothing or a / with something
 $~ix');
 }
 /**
  * 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);
     }
 }
示例#6
0
 /**
  * @see sfValidatorUrl
  */
 protected function doClean($value)
 {
     try {
         return parent::doClean($value);
     } catch (sfValidatorError $e) {
         if (strncmp($value, 'page:', 5) === 0 && dmDb::table('DmPage')->findOneBySource($value)) {
             return $value;
         } elseif (strncmp($value, 'media:', 6) === 0 && dmDb::table('DmMedia')->findOneByIdWithFolder(substr($value, 6))) {
             return $value;
         } elseif ('#' === $value[0]) {
             return $value;
         } elseif ('@' === $value[0]) {
             return $value;
         }
         throw $e;
     }
 }
示例#7
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');
}
 /**
  * @param array $options   An array of options
  * @param array $messages  An array of error messages
  *
  * @see sfValidatorRegex
  */
 protected function configure($options = array(), $messages = array())
 {
     parent::configure($options, $messages);
     $this->setOption('pattern', self::PATTERN);
 }
示例#9
0
<?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');
    }
}