/** * 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; } $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); }
/** * Use the content as the image source. * * @access public * @param array $tag * @param string $content * @return string */ public function parse(array $tag, $content) { $tag['attributes']['src'] = $content; if (empty($tag['attributes']['alt'])) { $tag['attributes']['alt'] = ''; } return parent::parse($tag, $content); }
/** * Using shorthand variation if enabled. * * @access public * @param array $tag * @param string $content * @return string */ public function parse(array $tag, $content) { if (empty($tag['attributes']['default'])) { $tag['attributes']['default'] = $content; } if ($this->getParser()->config('shorthand')) { $tag['content'] = $this->message('link'); return '[' . parent::parse($tag, $content) . ']'; } return parent::parse($tag, $content); }
/** * 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://') > 1) { return; } $tag['attributes']['src'] = $content; if (empty($tag['attributes']['alt'])) { $tag['attributes']['alt'] = ''; } return parent::parse($tag, $content); }
/** * 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 $provider . ':' . $content; } $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); }
/** * Custom build the HTML for videos. * * @access public * @param array $tag * @param string $content * @return string */ public function parse(array $tag, $content) { $provider = isset($tag['attributes']['default']) ? $tag['attributes']['default'] : 'youtube'; $size = strtolower(isset($tag['attributes']['size']) ? $tag['attributes']['size'] : 'small'); if (empty($this->_formats[$provider]) || $this->_formats[$provider]['pattern'] && !preg_match($this->_formats[$provider]['pattern'], $content)) { return htmlentities($provider . ':' . $content, ENT_QUOTES, 'UTF-8'); } $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); }
/** * Add additional filters. * * @access public * @param DecodaFilter $filter * @return Decoda * @chainable */ public function addFilter(DecodaFilter $filter) { $filter->setParser($this); $class = str_replace('Filter', '', get_class($filter)); $tags = $filter->tags(); $this->_filters[$class] = $filter; $this->_tags = $tags + $this->_tags; foreach ($tags as $tag => $options) { $this->_filterMap[$tag] = $class; } $filter->setupHooks($this); return $this; }