forked from samwilson/dokuwiki-plugin-log404
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
68 lines (62 loc) · 2.39 KB
/
admin.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* DokuWiki Plugin log404 (Admin Component)
*
* @license GPL 3 http://www.gnu.org/licenses/gpl-3.0.html
* @author Sam Wilson <[email protected]>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
/**
* The admin class handles the display and user-manipulation of the 404 log.
*/
class admin_plugin_log404 extends DokuWiki_Admin_Plugin {
public function handle() {
global $ID;
if (isset($_GET['delete'])) {
$log = $this->loadHelper('log404');
$log->deleteRecord($_GET['delete']);
msg("Records for ".$_GET['delete']." have been removed from the 404 log.");
send_redirect(wl($ID, array('do'=>'admin', 'page'=>$this->getPluginName()), true, '&'));
}
}
public function html() {
ptln('<h1>'.$this->getLang('menu').'</h1>');
$log = $this->loadHelper('log404');
$log->load();
ptln('<ol class='.$this->getPluginName().'>');
foreach ($log->getRecords() as $id => $detail) {
ptln($this->getHtml($id, $detail));
}
ptln('</ol>');
}
protected function getHtml($id, $data) {
global $ID;
$delUrl = wl($ID, array('do'=>'admin', 'page'=>$this->getPluginName(), 'delete'=>$id));
$ignoreUrl = wl($ID, array('do'=>'admin', 'page'=>$this->getPluginName(), 'ignore'=>$id));
$title = '<strong class="title">'.$data['count'].' <code>'.$id.'</code></strong> '
. ' <a href="'.wl($id).'">[Go to page]</a>'
. ' <a href="'.$delUrl.'">[Delete '.$data['count'].' log entries]</a>'
. ' <a href="'.$ignoreUrl.'">[Add to <em>ignore list</em>]</a>'
. '</span>';
$out = $title.'<ol>';
foreach ($data['hits'] as $hit) {
$line = $hit['date'];
if (!empty($hit['ip'])) {
$line .= ' <em>IP:</em> '.$hit['ip'];
}
if (!empty($hit['referer'])) {
$line .= ' <em>Referer:</em> <a href="'.$hit['referer'].'">'.$hit['referer'].'</a>';
}
if (!empty($hit['user_agent'])) {
$line .= ' <em>User Agent:</em> '.$hit['user_agent'];
}
// The line should never actually be empty, but still...
if (!empty($line)) {
$out .= "<li>$line</li>";
}
}
$out .= '</ol>';
return "<li>$out</li>";
}
}