|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Markup |
|
17 * @subpackage Renderer_Html |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Img.php 20663 2010-01-26 18:45:18Z kokx $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Markup_Renderer_Html |
|
25 */ |
|
26 require_once 'Zend/Markup/Renderer/Html.php'; |
|
27 /** |
|
28 * @see Zend_Markup_Renderer_Html_HtmlAbstract |
|
29 */ |
|
30 require_once 'Zend/Markup/Renderer/Html/HtmlAbstract.php'; |
|
31 |
|
32 /** |
|
33 * Tag interface |
|
34 * |
|
35 * @category Zend |
|
36 * @package Zend_Markup |
|
37 * @subpackage Renderer_Html |
|
38 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
39 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
40 */ |
|
41 class Zend_Markup_Renderer_Html_Img extends Zend_Markup_Renderer_Html_HtmlAbstract |
|
42 { |
|
43 |
|
44 /** |
|
45 * Convert the token |
|
46 * |
|
47 * @param Zend_Markup_Token $token |
|
48 * @param string $text |
|
49 * |
|
50 * @return string |
|
51 */ |
|
52 public function convert(Zend_Markup_Token $token, $text) |
|
53 { |
|
54 $uri = $text; |
|
55 |
|
56 if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri)) { |
|
57 $uri = 'http://' . $uri; |
|
58 } |
|
59 |
|
60 // check if the URL is valid |
|
61 if (!Zend_Markup_Renderer_Html::isValidUri($uri)) { |
|
62 return $text; |
|
63 } |
|
64 |
|
65 if ($token->hasAttribute('alt')) { |
|
66 $alt = $token->getAttribute('alt'); |
|
67 } else { |
|
68 // try to get the alternative from the URL |
|
69 $alt = rtrim($text, '/'); |
|
70 $alt = strrchr($alt, '/'); |
|
71 if (false !== strpos($alt, '.')) { |
|
72 $alt = substr($alt, 1, strpos($alt, '.') - 1); |
|
73 } |
|
74 } |
|
75 |
|
76 // run the URI and alt through htmlentities |
|
77 $uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding()); |
|
78 $alt = htmlentities($alt, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding()); |
|
79 |
|
80 |
|
81 return "<img src=\"{$uri}\" alt=\"{$alt}\"" . Zend_Markup_Renderer_Html::renderAttributes($token) . " />"; |
|
82 } |
|
83 |
|
84 } |