This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/libraries/BBcodeDefinitions/Quote.php

76 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
* Holds the forum post quoting bbcode class.
*
* @package Sakura
*/
namespace Sakura\BBcodeDefinitions;
use JBBCode\CodeDefinition;
use JBBCode\ElementNode;
2016-03-31 20:03:25 +00:00
use Sakura\ActiveUser;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Perms\Forum as ForumPerms;
use Sakura\Router;
/**
* Quote BBcode for JBBCode.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class Quote extends CodeDefinition
{
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->setTagName("quote");
$this->setUseOption(true);
$this->setParseContent(true);
}
/**
* Compiles the user bbcode to HTML
*
* @param ElementNode $el The JBBCode element node.
*
* @return string The compiled HTML.
*/
public function asHtml(ElementNode $el)
{
$attr = $el->getAttribute()['quote'];
if (substr($attr, 0, 1) === '#') {
$postId = substr($attr, 1);
$post = new Post($postId);
$forum = new Forum($post->forum);
if ($post->id !== 0
2016-03-31 20:03:25 +00:00
&& $forum->permission(ForumPerms::VIEW, ActiveUser::$user->id)) {
$postLink = Router::route('forums.post', $post->id);
$content = "<blockquote><div class='quotee'><a href='{$postLink}' style='color: inherit;'>"
. "<span style='color: {$post->poster->colour}'>"
. "{$post->poster->username}</span> wrote</a></div>"
. "<div class='quote'>{$post->parsed}</div></blockquote>";
return $content;
}
}
$content = "";
foreach ($el->getChildren() as $child) {
$content .= $child->getAsHTML();
}
return "<blockquote><div class='quotee'>{$attr} wrote</div>
<div class='quote'>{$content}</div></blockquote>";
}
}