File indexing completed on 2025-02-09 07:20:14
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Markup 0017 * @subpackage Renderer_Html 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Markup_Renderer_Html 0025 */ 0026 // require_once 'Zend/Markup/Renderer/Html.php'; 0027 /** 0028 * @see Zend_Markup_Renderer_Html_HtmlAbstract 0029 */ 0030 // require_once 'Zend/Markup/Renderer/Html/HtmlAbstract.php'; 0031 0032 /** 0033 * Tag interface 0034 * 0035 * @category Zend 0036 * @package Zend_Markup 0037 * @subpackage Renderer_Html 0038 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0039 * @license http://framework.zend.com/license/new-bsd New BSD License 0040 */ 0041 class Zend_Markup_Renderer_Html_Url extends Zend_Markup_Renderer_Html_HtmlAbstract 0042 { 0043 0044 /** 0045 * Convert the token 0046 * 0047 * @param Zend_Markup_Token $token 0048 * @param string $text 0049 * 0050 * @return string 0051 */ 0052 public function convert(Zend_Markup_Token $token, $text) 0053 { 0054 if ($token->hasAttribute('url')) { 0055 $uri = $token->getAttribute('url'); 0056 } else { 0057 $uri = $text; 0058 } 0059 0060 if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri)) { 0061 $uri = 'http://' . $uri; 0062 } 0063 0064 // check if the URL is valid 0065 if (!Zend_Markup_Renderer_Html::isValidUri($uri)) { 0066 return $text; 0067 } 0068 0069 $attributes = Zend_Markup_Renderer_Html::renderAttributes($token); 0070 0071 // run the URI through htmlentities 0072 $uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding()); 0073 0074 return "<a href=\"{$uri}\"{$attributes}>{$text}</a>"; 0075 } 0076 0077 }