diff --git a/data/config.ini b/data/config.ini index 58850975..bbbda47d 100644 --- a/data/config.ini +++ b/data/config.ini @@ -30,6 +30,7 @@ paths[privacy]=./data/privacy.md [browsing] usersPerPage=8 postsPerPage=20 +logsPerPage=250 thumbWidth=150 thumbHeight=150 thumbStyle=outside diff --git a/public_html/media/css/logs.css b/public_html/media/css/logs.css index ecd40ec8..01c250ec 100644 --- a/public_html/media/css/logs.css +++ b/public_html/media/css/logs.css @@ -1,3 +1,7 @@ +#content form { + margin-bottom: 1em; +} + #content input { margin: 0 1em; height: 25px; @@ -6,6 +10,7 @@ pre { font-size: 11pt; + margin: 0; } pre strong { diff --git a/src/Controllers/LogController.php b/src/Controllers/LogController.php index 9d91e0e9..e11cdab4 100644 --- a/src/Controllers/LogController.php +++ b/src/Controllers/LogController.php @@ -25,22 +25,46 @@ class LogController /** * @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) + public function viewAction($name, $page = 1, $filter = '') { + //redirect requests in form of ?query=... to canonical address + $formQuery = InputHelper::get('query'); + if ($formQuery !== null) + { + \Chibi\UrlHelper::forward( + \Chibi\UrlHelper::route( + 'log', + 'view', + [ + 'name' => $name, + 'filter' => $formQuery, + 'page' => 1 + ])); + return; + } + $this->context->subTitle = 'logs (' . $name . ')'; $this->context->stylesheets []= 'logs.css'; + $this->context->stylesheets []= 'paginator.css'; $this->context->scripts []= 'logs.js'; + if ($this->context->user->hasEnabledEndlessScrolling()) + $this->context->scripts []= 'paginator-endless.js'; PrivilegesHelper::confirmWithException(Privilege::ViewLog); + //parse input + $page = max(1, intval($page)); $name = str_replace(['/', '\\'], '', $name); //paranoia mode $path = TextHelper::absolutePath($this->config->main->logsPath . DS . $name); if (!file_exists($path)) throw new SimpleException('Specified log doesn\'t exist'); - $filter = InputHelper::get('filter'); - + //load lines $lines = file_get_contents($path); $lines = explode(PHP_EOL, str_replace(["\r", "\n"], PHP_EOL, $lines)); $lines = array_reverse($lines); @@ -48,6 +72,13 @@ class LogController if (!empty($filter)) $lines = array_filter($lines, function($line) use ($filter) { return stripos($line, $filter) !== false; }); + $lineCount = count($lines); + $logsPerPage = intval($this->config->browsing->logsPerPage); + $pageCount = ceil($lineCount / $logsPerPage); + $page = min($pageCount, $page); + + $lines = array_slice($lines, ($page - 1) * $logsPerPage, $logsPerPage); + //stylize important lines foreach ($lines as &$line) if (strpos($line, 'flag') !== false) @@ -58,8 +89,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; - $this->context->transport->log = $lines; } } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index ee7e93ad..a6261bf6 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -75,7 +75,7 @@ class PostController } $query = trim($query); - $page = intval($page); + $page = max(1, intval($page)); $postsPerPage = intval($this->config->browsing->postsPerPage); $this->context->subTitle = 'posts'; $this->context->transport->searchQuery = $query; @@ -88,7 +88,6 @@ class PostController $this->context->massTagQuery = $query; } - $page = max(1, $page); $posts = PostSearchService::getEntities($query, $postsPerPage, $page); $postCount = PostSearchService::getEntityCount($query, $postsPerPage, $page); $pageCount = ceil($postCount / $postsPerPage); diff --git a/src/Views/log-view.phtml b/src/Views/log-view.phtml index f54dc4dc..08c8b96c 100644 --- a/src/Views/log-view.phtml +++ b/src/Views/log-view.phtml @@ -1,11 +1,15 @@ -context->transport->log)): ?> +context->transport->lines)): ?>
This log is empty. Go back
-context->transport->log ?>+
context->transport->lines ?>+