Exemple #1
0
 /**
  * Set up Decoda.
  */
 protected function setUp()
 {
     parent::setUp();
     $decoda = new Decoda();
     $decoda->addFilter(new EmailFilter(array('encrypt' => false)));
     $decoda->addFilter(new UrlFilter());
     $this->object = new ClickableHook();
     $this->object->setParser($decoda);
 }
Exemple #2
0
 public function textToBBcode($text)
 {
     $whitelist = explode(",", Settings::get('whitelist_tags'));
     $code = new Decoda\Decoda($text, array('xhtmlOutput' => true, 'strictMode' => false, 'escapeHtml' => false));
     $code->addFilter(new \Decoda\Filter\ImageFilter());
     $code->addHook(new \Decoda\Hook\EmoticonHook(array('path' => URL::to('plugins/shahiemseymor/bbcode/emoticons') . '/')));
     $code->whitelist($whitelist)->addFilter(new \Decoda\Filter\DefaultFilter());
     if (trim(Settings::get('language')) != '') {
         $code->setLocale(Settings::get('language'));
     }
     if (Settings::get('shorthand') == TRUE) {
         $code->addFilter(new \Decoda\Filter\EmailFilter())->addFilter(new \Decoda\Filter\UrlFilter())->setShorthand($text);
     }
     $code->defaults();
     return $code->parse();
 }
 /**
  * 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;
 }
Exemple #4
0
 public function Parse($string)
 {
     $code = new Decoda($string);
     $code->defaults();
     $code->addFilter(new \Decoda\Filter\CodeFilter());
     $code->addHook(new \Decoda\Hook\EmoticonHook());
     $code->addHook(new \Decoda\Hook\CensorHook());
     return $code->parse();
 }
 /**
  * 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;
 }
Exemple #6
0
 /**
  * Add additional filters.
  *
  * @see \Decoda\Decoda::addFilter()
  *
  * @param Filter $filter
  * @param string $id
  *
  * @return Decoda
  */
 public function addFilter(Filter $filter, $id = null)
 {
     if (null === $id) {
         // this is to keep method signature
         $id = explode('\\', get_class($filter));
         $id = str_replace('Filter', '', end($id));
     }
     return parent::addFilter($filter, strtolower($id));
 }