-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·245 lines (200 loc) · 6.47 KB
/
functions.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
// No cookies whatsoever
define('NOCOOKIES', 1);
$_COOKIE = array();
chdir('..');
require_once('./global.php');
require_once(DIR . '/includes/functions.php');
require_once(DIR . '/includes/functions_login.php');
function str($str, $amp = false) {
global $vbulletin;
if ($amp)
$str = str_replace('&', '&', $str);
$charset = vB_Template_Runtime::fetchStyleVar('charset');
if ($charset == '') $charset ='ISO-8859-1';
return to_utf8($str, $charset);
}
function fetch_forum($forumid) {
global $vbulletin;
if ($forumid == -1) {
return array(
'title' => str($vbulletin->options['bbtitle']),
'threadcount' => 0,
);
}
// Don't use cache as it doesn't include threadcount by default
$foruminfo = fetch_foruminfo($forumid, false);
if (!$foruminfo)
return false;
return array(
'id' => intval($foruminfo['forumid']),
'title' => str($foruminfo['title'], true),
'description' => str($foruminfo['description'], true),
'threadcount' => intval($foruminfo['threadcount']),
'replycount' => intval($foruminfo['replycount']),
);
}
function can_view_forum($foruminfo) {
global $vbulletin;
$forumperms = fetch_permissions($foruminfo['forumid']);
return ($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']);
// TODO: Forum password?
}
// @see construct_subforum_bit
function fetch_subforum_list($parentid = -1) {
global $vbulletin;
cache_ordered_forums(1); // 1 means: also cache thread/reply counts
$result = array();
if (!isset($vbulletin->iforumcache["$parentid"]))
return $result;
foreach ($vbulletin->iforumcache["$parentid"] as $forumid) {
$forum = $vbulletin->forumcache["$forumid"];
$forumperms = $vbulletin->userinfo['forumpermissions']["$forumid"];
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) AND
($vbulletin->forumcache["$forumid"]['showprivate'] == 1 OR
(!$vbulletin->forumcache["$forumid"]['showprivate'] AND
!$vbulletin->options['showprivateforums'])
)
) {
// no permission to view current forum
continue;
}
if (!$forum['displayorder'] OR
!($forum['options'] & $vbulletin->bf_misc_forumoptions['active'])) {
// forum not active
continue;
}
// get on/off status
//$lastpostinfo = $vbulletin->forumcache["$lastpostarray[$forumid]"];
//$forum['statusicon'] = fetch_forum_lightbulb($forumid, $lastpostinfo, $forum);
//$show['newposticon'] = ($forum['statusicon'] ? true : false);
$result[] = array(
'id' => $forum['forumid'],
'title' => str($forum['title'], true),
'description' => str($forum['description'], true),
'threadcount' => intval($forum['threadcount']),
'replycount' => intval($forum['replycount']),
);
}
return $result;
}
function fetch_threads($forumid, $perpage = 10, $page = 1) {
global $db;
if ($page < 1) $page = 1;
$offset = ($page - 1) * $perpage;
$allthreads = array();
// Show sticky threads only on first page
if ($page == 1) {
$stickies = $db->query_read_slave("
SELECT t.threadid, t.title, t.replycount
FROM " . TABLE_PREFIX . "thread t
WHERE t.forumid = $forumid
AND t.visible = 1
AND t.sticky = 1
AND t.open <> 10
ORDER BY t.lastpost DESC
");
while ($sticky = $db->fetch_array($stickies)) {
$sticky['sticky'] = true;
$allthreads[] = $sticky;
}
}
$threads = $db->query_read_slave("
SELECT t.threadid, t.title, t.replycount
FROM " . TABLE_PREFIX . "thread t
WHERE t.forumid = $forumid
AND t.visible = 1
AND t.sticky <> 1
AND t.open <> 10
ORDER BY t.lastpost DESC
LIMIT $offset, $perpage
");
$result = array();
while ($thread = $db->fetch_array($threads)) {
$allthreads[] = $thread;
}
foreach ($allthreads as $thread) {
$result[] = array(
'id' => intval($thread['threadid']),
'title' => str($thread['title'], true),
'replycount' => intval($thread['replycount']),
'sticky' => $thread['sticky'] ? true : false,
);
}
return $result;
}
function fetch_thread($threadid) {
global $vbulletin;
$threadinfo = fetch_threadinfo($threadid);
if (!$threadinfo)
return false;
return array(
'id' => intval($threadinfo['threadid']),
'forumid' => intval($threadinfo['forumid']),
'title' => str($threadinfo['title']),
'replycount' => intval($threadinfo['replycount']),
'open' => $threadinfo['open'] == 1,
);
}
function fetch_posts($threadid, $perpage = 10, $page = 1) {
global $db;
$threadid = intval($threadid);
$perpage = intval($perpage);
$page = intval($page);
if ($page < 1) $page = 1;
$offset = ($page - 1) * $perpage;
$posts = $db->query_read("
SELECT p.username, p.pagetext
FROM " . TABLE_PREFIX . "post AS p
LEFT JOIN " . TABLE_PREFIX . "user AS u ON (u.userid = p.userid)
WHERE p.threadid = $threadid
AND p.visible = 1
ORDER BY p.dateline
LIMIT $offset, $perpage
");
$result = array();
while ($post = $db->fetch_array($posts)) {
$result[] = $post;
}
return $result;
}
function can_view_thread($threadinfo) {
// @see showthread.php
global $vbulletin;
$forumperms = fetch_permissions($threadinfo['forumid']);
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']))
return false;
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
return false;
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND
($thread['postuserid'] != $vbulletin->userinfo['userid'] OR
$vbulletin->userinfo['userid'] == 0))
return false;
// TODO: Forum password?
return true;
}
function login($username, $password) {
global $vbulletin;
if (verify_authentication($username, $password, '', '', '', false)) {
process_new_login('', '', '');
return get_userinfo();
} else {
return false;
}
}
function logout() {
process_logout();
return get_userinfo();
}
function get_userinfo() {
global $vbulletin;
return array(
'id' => intval($vbulletin->userinfo['userid']),
'name' => str($vbulletin->userinfo['username']),
's' => str($vbulletin->session->vars['dbsessionhash']),
);
}
function shutdown() {
exec_shut_down(); // Save session, close DB etc.
}
?>