This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/contrib/log_db/theme.php

86 lines
2.6 KiB
PHP
Raw Normal View History

2009-12-30 07:59:40 +00:00
<?php
class LogDatabaseTheme extends Themelet {
2010-02-03 13:57:39 +00:00
protected function heie($var) {
if(isset($_GET[$var])) return html_escape($_GET[$var]);
else return "";
}
2009-12-30 07:59:40 +00:00
public function display_events($events) {
2010-02-03 13:57:39 +00:00
$table = "
<style>
.sizedinputs TD INPUT {
width: 100%;
}
</style>
<table class='zebra'>
<thead>
<tr><th>Time</th><th>Module</th><th>User</th><th>Message</th></tr>
<form action='".make_link("log/view")."' method='GET'>
<tr class='sizedinputs'>
<td><input type='text' name='time' value='".$this->heie("time")."'></td>
<td><input type='text' name='module' value='".$this->heie("module")."'></td>
<td><input type='text' name='user' value='".$this->heie("user")."'></td>
<td>
<select name='priority'>
<option value='".SCORE_LOG_DEBUG."'>Debug</option>
<option value='".SCORE_LOG_INFO."' selected>Info</option>
<option value='".SCORE_LOG_WARNING."'>Warning</option>
<option value='".SCORE_LOG_ERROR."'>Error</option>
<option value='".SCORE_LOG_CRITICAL."'>Critical</option>
</select>
<input type='submit' value='Search' style='width: 20%'>
</td>
</tr>
</form>
</thead>
<tbody>\n";
2009-12-30 07:59:40 +00:00
$n = 0;
foreach($events as $event) {
$oe = ($n++ % 2 == 0) ? "even" : "odd";
2010-01-05 10:52:23 +00:00
$c = $this->pri_to_col($event['priority']);
$table .= "<tr style='color: $c' class='$oe'>";
$table .= "<td>".str_replace(" ", "&nbsp;", $event['date_sent'])."</td>";
$table .= "<td>".$event['section']."</td>";
if($event['username'] == "Anonymous") {
$table .= "<td>".$event['address']."</td>";
}
else {
$table .= "<td><span title='".$event['address']."'>".
"<a href='".make_link("user/".url_escape($event['username']))."'>".html_escape($event['username'])."</a>".
"</span></td>";
2010-01-05 10:52:23 +00:00
}
2010-02-02 00:55:34 +00:00
$table .= "<td>".$this->scan_entities(html_escape($event['message']))."</td>";
2010-01-05 10:52:23 +00:00
$table .= "</tr>\n";
2009-12-30 07:59:40 +00:00
}
$table .= "</tbody></table>";
global $page;
$page->set_title("Event Log");
$page->set_heading("Event Log");
$page->add_block(new NavBlock());
$page->add_block(new Block("Events", $table));
}
2010-01-05 10:52:23 +00:00
protected function pri_to_col($pri) {
switch($pri) {
case SCORE_LOG_DEBUG: return "#999";
case SCORE_LOG_INFO: return "#000";
case SCORE_LOG_WARNING: return "#800";
case SCORE_LOG_ERROR: return "#C00";
case SCORE_LOG_CRITICAL: return "#F00";
default: return "";
}
}
2010-02-02 00:55:34 +00:00
protected function scan_entities($line) {
$line = preg_replace_callback("/Image #(\d+)/s", array($this, "link_image"), $line);
return $line;
}
protected function link_image($id) {
$iid = int_escape($id[1]);
return "<a href='".make_link("post/view/$iid")."'>Image #$iid</a>";
}
2009-12-30 07:59:40 +00:00
}
?>