forked from texnixe/kirby-logger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanelview.php
More file actions
51 lines (44 loc) · 1.16 KB
/
panelview.php
File metadata and controls
51 lines (44 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Logger;
use \Kirby\Panel\Topbar;
use \l;
use \r;
use \f;
use \c;
if(class_exists('Panel')) {
class LoggerController extends \Kirby\Panel\Controllers\Base {
public function view($file, $data = array()) {
return new LoggerView($file, $data);
}
public function getChanges() {
$filepath = panel()->site()->kirby()->roots()->index() . DS . "logger/log.txt";
$entries = c::get('logger.entries', 50);
$changes = tail($filepath, $entries);
return compact('changes', 'entries');
}
public function index() {
return $this->screen('index', new TopbarGenerator(), $this->getChanges());
}
}
class TopbarGenerator {
public function topbar(Topbar $topbar) {
$topbar->append(panel()->site()->url() . '/panel/logger', 'Logger');
}
}
class LoggerView extends \Kirby\Panel\View {
public function __construct($file, $data = array()) {
parent::__construct($file, $data);
$this->_root = __DIR__ . DS . 'views';
}
}
$panel = panel();
$panel->routes[] = [
'pattern' => 'logger',
'action' => function() {
$ctrl = new LoggerController();
return $ctrl->index();
},
'method' => 'GET',
'filter' => array('auth')
];
}