Newest chibi-core

This commit is contained in:
Marcin Kurczewski 2014-04-29 21:35:29 +02:00
parent ef4fd57927
commit 81e43286b5
60 changed files with 762 additions and 849 deletions

View file

@ -1,6 +1,6 @@
<?php <?php
require_once 'src/core.php'; require_once 'src/core.php';
$config = \Chibi\Registry::getConfig(); $config = getConfig();
$fontsPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'fonts'); $fontsPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'fonts');
$libPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'lib'); $libPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'lib');

@ -1 +1 @@
Subproject commit 32f3c0418d758a693fe09170baa8043c38fe8cb8 Subproject commit 45c662d0a4b32e09399b5b68ac53aaa3f1a29911

View file

@ -1,5 +1,198 @@
<?php <?php
require_once '../src/core.php'; require_once '../src/core.php';
$query = $_SERVER['REQUEST_URI']; $query = rtrim($_SERVER['REQUEST_URI'], '/');
\Chibi\Facade::run($query, new Bootstrap());
//prepare context
$context = new StdClass;
$context->startTime = $startTime;
$context->query = $query;
function renderView()
{
$context = getContext();
\Chibi\View::render($context->layoutName, $context);
}
function getContext()
{
global $context;
return $context;
}
$context->simpleControllerName = null;
$context->simpleActionName = null;
\Chibi\Router::setObserver(function($route, $args)
{
$context = getContext();
$context->route = $route;
list ($className, $methodName) = $route->destination;
$context->simpleControllerName = TextCaseConverter::convert(
str_replace('Controller', '', $className),
TextCaseConverter::CAMEL_CASE,
TextCaseConverter::SPINAL_CASE);
$context->simpleActionName = TextCaseConverter::convert(
str_replace('Action', '', $methodName),
TextCaseConverter::CAMEL_CASE,
TextCaseConverter::SPINAL_CASE);
$context->viewName = sprintf(
'%s-%s',
$context->simpleControllerName,
$context->simpleActionName);
});
foreach (['GET', 'POST'] as $method)
{
\Chibi\Router::register(['IndexController', 'indexAction'], $method, '');
\Chibi\Router::register(['IndexController', 'indexAction'], $method, '/index');
\Chibi\Router::register(['IndexController', 'helpAction'], $method, '/help');
\Chibi\Router::register(['IndexController', 'helpAction'], $method, '/help/{tab}');
\Chibi\Router::register(['LogController', 'listAction'], $method, '/logs');
\Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}', ['name' => '[0-9a-zA-Z._-]+']);
\Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}/{page}', ['name' => '[0-9a-zA-Z._-]+', 'page' => '\d*']);
\Chibi\Router::register(['LogController', 'viewAction'], $method, '/log/{name}/{page}/{filter}', ['name' => '[0-9a-zA-Z._-]+', 'page' => '\d*', 'filter' => '.*']);
\Chibi\Router::register(['AuthController', 'loginAction'], $method, '/auth/login');
\Chibi\Router::register(['AuthController', 'logoutAction'], $method, '/auth/logout');
\Chibi\Router::register(['AuthController', 'loginAction'], 'POST', '/auth/login');
\Chibi\Router::register(['AuthController', 'logoutAction'], 'POST', '/auth/logout');
\Chibi\Router::register(['CommentController', 'listAction'], $method, '/comments');
\Chibi\Router::register(['CommentController', 'listAction'], $method, '/comments/{page}', ['page' => '\d+']);
\Chibi\Router::register(['CommentController', 'addAction'], $method, '/post/{postId}/add-comment', ['postId' => '\d+']);
\Chibi\Router::register(['CommentController', 'deleteAction'], $method, '/comment/{id}/delete', ['id' => '\d+']);
\Chibi\Router::register(['CommentController', 'editAction'], $method, '/comment/{id}/edit', ['id' => '\d+']);
$postValidation =
[
'tag' => '[^\/]*',
'enable' => '0|1',
'source' => 'posts|mass-tag',
'query' => '[^\/]*',
'additionalInfo' => '[^\/]*',
'score' => '-1|0|1',
];
\Chibi\Router::register(['PostController', 'uploadAction'], $method, '/posts/upload', $postValidation);
\Chibi\Router::register(['PostController', 'listAction'], $method, '/{source}', $postValidation);
\Chibi\Router::register(['PostController', 'listAction'], $method, '/{source}/{query}', $postValidation);
\Chibi\Router::register(['PostController', 'listAction'], $method, '/{source}/{query}/{page}', $postValidation);
\Chibi\Router::register(['PostController', 'listAction'], $method, '/{source}/{additionalInfo}/{query}/{page}', $postValidation);
\Chibi\Router::register(['PostController', 'toggleTagAction'], $method, '/post/{id}/toggle-tag/{tag}/{enable}', $postValidation);
\Chibi\Router::register(['PostController', 'favoritesAction'], $method, '/favorites', $postValidation);
\Chibi\Router::register(['PostController', 'favoritesAction'], $method, '/favorites/{page}', $postValidation);
\Chibi\Router::register(['PostController', 'upvotedAction'], $method, '/upvoted', $postValidation);
\Chibi\Router::register(['PostController', 'upvotedAction'], $method, '/upvoted/{page}', $postValidation);
\Chibi\Router::register(['PostController', 'randomAction'], $method, '/random', $postValidation);
\Chibi\Router::register(['PostController', 'randomAction'], $method, '/random/{page}', $postValidation);
\Chibi\Router::register(['PostController', 'viewAction'], $method, '/post/{id}', $postValidation);
\Chibi\Router::register(['PostController', 'retrieveAction'], $method, '/post/{name}/retrieve', $postValidation);
\Chibi\Router::register(['PostController', 'thumbAction'], $method, '/post/{name}/thumb', $postValidation);
\Chibi\Router::register(['PostController', 'removeFavoriteAction'], $method, '/post/{id}/rem-fav', $postValidation);
\Chibi\Router::register(['PostController', 'addFavoriteAction'], $method, '/post/{id}/add-fav', $postValidation);
\Chibi\Router::register(['PostController', 'deleteAction'], $method, '/post/{id}/delete', $postValidation);
\Chibi\Router::register(['PostController', 'hideAction'], $method, '/post/{id}/hide', $postValidation);
\Chibi\Router::register(['PostController', 'unhideAction'], $method, '/post/{id}/unhide', $postValidation);
\Chibi\Router::register(['PostController', 'editAction'], $method, '/post/{id}/edit', $postValidation);
\Chibi\Router::register(['PostController', 'flagAction'], $method, '/post/{id}/flag', $postValidation);
\Chibi\Router::register(['PostController', 'featureAction'], $method, '/post/{id}/feature', $postValidation);
\Chibi\Router::register(['PostController', 'scoreAction'], $method, '/post/{id}/score/{score}', $postValidation);
$tagValidation =
[
'page' => '\d*',
'filter' => '[^\/]+',
];
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags', $tagValidation);
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags/{filter}', $tagValidation);
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags/{page}', $tagValidation);
\Chibi\Router::register(['TagController', 'listAction'], $method, '/tags/{filter}/{page}', $tagValidation);
\Chibi\Router::register(['TagController', 'autoCompleteAction'], $method, '/tags-autocomplete', $tagValidation);
\Chibi\Router::register(['TagController', 'relatedAction'], $method, '/tags-related', $tagValidation);
\Chibi\Router::register(['TagController', 'mergeAction'], $method, '/tags-merge', $tagValidation);
\Chibi\Router::register(['TagController', 'renameAction'], $method, '/tags-rename', $tagValidation);
\Chibi\Router::register(['TagController', 'massTagRedirectAction'], $method, '/mass-tag-redirect', $tagValidation);
$userValidations =
[
'name' => '[^\/]+',
'page' => '\d*',
'tab' => 'favs|uploads',
'filter' => '[^\/]+',
];
\Chibi\Router::register(['UserController', 'registrationAction'], $method, '/register', $userValidations);
\Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}', $userValidations);
\Chibi\Router::register(['UserController', 'viewAction'], $method, '/user/{name}/{tab}/{page}', $userValidations);
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users', $userValidations);
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users/{page}', $userValidations);
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users/{filter}', $userValidations);
\Chibi\Router::register(['UserController', 'listAction'], $method, '/users/{filter}/{page}', $userValidations);
\Chibi\Router::register(['UserController', 'flagAction'], $method, '/user/{name}/flag', $userValidations);
\Chibi\Router::register(['UserController', 'banAction'], $method, '/user/{name}/ban', $userValidations);
\Chibi\Router::register(['UserController', 'unbanAction'], $method, '/user/{name}/unban', $userValidations);
\Chibi\Router::register(['UserController', 'acceptRegistrationAction'], $method, '/user/{name}/accept-registration', $userValidations);
\Chibi\Router::register(['UserController', 'deleteAction'], $method, '/user/{name}/delete', $userValidations);
\Chibi\Router::register(['UserController', 'settingsAction'], $method, '/user/{name}/settings', $userValidations);
\Chibi\Router::register(['UserController', 'editAction'], $method, '/user/{name}/edit', $userValidations);
\Chibi\Router::register(['UserController', 'activationAction'], $method, '/activation/{token}', $userValidations);
\Chibi\Router::register(['UserController', 'activationProxyAction'], $method, '/activation-proxy/{token}', $userValidations);
\Chibi\Router::register(['UserController', 'passwordResetAction'], $method, '/password-reset/{token}', $userValidations);
\Chibi\Router::register(['UserController', 'passwordResetProxyAction'], $method, '/password-reset-proxy/{token}', $userValidations);
\Chibi\Router::register(['UserController', 'toggleSafetyAction'], $method, '/user/toggle-safety/{safety}', $userValidations);
}
Assets::setTitle($config->main->title);
$context->handleExceptions = false;
$context->json = isset($_GET['json']);
$context->layoutName = $context->json
? 'layout-json'
: 'layout-normal';
$context->viewName = '';
$context->transport = new StdClass;
StatusHelper::init();
session_start();
AuthController::doLogIn();
try
{
try
{
\Chibi\Router::run($query);
renderView();
AuthController::observeWorkFinish();
}
catch (\Chibi\UnhandledRouteException $e)
{
throw new SimpleNotFoundException($query . ' not found.');
}
}
catch (\Chibi\MissingViewFileException $e)
{
$context->json = true;
$context->layoutName = 'layout-json';
renderView();
}
catch (SimpleException $e)
{
if ($e instanceof SimpleNotFoundException)
\Chibi\Util\Headers::setCode(404);
StatusHelper::failure($e->getMessage());
if (!$context->handleExceptions)
$context->viewName = 'message';
renderView();
}
catch (Exception $e)
{
\Chibi\Util\Headers::setCode(400);
StatusHelper::failure($e->getMessage());
$context->transport->exception = $e;
$context->transport->queries = \Chibi\Database::getLogs();
$context->viewName = 'error-exception';
renderView();
}

View file

@ -59,7 +59,7 @@ foreach (R::findAll('post') as $post)
} }
$names = array_flip($names); $names = array_flip($names);
$config = \Chibi\Registry::getConfig(); $config = getConfig();
foreach (glob(TextHelper::absolutePath($config->main->filesPath) . DS . '*') as $name) foreach (glob(TextHelper::absolutePath($config->main->filesPath) . DS . '*') as $name)
{ {
$name = basename($name); $name = basename($name);

View file

@ -1,70 +0,0 @@
<?php
use \Chibi\Database as Database;
class Bootstrap
{
public function render($callback = null)
{
if ($callback !== null)
$callback();
else
(new \Chibi\View())->renderFile($this->context->layoutName);
}
public function workWrapper($workCallback)
{
$this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/';
$this->context->viewDecorators []= new CustomAssetViewDecorator();
$this->context->viewDecorators []= new \Chibi\PrettyPrintViewDecorator();
CustomAssetViewDecorator::setTitle($this->config->main->title);
$this->context->handleExceptions = false;
$this->context->json = isset($_GET['json']);
$this->context->layoutName = $this->context->json
? 'layout-json'
: 'layout-normal';
$this->context->transport = new StdClass;
StatusHelper::init();
session_start();
AuthController::doLogIn();
if (empty($this->context->route))
{
http_response_code(404);
$this->context->viewName = 'error-404';
$this->render();
return;
}
try
{
$this->render($workCallback);
}
catch (\Chibi\MissingViewFileException $e)
{
$this->context->json = true;
$this->context->layoutName = 'layout-json';
$this->render();
}
catch (SimpleException $e)
{
if ($e instanceof SimpleNotFoundException)
http_response_code(404);
StatusHelper::failure($e->getMessage());
if (!$this->context->handleExceptions)
$this->context->viewName = 'message';
$this->render();
}
catch (Exception $e)
{
StatusHelper::failure($e->getMessage());
$this->context->transport->exception = $e;
$this->context->transport->queries = Database::getLogs();
$this->context->viewName = 'error-exception';
$this->render();
}
AuthController::observeWorkFinish();
}
}

View file

@ -5,17 +5,17 @@ class AuthController
{ {
if (isset($_SESSION['login-redirect-url'])) if (isset($_SESSION['login-redirect-url']))
{ {
\Chibi\UrlHelper::forward($_SESSION['login-redirect-url']); \Chibi\Util\Url::forward(\Chibi\Util\Url::makeAbsolute($_SESSION['login-redirect-url']));
unset($_SESSION['login-redirect-url']); unset($_SESSION['login-redirect-url']);
return; return;
} }
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); \Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
} }
public static function tryLogin($name, $password) public static function tryLogin($name, $password)
{ {
$config = \Chibi\Registry::getConfig(); $config = getConfig();
$context = \Chibi\Registry::getContext(); $context = getContext();
$dbUser = UserModel::findByNameOrEmail($name, false); $dbUser = UserModel::findByNameOrEmail($name, false);
if ($dbUser === null) if ($dbUser === null)
@ -49,15 +49,13 @@ class AuthController
return self::tryLogin($name, $password); return self::tryLogin($name, $password);
} }
/**
* @route /auth/login
*/
public function loginAction() public function loginAction()
{ {
$this->context->handleExceptions = true; $context = getContext();
$context->handleExceptions = true;
//check if already logged in //check if already logged in
if ($this->context->loggedIn) if ($context->loggedIn)
{ {
self::redirectAfterLog(); self::redirectAfterLog();
return; return;
@ -79,16 +77,14 @@ class AuthController
} }
} }
/**
* @route /auth/logout
*/
public function logoutAction() public function logoutAction()
{ {
$this->context->viewName = null; $context = getContext();
$this->context->layoutName = null; $context->viewName = null;
$context->layoutName = null;
self::doLogOut(); self::doLogOut();
setcookie('auth', false, 0, '/'); setcookie('auth', false, 0, '/');
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); \Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
} }
public static function doLogOut() public static function doLogOut()
@ -98,7 +94,7 @@ class AuthController
public static function doLogIn() public static function doLogIn()
{ {
$context = \Chibi\Registry::getContext(); $context = getContext();
if (!isset($_SESSION['user'])) if (!isset($_SESSION['user']))
{ {
if (!empty($context->user) and $context->user->id) if (!empty($context->user) and $context->user->id)
@ -133,7 +129,7 @@ class AuthController
public static function doReLog() public static function doReLog()
{ {
$context = \Chibi\Registry::getContext(); $context = getContext();
if ($context->user !== null) if ($context->user !== null)
self::doLogOut(); self::doLogOut();
self::doLogIn(); self::doLogIn();
@ -141,10 +137,12 @@ class AuthController
public static function observeWorkFinish() public static function observeWorkFinish()
{ {
if (strpos(\Chibi\HeadersHelper::get('Content-Type'), 'text/html') === false) if (strpos(\Chibi\Util\Headers::get('Content-Type'), 'text/html') === false)
return; return;
$context = \Chibi\Registry::getContext(); if (\Chibi\Util\Headers::getCode() != 200)
if ($context->route->simpleControllerName == 'auth') return;
$context = getContext();
if ($context->simpleControllerName == 'auth')
return; return;
$_SESSION['login-redirect-url'] = $context->query; $_SESSION['login-redirect-url'] = $context->query;
} }

View file

@ -1,17 +1,12 @@
<?php <?php
class CommentController class CommentController
{ {
/**
* @route /comments
* @route /comments/{page}
* @validate page [0-9]+
*/
public function listAction($page) public function listAction($page)
{ {
PrivilegesHelper::confirmWithException(Privilege::ListComments); PrivilegesHelper::confirmWithException(Privilege::ListComments);
$page = max(1, intval($page)); $page = max(1, intval($page));
$commentsPerPage = intval($this->config->comments->commentsPerPage); $commentsPerPage = intval(getConfig()->comments->commentsPerPage);
$searchQuery = 'comment_min:1 order:comment_date,desc'; $searchQuery = 'comment_min:1 order:comment_date,desc';
$posts = PostSearchService::getEntities($searchQuery, $commentsPerPage, $page); $posts = PostSearchService::getEntities($searchQuery, $commentsPerPage, $page);
@ -24,30 +19,26 @@ class CommentController
$comments = array_merge($comments, $post->getComments()); $comments = array_merge($comments, $post->getComments());
CommentModel::preloadCommenters($comments); CommentModel::preloadCommenters($comments);
$this->context->postGroups = true; $context = getContext();
$this->context->transport->posts = $posts; $context->postGroups = true;
$this->context->transport->paginator = new StdClass; $context->transport->posts = $posts;
$this->context->transport->paginator->page = $page; $context->transport->paginator = new StdClass;
$this->context->transport->paginator->pageCount = $pageCount; $context->transport->paginator->page = $page;
$this->context->transport->paginator->entityCount = $postCount; $context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entities = $posts; $context->transport->paginator->entityCount = $postCount;
$this->context->transport->paginator->params = func_get_args(); $context->transport->paginator->entities = $posts;
$context->transport->paginator->params = func_get_args();
} }
/**
* @route /post/{postId}/add-comment
* @valdiate postId [0-9]+
*/
public function addAction($postId) public function addAction($postId)
{ {
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::AddComment); PrivilegesHelper::confirmWithException(Privilege::AddComment);
if ($this->config->registration->needEmailForCommenting) if (getConfig()->registration->needEmailForCommenting)
PrivilegesHelper::confirmEmail($this->context->user); PrivilegesHelper::confirmEmail($context->user);
$post = PostModel::findById($postId); $post = PostModel::findById($postId);
$this->context->transport->post = $post; $context->transport->post = $post;
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -56,8 +47,8 @@ class CommentController
$comment = CommentModel::spawn(); $comment = CommentModel::spawn();
$comment->setPost($post); $comment->setPost($post);
if ($this->context->loggedIn) if ($context->loggedIn)
$comment->setCommenter($this->context->user); $comment->setCommenter($context->user);
else else
$comment->setCommenter(null); $comment->setCommenter(null);
$comment->commentDate = time(); $comment->commentDate = time();
@ -68,21 +59,16 @@ class CommentController
CommentModel::save($comment); CommentModel::save($comment);
LogHelper::log('{user} commented on {post}', ['post' => TextHelper::reprPost($post->id)]); LogHelper::log('{user} commented on {post}', ['post' => TextHelper::reprPost($post->id)]);
} }
$this->context->transport->textPreview = $comment->getText(); $context->transport->textPreview = $comment->getText();
StatusHelper::success(); StatusHelper::success();
} }
} }
/**
* @route /comment/{id}/edit
* @validate id [0-9]+
*/
public function editAction($id) public function editAction($id)
{ {
$context = getContext();
$comment = CommentModel::findById($id); $comment = CommentModel::findById($id);
$this->context->transport->comment = $comment; $context->transport->comment = $comment;
PrivilegesHelper::confirmWithException( PrivilegesHelper::confirmWithException(
Privilege::EditComment, Privilege::EditComment,
@ -100,17 +86,11 @@ class CommentController
CommentModel::save($comment); CommentModel::save($comment);
LogHelper::log('{user} edited comment in {post}', ['post' => TextHelper::reprPost($comment->getPost())]); LogHelper::log('{user} edited comment in {post}', ['post' => TextHelper::reprPost($comment->getPost())]);
} }
$this->context->transport->textPreview = $comment->getText(); $context->transport->textPreview = $comment->getText();
StatusHelper::success(); StatusHelper::success();
} }
} }
/**
* @route /comment/{id}/delete
* @validate id [0-9]+
*/
public function deleteAction($id) public function deleteAction($id)
{ {
$comment = CommentModel::findById($id); $comment = CommentModel::findById($id);

View file

@ -1,43 +1,39 @@
<?php <?php
class IndexController class IndexController
{ {
/**
* @route /
* @route /index
*/
public function indexAction() public function indexAction()
{ {
$this->context->transport->postCount = PostModel::getCount(); $context = getContext();
$context->transport->postCount = PostModel::getCount();
$featuredPost = $this->getFeaturedPost(); $featuredPost = $this->getFeaturedPost();
if ($featuredPost) if ($featuredPost)
{ {
$this->context->featuredPost = $featuredPost; $context->featuredPost = $featuredPost;
$this->context->featuredPostDate = PropertyModel::get(PropertyModel::FeaturedPostDate); $context->featuredPostDate = PropertyModel::get(PropertyModel::FeaturedPostDate);
$this->context->featuredPostUser = UserModel::findByNameOrEmail( $context->featuredPostUser = UserModel::findByNameOrEmail(
PropertyModel::get(PropertyModel::FeaturedPostUserName), PropertyModel::get(PropertyModel::FeaturedPostUserName),
false); false);
} }
} }
/**
* @route /help
* @route /help/{tab}
*/
public function helpAction($tab = null) public function helpAction($tab = null)
{ {
if (empty($this->config->help->paths) or empty($this->config->help->title)) $config = getConfig();
$context = getContext();
if (empty($config->help->paths) or empty($config->help->title))
throw new SimpleException('Help is disabled'); throw new SimpleException('Help is disabled');
$tab = $tab ?: array_keys($this->config->help->subTitles)[0]; $tab = $tab ?: array_keys($config->help->subTitles)[0];
if (!isset($this->config->help->paths[$tab])) if (!isset($config->help->paths[$tab]))
throw new SimpleException('Invalid tab'); throw new SimpleException('Invalid tab');
$this->context->path = TextHelper::absolutePath($this->config->help->paths[$tab]); $context->path = TextHelper::absolutePath($config->help->paths[$tab]);
$this->context->tab = $tab; $context->tab = $tab;
} }
private function getFeaturedPost() private function getFeaturedPost()
{ {
$featuredPostRotationTime = $this->config->misc->featuredPostMaxDays * 24 * 3600; $config = getConfig();
$featuredPostRotationTime = $config->misc->featuredPostMaxDays * 24 * 3600;
$featuredPostId = PropertyModel::get(PropertyModel::FeaturedPostId); $featuredPostId = PropertyModel::get(PropertyModel::FeaturedPostId);
$featuredPostDate = PropertyModel::get(PropertyModel::FeaturedPostDate); $featuredPostDate = PropertyModel::get(PropertyModel::FeaturedPostDate);

View file

@ -1,14 +1,12 @@
<?php <?php
class LogController class LogController
{ {
/**
* @route /logs
*/
public function listAction() public function listAction()
{ {
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListLogs); PrivilegesHelper::confirmWithException(Privilege::ListLogs);
$path = TextHelper::absolutePath($this->config->main->logsPath); $path = TextHelper::absolutePath(getConfig()->main->logsPath);
$logs = []; $logs = [];
foreach (glob($path . DS . '*.log') as $log) foreach (glob($path . DS . '*.log') as $log)
@ -19,27 +17,19 @@ class LogController
return strnatcasecmp($b, $a); //reverse natcasesort return strnatcasecmp($b, $a); //reverse natcasesort
}); });
$this->context->transport->logs = $logs; $context->transport->logs = $logs;
} }
/**
* @route /log/{name}
* @route /log/{name}/{page}
* @route /log/{name}/{page}/{filter}
* @validate name [0-9a-zA-Z._-]+
* @validate page \d*
* @validate filter .*
*/
public function viewAction($name, $page = 1, $filter = '') public function viewAction($name, $page = 1, $filter = '')
{ {
$context = getContext();
//redirect requests in form of ?query=... to canonical address //redirect requests in form of ?query=... to canonical address
$formQuery = InputHelper::get('query'); $formQuery = InputHelper::get('query');
if ($formQuery !== null) if ($formQuery !== null)
{ {
\Chibi\UrlHelper::forward( \Chibi\Util\Url::forward(
\Chibi\UrlHelper::route( \Chibi\Router::linkTo(
'log', ['LogController', 'viewAction'],
'view',
[ [
'name' => $name, 'name' => $name,
'filter' => $formQuery, 'filter' => $formQuery,
@ -53,7 +43,7 @@ class LogController
//parse input //parse input
$page = max(1, intval($page)); $page = max(1, intval($page));
$name = str_replace(['/', '\\'], '', $name); //paranoia mode $name = str_replace(['/', '\\'], '', $name); //paranoia mode
$path = TextHelper::absolutePath($this->config->main->logsPath . DS . $name); $path = TextHelper::absolutePath(getConfig()->main->logsPath . DS . $name);
if (!file_exists($path)) if (!file_exists($path))
throw new SimpleNotFoundException('Specified log doesn\'t exist'); throw new SimpleNotFoundException('Specified log doesn\'t exist');
@ -71,7 +61,7 @@ class LogController
} }
$lineCount = count($lines); $lineCount = count($lines);
$logsPerPage = intval($this->config->browsing->logsPerPage); $logsPerPage = intval(getConfig()->browsing->logsPerPage);
$pageCount = ceil($lineCount / $logsPerPage); $pageCount = ceil($lineCount / $logsPerPage);
$page = min($pageCount, $page); $page = min($pageCount, $page);
@ -87,13 +77,13 @@ class LogController
$lines = TextHelper::parseMarkdown($lines, true); $lines = TextHelper::parseMarkdown($lines, true);
$lines = trim($lines); $lines = trim($lines);
$this->context->transport->paginator = new StdClass; $context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page; $context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount; $context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $lineCount; $context->transport->paginator->entityCount = $lineCount;
$this->context->transport->paginator->entities = $lines; $context->transport->paginator->entities = $lines;
$this->context->transport->lines = $lines; $context->transport->lines = $lines;
$this->context->transport->filter = $filter; $context->transport->filter = $filter;
$this->context->transport->name = $name; $context->transport->name = $name;
} }
} }

View file

@ -36,58 +36,45 @@ class PostController
throw new SimpleException('Generic file upload error'); throw new SimpleException('Generic file upload error');
} }
/**
* @route /{source}
* @route /{source}/{page}
* @route /{source}/{query}/
* @route /{source}/{query}/{page}
* @route /{source}/{additionalInfo}/{query}/
* @route /{source}/{additionalInfo}/{query}/{page}
* @validate source posts|mass-tag
* @validate page \d*
* @validate query [^\/]*
* @validate additionalInfo [^\/]*
*/
public function listAction($query = null, $page = 1, $source = 'posts', $additionalInfo = null) public function listAction($query = null, $page = 1, $source = 'posts', $additionalInfo = null)
{ {
$this->context->viewName = 'post-list-wrapper'; $context = getContext();
$this->context->source = $source; $context->viewName = 'post-list-wrapper';
$this->context->additionalInfo = $additionalInfo; $context->source = $source;
$this->context->handleExceptions = true; $context->additionalInfo = $additionalInfo;
$context->handleExceptions = true;
//redirect requests in form of /posts/?query=... to canonical address //redirect requests in form of /posts/?query=... to canonical address
$formQuery = InputHelper::get('query'); $formQuery = InputHelper::get('query');
if ($formQuery !== null) if ($formQuery !== null)
{ {
$this->context->transport->searchQuery = $formQuery; $context->transport->searchQuery = $formQuery;
$this->context->transport->lastSearchQuery = $formQuery; $context->transport->lastSearchQuery = $formQuery;
if (strpos($formQuery, '/') !== false) if (strpos($formQuery, '/') !== false)
throw new SimpleException('Search query contains invalid characters'); throw new SimpleException('Search query contains invalid characters');
$url = \Chibi\UrlHelper::route('post', 'list', [ $url = \Chibi\Router::linkTo(['PostController', 'listAction'], [
'source' => $source, 'source' => $source,
'additionalInfo' => $additionalInfo, 'additionalInfo' => $additionalInfo,
'query' => $formQuery]); 'query' => $formQuery]);
\Chibi\UrlHelper::forward($url); \Chibi\Util\Url::forward($url);
return; return;
} }
$query = trim($query); $query = trim($query);
$page = max(1, intval($page)); $page = max(1, intval($page));
$postsPerPage = intval($this->config->browsing->postsPerPage); $postsPerPage = intval(getConfig()->browsing->postsPerPage);
$this->context->transport->searchQuery = $query; $context->transport->searchQuery = $query;
$this->context->transport->lastSearchQuery = $query; $context->transport->lastSearchQuery = $query;
PrivilegesHelper::confirmWithException(Privilege::ListPosts); PrivilegesHelper::confirmWithException(Privilege::ListPosts);
if ($source == 'mass-tag') if ($source == 'mass-tag')
{ {
PrivilegesHelper::confirmWithException(Privilege::MassTag); PrivilegesHelper::confirmWithException(Privilege::MassTag);
$this->context->massTagTag = $additionalInfo; $context->massTagTag = $additionalInfo;
$this->context->massTagQuery = $query; $context->massTagQuery = $query;
if (!PrivilegesHelper::confirm(Privilege::MassTag, 'all')) if (!PrivilegesHelper::confirm(Privilege::MassTag, 'all'))
$query = trim($query . ' submit:' . $this->context->user->name); $query = trim($query . ' submit:' . $context->user->name);
} }
$posts = PostSearchService::getEntities($query, $postsPerPage, $page); $posts = PostSearchService::getEntities($query, $postsPerPage, $page);
@ -96,26 +83,20 @@ class PostController
$page = min($pageCount, $page); $page = min($pageCount, $page);
PostModel::preloadTags($posts); PostModel::preloadTags($posts);
$this->context->transport->paginator = new StdClass; $context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page; $context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount; $context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $postCount; $context->transport->paginator->entityCount = $postCount;
$this->context->transport->paginator->entities = $posts; $context->transport->paginator->entities = $posts;
$this->context->transport->posts = $posts; $context->transport->posts = $posts;
} }
/**
* @route /post/{id}/toggle-tag/{tag}/{enable}
* @validate tag [^\/]*
* @validate enable 0|1
*/
public function toggleTagAction($id, $tag, $enable) public function toggleTagAction($id, $tag, $enable)
{ {
$context = getContext();
$tagName = $tag; $tagName = $tag;
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
$this->context->transport->post = $post; $context->transport->post = $post;
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -158,60 +139,39 @@ class PostController
} }
} }
/**
* @route /favorites
* @route /favorites/{page}
* @validate page \d*
*/
public function favoritesAction($page = 1) public function favoritesAction($page = 1)
{ {
$this->listAction('favmin:1', $page); $this->listAction('favmin:1', $page);
} }
/**
* @route /upvoted
* @route /upvoted/{page}
* @validate page \d*
*/
public function upvotedAction($page = 1) public function upvotedAction($page = 1)
{ {
$this->listAction('scoremin:1', $page); $this->listAction('scoremin:1', $page);
} }
/**
* @route /random
* @route /random/{page}
* @validate page \d*
*/
public function randomAction($page = 1) public function randomAction($page = 1)
{ {
$this->listAction('order:random', $page); $this->listAction('order:random', $page);
} }
/**
* @route /post/upload
*/
public function uploadAction() public function uploadAction()
{ {
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::UploadPost); PrivilegesHelper::confirmWithException(Privilege::UploadPost);
if ($this->config->registration->needEmailForUploading) if (getConfig()->registration->needEmailForUploading)
PrivilegesHelper::confirmEmail($this->context->user); PrivilegesHelper::confirmEmail($context->user);
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
\Chibi\Database::transaction(function() \Chibi\Database::transaction(function() use ($context)
{ {
$post = PostModel::spawn(); $post = PostModel::spawn();
LogHelper::bufferChanges(); LogHelper::bufferChanges();
//basic stuff //basic stuff
$anonymous = InputHelper::get('anonymous'); $anonymous = InputHelper::get('anonymous');
if ($this->context->loggedIn and !$anonymous) if ($context->loggedIn and !$anonymous)
$post->setUploader($this->context->user); $post->setUploader($context->user);
//store the post to get the ID in the logs //store the post to get the ID in the logs
PostModel::forgeId($post); PostModel::forgeId($post);
@ -227,7 +187,7 @@ class PostController
LogHelper::setBuffer([]); LogHelper::setBuffer([]);
//log //log
$fmt = ($anonymous and !$this->config->misc->logAnonymousUploads) $fmt = ($anonymous and !getConfig()->misc->logAnonymousUploads)
? '{anon}' ? '{anon}'
: '{user}'; : '{user}';
$fmt .= ' added {post} (tags: {tags}, safety: {safety}, source: {source})'; $fmt .= ' added {post} (tags: {tags}, safety: {safety}, source: {source})';
@ -246,15 +206,11 @@ class PostController
} }
} }
/**
* @route /post/{id}/edit
*/
public function editAction($id) public function editAction($id)
{ {
$context = getContext();
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
$this->context->transport->post = $post; $context->transport->post = $post;
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -273,11 +229,6 @@ class PostController
} }
} }
/**
* @route /post/{id}/flag
*/
public function flagAction($id) public function flagAction($id)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
@ -298,11 +249,6 @@ class PostController
} }
} }
/**
* @route /post/{id}/hide
*/
public function hideAction($id) public function hideAction($id)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
@ -318,11 +264,6 @@ class PostController
} }
} }
/**
* @route /post/{id}/unhide
*/
public function unhideAction($id) public function unhideAction($id)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
@ -338,11 +279,6 @@ class PostController
} }
} }
/**
* @route /post/{id}/delete
*/
public function deleteAction($id) public function deleteAction($id)
{ {
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
@ -357,92 +293,70 @@ class PostController
} }
} }
/**
* @route /post/{id}/add-fav
* @route /post/{id}/fav-add
*/
public function addFavoriteAction($id) public function addFavoriteAction($id)
{ {
$context = getContext();
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
if (!$this->context->loggedIn) if (!$context->loggedIn)
throw new SimpleException('Not logged in'); throw new SimpleException('Not logged in');
UserModel::updateUserScore($this->context->user, $post, 1); UserModel::updateUserScore($context->user, $post, 1);
UserModel::addToUserFavorites($this->context->user, $post); UserModel::addToUserFavorites($context->user, $post);
StatusHelper::success(); StatusHelper::success();
} }
} }
/** public function removeFavoriteAction($id)
* @route /post/{id}/rem-fav
* @route /post/{id}/fav-rem
*/
public function remFavoriteAction($id)
{ {
$context = getContext();
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); PrivilegesHelper::confirmWithException(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
if (!$this->context->loggedIn) if (!$context->loggedIn)
throw new SimpleException('Not logged in'); throw new SimpleException('Not logged in');
UserModel::removeFromUserFavorites($this->context->user, $post); UserModel::removeFromUserFavorites($context->user, $post);
StatusHelper::success(); StatusHelper::success();
} }
} }
/**
* @route /post/{id}/score/{score}
* @validate score -1|0|1
*/
public function scoreAction($id, $score) public function scoreAction($id, $score)
{ {
$context = getContext();
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); PrivilegesHelper::confirmWithException(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
if (!$this->context->loggedIn) if (!$context->loggedIn)
throw new SimpleException('Not logged in'); throw new SimpleException('Not logged in');
UserModel::updateUserScore($this->context->user, $post, $score); UserModel::updateUserScore($context->user, $post, $score);
StatusHelper::success(); StatusHelper::success();
} }
} }
/**
* @route /post/{id}/feature
*/
public function featureAction($id) public function featureAction($id)
{ {
$context = getContext();
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
PrivilegesHelper::confirmWithException(Privilege::FeaturePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader())); PrivilegesHelper::confirmWithException(Privilege::FeaturePost, PrivilegesHelper::getIdentitySubPrivilege($post->getUploader()));
PropertyModel::set(PropertyModel::FeaturedPostId, $post->id); PropertyModel::set(PropertyModel::FeaturedPostId, $post->id);
PropertyModel::set(PropertyModel::FeaturedPostDate, time()); PropertyModel::set(PropertyModel::FeaturedPostDate, time());
PropertyModel::set(PropertyModel::FeaturedPostUserName, $this->context->user->name); PropertyModel::set(PropertyModel::FeaturedPostUserName, $context->user->name);
StatusHelper::success(); StatusHelper::success();
LogHelper::log('{user} featured {post} on main page', ['post' => TextHelper::reprPost($post)]); LogHelper::log('{user} featured {post} on main page', ['post' => TextHelper::reprPost($post)]);
} }
/**
* Action that decorates the page containing the post.
* @route /post/{id}
*/
public function viewAction($id) public function viewAction($id)
{ {
$context = getContext();
$post = PostModel::findByIdOrName($id); $post = PostModel::findByIdOrName($id);
CommentModel::preloadCommenters($post->getComments()); CommentModel::preloadCommenters($post->getComments());
@ -453,40 +367,35 @@ class PostController
try try
{ {
$this->context->transport->lastSearchQuery = InputHelper::get('last-search-query'); $context->transport->lastSearchQuery = InputHelper::get('last-search-query');
list ($prevPostId, $nextPostId) = list ($prevPostId, $nextPostId) =
PostSearchService::getPostIdsAround( PostSearchService::getPostIdsAround(
$this->context->transport->lastSearchQuery, $id); $context->transport->lastSearchQuery, $id);
} }
#search for some reason was invalid, e.g. tag was deleted in the meantime #search for some reason was invalid, e.g. tag was deleted in the meantime
catch (Exception $e) catch (Exception $e)
{ {
$this->context->transport->lastSearchQuery = ''; $context->transport->lastSearchQuery = '';
list ($prevPostId, $nextPostId) = list ($prevPostId, $nextPostId) =
PostSearchService::getPostIdsAround( PostSearchService::getPostIdsAround(
$this->context->transport->lastSearchQuery, $id); $context->transport->lastSearchQuery, $id);
} }
$favorite = $this->context->user->hasFavorited($post); $favorite = $context->user->hasFavorited($post);
$score = $this->context->user->getScore($post); $score = $context->user->getScore($post);
$flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', [])); $flagged = in_array(TextHelper::reprPost($post), SessionHelper::get('flagged', []));
$this->context->favorite = $favorite; $context->favorite = $favorite;
$this->context->score = $score; $context->score = $score;
$this->context->flagged = $flagged; $context->flagged = $flagged;
$this->context->transport->post = $post; $context->transport->post = $post;
$this->context->transport->prevPostId = $prevPostId ? $prevPostId : null; $context->transport->prevPostId = $prevPostId ? $prevPostId : null;
$this->context->transport->nextPostId = $nextPostId ? $nextPostId : null; $context->transport->nextPostId = $nextPostId ? $nextPostId : null;
} }
/**
* Action that renders the thumbnail of the requested file and sends it to user.
* @route /post/{name}/thumb
*/
public function thumbAction($name, $width = null, $height = null) public function thumbAction($name, $width = null, $height = null)
{ {
$context = getContext();
$path = PostModel::getThumbCustomPath($name, $width, $height); $path = PostModel::getThumbCustomPath($name, $width, $height);
if (!file_exists($path)) if (!file_exists($path))
{ {
@ -498,41 +407,41 @@ class PostController
PrivilegesHelper::confirmWithException(Privilege::ListPosts, PostSafety::toString($post->safety)); PrivilegesHelper::confirmWithException(Privilege::ListPosts, PostSafety::toString($post->safety));
$post->makeThumb($width, $height); $post->makeThumb($width, $height);
if (!file_exists($path)) if (!file_exists($path))
$path = TextHelper::absolutePath($this->config->main->mediaPath . DS . 'img' . DS . 'thumb.jpg'); {
$path = getConfig()->main->mediaPath . DS . 'img' . DS . 'thumb.jpg';
$path = TextHelper::absolutePath($path);
}
} }
} }
if (!is_readable($path)) if (!is_readable($path))
throw new SimpleException('Thumbnail file is not readable'); throw new SimpleException('Thumbnail file is not readable');
$this->context->layoutName = 'layout-file'; $context->layoutName = 'layout-file';
$this->context->transport->cacheDaysToLive = 365; $context->transport->cacheDaysToLive = 365;
$this->context->transport->mimeType = 'image/jpeg'; $context->transport->mimeType = 'image/jpeg';
$this->context->transport->fileHash = 'thumb' . md5($name . filemtime($path)); $context->transport->fileHash = 'thumb' . md5($name . filemtime($path));
$this->context->transport->filePath = $path; $context->transport->filePath = $path;
} }
/**
* Action that renders the requested file itself and sends it to user.
* @route /post/{name}/retrieve
*/
public function retrieveAction($name) public function retrieveAction($name)
{ {
$post = PostModel::findByName($name, true); $post = PostModel::findByName($name, true);
$config = getConfig();
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::RetrievePost); PrivilegesHelper::confirmWithException(Privilege::RetrievePost);
PrivilegesHelper::confirmWithException(Privilege::RetrievePost, PostSafety::toString($post->safety)); PrivilegesHelper::confirmWithException(Privilege::RetrievePost, PostSafety::toString($post->safety));
$path = TextHelper::absolutePath($this->config->main->filesPath . DS . $post->name); $path = $config->main->filesPath . DS . $post->name;
$path = TextHelper::absolutePath($path);
if (!file_exists($path)) if (!file_exists($path))
throw new SimpleNotFoundException('Post file does not exist'); throw new SimpleNotFoundException('Post file does not exist');
if (!is_readable($path)) if (!is_readable($path))
throw new SimpleException('Post file is not readable'); throw new SimpleException('Post file is not readable');
$fn = sprintf('%s_%s_%s.%s', $fn = sprintf('%s_%s_%s.%s',
$this->config->main->title, $config->main->title,
$post->id, $post->id,
join(',', array_map(function($tag) { return $tag->name; }, $post->getTags())), join(',', array_map(function($tag) { return $tag->name; }, $post->getTags())),
TextHelper::resolveMimeType($post->mimeType) ?: 'dat'); TextHelper::resolveMimeType($post->mimeType) ?: 'dat');
@ -540,12 +449,12 @@ class PostController
$ttl = 60 * 60 * 24 * 14; $ttl = 60 * 60 * 24 * 14;
$this->context->layoutName = 'layout-file'; $context->layoutName = 'layout-file';
$this->context->transport->cacheDaysToLive = 14; $context->transport->cacheDaysToLive = 14;
$this->context->transport->customFileName = $fn; $context->transport->customFileName = $fn;
$this->context->transport->mimeType = $post->mimeType; $context->transport->mimeType = $post->mimeType;
$this->context->transport->fileHash = 'post' . $post->fileHash; $context->transport->fileHash = 'post' . $post->fileHash;
$this->context->transport->filePath = $path; $context->transport->filePath = $path;
} }

View file

@ -1,53 +1,44 @@
<?php <?php
class TagController class TagController
{ {
/**
* @route /tags
* @route /tags/{page}
* @route /tags/{filter}
* @route /tags/{filter}/{page}
* @validate filter [a-zA-Z\32:,_-]+
* @validate page \d*
*/
public function listAction($filter = null, $page = 1) public function listAction($filter = null, $page = 1)
{ {
$this->context->viewName = 'tag-list-wrapper'; $context = getContext();
$context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::ListTags); PrivilegesHelper::confirmWithException(Privilege::ListTags);
$suppliedFilter = $filter ?: 'order:alpha,asc'; $suppliedFilter = $filter ?: 'order:alpha,asc';
$page = max(1, intval($page)); $page = max(1, intval($page));
$tagsPerPage = intval($this->config->browsing->tagsPerPage); $tagsPerPage = intval(getConfig()->browsing->tagsPerPage);
$tags = TagSearchService::getEntitiesRows($suppliedFilter, $tagsPerPage, $page); $tags = TagSearchService::getEntitiesRows($suppliedFilter, $tagsPerPage, $page);
$tagCount = TagSearchService::getEntityCount($suppliedFilter); $tagCount = TagSearchService::getEntityCount($suppliedFilter);
$pageCount = ceil($tagCount / $tagsPerPage); $pageCount = ceil($tagCount / $tagsPerPage);
$page = min($pageCount, $page); $page = min($pageCount, $page);
$this->context->filter = $suppliedFilter; $context->filter = $suppliedFilter;
$this->context->transport->tags = $tags; $context->transport->tags = $tags;
if ($this->context->json) if ($context->json)
{ {
$this->context->transport->tags = array_values(array_map(function($tag) { $context->transport->tags = array_values(array_map(function($tag) {
return ['name' => $tag['name'], 'count' => $tag['post_count']]; return ['name' => $tag['name'], 'count' => $tag['post_count']];
}, $this->context->transport->tags)); }, $context->transport->tags));
} }
else else
{ {
$this->context->highestUsage = TagSearchService::getMostUsedTag()['post_count']; $context->highestUsage = TagSearchService::getMostUsedTag()['post_count'];
$this->context->transport->paginator = new StdClass; $context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page; $context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount; $context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $tagCount; $context->transport->paginator->entityCount = $tagCount;
$this->context->transport->paginator->entities = $tags; $context->transport->paginator->entities = $tags;
} }
} }
/**
* @route /tags-autocomplete
*/
public function autoCompleteAction() public function autoCompleteAction()
{ {
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListTags); PrivilegesHelper::confirmWithException(Privilege::ListTags);
$suppliedSearch = InputHelper::get('search'); $suppliedSearch = InputHelper::get('search');
@ -55,7 +46,7 @@ class TagController
$filter = $suppliedSearch . ' order:popularity,desc'; $filter = $suppliedSearch . ' order:popularity,desc';
$tags = TagSearchService::getEntitiesRows($filter, 15, 1); $tags = TagSearchService::getEntitiesRows($filter, 15, 1);
$this->context->transport->tags = $context->transport->tags =
array_values(array_map( array_values(array_map(
function($tag) function($tag)
{ {
@ -66,20 +57,18 @@ class TagController
}, $tags)); }, $tags));
} }
/**
* @route /tags-related
*/
public function relatedAction() public function relatedAction()
{ {
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListTags); PrivilegesHelper::confirmWithException(Privilege::ListTags);
$suppliedContext = (array) InputHelper::get('context'); $suppliedContext = (array) InputHelper::get('context');
$suppliedTag = InputHelper::get('tag'); $suppliedTag = InputHelper::get('tag');
$limit = intval($this->config->browsing->tagsRelated); $limit = intval(getConfig()->browsing->tagsRelated);
$tags = TagSearchService::getRelatedTagRows($suppliedTag, $suppliedContext, $limit); $tags = TagSearchService::getRelatedTagRows($suppliedTag, $suppliedContext, $limit);
$this->context->transport->tags = $context->transport->tags =
array_values(array_map( array_values(array_map(
function($tag) function($tag)
{ {
@ -90,13 +79,11 @@ class TagController
}, $tags)); }, $tags));
} }
/**
* @route /tag/merge
*/
public function mergeAction() public function mergeAction()
{ {
$this->context->viewName = 'tag-list-wrapper'; $context = getContext();
$this->context->handleExceptions = true; $context->viewName = 'tag-list-wrapper';
$context->handleExceptions = true;
PrivilegesHelper::confirmWithException(Privilege::MergeTags); PrivilegesHelper::confirmWithException(Privilege::MergeTags);
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
@ -119,13 +106,11 @@ class TagController
} }
} }
/**
* @route /tag/rename
*/
public function renameAction() public function renameAction()
{ {
$this->context->viewName = 'tag-list-wrapper'; $context = getContext();
$this->context->handleExceptions = true; $context->viewName = 'tag-list-wrapper';
$context->handleExceptions = true;
PrivilegesHelper::confirmWithException(Privilege::MergeTags); PrivilegesHelper::confirmWithException(Privilege::MergeTags);
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
@ -148,12 +133,10 @@ class TagController
} }
} }
/**
* @route /mass-tag-redirect
*/
public function massTagRedirectAction() public function massTagRedirectAction()
{ {
$this->context->viewName = 'tag-list-wrapper'; $context = getContext();
$context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::MassTag); PrivilegesHelper::confirmWithException(Privilege::MassTag);
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
@ -170,7 +153,7 @@ class TagController
]; ];
if ($suppliedOldPage != 0 and $suppliedOldQuery == $suppliedQuery) if ($suppliedOldPage != 0 and $suppliedOldQuery == $suppliedQuery)
$params['page'] = $suppliedOldPage; $params['page'] = $suppliedOldPage;
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('post', 'list', $params)); \Chibi\Util\Url::forward(\Chibi\Router::linkTo(['PostController', 'listAction'], $params));
} }
} }
} }

View file

@ -3,11 +3,12 @@ class UserController
{ {
private function loadUserView($user) private function loadUserView($user)
{ {
$context = getContext();
$flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', [])); $flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', []));
$this->context->flagged = $flagged; $context->flagged = $flagged;
$this->context->transport->user = $user; $context->transport->user = $user;
$this->context->handleExceptions = true; $context->handleExceptions = true;
$this->context->viewName = 'user-view'; $context->viewName = 'user-view';
} }
private static function sendTokenizedEmail( private static function sendTokenizedEmail(
@ -27,13 +28,13 @@ class UserController
$token->expires = null; $token->expires = null;
TokenModel::save($token); TokenModel::save($token);
\Chibi\Registry::getContext()->mailSent = true; getContext()->mailSent = true;
$tokens = []; $tokens = [];
$tokens['host'] = $_SERVER['HTTP_HOST']; $tokens['host'] = $_SERVER['HTTP_HOST'];
$tokens['token'] = $token->token; //gosh this code looks so silly $tokens['token'] = $token->token; //gosh this code looks so silly
$tokens['nl'] = PHP_EOL; $tokens['nl'] = PHP_EOL;
if ($linkActionName !== null) if ($linkActionName !== null)
$tokens['link'] = \Chibi\UrlHelper::route('user', $linkActionName, ['token' => $token->token]); $tokens['link'] = \Chibi\Router::linkTo(['UserController', $linkActionName], ['token' => $token->token]);
$body = wordwrap(TextHelper::replaceTokens($body, $tokens), 70); $body = wordwrap(TextHelper::replaceTokens($body, $tokens), 70);
$subject = TextHelper::replaceTokens($subject, $tokens); $subject = TextHelper::replaceTokens($subject, $tokens);
@ -67,7 +68,7 @@ class UserController
private static function sendEmailChangeConfirmation($user) private static function sendEmailChangeConfirmation($user)
{ {
$regConfig = \Chibi\Registry::getConfig()->registration; $regConfig = getConfig()->registration;
if (!$regConfig->confirmationEmailEnabled) if (!$regConfig->confirmationEmailEnabled)
{ {
$user->emailConfirmed = $user->emailUnconfirmed; $user->emailConfirmed = $user->emailUnconfirmed;
@ -82,12 +83,12 @@ class UserController
$regConfig->confirmationEmailSenderName, $regConfig->confirmationEmailSenderName,
$regConfig->confirmationEmailSenderEmail, $regConfig->confirmationEmailSenderEmail,
$user->emailUnconfirmed, $user->emailUnconfirmed,
'activation'); 'activationAction');
} }
private static function sendPasswordResetConfirmation($user) private static function sendPasswordResetConfirmation($user)
{ {
$regConfig = \Chibi\Registry::getConfig()->registration; $regConfig = getConfig()->registration;
return self::sendTokenizedEmail( return self::sendTokenizedEmail(
$user, $user,
@ -96,49 +97,34 @@ class UserController
$regConfig->passwordResetEmailSenderName, $regConfig->passwordResetEmailSenderName,
$regConfig->passwordResetEmailSenderEmail, $regConfig->passwordResetEmailSenderEmail,
$user->emailConfirmed, $user->emailConfirmed,
'password-reset'); 'passwordResetAction');
} }
/**
* @route /users
* @route /users/{page}
* @route /users/{filter}
* @route /users/{filter}/{page}
* @validate filter [a-zA-Z\32:,_-]+
* @validate page [0-9]+
*/
public function listAction($filter, $page) public function listAction($filter, $page)
{ {
$context = getContext();
PrivilegesHelper::confirmWithException( PrivilegesHelper::confirmWithException(
Privilege::ListUsers); Privilege::ListUsers);
$suppliedFilter = $filter ?: InputHelper::get('filter') ?: 'order:alpha,asc'; $suppliedFilter = $filter ?: InputHelper::get('filter') ?: 'order:alpha,asc';
$page = max(1, intval($page)); $page = max(1, intval($page));
$usersPerPage = intval($this->config->browsing->usersPerPage); $usersPerPage = intval(getConfig()->browsing->usersPerPage);
$users = UserSearchService::getEntities($suppliedFilter, $usersPerPage, $page); $users = UserSearchService::getEntities($suppliedFilter, $usersPerPage, $page);
$userCount = UserSearchService::getEntityCount($suppliedFilter); $userCount = UserSearchService::getEntityCount($suppliedFilter);
$pageCount = ceil($userCount / $usersPerPage); $pageCount = ceil($userCount / $usersPerPage);
$page = min($pageCount, $page); $page = min($pageCount, $page);
$this->context->filter = $suppliedFilter; $context->filter = $suppliedFilter;
$this->context->transport->users = $users; $context->transport->users = $users;
$this->context->transport->paginator = new StdClass; $context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page; $context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount; $context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $userCount; $context->transport->paginator->entityCount = $userCount;
$this->context->transport->paginator->entities = $users; $context->transport->paginator->entities = $users;
$this->context->transport->paginator->params = func_get_args(); $context->transport->paginator->params = func_get_args();
} }
/**
* @route /user/{name}/flag
* @validate name [^\/]+
*/
public function flagAction($name) public function flagAction($name)
{ {
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
@ -163,12 +149,6 @@ class UserController
} }
} }
/**
* @route /user/{name}/ban
* @validate name [^\/]+
*/
public function banAction($name) public function banAction($name)
{ {
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
@ -186,12 +166,6 @@ class UserController
} }
} }
/**
* @route /post/{name}/unban
* @validate name [^\/]+
*/
public function unbanAction($name) public function unbanAction($name)
{ {
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
@ -209,12 +183,6 @@ class UserController
} }
} }
/**
* @route /post/{name}/accept-registration
* @validate name [^\/]+
*/
public function acceptRegistrationAction($name) public function acceptRegistrationAction($name)
{ {
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
@ -230,14 +198,9 @@ class UserController
} }
} }
/**
* @route /user/{name}/delete
* @validate name [^\/]+
*/
public function deleteAction($name) public function deleteAction($name)
{ {
$context = getContext();
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException( PrivilegesHelper::confirmWithException(
Privilege::ViewUser, Privilege::ViewUser,
@ -247,14 +210,14 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($user)); PrivilegesHelper::getIdentitySubPrivilege($user));
$this->loadUserView($user); $this->loadUserView($user);
$this->context->transport->tab = 'delete'; $context->transport->tab = 'delete';
$this->context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password'); $context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
$name = $user->name; $name = $user->name;
if ($this->context->user->id == $user->id) if ($context->user->id == $user->id)
{ {
$suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt); $suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt);
if ($suppliedPasswordHash != $user->passHash) if ($suppliedPasswordHash != $user->passHash)
@ -263,23 +226,18 @@ class UserController
$oldId = $user->id; $oldId = $user->id;
UserModel::remove($user); UserModel::remove($user);
if ($oldId == $this->context->user->id) if ($oldId == $context->user->id)
AuthController::doLogOut(); AuthController::doLogOut();
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); \Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
LogHelper::log('{user} removed {subject}\'s account', ['subject' => TextHelper::reprUser($name)]); LogHelper::log('{user} removed {subject}\'s account', ['subject' => TextHelper::reprUser($name)]);
StatusHelper::success(); StatusHelper::success();
} }
} }
/**
* @route /user/{name}/settings
* @validate name [^\/]+
*/
public function settingsAction($name) public function settingsAction($name)
{ {
$context = getContext();
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException( PrivilegesHelper::confirmWithException(
Privilege::ViewUser, Privilege::ViewUser,
@ -289,7 +247,7 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($user)); PrivilegesHelper::getIdentitySubPrivilege($user));
$this->loadUserView($user); $this->loadUserView($user);
$this->context->transport->tab = 'settings'; $context->transport->tab = 'settings';
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -305,21 +263,16 @@ class UserController
if ($user->accessRank != AccessRank::Anonymous) if ($user->accessRank != AccessRank::Anonymous)
UserModel::save($user); UserModel::save($user);
if ($user->id == $this->context->user->id) if ($user->id == $context->user->id)
$this->context->user = $user; $context->user = $user;
AuthController::doReLog(); AuthController::doReLog();
StatusHelper::success('Browsing settings updated!'); StatusHelper::success('Browsing settings updated!');
} }
} }
/**
* @route /user/{name}/edit
* @validate name [^\/]+
*/
public function editAction($name) public function editAction($name)
{ {
$context = getContext();
try try
{ {
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
@ -328,14 +281,14 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($user)); PrivilegesHelper::getIdentitySubPrivilege($user));
$this->loadUserView($user); $this->loadUserView($user);
$this->context->transport->tab = 'edit'; $context->transport->tab = 'edit';
$this->context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password'); $context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
$this->context->suppliedName = $suppliedName = InputHelper::get('name'); $context->suppliedName = $suppliedName = InputHelper::get('name');
$this->context->suppliedPassword1 = $suppliedPassword1 = InputHelper::get('password1'); $context->suppliedPassword1 = $suppliedPassword1 = InputHelper::get('password1');
$this->context->suppliedPassword2 = $suppliedPassword2 = InputHelper::get('password2'); $context->suppliedPassword2 = $suppliedPassword2 = InputHelper::get('password2');
$this->context->suppliedEmail = $suppliedEmail = InputHelper::get('email'); $context->suppliedEmail = $suppliedEmail = InputHelper::get('email');
$this->context->suppliedAccessRank = $suppliedAccessRank = InputHelper::get('access-rank'); $context->suppliedAccessRank = $suppliedAccessRank = InputHelper::get('access-rank');
$currentPasswordHash = $user->passHash; $currentPasswordHash = $user->passHash;
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
@ -377,7 +330,7 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($user)); PrivilegesHelper::getIdentitySubPrivilege($user));
$suppliedEmail = UserModel::validateEmail($suppliedEmail); $suppliedEmail = UserModel::validateEmail($suppliedEmail);
if ($this->context->user->id == $user->id) if ($context->user->id == $user->id)
{ {
$user->emailUnconfirmed = $suppliedEmail; $user->emailUnconfirmed = $suppliedEmail;
if (!empty($user->emailUnconfirmed)) if (!empty($user->emailUnconfirmed))
@ -407,14 +360,14 @@ class UserController
'rank' => AccessRank::toString($suppliedAccessRank)]); 'rank' => AccessRank::toString($suppliedAccessRank)]);
} }
if ($this->context->user->id == $user->id) if ($context->user->id == $user->id)
{ {
$suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt); $suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt);
if ($suppliedPasswordHash != $currentPasswordHash) if ($suppliedPasswordHash != $currentPasswordHash)
throw new SimpleException('Must supply valid current password'); throw new SimpleException('Must supply valid current password');
} }
UserModel::save($user); UserModel::save($user);
if ($this->context->user->id == $user->id) if ($context->user->id == $user->id)
AuthController::doReLog(); AuthController::doReLog();
if ($confirmMail) if ($confirmMail)
@ -429,23 +382,15 @@ class UserController
} }
catch (Exception $e) catch (Exception $e)
{ {
$this->context->transport->user = UserModel::findByNameOrEmail($name); $context->transport->user = UserModel::findByNameOrEmail($name);
throw $e; throw $e;
} }
} }
/**
* @route /user/{name}/{tab}
* @route /user/{name}/{tab}/{page}
* @validate name [^\/]+
* @validate tab favs|uploads
* @validate page \d*
*/
public function viewAction($name, $tab = 'favs', $page) public function viewAction($name, $tab = 'favs', $page)
{ {
$postsPerPage = intval($this->config->browsing->postsPerPage); $context = getContext();
$postsPerPage = intval(getConfig()->browsing->postsPerPage);
$user = UserModel::findByNameOrEmail($name); $user = UserModel::findByNameOrEmail($name);
if ($tab === null) if ($tab === null)
$tab = 'favs'; $tab = 'favs';
@ -472,53 +417,45 @@ class UserController
$pageCount = ceil($postCount / $postsPerPage); $pageCount = ceil($postCount / $postsPerPage);
PostModel::preloadTags($posts); PostModel::preloadTags($posts);
$this->context->transport->tab = $tab; $context->transport->tab = $tab;
$this->context->transport->lastSearchQuery = $query; $context->transport->lastSearchQuery = $query;
$this->context->transport->paginator = new StdClass; $context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page; $context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount; $context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $postCount; $context->transport->paginator->entityCount = $postCount;
$this->context->transport->paginator->entities = $posts; $context->transport->paginator->entities = $posts;
$this->context->transport->posts = $posts; $context->transport->posts = $posts;
} }
/**
* @route /user/toggle-safety/{safety}
*/
public function toggleSafetyAction($safety) public function toggleSafetyAction($safety)
{ {
$context = getContext();
PrivilegesHelper::confirmWithException( PrivilegesHelper::confirmWithException(
Privilege::ChangeUserSettings, Privilege::ChangeUserSettings,
PrivilegesHelper::getIdentitySubPrivilege($this->context->user)); PrivilegesHelper::getIdentitySubPrivilege($context->user));
if (!in_array($safety, PostSafety::getAll())) if (!in_array($safety, PostSafety::getAll()))
throw new SimpleExcetpion('Invalid safety'); throw new SimpleExcetpion('Invalid safety');
$this->context->user->enableSafety($safety, $context->user->enableSafety($safety,
!$this->context->user->hasEnabledSafety($safety)); !$context->user->hasEnabledSafety($safety));
if ($this->context->user->accessRank != AccessRank::Anonymous) if ($context->user->accessRank != AccessRank::Anonymous)
UserModel::save($this->context->user); UserModel::save($context->user);
AuthController::doReLog(); AuthController::doReLog();
StatusHelper::success(); StatusHelper::success();
} }
/**
* @route /register
*/
public function registrationAction() public function registrationAction()
{ {
$this->context->handleExceptions = true; $context = getContext();
$context->handleExceptions = true;
//check if already logged in //check if already logged in
if ($this->context->loggedIn) if ($context->loggedIn)
{ {
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); \Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
return; return;
} }
@ -526,10 +463,10 @@ class UserController
$suppliedPassword1 = InputHelper::get('password1'); $suppliedPassword1 = InputHelper::get('password1');
$suppliedPassword2 = InputHelper::get('password2'); $suppliedPassword2 = InputHelper::get('password2');
$suppliedEmail = InputHelper::get('email'); $suppliedEmail = InputHelper::get('email');
$this->context->suppliedName = $suppliedName; $context->suppliedName = $suppliedName;
$this->context->suppliedPassword1 = $suppliedPassword1; $context->suppliedPassword1 = $suppliedPassword1;
$this->context->suppliedPassword2 = $suppliedPassword2; $context->suppliedPassword2 = $suppliedPassword2;
$this->context->suppliedEmail = $suppliedEmail; $context->suppliedEmail = $suppliedEmail;
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -540,7 +477,7 @@ class UserController
$suppliedPassword = UserModel::validatePassword($suppliedPassword1); $suppliedPassword = UserModel::validatePassword($suppliedPassword1);
$suppliedEmail = UserModel::validateEmail($suppliedEmail); $suppliedEmail = UserModel::validateEmail($suppliedEmail);
if (empty($suppliedEmail) and $this->config->registration->needEmailForRegistering) if (empty($suppliedEmail) and getConfig()->registration->needEmailForRegistering)
throw new SimpleException('E-mail address is required - you will be sent confirmation e-mail.'); throw new SimpleException('E-mail address is required - you will be sent confirmation e-mail.');
//register the user //register the user
@ -572,35 +509,31 @@ class UserController
self::sendEmailChangeConfirmation($dbUser); self::sendEmailChangeConfirmation($dbUser);
$message = 'Congratulations, your account was created.'; $message = 'Congratulations, your account was created.';
if (!empty($this->context->mailSent)) if (!empty($context->mailSent))
{ {
$message .= ' Please wait for activation e-mail.'; $message .= ' Please wait for activation e-mail.';
if ($this->config->registration->staffActivation) if (getConfig()->registration->staffActivation)
$message .= ' After this, your registration must be confirmed by staff.'; $message .= ' After this, your registration must be confirmed by staff.';
} }
elseif ($this->config->registration->staffActivation) elseif (getConfig()->registration->staffActivation)
$message .= ' Your registration must be now confirmed by staff.'; $message .= ' Your registration must be now confirmed by staff.';
LogHelper::log('{subject} just signed up', ['subject' => TextHelper::reprUser($dbUser)]); LogHelper::log('{subject} just signed up', ['subject' => TextHelper::reprUser($dbUser)]);
StatusHelper::success($message); StatusHelper::success($message);
if (!$this->config->registration->needEmailForRegistering and !$this->config->registration->staffActivation) if (!getConfig()->registration->needEmailForRegistering and !getConfig()->registration->staffActivation)
{ {
$this->context->user = $dbUser; $context->user = $dbUser;
AuthController::doReLog(); AuthController::doReLog();
} }
} }
} }
/**
* @route /activation/{token}
*/
public function activationAction($token) public function activationAction($token)
{ {
$this->context->viewName = 'message'; $context = getContext();
CustomAssetViewDecorator::setSubTitle('account activation'); $context->viewName = 'message';
Assets::setSubTitle('account activation');
$dbToken = TokenModel::findByToken($token); $dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken); TokenModel::checkValidity($dbToken);
@ -614,26 +547,22 @@ class UserController
LogHelper::log('{subject} just activated account', ['subject' => TextHelper::reprUser($dbUser)]); LogHelper::log('{subject} just activated account', ['subject' => TextHelper::reprUser($dbUser)]);
$message = 'Activation completed successfully.'; $message = 'Activation completed successfully.';
if ($this->config->registration->staffActivation) if (getConfig()->registration->staffActivation)
$message .= ' However, your account still must be confirmed by staff.'; $message .= ' However, your account still must be confirmed by staff.';
StatusHelper::success($message); StatusHelper::success($message);
if (!$this->config->registration->staffActivation) if (!getConfig()->registration->staffActivation)
{ {
$this->context->user = $dbUser; $context->user = $dbUser;
AuthController::doReLog(); AuthController::doReLog();
} }
} }
/**
* @route /password-reset/{token}
*/
public function passwordResetAction($token) public function passwordResetAction($token)
{ {
$this->context->viewName = 'message'; $context = getContext();
CustomAssetViewDecorator::setSubTitle('password reset'); $context->viewName = 'message';
Assets::setSubTitle('password reset');
$dbToken = TokenModel::findByToken($token); $dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken); TokenModel::checkValidity($dbToken);
@ -654,20 +583,15 @@ class UserController
$message = 'Password reset successful. Your new password is **' . $randomPassword . '**.'; $message = 'Password reset successful. Your new password is **' . $randomPassword . '**.';
StatusHelper::success($message); StatusHelper::success($message);
$this->context->user = $dbUser; $context->user = $dbUser;
AuthController::doReLog(); AuthController::doReLog();
} }
/**
* @route /password-reset-proxy
*/
public function passwordResetProxyAction() public function passwordResetProxyAction()
{ {
$this->context->viewName = 'user-select'; $context = getContext();
CustomAssetViewDecorator::setSubTitle('password reset'); $context->viewName = 'user-select';
Assets::setSubTitle('password reset');
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {
@ -681,13 +605,11 @@ class UserController
} }
} }
/**
* @route /activation-proxy
*/
public function activationProxyAction() public function activationProxyAction()
{ {
$this->context->viewName = 'user-select'; $context = getContext();
CustomAssetViewDecorator::setSubTitle('account activation'); $context->viewName = 'user-select';
Assets::setSubTitle('account activation');
if (InputHelper::get('submit')) if (InputHelper::get('submit'))
{ {

View file

@ -127,7 +127,7 @@ class CustomMarkdown extends \Michelf\MarkdownExtra
protected function doPosts($text) protected function doPosts($text)
{ {
$link = \Chibi\UrlHelper::route('post', 'view', ['id' => '_post_']); $link = \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => '_post_']);
return preg_replace_callback('/(?:(?<![^\s\(\)\[\]]))@(\d+)/', function($x) use ($link) return preg_replace_callback('/(?:(?<![^\s\(\)\[\]]))@(\d+)/', function($x) use ($link)
{ {
return $this->hashPart('<a href="' . str_replace('_post_', $x[1], $link) . '"><code>' . $x[0] . '</code></a>'); return $this->hashPart('<a href="' . str_replace('_post_', $x[1], $link) . '"><code>' . $x[0] . '</code></a>');
@ -136,7 +136,7 @@ class CustomMarkdown extends \Michelf\MarkdownExtra
protected function doTags($text) protected function doTags($text)
{ {
$link = \Chibi\UrlHelper::route('post', 'list', ['query' => '_query_']); $link = \Chibi\Router::linkTo(['PostController', 'listAction'], ['query' => '_query_']);
return preg_replace_callback('/(?:(?<![^\s\(\)\[\]]))#([()\[\]a-zA-Z0-9_.-]+)/', function($x) use ($link) return preg_replace_callback('/(?:(?<![^\s\(\)\[\]]))#([()\[\]a-zA-Z0-9_.-]+)/', function($x) use ($link)
{ {
return $this->hashPart('<a href="' . str_replace('_query_', $x[1], $link) . '">' . $x[0] . '</a>'); return $this->hashPart('<a href="' . str_replace('_query_', $x[1], $link) . '">' . $x[0] . '</a>');
@ -145,7 +145,7 @@ class CustomMarkdown extends \Michelf\MarkdownExtra
protected function doUsers($text) protected function doUsers($text)
{ {
$link = \Chibi\UrlHelper::route('user', 'view', ['name' => '_name_']); $link = \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => '_name_']);
return preg_replace_callback('/(?:(?<![^\s\(\)\[\]]))\+([a-zA-Z0-9_-]+)/', function($x) use ($link) return preg_replace_callback('/(?:(?<![^\s\(\)\[\]]))\+([a-zA-Z0-9_-]+)/', function($x) use ($link)
{ {
return $this->hashPart('<a href="' . str_replace('_name_', $x[1], $link) . '">' . $x[0] . '</a>'); return $this->hashPart('<a href="' . str_replace('_name_', $x[1], $link) . '">' . $x[0] . '</a>');
@ -154,7 +154,7 @@ class CustomMarkdown extends \Michelf\MarkdownExtra
protected function doSearchPermalinks($text) protected function doSearchPermalinks($text)
{ {
$link = \Chibi\UrlHelper::route('post', 'list', ['query' => '_query_']); $link = \Chibi\Router::linkTo(['PostController', 'listAction'], ['query' => '_query_']);
return preg_replace_callback('{\[search\]((?:[^\[]|\[(?!\/?search\]))+)\[\/search\]}is', function($x) use ($link) return preg_replace_callback('{\[search\]((?:[^\[]|\[(?!\/?search\]))+)\[\/search\]}is', function($x) use ($link)
{ {
return $this->hashPart('<a href="' . str_replace('_query_', urlencode($x[1]), $link) . '">' . $x[1] . '</a>'); return $this->hashPart('<a href="' . str_replace('_query_', urlencode($x[1]), $link) . '">' . $x[1] . '</a>');

View file

@ -1,9 +1,15 @@
<?php <?php
class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator class Assets extends \Chibi\Util\Assets
{ {
private static $pageThumb = null; private static $pageThumb = null;
private static $subTitle = null; private static $subTitle = null;
public static function init()
{
\Chibi\Util\Assets::disable();
self::enable();
}
public static function setSubTitle($text) public static function setSubTitle($text)
{ {
self::$subTitle = $text; self::$subTitle = $text;
@ -14,7 +20,17 @@ class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
self::$pageThumb = $path; self::$pageThumb = $path;
} }
public function transformHtml($html) public static function addStylesheet($path)
{
return parent::addStylesheet('/media/css/' . $path);
}
public static function addScript($path)
{
return parent::addScript('/media/js/' . $path);
}
public static function transformHtml($html)
{ {
self::$title = isset(self::$subTitle) self::$title = isset(self::$subTitle)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', self::$title, self::$subTitle) ? sprintf('%s&nbsp;&ndash;&nbsp;%s', self::$title, self::$subTitle)
@ -23,7 +39,7 @@ class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
$html = parent::transformHtml($html); $html = parent::transformHtml($html);
$headSnippet = '<meta property="og:title" content="' . self::$title . '"/>'; $headSnippet = '<meta property="og:title" content="' . self::$title . '"/>';
$headSnippet .= '<meta property="og:url" content="' . \Chibi\UrlHelper::currentUrl() . '"/>'; $headSnippet .= '<meta property="og:url" content="' . \Chibi\Util\Url::currentUrl() . '"/>';
if (!empty(self::$pageThumb)) if (!empty(self::$pageThumb))
$headSnippet .= '<meta property="og:image" content="' . self::$pageThumb . '"/>'; $headSnippet .= '<meta property="og:image" content="' . self::$pageThumb . '"/>';
@ -38,3 +54,5 @@ class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
return $html; return $html;
} }
} }
Assets::init();

View file

@ -36,8 +36,7 @@ class LogHelper
public static function getLogPath() public static function getLogPath()
{ {
return TextHelper::absolutePath( return TextHelper::absolutePath(getConfig()->main->logsPath . DS . date('Y-m') . '.log');
\Chibi\Registry::getConfig()->main->logsPath . DS . date('Y-m') . '.log');
} }
public static function log($text, array $tokens = []) public static function log($text, array $tokens = [])
@ -72,7 +71,7 @@ class LogEvent
$this->text = $text; $this->text = $text;
$this->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'; $this->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
$context = \Chibi\Registry::getContext(); $context = getContext();
$tokens['anon'] = UserModel::getAnonymousName(); $tokens['anon'] = UserModel::getAnonymousName();
if ($context->loggedIn and isset($context->user)) if ($context->loggedIn and isset($context->user))
$tokens['user'] = TextHelper::reprUser($context->user->name); $tokens['user'] = TextHelper::reprUser($context->user->name);

View file

@ -6,7 +6,7 @@ class PrivilegesHelper
public static function init() public static function init()
{ {
self::$privileges = []; self::$privileges = [];
foreach (\Chibi\Registry::getConfig()->privileges as $key => $minAccessRankName) foreach (getConfig()->privileges as $key => $minAccessRankName)
{ {
if (strpos($key, '.') === false) if (strpos($key, '.') === false)
$key .= '.'; $key .= '.';
@ -37,7 +37,7 @@ class PrivilegesHelper
if (php_sapi_name() == 'cli') if (php_sapi_name() == 'cli')
return true; return true;
$user = \Chibi\Registry::getContext()->user; $user = getContext()->user;
$minAccessRank = AccessRank::Admin; $minAccessRank = AccessRank::Admin;
$key = TextCaseConverter::convert(Privilege::toString($privilege), $key = TextCaseConverter::convert(Privilege::toString($privilege),
@ -70,7 +70,7 @@ class PrivilegesHelper
{ {
if (!$user) if (!$user)
return 'all'; return 'all';
$userFromContext = \Chibi\Registry::getContext()->user; $userFromContext = getContext()->user;
return $user->id == $userFromContext->id ? 'own' : 'all'; return $user->id == $userFromContext->id ? 'own' : 'all';
} }
@ -85,7 +85,7 @@ class PrivilegesHelper
if (php_sapi_name() == 'cli') if (php_sapi_name() == 'cli')
return PostSafety::getAll(); return PostSafety::getAll();
$context = \Chibi\Registry::getContext(); $context = getContext();
return array_filter(PostSafety::getAll(), function($safety) use ($context) return array_filter(PostSafety::getAll(), function($safety) use ($context)
{ {
return PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety)) and return PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety)) and

View file

@ -3,7 +3,7 @@ class StatusHelper
{ {
private static function flag($success, $message = null) private static function flag($success, $message = null)
{ {
$context = \Chibi\Registry::getContext(); $context = getContext();
if (!empty($message)) if (!empty($message))
{ {
if (!preg_match('/[.?!]$/', $message)) if (!preg_match('/[.?!]$/', $message))
@ -17,7 +17,7 @@ class StatusHelper
public static function init() public static function init()
{ {
$context = \Chibi\Registry::getContext(); $context = getContext();
$context->transport->success = null; $context->transport->success = null;
} }

View file

@ -178,7 +178,7 @@ class TextHelper
public static function encrypt($text) public static function encrypt($text)
{ {
$salt = \Chibi\Registry::getConfig()->main->salt; $salt = getConfig()->main->salt;
$alg = MCRYPT_RIJNDAEL_256; $alg = MCRYPT_RIJNDAEL_256;
$mode = MCRYPT_MODE_CBC; $mode = MCRYPT_MODE_CBC;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($alg, $mode), MCRYPT_RAND); $iv = mcrypt_create_iv(mcrypt_get_iv_size($alg, $mode), MCRYPT_RAND);
@ -189,7 +189,7 @@ class TextHelper
{ {
try try
{ {
$salt = \Chibi\Registry::getConfig()->main->salt; $salt = getConfig()->main->salt;
list ($iv, $hash) = explode('|', $text, 2); list ($iv, $hash) = explode('|', $text, 2);
$iv = base64_decode($iv); $iv = base64_decode($iv);
$hash = base64_decode($hash); $hash = base64_decode($hash);
@ -216,7 +216,7 @@ class TextHelper
public static function absolutePath($path) public static function absolutePath($path)
{ {
if ($path{0} != DS) if ($path{0} != DS)
$path = \Chibi\Registry::getContext()->rootDir . DS . $path; $path = getConfig()->rootDir . DS . $path;
$path = self::cleanPath($path); $path = self::cleanPath($path);
return $path; return $path;

View file

@ -90,7 +90,7 @@ class CommentModel extends AbstractCrudModel
public static function validateText($text) public static function validateText($text)
{ {
$text = trim($text); $text = trim($text);
$config = \Chibi\Registry::getConfig(); $config = getConfig();
if (strlen($text) < $config->comments->minLength) if (strlen($text) < $config->comments->minLength)
throw new SimpleException('Comment must have at least %d characters', $config->comments->minLength); throw new SimpleException('Comment must have at least %d characters', $config->comments->minLength);

View file

@ -105,7 +105,7 @@ class PostEntity extends AbstractEntity
public function setRelationsFromText($relationsText) public function setRelationsFromText($relationsText)
{ {
$config = \Chibi\Registry::getConfig(); $config = getConfig();
$relatedIds = array_filter(preg_split('/\D/', $relationsText)); $relatedIds = array_filter(preg_split('/\D/', $relationsText));
$relatedPosts = []; $relatedPosts = [];
@ -215,7 +215,7 @@ class PostEntity extends AbstractEntity
public function setCustomThumbnailFromPath($srcPath) public function setCustomThumbnailFromPath($srcPath)
{ {
$config = \Chibi\Registry::getConfig(); $config = getConfig();
$mimeType = mime_content_type($srcPath); $mimeType = mime_content_type($srcPath);
if (!in_array($mimeType, ['image/gif', 'image/png', 'image/jpeg'])) if (!in_array($mimeType, ['image/gif', 'image/png', 'image/jpeg']))
@ -323,7 +323,7 @@ class PostEntity extends AbstractEntity
if (!isset($srcImage)) if (!isset($srcImage))
return false; return false;
$config = \Chibi\Registry::getConfig(); $config = getConfig();
switch ($config->browsing->thumbStyle) switch ($config->browsing->thumbStyle)
{ {
case 'outside': case 'outside':

View file

@ -77,7 +77,7 @@ class UserEntity extends AbstractEntity
{ {
$ret = $this->getSetting(UserModel::SETTING_HIDE_DISLIKED_POSTS); $ret = $this->getSetting(UserModel::SETTING_HIDE_DISLIKED_POSTS);
if ($ret === null) if ($ret === null)
$ret = !\Chibi\Registry::getConfig()->browsing->showDislikedPostsDefault; $ret = !getConfig()->browsing->showDislikedPostsDefault;
return $ret; return $ret;
} }
@ -90,7 +90,7 @@ class UserEntity extends AbstractEntity
{ {
$ret = $this->getSetting(UserModel::SETTING_POST_TAG_TITLES); $ret = $this->getSetting(UserModel::SETTING_POST_TAG_TITLES);
if ($ret === null) if ($ret === null)
$ret = \Chibi\Registry::getConfig()->browsing->showPostTagTitlesDefault; $ret = getConfig()->browsing->showPostTagTitlesDefault;
return $ret; return $ret;
} }
@ -103,7 +103,7 @@ class UserEntity extends AbstractEntity
{ {
$ret = $this->getSetting(UserModel::SETTING_ENDLESS_SCROLLING); $ret = $this->getSetting(UserModel::SETTING_ENDLESS_SCROLLING);
if ($ret === null) if ($ret === null)
$ret = \Chibi\Registry::getConfig()->browsing->endlessScrollingDefault; $ret = getConfig()->browsing->endlessScrollingDefault;
return $ret; return $ret;
} }

View file

@ -13,7 +13,7 @@ class PostModel extends AbstractCrudModel
public static function init() public static function init()
{ {
self::$config = \Chibi\Registry::getConfig(); self::$config = getConfig();
} }
public static function spawn() public static function spawn()

View file

@ -9,7 +9,7 @@ class PostSearchParser extends AbstractSearchParser
protected function processSetup(&$tokens) protected function processSetup(&$tokens)
{ {
$config = \Chibi\Registry::getConfig(); $config = getConfig();
$this->tags = []; $this->tags = [];
$crit = new Sql\ConjunctionFunctor(); $crit = new Sql\ConjunctionFunctor();
@ -24,7 +24,7 @@ class PostSearchParser extends AbstractSearchParser
protected function processTeardown() protected function processTeardown()
{ {
if (\Chibi\Registry::getContext()->user->hasEnabledHidingDislikedPosts() and !$this->showDisliked) if (getContext()->user->hasEnabledHidingDislikedPosts() and !$this->showDisliked)
$this->processComplexToken('special', 'disliked', true); $this->processComplexToken('special', 'disliked', true);
if (!PrivilegesHelper::confirm(Privilege::ListPosts, 'hidden') or !$this->showHidden) if (!PrivilegesHelper::confirm(Privilege::ListPosts, 'hidden') or !$this->showHidden)
@ -146,7 +146,7 @@ class PostSearchParser extends AbstractSearchParser
elseif ($key == 'special') elseif ($key == 'special')
{ {
$context = \Chibi\Registry::getContext(); $context = getContext();
$value = strtolower($value); $value = strtolower($value);
if (in_array($value, ['fav', 'favs', 'favd'])) if (in_array($value, ['fav', 'favs', 'favd']))
{ {

View file

@ -179,22 +179,23 @@ class UserModel extends AbstractCrudModel
public static function validateUserName($userName) public static function validateUserName($userName)
{ {
$userName = trim($userName); $userName = trim($userName);
$config = getConfig();
$dbUser = self::findByName($userName, false); $dbUser = self::findByName($userName, false);
if ($dbUser !== null) if ($dbUser !== null)
{ {
if (!$dbUser->emailConfirmed and \Chibi\Registry::getConfig()->registration->needEmailForRegistering) if (!$dbUser->emailConfirmed and $config->registration->needEmailForRegistering)
throw new SimpleException('User with this name is already registered and awaits e-mail confirmation'); throw new SimpleException('User with this name is already registered and awaits e-mail confirmation');
if (!$dbUser->staffConfirmed and \Chibi\Registry::getConfig()->registration->staffActivation) if (!$dbUser->staffConfirmed and $config->registration->staffActivation)
throw new SimpleException('User with this name is already registered and awaits staff confirmation'); throw new SimpleException('User with this name is already registered and awaits staff confirmation');
throw new SimpleException('User with this name is already registered'); throw new SimpleException('User with this name is already registered');
} }
$userNameMinLength = intval(\Chibi\Registry::getConfig()->registration->userNameMinLength); $userNameMinLength = intval($config->registration->userNameMinLength);
$userNameMaxLength = intval(\Chibi\Registry::getConfig()->registration->userNameMaxLength); $userNameMaxLength = intval($config->registration->userNameMaxLength);
$userNameRegex = \Chibi\Registry::getConfig()->registration->userNameRegex; $userNameRegex = $config->registration->userNameRegex;
if (strlen($userName) < $userNameMinLength) if (strlen($userName) < $userNameMinLength)
throw new SimpleException('User name must have at least %d characters', $userNameMinLength); throw new SimpleException('User name must have at least %d characters', $userNameMinLength);
@ -210,8 +211,9 @@ class UserModel extends AbstractCrudModel
public static function validatePassword($password) public static function validatePassword($password)
{ {
$passMinLength = intval(\Chibi\Registry::getConfig()->registration->passMinLength); $config = getConfig();
$passRegex = \Chibi\Registry::getConfig()->registration->passRegex; $passMinLength = intval($config->registration->passMinLength);
$passRegex = $config->registration->passRegex;
if (strlen($password) < $passMinLength) if (strlen($password) < $passMinLength)
throw new SimpleException('Password must have at least %d characters', $passMinLength); throw new SimpleException('Password must have at least %d characters', $passMinLength);
@ -254,7 +256,7 @@ class UserModel extends AbstractCrudModel
public static function hashPassword($pass, $salt2) public static function hashPassword($pass, $salt2)
{ {
$salt1 = \Chibi\Registry::getConfig()->main->salt; $salt1 = getConfig()->main->salt;
return sha1($salt1 . $salt2 . $pass); return sha1($salt1 . $salt2 . $pass);
} }
} }

View file

@ -1,12 +1,12 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('authentication form'); Assets::setSubTitle('authentication form');
CustomAssetViewDecorator::addStylesheet('auth.css'); Assets::addStylesheet('auth.css');
?> ?>
<form action="<?= \Chibi\UrlHelper::route('auth', 'login') ?>" class="auth" method="post"> <form action="<?= \Chibi\Router::linkTo(['AuthController', 'loginAction']) ?>" class="auth" method="post">
<p> <p>
If you don't have an account yet,<br/> If you don't have an account yet,<br/>
<a href="<?= \Chibi\UrlHelper::route('user', 'registration'); ?>">click here</a> to create a new one. <a href="<?= \Chibi\Router::linkTo(['UserController', 'registrationAction']); ?>">click here</a> to create a new one.
</p> </p>
<div class="form-row"> <div class="form-row">
@ -29,7 +29,7 @@ CustomAssetViewDecorator::addStylesheet('auth.css');
</div> </div>
</div> </div>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>
@ -38,9 +38,9 @@ CustomAssetViewDecorator::addStylesheet('auth.css');
<div> <div>
<p>Problems logging in?</p> <p>Problems logging in?</p>
<ul> <ul>
<li><a href="<?= \Chibi\UrlHelper::route('user', 'password-reset-proxy') ?>">I don't remember my password</a></li> <li><a href="<?= \Chibi\Router::linkTo(['UserController', 'passwordResetProxyAction']) ?>">I don't remember my password</a></li>
<li><a href="<?= \Chibi\UrlHelper::route('user', 'activation-proxy') ?>">I haven't received activation e-mail</a></li> <li><a href="<?= \Chibi\Router::linkTo(['UserController', 'activationProxyAction']) ?>">I haven't received activation e-mail</a></li>
<li><a href="<?= \Chibi\UrlHelper::route('user', 'registration') ?>">I don't have an account</a></li> <li><a href="<?= \Chibi\Router::linkTo(['UserController', 'registrationAction']) ?>">I don't have an account</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -1,10 +1,10 @@
<?php <?php
CustomAssetViewDecorator::addStylesheet('comment-edit.css'); Assets::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js'); Assets::addScript('comment-edit.js');
?> ?>
<form <form
action="<?= \Chibi\UrlHelper::route('comment', 'add', ['postId' => $this->context->transport->post->id]) ?>" action="<?= \Chibi\Router::linkTo(['CommentController', 'addAction'], ['postId' => $this->context->transport->post->id]) ?>"
method="post" method="post"
class="add-comment"> class="add-comment">

View file

@ -1,10 +1,10 @@
<?php <?php
CustomAssetViewDecorator::addStylesheet('comment-edit.css'); Assets::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js'); Assets::addScript('comment-edit.js');
?> ?>
<form <form
action="<?= \Chibi\UrlHelper::route('comment', 'edit', ['id' => $this->context->transport->comment->id]) ?>" action="<?= \Chibi\Router::linkTo(['CommentController', 'editAction'], ['id' => $this->context->transport->comment->id]) ?>"
method="post" method="post"
class="edit-comment"> class="edit-comment">

View file

@ -1,15 +1,15 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('comments'); Assets::setSubTitle('comments');
?> ?>
<?php if (empty($this->context->transport->posts)): ?> <?php if (empty($this->context->transport->posts)): ?>
<p class="alert alert-warning">No comments to show.</p> <p class="alert alert-warning">No comments to show.</p>
<?php else: ?> <?php else: ?>
<?php <?php
CustomAssetViewDecorator::addStylesheet('comment-list.css'); Assets::addStylesheet('comment-list.css');
CustomAssetViewDecorator::addStylesheet('comment-small.css'); Assets::addStylesheet('comment-small.css');
CustomAssetViewDecorator::addStylesheet('comment-edit.css'); Assets::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js'); Assets::addScript('comment-edit.js');
?> ?>
<div class="comments-wrapper"> <div class="comments-wrapper">
@ -20,18 +20,18 @@ CustomAssetViewDecorator::setSubTitle('comments');
<?php <?php
$this->context->post = $post; $this->context->post = $post;
$comments = array_reverse($post->getComments()); $comments = array_reverse($post->getComments());
$commentsToDisplay = array_slice($comments, 0, $this->config->comments->maxCommentsInList); $commentsToDisplay = array_slice($comments, 0, getConfig()->comments->maxCommentsInList);
?> ?>
<?= $this->renderFile('post-small') ?> <?php \Chibi\View::render('post-small', $this->context) ?>
</div> </div>
<div class="comments"> <div class="comments">
<?php foreach ($commentsToDisplay as $comment): ?> <?php foreach ($commentsToDisplay as $comment): ?>
<?php $this->context->comment = $comment ?> <?php $this->context->comment = $comment ?>
<?= $this->renderFile('comment-small') ?> <?php \Chibi\View::render('comment-small', $this->context) ?>
<?php endforeach ?> <?php endforeach ?>
<?php if (count($comments) > count($commentsToDisplay)): ?> <?php if (count($comments) > count($commentsToDisplay)): ?>
<a href="<?= \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->post->id]) ?>"> <a href="<?= \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => $this->context->post->id]) ?>">
<span class="hellip">(more&hellip;)</span> <span class="hellip">(more&hellip;)</span>
</a> </a>
<?php endif ?> <?php endif ?>
@ -41,6 +41,6 @@ CustomAssetViewDecorator::setSubTitle('comments');
<?php endforeach ?> <?php endforeach ?>
</div> </div>
<?php $this->renderFile('paginator') ?> <?php \Chibi\View::render('paginator', $this->context) ?>
</div> </div>
<?php endif ?> <?php endif ?>

View file

@ -1,19 +1,19 @@
<?php <?php
CustomAssetViewDecorator::addStylesheet('comment-small.css'); Assets::addStylesheet('comment-small.css');
CustomAssetViewDecorator::addStylesheet('comment-edit.css'); Assets::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js'); Assets::addScript('comment-edit.js');
?> ?>
<div class="comment"> <div class="comment">
<div class="avatar"> <div class="avatar">
<?php $commenter = $this->context->comment->getCommenter() ?> <?php $commenter = $this->context->comment->getCommenter() ?>
<?php if ($commenter): ?> <?php if ($commenter): ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $commenter->name]) ?>"> <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $commenter->name]) ?>">
<img src="<?= htmlspecialchars($commenter->getAvatarUrl(40)) ?>" alt="<?= $commenter->name ?>"/> <img src="<?= htmlspecialchars($commenter->getAvatarUrl(40)) ?>" alt="<?= $commenter->name ?>"/>
</a> </a>
<?php else: ?> <?php else: ?>
<img <img
src="<?= \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" src="<?= \Chibi\Util\Url::makeAbsolute('/media/img/pixel.gif') ?>"
alt="<?= UserModel::getAnonymousName() ?>"> alt="<?= UserModel::getAnonymousName() ?>">
<?php endif ?> <?php endif ?>
</div> </div>
@ -22,7 +22,7 @@ CustomAssetViewDecorator::addScript('comment-edit.js');
<div class="header"> <div class="header">
<span class="nickname"> <span class="nickname">
<?php if ($commenter): ?> <?php if ($commenter): ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $commenter->name]) ?>"> <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $commenter->name]) ?>">
<?= $commenter->name ?> <?= $commenter->name ?>
</a> </a>
<?php else: ?> <?php else: ?>
@ -38,7 +38,7 @@ CustomAssetViewDecorator::addScript('comment-edit.js');
Privilege::EditComment, Privilege::EditComment,
PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?> PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?>
<span class="edit"> <span class="edit">
<a href="<?= \Chibi\UrlHelper::route('comment', 'edit', ['id' => $this->context->comment->id]) ?>"> <a href="<?= \Chibi\Router::linkTo(['CommentController', 'editAction'], ['id' => $this->context->comment->id]) ?>">
edit edit
</a> </a>
</span> </span>
@ -48,7 +48,7 @@ CustomAssetViewDecorator::addScript('comment-edit.js');
PrivilegesHelper::confirm(Privilege::DeleteComment, PrivilegesHelper::confirm(Privilege::DeleteComment,
PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?> PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?>
<span class="delete"> <span class="delete">
<a href="<?= \Chibi\UrlHelper::route('comment', 'delete', ['id' => $this->context->comment->id]) ?>" <a href="<?= \Chibi\Router::linkTo(['CommentController', 'deleteAction'], ['id' => $this->context->comment->id]) ?>"
class="simple-action confirmable" class="simple-action confirmable"
data-confirm-text="Are you sure you want to delete this comment?"> data-confirm-text="Are you sure you want to delete this comment?">
delete delete

View file

@ -1,4 +1,4 @@
<?php CustomAssetViewDecorator::addStylesheet('debug.css') ?> <?php Assets::addStylesheet('debug.css') ?>
<div class="main-wrapper"> <div class="main-wrapper">
<?php foreach (\Chibi\Database::getLogs() as $log): ?> <?php foreach (\Chibi\Database::getLogs() as $log): ?>
<div class="debug"> <div class="debug">

View file

@ -1,8 +1,8 @@
<?php <?php
CustomAssetViewDecorator::setSubtitle('help'); Assets::setSubtitle('help');
CustomAssetViewDecorator::addStylesheet('index-help.css'); Assets::addStylesheet('index-help.css');
$tabs = $this->config->help->subTitles; $tabs = getConfig()->help->subTitles;
$firstTab = !empty($tabs) ? array_keys($tabs)[0] : null; $firstTab = !empty($tabs) ? array_keys($tabs)[0] : null;
$showTabs = count($tabs) > 1; $showTabs = count($tabs) > 1;
?> ?>
@ -16,7 +16,7 @@ $showTabs = count($tabs) > 1;
<?php else: ?> <?php else: ?>
<li class="<?= $tab ?>"> <li class="<?= $tab ?>">
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('index', 'help', $tab == $firstTab ? [] : ['tab' => $tab]) ?>"> <a href="<?= \Chibi\Router::linkTo(['IndexController', 'helpAction'], $tab == $firstTab ? [] : ['tab' => $tab]) ?>">
<?= $text ?> <?= $text ?>
</a> </a>
</li> </li>

View file

@ -1,10 +1,10 @@
<?php <?php
CustomAssetViewDecorator::setSubtitle('home'); Assets::setSubtitle('home');
CustomAssetViewDecorator::addStylesheet('index-index.css'); Assets::addStylesheet('index-index.css');
?> ?>
<div id="welcome"> <div id="welcome">
<h1><?= $this->config->main->title ?></h1> <h1><?= getConfig()->main->title ?></h1>
<p> <p>
<span>serving <?= $this->context->transport->postCount ?> posts</span> <span>serving <?= $this->context->transport->postCount ?> posts</span>
</p> </p>
@ -14,11 +14,11 @@ CustomAssetViewDecorator::addStylesheet('index-index.css');
<div class="body"> <div class="body">
<?php <?php
$this->context->transport->post = $this->context->featuredPost; $this->context->transport->post = $this->context->featuredPost;
$this->context->imageLink = \Chibi\UrlHelper::route('post', 'view', [ $this->context->imageLink = \Chibi\Router::linkTo(['PostController', 'viewAction'], [
'id' => $this->context->featuredPost->id]); 'id' => $this->context->featuredPost->id]);
?> ?>
<?= $this->renderFile('post-file-render') ?> <?php \Chibi\View::render('post-file-render', $this->context) ?>
</div> </div>
<div class="footer"> <div class="footer">
@ -29,7 +29,7 @@ CustomAssetViewDecorator::addStylesheet('index-index.css');
<?php uasort($tags, function($a, $b) { return strnatcasecmp($a->name, $b->name); }) ?> <?php uasort($tags, function($a, $b) { return strnatcasecmp($a->name, $b->name); }) ?>
<?php foreach ($tags as $tag): ?> <?php foreach ($tags as $tag): ?>
<li> <li>
<a href="<?= \Chibi\UrlHelper::route('post', 'list', ['query' => $tag->name]) ?>"> <a href="<?= \Chibi\Router::linkTo(['PostController', 'listAction'], ['query' => $tag->name]) ?>">
<?= $tag->name ?> <?= $tag->name ?>
</a> </a>
</li> </li>
@ -41,7 +41,7 @@ CustomAssetViewDecorator::addStylesheet('index-index.css');
Featured Featured
<?php if ($this->context->featuredPostUser): ?> <?php if ($this->context->featuredPostUser): ?>
by by
<a href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->featuredPostUser->name]) ?>"> <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $this->context->featuredPostUser->name]) ?>">
<?= $this->context->featuredPostUser->name ?> <?= $this->context->featuredPostUser->name ?>
</a>, </a>,
<?php endif ?> <?php endif ?>

View file

@ -1,7 +1,7 @@
<?php <?php
if (!empty($this->context->transport->errorMessage)) if (!empty($this->context->transport->errorMessage))
{ {
\Chibi\HeadersHelper::set('Content-Type', 'text/plain; charset=utf-8'); \Chibi\Util\Headers::set('Content-Type', 'text/plain; charset=utf-8');
echo $this->context->transport->errorMessage; echo $this->context->transport->errorMessage;
} }
else else
@ -18,20 +18,20 @@ else
? trim(trim($_SERVER['HTTP_IF_NONE_MATCH']), '"') ? trim(trim($_SERVER['HTTP_IF_NONE_MATCH']), '"')
: false; : false;
\Chibi\HeadersHelper::set('ETag', '"' . $eTag . '"'); \Chibi\Util\Headers::set('ETag', '"' . $eTag . '"');
\Chibi\HeadersHelper::set('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $lastModified)); \Chibi\Util\Headers::set('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $lastModified));
\Chibi\HeadersHelper::set('Pragma', 'public'); \Chibi\Util\Headers::set('Pragma', 'public');
\Chibi\HeadersHelper::set('Cache-Control', 'public, max-age=' . $ttl); \Chibi\Util\Headers::set('Cache-Control', 'public, max-age=' . $ttl);
\Chibi\HeadersHelper::set('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl)); \Chibi\Util\Headers::set('Expires', gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl));
if (isset($this->context->transport->customFileName)) if (isset($this->context->transport->customFileName))
{ {
\Chibi\HeadersHelper::set( \Chibi\Util\Headers::set(
'Content-Disposition', 'Content-Disposition',
'inline; filename="' . $this->context->transport->customFileName . '"'); 'inline; filename="' . $this->context->transport->customFileName . '"');
} }
\Chibi\HeadersHelper::set( \Chibi\Util\Headers::set(
'Content-Type', 'Content-Type',
$this->context->transport->mimeType); $this->context->transport->mimeType);

View file

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

View file

@ -1,10 +1,10 @@
<?php <?php
CustomAssetViewDecorator::addStylesheet('../lib/jquery-ui/jquery-ui.css'); Assets::addStylesheet('../lib/jquery-ui/jquery-ui.css');
CustomAssetViewDecorator::addStylesheet('core.css'); Assets::addStylesheet('core.css');
CustomAssetViewDecorator::addScript('../lib/jquery/jquery.min.js'); Assets::addScript('../lib/jquery/jquery.min.js');
CustomAssetViewDecorator::addScript('../lib/jquery-ui/jquery-ui.min.js'); Assets::addScript('../lib/jquery-ui/jquery-ui.min.js');
CustomAssetViewDecorator::addScript('../lib/mousetrap/mousetrap.min.js'); Assets::addScript('../lib/mousetrap/mousetrap.min.js');
CustomAssetViewDecorator::addScript('core.js'); Assets::addScript('core.js');
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -24,14 +24,14 @@ CustomAssetViewDecorator::addScript('core.js');
<nav id="top-nav"> <nav id="top-nav">
<div class="main-wrapper"> <div class="main-wrapper">
<?php $this->renderFile('top-navigation') ?> <?php \Chibi\View::render('top-navigation', $this->context) ?>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</nav> </nav>
<section id="content"> <section id="content">
<div class="main-wrapper"> <div class="main-wrapper">
<?= $this->renderView() ?> <?= \Chibi\View::render($this->context->viewName, $this->context) ?>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</section> </section>
@ -43,14 +43,14 @@ CustomAssetViewDecorator::addScript('core.js');
<span>Queries:&nbsp;<?= count(\Chibi\Database::getLogs()) ?></span> <span>Queries:&nbsp;<?= count(\Chibi\Database::getLogs()) ?></span>
<span><a href="<?= SZURU_LINK ?>">szurubooru&nbsp;v<?= SZURU_VERSION ?></a></span> <span><a href="<?= SZURU_LINK ?>">szurubooru&nbsp;v<?= SZURU_VERSION ?></a></span>
<?php if (PrivilegesHelper::confirm(Privilege::ListLogs)): ?> <?php if (PrivilegesHelper::confirm(Privilege::ListLogs)): ?>
<span><a href="<?= \Chibi\UrlHelper::route('log', 'list') ?>">Logs</a></span> <span><a href="<?= \Chibi\Router::linkTo(['LogController', 'listAction']) ?>">Logs</a></span>
<?php endif ?> <?php endif ?>
<hr> <hr>
</div> </div>
</footer> </footer>
<?php if ($this->config->misc->debugQueries): ?> <?php if (getConfig()->misc->debugQueries): ?>
<?= $this->renderFile('debug') ?> <?= \Chibi\View::render('debug', $this->context) ?>
<?php endif ?> <?php endif ?>
<div id="small-screen"></div> <div id="small-screen"></div>

View file

@ -8,7 +8,7 @@ $this->context->subTitle = 'latest logs';
<ul> <ul>
<?php foreach ($this->context->transport->logs as $log): ?> <?php foreach ($this->context->transport->logs as $log): ?>
<li> <li>
<a href="<?= \Chibi\UrlHelper::route('log', 'view', ['name' => $log]) ?>"> <a href="<?= \Chibi\Router::linkTo(['LogController', 'viewAction'], ['name' => $log]) ?>">
<?= $log ?> <?= $log ?>
</a> </a>
</li> </li>

View file

@ -1,19 +1,19 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('logs (' . $name . ')'); Assets::setSubTitle('logs (' . $this->context->transport->name . ')');
?> ?>
<?php if (empty($this->context->transport->lines)): ?> <?php if (empty($this->context->transport->lines)): ?>
<p class="alert alert-warning"> <p class="alert alert-warning">
This log is empty. <a href="<?= \Chibi\UrlHelper::route('log', 'list') ?>">Go back</a> This log is empty. <a href="<?= \Chibi\Router::linkTo(['LogController', 'listAction']) ?>">Go back</a>
</p> </p>
<?php else: ?> <?php else: ?>
<?php <?php
CustomAssetViewDecorator::addStylesheet('logs.css'); Assets::addStylesheet('logs.css');
CustomAssetViewDecorator::addScript('logs.js'); Assets::addScript('logs.js');
?> ?>
<form method="get" <form method="get"
action="<?= \Chibi\UrlHelper::route('log', 'view', ['name' => $this->context->transport->name]) ?>"> action="<?= \Chibi\Router::linkTo(['LogController', 'viewAction'], ['name' => $this->context->transport->name]) ?>">
Keep only lines that contain: Keep only lines that contain:
@ -27,5 +27,5 @@ CustomAssetViewDecorator::setSubTitle('logs (' . $name . ')');
<code><?= $this->context->transport->lines ?></code> <code><?= $this->context->transport->lines ?></code>
</div> </div>
<?php $this->renderFile('paginator') ?> <?php \Chibi\View::render('paginator', $this->context) ?>
<?php endif ?> <?php endif ?>

View file

@ -29,22 +29,21 @@ if (!function_exists('pageUrl'))
{ {
function pageUrl($page) function pageUrl($page)
{ {
$context = \Chibi\Registry::getContext(); $context = getContext();
$controller = $context->route->simpleControllerName; $destination = $context->route->destination;
$action = $context->route->simpleActionName;
$page = max(1, min($context->transport->paginator->pageCount, $page)); $page = max(1, min($context->transport->paginator->pageCount, $page));
$params = $context->route->arguments; $params = $context->route->arguments;
$params['page'] = $page; $params['page'] = $page;
return \Chibi\UrlHelper::route($controller, $action, $params); return \Chibi\Router::linkTo($destination, $params);
} }
} }
?> ?>
<?php if (!empty($pagesVisible)): ?> <?php if (!empty($pagesVisible)): ?>
<?php <?php
CustomAssetViewDecorator::addStylesheet('paginator.css'); Assets::addStylesheet('paginator.css');
if ($this->context->user->hasEnabledEndlessScrolling()) if ($this->context->user->hasEnabledEndlessScrolling())
CustomAssetViewDecorator::addScript('paginator-endless.js'); Assets::addScript('paginator-endless.js');
?> ?>
<nav class="paginator-wrapper"> <nav class="paginator-wrapper">

View file

@ -1,5 +1,5 @@
<form method="post" <form method="post"
action="<?= \Chibi\UrlHelper::route('post', 'edit', ['id' => $this->context->transport->post->id]) ?>" action="<?= \Chibi\Router::linkTo(['PostController', 'editAction'], ['id' => $this->context->transport->post->id]) ?>"
enctype="multipart/form-data" enctype="multipart/form-data"
class="edit-post"> class="edit-post">

View file

@ -1,4 +1,4 @@
<?php CustomAssetViewDecorator::setPageThumb(\Chibi\UrlHelper::route('post', 'thumb', ['name' => $this->context->transport->post->name])) ?> <?php Assets::setPageThumb(\Chibi\Router::linkTo(['PostController', 'thumbAction'], ['name' => $this->context->transport->post->name])) ?>
<?php $post = $this->context->transport->post ?> <?php $post = $this->context->transport->post ?>
<?php if ($post->type == PostType::Image): ?> <?php if ($post->type == PostType::Image): ?>
@ -7,7 +7,7 @@
<a href="<?= $this->context->imageLink ?>"> <a href="<?= $this->context->imageLink ?>">
<?php endif ?> <?php endif ?>
<img src="<?= \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $post->name]) ?>" alt="<?= $post->name ?>"/> <img src="<?= \Chibi\Router::linkTo(['PostController', 'retrieveAction'], ['name' => $post->name]) ?>" alt="<?= $post->name ?>"/>
<?php if (!empty($this->context->imageLink)): ?> <?php if (!empty($this->context->imageLink)): ?>
</a> </a>
@ -19,9 +19,9 @@
type="<?= $post->mimeType ?>" type="<?= $post->mimeType ?>"
width="<?= $post->imageWidth ?>" width="<?= $post->imageWidth ?>"
height="<?= $post->imageHeight ?>" height="<?= $post->imageHeight ?>"
data="<?= \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $post->name]) ?>"> data="<?= \Chibi\Router::linkTo(['PostController', 'retrieveAction'], ['name' => $post->name]) ?>">
<param name="movie" value="<?= \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $post->name]) ?>"/> <param name="movie" value="<?= \Chibi\Router::linkTo(['PostController', 'retrieveAction'], ['name' => $post->name]) ?>"/>
<param name="wmode" value="opaque"/> <param name="wmode" value="opaque"/>
</object> </object>
@ -40,7 +40,7 @@
<video style="max-width: 100%" controls> <video style="max-width: 100%" controls>
<source <source
type="<?= $post->mimeType ?>" type="<?= $post->mimeType ?>"
src="<?= \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $post->name]) ?>"> src="<?= \Chibi\Router::linkTo(['PostController', 'retrieveAction'], ['name' => $post->name]) ?>">
Your browser doesn't support HTML5 &lt;video&gt; tag. Your browser doesn't support HTML5 &lt;video&gt; tag.
</video> </video>

View file

@ -1,35 +1,35 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('posts'); Assets::setSubTitle('posts');
$tabs = []; $tabs = [];
$activeTab = 0; $activeTab = 0;
if (PrivilegesHelper::confirm(Privilege::ListPosts)) if (PrivilegesHelper::confirm(Privilege::ListPosts))
$tabs []= ['All posts', \Chibi\UrlHelper::route('post', 'list')]; $tabs []= ['All posts', \Chibi\Router::linkTo(['PostController', 'listAction'])];
if (PrivilegesHelper::confirm(Privilege::ListPosts)) if (PrivilegesHelper::confirm(Privilege::ListPosts))
{ {
$tabs []= ['Random', \Chibi\UrlHelper::route('post', 'random')]; $tabs []= ['Random', \Chibi\Router::linkTo(['PostController', 'randomAction'])];
if ($this->context->route->simpleActionName == 'random') if ($this->context->simpleActionName == 'random')
$activeTab = count($tabs) - 1; $activeTab = count($tabs) - 1;
} }
if (PrivilegesHelper::confirm(Privilege::ListPosts)) if (PrivilegesHelper::confirm(Privilege::ListPosts))
{ {
$tabs []= ['Favorites', \Chibi\UrlHelper::route('post', 'favorites')]; $tabs []= ['Favorites', \Chibi\Router::linkTo(['PostController', 'favoritesAction'])];
if ($this->context->route->simpleActionName == 'favorites') if ($this->context->simpleActionName == 'favorites')
$activeTab = count($tabs) - 1; $activeTab = count($tabs) - 1;
} }
if (PrivilegesHelper::confirm(Privilege::ListPosts)) if (PrivilegesHelper::confirm(Privilege::ListPosts))
{ {
$tabs []= ['Upvoted', \Chibi\UrlHelper::route('post', 'upvoted')]; $tabs []= ['Upvoted', \Chibi\Router::linkTo(['PostController', 'upvotedAction'])];
if ($this->context->route->simpleActionName == 'upvoted') if ($this->context->simpleActionName == 'upvoted')
$activeTab = count($tabs) - 1; $activeTab = count($tabs) - 1;
} }
if (PrivilegesHelper::confirm(Privilege::MassTag)) if (PrivilegesHelper::confirm(Privilege::MassTag))
{ {
$tabs []= ['Mass tag', \Chibi\UrlHelper::route('post', 'list', [ $tabs []= ['Mass tag', \Chibi\Router::linkTo(['PostController', 'listAction'], [
'source' => 'mass-tag', 'source' => 'mass-tag',
'query' => isset($this->context->transport->searchQuery) 'query' => isset($this->context->transport->searchQuery)
? htmlspecialchars($this->context->transport->searchQuery) ? htmlspecialchars($this->context->transport->searchQuery)
@ -67,5 +67,5 @@ if (PrivilegesHelper::confirm(Privilege::MassTag))
</nav> </nav>
<div class="tab-content"> <div class="tab-content">
<?php $this->renderFile('post-list') ?> <?php \Chibi\View::render('post-list', $this->context) ?>
</div> </div>

View file

@ -1,19 +1,19 @@
<?php <?php
CustomAssetViewDecorator::addStylesheet('post-list.css'); Assets::addStylesheet('post-list.css');
CustomAssetViewDecorator::addScript('post-list.js'); Assets::addScript('post-list.js');
?> ?>
<?php if (isset($this->context->source) <?php if (isset($this->context->source)
and $this->context->source == 'mass-tag' and $this->context->source == 'mass-tag'
and PrivilegesHelper::confirm(Privilege::MassTag)): ?> and PrivilegesHelper::confirm(Privilege::MassTag)): ?>
<?php $this->renderFile('tag-mass-tag') ?> <?php \Chibi\View::render('tag-mass-tag', $this->context) ?>
<?php endif ?> <?php endif ?>
<?php if (!empty($this->context->transport->message)): ?> <?php if (!empty($this->context->transport->message)): ?>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<?php elseif (empty($this->context->transport->posts)): ?> <?php elseif (empty($this->context->transport->posts)): ?>
<p class="alert alert-warning">No posts to show.</p> <p class="alert alert-warning">No posts to show.</p>
<?php else: ?> <?php else: ?>
@ -21,11 +21,11 @@ CustomAssetViewDecorator::addScript('post-list.js');
<div class="posts paginator-content"> <div class="posts paginator-content">
<?php foreach ($this->context->transport->posts as $post): ?> <?php foreach ($this->context->transport->posts as $post): ?>
<?php $this->context->post = $post ?> <?php $this->context->post = $post ?>
<?= $this->renderFile('post-small') ?> <?php \Chibi\View::render('post-small', $this->context) ?>
<?php endforeach ?> <?php endforeach ?>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<?php $this->renderFile('paginator') ?> <?php \Chibi\View::render('paginator', $this->context) ?>
<?php endif ?> <?php endif ?>

View file

@ -1,5 +1,5 @@
<?php <?php
CustomAssetViewDecorator::addStylesheet('post-small.css'); Assets::addStylesheet('post-small.css');
$classNames = $classNames =
[ [
@ -28,7 +28,7 @@ if ($masstag)
<div class="<?= implode(' ', $classNames) ?>"> <div class="<?= implode(' ', $classNames) ?>">
<?php if ($masstag): ?> <?php if ($masstag): ?>
<a class="toggle-tag" <a class="toggle-tag"
href="<?= \Chibi\UrlHelper::route('post', 'toggle-tag', [ href="<?= \Chibi\Router::linkTo(['PostController', 'toggleTagAction'], [
'id' => $this->context->post->id, 'id' => $this->context->post->id,
'tag' => $this->context->additionalInfo, 'tag' => $this->context->additionalInfo,
'enable' => '_enable_']) ?>" 'enable' => '_enable_']) ?>"
@ -44,11 +44,11 @@ if ($masstag)
<?php if ($this->context->user->hasEnabledPostTagTitles()): ?> <?php if ($this->context->user->hasEnabledPostTagTitles()): ?>
title="<?= TextHelper::reprTags($this->context->post->getTags()) ?>" title="<?= TextHelper::reprTags($this->context->post->getTags()) ?>"
<?php endif ?> <?php endif ?>
href="<?= \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->post->id]) ?>"> href="<?= \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => $this->context->post->id]) ?>">
<img <img
class="thumb" class="thumb"
src="<?= \Chibi\UrlHelper::route('post', 'thumb', ['name' => $this->context->post->name]) ?>" src="<?= \Chibi\Router::linkTo(['PostController', 'thumbAction'], ['name' => $this->context->post->name]) ?>"
alt="@<?= $this->context->post->id ?>"/> alt="@<?= $this->context->post->id ?>"/>
<?php <?php

View file

@ -1,9 +1,9 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('upload'); Assets::setSubTitle('upload');
CustomAssetViewDecorator::addStylesheet('post-upload.css'); Assets::addStylesheet('post-upload.css');
CustomAssetViewDecorator::addScript('post-upload.js'); Assets::addScript('post-upload.js');
CustomAssetViewDecorator::addStylesheet('../lib/tagit/jquery.tagit.css'); Assets::addStylesheet('../lib/tagit/jquery.tagit.css');
CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js'); Assets::addScript('../lib/tagit/jquery.tagit.js');
?> ?>
<div id="sidebar"> <div id="sidebar">
@ -37,7 +37,7 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div id="upload-step2" data-redirect-url="<?= \Chibi\UrlHelper::route('post', 'list') ?>"> <div id="upload-step2" data-redirect-url="<?= \Chibi\Router::linkTo(['PostController', 'listAction']) ?>">
<hr> <hr>
<div class="posts"> <div class="posts">
@ -51,7 +51,7 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
<div id="post-template" class="post"> <div id="post-template" class="post">
<p class="alert alert-error">Some kind of error</p> <p class="alert alert-error">Some kind of error</p>
<img class="thumbnail" src="<?= \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="Thumbnail"/> <img class="thumbnail" src="<?= \Chibi\Util\Url::makeAbsolute('/media/img/pixel.gif') ?>" alt="Thumbnail"/>
<div class="form-wrapper"> <div class="form-wrapper">
<div class="ops"> <div class="ops">
@ -68,7 +68,7 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
</a> </a>
</div> </div>
<form action="<?= \Chibi\UrlHelper::route('post', 'upload') ?>" method="post"> <form action="<?= \Chibi\Router::linkTo(['PostController', 'uploadAction']) ?>" method="post">
<div class="form-row file-name"> <div class="form-row file-name">
<label>File:</label> <label>File:</label>
<strong>filename.jpg</strong> <strong>filename.jpg</strong>
@ -121,4 +121,4 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
</div> </div>
</div> </div>
<img id="lightbox" src="<?= \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="Preview"/> <img id="lightbox" src="<?= \Chibi\Util\Url::makeAbsolute('/media/img/pixel.gif') ?>" alt="Preview"/>

View file

@ -2,11 +2,11 @@
$subTitle = sprintf('showing %s&nbsp;&ndash;%s', $subTitle = sprintf('showing %s&nbsp;&ndash;%s',
TextHelper::reprPost($this->context->transport->post), TextHelper::reprPost($this->context->transport->post),
TextHelper::reprTags($this->context->transport->post->getTags())); TextHelper::reprTags($this->context->transport->post->getTags()));
CustomAssetViewDecorator::setSubTitle($subTitle); Assets::setSubTitle($subTitle);
CustomAssetViewDecorator::addStylesheet('post-view.css'); Assets::addStylesheet('post-view.css');
CustomAssetViewDecorator::addScript('post-view.js'); Assets::addScript('post-view.js');
CustomAssetViewDecorator::addStylesheet('../lib/tagit/jquery.tagit.css'); Assets::addStylesheet('../lib/tagit/jquery.tagit.css');
CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js'); Assets::addScript('../lib/tagit/jquery.tagit.js');
$editPostPrivileges = [ $editPostPrivileges = [
Privilege::EditPostSafety, Privilege::EditPostSafety,
@ -30,7 +30,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<nav id="around"> <nav id="around">
<div class="left"> <div class="left">
<?php if ($this->context->transport->nextPostId): ?> <?php if ($this->context->transport->nextPostId): ?>
<a href="<?= \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->transport->nextPostId]) ?>"> <a href="<?= \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => $this->context->transport->nextPostId]) ?>">
<?php else: ?> <?php else: ?>
<a class="disabled"> <a class="disabled">
<?php endif ?> <?php endif ?>
@ -41,7 +41,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="right"> <div class="right">
<?php if ($this->context->transport->prevPostId): ?> <?php if ($this->context->transport->prevPostId): ?>
<a href="<?= \Chibi\UrlHelper::route('post', 'view', ['id' => $this->context->transport->prevPostId]) ?>"> <a href="<?= \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => $this->context->transport->prevPostId]) ?>">
<?php else: ?> <?php else: ?>
<a class="disabled"> <a class="disabled">
<?php endif ?> <?php endif ?>
@ -55,7 +55,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php if (!empty($this->context->transport->lastSearchQuery)): ?> <?php if (!empty($this->context->transport->lastSearchQuery)): ?>
<div class="text"> <div class="text">
Current&nbsp;search:<br/> Current&nbsp;search:<br/>
<a href="<?= \Chibi\UrlHelper::route('post', 'list', [ <a href="<?= \Chibi\Router::linkTo(['PostController', 'listAction'], [
'query' => $this->context->transport->lastSearchQuery]) ?>"> 'query' => $this->context->transport->lastSearchQuery]) ?>">
<?= $this->context->transport->lastSearchQuery ?> <?= $this->context->transport->lastSearchQuery ?>
</a> </a>
@ -70,7 +70,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php uasort($tags, function($a, $b) { return strnatcasecmp($a->name, $b->name); }) ?> <?php uasort($tags, function($a, $b) { return strnatcasecmp($a->name, $b->name); }) ?>
<?php foreach ($tags as $tag): ?> <?php foreach ($tags as $tag): ?>
<li title="<?= $tag->name ?>"> <li title="<?= $tag->name ?>">
<a href="<?= \Chibi\UrlHelper::route('post', 'list', ['query' => $tag->name]) ?>"><?= $tag->name ?></a> <a href="<?= \Chibi\Router::linkTo(['PostController', 'listAction'], ['query' => $tag->name]) ?>"><?= $tag->name ?></a>
<span class="count"><?= TextHelper::useDecimalUnits($tag->getPostCount()) ?></span> <span class="count"><?= TextHelper::useDecimalUnits($tag->getPostCount()) ?></span>
</li> </li>
<?php endforeach ?> <?php endforeach ?>
@ -84,14 +84,14 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php $uploader = $this->context->transport->post->getUploader() ?> <?php $uploader = $this->context->transport->post->getUploader() ?>
<?php if ($uploader): ?> <?php if ($uploader): ?>
<span class="value" title="<?= $val = $uploader->name ?>"> <span class="value" title="<?= $val = $uploader->name ?>">
<a href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $uploader->name]) ?>"> <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $uploader->name]) ?>">
<img src="<?= htmlentities($uploader->getAvatarUrl(24)) ?>" alt="<?= $uploader->name ?>"/> <img src="<?= htmlentities($uploader->getAvatarUrl(24)) ?>" alt="<?= $uploader->name ?>"/>
<?= $val ?> <?= $val ?>
</a> </a>
</span> </span>
<?php else: ?> <?php else: ?>
<span class="value" title="<?= UserModel::getAnonymousName() ?>"> <span class="value" title="<?= UserModel::getAnonymousName() ?>">
<img src="<?= \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="<?= UserModel::getAnonymousName() ?>"/> <img src="<?= \Chibi\Util\Url::makeAbsolute('/media/img/pixel.gif') ?>" alt="<?= UserModel::getAnonymousName() ?>"/>
<?= UserModel::getAnonymousName() ?> <?= UserModel::getAnonymousName() ?>
</span> </span>
<?php endif ?> <?php endif ?>
@ -135,7 +135,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<span class="value"> <span class="value">
<?= $this->context->transport->post->score ?> <?= $this->context->transport->post->score ?>
<?php $scoreLink = function($score) { return \Chibi\UrlHelper::route('post', 'score', ['id' => $this->context->transport->post->id, 'score' => $score]); } ?> <?php $scoreLink = function($score) { return \Chibi\Router::linkTo(['PostController', 'scoreAction'], ['id' => $this->context->transport->post->id, 'score' => $score]); } ?>
<?php if (PrivilegesHelper::confirm(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?> <?php if (PrivilegesHelper::confirm(Privilege::ScorePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
<?php if ($this->context->score === 1): ?> <?php if ($this->context->score === 1): ?>
<a class="simple-action selected" href="<?= $scoreLink(0) ?>"> <a class="simple-action selected" href="<?= $scoreLink(0) ?>">
@ -162,7 +162,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="unit hl-options"> <div class="unit hl-options">
<?php if ($this->context->transport->post->type != PostType::Youtube): ?> <?php if ($this->context->transport->post->type != PostType::Youtube): ?>
<div class="hl-option"> <div class="hl-option">
<a href="<?= \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" title="Download"> <a href="<?= \Chibi\Router::linkTo(['PostController', 'retrieveAction'], ['name' => $this->context->transport->post->name]) ?>" title="Download">
<i class="icon-dl"></i> <i class="icon-dl"></i>
<span> <span>
<?php <?php
@ -179,12 +179,12 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php if (PrivilegesHelper::confirm(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?> <?php if (PrivilegesHelper::confirm(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
<div class="hl-option"> <div class="hl-option">
<?php if (!$this->context->favorite): ?> <?php if (!$this->context->favorite): ?>
<a class="add-fav icon simple-action" href="<?= \Chibi\UrlHelper::route('post', 'add-favorite', ['id' => $this->context->transport->post->id]) ?>"> <a class="add-fav icon simple-action" href="<?= \Chibi\Router::linkTo(['PostController', 'addFavoriteAction'], ['id' => $this->context->transport->post->id]) ?>">
<i class="icon-fav"></i> <i class="icon-fav"></i>
<span>Add to favorites</span> <span>Add to favorites</span>
</a> </a>
<?php else: ?> <?php else: ?>
<a class="rem-fav icon simple-action" href="<?= \Chibi\UrlHelper::route('post', 'rem-favorite', ['id' => $this->context->transport->post->id]) ?>"> <a class="rem-fav icon simple-action" href="<?= \Chibi\Router::linkTo(['PostController', 'removeFavoriteAction'], ['id' => $this->context->transport->post->id]) ?>">
<i class="icon-fav"></i> <i class="icon-fav"></i>
<span>Remove from favorites</span> <span>Remove from favorites</span>
</a> </a>
@ -208,7 +208,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<ul> <ul>
<?php foreach ($this->context->transport->post->getFavorites() as $user): ?> <?php foreach ($this->context->transport->post->getFavorites() as $user): ?>
<li> <li>
<a href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $user->name]) ?>" title="<?= $user->name ?>"> <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $user->name]) ?>" title="<?= $user->name ?>">
<img src="<?= htmlspecialchars($user->getAvatarUrl()) ?>" alt="<?= $user->name ?>"> <img src="<?= htmlspecialchars($user->getAvatarUrl()) ?>" alt="<?= $user->name ?>">
</a> </a>
</li> </li>
@ -223,7 +223,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<ul> <ul>
<?php foreach ($this->context->transport->post->getRelations() as $relatedPost): ?> <?php foreach ($this->context->transport->post->getRelations() as $relatedPost): ?>
<li> <li>
<a href="<?= \Chibi\UrlHelper::route('post', 'view', ['id' => $relatedPost->id]) ?>"> <a href="<?= \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => $relatedPost->id]) ?>">
@<?= $relatedPost->id ?> @<?= $relatedPost->id ?>
</a> </a>
</li> </li>
@ -241,9 +241,9 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[ [
'class' => 'feature', 'class' => 'feature',
'text' => 'Feature on main page', 'text' => 'Feature on main page',
'simple-action' => \Chibi\UrlHelper::route('post', 'feature', ['id' => $this->context->transport->post->id]), 'simple-action' => \Chibi\Router::linkTo(['PostController', 'featureAction'], ['id' => $this->context->transport->post->id]),
'data-confirm-text' => 'Are you sure you want to feature this post on the main page?', 'data-confirm-text' => 'Are you sure you want to feature this post on the main page?',
'data-redirect-url' => \Chibi\UrlHelper::route('index', 'index'), 'data-redirect-url' => \Chibi\Router::linkTo(['IndexController', 'indexAction']),
]; ];
} }
@ -264,7 +264,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[ [
'class' => 'flag', 'class' => 'flag',
'text' => 'Flag for moderator attention', 'text' => 'Flag for moderator attention',
'simple-action' => \Chibi\UrlHelper::route('post', 'flag', ['id' => $this->context->transport->post->id]), 'simple-action' => \Chibi\Router::linkTo(['PostController', 'flagAction'], ['id' => $this->context->transport->post->id]),
'data-confirm-text' => 'Are you sure you want to flag this post?', 'data-confirm-text' => 'Are you sure you want to flag this post?',
]; ];
} }
@ -278,7 +278,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[ [
'class' => 'unhide', 'class' => 'unhide',
'text' => 'Unhide', 'text' => 'Unhide',
'simple-action' => \Chibi\UrlHelper::route('post', 'unhide', ['id' => $this->context->transport->post->id]), 'simple-action' => \Chibi\Router::linkTo(['PostController', 'unhideAction'], ['id' => $this->context->transport->post->id]),
]; ];
} }
else else
@ -287,7 +287,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[ [
'class' => 'hide', 'class' => 'hide',
'text' => 'Hide', 'text' => 'Hide',
'simple-action' => \Chibi\UrlHelper::route('post', 'hide', ['id' => $this->context->transport->post->id]), 'simple-action' => \Chibi\Router::linkTo(['PostController', 'hideAction'], ['id' => $this->context->transport->post->id]),
]; ];
} }
} }
@ -298,31 +298,31 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[ [
'class' => 'delete', 'class' => 'delete',
'text' => 'Delete', 'text' => 'Delete',
'simple-action' => \Chibi\UrlHelper::route('post', 'delete', ['id' => $this->context->transport->post->id]), 'simple-action' => \Chibi\Router::linkTo(['PostController', 'deleteAction'], ['id' => $this->context->transport->post->id]),
'data-confirm-text' => 'Are you sure you want to delete this post?', 'data-confirm-text' => 'Are you sure you want to delete this post?',
'data-redirect-url' => \Chibi\UrlHelper::route('post', 'list'), 'data-redirect-url' => \Chibi\Router::linkTo(['PostController', 'listAction']),
]; ];
} }
$this->context->options = $options; $this->context->options = $options;
$this->renderFile('sidebar-options'); \Chibi\View::render('sidebar-options', $this->context);
?> ?>
</div> </div>
<div id="inner-content"> <div id="inner-content">
<?php if ($canEditAnything): ?> <?php if ($canEditAnything): ?>
<div class="unit edit-post"> <div class="unit edit-post">
<?php $this->renderFile('post-edit') ?> <?php \Chibi\View::render('post-edit', $this->context) ?>
</div> </div>
<?php endif ?> <?php endif ?>
<div class="post-wrapper post-type-<?= PostType::toString($this->context->transport->post->type) ?>"> <div class="post-wrapper post-type-<?= PostType::toString($this->context->transport->post->type) ?>">
<?= $this->renderFile('post-file-render') ?> <?= \Chibi\View::render('post-file-render', $this->context) ?>
</div> </div>
<?php <?php
CustomAssetViewDecorator::addStylesheet('comment-list.css'); Assets::addStylesheet('comment-list.css');
CustomAssetViewDecorator::addStylesheet('comment-small.css'); Assets::addStylesheet('comment-small.css');
?> ?>
<div class="comments-wrapper"> <div class="comments-wrapper">
<?php if (!empty($this->context->transport->post->getComments())): ?> <?php if (!empty($this->context->transport->post->getComments())): ?>
@ -331,7 +331,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="comments"> <div class="comments">
<?php foreach ($this->context->transport->post->getComments() as $comment): ?> <?php foreach ($this->context->transport->post->getComments() as $comment): ?>
<?php $this->context->comment = $comment ?> <?php $this->context->comment = $comment ?>
<?= $this->renderFile('comment-small') ?> <?= \Chibi\View::render('comment-small', $this->context) ?>
<?php endforeach ?> <?php endforeach ?>
</div> </div>
</div> </div>
@ -340,7 +340,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php if (PrivilegesHelper::confirm(Privilege::AddComment)): ?> <?php if (PrivilegesHelper::confirm(Privilege::AddComment)): ?>
<div class="unit comment-add"> <div class="unit comment-add">
<?php $this->renderFile('comment-add') ?> <?php \Chibi\View::render('comment-add', $this->context) ?>
</div> </div>
<?php endif ?> <?php endif ?>
</div> </div>

View file

@ -1,25 +1,26 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('tags'); Assets::setSubTitle('tags');
CustomAssetViewDecorator::addStylesheet('tag-list.css'); Assets::addStylesheet('tag-list.css');
$tabs = []; $tabs = [];
if (PrivilegesHelper::confirm(Privilege::ListTags)) $tabs['list'] = 'List'; if (PrivilegesHelper::confirm(Privilege::ListTags)) $tabs['list'] = ['List', 'listAction'];
if (PrivilegesHelper::confirm(Privilege::RenameTags)) $tabs['rename'] = 'Rename'; if (PrivilegesHelper::confirm(Privilege::RenameTags)) $tabs['rename'] = ['Rename', 'renameAction'];
if (PrivilegesHelper::confirm(Privilege::MergeTags)) $tabs['merge'] = 'Merge'; if (PrivilegesHelper::confirm(Privilege::MergeTags)) $tabs['merge'] = ['Merge', 'mergeAction'];
if (PrivilegesHelper::confirm(Privilege::MassTag)) $tabs['mass-tag-redirect'] = 'Mass tag'; if (PrivilegesHelper::confirm(Privilege::MassTag)) $tabs['mass-tag-redirect'] = ['Mass tag', 'massTagRedirectAction'];
$showTabs = count($tabs) > 1; $showTabs = count($tabs) > 1;
?> ?>
<?php if ($showTabs): ?> <?php if ($showTabs): ?>
<nav class="tabs"> <nav class="tabs">
<ul> <ul>
<?php foreach ($tabs as $tab => $name): ?> <?php foreach ($tabs as $tab => $item): ?>
<?php if ($this->context->route->simpleActionName == $tab): ?> <?php list ($name, $action) = $item ?>
<?php if ($this->context->simpleActionName == $tab): ?>
<li class="selected <?= $tab ?>"> <li class="selected <?= $tab ?>">
<?php else: ?> <?php else: ?>
<li class="<?= $tab ?>"> <li class="<?= $tab ?>">
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('tag', $tab) ?>"> <a href="<?= \Chibi\Router::linkTo(['TagController', $action]) ?>">
<?= $name ?> <?= $name ?>
</a> </a>
</li> </li>
@ -30,20 +31,20 @@ $showTabs = count($tabs) > 1;
<div class="tab-content"> <div class="tab-content">
<?php endif ?> <?php endif ?>
<?php if ($this->context->route->simpleActionName == 'merge'): ?> <?php if ($this->context->simpleActionName == 'merge'): ?>
<?php $this->renderFile('tag-merge') ?> <?php \Chibi\View::render('tag-merge', $this->context) ?>
<?php endif ?> <?php endif ?>
<?php if ($this->context->route->simpleActionName == 'rename'): ?> <?php if ($this->context->simpleActionName == 'rename'): ?>
<?php $this->renderFile('tag-rename') ?> <?php \Chibi\View::render('tag-rename', $this->context) ?>
<?php endif ?> <?php endif ?>
<?php if ($this->context->route->simpleActionName == 'list'): ?> <?php if ($this->context->simpleActionName == 'list'): ?>
<?php $this->renderFile('tag-list') ?> <?php \Chibi\View::render('tag-list', $this->context) ?>
<?php endif ?> <?php endif ?>
<?php if ($this->context->route->simpleActionName == 'mass-tag-redirect'): ?> <?php if ($this->context->simpleActionName == 'mass-tag-redirect'): ?>
<?php $this->renderFile('tag-mass-tag') ?> <?php \Chibi\View::render('tag-mass-tag', $this->context) ?>
<?php endif ?> <?php endif ?>
<?php if ($showTabs): ?> <?php if ($showTabs): ?>

View file

@ -16,7 +16,7 @@
<?php else: ?> <?php else: ?>
<li> <li>
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('tag', 'list', ['filter' => $key]) ?>"><?= $text ?></a> <a href="<?= \Chibi\Router::linkTo(['TagController', 'listAction'], ['filter' => $key]) ?>"><?= $text ?></a>
</li> </li>
<?php endforeach ?> <?php endforeach ?>
</ul> </ul>
@ -28,7 +28,7 @@
<?php $max = $this->context->highestUsage ?> <?php $max = $this->context->highestUsage ?>
<?php $add = 0. ?> <?php $add = 0. ?>
<?php $mul = 10. / max(1, log(max(1, $max))) ?> <?php $mul = 10. / max(1, log(max(1, $max))) ?>
<?php $url = \Chibi\UrlHelper::route('post', 'list', ['query' => '_query_']) ?> <?php $url = \Chibi\Router::linkTo(['PostController', 'listAction'], ['query' => '_query_']) ?>
<div class="tags paginator-content"> <div class="tags paginator-content">
<ul> <ul>
<?php foreach ($this->context->transport->tags as $tag): ?> <?php foreach ($this->context->transport->tags as $tag): ?>
@ -43,5 +43,5 @@
</ul> </ul>
</div> </div>
<?php $this->renderFile('paginator') ?> <?php \Chibi\View::render('paginator', $this->context) ?>
<?php endif ?> <?php endif ?>

View file

@ -1,5 +1,5 @@
<div class="form-wrapper"> <div class="form-wrapper">
<form method="post" action="<?= \Chibi\UrlHelper::route('tag', 'mass-tag-redirect') ?>"> <form method="post" action="<?= \Chibi\Router::linkTo(['TagController', 'massTagRedirectAction']) ?>">
<h1>mass tag</h1> <h1>mass tag</h1>
<div class="form-row"> <div class="form-row">

View file

@ -1,5 +1,5 @@
<div class="form-wrapper"> <div class="form-wrapper">
<form method="post" action="<?= \Chibi\UrlHelper::route('tag', 'merge') ?>"> <form method="post" action="<?= \Chibi\Router::linkTo(['TagController', 'mergeAction']) ?>">
<h1>merge tags</h1> <h1>merge tags</h1>
<div class="form-row"> <div class="form-row">
@ -18,7 +18,7 @@
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row"> <div class="form-row">
<label></label> <label></label>

View file

@ -1,5 +1,5 @@
<div class="form-wrapper"> <div class="form-wrapper">
<form method="post" action="<?= \Chibi\UrlHelper::route('tag', 'rename') ?>"> <form method="post" action="<?= \Chibi\Router::linkTo(['TagController', 'renameAction']) ?>">
<h1>rename tags</h1> <h1>rename tags</h1>
<div class="form-row"> <div class="form-row">
@ -18,7 +18,7 @@
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row"> <div class="form-row">
<label></label> <label></label>

View file

@ -2,16 +2,8 @@
<?php <?php
$nav = []; $nav = [];
if ($this->context->route) $activeController = $this->context->simpleControllerName;
{ $activeAction = $this->context->simpleActionName;
$activeController = $this->context->route->simpleControllerName;
$activeAction = $this->context->route->simpleActionName;
}
else
{
$activeController = null;
$activeAction = null;
}
$registerNavItem = function ($text, $link, $active = false) use (&$nav) $registerNavItem = function ($text, $link, $active = false) use (&$nav)
{ {
@ -23,14 +15,14 @@
$registerNavItem( $registerNavItem(
'Home', 'Home',
\Chibi\UrlHelper::route('index', 'index'), \Chibi\Router::linkTo(['IndexController', 'indexAction']),
$activeController == 'index' and $activeAction == 'index'); $activeController == 'index' and $activeAction == 'index');
if (PrivilegesHelper::confirm(Privilege::ListPosts)) if (PrivilegesHelper::confirm(Privilege::ListPosts))
{ {
$registerNavItem( $registerNavItem(
'Browse', 'Browse',
\Chibi\UrlHelper::route('post', 'list'), \Chibi\Router::linkTo(['PostController', 'listAction']),
$activeController == 'post' and $activeAction != 'upload'); $activeController == 'post' and $activeAction != 'upload');
} }
@ -38,7 +30,7 @@
{ {
$registerNavItem( $registerNavItem(
'Upload', 'Upload',
\Chibi\UrlHelper::route('post', 'upload'), \Chibi\Router::linkTo(['PostController', 'uploadAction']),
$activeController == 'post' and $activeAction == 'upload'); $activeController == 'post' and $activeAction == 'upload');
} }
@ -46,7 +38,7 @@
{ {
$registerNavItem( $registerNavItem(
'Comments', 'Comments',
\Chibi\UrlHelper::route('comment', 'list'), \Chibi\Router::linkTo(['CommentController', 'listAction']),
$activeController == 'comment'); $activeController == 'comment');
} }
@ -54,7 +46,7 @@
{ {
$registerNavItem( $registerNavItem(
'Tags', 'Tags',
\Chibi\UrlHelper::route('tag', 'list'), \Chibi\Router::linkTo(['TagController', 'listAction']),
$activeController == 'tag'); $activeController == 'tag');
} }
@ -62,7 +54,7 @@
{ {
$registerNavItem( $registerNavItem(
'Users', 'Users',
\Chibi\UrlHelper::route('user', 'list'), \Chibi\Router::linkTo(['UserController', 'listAction']),
$activeController == 'user' and $activeAction != 'registration' and $activeController == 'user' and $activeAction != 'registration' and
(!isset($this->context->route->arguments['name']) or (!isset($this->context->route->arguments['name']) or
$this->context->route->arguments['name'] != $this->context->user->name)); $this->context->route->arguments['name'] != $this->context->user->name));
@ -72,32 +64,32 @@
{ {
$registerNavItem( $registerNavItem(
'Log in', 'Log in',
\Chibi\UrlHelper::route('auth', 'login'), \Chibi\Router::linkTo(['AuthController', 'loginAction']),
$activeController == 'auth' and $activeAction == 'login'); $activeController == 'auth' and $activeAction == 'login');
$registerNavItem( $registerNavItem(
'Register', 'Register',
\Chibi\UrlHelper::route('user', 'registration'), \Chibi\Router::linkTo(['UserController', 'registrationAction']),
$activeController == 'user' and $activeAction == 'registration'); $activeController == 'user' and $activeAction == 'registration');
} }
else else
{ {
$registerNavItem( $registerNavItem(
'My account', 'My account',
\Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->user->name]), \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $this->context->user->name]),
$activeController == 'user' and isset($this->context->route->arguments['name']) and $activeController == 'user' and isset($this->context->route->arguments['name']) and
$this->context->route->arguments['name'] == $this->context->user->name); $this->context->route->arguments['name'] == $this->context->user->name);
$registerNavItem( $registerNavItem(
'Log out', 'Log out',
\Chibi\UrlHelper::route('auth', 'logout')); \Chibi\Router::linkTo(['AuthController', 'logoutAction']));
} }
if (!empty($this->config->help->title)) if (!empty(getConfig()->help->title))
{ {
$registerNavItem( $registerNavItem(
$this->config->help->title, getConfig()->help->title,
\Chibi\UrlHelper::route('index', 'help'), \Chibi\Router::linkTo(['IndexController', 'helpAction']),
$activeController == 'index' and $activeAction == 'help'); $activeController == 'index' and $activeAction == 'help');
} }
@ -123,7 +115,7 @@
<li class="safety-<?= TextCaseConverter::convert(PostSafety::toString($safety), TextCaseConverter::CAMEL_CASE, TextCaseConverter::SPINAL_CASE) ?>"> <li class="safety-<?= TextCaseConverter::convert(PostSafety::toString($safety), TextCaseConverter::CAMEL_CASE, TextCaseConverter::SPINAL_CASE) ?>">
<a class="<?= $this->context->user->hasEnabledSafety($safety) ? 'enabled' : 'disabled' ?>" <a class="<?= $this->context->user->hasEnabledSafety($safety) ? 'enabled' : 'disabled' ?>"
href="<?= \Chibi\UrlHelper::route('user', 'toggle-safety', ['safety' => $safety]) ?>" href="<?= \Chibi\Router::linkTo(['UserController', 'toggleSafetyAction'], ['safety' => $safety]) ?>"
title="Searching <?= PostSafety::toDisplayString($safety) ?> posts: <?= $this->context->user->hasEnabledSafety($safety) ? 'enabled' : 'disabled' ?>"> title="Searching <?= PostSafety::toDisplayString($safety) ?> posts: <?= $this->context->user->hasEnabledSafety($safety) ? 'enabled' : 'disabled' ?>">
<span><?= ucfirst(PostSafety::toDisplayString($safety)) ?></span> <span><?= ucfirst(PostSafety::toDisplayString($safety)) ?></span>
@ -138,7 +130,7 @@
<?php endif ?> <?php endif ?>
<li class="search"> <li class="search">
<form name="search" action="<?= \Chibi\UrlHelper::route('post', 'list') ?>" method="get"> <form name="search" action="<?= \Chibi\Router::linkTo(['PostController', 'listAction']) ?>" method="get">
<input <input
class="autocomplete" class="autocomplete"

View file

@ -1,5 +1,5 @@
<form <form
action="<?= \Chibi\UrlHelper::route('user', 'delete', ['name' => $this->context->transport->user->name]) ?>" action="<?= \Chibi\Router::linkTo(['UserController', 'deleteAction'], ['name' => $this->context->transport->user->name]) ?>"
method="post" method="post"
class="delete confirmable" class="delete confirmable"
autocomplete="off" autocomplete="off"
@ -16,7 +16,7 @@
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row"> <div class="form-row">
<label></label> <label></label>

View file

@ -1,4 +1,4 @@
<form action="<?= \Chibi\UrlHelper::route('user', 'edit', ['name' => $this->context->transport->user->name]) ?>" method="post" class="edit" autocomplete="off"> <form action="<?= \Chibi\Router::linkTo(['UserController', 'editAction'], ['name' => $this->context->transport->user->name]) ?>" method="post" class="edit" autocomplete="off">
<?php if ($this->context->user->id == $this->context->transport->user->id): ?> <?php if ($this->context->user->id == $this->context->transport->user->id): ?>
<div class="form-row current-password"> <div class="form-row current-password">
<label for="current-password">Current password:</label> <label for="current-password">Current password:</label>
@ -101,7 +101,7 @@
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row"> <div class="form-row">
<label></label> <label></label>

View file

@ -1,9 +1,9 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('users'); Assets::setSubTitle('users');
CustomAssetViewDecorator::addStylesheet('user-list.css'); Assets::addStylesheet('user-list.css');
CustomAssetViewDecorator::addStylesheet('paginator.css'); Assets::addStylesheet('paginator.css');
if ($this->context->user->hasEnabledEndlessScrolling()) if ($this->context->user->hasEnabledEndlessScrolling())
CustomAssetViewDecorator::addScript('paginator-endless.js'); Assets::addScript('paginator-endless.js');
?> ?>
<nav class="sort-styles"> <nav class="sort-styles">
@ -17,7 +17,7 @@ if ($this->context->user->hasEnabledEndlessScrolling())
'order:date,desc' => 'Sort new&rarr;old', 'order:date,desc' => 'Sort new&rarr;old',
]; ];
if ($this->config->registration->staffActivation) if (getConfig()->registration->staffActivation)
$filters['pending'] = 'Pending staff review'; $filters['pending'] = 'Pending staff review';
?> ?>
@ -27,7 +27,7 @@ if ($this->context->user->hasEnabledEndlessScrolling())
<?php else: ?> <?php else: ?>
<li> <li>
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'list', ['filter' => $key]) ?>"><?= $text ?></a> <a href="<?= \Chibi\Router::linkTo(['UserController', 'listAction'], ['filter' => $key]) ?>"><?= $text ?></a>
</li> </li>
<?php endforeach ?> <?php endforeach ?>
</ul> </ul>
@ -40,12 +40,12 @@ if ($this->context->user->hasEnabledEndlessScrolling())
<div class="users paginator-content"> <div class="users paginator-content">
<?php foreach ($this->context->transport->users as $user): ?> <?php foreach ($this->context->transport->users as $user): ?>
<div class="user"> <div class="user">
<a class="avatar" href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $user->name]) ?>"> <a class="avatar" href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $user->name]) ?>">
<img src="<?= htmlspecialchars($user->getAvatarUrl(100)) ?>" alt="<?= $user->name ?>"/> <img src="<?= htmlspecialchars($user->getAvatarUrl(100)) ?>" alt="<?= $user->name ?>"/>
</a> </a>
<div class="details"> <div class="details">
<h1> <h1>
<a href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $user->name]) ?>"> <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $user->name]) ?>">
<?= $user->name ?> <?= $user->name ?>
</a> </a>
</h1> </h1>
@ -68,5 +68,5 @@ if ($this->context->user->hasEnabledEndlessScrolling())
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<?php $this->renderFile('paginator') ?> <?php \Chibi\View::render('paginator', $this->context) ?>
<?php endif ?> <?php endif ?>

View file

@ -1,15 +1,15 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle('registration form'); Assets::setSubTitle('registration form');
?> ?>
<?php if ($this->context->transport->success === true): ?> <?php if ($this->context->transport->success === true): ?>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<?php else: ?> <?php else: ?>
<?php <?php
CustomAssetViewDecorator::addStylesheet('auth.css'); Assets::addStylesheet('auth.css');
?> ?>
<form action="<?= \Chibi\UrlHelper::route('auth', 'register') ?>" class="auth register" method="post"> <form action="<?= \Chibi\Router::linkTo(['UserController', 'registrationAction']) ?>" class="auth register" method="post">
<p>Registered users can view more content,<br/>upload files and add posts to favorites.</p> <p>Registered users can view more content,<br/>upload files and add posts to favorites.</p>
<div class="form-row"> <div class="form-row">
@ -68,7 +68,7 @@ CustomAssetViewDecorator::setSubTitle('registration form');
Leave blank for random Gravatar. Leave blank for random Gravatar.
</p> </p>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>

View file

@ -1,13 +1,12 @@
<?php if ($this->context->transport->success === true): ?> <?php if ($this->context->transport->success === true): ?>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<?php else: ?> <?php else: ?>
<?php <?php
CustomAssetViewDecorator::addStylesheet('auth.css'); Assets::addStylesheet('auth.css');
?> ?>
<form <form
method="post" method="post"
action="<?= \Chibi\UrlHelper::route($this->context->route->simpleControllerName, $this->context->route->simpleActionName) ?>"
class="auth" class="auth"
autocomplete="off"> autocomplete="off">
@ -20,7 +19,7 @@
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row"> <div class="form-row">
<label></label> <label></label>

View file

@ -1,4 +1,4 @@
<form action="<?= \Chibi\UrlHelper::route('user', 'settings', ['name' => $this->context->transport->user->name]) ?>" method="post" class="settings"> <form action="<?= \Chibi\Router::linkTo(['UserController', 'settingsAction'], ['name' => $this->context->transport->user->name]) ?>" method="post" class="settings">
<div class="form-row safety"> <div class="form-row safety">
<label>Safety:</label> <label>Safety:</label>
<div class="input-wrapper"> <div class="input-wrapper">
@ -81,7 +81,7 @@
<input type="hidden" name="submit" value="1"/> <input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?> <?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row"> <div class="form-row">
<label></label> <label></label>

View file

@ -1,11 +1,11 @@
<?php <?php
CustomAssetViewDecorator::setSubTitle($this->context->transport->user->name); Assets::setSubTitle($this->context->transport->user->name);
CustomAssetViewDecorator::addStylesheet('user-view.css'); Assets::addStylesheet('user-view.css');
?> ?>
<div id="sidebar"> <div id="sidebar">
<div class="avatar-wrapper"> <div class="avatar-wrapper">
<a href="<?= \Chibi\UrlHelper::route('user', 'view', ['name' => $this->context->transport->user->name]) ?>"> <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], ['name' => $this->context->transport->user->name]) ?>">
<img <img
src="<?= htmlspecialchars($this->context->transport->user->getAvatarUrl(140)) ?>" src="<?= htmlspecialchars($this->context->transport->user->getAvatarUrl(140)) ?>"
alt="<?= $this->context->transport->user->name ?>"/> alt="<?= $this->context->transport->user->name ?>"/>
@ -93,20 +93,20 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
[ [
'class' => 'edit', 'class' => 'edit',
'text' => 'Edit account settings', 'text' => 'Edit account settings',
'link' => \Chibi\UrlHelper::route('user', 'edit', [ 'link' => \Chibi\Router::linkTo(['UserController', 'editAction'], [
'name' => $this->context->transport->user->name, 'tab' => 'edit']), 'name' => $this->context->transport->user->name, 'tab' => 'edit']),
]; ];
} }
if (PrivilegesHelper::confirm(Privilege::AcceptUserRegistration) if (PrivilegesHelper::confirm(Privilege::AcceptUserRegistration)
and !$this->context->transport->user->staffConfirmed and !$this->context->transport->user->staffConfirmed
and $this->config->registration->staffActivation) and getConfig()->registration->staffActivation)
{ {
$options []= $options []=
[ [
'class' => 'accept-registration', 'class' => 'accept-registration',
'text' => 'Accept registration', 'text' => 'Accept registration',
'simple-action' => \Chibi\UrlHelper::route('user', 'accept-registration', [ 'simple-action' => \Chibi\Router::linkTo(['UserController', 'acceptRegistrationAction'], [
'name' => $this->context->transport->user->name]), 'name' => $this->context->transport->user->name]),
]; ];
} }
@ -130,7 +130,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
[ [
'class' => 'flag', 'class' => 'flag',
'text' => 'Flag for moderator attention', 'text' => 'Flag for moderator attention',
'simple-action' => \Chibi\UrlHelper::route('user', 'flag', [ 'simple-action' => \Chibi\Router::linkTo(['UserController', 'flagAction'], [
'name' => $this->context->transport->user->name]), 'name' => $this->context->transport->user->name]),
'data-confirm-text' => 'Are you sure you want to flag this user?', 'data-confirm-text' => 'Are you sure you want to flag this user?',
]; ];
@ -147,7 +147,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
[ [
'class' => 'ban', 'class' => 'ban',
'text' => 'Ban user', 'text' => 'Ban user',
'simple-action' => \Chibi\UrlHelper::route('user', 'ban', [ 'simple-action' => \Chibi\Router::linkTo(['UserController', 'banAction'], [
'name' => $this->context->transport->user->name]), 'name' => $this->context->transport->user->name]),
'data-confirm-text' => 'Are you sure you want to ban this user?', 'data-confirm-text' => 'Are you sure you want to ban this user?',
]; ];
@ -158,7 +158,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
[ [
'class' => 'unban', 'class' => 'unban',
'text' => 'Unban user', 'text' => 'Unban user',
'simple-action' => \Chibi\UrlHelper::route('user', 'unban', [ 'simple-action' => \Chibi\Router::linkTo(['UserController', 'unbanAction'], [
'name' => $this->context->transport->user->name]), 'name' => $this->context->transport->user->name]),
'data-confirm-text' => 'Are you sure you want to unban this user?', 'data-confirm-text' => 'Are you sure you want to unban this user?',
]; ];
@ -173,13 +173,13 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
[ [
'class' => 'delete', 'class' => 'delete',
'text' => 'Delete account', 'text' => 'Delete account',
'link' => \Chibi\UrlHelper::route('user', 'delete', [ 'link' => \Chibi\Router::linkTo(['UserController', 'deleteAction'], [
'name' => $this->context->transport->user->name, 'tab' => 'delete']), 'name' => $this->context->transport->user->name, 'tab' => 'delete']),
]; ];
} }
$this->context->options = $options; $this->context->options = $options;
$this->renderFile('sidebar-options'); \Chibi\View::render('sidebar-options', $this->context);
?> ?>
</div> </div>
@ -191,7 +191,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
<?php else: ?> <?php else: ?>
<li class="favs"> <li class="favs">
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'view', [ <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], [
'name' => $this->context->transport->user->name, 'name' => $this->context->transport->user->name,
'tab' => 'favs', 'tab' => 'favs',
'page' => 1]) ?>"> 'page' => 1]) ?>">
@ -204,7 +204,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
<?php else: ?> <?php else: ?>
<li class="uploads"> <li class="uploads">
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'view', [ <a href="<?= \Chibi\Router::linkTo(['UserController', 'viewAction'], [
'name' => $this->context->transport->user->name, 'name' => $this->context->transport->user->name,
'tab' => 'uploads', 'tab' => 'uploads',
'page' => 1]) ?>"> 'page' => 1]) ?>">
@ -221,7 +221,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
<?php else: ?> <?php else: ?>
<li class="settings"> <li class="settings">
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'settings', [ <a href="<?= \Chibi\Router::linkTo(['UserController', 'settingsAction'], [
'name' => $this->context->transport->user->name]) ?>"> 'name' => $this->context->transport->user->name]) ?>">
Browsing settings Browsing settings
</a> </a>
@ -234,7 +234,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
<?php else: ?> <?php else: ?>
<li class="edit"> <li class="edit">
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'edit', [ <a href="<?= \Chibi\Router::linkTo(['UserController', 'editAction'], [
'name' => $this->context->transport->user->name]) ?>"> 'name' => $this->context->transport->user->name]) ?>">
Account settings Account settings
</a> </a>
@ -249,7 +249,7 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
<?php else: ?> <?php else: ?>
<li class="delete"> <li class="delete">
<?php endif ?> <?php endif ?>
<a href="<?= \Chibi\UrlHelper::route('user', 'delete', [ <a href="<?= \Chibi\Router::linkTo(['UserController', 'deleteAction'], [
'name' => $this->context->transport->user->name]) ?>"> 'name' => $this->context->transport->user->name]) ?>">
Delete account Delete account
</a> </a>
@ -260,15 +260,15 @@ CustomAssetViewDecorator::addStylesheet('user-view.css');
<div class="tab-content"> <div class="tab-content">
<?php if (isset($this->context->transport->posts)): ?> <?php if (isset($this->context->transport->posts)): ?>
<?php $this->renderFile('post-list') ?> <?php \Chibi\View::render('post-list', $this->context) ?>
<?php endif ?> <?php endif ?>
<?php if ($this->context->transport->tab == 'settings'): ?> <?php if ($this->context->transport->tab == 'settings'): ?>
<?php $this->renderFile('user-settings') ?> <?php \Chibi\View::render('user-settings', $this->context) ?>
<?php elseif ($this->context->transport->tab == 'edit'): ?> <?php elseif ($this->context->transport->tab == 'edit'): ?>
<?php $this->renderFile('user-edit') ?> <?php \Chibi\View::render('user-edit', $this->context) ?>
<?php elseif ($this->context->transport->tab == 'delete'): ?> <?php elseif ($this->context->transport->tab == 'delete'): ?>
<?php $this->renderFile('user-delete') ?> <?php \Chibi\View::render('user-delete', $this->context) ?>
<?php endif ?> <?php endif ?>
</div> </div>

View file

@ -1,10 +1,10 @@
<?php <?php
$startTime = microtime(true);
define('SZURU_VERSION', '0.7.1'); define('SZURU_VERSION', '0.7.1');
define('SZURU_LINK', 'http://github.com/rr-/szurubooru'); define('SZURU_LINK', 'http://github.com/rr-/szurubooru');
//basic settings and preparation //basic settings and preparation
define('DS', DIRECTORY_SEPARATOR); define('DS', DIRECTORY_SEPARATOR);
$startTime = microtime(true);
$rootDir = __DIR__ . DS . '..' . DS; $rootDir = __DIR__ . DS . '..' . DS;
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
setlocale(LC_CTYPE, 'en_US.UTF-8'); setlocale(LC_CTYPE, 'en_US.UTF-8');
@ -14,8 +14,9 @@ ini_set('memory_limit', '128M');
require_once $rootDir . 'lib' . DS . 'TextCaseConverter' . DS . 'TextCaseConverter.php'; require_once $rootDir . 'lib' . DS . 'TextCaseConverter' . DS . 'TextCaseConverter.php';
require_once $rootDir . 'lib' . DS . 'php-markdown' . DS . 'Michelf' . DS . 'Markdown.php'; require_once $rootDir . 'lib' . DS . 'php-markdown' . DS . 'Michelf' . DS . 'Markdown.php';
require_once $rootDir . 'lib' . DS . 'php-markdown' . DS . 'Michelf' . DS . 'MarkdownExtra.php'; require_once $rootDir . 'lib' . DS . 'php-markdown' . DS . 'Michelf' . DS . 'MarkdownExtra.php';
require_once $rootDir . 'lib' . DS . 'chibi-core' . DS . 'Facade.php'; require_once $rootDir . 'lib' . DS . 'chibi-core' . DS . 'include.php';
\Chibi\AutoLoader::init([__DIR__, $rootDir . 'lib' . DS . 'chibi-sql']); \Chibi\AutoLoader::registerFilesystem($rootDir . 'lib' . DS . 'chibi-sql');
\Chibi\AutoLoader::registerFilesystem(__DIR__);
//load config manually //load config manually
$configPaths = $configPaths =
@ -27,7 +28,14 @@ $config = new \Chibi\Config();
foreach ($configPaths as $path) foreach ($configPaths as $path)
if (file_exists($path)) if (file_exists($path))
$config->loadIni($path); $config->loadIni($path);
\Chibi\Registry::setConfig($config); $config->rootDir = $rootDir;
function getConfig()
{
global $config;
return $config;
}
//extension sanity checks //extension sanity checks
$requiredExtensions = ['pdo', 'pdo_' . $config->main->dbDriver, 'gd', 'openssl', 'fileinfo']; $requiredExtensions = ['pdo', 'pdo_' . $config->main->dbDriver, 'gd', 'openssl', 'fileinfo'];
@ -35,12 +43,6 @@ foreach ($requiredExtensions as $ext)
if (!extension_loaded($ext)) if (!extension_loaded($ext))
die('PHP extension "' . $ext . '" must be enabled to continue.' . PHP_EOL); die('PHP extension "' . $ext . '" must be enabled to continue.' . PHP_EOL);
//prepare context
\Chibi\Facade::init();
$context = \Chibi\Registry::getContext();
$context->startTime = $startTime;
$context->rootDir = $rootDir;
\Chibi\Database::connect( \Chibi\Database::connect(
$config->main->dbDriver, $config->main->dbDriver,
TextHelper::absolutePath($config->main->dbLocation), TextHelper::absolutePath($config->main->dbLocation),

View file

@ -1,6 +1,6 @@
<?php <?php
require_once 'src/core.php'; require_once 'src/core.php';
$config = \Chibi\Registry::getConfig(); $config = getConfig();
function getDbVersion() function getDbVersion()
{ {
@ -29,7 +29,7 @@ function getDbVersion()
return [$dbVersionMajor, $dbVersionMinor]; return [$dbVersionMajor, $dbVersionMinor];
} }
$upgradesPath = TextHelper::absolutePath(\Chibi\Registry::getContext()->rootDir . DS . 'src' . DS . 'Upgrades' . DS . $config->main->dbDriver); $upgradesPath = TextHelper::absolutePath($config->rootDir . DS . 'src' . DS . 'Upgrades' . DS . $config->main->dbDriver);
$upgrades = glob($upgradesPath . DS . '*.sql'); $upgrades = glob($upgradesPath . DS . '*.sql');
natcasesort($upgrades); natcasesort($upgrades);