示例#1
0
文件: Url.php 项目: henvic/MediaLab
 public function isValid($value)
 {
     $valueString = (string) $value;
     $this->_setValue($valueString);
     Zend_Uri::setConfig(array('allow_unwise' => true));
     $check = Zend_Uri::check($value);
     Zend_Uri::setConfig(array('allow_unwise' => false));
     if (!$check) {
         $this->_error(self::INVALID_URL);
         return false;
     }
     return true;
 }
示例#2
0
 protected function _load()
 {
     if (!isset($this->_options[0])) {
         throw new Exceptions_SeotoasterWidgetException('Rss feed url should be specified');
     }
     $scheme = 'http';
     $feeds = array();
     //little hack for options, needs to be somthing better
     if (preg_match('~^https?$~', $this->_options[0])) {
         $scheme = array_shift($this->_options);
         $this->_options[0] = ltrim($this->_options[0], '/');
     }
     $feedUrl = $scheme . '://' . str_replace(' ', '+', html_entity_decode($this->_options[0]));
     $maxResult = isset($this->_options[1]) ? $this->_options[1] : self::RSS_RESULT_COUNT;
     Zend_Uri::setConfig(array('allow_unwise' => true));
     if (!Zend_Uri::check($feedUrl)) {
         throw new Exceptions_SeotoasterWidgetException('Rss feed url is not valid.');
     }
     Zend_Feed_Reader::setCache(Zend_Registry::get('cache'));
     Zend_Feed_Reader::useHttpConditionalGet();
     try {
         $rss = Zend_Feed_Reader::import($feedUrl);
     } catch (Exception $e) {
         return $e->getMessage();
     }
     $i = 0;
     foreach ($rss as $item) {
         if ($i == $maxResult) {
             break;
         }
         $feeds[] = array('title' => $item->getTitle(), 'link' => $item->getLink(), 'description' => Tools_Text_Tools::cutText(strip_tags($item->getDescription()), isset($this->_options[2]) ? $this->_options[2] : self::RSS_DESC_LENGTH), 'pubDate' => $item->getDateCreated(), 'content' => $item->getContent(), 'authors' => $item->getAuthors(), 'image' => $this->_getRssEntryImage($item->getContent()));
         $i++;
     }
     $this->_view->useImage = isset($this->_options[3]) && $this->_options[3] == 'img' ? true : false;
     $this->_view->feed = $feeds;
     return $this->_view->render('rss.phtml');
 }
示例#3
0
 /**
  * Test that after setting 'allow_unwise' to true unwise characters are
  * accepted
  *
  */
 public function testAllowUnwiseQueryString()
 {
     $unwise = array('http://example.com/?q={', 'http://example.com/?q=}', 'http://example.com/?q=|', 'http://example.com/?q=\\', 'http://example.com/?q=^', 'http://example.com/?q=`');
     Zend_Uri::setConfig(array('allow_unwise' => true));
     foreach ($unwise as $uri) {
         $this->assertTrue(Zend_Uri::check($uri), "failed for URI {$uri}");
     }
     Zend_Uri::setConfig(array('allow_unwise' => false));
 }
示例#4
0
 /**
  * Check valid URL
  *
  * @param string $aURL 
  * @param bool $allow_unwise //Allow to use in a URL "not smart symbols" -> "{", "}", "|", "\", "^", "`" 
  * @return bool
  */
 static function checkValid_URL($aURL, $allow_unwise = false)
 {
     //----------------
     Zend_Uri::setConfig(array('allow_unwise' => $allow_unwise));
     return Zend_Uri::check($aURL);
 }
示例#5
0
文件: UriTest.php 项目: travisj/zf
 /**
  * Tests that Zend_Uri::setConfig() throws Zend_Uri_Exception if no array
  * nor Zend_Config is given as first parameter
  *
  * @group ZF-5578
  * @expectedException Zend_Uri_Exception
  */
 public function testSetConfigInvalid()
 {
     Zend_Uri::setConfig('This should cause an exception');
 }
示例#6
0
 /**
  * 
  * Checks if there is a link to redirect after sign in ...
  * It has to be a internal link, so it won't accept
  * if it makes the user goes to somewhere else instead
  */
 public function checkLinkToRedirect()
 {
     $config = self::$_registry->get("config");
     $redirectAfterLogin = filter_input(INPUT_GET, "redirect_after_login", FILTER_UNSAFE_RAW);
     if ($redirectAfterLogin && $redirectAfterLogin != null) {
         $testLink = $redirectAfterLogin;
     } else {
         if (isset($_SERVER['HTTP_REFERER'])) {
             $router = Zend_Controller_Front::getInstance()->getRouter();
             if ($router->getCurrentRouteName() == "login") {
                 $referer = $_SERVER['HTTP_REFERER'];
                 $partialLink = explode("?redirect_after_login="******"?", $_SERVER['REQUEST_URI'], 2);
     $thisPage = $thisPage[0];
     if (mb_substr($testLink, 0, 1) == '/' && !mb_strpos($testLink, "@") && $thisPage != $testLink) {
         // @todo HTTPS support
         $redirTo = "http://" . $config['webhost'] . $testLink;
         Zend_Uri::setConfig(array('allow_unwise' => true));
         if (Zend_Uri::check($redirTo)) {
             $testUri = Zend_Uri::factory($redirTo);
             $path = $testUri->getPath();
             Zend_Uri::setConfig(array('allow_unwise' => false));
             return $path;
         }
     }
     return false;
 }