public static function addId($tag)
 {
     $post = CommentPost::find($tag->getAttribute('id'));
     if ($post) {
         $tag->setAttribute('discussionid', (int) $post->discussion_id);
         $tag->setAttribute('number', (int) $post->number);
         return true;
     }
 }
Exemple #2
0
 protected function formatPost($post)
 {
     // Code blocks
     $regexp = "/(.*)^\\s*\\[code\\]\n?(.*?)\n?\\[\\/code]\$/ims";
     while (preg_match($regexp, $post->content)) {
         $post->content = preg_replace($regexp, "\$1```\n\$2\n```", $post->content);
     }
     // Inline tags
     $replace = ['/\\[url=(.*?)\\](.*?)\\[\\/url\\]/i' => '[$2]($1)', '/\\[b\\](.*?)\\[\\/b\\]/i' => '**$1**', '/\\[i\\](.*?)\\[\\/i\\]/i' => '*$1*', '/\\[h\\](.*?)\\[\\/h\\]/i' => '# $1', '/\\[img\\](.*?)\\[\\/img\\]/i' => '![]($1)', '/\\[code\\](.*?)\\[\\/code\\]/i' => '`$1`'];
     $post->content = preg_replace(array_keys($replace), array_values($replace), $post->content);
     // Quotes
     $regexp = "/(.*?)\n?\\[quote(?:=(.*?)(]?))?\\]\n?(.*?)\n?\\[\\/quote\\]\n{0,2}/is";
     while (preg_match($regexp, $post->content)) {
         $post->content = preg_replace_callback($regexp, function ($matches) use($post) {
             if (strpos($matches[2], ':') !== false) {
                 list($postId, $user) = explode(':', $matches[2]);
                 $mentionedPost = CommentPost::find($postId);
                 return $matches[1] . "\n@" . $mentionedPost->user->username . '#' . $mentionedPost->number . ' ';
             } else {
                 return $matches[1] . '> ' . str_replace("\n", "\n> ", $matches[4]) . "\n\n";
             }
         }, $post->content);
     }
 }