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/app/BBcodeDefinitions/User.php

56 lines
1.2 KiB
PHP
Raw Normal View History

2016-01-22 12:46:52 +00:00
<?php
2016-02-03 22:22:56 +00:00
/**
* Holds the username linking bbcode class.
2016-03-08 23:07:58 +00:00
*
2016-02-03 22:22:56 +00:00
* @package Sakura
2016-01-22 12:46:52 +00:00
*/
namespace Sakura\BBcodeDefinitions;
use JBBCode\CodeDefinition;
use JBBCode\ElementNode;
2016-03-19 15:29:47 +00:00
use Sakura\Router;
2016-03-26 18:03:35 +00:00
use Sakura\User as SakuraUser;
2016-01-22 12:46:52 +00:00
2016-02-03 22:22:56 +00:00
/**
* Username BBcode for JBBCode.
2016-03-08 23:07:58 +00:00
*
2016-02-03 22:22:56 +00:00
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
2016-01-22 12:46:52 +00:00
class User extends CodeDefinition
{
2016-02-03 22:22:56 +00:00
/**
* Constructor.
*/
2016-01-22 12:46:52 +00:00
public function __construct()
{
parent::__construct();
$this->setTagName("user");
$this->setUseOption(false);
$this->setParseContent(false);
}
2016-02-03 22:22:56 +00:00
/**
* Compiles the user bbcode to HTML
2016-03-08 23:07:58 +00:00
*
2016-02-03 22:22:56 +00:00
* @param ElementNode $el The JBBCode element node.
2016-03-08 23:07:58 +00:00
*
2016-02-03 22:22:56 +00:00
* @return string The compiled HTML.
*/
2016-01-22 12:46:52 +00:00
public function asHtml(ElementNode $el)
{
$content = "";
foreach ($el->getChildren() as $child) {
2016-04-01 21:44:31 +00:00
$content .= clean_string($child->getAsText(), true);
2016-01-22 12:46:52 +00:00
}
2016-03-26 18:03:35 +00:00
$user = SakuraUser::construct($content);
2016-03-19 15:29:47 +00:00
$profile = Router::route('user.profile', $user->id);
2016-01-22 12:46:52 +00:00
2016-03-19 15:29:47 +00:00
return "<a class='default username' href='{$profile} style='color: {$user->colour};
text-shadow: 0 0 .3em {$user->colour}; font-weight: bold;'>{$user->username}</a>";
2016-01-22 12:46:52 +00:00
}
}