diff --git a/src/Bootstrap.php b/src/Bootstrap.php
index 0f00a2ff..cef2078b 100644
--- a/src/Bootstrap.php
+++ b/src/Bootstrap.php
@@ -7,19 +7,7 @@ class Bootstrap
session_start();
$this->context->handleExceptions = false;
- $this->context->title = $this->config->main->title;
- $this->context->stylesheets =
- [
- '../lib/jquery-ui/jquery-ui.css',
- 'core.css',
- ];
- $this->context->scripts =
- [
- '../lib/jquery/jquery.min.js',
- '../lib/jquery-ui/jquery-ui.min.js',
- '../lib/mousetrap/mousetrap.min.js',
- 'core.js',
- ];
+ LayoutHelper::setTitle($this->config->main->title);
$this->context->json = isset($_GET['json']);
$this->context->layoutName = $this->context->json
@@ -39,7 +27,14 @@ class Bootstrap
try
{
- $workCallback();
+ if ($this->context->layoutName == 'layout-normal')
+ {
+ ob_start(['LayoutHelper', 'transformHtml']);
+ $workCallback();
+ ob_end_flush();
+ }
+ else
+ $workCallback();
}
catch (\Chibi\MissingViewFileException $e)
{
diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php
index 6cd94b9b..ad4fa6b5 100644
--- a/src/Controllers/AuthController.php
+++ b/src/Controllers/AuthController.php
@@ -55,8 +55,6 @@ class AuthController
public function loginAction()
{
$this->context->handleExceptions = true;
- $this->context->stylesheets []= 'auth.css';
- $this->context->subTitle = 'authentication form';
//check if already logged in
if ($this->context->loggedIn)
diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php
index 25694680..0af886af 100644
--- a/src/Controllers/CommentController.php
+++ b/src/Controllers/CommentController.php
@@ -8,18 +8,8 @@ class CommentController
*/
public function listAction($page)
{
- $this->context->stylesheets []= 'post-small.css';
- $this->context->stylesheets []= 'comment-list.css';
- $this->context->stylesheets []= 'comment-small.css';
- $this->context->stylesheets []= 'comment-edit.css';
- $this->context->stylesheets []= 'paginator.css';
- if ($this->context->user->hasEnabledEndlessScrolling())
- $this->context->scripts []= 'paginator-endless.js';
- $this->context->scripts []= 'comment-edit.js';
-
$page = intval($page);
$commentsPerPage = intval($this->config->comments->commentsPerPage);
- $this->context->subTitle = 'comments';
PrivilegesHelper::confirmWithException(Privilege::ListComments);
$page = max(1, $page);
diff --git a/src/Controllers/IndexController.php b/src/Controllers/IndexController.php
index 6a072f66..05016c7d 100644
--- a/src/Controllers/IndexController.php
+++ b/src/Controllers/IndexController.php
@@ -7,8 +7,6 @@ class IndexController
*/
public function indexAction()
{
- $this->context->subTitle = 'home';
- $this->context->stylesheets []= 'index-index.css';
$this->context->transport->postCount = PostModel::getCount();
$featuredPost = $this->getFeaturedPost();
@@ -17,7 +15,6 @@ class IndexController
$this->context->featuredPost = $featuredPost;
$this->context->featuredPostDate = PropertyModel::get(PropertyModel::FeaturedPostDate);
$this->context->featuredPostUser = UserModel::findByNameOrEmail(PropertyModel::get(PropertyModel::FeaturedPostUserName), false);
- $this->context->pageThumb = \Chibi\UrlHelper::route('post', 'thumb', ['name' => $featuredPost->name]);
}
}
@@ -33,8 +30,6 @@ class IndexController
if (!isset($this->config->help->paths[$tab]))
throw new SimpleException('Invalid tab');
$this->context->path = TextHelper::absolutePath($this->config->help->paths[$tab]);
- $this->context->stylesheets []= 'index-help.css';
- $this->context->subTitle = 'help';
$this->context->tab = $tab;
}
diff --git a/src/Controllers/LogController.php b/src/Controllers/LogController.php
index e11cdab4..90452102 100644
--- a/src/Controllers/LogController.php
+++ b/src/Controllers/LogController.php
@@ -6,7 +6,6 @@ class LogController
*/
public function listAction()
{
- $this->context->subTitle = 'latest logs';
PrivilegesHelper::confirmWithException(Privilege::ListLogs);
$path = TextHelper::absolutePath($this->config->main->logsPath);
@@ -49,12 +48,6 @@ class LogController
return;
}
- $this->context->subTitle = 'logs (' . $name . ')';
- $this->context->stylesheets []= 'logs.css';
- $this->context->stylesheets []= 'paginator.css';
- $this->context->scripts []= 'logs.js';
- if ($this->context->user->hasEnabledEndlessScrolling())
- $this->context->scripts []= 'paginator-endless.js';
PrivilegesHelper::confirmWithException(Privilege::ViewLog);
//parse input
diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php
index a2d9b45d..47b0cf33 100644
--- a/src/Controllers/PostController.php
+++ b/src/Controllers/PostController.php
@@ -1,13 +1,6 @@
context->stylesheets []= '../lib/tagit/jquery.tagit.css';
- $this->context->scripts []= '../lib/tagit/jquery.tagit.js';
- $callback();
- }
-
private static function handleUploadErrors($file)
{
switch ($file['error'])
@@ -52,12 +45,6 @@ class PostController
public function listAction($query = null, $page = 1, $source = 'posts', $additionalInfo = null)
{
$this->context->viewName = 'post-list-wrapper';
- $this->context->stylesheets []= 'post-small.css';
- $this->context->stylesheets []= 'post-list.css';
- $this->context->stylesheets []= 'paginator.css';
- $this->context->scripts []= 'post-list.js';
- if ($this->context->user->hasEnabledEndlessScrolling())
- $this->context->scripts []= 'paginator-endless.js';
$this->context->source = $source;
$this->context->additionalInfo = $additionalInfo;
@@ -77,7 +64,6 @@ class PostController
$query = trim($query);
$page = max(1, intval($page));
$postsPerPage = intval($this->config->browsing->postsPerPage);
- $this->context->subTitle = 'posts';
$this->context->transport->searchQuery = $query;
$this->context->transport->lastSearchQuery = $query;
PrivilegesHelper::confirmWithException(Privilege::ListPosts);
@@ -180,9 +166,6 @@ class PostController
*/
public function uploadAction()
{
- $this->context->stylesheets []= 'post-upload.css';
- $this->context->scripts []= 'post-upload.js';
- $this->context->subTitle = 'upload';
PrivilegesHelper::confirmWithException(Privilege::UploadPost);
if ($this->config->registration->needEmailForUploading)
PrivilegesHelper::confirmEmail($this->context->user);
@@ -458,13 +441,6 @@ class PostController
$score = $this->context->user->getScore($post);
$flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', []));
- $this->context->pageThumb = \Chibi\UrlHelper::route('post', 'thumb', ['name' => $post->name]);
- $this->context->stylesheets []= 'post-view.css';
- $this->context->stylesheets []= 'comment-small.css';
- $this->context->stylesheets []= 'comment-edit.css';
- $this->context->scripts []= 'post-view.js';
- $this->context->scripts []= 'comment-edit.js';
- $this->context->subTitle = 'showing ' . TextHelper::reprPost($post) . ' – ' . TextHelper::reprTags($post->getTags());
$this->context->favorite = $favorite;
$this->context->score = $score;
$this->context->flagged = $flagged;
diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php
index f385bd2d..505ce4d9 100644
--- a/src/Controllers/TagController.php
+++ b/src/Controllers/TagController.php
@@ -8,8 +8,6 @@ class TagController
*/
public function listAction($filter = null)
{
- $this->context->stylesheets []= 'tag-list.css';
- $this->context->subTitle = 'tags';
$this->context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::ListTags);
@@ -32,8 +30,6 @@ class TagController
*/
public function mergeAction()
{
- $this->context->stylesheets []= 'tag-list.css';
- $this->context->subTitle = 'tags';
$this->context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
@@ -60,8 +56,6 @@ class TagController
*/
public function renameAction()
{
- $this->context->stylesheets []= 'tag-list.css';
- $this->context->subTitle = 'tags';
$this->context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
@@ -88,8 +82,6 @@ class TagController
*/
public function massTagRedirectAction()
{
- $this->context->stylesheets []= 'tag-list.css';
- $this->context->subTitle = 'tags';
$this->context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::MassTag);
diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php
index 0e6f8b28..56cb1a68 100644
--- a/src/Controllers/UserController.php
+++ b/src/Controllers/UserController.php
@@ -8,8 +8,6 @@ class UserController
$this->context->transport->user = $user;
$this->context->handleExceptions = true;
$this->context->viewName = 'user-view';
- $this->context->stylesheets []= 'user-view.css';
- $this->context->subTitle = $user->name;
}
private static function sendTokenizedEmail(
@@ -109,11 +107,6 @@ class UserController
*/
public function listAction($sortStyle, $page)
{
- $this->context->stylesheets []= 'user-list.css';
- $this->context->stylesheets []= 'paginator.css';
- if ($this->context->user->hasEnabledEndlessScrolling())
- $this->context->scripts []= 'paginator-endless.js';
-
if ($sortStyle == '' or $sortStyle == 'alpha')
$sortStyle = 'alpha,asc';
if ($sortStyle == 'date')
@@ -121,7 +114,6 @@ class UserController
$page = intval($page);
$usersPerPage = intval($this->config->browsing->usersPerPage);
- $this->context->subTitle = 'users';
PrivilegesHelper::confirmWithException(Privilege::ListUsers);
$page = max(1, $page);
@@ -422,12 +414,6 @@ class UserController
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
$this->loadUserView($user);
- $this->context->stylesheets []= 'post-list.css';
- $this->context->stylesheets []= 'post-small.css';
- $this->context->stylesheets []= 'paginator.css';
- $this->context->scripts []= 'post-list.js';
- if ($this->context->user->hasEnabledEndlessScrolling())
- $this->context->scripts []= 'paginator-endless.js';
$query = '';
if ($tab == 'uploads')
@@ -483,8 +469,6 @@ class UserController
public function registrationAction()
{
$this->context->handleExceptions = true;
- $this->context->stylesheets []= 'auth.css';
- $this->context->subTitle = 'registration form';
//check if already logged in
if ($this->context->loggedIn)
@@ -570,8 +554,8 @@ class UserController
*/
public function activationAction($token)
{
- $this->context->subTitle = 'account activation';
$this->context->viewName = 'message';
+ LayoutHelper::setSubTitle('account activation');
$dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken);
@@ -603,8 +587,8 @@ class UserController
*/
public function passwordResetAction($token)
{
- $this->context->subTitle = 'password reset';
$this->context->viewName = 'message';
+ LayoutHelper::setSubTitle('password reset');
$dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken);
@@ -637,9 +621,8 @@ class UserController
*/
public function passwordResetProxyAction()
{
- $this->context->subTtile = 'password reset';
$this->context->viewName = 'user-select';
- $this->context->stylesheets []= 'auth.css';
+ LayoutHelper::setSubTitle('password reset');
if (InputHelper::get('submit'))
{
@@ -658,9 +641,8 @@ class UserController
*/
public function activationProxyAction()
{
- $this->context->subTitle = 'account activation';
$this->context->viewName = 'user-select';
- $this->context->stylesheets []= 'auth.css';
+ LayoutHelper::setSubTitle('account activation');
if (InputHelper::get('submit'))
{
diff --git a/src/Helpers/LayoutHelper.php b/src/Helpers/LayoutHelper.php
new file mode 100644
index 00000000..a4ce0a92
--- /dev/null
+++ b/src/Helpers/LayoutHelper.php
@@ -0,0 +1,66 @@
+' . $title . '';
+
+ $headSnippet .= '';
+ $headSnippet .= '';
+ if (!empty(self::$pageThumb))
+ $headSnippet .= '';
+
+ foreach (array_unique(self::$stylesheets) as $name)
+ $headSnippet .= '';
+
+ foreach (array_unique(self::$scripts) as $name)
+ $bodySnippet .= '';
+
+ $bodySnippet .= '';
+
+ $html = str_replace('', $headSnippet . '', $html);
+ $html = str_replace('