diff --git a/init.php b/init.php
index c7a29ade..6102642a 100644
--- a/init.php
+++ b/init.php
@@ -1,6 +1,6 @@
main->mediaPath . DS . 'fonts');
$libPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'lib');
diff --git a/lib/chibi-core b/lib/chibi-core
index 32f3c041..45c662d0 160000
--- a/lib/chibi-core
+++ b/lib/chibi-core
@@ -1 +1 @@
-Subproject commit 32f3c0418d758a693fe09170baa8043c38fe8cb8
+Subproject commit 45c662d0a4b32e09399b5b68ac53aaa3f1a29911
diff --git a/public_html/dispatch.php b/public_html/dispatch.php
index ea08b316..64667d9e 100644
--- a/public_html/dispatch.php
+++ b/public_html/dispatch.php
@@ -1,5 +1,198 @@
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();
+}
diff --git a/scripts/process-detached-files.php b/scripts/process-detached-files.php
index 382ca7c7..7ccdb058 100644
--- a/scripts/process-detached-files.php
+++ b/scripts/process-detached-files.php
@@ -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);
diff --git a/src/Bootstrap.php b/src/Bootstrap.php
deleted file mode 100644
index 055944b2..00000000
--- a/src/Bootstrap.php
+++ /dev/null
@@ -1,70 +0,0 @@
-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();
- }
-}
diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php
index 873601ec..0731e76a 100644
--- a/src/Controllers/AuthController.php
+++ b/src/Controllers/AuthController.php
@@ -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;
}
diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php
index 52382967..096d803a 100644
--- a/src/Controllers/CommentController.php
+++ b/src/Controllers/CommentController.php
@@ -1,17 +1,12 @@
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);
diff --git a/src/Controllers/IndexController.php b/src/Controllers/IndexController.php
index 386fe063..a76726dc 100644
--- a/src/Controllers/IndexController.php
+++ b/src/Controllers/IndexController.php
@@ -1,43 +1,39 @@
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);
diff --git a/src/Controllers/LogController.php b/src/Controllers/LogController.php
index 00726d7e..888a5542 100644
--- a/src/Controllers/LogController.php
+++ b/src/Controllers/LogController.php
@@ -1,14 +1,12 @@
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;
}
}
diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php
index 25381571..05946e03 100644
--- a/src/Controllers/PostController.php
+++ b/src/Controllers/PostController.php
@@ -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;
}
diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php
index 7c69216c..20109e87 100644
--- a/src/Controllers/TagController.php
+++ b/src/Controllers/TagController.php
@@ -1,53 +1,44 @@
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));
}
}
}
diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php
index 83236026..ef3ddb2a 100644
--- a/src/Controllers/UserController.php
+++ b/src/Controllers/UserController.php
@@ -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'))
{
diff --git a/src/CustomMarkdown.php b/src/CustomMarkdown.php
index 99acb544..2cc80f6c 100644
--- a/src/CustomMarkdown.php
+++ b/src/CustomMarkdown.php
@@ -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('/(?:(?hashPart('' . $x[0] . '
');
@@ -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('/(?:(?hashPart('' . $x[0] . '');
@@ -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('/(?:(?hashPart('' . $x[0] . '');
@@ -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('' . $x[1] . '');
diff --git a/src/Helpers/CustomAssetViewDecorator.php b/src/Helpers/Assets.php
similarity index 70%
rename from src/Helpers/CustomAssetViewDecorator.php
rename to src/Helpers/Assets.php
index 86acb35c..50d555ce 100644
--- a/src/Helpers/CustomAssetViewDecorator.php
+++ b/src/Helpers/Assets.php
@@ -1,9 +1,15 @@
';
- $headSnippet .= '';
+ $headSnippet .= '';
if (!empty(self::$pageThumb))
$headSnippet .= '';
@@ -38,3 +54,5 @@ class CustomAssetViewDecorator extends \Chibi\AssetViewDecorator
return $html;
}
}
+
+Assets::init();
diff --git a/src/Helpers/LogHelper.php b/src/Helpers/LogHelper.php
index f1ad941a..ee110410 100644
--- a/src/Helpers/LogHelper.php
+++ b/src/Helpers/LogHelper.php
@@ -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);
diff --git a/src/Helpers/PrivilegesHelper.php b/src/Helpers/PrivilegesHelper.php
index 5252b736..9d0c9611 100644
--- a/src/Helpers/PrivilegesHelper.php
+++ b/src/Helpers/PrivilegesHelper.php
@@ -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
diff --git a/src/Helpers/StatusHelper.php b/src/Helpers/StatusHelper.php
index 59db5964..223956e3 100644
--- a/src/Helpers/StatusHelper.php
+++ b/src/Helpers/StatusHelper.php
@@ -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;
}
diff --git a/src/Helpers/TextHelper.php b/src/Helpers/TextHelper.php
index bdb0904a..c0b758f1 100644
--- a/src/Helpers/TextHelper.php
+++ b/src/Helpers/TextHelper.php
@@ -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;
diff --git a/src/Models/CommentModel.php b/src/Models/CommentModel.php
index d7d47f27..74e1a3a3 100644
--- a/src/Models/CommentModel.php
+++ b/src/Models/CommentModel.php
@@ -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);
diff --git a/src/Models/Entities/PostEntity.php b/src/Models/Entities/PostEntity.php
index 4ae6cb9c..c8251d4a 100644
--- a/src/Models/Entities/PostEntity.php
+++ b/src/Models/Entities/PostEntity.php
@@ -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':
diff --git a/src/Models/Entities/UserEntity.php b/src/Models/Entities/UserEntity.php
index b23998c0..07a4d7c3 100644
--- a/src/Models/Entities/UserEntity.php
+++ b/src/Models/Entities/UserEntity.php
@@ -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;
}
diff --git a/src/Models/PostModel.php b/src/Models/PostModel.php
index f1575234..b616fd0b 100644
--- a/src/Models/PostModel.php
+++ b/src/Models/PostModel.php
@@ -13,7 +13,7 @@ class PostModel extends AbstractCrudModel
public static function init()
{
- self::$config = \Chibi\Registry::getConfig();
+ self::$config = getConfig();
}
public static function spawn()
diff --git a/src/Models/SearchParsers/PostSearchParser.php b/src/Models/SearchParsers/PostSearchParser.php
index 52691ec1..fc097242 100644
--- a/src/Models/SearchParsers/PostSearchParser.php
+++ b/src/Models/SearchParsers/PostSearchParser.php
@@ -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']))
{
diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php
index 42f9851f..502023db 100644
--- a/src/Models/UserModel.php
+++ b/src/Models/UserModel.php
@@ -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);
}
}
diff --git a/src/Views/auth-login.phtml b/src/Views/auth-login.phtml
index 5dd50076..cb827168 100644
--- a/src/Views/auth-login.phtml
+++ b/src/Views/auth-login.phtml
@@ -1,12 +1,12 @@
-