示例#1
0
文件: Img.php 项目: be-dmitry/zf1
 /**
  * Convert the token
  *
  * @param Zend_Markup_Token $token
  * @param string $text
  *
  * @return string
  */
 public function convert(Zend_Markup_Token $token, $text)
 {
     $uri = $text;
     if (!preg_match('/^([a-z][a-z+\\-.]*):/i', $uri)) {
         $uri = 'http://' . $uri;
     }
     // check if the URL is valid
     if (!Zend_Markup_Renderer_Html::isValidUri($uri)) {
         return $text;
     }
     if ($token->hasAttribute('alt')) {
         $alt = $token->getAttribute('alt');
     } else {
         // try to get the alternative from the URL
         $alt = rtrim($text, '/');
         $alt = strrchr($alt, '/');
         if (false !== strpos($alt, '.')) {
             $alt = substr($alt, 1, strpos($alt, '.') - 1);
         }
     }
     // run the URI and alt through htmlentities
     $uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
     $alt = htmlentities($alt, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
     return "<img src=\"{$uri}\" alt=\"{$alt}\"" . Zend_Markup_Renderer_Html::renderAttributes($token) . " />";
 }
示例#2
0
 /**
  * Convert the token
  *
  * @param Zend_Markup_Token $token
  * @param string $text
  *
  * @return string
  */
 public function convert(Zend_Markup_Token $token, $text)
 {
     if ($token->hasAttribute('url')) {
         $uri = $token->getAttribute('url');
     } else {
         $uri = $text;
     }
     if (!preg_match('/^([a-z][a-z+\\-.]*):/i', $uri)) {
         $uri = 'http://' . $uri;
     }
     // check if the URL is valid
     if (!Zend_Markup_Renderer_Html::isValidUri($uri)) {
         return $text;
     }
     $attributes = Zend_Markup_Renderer_Html::renderAttributes($token);
     // run the URI through htmlentities
     $uri = htmlentities($uri, ENT_QUOTES, Zend_Markup_Renderer_Html::getEncoding());
     return "<a href=\"{$uri}\"{$attributes}>{$text}</a>";
 }