]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - Classes/class-notes.php
Fix overflow on long spamfilter entries
[irc/unrealircd/unrealircd-webpanel.git] / Classes / class-notes.php
CommitLineData
7bcd30ed
VP
1<?php
2
3/* Make notes against nicks, IPs and account names. */
4
5class Notes { // OKAY CLASS GET YOUR NOTEPAD OUT
6 /**
7 * Find function for Notes
8 * @param array $query The query to search for -- ["ip" => "127.0.0.1", "nick" => "bob", "account" => "bob", "id" => "lol]
d5ffb4bb 9 * @return array Returns an array of objects (notes)
7bcd30ed 10 */
d5ffb4bb 11 public static function find(array $query) : array
7bcd30ed
VP
12 {
13 global $config;
14 read_config_db();
15 if (!isset($config['notes']))
d5ffb4bb 16 return [];
7bcd30ed
VP
17
18 $notes = [];
19 foreach ($query as $key => $value)
d5ffb4bb
VP
20 {
21 foreach ($config['notes'] as $nkey => $nvalue) // $nkey = "ip" "nick" "account", $nvalue = array
7bcd30ed 22 {
d5ffb4bb
VP
23 foreach ($nvalue as $k => $n) // $k = "127.0.0.1", "bob", "bobsaccount", $n = array of notes [id => note]
24 {
25 if ($value != $k)
26 continue;
27 $note = [];
28 $note["type"] = $nkey;
29 $note["data"] = $k;
30 $note["notes"] = $n;
31 $notes[$key] = $note;
32 }
7bcd30ed
VP
33 }
34 }
d5ffb4bb 35 return !empty($notes) ? $notes : [];
7bcd30ed
VP
36 }
37
38 /**
39 * Add a note to one or more peices of data
40 * @param array ["ip" => "127.0.0.1"]
41 * @param string $note "This is a note"
42 * @return void
43 */
44 public static function add(array $params, string $note)
45 {
46 global $config;
47 read_config_db();
48 foreach ($params as $key => $value)
49 {
50 $id = md5(random_bytes(20)); // note ID (for linking)
51 $config['notes'][$key][$value][$id] = $note;
52 }
53 write_config(); // write db
54 }
55
56 public static function delete_by_id(string $id)
57 {
58 global $config;
59 read_config_db();
60 if (!isset($config['notes']))
61 return NULL;
62
63 foreach ($config['notes'] as $nkey => $nvalue)
64 foreach ($nvalue as $key => $value)
65 if ($value == $id)
66 {
67 unset($config['notes'][$nkey][$key]);
68 break;
69 }
70
71 write_config('notes');
72 }
73}