1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
19: class LinksController {
20:
21: 22: 23: 24:
25: public $moduleName;
26:
27:
28: public $db;
29:
30:
31: public $settingManager;
32:
33:
34: public $text;
35:
36:
37: public $accessManager;
38:
39: 40: 41:
42: public function setup() {
43: $this->db->loadSQLFile($this->moduleName, "links");
44: $this->settingManager->add($this->moduleName, 'showfullurls', 'Enable full urls in the link list output', 'edit', "options", 0, "true;false", "1;0");
45: }
46:
47: 48: 49: 50:
51: public function linksListCommand($message, $channel, $sender, $sendto, $args) {
52: $blob = '';
53:
54: $sql = "SELECT * FROM links ORDER BY name ASC";
55: $data = $this->db->query($sql);
56: forEach ($data as $row) {
57: $remove = $this->text->makeChatcmd('Remove', "/tell <myname> <symbol>links rem $row->id");
58: if ($this->settingManager->get('showfullurls') == 1) {
59: $website = $this->text->makeChatcmd($row->website, "/start $row->website");
60: } else {
61: $website = $this->text->makeChatcmd('[Link]', "/start $row->website");
62: }
63: $blob .= "$website <highlight>$row->comments<end> [$row->name] $remove\n";
64: }
65:
66: if (count($data) == 0) {
67: $msg = "No links found.";
68: } else {
69: $msg = $this->text->makeBlob('Links', $blob);
70: }
71:
72: $sendto->reply($msg);
73: }
74:
75: 76: 77: 78:
79: public function linksAddCommand($message, $channel, $sender, $sendto, $args) {
80: $website = htmlspecialchars($args[1]);
81: $comments = $args[2];
82:
83: $this->db->exec("INSERT INTO links (`name`, `website`, `comments`, `dt`) VALUES (?, ?, ?, ?)", $sender, $website, $comments, time());
84: $msg = "Link added successfully.";
85: $sendto->reply($msg);
86: }
87:
88: 89: 90: 91:
92: public function linksRemoveCommand($message, $channel, $sender, $sendto, $args) {
93: $id = $args[1];
94:
95: $obj = $this->db->queryRow("SELECT * FROM links WHERE id = ?", $id);
96: if (empty($obj)) {
97: $msg = "Link with ID <highlight>$id<end> could not be found.";
98: } else if ($obj->name == $sender || $this->accessManager->compareCharacterAccessLevels($sender, $obj->name) > 0) {
99: $this->db->exec("DELETE FROM links WHERE id = ?", $id);
100: $msg = "Link with ID <highlight>$id<end> deleted successfully.";
101: } else {
102: $msg = "You do not have permission to delete link with ID <highlight>$id<end>";
103: }
104: $sendto->reply($msg);
105: }
106: }
107: