Ejemplo n.º 1
0
 /**
  * Encrypt the email before parsing it within tags.
  *
  * @access public
  * @param array $tag
  * @param string $content
  * @return string
  */
 public function parse(array $tag, $content)
 {
     if (empty($tag['attributes']['default'])) {
         $email = $content;
         $default = false;
     } else {
         $email = $tag['attributes']['default'];
         $default = true;
     }
     // Return an invalid email
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return $content;
     }
     $encrypted = '';
     if ($this->config('encrypt')) {
         $length = strlen($email);
         if ($length > 0) {
             for ($i = 0; $i < $length; ++$i) {
                 $encrypted .= '&#' . ord(substr($email, $i, 1)) . ';';
             }
         }
     } else {
         $encrypted = $email;
     }
     $tag['attributes']['href'] = 'mailto:' . $encrypted;
     if ($this->getParser()->config('shorthand')) {
         $tag['content'] = $this->message('mail');
         return '[' . parent::parse($tag, $content) . ']';
     }
     if (!$default) {
         $tag['content'] = $encrypted;
     }
     return parent::parse($tag, $content);
 }
Ejemplo n.º 2
0
 /**
  * Use the content as the image source.
  *
  * @access public
  * @param array $tag
  * @param string $content
  * @return string
  */
 public function parse(array $tag, $content)
 {
     // If more than 1 http:// is found in the string, possible XSS attack
     if (substr_count($content, 'http://') + substr_count($content, 'https://') > 1) {
         return null;
     }
     $tag['attributes']['src'] = $content;
     if (empty($tag['attributes']['alt'])) {
         $tag['attributes']['alt'] = '';
     }
     return parent::parse($tag, $content);
 }
Ejemplo n.º 3
0
 /**
  * Custom build the HTML for videos.
  *
  * @access public
  * @param array $tag
  * @param string $content
  * @return string
  */
 public function parse(array $tag, $content)
 {
     $provider = $tag['attributes']['default'];
     $size = strtolower(isset($tag['attributes']['size']) ? $tag['attributes']['size'] : 'medium');
     if (empty($this->_formats[$provider])) {
         return sprintf('(Invalid %s video code)', $provider);
     }
     $video = $this->_formats[$provider];
     $size = isset($video[$size]) ? $video[$size] : $video['medium'];
     $tag['attributes']['width'] = $size[0];
     $tag['attributes']['height'] = $size[1];
     $tag['attributes']['player'] = $video['player'];
     $tag['attributes']['url'] = str_replace(array('{id}', '{width}', '{height}'), array($content, $size[0], $size[1]), $video['path']);
     return parent::parse($tag, $content);
 }
Ejemplo n.º 4
0
 /**
  * Using shorthand variation if enabled.
  *
  * @access public
  * @param array $tag
  * @param string $content
  * @return string
  */
 public function parse(array $tag, $content)
 {
     $url = isset($tag['attributes']['href']) ? $tag['attributes']['href'] : $content;
     $protocols = $this->config('protocols');
     // Return an invalid URL
     if (!filter_var($url, FILTER_VALIDATE_URL) || !preg_match('/^(' . implode('|', $protocols) . ')/i', $url)) {
         return $url;
     }
     $tag['attributes']['href'] = $url;
     if ($this->getParser()->config('shorthand')) {
         $tag['content'] = $this->message('link');
         return '[' . parent::parse($tag, $content) . ']';
     }
     return parent::parse($tag, $content);
 }
Ejemplo n.º 5
0
 /**
  * Strip a node but keep the URL regardless of location.
  *
  * @access public
  * @param array $tag
  * @param string $content
  * @return string
  */
 public function strip(array $tag, $content)
 {
     $url = isset($tag['attributes']['href']) ? $tag['attributes']['href'] : $content;
     return parent::strip($tag, $url);
 }
Ejemplo n.º 6
0
 /**
  * Strip a node but keep the email regardless of location.
  *
  * @access public
  * @param array $tag
  * @param string $content
  * @return string
  */
 public function strip(array $tag, $content)
 {
     $email = isset($tag['attributes']['default']) ? $tag['attributes']['default'] : $content;
     return parent::strip($tag, $email);
 }