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
require_once 'src/core.php';
$config = \Chibi\Registry::getConfig();
$config = getConfig();
$fontsPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'fonts');
$libPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'lib');

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

View file

@ -1,5 +1,198 @@
<?php
require_once '../src/core.php';
$query = $_SERVER['REQUEST_URI'];
\Chibi\Facade::run($query, new Bootstrap());
$query = rtrim($_SERVER['REQUEST_URI'], '/');
//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);
$config = \Chibi\Registry::getConfig();
$config = getConfig();
foreach (glob(TextHelper::absolutePath($config->main->filesPath) . DS . '*') as $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']))
{
\Chibi\UrlHelper::forward($_SESSION['login-redirect-url']);
\Chibi\Util\Url::forward(\Chibi\Util\Url::makeAbsolute($_SESSION['login-redirect-url']));
unset($_SESSION['login-redirect-url']);
return;
}
\Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index'));
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
}
public static function tryLogin($name, $password)
{
$config = \Chibi\Registry::getConfig();
$context = \Chibi\Registry::getContext();
$config = getConfig();
$context = getContext();
$dbUser = UserModel::findByNameOrEmail($name, false);
if ($dbUser === null)
@ -49,15 +49,13 @@ class AuthController
return self::tryLogin($name, $password);
}
/**
* @route /auth/login
*/
public function loginAction()
{
$this->context->handleExceptions = true;
$context = getContext();
$context->handleExceptions = true;
//check if already logged in
if ($this->context->loggedIn)
if ($context->loggedIn)
{
self::redirectAfterLog();
return;
@ -79,16 +77,14 @@ class AuthController
}
}
/**
* @route /auth/logout
*/
public function logoutAction()
{
$this->context->viewName = null;
$this->context->layoutName = null;
$context = getContext();
$context->viewName = null;
$context->layoutName = null;
self::doLogOut();
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()
@ -98,7 +94,7 @@ class AuthController
public static function doLogIn()
{
$context = \Chibi\Registry::getContext();
$context = getContext();
if (!isset($_SESSION['user']))
{
if (!empty($context->user) and $context->user->id)
@ -133,7 +129,7 @@ class AuthController
public static function doReLog()
{
$context = \Chibi\Registry::getContext();
$context = getContext();
if ($context->user !== null)
self::doLogOut();
self::doLogIn();
@ -141,10 +137,12 @@ class AuthController
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;
$context = \Chibi\Registry::getContext();
if ($context->route->simpleControllerName == 'auth')
if (\Chibi\Util\Headers::getCode() != 200)
return;
$context = getContext();
if ($context->simpleControllerName == 'auth')
return;
$_SESSION['login-redirect-url'] = $context->query;
}

View file

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

View file

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

View file

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

View file

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

View file

@ -1,53 +1,44 @@
<?php
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)
{
$this->context->viewName = 'tag-list-wrapper';
$context = getContext();
$context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::ListTags);
$suppliedFilter = $filter ?: 'order:alpha,asc';
$page = max(1, intval($page));
$tagsPerPage = intval($this->config->browsing->tagsPerPage);
$tagsPerPage = intval(getConfig()->browsing->tagsPerPage);
$tags = TagSearchService::getEntitiesRows($suppliedFilter, $tagsPerPage, $page);
$tagCount = TagSearchService::getEntityCount($suppliedFilter);
$pageCount = ceil($tagCount / $tagsPerPage);
$page = min($pageCount, $page);
$this->context->filter = $suppliedFilter;
$this->context->transport->tags = $tags;
$context->filter = $suppliedFilter;
$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']];
}, $this->context->transport->tags));
}, $context->transport->tags));
}
else
{
$this->context->highestUsage = TagSearchService::getMostUsedTag()['post_count'];
$this->context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $tagCount;
$this->context->transport->paginator->entities = $tags;
$context->highestUsage = TagSearchService::getMostUsedTag()['post_count'];
$context->transport->paginator = new StdClass;
$context->transport->paginator->page = $page;
$context->transport->paginator->pageCount = $pageCount;
$context->transport->paginator->entityCount = $tagCount;
$context->transport->paginator->entities = $tags;
}
}
/**
* @route /tags-autocomplete
*/
public function autoCompleteAction()
{
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListTags);
$suppliedSearch = InputHelper::get('search');
@ -55,7 +46,7 @@ class TagController
$filter = $suppliedSearch . ' order:popularity,desc';
$tags = TagSearchService::getEntitiesRows($filter, 15, 1);
$this->context->transport->tags =
$context->transport->tags =
array_values(array_map(
function($tag)
{
@ -66,20 +57,18 @@ class TagController
}, $tags));
}
/**
* @route /tags-related
*/
public function relatedAction()
{
$context = getContext();
PrivilegesHelper::confirmWithException(Privilege::ListTags);
$suppliedContext = (array) InputHelper::get('context');
$suppliedTag = InputHelper::get('tag');
$limit = intval($this->config->browsing->tagsRelated);
$limit = intval(getConfig()->browsing->tagsRelated);
$tags = TagSearchService::getRelatedTagRows($suppliedTag, $suppliedContext, $limit);
$this->context->transport->tags =
$context->transport->tags =
array_values(array_map(
function($tag)
{
@ -90,13 +79,11 @@ class TagController
}, $tags));
}
/**
* @route /tag/merge
*/
public function mergeAction()
{
$this->context->viewName = 'tag-list-wrapper';
$this->context->handleExceptions = true;
$context = getContext();
$context->viewName = 'tag-list-wrapper';
$context->handleExceptions = true;
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
if (InputHelper::get('submit'))
@ -119,13 +106,11 @@ class TagController
}
}
/**
* @route /tag/rename
*/
public function renameAction()
{
$this->context->viewName = 'tag-list-wrapper';
$this->context->handleExceptions = true;
$context = getContext();
$context->viewName = 'tag-list-wrapper';
$context->handleExceptions = true;
PrivilegesHelper::confirmWithException(Privilege::MergeTags);
if (InputHelper::get('submit'))
@ -148,12 +133,10 @@ class TagController
}
}
/**
* @route /mass-tag-redirect
*/
public function massTagRedirectAction()
{
$this->context->viewName = 'tag-list-wrapper';
$context = getContext();
$context->viewName = 'tag-list-wrapper';
PrivilegesHelper::confirmWithException(Privilege::MassTag);
if (InputHelper::get('submit'))
@ -170,7 +153,7 @@ class TagController
];
if ($suppliedOldPage != 0 and $suppliedOldQuery == $suppliedQuery)
$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)
{
$context = getContext();
$flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', []));
$this->context->flagged = $flagged;
$this->context->transport->user = $user;
$this->context->handleExceptions = true;
$this->context->viewName = 'user-view';
$context->flagged = $flagged;
$context->transport->user = $user;
$context->handleExceptions = true;
$context->viewName = 'user-view';
}
private static function sendTokenizedEmail(
@ -27,13 +28,13 @@ class UserController
$token->expires = null;
TokenModel::save($token);
\Chibi\Registry::getContext()->mailSent = true;
getContext()->mailSent = true;
$tokens = [];
$tokens['host'] = $_SERVER['HTTP_HOST'];
$tokens['token'] = $token->token; //gosh this code looks so silly
$tokens['nl'] = PHP_EOL;
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);
$subject = TextHelper::replaceTokens($subject, $tokens);
@ -67,7 +68,7 @@ class UserController
private static function sendEmailChangeConfirmation($user)
{
$regConfig = \Chibi\Registry::getConfig()->registration;
$regConfig = getConfig()->registration;
if (!$regConfig->confirmationEmailEnabled)
{
$user->emailConfirmed = $user->emailUnconfirmed;
@ -82,12 +83,12 @@ class UserController
$regConfig->confirmationEmailSenderName,
$regConfig->confirmationEmailSenderEmail,
$user->emailUnconfirmed,
'activation');
'activationAction');
}
private static function sendPasswordResetConfirmation($user)
{
$regConfig = \Chibi\Registry::getConfig()->registration;
$regConfig = getConfig()->registration;
return self::sendTokenizedEmail(
$user,
@ -96,49 +97,34 @@ class UserController
$regConfig->passwordResetEmailSenderName,
$regConfig->passwordResetEmailSenderEmail,
$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)
{
$context = getContext();
PrivilegesHelper::confirmWithException(
Privilege::ListUsers);
$suppliedFilter = $filter ?: InputHelper::get('filter') ?: 'order:alpha,asc';
$page = max(1, intval($page));
$usersPerPage = intval($this->config->browsing->usersPerPage);
$usersPerPage = intval(getConfig()->browsing->usersPerPage);
$users = UserSearchService::getEntities($suppliedFilter, $usersPerPage, $page);
$userCount = UserSearchService::getEntityCount($suppliedFilter);
$pageCount = ceil($userCount / $usersPerPage);
$page = min($pageCount, $page);
$this->context->filter = $suppliedFilter;
$this->context->transport->users = $users;
$this->context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $userCount;
$this->context->transport->paginator->entities = $users;
$this->context->transport->paginator->params = func_get_args();
$context->filter = $suppliedFilter;
$context->transport->users = $users;
$context->transport->paginator = new StdClass;
$context->transport->paginator->page = $page;
$context->transport->paginator->pageCount = $pageCount;
$context->transport->paginator->entityCount = $userCount;
$context->transport->paginator->entities = $users;
$context->transport->paginator->params = func_get_args();
}
/**
* @route /user/{name}/flag
* @validate name [^\/]+
*/
public function flagAction($name)
{
$user = UserModel::findByNameOrEmail($name);
@ -163,12 +149,6 @@ class UserController
}
}
/**
* @route /user/{name}/ban
* @validate name [^\/]+
*/
public function banAction($name)
{
$user = UserModel::findByNameOrEmail($name);
@ -186,12 +166,6 @@ class UserController
}
}
/**
* @route /post/{name}/unban
* @validate name [^\/]+
*/
public function unbanAction($name)
{
$user = UserModel::findByNameOrEmail($name);
@ -209,12 +183,6 @@ class UserController
}
}
/**
* @route /post/{name}/accept-registration
* @validate name [^\/]+
*/
public function acceptRegistrationAction($name)
{
$user = UserModel::findByNameOrEmail($name);
@ -230,14 +198,9 @@ class UserController
}
}
/**
* @route /user/{name}/delete
* @validate name [^\/]+
*/
public function deleteAction($name)
{
$context = getContext();
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Privilege::ViewUser,
@ -247,14 +210,14 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($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'))
{
$name = $user->name;
if ($this->context->user->id == $user->id)
if ($context->user->id == $user->id)
{
$suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt);
if ($suppliedPasswordHash != $user->passHash)
@ -263,23 +226,18 @@ class UserController
$oldId = $user->id;
UserModel::remove($user);
if ($oldId == $this->context->user->id)
if ($oldId == $context->user->id)
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)]);
StatusHelper::success();
}
}
/**
* @route /user/{name}/settings
* @validate name [^\/]+
*/
public function settingsAction($name)
{
$context = getContext();
$user = UserModel::findByNameOrEmail($name);
PrivilegesHelper::confirmWithException(
Privilege::ViewUser,
@ -289,7 +247,7 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($user));
$this->loadUserView($user);
$this->context->transport->tab = 'settings';
$context->transport->tab = 'settings';
if (InputHelper::get('submit'))
{
@ -305,21 +263,16 @@ class UserController
if ($user->accessRank != AccessRank::Anonymous)
UserModel::save($user);
if ($user->id == $this->context->user->id)
$this->context->user = $user;
if ($user->id == $context->user->id)
$context->user = $user;
AuthController::doReLog();
StatusHelper::success('Browsing settings updated!');
}
}
/**
* @route /user/{name}/edit
* @validate name [^\/]+
*/
public function editAction($name)
{
$context = getContext();
try
{
$user = UserModel::findByNameOrEmail($name);
@ -328,14 +281,14 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($user));
$this->loadUserView($user);
$this->context->transport->tab = 'edit';
$context->transport->tab = 'edit';
$this->context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
$this->context->suppliedName = $suppliedName = InputHelper::get('name');
$this->context->suppliedPassword1 = $suppliedPassword1 = InputHelper::get('password1');
$this->context->suppliedPassword2 = $suppliedPassword2 = InputHelper::get('password2');
$this->context->suppliedEmail = $suppliedEmail = InputHelper::get('email');
$this->context->suppliedAccessRank = $suppliedAccessRank = InputHelper::get('access-rank');
$context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
$context->suppliedName = $suppliedName = InputHelper::get('name');
$context->suppliedPassword1 = $suppliedPassword1 = InputHelper::get('password1');
$context->suppliedPassword2 = $suppliedPassword2 = InputHelper::get('password2');
$context->suppliedEmail = $suppliedEmail = InputHelper::get('email');
$context->suppliedAccessRank = $suppliedAccessRank = InputHelper::get('access-rank');
$currentPasswordHash = $user->passHash;
if (InputHelper::get('submit'))
@ -377,7 +330,7 @@ class UserController
PrivilegesHelper::getIdentitySubPrivilege($user));
$suppliedEmail = UserModel::validateEmail($suppliedEmail);
if ($this->context->user->id == $user->id)
if ($context->user->id == $user->id)
{
$user->emailUnconfirmed = $suppliedEmail;
if (!empty($user->emailUnconfirmed))
@ -407,14 +360,14 @@ class UserController
'rank' => AccessRank::toString($suppliedAccessRank)]);
}
if ($this->context->user->id == $user->id)
if ($context->user->id == $user->id)
{
$suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt);
if ($suppliedPasswordHash != $currentPasswordHash)
throw new SimpleException('Must supply valid current password');
}
UserModel::save($user);
if ($this->context->user->id == $user->id)
if ($context->user->id == $user->id)
AuthController::doReLog();
if ($confirmMail)
@ -429,23 +382,15 @@ class UserController
}
catch (Exception $e)
{
$this->context->transport->user = UserModel::findByNameOrEmail($name);
$context->transport->user = UserModel::findByNameOrEmail($name);
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)
{
$postsPerPage = intval($this->config->browsing->postsPerPage);
$context = getContext();
$postsPerPage = intval(getConfig()->browsing->postsPerPage);
$user = UserModel::findByNameOrEmail($name);
if ($tab === null)
$tab = 'favs';
@ -472,53 +417,45 @@ class UserController
$pageCount = ceil($postCount / $postsPerPage);
PostModel::preloadTags($posts);
$this->context->transport->tab = $tab;
$this->context->transport->lastSearchQuery = $query;
$this->context->transport->paginator = new StdClass;
$this->context->transport->paginator->page = $page;
$this->context->transport->paginator->pageCount = $pageCount;
$this->context->transport->paginator->entityCount = $postCount;
$this->context->transport->paginator->entities = $posts;
$this->context->transport->posts = $posts;
$context->transport->tab = $tab;
$context->transport->lastSearchQuery = $query;
$context->transport->paginator = new StdClass;
$context->transport->paginator->page = $page;
$context->transport->paginator->pageCount = $pageCount;
$context->transport->paginator->entityCount = $postCount;
$context->transport->paginator->entities = $posts;
$context->transport->posts = $posts;
}
/**
* @route /user/toggle-safety/{safety}
*/
public function toggleSafetyAction($safety)
{
$context = getContext();
PrivilegesHelper::confirmWithException(
Privilege::ChangeUserSettings,
PrivilegesHelper::getIdentitySubPrivilege($this->context->user));
PrivilegesHelper::getIdentitySubPrivilege($context->user));
if (!in_array($safety, PostSafety::getAll()))
throw new SimpleExcetpion('Invalid safety');
$this->context->user->enableSafety($safety,
!$this->context->user->hasEnabledSafety($safety));
$context->user->enableSafety($safety,
!$context->user->hasEnabledSafety($safety));
if ($this->context->user->accessRank != AccessRank::Anonymous)
UserModel::save($this->context->user);
if ($context->user->accessRank != AccessRank::Anonymous)
UserModel::save($context->user);
AuthController::doReLog();
StatusHelper::success();
}
/**
* @route /register
*/
public function registrationAction()
{
$this->context->handleExceptions = true;
$context = getContext();
$context->handleExceptions = true;
//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;
}
@ -526,10 +463,10 @@ class UserController
$suppliedPassword1 = InputHelper::get('password1');
$suppliedPassword2 = InputHelper::get('password2');
$suppliedEmail = InputHelper::get('email');
$this->context->suppliedName = $suppliedName;
$this->context->suppliedPassword1 = $suppliedPassword1;
$this->context->suppliedPassword2 = $suppliedPassword2;
$this->context->suppliedEmail = $suppliedEmail;
$context->suppliedName = $suppliedName;
$context->suppliedPassword1 = $suppliedPassword1;
$context->suppliedPassword2 = $suppliedPassword2;
$context->suppliedEmail = $suppliedEmail;
if (InputHelper::get('submit'))
{
@ -540,7 +477,7 @@ class UserController
$suppliedPassword = UserModel::validatePassword($suppliedPassword1);
$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.');
//register the user
@ -572,35 +509,31 @@ class UserController
self::sendEmailChangeConfirmation($dbUser);
$message = 'Congratulations, your account was created.';
if (!empty($this->context->mailSent))
if (!empty($context->mailSent))
{
$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.';
}
elseif ($this->config->registration->staffActivation)
elseif (getConfig()->registration->staffActivation)
$message .= ' Your registration must be now confirmed by staff.';
LogHelper::log('{subject} just signed up', ['subject' => TextHelper::reprUser($dbUser)]);
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();
}
}
}
/**
* @route /activation/{token}
*/
public function activationAction($token)
{
$this->context->viewName = 'message';
CustomAssetViewDecorator::setSubTitle('account activation');
$context = getContext();
$context->viewName = 'message';
Assets::setSubTitle('account activation');
$dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken);
@ -614,26 +547,22 @@ class UserController
LogHelper::log('{subject} just activated account', ['subject' => TextHelper::reprUser($dbUser)]);
$message = 'Activation completed successfully.';
if ($this->config->registration->staffActivation)
if (getConfig()->registration->staffActivation)
$message .= ' However, your account still must be confirmed by staff.';
StatusHelper::success($message);
if (!$this->config->registration->staffActivation)
if (!getConfig()->registration->staffActivation)
{
$this->context->user = $dbUser;
$context->user = $dbUser;
AuthController::doReLog();
}
}
/**
* @route /password-reset/{token}
*/
public function passwordResetAction($token)
{
$this->context->viewName = 'message';
CustomAssetViewDecorator::setSubTitle('password reset');
$context = getContext();
$context->viewName = 'message';
Assets::setSubTitle('password reset');
$dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken);
@ -654,20 +583,15 @@ class UserController
$message = 'Password reset successful. Your new password is **' . $randomPassword . '**.';
StatusHelper::success($message);
$this->context->user = $dbUser;
$context->user = $dbUser;
AuthController::doReLog();
}
/**
* @route /password-reset-proxy
*/
public function passwordResetProxyAction()
{
$this->context->viewName = 'user-select';
CustomAssetViewDecorator::setSubTitle('password reset');
$context = getContext();
$context->viewName = 'user-select';
Assets::setSubTitle('password reset');
if (InputHelper::get('submit'))
{
@ -681,13 +605,11 @@ class UserController
}
}
/**
* @route /activation-proxy
*/
public function activationProxyAction()
{
$this->context->viewName = 'user-select';
CustomAssetViewDecorator::setSubTitle('account activation');
$context = getContext();
$context->viewName = 'user-select';
Assets::setSubTitle('account activation');
if (InputHelper::get('submit'))
{

View file

@ -127,7 +127,7 @@ class CustomMarkdown extends \Michelf\MarkdownExtra
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 $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)
{
$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 $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)
{
$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 $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)
{
$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 $this->hashPart('<a href="' . str_replace('_query_', urlencode($x[1]), $link) . '">' . $x[1] . '</a>');

View file

@ -1,9 +1,15 @@
<?php
class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
class Assets extends \Chibi\Util\Assets
{
private static $pageThumb = null;
private static $subTitle = null;
public static function init()
{
\Chibi\Util\Assets::disable();
self::enable();
}
public static function setSubTitle($text)
{
self::$subTitle = $text;
@ -14,7 +20,17 @@ class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
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)
? sprintf('%s&nbsp;&ndash;&nbsp;%s', self::$title, self::$subTitle)
@ -23,7 +39,7 @@ class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
$html = parent::transformHtml($html);
$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))
$headSnippet .= '<meta property="og:image" content="' . self::$pageThumb . '"/>';
@ -38,3 +54,5 @@ class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
return $html;
}
}
Assets::init();

View file

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

View file

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

View file

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

View file

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

View file

@ -90,7 +90,7 @@ class CommentModel extends AbstractCrudModel
public static function validateText($text)
{
$text = trim($text);
$config = \Chibi\Registry::getConfig();
$config = getConfig();
if (strlen($text) < $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)
{
$config = \Chibi\Registry::getConfig();
$config = getConfig();
$relatedIds = array_filter(preg_split('/\D/', $relationsText));
$relatedPosts = [];
@ -215,7 +215,7 @@ class PostEntity extends AbstractEntity
public function setCustomThumbnailFromPath($srcPath)
{
$config = \Chibi\Registry::getConfig();
$config = getConfig();
$mimeType = mime_content_type($srcPath);
if (!in_array($mimeType, ['image/gif', 'image/png', 'image/jpeg']))
@ -323,7 +323,7 @@ class PostEntity extends AbstractEntity
if (!isset($srcImage))
return false;
$config = \Chibi\Registry::getConfig();
$config = getConfig();
switch ($config->browsing->thumbStyle)
{
case 'outside':

View file

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

View file

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

View file

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

View file

@ -179,22 +179,23 @@ class UserModel extends AbstractCrudModel
public static function validateUserName($userName)
{
$userName = trim($userName);
$config = getConfig();
$dbUser = self::findByName($userName, false);
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');
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');
}
$userNameMinLength = intval(\Chibi\Registry::getConfig()->registration->userNameMinLength);
$userNameMaxLength = intval(\Chibi\Registry::getConfig()->registration->userNameMaxLength);
$userNameRegex = \Chibi\Registry::getConfig()->registration->userNameRegex;
$userNameMinLength = intval($config->registration->userNameMinLength);
$userNameMaxLength = intval($config->registration->userNameMaxLength);
$userNameRegex = $config->registration->userNameRegex;
if (strlen($userName) < $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)
{
$passMinLength = intval(\Chibi\Registry::getConfig()->registration->passMinLength);
$passRegex = \Chibi\Registry::getConfig()->registration->passRegex;
$config = getConfig();
$passMinLength = intval($config->registration->passMinLength);
$passRegex = $config->registration->passRegex;
if (strlen($password) < $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)
{
$salt1 = \Chibi\Registry::getConfig()->main->salt;
$salt1 = getConfig()->main->salt;
return sha1($salt1 . $salt2 . $pass);
}
}

View file

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

View file

@ -1,10 +1,10 @@
<?php
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
Assets::addStylesheet('comment-edit.css');
Assets::addScript('comment-edit.js');
?>
<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"
class="add-comment">

View file

@ -1,10 +1,10 @@
<?php
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
Assets::addStylesheet('comment-edit.css');
Assets::addScript('comment-edit.js');
?>
<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"
class="edit-comment">

View file

@ -1,15 +1,15 @@
<?php
CustomAssetViewDecorator::setSubTitle('comments');
Assets::setSubTitle('comments');
?>
<?php if (empty($this->context->transport->posts)): ?>
<p class="alert alert-warning">No comments to show.</p>
<?php else: ?>
<?php
CustomAssetViewDecorator::addStylesheet('comment-list.css');
CustomAssetViewDecorator::addStylesheet('comment-small.css');
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
Assets::addStylesheet('comment-list.css');
Assets::addStylesheet('comment-small.css');
Assets::addStylesheet('comment-edit.css');
Assets::addScript('comment-edit.js');
?>
<div class="comments-wrapper">
@ -20,18 +20,18 @@ CustomAssetViewDecorator::setSubTitle('comments');
<?php
$this->context->post = $post;
$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 class="comments">
<?php foreach ($commentsToDisplay as $comment): ?>
<?php $this->context->comment = $comment ?>
<?= $this->renderFile('comment-small') ?>
<?php \Chibi\View::render('comment-small', $this->context) ?>
<?php endforeach ?>
<?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>
</a>
<?php endif ?>
@ -41,6 +41,6 @@ CustomAssetViewDecorator::setSubTitle('comments');
<?php endforeach ?>
</div>
<?php $this->renderFile('paginator') ?>
<?php \Chibi\View::render('paginator', $this->context) ?>
</div>
<?php endif ?>

View file

@ -1,19 +1,19 @@
<?php
CustomAssetViewDecorator::addStylesheet('comment-small.css');
CustomAssetViewDecorator::addStylesheet('comment-edit.css');
CustomAssetViewDecorator::addScript('comment-edit.js');
Assets::addStylesheet('comment-small.css');
Assets::addStylesheet('comment-edit.css');
Assets::addScript('comment-edit.js');
?>
<div class="comment">
<div class="avatar">
<?php $commenter = $this->context->comment->getCommenter() ?>
<?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 ?>"/>
</a>
<?php else: ?>
<img
src="<?= \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>"
src="<?= \Chibi\Util\Url::makeAbsolute('/media/img/pixel.gif') ?>"
alt="<?= UserModel::getAnonymousName() ?>">
<?php endif ?>
</div>
@ -22,7 +22,7 @@ CustomAssetViewDecorator::addScript('comment-edit.js');
<div class="header">
<span class="nickname">
<?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 ?>
</a>
<?php else: ?>
@ -38,7 +38,7 @@ CustomAssetViewDecorator::addScript('comment-edit.js');
Privilege::EditComment,
PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?>
<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
</a>
</span>
@ -48,7 +48,7 @@ CustomAssetViewDecorator::addScript('comment-edit.js');
PrivilegesHelper::confirm(Privilege::DeleteComment,
PrivilegesHelper::getIdentitySubPrivilege($commenter))): ?>
<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"
data-confirm-text="Are you sure you want to delete this comment?">
delete

View file

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

View file

@ -1,8 +1,8 @@
<?php
CustomAssetViewDecorator::setSubtitle('help');
CustomAssetViewDecorator::addStylesheet('index-help.css');
Assets::setSubtitle('help');
Assets::addStylesheet('index-help.css');
$tabs = $this->config->help->subTitles;
$tabs = getConfig()->help->subTitles;
$firstTab = !empty($tabs) ? array_keys($tabs)[0] : null;
$showTabs = count($tabs) > 1;
?>
@ -16,7 +16,7 @@ $showTabs = count($tabs) > 1;
<?php else: ?>
<li class="<?= $tab ?>">
<?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 ?>
</a>
</li>

View file

@ -1,10 +1,10 @@
<?php
CustomAssetViewDecorator::setSubtitle('home');
CustomAssetViewDecorator::addStylesheet('index-index.css');
Assets::setSubtitle('home');
Assets::addStylesheet('index-index.css');
?>
<div id="welcome">
<h1><?= $this->config->main->title ?></h1>
<h1><?= getConfig()->main->title ?></h1>
<p>
<span>serving <?= $this->context->transport->postCount ?> posts</span>
</p>
@ -14,11 +14,11 @@ CustomAssetViewDecorator::addStylesheet('index-index.css');
<div class="body">
<?php
$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]);
?>
<?= $this->renderFile('post-file-render') ?>
<?php \Chibi\View::render('post-file-render', $this->context) ?>
</div>
<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 foreach ($tags as $tag): ?>
<li>
<a href="<?= \Chibi\UrlHelper::route('post', 'list', ['query' => $tag->name]) ?>">
<a href="<?= \Chibi\Router::linkTo(['PostController', 'listAction'], ['query' => $tag->name]) ?>">
<?= $tag->name ?>
</a>
</li>
@ -41,7 +41,7 @@ CustomAssetViewDecorator::addStylesheet('index-index.css');
Featured
<?php if ($this->context->featuredPostUser): ?>
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 ?>
</a>,
<?php endif ?>

View file

@ -1,7 +1,7 @@
<?php
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;
}
else
@ -18,20 +18,20 @@ else
? trim(trim($_SERVER['HTTP_IF_NONE_MATCH']), '"')
: false;
\Chibi\HeadersHelper::set('ETag', '"' . $eTag . '"');
\Chibi\HeadersHelper::set('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $lastModified));
\Chibi\HeadersHelper::set('Pragma', 'public');
\Chibi\HeadersHelper::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('ETag', '"' . $eTag . '"');
\Chibi\Util\Headers::set('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $lastModified));
\Chibi\Util\Headers::set('Pragma', 'public');
\Chibi\Util\Headers::set('Cache-Control', 'public, max-age=' . $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))
{
\Chibi\HeadersHelper::set(
\Chibi\Util\Headers::set(
'Content-Disposition',
'inline; filename="' . $this->context->transport->customFileName . '"');
}
\Chibi\HeadersHelper::set(
\Chibi\Util\Headers::set(
'Content-Type',
$this->context->transport->mimeType);

View file

@ -1,3 +1,3 @@
<?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');

View file

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

View file

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

View file

@ -1,19 +1,19 @@
<?php
CustomAssetViewDecorator::setSubTitle('logs (' . $name . ')');
Assets::setSubTitle('logs (' . $this->context->transport->name . ')');
?>
<?php if (empty($this->context->transport->lines)): ?>
<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>
<?php else: ?>
<?php
CustomAssetViewDecorator::addStylesheet('logs.css');
CustomAssetViewDecorator::addScript('logs.js');
Assets::addStylesheet('logs.css');
Assets::addScript('logs.js');
?>
<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:
@ -27,5 +27,5 @@ CustomAssetViewDecorator::setSubTitle('logs (' . $name . ')');
<code><?= $this->context->transport->lines ?></code>
</div>
<?php $this->renderFile('paginator') ?>
<?php \Chibi\View::render('paginator', $this->context) ?>
<?php endif ?>

View file

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

View file

@ -1,5 +1,5 @@
<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"
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 if ($post->type == PostType::Image): ?>
@ -7,7 +7,7 @@
<a href="<?= $this->context->imageLink ?>">
<?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)): ?>
</a>
@ -19,9 +19,9 @@
type="<?= $post->mimeType ?>"
width="<?= $post->imageWidth ?>"
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"/>
</object>
@ -40,7 +40,7 @@
<video style="max-width: 100%" controls>
<source
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.
</video>

View file

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

View file

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

View file

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

View file

@ -1,9 +1,9 @@
<?php
CustomAssetViewDecorator::setSubTitle('upload');
CustomAssetViewDecorator::addStylesheet('post-upload.css');
CustomAssetViewDecorator::addScript('post-upload.js');
CustomAssetViewDecorator::addStylesheet('../lib/tagit/jquery.tagit.css');
CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
Assets::setSubTitle('upload');
Assets::addStylesheet('post-upload.css');
Assets::addScript('post-upload.js');
Assets::addStylesheet('../lib/tagit/jquery.tagit.css');
Assets::addScript('../lib/tagit/jquery.tagit.js');
?>
<div id="sidebar">
@ -37,7 +37,7 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
<div class="clear"></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>
<div class="posts">
@ -51,7 +51,7 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
<div id="post-template" class="post">
<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="ops">
@ -68,7 +68,7 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
</a>
</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">
<label>File:</label>
<strong>filename.jpg</strong>
@ -121,4 +121,4 @@ CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
</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',
TextHelper::reprPost($this->context->transport->post),
TextHelper::reprTags($this->context->transport->post->getTags()));
CustomAssetViewDecorator::setSubTitle($subTitle);
CustomAssetViewDecorator::addStylesheet('post-view.css');
CustomAssetViewDecorator::addScript('post-view.js');
CustomAssetViewDecorator::addStylesheet('../lib/tagit/jquery.tagit.css');
CustomAssetViewDecorator::addScript('../lib/tagit/jquery.tagit.js');
Assets::setSubTitle($subTitle);
Assets::addStylesheet('post-view.css');
Assets::addScript('post-view.js');
Assets::addStylesheet('../lib/tagit/jquery.tagit.css');
Assets::addScript('../lib/tagit/jquery.tagit.js');
$editPostPrivileges = [
Privilege::EditPostSafety,
@ -30,7 +30,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<nav id="around">
<div class="left">
<?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: ?>
<a class="disabled">
<?php endif ?>
@ -41,7 +41,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="right">
<?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: ?>
<a class="disabled">
<?php endif ?>
@ -55,7 +55,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php if (!empty($this->context->transport->lastSearchQuery)): ?>
<div class="text">
Current&nbsp;search:<br/>
<a href="<?= \Chibi\UrlHelper::route('post', 'list', [
<a href="<?= \Chibi\Router::linkTo(['PostController', 'listAction'], [
'query' => $this->context->transport->lastSearchQuery]) ?>">
<?= $this->context->transport->lastSearchQuery ?>
</a>
@ -70,7 +70,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php uasort($tags, function($a, $b) { return strnatcasecmp($a->name, $b->name); }) ?>
<?php foreach ($tags as $tag): ?>
<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>
</li>
<?php endforeach ?>
@ -84,14 +84,14 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php $uploader = $this->context->transport->post->getUploader() ?>
<?php if ($uploader): ?>
<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 ?>"/>
<?= $val ?>
</a>
</span>
<?php else: ?>
<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() ?>
</span>
<?php endif ?>
@ -135,7 +135,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<span class="value">
<?= $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 ($this->context->score === 1): ?>
<a class="simple-action selected" href="<?= $scoreLink(0) ?>">
@ -162,7 +162,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="unit hl-options">
<?php if ($this->context->transport->post->type != PostType::Youtube): ?>
<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>
<span>
<?php
@ -179,12 +179,12 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php if (PrivilegesHelper::confirm(Privilege::FavoritePost, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
<div class="hl-option">
<?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>
<span>Add to favorites</span>
</a>
<?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>
<span>Remove from favorites</span>
</a>
@ -208,7 +208,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<ul>
<?php foreach ($this->context->transport->post->getFavorites() as $user): ?>
<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 ?>">
</a>
</li>
@ -223,7 +223,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<ul>
<?php foreach ($this->context->transport->post->getRelations() as $relatedPost): ?>
<li>
<a href="<?= \Chibi\UrlHelper::route('post', 'view', ['id' => $relatedPost->id]) ?>">
<a href="<?= \Chibi\Router::linkTo(['PostController', 'viewAction'], ['id' => $relatedPost->id]) ?>">
@<?= $relatedPost->id ?>
</a>
</li>
@ -241,9 +241,9 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[
'class' => 'feature',
'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-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',
'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?',
];
}
@ -278,7 +278,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[
'class' => '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
@ -287,7 +287,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
[
'class' => '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',
'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-redirect-url' => \Chibi\UrlHelper::route('post', 'list'),
'data-redirect-url' => \Chibi\Router::linkTo(['PostController', 'listAction']),
];
}
$this->context->options = $options;
$this->renderFile('sidebar-options');
\Chibi\View::render('sidebar-options', $this->context);
?>
</div>
<div id="inner-content">
<?php if ($canEditAnything): ?>
<div class="unit edit-post">
<?php $this->renderFile('post-edit') ?>
<?php \Chibi\View::render('post-edit', $this->context) ?>
</div>
<?php endif ?>
<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>
<?php
CustomAssetViewDecorator::addStylesheet('comment-list.css');
CustomAssetViewDecorator::addStylesheet('comment-small.css');
Assets::addStylesheet('comment-list.css');
Assets::addStylesheet('comment-small.css');
?>
<div class="comments-wrapper">
<?php if (!empty($this->context->transport->post->getComments())): ?>
@ -331,7 +331,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<div class="comments">
<?php foreach ($this->context->transport->post->getComments() as $comment): ?>
<?php $this->context->comment = $comment ?>
<?= $this->renderFile('comment-small') ?>
<?= \Chibi\View::render('comment-small', $this->context) ?>
<?php endforeach ?>
</div>
</div>
@ -340,7 +340,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php if (PrivilegesHelper::confirm(Privilege::AddComment)): ?>
<div class="unit comment-add">
<?php $this->renderFile('comment-add') ?>
<?php \Chibi\View::render('comment-add', $this->context) ?>
</div>
<?php endif ?>
</div>

View file

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

View file

@ -16,7 +16,7 @@
<?php else: ?>
<li>
<?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>
<?php endforeach ?>
</ul>
@ -28,7 +28,7 @@
<?php $max = $this->context->highestUsage ?>
<?php $add = 0. ?>
<?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">
<ul>
<?php foreach ($this->context->transport->tags as $tag): ?>
@ -43,5 +43,5 @@
</ul>
</div>
<?php $this->renderFile('paginator') ?>
<?php \Chibi\View::render('paginator', $this->context) ?>
<?php endif ?>

View file

@ -1,5 +1,5 @@
<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>
<div class="form-row">

View file

@ -1,5 +1,5 @@
<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>
<div class="form-row">
@ -18,7 +18,7 @@
<input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?>
<?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row">
<label></label>

View file

@ -1,5 +1,5 @@
<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>
<div class="form-row">
@ -18,7 +18,7 @@
<input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?>
<?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row">
<label></label>

View file

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

View file

@ -1,5 +1,5 @@
<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"
class="delete confirmable"
autocomplete="off"
@ -16,7 +16,7 @@
<input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?>
<?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row">
<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): ?>
<div class="form-row current-password">
<label for="current-password">Current password:</label>
@ -101,7 +101,7 @@
<input type="hidden" name="submit" value="1"/>
<?php $this->renderFile('message') ?>
<?php \Chibi\View::render('message', $this->context) ?>
<div class="form-row">
<label></label>

View file

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

View file

@ -1,15 +1,15 @@
<?php
CustomAssetViewDecorator::setSubTitle('registration form');
Assets::setSubTitle('registration form');
?>
<?php if ($this->context->transport->success === true): ?>
<?php $this->renderFile('message') ?>
<?php \Chibi\View::render('message', $this->context) ?>
<?php else: ?>
<?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>
<div class="form-row">
@ -68,7 +68,7 @@ CustomAssetViewDecorator::setSubTitle('registration form');
Leave blank for random Gravatar.
</p>
<?php $this->renderFile('message') ?>
<?php \Chibi\View::render('message', $this->context) ?>
<input type="hidden" name="submit" value="1"/>

View file

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

View file

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

View file

@ -1,10 +1,10 @@
<?php
$startTime = microtime(true);
define('SZURU_VERSION', '0.7.1');
define('SZURU_LINK', 'http://github.com/rr-/szurubooru');
//basic settings and preparation
define('DS', DIRECTORY_SEPARATOR);
$startTime = microtime(true);
$rootDir = __DIR__ . DS . '..' . DS;
date_default_timezone_set('UTC');
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 . 'php-markdown' . DS . 'Michelf' . DS . 'Markdown.php';
require_once $rootDir . 'lib' . DS . 'php-markdown' . DS . 'Michelf' . DS . 'MarkdownExtra.php';
require_once $rootDir . 'lib' . DS . 'chibi-core' . DS . 'Facade.php';
\Chibi\AutoLoader::init([__DIR__, $rootDir . 'lib' . DS . 'chibi-sql']);
require_once $rootDir . 'lib' . DS . 'chibi-core' . DS . 'include.php';
\Chibi\AutoLoader::registerFilesystem($rootDir . 'lib' . DS . 'chibi-sql');
\Chibi\AutoLoader::registerFilesystem(__DIR__);
//load config manually
$configPaths =
@ -27,7 +28,14 @@ $config = new \Chibi\Config();
foreach ($configPaths as $path)
if (file_exists($path))
$config->loadIni($path);
\Chibi\Registry::setConfig($config);
$config->rootDir = $rootDir;
function getConfig()
{
global $config;
return $config;
}
//extension sanity checks
$requiredExtensions = ['pdo', 'pdo_' . $config->main->dbDriver, 'gd', 'openssl', 'fileinfo'];
@ -35,12 +43,6 @@ foreach ($requiredExtensions as $ext)
if (!extension_loaded($ext))
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(
$config->main->dbDriver,
TextHelper::absolutePath($config->main->dbLocation),

View file

@ -1,6 +1,6 @@
<?php
require_once 'src/core.php';
$config = \Chibi\Registry::getConfig();
$config = getConfig();
function getDbVersion()
{
@ -29,7 +29,7 @@ function getDbVersion()
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');
natcasesort($upgrades);