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_Img 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         $uri = $text;
0055 
0056         if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri)) {
0057             $uri = 'http://' . $uri;
0058         }
0059 
0060         // check if the URL is valid
0061         if (!Zend_Markup_Renderer_Html::isValidUri($uri)) {
0062             return $text;
0063         }
0064 
0065         if ($token->hasAttribute('alt')) {
0066             $alt = $token->getAttribute('alt');
0067         } else {
0068             // try to get the alternative from the URL
0069             $alt = rtrim($text, '/');
0070             $alt = strrchr($alt, '/');
0071             if (false !== strpos($alt, '.')) {
0072                 $alt = substr($alt, 1, strpos($alt, '.') - 1);
0073             }
0074         }
0075 
0076         // run the URI and alt through htmlentities
0077         $uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
0078         $alt = htmlentities($alt, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
0079 
0080 
0081         return "<img src=\"{$uri}\" alt=\"{$alt}\"" . Zend_Markup_Renderer_Html::renderAttributes($token) . " />";
0082     }
0083 
0084 }