-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetchposts.php
299 lines (264 loc) · 8.69 KB
/
fetchposts.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
/***************************************************************************
* fetchposts.php
* -------------------
* begin : Tuesday, August 13, 2002
* copyright : (C) 2002 Smartor
* email : [email protected]
* original work : Volker Rattel <[email protected]>
*
* $Id: fetchposts.php,v 1.1 2004/04/25 09:00:38 RJ Exp $
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/***************************************************************************
*
* Some code in this file I borrowed from the phpBB Fetch Posts MOD by Ca5ey
* and Mouse Hover Topic Preview MOD by Shannado
*
***************************************************************************/
if ( !defined('IN_PHPBB') )
{
die("Hacking attempt");
}
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime(0);
include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx);
function phpbb_fetch_posts($forum_sql, $number_of_posts, $text_length)
{
global $db, $board_config;
$sql = 'SELECT
t.topic_id,
t.topic_time,
t.topic_title,
pt.post_text,
u.username,
u.user_id,
t.topic_replies,
pt.bbcode_uid,
t.forum_id,
t.topic_poster,
t.topic_first_post_id,
t.topic_status,
pt.post_id,
p.post_id,
p.enable_smilies
FROM
' . TOPICS_TABLE . ' AS t,
' . USERS_TABLE . ' AS u,
' . POSTS_TEXT_TABLE . ' AS pt,
' . POSTS_TABLE . ' AS p
WHERE
t.forum_id IN (' . $forum_sql . ') AND
t.topic_time <= ' . time() . ' AND
t.topic_poster = u.user_id AND
t.topic_first_post_id = pt.post_id AND
t.topic_first_post_id = p.post_id AND
t.topic_type in ('.POST_ANNOUNCE.')
ORDER BY
t.topic_time DESC';
if ($number_of_posts != 0)
{
$sql .= '
LIMIT
0,' . $number_of_posts;
}
//
// query the database
//
if(!($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, 'Could not query announcements information', '', __LINE__, __FILE__, $sql);
}
//
// fetch all postings
//
$posts = array();
if ($row = $db->sql_fetchrow($result))
{
$i = 0;
do
{
$posts[$i]['bbcode_uid'] = $row['bbcode_uid'];
$posts[$i]['enable_smilies'] = $row['enable_smilies'];
$posts[$i]['post_text'] = $row['post_text'];
$posts[$i]['topic_id'] = $row['topic_id'];
$posts[$i]['topic_replies'] = $row['topic_replies'];
$posts[$i]['topic_time'] = create_date($board_config['default_dateformat'], $row['topic_time'], $board_config['board_timezone']);
$posts[$i]['topic_title'] = $row['topic_title'];
$posts[$i]['user_id'] = $row['user_id'];
$posts[$i]['username'] = $row['username'];
//
// do a little magic
// note: part of this comes from mds' news script and some additional magics from Smartor
//
stripslashes($posts[$i]['post_text']);
if (($text_length == 0) or (strlen($posts[$i]['post_text']) <= $text_length))
{
$posts[$i]['post_text'] = bbencode_second_pass($posts[$i]['post_text'], $posts[$i]['bbcode_uid']);
$posts[$i]['striped'] = 0;
}
else // strip text for news
{
$posts[$i]['post_text'] = bbencode_strip($posts[$i]['post_text'], $posts[$i]['bbcode_uid']);
$posts[$i]['post_text'] = substr($posts[$i]['post_text'], 0, $text_length) . '...';
$posts[$i]['striped'] = 1;
}
//
// Smilies
//
if ($posts[$i]['enable_smilies'] == 1)
{
$posts[$i]['post_text'] = smilies_pass($posts[$i]['post_text']);
}
$posts[$i]['post_text'] = make_clickable($posts[$i]['post_text']);
//
// define censored word matches
//
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
//
// censor text and title
//
if (count($orig_word))
{
$posts[$i]['topic_title'] = preg_replace($orig_word, $replacement_word, $posts[$i]['topic_title']);
$posts[$i]['post_text'] = preg_replace($orig_word, $replacement_word, $posts[$i]['post_text']);
}
$posts[$i]['post_text'] = nl2br($posts[$i]['post_text']);
$i++;
}
while ($row = $db->sql_fetchrow($result));
}
//
// return the result
//
return $posts;
} // phpbb_fetch_posts
function phpbb_fetch_poll($forum_sql)
{
global $db;
$sql = 'SELECT
t.*,
vd.*
FROM
' . TOPICS_TABLE . ' AS t,
' . VOTE_DESC_TABLE . ' AS vd
WHERE
t.forum_id IN (' . $forum_sql . ') AND
t.topic_status <> 1 AND
t.topic_status <> 2 AND
t.topic_vote = 1 AND
t.topic_id = vd.topic_id
ORDER BY
t.topic_time DESC
LIMIT
0,1';
if (!$query = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not query poll information', '', __LINE__, __FILE__, $sql);
}
$result = $db->sql_fetchrow($query);
if ($result)
{
$sql = 'SELECT
*
FROM
' . VOTE_RESULTS_TABLE . '
WHERE
vote_id = ' . $result['vote_id'] . '
ORDER BY
vote_option_id';
if (!$query = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not query vote result information', '', __LINE__, __FILE__, $sql);
}
while ($row = $db->sql_fetchrow($query))
{
$result['options'][] = $row;
}
}
return $result;
} // end func phpbb_fetch_poll
//
// Function strip all BBcodes (borrowed from Mouse Hover Topic Preview MOD)
//
function bbencode_strip($text, $uid)
{
// pad it with a space so we can distinguish between FALSE and matching the 1st char (index 0).
// This is important; bbencode_quote(), bbencode_list(), and bbencode_code() all depend on it.
$text = " " . $text;
// First: If there isn't a "[" and a "]" in the message, don't bother.
if (! (strpos($text, "[") && strpos($text, "]")) )
{
// Remove padding, return.
$text = substr($text, 1);
return $text;
}
// [CODE] and [ /CODE ] for posting code (HTML, PHP, C etc etc) in your posts.
$text = str_replace("[code:1:$uid]","", $text);
$text = str_replace("[/code:1:$uid]", "", $text);
$text = str_replace("[code:$uid]", "", $text);
$text = str_replace("[/code:$uid]", "", $text);
// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = str_replace("[quote:1:$uid]","", $text);
$text = str_replace("[/quote:1:$uid]", "", $text);
$text = str_replace("[quote:$uid]", "", $text);
$text = str_replace("[/quote:$uid]", "", $text);
// New one liner to deal with opening quotes with usernames...
// replaces the two line version that I had here before..
$text = preg_replace("/\[quote:$uid=(?:\"?([^\"]*)\"?)\]/si", "", $text);
$text = preg_replace("/\[quote:1:$uid=(?:\"?([^\"]*)\"?)\]/si", "", $text);
// [list] and [list=x] for (un)ordered lists.
// unordered lists
$text = str_replace("[list:$uid]", "", $text);
// li tags
$text = str_replace("[*:$uid]", "", $text);
// ending tags
$text = str_replace("[/list:u:$uid]", "", $text);
$text = str_replace("[/list:o:$uid]", "", $text);
// Ordered lists
$text = preg_replace("/\[list=([a1]):$uid\]/si", "", $text);
// colours
$text = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+):$uid\]/si", "", $text);
$text = str_replace("[/color:$uid]", "", $text);
// url #2
$text = str_replace("[url]","", $text);
$text = str_replace("[/url]", "", $text);
// url /\[url=([a-z0-9\-\.,\?!%\*_\/:;~\\&$@\/=\+]+)\](.*?)\[/url\]/si
$text = preg_replace("/\[url=([a-z0-9\-\.,\?!%\*_\/:;~\\&$@\/=\+]+)\]/si", "", $text);
$text = str_replace("[/url:$uid]", "", $text);
// img
$text = str_replace("[img:$uid]","", $text);
$text = str_replace("[/img:$uid]", "", $text);
// email
$text = str_replace("[email:$uid]","", $text);
$text = str_replace("[/email:$uid]", "", $text);
// size
$text = preg_replace("/\[size=([\-\+]?[1-2]?[0-9]):$uid\]/si", "", $text);
$text = str_replace("[/size:$uid]", "", $text);
// align
$text = preg_replace("/\[align=(left|right|center|justify):$uid\]/si", "", $text);
$text = str_replace("[/align:$uid]", "", $text);
// [b] and [/b] for bolding text.
$text = str_replace("[b:$uid]","", $text);
$text = str_replace("[/b:$uid]", "", $text);
// [u] and [/u] for underlining text.
$text = str_replace("[u:$uid]", "", $text);
$text = str_replace("[/u:$uid]", "", $text);
// [i] and [/i] for italicizing text.
$text = str_replace("[i:$uid]", "", $text);
$text = str_replace("[/i:$uid]", "", $text);
// Remove our padding from the string..
$text = substr($text, 1);
return $text;
}
?>