blob: 0e11bf8eff982a6984bbd8d319fabaf01ba07e52 (
plain)
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
|
<?php
use Engelsystem\Database\DB;
/**
* Creates a log entry.
*
* @param string $nick Username
* @param string $message Log Message
* @return bool
*/
function LogEntry_create($nick, $message)
{
return DB::insert('
INSERT INTO `LogEntries` (`timestamp`, `nick`, `message`)
VALUES(?, ?, ?)
', [time(), $nick, $message]);
}
/**
* Returns log entries with maximum count of 10000.
*
* @return array
*/
function LogEntries()
{
return DB::select('SELECT * FROM `LogEntries` ORDER BY `timestamp` DESC LIMIT 10000');
}
/**
* Returns log entries filtered by a keyword
*
* @param string $keyword
* @return array
*/
function LogEntries_filter($keyword)
{
if ($keyword == '') {
return LogEntries();
}
$keyword = '%' . $keyword . '%';
return DB::select('
SELECT *
FROM `LogEntries`
WHERE `nick` LIKE ?
OR `message` LIKE ?
ORDER BY `timestamp` DESC
',
[$keyword, $keyword]
);
}
/**
* Delete all log entries.
*
* @return bool
*/
function LogEntries_clear_all()
{
return DB::statement('TRUNCATE `LogEntries`');
}
|