public function parse(array $tag, $content)
 {
     $chart = array();
     $fromTable = isset($tag['attributes']['from']) ? trim($tag['attributes']['from']) : '';
     if ($fromTable) {
         list($tableName, $seriesKeys) = explode('|', $fromTable) + array(null, null);
         if (!isset($this->_parser->chartTables[$tableName])) {
             if (isset($tag['isPostponed']) && $tag['isPostponed']) {
                 return sprintf('<div class="decoda-error">Chart error: table \'%s\' not found.</div>', $tableName);
             }
             $tag['isPostponed'] = true;
             return sprintf('<!-- ###chart{%s}### -->', base64_encode(serialize(array('tag' => $tag, 'content' => $content))));
         }
         $table = $this->_parser->chartTables[$tableName];
         $categories = isset($table['categories']) ? $table['categories'] : array();
         $series = isset($table['series']) ? $table['series'] : array();
         if (!empty($seriesKeys)) {
             $series = array();
             foreach (explode(',', $seriesKeys) as $key) {
                 if (isset($table['series'][$key])) {
                     $series[] = $table['series'][$key];
                 }
             }
         }
         $chart = array('xAxis' => array('categories' => $categories), 'series' => $series);
     }
     $data = (array) json_decode($content, true);
     if (!$data && strlen(trim($content)) > 0) {
         return sprintf('<div class="decoda-error">Chart error: unable to parse chart options.</div>');
     }
     $tag['attributes']['data-chart'] = json_encode($this->merge($chart, $data));
     return parent::parse($tag, '');
 }
Пример #2
0
 /**
  * Using shorthand variation if enabled.
  *
  * @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->getConfig('protocols');
     $defaultProtocol = $this->getConfig('defaultProtocol');
     $hasProtocol = preg_match('/^(' . implode('|', $protocols) . ')/i', $url);
     if (!in_array($defaultProtocol, $protocols)) {
         $defaultProtocol = 'http';
     }
     // Allow relative and absolute paths, else check protocols
     if (!preg_match('/^(\\.\\.?)?\\//', $url)) {
         if (!$hasProtocol) {
             // Only allow if no protocol exists, just not the ones not in the list
             if (preg_match('/^(?![a-z]+:\\/\\/)/', $url) && filter_var($defaultProtocol . '://' . $url, FILTER_VALIDATE_URL)) {
                 $url = $defaultProtocol . '://' . $url;
             } else {
                 return $url;
             }
         }
         // Return an invalid URL
         if (!filter_var($url, FILTER_VALIDATE_URL)) {
             return $url;
         }
     }
     $tag['attributes']['href'] = $url;
     if ($this->getParser()->getConfig('shorthandLinks')) {
         $tag['content'] = $this->message('link');
         return '[' . parent::parse($tag, $content) . ']';
     }
     return parent::parse($tag, $content);
 }
Пример #3
0
 /**
  * Encrypt the email before parsing it within tags.
  *
  * @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->getConfig('encrypt')) {
         $length = mb_strlen($email);
         if ($length > 0) {
             for ($i = 0; $i < $length; ++$i) {
                 $encrypted .= '&#' . ord(mb_substr($email, $i, 1)) . ';';
             }
         }
     } else {
         $encrypted = $email;
     }
     $tag['attributes']['href'] = 'mailto:' . $encrypted;
     if ($this->getParser()->getConfig('shorthandLinks')) {
         $tag['content'] = $this->message('mail');
         return '[' . parent::parse($tag, $content) . ']';
     }
     if (!$default) {
         $tag['content'] = $encrypted;
     }
     return parent::parse($tag, $content);
 }
 /**
  * Custom build the HTML for audios.
  *
  * @param   array   $tag
  * @param   string  $content
  * @return  string
  */
 public function parse(array $tag, $content)
 {
     $size = mb_strtolower(isset($tag['attributes']['size']) ? $tag['attributes']['size'] : 'medium');
     foreach ($this->_formats as $format) {
         if (preg_match($format['pattern'], $content)) {
             $tag['attributes']['width'] = $format[$size][0];
             $tag['attributes']['height'] = $format[$size][1];
             $tag['attributes']['player'] = $format['player'];
             $tag['attributes']['url'] = preg_replace($format['pattern'], $format[$size][2], $content);
             return parent::parse($tag, $content);
         }
     }
     return '[url]' . $content . '[/url]';
 }
Пример #5
0
 /**
  * Custom build the HTML for videos.
  *
  * @param array $tag
  * @param string $content
  * @return string
  */
 public function parse(array $tag, $content)
 {
     $provider = isset($tag['attributes']['default']) ? $tag['attributes']['default'] : $tag['tag'];
     $size = mb_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);
 }
Пример #6
0
 /**
  * Use the content as the image source.
  *
  * @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 (mb_substr_count($content, 'http://') + mb_substr_count($content, 'https://') > 1) {
         return null;
     }
     $tag['attributes']['src'] = $content;
     if (!empty($tag['attributes']['default'])) {
         list($width, $height) = explode('x', $tag['attributes']['default']);
         $tag['attributes']['width'] = $width;
         $tag['attributes']['height'] = $height;
     }
     if (empty($tag['attributes']['alt'])) {
         $tag['attributes']['alt'] = '';
     }
     return parent::parse($tag, $content);
 }