Beispiel #1
0
 /**
  * Parse le content et retourne du HTML valide
  *
  */
 public function getContentHtml()
 {
     $code = new Decoda\Decoda($this->content);
     $code->defaults();
     $code->setXhtml(false);
     $code->setStrict(false);
     $code->setLineBreaks(true);
     return $code->parse();
 }
Beispiel #2
0
 /**
  * Affiche le contenue 
  *
  * @access public
  * @return HTML
  */
 public function getPreview()
 {
     $code = new Decoda\Decoda(Input::get('content'));
     $code->defaults();
     $code->setXhtml(false);
     $code->setStrict(false);
     $code->setLineBreaks(true);
     return $code->parse();
 }
Beispiel #3
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 #4
0
 /**
  * Formate la sortie de la description
  *
  */
 public function getDescriptionHtml()
 {
     $code = new Decoda\Decoda($this->description);
     $code->defaults();
     return $code->parse();
 }
Beispiel #5
0
[b][i][u]Bold, italics, underline[/u][/i][/b]';
$code = new \Decoda\Decoda($string);
$code->resetHooks()->resetFilters();
echo $code->parse();
?>

<h2>Disable tag parsing</h2>

<?php 
$string = '[b]Bold[/b]
[i]Italics[/i]
[u]Underline[/u]
[s]Strike through[/s]
[b][i][u]Bold, italics, underline[/u][/i][/b]';
$code = new \Decoda\Decoda($string);
$code->defaults()->disable();
echo $code->parse();
?>

<h2>Customizable brackets</h2>

<?php 
$string = '{b}Bold{/b}
{i}Italics{/i}
{u}Underline{/u}
{s}Strike through{/s}
{b}{i}{u}Bold, italics, underline{/u}{/i}{/b}';
$code = new \Decoda\Decoda($string);
$code->addFilter(new \Decoda\Filter\DefaultFilter())->setBrackets('{', '}');
echo $code->parse();
?>
Beispiel #6
0
 public function bbcode($text)
 {
     $decoda = new Decoda\Decoda($text);
     $decoda->defaults();
     $decoda->setStrict(false);
     // $decoda->removeFilter('Video');
     $decoda->removeHook('Censor');
     //$decoda->removeFilter('Url');
     $html = $decoda->parse();
     // $errors = $decoda->getErrors();
     // foreach($errors as $error) {
     //     $string = "";
     //     foreach($error as $key => $value) {
     //         $string = $key . ":" . $value . ", ";
     //     }
     //     error_log($string);
     // }
     // print_r($errors);
     $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;
     // return $decoda->parse();
     // return $text;
 }
Beispiel #7
0
 /**
  * Edit le post de l'utilisateur
  *
  * @param $slug Slug du topic
  * @param $id Id du topic
  * @param $postId Id du post
  */
 public function postEdit($slug, $id, $postId)
 {
     $user = Auth::user();
     $topic = Topic::find($id);
     $forum = $topic->forum;
     $category = $forum->getCategory();
     $post = Post::find($postId);
     $parsedContent = null;
     if ($user->group->is_modo == false) {
         if ($post->user_id != $user->id) {
             return Redirect::route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with('message', 'You can\'t edit this post');
         }
     }
     // Prévisualisation du post
     if (Request::getMethod() == 'POST' && Input::get('preview') == true) {
         $post->content = Input::get('content');
         $code = new Decoda\Decoda($post->content);
         $code->defaults();
         $parsedContent = $code->parse();
     }
     if (Request::isMethod('post') && Input::get('post') == true) {
         $post->content = Input::get('content');
         $post->save();
         return Redirect::route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id]);
     }
     return View::make('forum.post_edit', ['user' => $user, 'topic' => $topic, 'forum' => $forum, 'post' => $post, 'category' => $category, 'parsedContent' => $parsedContent]);
 }
Beispiel #8
0
        .decoda-quote-date { float: right; }
        .decoda-code { background: lightgray; padding: 10px; border-radius: 3px; }
        .decoda-alert { background: lightpink; padding: 10px; border-radius: 3px; }
        .decoda-note { background: powderblue; padding: 10px; border-radius: 3px; }
        .decoda-spoiler-content { background: palegreen; margin-top: 5px; padding: 10px; border-radius: 3px; }
        .decoda-spoiler-content .decoda-spoiler { margin-top: 10px; }
        .decoda-spoiler-content .decoda-spoiler-content { background: oldlace; }
    </style>
</head>
<body>
    <h1>Decoda</h1>

    <?php 
// Copyright
$code = new \Decoda\Decoda('Copyright 2009-' . date('Y') . ' [sup]&copy;[/sup] Miles Johnson - [url]http://milesj.me[/url]');
$code->defaults();
echo $code->parse();
?>

    <dl>
        <dt>About</dt>
        <dd><?php 
buildMenu($about, $view);
?>
</dd>

        <dt>Filters</dt>
        <dd><?php 
buildMenu($filters, $view);
?>
</dd>