-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdcc.php
175 lines (142 loc) · 4.02 KB
/
xdcc.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
//controler
require_once 'database.php';
require_once 'class/Bookmark.php';
require_once 'class/Bot.php';
function haveXMLContent($xmlFile) {
$filecontent = file_get_contents($xmlFile);
return simplexml_load_string($filecontent);
}
// return bookmark or bot object
function returnObject($b, $n) {
for($i = 0; $i < count($b); $i++) {
if($b[$i]->getName() == $n) {
return $b[$i];
}
}
}
function searchId($b, $n) {
for($i = 0; $i < count($b); $i++) {
if($b[$i]->getName() == $n) {
return $i;
}
}
}
class XDCC_File {
private $id = "";
private $name = "";
function __construct($id, $n) {
$this->id = $id;
$this->name = $n;
}
public function getId() {
return $this->id;
}
public function getName() {
return $this->name;
}
}
/*
____ _ _
| __ ) ___ ___ | | ___ __ ___ __ _ _ __| | __
| _ \ / _ \ / _ \| |/ / '_ ` _ \ / _` | '__| |/ /
| |_) | (_) | (_) | <| | | | | | (_| | | | <
|____/ \___/ \___/|_|\_\_| |_| |_|\__,_|_| |_|\_\
*/
function getBookmarkList() {
$jsonRS = readBookmarkFile();
$bookmarks = array();
foreach ($jsonRS as $rs) {
array_push($bookmarks, new Bookmark(stripslashes($rs['name']), stripslashes($rs['search']), stripslashes($rs['bot'])));
}
return $bookmarks;
}
function insertBookmark($b) {
$bookmarks = getBookmarkList();
array_push($bookmarks, $b);
// save database
saveBookmarkList($bookmarks);
}
// http://stackoverflow.com/q/21559760
function removeBookmark($bname) {
$bookmarks = getBookmarkList();
$id = searchId($bookmarks, $bname);
unset($bookmarks[$id]); // removes the array at given index
$reindex = array_values($bookmarks); // normalize index
$bookmarks = $reindex; // update variable
saveBookmarkList($bookmarks);
}
/*
____ _
| __ ) ___ | |_
| _ \ / _ \| __|
| |_) | (_) | |_
|____/ \___/ \__|
*/
function getBotList() {
$jsonRS = readBotFile();
$bots = array();
foreach ($jsonRS as $rs) {
array_push($bots, new Bot(stripslashes($rs['name']), stripslashes($rs['xml']), stripslashes($rs['website']), stripslashes($rs['irc'])));
}
return $bots;
}
function insertBot($b) {
$bots = getBotList();
array_push($bots, $b);
// save database
saveBotList($bots);
}
// http://stackoverflow.com/q/21559760
function removeBot($bname) {
$bots = getBotList();
$id = searchId($bots, $bname);
unset($bots[$id]); // removes the array at given index
$reindex = array_values($bots); // normalize index
$bots = $reindex; // update variable
saveBotList($bots);
}
function searchBotXMLContent($b, $n) {
for($i = 0; $i < count($b); $i++) {
if($b[$i]->getName() == $n) {
return $b[$i]->getXmlContent();
}
}
}
function searchBotList($xml, $bot, $search = null, $onBot = true) {
$dom = "";
foreach($xml->packlist->pack as $p) {
if ($search === null || stripos($p->packname, $search) !== false) {
$dom .= "<tbody><tr title=\"$bot — {$p->packname}\" onclick=\"javascript:paste('$bot', {$p->packnr});\">";
if (!$onBot)
$dom .= "<td class=\"text-center\">$bot</td>";
$dom .= "<td class=\"text-center\">{$p->packnr}</td>";
$dom .= "<td class=\"text-center\">{$p->packsize}</td>";
$dom .= "<td>{$p->packname}</td>";
$dom .= "</tr></tbody>";
}
}
return $dom;
}
function searchBotsList($search) {
require 'config.php'; // with require_once, it does nothing
$dom = "";
$bots = getBotList();
$dom .= "<table id=\"filelist\">";
$dom .= "<tr id=\"trmain\">";
$dom .= "<th>{$lang[$language]['Bot:']}</th>";
$dom .= "<th>{$lang[$language]['Pack']}</th>";
$dom .= "<th>{$lang[$language]['Size']}</th>";
$dom .= "<th>{$lang[$language]['File']}</th>";
$dom .= "</tr>";
foreach($bots as $bot) {
$xml = haveXMLContent(searchBotXMLContent(getBotList(), $bot->getName()));
if (!$xml || !$xml->packlist->pack)
;
else
$dom .= searchBotList($xml, $bot->getName(), $search, false);
}
$dom .= "</table>";
return $dom;
}
?>