/** * Process bbcode inside a string * @since Version 3.10.0 * @param string|DOMDocument $string The HTML or text block to process * @return DOMDocument */ public static function Process($string, $doBbcode = true) { if (!$doBbcode) { return $string; } $timer = Debug::getTimer(); /** * Pre-process the string before we send it through the BBCode parser */ $string = self::preProcessBBCodeUIDs($string); $parser = new Decoda($string); $parser->addPath(__DIR__ . DIRECTORY_SEPARATOR . 'BbcodeEtc' . DIRECTORY_SEPARATOR); $emoticonConfig = ['path' => '//static.railpage.com.au/images/smiles/', 'extension' => 'gif']; $engine = new DecodaPhpEngine(); $engine->addPath(__DIR__ . DIRECTORY_SEPARATOR . 'BbcodeEtc' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR); $parser->setEngine($engine); $parser->defaults(); $parser->setStrict(false); $parser->setLineBreaks(false); $parser->removeHook('Emoticon'); $parser->addFilter(new RailpageImageFilter()); $string = $parser->parse(); $string = html_entity_decode($string); // Fix: if I set escapeHtml in the Decoda options, it fails to auto linkify links //$string = wpautop($string); Debug::LogEvent(__METHOD__, $timer); return $string; }
/** * Instantiate the class and apply settings. * * @param View $view * @param array $settings */ public function __construct(View $view, $settings = array()) { parent::__construct($view, $settings); $settings = $settings + Configure::read('Decoda.config'); $locale = Configure::read('Config.language') ?: $settings['locale']; $localeMap = Configure::read('Decoda.locales'); unset($settings['locale']); $decoda = new Decoda('', $settings); $decoda->whitelist($settings['whitelist'])->blacklist($settings['blacklist']); if ($paths = $settings['paths']) { foreach ((array) $paths as $path) { $decoda->addPath($path); } } if ($messages = $settings['messages']) { $decoda->addMessages(new \Decoda\Loader\DataLoader($messages)); } // Set locale if (isset($localeMap[$locale])) { $decoda->setLocale($localeMap[$locale]); } else { if (in_array($locale, $localeMap)) { $decoda->setLocale($locale); } } // Apply hooks and filters if (empty($settings['filters']) && empty($settings['hooks'])) { $decoda->defaults(); } else { if ($filters = $settings['filters']) { foreach ((array) $filters as $filter) { $filter = sprintf('\\Decoda\\Filter\\%sFilter', $filter); $decoda->addFilter(new $filter()); } } if ($hooks = $settings['hooks']) { foreach ((array) $hooks as $hook) { $hook = sprintf('\\Decoda\\Hook\\%sHook', $hook); $decoda->addHook(new $hook()); } } } // Custom config $decoda->addHook(new \Decoda\Hook\EmoticonHook(array('path' => '/utility/img/emoticon/'))); $decoda->setEngine(new CakeEngine($settings['helpers'])); $this->_decoda = $decoda; }