PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Markup/Renderer/Html/Img.php

https://gitlab.com/devtoannh/cafe
PHP | 84 lines | 28 code | 10 blank | 46 comment | 5 complexity | 44da7011f61d07b45248f1b1af57cb63 MD5 | raw file
  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-2011 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 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_Markup_Renderer_Html
  24. */
  25. require_once 'Zend/Markup/Renderer/Html.php';
  26. /**
  27. * @see Zend_Markup_Renderer_Html_HtmlAbstract
  28. */
  29. require_once 'Zend/Markup/Renderer/Html/HtmlAbstract.php';
  30. /**
  31. * Tag interface
  32. *
  33. * @category Zend
  34. * @package Zend_Markup
  35. * @subpackage Renderer_Html
  36. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Markup_Renderer_Html_Img extends Zend_Markup_Renderer_Html_HtmlAbstract
  40. {
  41. /**
  42. * Convert the token
  43. *
  44. * @param Zend_Markup_Token $token
  45. * @param string $text
  46. *
  47. * @return string
  48. */
  49. public function convert(Zend_Markup_Token $token, $text)
  50. {
  51. $uri = $text;
  52. if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri)) {
  53. $uri = 'http://' . $uri;
  54. }
  55. // check if the URL is valid
  56. if (!Zend_Markup_Renderer_Html::isValidUri($uri)) {
  57. return $text;
  58. }
  59. if ($token->hasAttribute('alt')) {
  60. $alt = $token->getAttribute('alt');
  61. } else {
  62. // try to get the alternative from the URL
  63. $alt = rtrim($text, '/');
  64. $alt = strrchr($alt, '/');
  65. if (false !== strpos($alt, '.')) {
  66. $alt = substr($alt, 1, strpos($alt, '.') - 1);
  67. }
  68. }
  69. // run the URI and alt through htmlentities
  70. $uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
  71. $alt = htmlentities($alt, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
  72. return "<img src=\"{$uri}\" alt=\"{$alt}\"" . Zend_Markup_Renderer_Html::renderAttributes($token) . " />";
  73. }
  74. }