diff --git a/app/BBCode/Parser.php b/app/BBCode/Parser.php
index 375427b..dd1ca9a 100644
--- a/app/BBCode/Parser.php
+++ b/app/BBCode/Parser.php
@@ -7,6 +7,7 @@
namespace Sakura\BBCode;
use Sakura\DB;
+use Sakura\User;
/**
* BBcode handler.
@@ -47,7 +48,7 @@ class Parser
Tags\Box::class,
Tags\Code::class,
Tags\ListTag::class,
- Tags\User::class,
+ Tags\UserTag::class,
Tags\Markdown::class,
// Newline must always be last
@@ -59,7 +60,7 @@ class Parser
* @param string $text
* @return string
*/
- public static function parseEmoticons($text)
+ public static function parseEmoticons($text, User $poster = null)
{
// Get emoticons from the database
$emotes = DB::table('emoticons')
@@ -81,12 +82,12 @@ class Parser
* @param string $text
* @return string
*/
- public static function toHTML($text)
+ public static function toHTML($text, User $poster)
{
$text = self::parseEmoticons($text);
foreach (self::$parsers as $parser) {
- $text = call_user_func([$parser, 'parse'], $text);
+ $text = call_user_func_array([$parser, 'parse'], [$text, $poster]);
}
return $text;
diff --git a/app/BBCode/TagBase.php b/app/BBCode/TagBase.php
index a9a6a6f..6ca7527 100644
--- a/app/BBCode/TagBase.php
+++ b/app/BBCode/TagBase.php
@@ -6,6 +6,8 @@
namespace Sakura\BBCode;
+use Sakura\User;
+
/**
* Interface for tags.
* @package Sakura
@@ -30,7 +32,7 @@ class TagBase
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace(static::$pattern, static::$replace, $text);
}
diff --git a/app/BBCode/Tags/Align.php b/app/BBCode/Tags/Align.php
index 34f8bbb..1c62027 100644
--- a/app/BBCode/Tags/Align.php
+++ b/app/BBCode/Tags/Align.php
@@ -7,6 +7,7 @@
namespace Sakura\BBCode\Tags;
use Sakura\BBCode\TagBase;
+use Sakura\User;
/**
* Align tag.
@@ -20,7 +21,7 @@ class Align extends TagBase
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace_callback(
'/\[align\=(left|center|centre|right)\](.*?)\[\/align\]/s',
@@ -29,7 +30,7 @@ class Align extends TagBase
$matches[1] = 'center';
}
- return "
"
- . "
{$title}
"
- . "
{$matches[2]}
"
+ return "
"
+ . "
{$title}
"
+ . "
{$matches[2]}
"
. "
";
},
$text
diff --git a/app/BBCode/Tags/Code.php b/app/BBCode/Tags/Code.php
index 2201742..a8ca006 100644
--- a/app/BBCode/Tags/Code.php
+++ b/app/BBCode/Tags/Code.php
@@ -7,6 +7,7 @@
namespace Sakura\BBCode\Tags;
use Sakura\BBCode\TagBase;
+use Sakura\User;
/**
* Code tag.
@@ -20,15 +21,15 @@ class Code extends TagBase
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace_callback(
'/\[code(?:\=([a-z]+))?\](.*?)\[\/code\]/s',
function ($matches) {
- $class = strlen($matches[1]) ? " class='lang-{$matches[1]}'" : '';
+ $class = strlen($matches[1]) ? "lang-{$matches[1]}" : '';
// htmlencode bbcode characters here as well
- return "
{$matches[2]}
";
+ return "
{$matches[2]}
";
},
$text
);
diff --git a/app/BBCode/Tags/Colour.php b/app/BBCode/Tags/Colour.php
index 8ed8457..6c440f2 100644
--- a/app/BBCode/Tags/Colour.php
+++ b/app/BBCode/Tags/Colour.php
@@ -25,5 +25,5 @@ class Colour extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$2";
+ public static $replace = "
$2";
}
diff --git a/app/BBCode/Tags/Header.php b/app/BBCode/Tags/Header.php
index fac0b9b..cb8a299 100644
--- a/app/BBCode/Tags/Header.php
+++ b/app/BBCode/Tags/Header.php
@@ -25,5 +25,5 @@ class Header extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$1
";
+ public static $replace = "";
}
diff --git a/app/BBCode/Tags/Image.php b/app/BBCode/Tags/Image.php
index 2547385..ea3f475 100644
--- a/app/BBCode/Tags/Image.php
+++ b/app/BBCode/Tags/Image.php
@@ -25,5 +25,5 @@ class Image extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
";
+ public static $replace = "
";
}
diff --git a/app/BBCode/Tags/Italics.php b/app/BBCode/Tags/Italics.php
index cd489fb..4d41508 100644
--- a/app/BBCode/Tags/Italics.php
+++ b/app/BBCode/Tags/Italics.php
@@ -25,5 +25,5 @@ class Italics extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$1";
+ public static $replace = "
$1";
}
diff --git a/app/BBCode/Tags/Link.php b/app/BBCode/Tags/Link.php
index e9099fb..fe25e24 100644
--- a/app/BBCode/Tags/Link.php
+++ b/app/BBCode/Tags/Link.php
@@ -25,5 +25,5 @@ class Link extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$1";
+ public static $replace = "
$1";
}
diff --git a/app/BBCode/Tags/ListTag.php b/app/BBCode/Tags/ListTag.php
index 0838d5f..297d63e 100644
--- a/app/BBCode/Tags/ListTag.php
+++ b/app/BBCode/Tags/ListTag.php
@@ -7,6 +7,7 @@
namespace Sakura\BBCode\Tags;
use Sakura\BBCode\TagBase;
+use Sakura\User;
/**
* List tag. Name is suffixed with Tag since "list" is a language construct.
@@ -20,18 +21,18 @@ class ListTag extends TagBase
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace_callback(
'/\[list(?:\=(1|A|a|I|i))?\](.*?)\[\/list\]/s',
function ($matches) {
- $content = preg_replace('/\[\*\](.*)/', '
$1', $matches[2]);
+ $content = preg_replace('/\[\*\](.*)/', '
$1', $matches[2]);
if ($matches[1] !== '') {
- return "
{$content}
";
+ return "
{$content}
";
}
- return "
";
+ return "
";
},
$text
);
diff --git a/app/BBCode/Tags/Markdown.php b/app/BBCode/Tags/Markdown.php
index 70d984d..4f9cd8e 100644
--- a/app/BBCode/Tags/Markdown.php
+++ b/app/BBCode/Tags/Markdown.php
@@ -8,6 +8,7 @@ namespace Sakura\BBCode\Tags;
use Parsedown;
use Sakura\BBCode\TagBase;
+use Sakura\User;
/**
* Markdown!
@@ -27,7 +28,7 @@ class Markdown extends TagBase
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace_callback(
'/\[md\](.*?)\[\/md\]/s',
@@ -41,7 +42,7 @@ class Markdown extends TagBase
->setMarkupEscaped(true)
->text($matches[1]);
- return "
{$parsed}
";
+ return "
{$parsed}
";
},
$text
);
diff --git a/app/BBCode/Tags/NamedLink.php b/app/BBCode/Tags/NamedLink.php
index 4947a8d..6a24e4a 100644
--- a/app/BBCode/Tags/NamedLink.php
+++ b/app/BBCode/Tags/NamedLink.php
@@ -25,5 +25,5 @@ class NamedLink extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$2";
+ public static $replace = "
$2";
}
diff --git a/app/BBCode/Tags/NamedQuote.php b/app/BBCode/Tags/NamedQuote.php
index 818b9e5..51bed29 100644
--- a/app/BBCode/Tags/NamedQuote.php
+++ b/app/BBCode/Tags/NamedQuote.php
@@ -11,6 +11,7 @@ use Sakura\CurrentSession;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Perms\Forum as ForumPerms;
+use Sakura\User;
/**
* Named quote tag.
@@ -24,11 +25,11 @@ class NamedQuote extends TagBase
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace_callback(
'/\[quote\=(#?)(.*?)\](.*)\[\/quote\]/s',
- function ($matches) {
+ function ($matches) use ($poster) {
$quoting = $matches[2];
$content = $matches[3];
@@ -36,15 +37,15 @@ class NamedQuote extends TagBase
$post = new Post(intval($matches[2]));
$forum = new Forum($post->forum);
- if ($post->id !== 0 && $forum->permission(ForumPerms::VIEW, CurrentSession::$user->id)) {
+ if ($post->id !== 0 && $forum->permission(ForumPerms::VIEW, $poster->id)) {
$link = route('forums.post', $post->id);
- $quoting = "
{$post->poster->username}";
+ $quoting = "
{$post->poster->username}";
$content = $post->parsed;
}
}
- return "
{$quoting}{$content}
";
+ return "
{$quoting}{$content}
";
},
$text
);
diff --git a/app/BBCode/Tags/Quote.php b/app/BBCode/Tags/Quote.php
index 14afd00..dc5c304 100644
--- a/app/BBCode/Tags/Quote.php
+++ b/app/BBCode/Tags/Quote.php
@@ -25,5 +25,5 @@ class Quote extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$1
";
+ public static $replace = "
$1
";
}
diff --git a/app/BBCode/Tags/Size.php b/app/BBCode/Tags/Size.php
index 4c574b9..500d4c9 100644
--- a/app/BBCode/Tags/Size.php
+++ b/app/BBCode/Tags/Size.php
@@ -7,6 +7,7 @@
namespace Sakura\BBCode\Tags;
use Sakura\BBCode\TagBase;
+use Sakura\User;
/**
* Size tag.
@@ -44,7 +45,7 @@ class Size extends TagBase
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace_callback(
'/\[size\=([a-z0-9]+)\](.*?)\[\/size\]/s',
@@ -62,7 +63,7 @@ class Size extends TagBase
}
// we'll just use per cent for now, don't let this make it to production though
- return "
{$matches[2]}
";
+ return "
{$matches[2]}
";
},
$text
);
diff --git a/app/BBCode/Tags/Spoiler.php b/app/BBCode/Tags/Spoiler.php
index dc50b96..081f834 100644
--- a/app/BBCode/Tags/Spoiler.php
+++ b/app/BBCode/Tags/Spoiler.php
@@ -25,5 +25,5 @@ class Spoiler extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$1";
+ public static $replace = "
$1";
}
diff --git a/app/BBCode/Tags/Strike.php b/app/BBCode/Tags/Strike.php
index d4b8371..b0280ef 100644
--- a/app/BBCode/Tags/Strike.php
+++ b/app/BBCode/Tags/Strike.php
@@ -25,5 +25,5 @@ class Strike extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$1";
+ public static $replace = "
$1";
}
diff --git a/app/BBCode/Tags/Underline.php b/app/BBCode/Tags/Underline.php
index f45d7d7..9d9682b 100644
--- a/app/BBCode/Tags/Underline.php
+++ b/app/BBCode/Tags/Underline.php
@@ -25,5 +25,5 @@ class Underline extends TagBase
* The string to replace it with.
* @var string
*/
- public static $replace = "
$1";
+ public static $replace = "
$1";
}
diff --git a/app/BBCode/Tags/User.php b/app/BBCode/Tags/UserTag.php
similarity index 71%
rename from app/BBCode/Tags/User.php
rename to app/BBCode/Tags/UserTag.php
index 4306931..ed80be3 100644
--- a/app/BBCode/Tags/User.php
+++ b/app/BBCode/Tags/UserTag.php
@@ -7,29 +7,29 @@
namespace Sakura\BBCode\Tags;
use Sakura\BBCode\TagBase;
-use Sakura\User as UserObject;
+use Sakura\User;
/**
* User tag.
* @package Sakura
* @author Julian van de Groep
*/
-class User extends TagBase
+class UserTag extends TagBase
{
/**
* Parses the bbcode.
* @param string $text
* @return string
*/
- public static function parse($text)
+ public static function parse($text, User $poster)
{
return preg_replace_callback(
'/\[user\]([0-9]+)\[\/user\]/s',
function ($matches) {
- $user = UserObject::construct($matches[1]);
+ $user = User::construct($matches[1]);
$route = route('user.profile', $user->id);
- return "{$user->username}";
},
$text
diff --git a/app/BBCode/Tags/YouTube.php b/app/BBCode/Tags/YouTube.php
index 5fbf0e1..6f0ede7 100644
--- a/app/BBCode/Tags/YouTube.php
+++ b/app/BBCode/Tags/YouTube.php
@@ -26,5 +26,5 @@ class YouTube extends TagBase
* @var string
*/
public static $replace = "";
+ . " frameborder='0' allowfullscreen class='bbcode__youtube'>";
}
diff --git a/app/Console/Command/RebuildForumCacheCommand.php b/app/Console/Command/RebuildForumCacheCommand.php
new file mode 100644
index 0000000..ec71378
--- /dev/null
+++ b/app/Console/Command/RebuildForumCacheCommand.php
@@ -0,0 +1,43 @@
+
+ */
+class RebuildForumCacheCommand extends Command
+{
+ /**
+ * A quick description of this command.
+ * @return string.
+ */
+ public function brief()
+ {
+ return 'Rebuild the forum bbcode cache';
+ }
+
+ /**
+ * Does the repository installing.
+ */
+ public function execute()
+ {
+ $this->getLogger()->writeln("This might take a while...");
+ $posts = DB::table('posts')->get(['post_id']);
+
+ foreach ($posts as $post) {
+ (new Post($post->post_id))->update(true);
+ }
+
+ $this->getLogger()->writeln("Done!");
+ }
+}
diff --git a/app/ExceptionHandler.php b/app/ExceptionHandler.php
index e293fc9..aed918e 100644
--- a/app/ExceptionHandler.php
+++ b/app/ExceptionHandler.php
@@ -69,9 +69,13 @@ class ExceptionHandler
http_response_code(500);
$debug = config('dev.show_errors');
+ $cli = php_sapi_name() === 'cli';
+
+ if ($cli || $debug) {
+ if (!$cli) {
+ header('Content-Type: text/plain');
+ }
- if ($debug) {
- header('Content-Type: text/plain');
echo $ex;
} else {
if (!self::$disableTemplate && Template::available()) {
diff --git a/app/Forum/Post.php b/app/Forum/Post.php
index dcdeba4..dec9e5c 100644
--- a/app/Forum/Post.php
+++ b/app/Forum/Post.php
@@ -132,7 +132,7 @@ class Post
}
if (strlen($this->parsed) < 1) {
- $this->parsed = BBParser::toHTML(htmlentities($this->text));
+ $this->parsed = BBParser::toHTML(htmlentities($this->text), $this->poster);
$this->update();
}
}
@@ -171,7 +171,7 @@ class Post
'post_time' => time(),
'post_subject' => $subject,
'post_text' => $text,
- 'post_text_parsed' => BBParser::toHTML(htmlentities($text)),
+ 'post_text_parsed' => BBParser::toHTML(htmlentities($text), $this->poster),
]);
// Update the last post date
@@ -183,9 +183,10 @@ class Post
/**
* Commit the changes to the Database.
+ * @param bool $ignoreIp
* @return Post
*/
- public function update()
+ public function update($ignoreIp = false)
{
// Create a topic object
$topic = new Topic($this->topic);
@@ -197,11 +198,11 @@ class Post
'topic_id' => $topic->id,
'forum_id' => $topic->forum,
'poster_id' => $this->poster->id,
- 'poster_ip' => Net::pton(Net::ip()),
+ 'poster_ip' => Net::pton($ignoreIp ? $this->ip : Net::ip()),
'post_time' => $this->time,
'post_subject' => $this->subject,
'post_text' => $this->text,
- 'post_text_parsed' => BBParser::toHTML(htmlentities($this->text)),
+ 'post_text_parsed' => BBParser::toHTML(htmlentities($this->text), $this->poster),
'post_edit_time' => $this->editTime,
'post_edit_reason' => $this->editReason,
'post_edit_user' => $this->editUser->id,
diff --git a/public/index.php b/public/index.php
index 51b2dd9..8da8781 100644
--- a/public/index.php
+++ b/public/index.php
@@ -12,10 +12,6 @@ require_once __DIR__ . '/../sakura.php';
// Start output buffering
ob_start(config('performance.compression') ? 'ob_gzhandler' : null);
-// Initialise the router and include the routes file
-Routerv1::init();
-include_once path('routes.php');
-
// Initialise the current session
$cookiePrefix = config('cookie.prefix');
CurrentSession::start(
diff --git a/resources/assets/less/yuuno/bbcode.less b/resources/assets/less/yuuno/bbcode.less
index 84d8386..4024c65 100644
--- a/resources/assets/less/yuuno/bbcode.less
+++ b/resources/assets/less/yuuno/bbcode.less
@@ -1,49 +1,45 @@
.bbcode {
- line-height: 1.4;
- word-wrap: break-word;
+ // line-height: 1.4;
+ // word-wrap: break-word;
- h1,
- h2,
- h3 {
+ &__header {
text-shadow: 0 0 5px #8364A1;
color: #614390;
}
- ul {
+ &__list {
margin-left: 2em;
- list-style: square;
- }
- .spoiler {
- background: #000;
-
- &:hover {
- background: inherit;
+ &--unordered {
+ list-style: square;
}
}
- blockquote {
+ &__spoiler {
+ background: #000;
+
+ &:hover {
+ background: #888;
+ }
+ }
+
+ &__quote {
border: 1px solid #9475b2;
border-bottom: 0;
border-right: 0;
background: #D8B9F6;
margin: .5em;
- > .quotee {
+ &-name {
font-weight: bold;
border-bottom: 1px solid #9475b2;
border-right: 1px solid #9475b2;
background: #B697d4;
padding-left: .5em;
}
-
- > .quote {
- margin-left: .5em;
- padding-bottom: .2em;
- }
}
- a {
+ &__link {
color: #22E;
text-decoration: none;
@@ -58,11 +54,11 @@
}
}
- .spoiler-box-container {
+ &__box {
border: 1px solid #9475b2;
margin: .5em;
- > .spoiler-box-title {
+ &-title {
text-align: center;
background: #B697d4;
font-weight: bold;
@@ -70,19 +66,24 @@
padding: 4px 0;
}
- > .spoiler-box-content {
+ &-content {
border-top: 1px solid #9475b2;
+
+ &--hidden {
+ .hidden;
+ }
}
}
- img {
+ &__image {
width: auto;
height: auto;
max-height: 100%;
max-width: 100%;
}
- code {
+ &__code {
font-size: 1.1em;
+ line-height: 1.5em;
}
}
diff --git a/sakura.php b/sakura.php
index b894038..26f6f9b 100644
--- a/sakura.php
+++ b/sakura.php
@@ -11,3 +11,6 @@ require_once 'vendor/autoload.php';
ExceptionHandler::register();
Config::load(path('config/config.ini'));
DB::connect(config('database'));
+
+Routerv1::init();
+include_once path('routes.php');