Ejemplo n.º 1
0
 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, '');
 }
 /**
  * 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]';
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 /**
  * Strip a node but keep the URL regardless of location.
  *
  * @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.
  *
  * @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);
 }