Closed #69
This commit is contained in:
parent
752cbbd016
commit
36e2e5827c
5 changed files with 54 additions and 9 deletions
|
@ -30,6 +30,7 @@ paths[privacy]=./data/privacy.md
|
|||
[browsing]
|
||||
usersPerPage=8
|
||||
postsPerPage=20
|
||||
logsPerPage=250
|
||||
thumbWidth=150
|
||||
thumbHeight=150
|
||||
thumbStyle=outside
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
<?php if (empty($this->context->transport->log)): ?>
|
||||
<?php if (empty($this->context->transport->lines)): ?>
|
||||
<p class="alert alert-warning">This log is empty. <a href="<?php echo \Chibi\UrlHelper::route('log', 'list') ?>">Go back</a></p>
|
||||
<?php else: ?>
|
||||
<form action="<?php echo \Chibi\UrlHelper::route('log', 'view', ['name' => $this->context->transport->name]) ?>" method="get">
|
||||
Keep only lines that contain:
|
||||
|
||||
<input type="text" name="filter" value="<?php echo $this->context->transport->filter ?>" placeholder="any text…"/>
|
||||
<input type="text" name="query" value="<?php echo $this->context->transport->filter ?>" placeholder="any text…"/>
|
||||
</form>
|
||||
|
||||
<pre><?php echo $this->context->transport->log ?></pre>
|
||||
<div class="paginator-content">
|
||||
<pre><?php echo $this->context->transport->lines ?></pre>
|
||||
</div>
|
||||
|
||||
<?php $this->renderFile('paginator') ?>
|
||||
<?php endif ?>
|
||||
|
|
Loading…
Reference in a new issue