public function __invoke($request)
 {
     $url = $this->view->basePath();
     $bbcode = new Decoda($request);
     $bbcode->defaults();
     $bbcode->addHook(new EmoticonHook(array('path' => $url . '/images/emoticons/')));
     return $bbcode->parse();
 }
Beispiel #2
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);
 }
 /**
  * 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;
 }
Beispiel #4
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();
 }
Beispiel #5
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();
 }
Beispiel #6
0
 /**
  * Validate the Decoda markup.
  *
  * @param string $model
  * @param string $field
  * @return bool
  */
 public function validateDecoda($model, $field = 'content')
 {
     if (!isset($this->data[$model][$field])) {
         return true;
     }
     $decoda = new Decoda($this->data[$model][$field]);
     $decoda->defaults()->parse();
     $errors = $decoda->getErrors();
     if (!$errors) {
         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 ($nesting) {
         return $this->invalid('content', 'The following tags have been nested in the wrong order: %s', implode(', ', $nesting));
     }
     if ($closing) {
         return $this->invalid('content', 'The following tags have no closing tag: %s', implode(', ', $closing));
     }
     if ($scope) {
         return $this->invalid('content', 'The following tags can not be placed within a specific tag: %s', implode(', ', $scope));
     }
     return true;
 }
Beispiel #7
0
 /**
  * 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;
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  */
 protected function _extractChunks($string)
 {
     if (isset($this->_filters['list'])) {
         $this->_filters['List'] = true;
     }
     $nodes = parent::_extractChunks($string);
     unset($this->_filters['List']);
     return $nodes;
 }
 /**
  * @expectedException \Decoda\Exception\MissingLocaleException
  */
 public function testCustomConfigPath()
 {
     $decoda = new Decoda('', array('configPath' => '/some/fake/path'));
     $this->assertEquals('Spoiler', $decoda->message('spoiler'));
 }
Beispiel #10
0
 /**
  * Add any hook dependencies.
  *
  * @param \Decoda\Decoda $decoda
  * @return \Decoda\Filter\CodeFilter
  */
 public function setupHooks(Decoda $decoda)
 {
     $decoda->addHook(new CodeHook());
     return $this;
 }