Refactored scripts and stylesheets

Styles, scripts and page titles are no longer set from controllers level.
Changed because it was breaking MVC pattern and led to spaghetti code.

Also, optimized JS/CSS inclusions a bit.
This commit is contained in:
Marcin Kurczewski 2014-02-01 11:17:02 +01:00
parent d170e3b526
commit 35cdc0cf3a
35 changed files with 374 additions and 275 deletions

View file

@ -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)
{

View file

@ -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)

View file

@ -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);

View file

@ -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;
}

View file

@ -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

View file

@ -1,13 +1,6 @@
<?php
class PostController
{
public function workWrapper($callback)
{
$this->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) . ' &ndash; ' . TextHelper::reprTags($post->getTags());
$this->context->favorite = $favorite;
$this->context->score = $score;
$this->context->flagged = $flagged;

View file

@ -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);

View file

@ -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'))
{

View file

@ -0,0 +1,66 @@
<?php
class LayoutHelper
{
private static $stylesheets = [];
private static $scripts = [];
private static $title = null;
private static $pageThumb = null;
private static $subTitle = null;
public static function setTitle($text)
{
self::$title = $text;
}
public static function setSubTitle($text)
{
self::$subTitle = $text;
}
public static function setPageThumb($path)
{
self::$pageThumb = $path;
}
public static function addStylesheet($css)
{
self::$stylesheets []= $css;
}
public static function addScript($js)
{
self::$scripts []= $js;
}
public static function transformHtml($html)
{
$bodySnippet = '';
$headSnippet = '';
$title = isset(self::$subTitle)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', self::$title, self::$subTitle)
: self::$title;
$headSnippet .= '<title>' . $title . '</title>';
$headSnippet .= '<meta property="og:title" content="' . $title . '"/>';
$headSnippet .= '<meta property="og:url" content="' . \Chibi\UrlHelper::currentUrl() . '"/>';
if (!empty(self::$pageThumb))
$headSnippet .= '<meta property="og:image" content="' . self::$pageThumb . '"/>';
foreach (array_unique(self::$stylesheets) as $name)
$headSnippet .= '<link rel="stylesheet" type="text/css" href="' . \Chibi\UrlHelper::absoluteUrl('/media/css/' . $name) . '"/>';
foreach (array_unique(self::$scripts) as $name)
$bodySnippet .= '<script type="text/javascript" src="' . \Chibi\UrlHelper::absoluteUrl('/media/js/' . $name) . '"></script>';
$bodySnippet .= '<script type="text/javascript">';
$bodySnippet .= '$(function() {';
$bodySnippet .= '$(\'body\').trigger(\'dom-update\');';
$bodySnippet .= '});';
$bodySnippet .= '</script>';
$html = str_replace('</head>', $headSnippet . '</head>', $html);
$html = str_replace('</body>', $bodySnippet . '</body>', $html);
return $html;
}
}

View file

@ -1,3 +1,8 @@
<?php
LayoutHelper::setSubTitle('authentication form');
LayoutHelper::addStylesheet('auth.css');
?>
<form action="<?php echo \Chibi\UrlHelper::route('auth', 'login') ?>" class="auth aligned" method="post">
<div>
<p>If you don't have an account yet,<br/><a href="<?php echo \Chibi\UrlHelper::route('user', 'registration'); ?>">click here</a> to create a new one.</p>

View file

@ -1,3 +1,8 @@
<?php
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
?>
<form action="<?php echo \Chibi\UrlHelper::route('comment', 'add', ['postId' => $this->context->transport->post->id]) ?>" method="post" class="add-comment aligned">
<h1>add comment</h1>

View file

@ -1,3 +1,8 @@
<?php
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
?>
<form action="<?php echo \Chibi\UrlHelper::route('comment', 'edit', ['id' => $this->context->transport->comment->id]) ?>" method="post" class="edit-comment aligned">
<h1>edit comment</h1>

View file

@ -1,6 +1,17 @@
<?php
LayoutHelper::setSubTitle('comments');
?>
<?php if (empty($this->context->transport->comments)): ?>
<p class="alert alert-warning">No comments to show.</p>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('comment-list.css');
LayoutHelper::addStylesheet('comment-small.css');
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
?>
<div class="comments-wrapper">
<div class="comments paginator-content">
<?php

View file

@ -1,3 +1,9 @@
<?php
LayoutHelper::addStylesheet('comment-small.css');
LayoutHelper::addStylesheet('comment-edit.css');
LayoutHelper::addScript('comment-edit.js');
?>
<div class="comment">
<div class="avatar">
<?php $commenter = $this->context->comment->getCommenter() ?>

View file

@ -1,4 +1,7 @@
<?php
LayoutHelper::setSubtitle('help');
LayoutHelper::addStylesheet('index-help.css');
$tabs = $this->config->help->subTitles;
$firstTab = !empty($tabs) ? array_keys($tabs)[0] : null;
?>

View file

@ -1,3 +1,8 @@
<?php
LayoutHelper::setSubtitle('home');
LayoutHelper::addStylesheet('index-index.css');
?>
<div id="welcome">
<h1><?php echo $this->config->main->title ?></h1>
<p>

View file

@ -1,2 +1,3 @@
<?php \Chibi\HeadersHelper::set('Content-Type', 'application/json') ?>
<?php echo TextHelper::jsonEncode($this->context->transport, '/.*(email|confirm|pass|salt)/i') ?>
<?php
\Chibi\HeadersHelper::set('Content-Type', 'application/json');
echo TextHelper::jsonEncode($this->context->transport, '/.*(email|confirm|pass|salt)/i');

View file

@ -1,23 +1,17 @@
<?php
LayoutHelper::addStylesheet('../lib/jquery-ui/jquery-ui.css');
LayoutHelper::addStylesheet('core.css');
LayoutHelper::addScript('../lib/jquery/jquery.min.js');
LayoutHelper::addScript('../lib/jquery-ui/jquery-ui.min.js');
LayoutHelper::addScript('../lib/mousetrap/mousetrap.min.js');
LayoutHelper::addScript('core.js');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<?php
$title = isset($this->context->subTitle)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', $this->context->title, $this->context->subTitle)
: $this->context->title
?>
<title><?php echo $title ?></title>
<?php foreach (array_unique($this->context->stylesheets) as $name): ?>
<link rel="stylesheet" type="text/css" href="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/css/' . $name) ?>"/>
<?php endforeach ?>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"/>
<meta property="og:title" content="<?php echo $title ?>"/>
<meta property="og:url" content="<?php echo \Chibi\UrlHelper::currentUrl() ?>"/>
<?php if (!empty($this->context->pageThumb)): ?>
<meta property="og:image" content="<?php echo $this->context->pageThumb ?>"/>
<?php endif ?>
</head>
<body>
@ -64,16 +58,6 @@
<?php endif ?>
</footer>
<?php foreach (array_unique($this->context->scripts) as $name): ?>
<script type="text/javascript" src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/js/' . $name) ?>"></script>
<?php endforeach ?>
<script type="text/javascript">
$(function()
{
$('body').trigger('dom-update');
});
</script>
<div id="small-screen"></div>
</body>
</html>

View file

@ -1,3 +1,7 @@
<?php
$this->context->subTitle = 'latest logs';
?>
<?php if (empty($this->context->transport->logs)): ?>
<p class="alert alert-warning">No logs to show.</p>
<?php else: ?>

View file

@ -1,6 +1,15 @@
<?php
LayoutHelper::setSubTitle('logs (' . $name . ')');
?>
<?php if (empty($this->context->transport->lines)): ?>
<p class="alert alert-warning">This log is empty. <a href="<?php echo \Chibi\UrlHelper::route('log', 'list') ?>">Go back</a></p>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('logs.css');
LayoutHelper::addScript('logs.js');
?>
<form action="<?php echo \Chibi\UrlHelper::route('log', 'view', ['name' => $this->context->transport->name]) ?>" method="get">
Keep only lines that contain:

View file

@ -38,6 +38,12 @@ if (!function_exists('pageUrl'))
?>
<?php if (!empty($pagesVisible)): ?>
<?php
LayoutHelper::addStylesheet('paginator.css');
if ($this->context->user->hasEnabledEndlessScrolling())
LayoutHelper::addScript('paginator-endless.js');
?>
<nav class="paginator-wrapper">
<ul class="paginator">
<?php if ($page > 1): ?>

View file

@ -1,3 +1,4 @@
<?php LayoutHelper::setPageThumb(\Chibi\UrlHelper::route('post', 'thumb', ['name' => $this->context->transport->post->name])) ?>
<?php $post = $this->context->transport->post ?>
<?php if ($post->type == PostType::Image): ?>

View file

@ -1,4 +1,6 @@
<?php
LayoutHelper::setSubTitle('posts');
$tabs = [];
if (PrivilegesHelper::confirm(Privilege::ListPosts)) $tabs []= ['All posts', \Chibi\UrlHelper::route('post', 'list')];
if (PrivilegesHelper::confirm(Privilege::ListPosts)) $tabs []= ['Random', \Chibi\UrlHelper::route('post', 'random')];

View file

@ -1,3 +1,8 @@
<?php
LayoutHelper::addStylesheet('post-list.css');
LayoutHelper::addScript('post-list.js');
?>
<?php if (isset($this->context->source) and $this->context->source == 'mass-tag' and PrivilegesHelper::confirm(Privilege::MassTag)): ?>
<?php $this->renderFile('tag-mass-tag') ?>
<?php endif ?>

View file

@ -1,11 +1,25 @@
<?php $classNames = ['post', 'post-type-' . TextHelper::camelCaseToHumanCase(PostType::toString($this->context->post->type))] ?>
<?php $masstag = (isset($this->context->source) and $this->context->source == 'mass-tag' and !empty($this->context->additionalInfo)) ?>
<?php if ($masstag): ?>
<?php $classNames []= 'taggable' ?>
<?php if ($this->context->post->isTaggedWith($this->context->additionalInfo)): ?>
<?php $classNames []= 'tagged' ?>
<?php endif ?>
<?php endif ?>
<?php
LayoutHelper::addStylesheet('post-small.css');
$classNames =
[
'post',
'post-type-' . TextHelper::camelCaseToHumanCase(PostType::toString($this->context->post->type))
];
$masstag = (isset($this->context->source)
and $this->context->source == 'mass-tag'
and !empty($this->context->additionalInfo));
if ($masstag)
{
$classNames []= 'taggable';
if ($this->context->post->isTaggedWith($this->context->additionalInfo))
{
$classNames []= 'tagged';
}
}
?>
<div class="<?php echo implode(' ', $classNames) ?>">
<?php if ($masstag): ?>

View file

@ -1,3 +1,11 @@
<?php
LayoutHelper::setSubTitle('upload');
LayoutHelper::addStylesheet('post-upload.css');
LayoutHelper::addScript('post-upload.js');
LayoutHelper::addStylesheet('../lib/tagit/jquery.tagit.css');
LayoutHelper::addScript('../lib/tagit/jquery.tagit.js');
?>
<div id="sidebar">
<div class="unit">
<h1>file upload</h1>

View file

@ -1,3 +1,11 @@
<?php
LayoutHelper::setSubTitle('showing ' . TextHelper::reprPost($this->context->transport->post) . ' &ndash; ' . TextHelper::reprTags($this->context->transport->post->getTags()));
LayoutHelper::addStylesheet('post-view.css');
LayoutHelper::addScript('post-view.js');
LayoutHelper::addStylesheet('../lib/tagit/jquery.tagit.css');
LayoutHelper::addScript('../lib/tagit/jquery.tagit.js');
?>
<div id="sidebar">
<nav id="around">
<div class="left">

View file

@ -6,37 +6,37 @@
<?php foreach ($this->context->options as $option): ?>
<li class="<?php echo $option['class']; if (isset($option['inactive'])) echo ' inactive' ?>">
<?php
$class = [];
$class = [];
$attrs = [];
if (!empty($option['link']))
$attrs = [];
if (!empty($option['link']))
{
$attrs['href'] = $option['link'];
}
elseif (!empty($option['simple-action']))
{
$attrs['href'] = $option['simple-action'];
$class []= 'simple-action';
if (isset($option['data-confirm-text']))
{
$attrs['href'] = $option['link'];
$attrs['data-confirm-text'] = $option['data-confirm-text'];
$class []= 'confirmable';
}
elseif (!empty($option['simple-action']))
{
$attrs['href'] = $option['simple-action'];
$class []= 'simple-action';
if (isset($option['data-confirm-text']))
{
$attrs['data-confirm-text'] = $option['data-confirm-text'];
$class []= 'confirmable';
}
if (isset($option['data-redirect-url']))
$attrs['data-redirect-url'] = $option['data-redirect-url'];
}
else
$attrs['href'] = '#';
if (isset($option['data-redirect-url']))
$attrs['data-redirect-url'] = $option['data-redirect-url'];
}
else
$attrs['href'] = '#';
if (!empty($class))
$attrs['class'] = join(' ', $class);
if (!empty($class))
$attrs['class'] = join(' ', $class);
echo TextHelper::htmlTag('a', TextHelper::HTML_OPEN, $attrs);
echo $option['text'];
echo TextHelper::htmlTag('a', TextHelper::HTML_CLOSE);
?>
echo TextHelper::htmlTag('a', TextHelper::HTML_OPEN, $attrs);
echo $option['text'];
echo TextHelper::htmlTag('a', TextHelper::HTML_CLOSE);
?>
</li>
<?php endforeach ?>
</ul>

View file

@ -1,8 +1,13 @@
<?php $tabs = [] ?>
<?php if (PrivilegesHelper::confirm(Privilege::ListTags)) $tabs['list'] = 'List'; ?>
<?php if (PrivilegesHelper::confirm(Privilege::RenameTags)) $tabs['rename'] = 'Rename'; ?>
<?php if (PrivilegesHelper::confirm(Privilege::MergeTags)) $tabs['merge'] = 'Merge'; ?>
<?php if (PrivilegesHelper::confirm(Privilege::MassTag)) $tabs['mass-tag-redirect'] = 'Mass tag'; ?>
<?php
LayoutHelper::setSubTitle('tags');
LayoutHelper::addStylesheet('tag-list.css');
$tabs = [];
if (PrivilegesHelper::confirm(Privilege::ListTags)) $tabs['list'] = 'List';
if (PrivilegesHelper::confirm(Privilege::RenameTags)) $tabs['rename'] = 'Rename';
if (PrivilegesHelper::confirm(Privilege::MergeTags)) $tabs['merge'] = 'Merge';
if (PrivilegesHelper::confirm(Privilege::MassTag)) $tabs['mass-tag-redirect'] = 'Mass tag';
?>
<?php if (count(array_diff($tabs, ['list'])) > 1): ?>
<nav class="tabs">

View file

@ -1,16 +1,16 @@
<nav class="sort-styles">
<ul>
<?php
$sortStyles =
[
'order:alpha,asc' => 'Sort A&rarr;Z',
'order:alpha,desc' => 'Sort Z&rarr;A',
'order:popularity,desc' => 'Often used first',
'order:popularity,asc' => 'Rarely used first',
];
$sortStyles =
[
'order:alpha,asc' => 'Sort A&rarr;Z',
'order:alpha,desc' => 'Sort Z&rarr;A',
'order:popularity,desc' => 'Often used first',
'order:popularity,asc' => 'Rarely used first',
];
if ($this->config->registration->staffActivation)
$sortStyles['pending'] = 'Pending staff review';
if ($this->config->registration->staffActivation)
$sortStyles['pending'] = 'Pending staff review';
?>
<?php foreach ($sortStyles as $key => $text): ?>

View file

@ -1,112 +1,112 @@
<ul class="main-nav">
<?php
$nav = [];
$nav = [];
if ($this->context->route)
{
$activeController = $this->context->route->simpleControllerName;
$activeAction = $this->context->route->simpleActionName;
}
else
{
$activeController = null;
$activeAction = null;
}
if ($this->context->route)
{
$activeController = $this->context->route->simpleControllerName;
$activeAction = $this->context->route->simpleActionName;
}
else
{
$activeController = null;
$activeAction = null;
}
$registerNavItem = function ($text, $link, $active = false) use (&$nav)
{
$nav []= [
'text' => $text,
'link' => $link,
'active' => $active];
};
$registerNavItem = function ($text, $link, $active = false) use (&$nav)
{
$nav []= [
'text' => $text,
'link' => $link,
'active' => $active];
};
$registerNavItem(
'Home',
\Chibi\UrlHelper::route('index', 'index'),
$activeController == 'index' and $activeAction == 'index');
if (PrivilegesHelper::confirm(Privilege::ListPosts))
{
$registerNavItem(
'Browse',
\Chibi\UrlHelper::route('post', 'list'),
$activeController == 'post' and $activeAction != 'upload');
}
if (PrivilegesHelper::confirm(Privilege::UploadPost))
{
$registerNavItem(
'Upload',
\Chibi\UrlHelper::route('post', 'upload'),
$activeController == 'post' and $activeAction == 'upload');
}
if (PrivilegesHelper::confirm(Privilege::ListComments))
{
$registerNavItem(
'Comments',
\Chibi\UrlHelper::route('comment', 'list'),
$activeController == 'comment');
}
if (PrivilegesHelper::confirm(Privilege::ListTags))
{
$registerNavItem(
'Tags',
\Chibi\UrlHelper::route('tag', 'list'),
$activeController == 'tag');
}
if (PrivilegesHelper::confirm(Privilege::ListUsers))
{
$registerNavItem(
'Users',
\Chibi\UrlHelper::route('user', 'list'),
$activeController == 'user' and $activeAction != 'registration' and (!isset($this->context->route->arguments['name']) or $this->context->route->arguments['name'] != $this->context->user->name));
}
if (!$this->context->loggedIn)
{
$registerNavItem(
'Log in',
\Chibi\UrlHelper::route('auth', 'login'),
$activeController == 'auth' and $activeAction == 'login');
$registerNavItem(
'Home',
\Chibi\UrlHelper::route('index', 'index'),
$activeController == 'index' and $activeAction == 'index');
'Register',
\Chibi\UrlHelper::route('user', 'registration'),
$activeController == 'user' and $activeAction == 'registration');
}
else
{
$registerNavItem(
'My account',
\Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->user->name]),
$activeController == 'user' and isset($this->context->route->arguments['name']) and $this->context->route->arguments['name'] == $this->context->user->name);
if (PrivilegesHelper::confirm(Privilege::ListPosts))
{
$registerNavItem(
'Browse',
\Chibi\UrlHelper::route('post', 'list'),
$activeController == 'post' and $activeAction != 'upload');
}
$registerNavItem(
'Log out',
\Chibi\UrlHelper::route('auth', 'logout'));
}
if (PrivilegesHelper::confirm(Privilege::UploadPost))
{
$registerNavItem(
'Upload',
\Chibi\UrlHelper::route('post', 'upload'),
$activeController == 'post' and $activeAction == 'upload');
}
if (!empty($this->config->help->title))
{
$registerNavItem(
$this->config->help->title,
\Chibi\UrlHelper::route('index', 'help'),
$activeController == 'index' and $activeAction == 'help');
}
if (PrivilegesHelper::confirm(Privilege::ListComments))
{
$registerNavItem(
'Comments',
\Chibi\UrlHelper::route('comment', 'list'),
$activeController == 'comment');
}
if (PrivilegesHelper::confirm(Privilege::ListTags))
{
$registerNavItem(
'Tags',
\Chibi\UrlHelper::route('tag', 'list'),
$activeController == 'tag');
}
if (PrivilegesHelper::confirm(Privilege::ListUsers))
{
$registerNavItem(
'Users',
\Chibi\UrlHelper::route('user', 'list'),
$activeController == 'user' and $activeAction != 'registration' and (!isset($this->context->route->arguments['name']) or $this->context->route->arguments['name'] != $this->context->user->name));
}
if (!$this->context->loggedIn)
{
$registerNavItem(
'Log in',
\Chibi\UrlHelper::route('auth', 'login'),
$activeController == 'auth' and $activeAction == 'login');
$registerNavItem(
'Register',
\Chibi\UrlHelper::route('user', 'registration'),
$activeController == 'user' and $activeAction == 'registration');
}
else
{
$registerNavItem(
'My account',
\Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->user->name]),
$activeController == 'user' and isset($this->context->route->arguments['name']) and $this->context->route->arguments['name'] == $this->context->user->name);
$registerNavItem(
'Log out',
\Chibi\UrlHelper::route('auth', 'logout'));
}
if (!empty($this->config->help->title))
{
$registerNavItem(
$this->config->help->title,
\Chibi\UrlHelper::route('index', 'help'),
$activeController == 'index' and $activeAction == 'help');
}
foreach ($nav as $navItem)
{
extract($navItem);
echo TextHelper::htmlTag('li', TextHelper::HTML_OPEN, ['class' => rtrim('main-nav-item ' . ($active ? 'active' : ''))]);
echo TextHelper::htmlTag('a', TextHelper::HTML_OPEN, ['href' => $link]);
echo $text;
echo TextHelper::htmlTag('a', textHelper::HTML_CLOSE);
echo TextHelper::htmlTag('li', textHelper::HTML_CLOSE);
}
foreach ($nav as $navItem)
{
extract($navItem);
echo TextHelper::htmlTag('li', TextHelper::HTML_OPEN, ['class' => rtrim('main-nav-item ' . ($active ? 'active' : ''))]);
echo TextHelper::htmlTag('a', TextHelper::HTML_OPEN, ['href' => $link]);
echo $text;
echo TextHelper::htmlTag('a', textHelper::HTML_CLOSE);
echo TextHelper::htmlTag('li', textHelper::HTML_CLOSE);
}
?>
<?php if (PrivilegesHelper::confirm(Privilege::ChangeUserSettings, PrivilegesHelper::getIdentitySubPrivilege($this->context->user))): ?>

View file

@ -1,16 +1,24 @@
<?php
LayoutHelper::setSubTitle('users');
LayoutHelper::addStylesheet('user-list.css');
LayoutHelper::addStylesheet('paginator.css');
if ($this->context->user->hasEnabledEndlessScrolling())
LayoutHelper::addScript('paginator-endless.js');
?>
<nav class="sort-styles">
<ul>
<?php
$sortStyles =
[
'alpha,asc' => 'Sort A&rarr;Z',
'alpha,desc' => 'Sort Z&rarr;A',
'date,asc' => 'Sort old&rarr;new',
'date,desc' => 'Sort new&rarr;old',
];
$sortStyles =
[
'alpha,asc' => 'Sort A&rarr;Z',
'alpha,desc' => 'Sort Z&rarr;A',
'date,asc' => 'Sort old&rarr;new',
'date,desc' => 'Sort new&rarr;old',
];
if ($this->config->registration->staffActivation)
$sortStyles['pending'] = 'Pending staff review';
if ($this->config->registration->staffActivation)
$sortStyles['pending'] = 'Pending staff review';
?>
<?php foreach ($sortStyles as $key => $text): ?>

View file

@ -1,6 +1,14 @@
<?php
LayoutHelper::setSubTitle('registration form');
?>
<?php if ($this->context->transport->success === true): ?>
<?php $this->renderFile('message') ?>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('auth.css');
?>
<form action="<?php echo \Chibi\UrlHelper::route('auth', 'register') ?>" class="auth aligned" method="post">
<div>
<p>Registered users can view more content,<br/>upload files and add posts to favorites.</p>

View file

@ -1,6 +1,10 @@
<?php if ($this->context->transport->success === true): ?>
<?php $this->renderFile('message') ?>
<?php else: ?>
<?php
LayoutHelper::addStylesheet('auth.css');
?>
<form action="<?php echo \Chibi\UrlHelper::route($this->context->route->simpleControllerName, $this->context->route->simpleActionName) ?>" method="post" class="auth aligned" autocomplete="off">
<div>
<label class="left">User:</label>

View file

@ -1,3 +1,8 @@
<?php
LayoutHelper::setSubTitle($this->context->transport->user->name);
LayoutHelper::addStylesheet('user-view.css');
?>
<div id="sidebar">
<div class="avatar-wrapper">
<a href="<?php echo \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->transport->user->name]) ?>">