public function parseRaw($string, $filters = array()) { $decoda = new Decoda(); foreach ($filters as $filter) { $filterClass = ucfirst($filter) . 'Filter'; if (class_exists($filterClass)) { $filterObj = new $filterClass(); $decoda->addFilter($filterObj); } } $decoda->reset($string); $string = $decoda->parse(); return $string; }
/** * Parse bbcode into safe HTML * * @access protected * @param string $text * @return string */ protected function _parseBBcode($text) { JLoader::register('Decoda', JPATH_COMPONENT_ADMINISTRATOR . '/libraries/decoda/Decoda.php'); $code = new Decoda($text); $code->setEscapeHtml(!$this->params->get('html.allow', true)); $filters = $this->params->get('bbcode.filters', array('default' => 1, 'text' => 1, 'image' => 1, 'quote' => 1, 'url' => 1, 'video' => 1)); foreach ($filters as $filter => $enabled) { if ($enabled) { $class = ucfirst($filter) . 'Filter'; $code->addFilter(new $class()); } } $whitelist = $this->params->get('bbcode.whitelist', ''); $whitelist = array_map('trim', explode(',', $whitelist)); call_user_func_array(array($code, 'whitelist'), $whitelist); return $code->parse(); }
function SECURITY($debug, $userlevel, $censor) { if (count($_POST) != 0 || count($_GET) != 0) { if (count($_POST) != 0) { include "plugins/decoda/decoda.php"; foreach ($_POST as $key => $val) { if ($key == 'message') { $code = new Decoda($val); $code->useShorthand(false); $code->makeClickable(true); $code->setupGeshi("use_css = false"); $code->addCensored(array($censor)); $val = $code->parse(true); } $_POST[$key] = $val; if ($debug == 1 && $userlevel == 255) { echo "POST ARRAY - Field : {$key} Value: {$val}<br />"; } } return $_POST; } elseif (count($_GET) != 0) { foreach ($_GET as $key => $val) { $val = addslashes($val); $val = htmlentities($val, ENT_QUOTES); $_GET[$key] = $val; if ($debug == 1 && $userlevel == 255) { echo "GET ARRAY - Field : {$key} Value: {$val}<br />"; } } return $_GET; } else { die("ERROR with the http phaser"); } } if ($debug == 1 && $userlevel == 255) { if (is_array($_SESSION)) { foreach ($_SESSION as $key => $val) { $_SESSION[$key] = $val; echo "SESSION ARRAY - Field : {$key} Value: {$val}<br />"; } } } }
/** * Procesado rápido de BBCode * @param type $string * @return type */ public static function procesar($string) { // Procesamos BBCode. $decoda = new Decoda($string); return $decoda->parse(FALSE); }
$code = new Decoda($string); $code->parse(); ?> <h2>Lists</h2> <?php $string = '[list] [li]Lorem ipsum dolor sit amet, consectetuer adipiscing elit.[/li] [li]Aliquam laoreet pulvinar sem. Aenean at odio.[/li] [li]Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec elit.[/li] [li]Fusce eget enim. Nullam tellus felis, sodales nec, sodales ac, commodo eu, ante.[/li] [li]Curabitur tincidunt, lacus eget iaculis tincidunt.[/li] [li]Curabitur sed tellus. Donec id dolor.[/li] [/list]'; $code = new Decoda($string); $code->parse(); ?> <h2>Images</h2> <?php $string = '[img]http://www.google.com/intl/en_ALL/images/srpr/logo1w.png[/img] [img width=175 height=50]http://www.google.com/intl/en_ALL/images/srpr/logo1w.png[/img]'; $code = new Decoda($string); $code->parse(); ?> </body> </html>
/** * Validate the Decoda markup. * * @access public * @param string $model * @return boolean */ public function validateDecoda($model) { $censored = array_map('trim', explode(',', $this->settings['censored_words'])); $locale = $this->config['decodaLocales'][Configure::read('Config.language')]; $decoda = new Decoda($this->data[$model]['content']); $decoda->defaults()->setXhtml()->setLocale($locale); $decoda->getHook('Censor')->blacklist($censored); $parsed = $decoda->parse(); $errors = $decoda->getErrors(); if (empty($errors)) { $this->data[$model]['contentHtml'] = $parsed; return true; } $nesting = array(); $closing = array(); $scope = array(); foreach ($errors as $error) { switch ($error['type']) { case Decoda::ERROR_NESTING: $nesting[] = $error['tag']; break; case Decoda::ERROR_CLOSING: $closing[] = $error['tag']; break; case Decoda::ERROR_SCOPE: $scope[] = $error['child'] . ' -> ' . $error['parent']; break; } } if (!empty($nesting)) { return $this->invalidate('content', 'The following tags have been nested in the wrong order: %s', implode(', ', $nesting)); } if (!empty($closing)) { return $this->invalidate('content', 'The following tags have no closing tag: %s', implode(', ', $closing)); } if (!empty($scope)) { return $this->invalidate('content', 'The following tags can not be placed within a specific tag: %s', implode(', ', $scope)); } return true; }
*/ protected function parseDefaults($string) { if (empty($this->allowed)) { $code = $this->markupCode; $result = $this->markupResult; } else { $code = array(); $result = array(); foreach ($this->markupCode as $tag => $regex) { if (in_array($tag, $this->allowed)) { $code[$tag] = $this->markupCode[$tag]; $result[$tag] = $this->markupResult[$tag]; } } } $string = preg_replace($code, $result, $string); return $string; }[/code]'; // Translate $code = new Decoda($string); $code->useShorthand(false); $code->makeClickable(true); //$code->addCensored(array('sit')); $test = $code->parse(true); echo $test; ?> </body> </html>