Beispiel #1
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\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 #2
0
 public function filter($text)
 {
     $config = array('escapeHtml' => false);
     $decoda = new Decoda\Decoda($text, $config);
     $decoda->setStrict(false);
     // $decoda->defaults();
     $decoda->addFilter(new \Decoda\Filter\DefaultFilter());
     $decoda->addFilter(new \Decoda\Filter\EmailFilter());
     $decoda->addFilter(new \Decoda\Filter\ImageFilter());
     $decoda->addFilter(new \Decoda\Filter\UrlFilter());
     $decoda->addFilter(new \Decoda\Filter\TextFilter());
     $decoda->addFilter(new \Decoda\Filter\VideoFilter());
     $decoda->addFilter(new \Decoda\Filter\CodeFilter());
     $decoda->addFilter(new \Decoda\Filter\QuoteFilter());
     $decoda->addFilter(new \Decoda\Filter\ListFilter());
     $decoda->addFilter(new \Decoda\Filter\TableFilter());
     $decoda->addFilter(new ComForumsBlock());
     $decoda->addHook(new \Decoda\Hook\ClickableHook());
     $parsed = $decoda->parse();
     $html = str_replace('<br />', '', $parsed);
     $nesting = array();
     $closing = array();
     $scope = array();
     $errors = array();
     foreach ($decoda->getErrors() as $error) {
         switch ($error['type']) {
             case Decoda\Decoda::ERROR_NESTING:
                 $nesting[] = $error['tag'];
                 break;
             case Decoda\Decoda::ERROR_CLOSING:
                 $closing[] = $error['tag'];
                 break;
             case Decoda\Decoda::ERROR_SCOPE:
                 $scope[] = $error['child'] . ' in ' . $error['parent'];
                 break;
         }
     }
     if (!empty($nesting)) {
         $errors[] = sprintf('The following tags have been nested in the wrong order: %s', implode(', ', $nesting));
     }
     if (!empty($closing)) {
         $errors[] = sprintf('The following tags have no closing tag: %s', implode(', ', $closing));
     }
     if (!empty($scope)) {
         $errors[] = sprintf('The following tags can not be placed within a specific tag: %s', implode(', ', $scope));
     }
     foreach ($errors as $error) {
         $string = '<div class="alert alert-error">';
         $string .= $error;
         $string .= '</div>';
         echo $string;
     }
     return $html;
 }
Beispiel #3
0
<?php

$code = new \Decoda\Decoda();
$code->addFilter(new \Decoda\Filter\UrlFilter());
$code->addHook(new \Decoda\Hook\ClickableHook());
?>

<h2>URL</h2>

<?php 
$string = 'Valid websites:
[url]http://domain.com[/url]
[url]https://securesite.com[/url]
[url]ftp://ftpsite.com[/url]
[url]irc://ircsite.com[/url]
[url]telnet://telnetsite.com[/url]
[url="http://domain.com"]Linked URL[/url]

Valid websites (auto-linked with hook):
http://domain.com
http://sub.domain.com/?with=param
http://user:pass@domain.com:80/?with=param

Invalid websites:
[url]domain.com[/url]
[url]www.domain.com[/url]
[url]wtf://unsupportedprotocol.com/[/url]';
$code->reset($string);
echo $code->parse();
?>
Beispiel #4
0
<h2>Emoticons</h2>

<?php 
$string = 'Decoda also comes with an emoticon system. It will convert any kind of smiley from emoticons.json into a small image.
The system will not parse smilies within strings (like URLs) that resemble smilies. Here are a couple:

:] :) :D :/ >[ :p :o >_>

It also supports the word syntax:

:happy: :aw: :cool: :kiss: :meh: :mmf: :heart:';
$code = new \Decoda\Decoda($string);
$code->addFilter(new \Decoda\Filter\ImageFilter());
$code->addHook(new \Decoda\Hook\EmoticonHook(array('path' => '../emoticons/')));
echo $code->parse();
Beispiel #5
0
<?php

$code = new \Decoda\Decoda();
$code->addFilter(new \Decoda\Filter\CodeFilter());
$code->addHook(new \Decoda\Hook\EmoticonHook());
$code->addHook(new \Decoda\Hook\CensorHook());
?>

<h2>Code</h2>

<?php 
$string = "[code]// Constants\ndefine('DECODA', __DIR__ . '/');\n\n// Includes\nspl_autoload_register();\nset_include_path(implode(PATH_SEPARATOR, array(\n    get_include_path(),\n    DECODA\n)));[/code]";
$code->reset($string);
echo $code->parse();
?>

<h2>Code <span>with filters and hooks</span></h2>

<?php 
$string = "[code]email@domain.com\n\n:] :) :D :/ >[ :p :o >_>\n\n:happy: :aw: :cool: :kiss: :meh: :mmf: :heart:\n\nfuuCCkk shhiiiitt bITCH assHOLE peeniiss douchhe\n\nfucker shiting bitched[/code]";
$code->reset($string);
echo $code->parse();
?>

<h2>Code <span>with language attribute</span></h2>

<?php 
$string = '[code="php"]<?php
abstract class HookAbstract implements Hook {

    /**
Beispiel #6
0
<h2>Censoring</h2>

<?php 
$string = 's**t f**k bitch

Decoda uses a pretty awesome censoring system. It censors any word in the censored.txt blacklist file.
It tries its best not to censor words within other words, but it can happen. Here are a few examples:

f**k shit bitch asshole penis douche

And here are the same words, but with different lengths for each letter, and in different cases.

fuuCCkk shhiiiitt! bITCH assHOLE peeniiss douchhe

It will also magically censor words that end with: ing, ed, er

f****r shiting bitched?

Lets try not to censor words that are already part of other words.

analyst cockle nigeria grape

Hope it works out, I tried to make it as smart as possible.

f**k. c**t';
$code = new \Decoda\Decoda($string);
$code->addHook(new \Decoda\Hook\CensorHook());
echo $code->parse();