discuzcode.func.php
13.1 KB
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
300
301
302
303
304
305
306
307
308
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: discuzcode.func.php 35182 2015-01-12 02:05:50Z nemohou $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
include template('mobile:discuzcode');
function mobile_discuzcode($param) {
global $_G;
list($message, $smileyoff, $bbcodeoff, $htmlon, $allowsmilies, $allowbbcode, $allowimgcode, $allowhtml, $jammer, $parsetype, $authorid, $allowmediacode, $pid, $lazyload, $pdateline, $first) = $param;
static $authorreplyexist;
$message = preg_replace(array(lang('forum/misc', 'post_edit_regexp'), lang('forum/misc', 'post_edithtml_regexp'), lang('forum/misc', 'post_editnobbcode_regexp')), '', $message);
if($pid && strpos($message, '[/password]') !== FALSE) {
if($authorid != $_G['uid'] && !$_G['forum']['ismoderator']) {
$message = preg_replace("/\s?\[password\](.+?)\[\/password\]\s?/ie", "parsepassword('\\1', \$pid)", $message);
if($_G['forum_discuzcode']['passwordlock'][$pid]) {
return '';
}
} else {
$message = preg_replace("/\s?\[password\](.+?)\[\/password\]\s?/ie", "", $message);
$_G['forum_discuzcode']['passwordauthor'][$pid] = 1;
}
}
if($parsetype != 1 && !$bbcodeoff && $allowbbcode && (strpos($message, '[/code]') || strpos($message, '[/CODE]')) !== FALSE) {
$message = preg_replace("/\s?\[code\](.+?)\[\/code\]\s?/ies", "mobile_parsecode('\\1')", $message);
}
$msglower = strtolower($message);
$htmlon = $htmlon && $allowhtml ? 1 : 0;
if(!$htmlon) {
$message = dhtmlspecialchars($message);
} else {
$message = preg_replace("/<script[^\>]*?>(.*?)<\/script>/i", '', $message);
}
if(!$smileyoff && $allowsmilies) {
$message = mobile_parsesmiles($message);
}
if($_G['setting']['allowattachurl'] && strpos($msglower, 'attach://') !== FALSE) {
$message = preg_replace("/attach:\/\/(\d+)\.?(\w*)/ie", "parseattachurl('\\1', '\\2', 1)", $message);
}
if($allowbbcode) {
if(strpos($msglower, 'ed2k://') !== FALSE) {
$message = preg_replace("/ed2k:\/\/(.+?)\//e", "mobile_parseed2k('\\1')", $message);
}
}
if(!$bbcodeoff && $allowbbcode) {
if(strpos($msglower, '[/url]') !== FALSE) {
$message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.|mailto:)?([^\r\n\[\"']+?))?\](.+?)\[\/url\]/ies", "mobile_parseurl('\\1', '\\5', '\\2')", $message);
}
if(strpos($msglower, '[/email]') !== FALSE) {
$message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "strip_tags(parseemail('\\1', '\\4'))", $message);
}
$nest = 0;
while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '[/table]') !== FALSE){
$message = preg_replace("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/ies", "mobile_parsetable('\\1', '\\2', '\\3')", $message);
if(++$nest > 4) break;
}
$message = str_replace(array(
'[/color]', '[/backcolor]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[s]', '[/s]', '[hr]', '[/p]',
'[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
'[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
), array(
'</font>', '</font>', '', '', '', '<strong>', '</strong>', '<strike>', '</strike>', '<hr class="l" />', '</p>', '', '',
'', '', '', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
'<ul type="A" class="litype_3">', '<li>', '<li>', '</ul>', '', '', ''
), preg_replace(array(
"/\[color=([#\w]+?)\]/i",
"/\[color=((rgb|rgba)\([\d\s,]+?\))\]/i",
"/\[backcolor=([#\w]+?)\]/i",
"/\[backcolor=((rgb|rgba)\([\d\s,]+?\))\]/i",
"/\[size=(\d{1,2}?)\]/i",
"/\[size=(\d{1,2}(\.\d{1,2}+)?(px|pt)+?)\]/i",
"/\[font=([^\[\<]+?)\]/i",
"/\[align=(left|center|right)\]/i",
"/\[p=(\d{1,2}|null), (\d{1,2}|null), (left|center|right)\]/i",
"/\[float=left\]/i",
"/\[float=right\]/i"
), array(
"<font color=\"\\1\">",
"<font style=\"color:\\1\">",
"<font style=\"background-color:\\1\">",
"<font style=\"background-color:\\1\">",
"",
"",
"",
"",
"<p>",
"",
""
), $message));
$message = preg_replace("/\s?\[postbg\]\s*([^\[\<\r\n;'\"\?\(\)]+?)\s*\[\/postbg\]\s?/is", "", $message);
if($parsetype != 1) {
if(strpos($msglower, '[/quote]') !== FALSE) {
$message = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", mobile_quote(), $message);
}
if(strpos($msglower, '[/free]') !== FALSE) {
$message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", mobile_free(), $message);
}
}
if(strpos($msglower, '[/media]') !== FALSE) {
$message = preg_replace("/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/ies", "bbcodeurl('\\2', '<a class=\"media\" href=\"{url}\" target=\"_blank\">{url}</a>')", $message);
}
if(strpos($msglower, '[/audio]') !== FALSE) {
$message = preg_replace("/\[audio(=1)*\]\s*([^\[\<\r\n]+?)\s*\[\/audio\]/ies", "bbcodeurl('\\2', '<a href=\"{url}\" target=\"_blank\">{url}</a>')", $message);
}
if(strpos($msglower, '[/flash]') !== FALSE) {
$message = preg_replace("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/ies", "bbcodeurl('\\4', '<a href=\"{url}\" target=\"_blank\">{url}</a>')", $message);
}
if($parsetype != 1 && $allowbbcode < 0 && isset($_G['cache']['bbcodes'][-$allowbbcode])) {
$message = preg_replace($_G['cache']['bbcodes'][-$allowbbcode]['searcharray'], $_G['cache']['bbcodes'][-$allowbbcode]['replacearray'], $message);
}
if($parsetype != 1 && strpos($msglower, '[/hide]') !== FALSE && $pid) {
if($_G['setting']['hideexpiration'] && $pdateline && (TIMESTAMP - $pdateline) / 86400 > $_G['setting']['hideexpiration']) {
$message = preg_replace("/\[hide[=]?(d\d+)?[,]?(\d+)?\]\s*(.*?)\s*\[\/hide\]/is", "\\3", $message);
$msglower = strtolower($message);
}
if(strpos($msglower, '[hide=d') !== FALSE) {
$message = preg_replace("/\[hide=(d\d+)?[,]?(\d+)?\]\s*(.*?)\s*\[\/hide\]/ies", "expirehide('\\1','\\2','\\3', $pdateline)", $message);
$msglower = strtolower($message);
}
if(strpos($msglower, '[hide]') !== FALSE) {
if($authorreplyexist === null) {
if(!$_G['forum']['ismoderator']) {
if($_G['uid']) {
$authorreplyexist = C::t('forum_post')->fetch_pid_by_tid_authorid($_G['tid'], $_G['uid']);
}
} else {
$authorreplyexist = TRUE;
}
}
if($authorreplyexist) {
$message = preg_replace("/\[hide\]\s*(.*?)\s*\[\/hide\]/is", mobile_hide_reply(), $message);
} else {
$message = preg_replace("/\[hide\](.*?)\[\/hide\]/is", mobile_hide_reply_hidden(), $message);
}
}
if(strpos($msglower, '[hide=') !== FALSE) {
$message = preg_replace("/\[hide=(\d+)\]\s*(.*?)\s*\[\/hide\]/ies", "creditshide(\\1,'\\2', $pid, $authorid)", $message);
}
}
}
if(strpos($message, '[/tthread]') !== FALSE) {
$matches = array();
preg_match('/\[tthread=(.+?),(.+?)\](.*?)\[\/tthread\]/', $message, $matches);
$message = preg_replace('/\[tthread=(.+?)\](.*?)\[\/tthread\]/', lang('plugin/qqconnect', 'connect_tthread_message', array('username' => $matches[1], 'nick' => $matches[2])), $message);
}
if(!$bbcodeoff) {
if($parsetype != 1 && strpos($msglower, '[swf]') !== FALSE) {
$message = preg_replace("/\[swf\]\s*([^\[\<\r\n]+?)\s*\[\/swf\]/ies", "bbcodeurl('\\1', ' <img src=\"'.STATICURL.'image/filetype/flash.gif\" align=\"absmiddle\" alt=\"\" /> <a href=\"{url}\" target=\"_blank\">Flash: {url}</a> ')", $message);
}
$attrsrc = !IS_ROBOT && $lazyload ? 'file' : 'src';
if(strpos($msglower, '[/img]') !== FALSE) {
$message = preg_replace(array(
"/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies",
"/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies"
), $allowimgcode ? array(
"mobile_parseimg(0, 0, '\\1', ".intval($lazyload).", ".intval($pid).", 'onmouseover=\"img_onmouseoverfunc(this)\" ".($lazyload ? "lazyloadthumb=\"1\"" : "onload=\"thumbImg(this)\"")."')",
"mobile_parseimg('\\1', '\\2', '\\3', ".intval($lazyload).", ".intval($pid).")"
) : ($allowbbcode ? array(
(!defined('IN_MOBILE') ? "bbcodeurl('\\1', '<a href=\"{url}\" target=\"_blank\">{url}</a>')" : "bbcodeurl('\\1', '')"),
(!defined('IN_MOBILE') ? "bbcodeurl('\\3', '<a href=\"{url}\" target=\"_blank\">{url}</a>')" : "bbcodeurl('\\3', '')"),
) : array("bbcodeurl('\\1', '{url}')", "bbcodeurl('\\3', '{url}')")), $message);
}
}
for($i = 0; $i <= $_G['forum_discuzcode']['pcodecount']; $i++) {
$message = str_replace("[\tDISCUZ_CODE_$i\t]", $_G['forum_discuzcode']['codehtml'][$i], $message);
}
unset($msglower);
$message = preg_replace("/(\[groupid=\d+\].*\[\/groupid\])/i", '', $message);
$message = preg_replace("/(\r\n|\n|\r){3,}/i", "\\1\\1\\1", $message);
return $message;
}
function mobile_parseurl($url, $text, $scheme) {
global $_G;
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
$url = $matches[0];
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
}
$url = substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url;
return '<a href="'.$url.'">'.$text.'</a>';
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == 'www.') {
$url = 'http://'.$url;
}
$url = !$scheme ? $_G['siteurl'].$url : $url;
return '<a href="'.$url.'">'.$text.'</a>';
}
}
function mobile_parsecode($code) {
global $_G;
$_G['forum_discuzcode']['pcodecount']++;
$code = dhtmlspecialchars(str_replace('\\"', '"', $code));
$code = str_replace("\n", "<li>", $code);
$_G['forum_discuzcode']['codehtml'][$_G['forum_discuzcode']['pcodecount']] = mobile_codedisp($code);
$_G['forum_discuzcode']['codecount']++;
return "[\tDISCUZ_CODE_".$_G['forum_discuzcode']['pcodecount']."\t]";
}
function mobile_parseimg($width, $height, $url) {
global $_G;
$url = htmlspecialchars(str_replace(array('<', '>'), '', str_replace('\\"', '\"', $url)));
if(strtolower(substr($url, 0, 7)) == 'static/') {
$url = $_G['siteurl'].$url;
}
if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://'))) {
$url = 'http://'.$url;
}
$extra = ($width > 0 ? 'width="'.$width.'" ' : '').($height > 0 ? 'height="'.$height.'" ' : '');
return mobile_image($url, $extra);
}
function mobile_parsesmiles(&$message) {
global $_G;
static $enablesmiles;
if($enablesmiles === null) {
$url = !in_array(strtolower(substr(STATICURL, 0, 6)), array('http:/', 'https:', 'ftp://')) ? $_G['siteurl'] : '';
$enablesmiles = false;
if(!empty($_G['cache']['smilies']) && is_array($_G['cache']['smilies'])) {
foreach($_G['cache']['smilies']['replacearray'] AS $key => $smiley) {
$enablesmiles[$key] = '<img src="'.$url.STATICURL.'image/smiley/'.$_G['cache']['smileytypes'][$_G['cache']['smilies']['typearray'][$key]]['directory'].'/'.$smiley.'" />';
}
}
}
$enablesmiles && $message = preg_replace($_G['cache']['smilies']['searcharray'], $enablesmiles, $message, $_G['setting']['maxsmilies']);
return $message;
}
function mobile_parsetable($width, $bgcolor, $message) {
if(strpos($message, '[/tr]') === FALSE && strpos($message, '[/td]') === FALSE) {
$rows = explode("\n", $message);
$s = '<ul>';
foreach($rows as $row) {
$s .= '<li>'.str_replace(array('\|', '|', '\n'), array('|', '</li><li>', "\n"), $row).'</li>';
}
$s .= '</ul>';
return $s;
} else {
if(!preg_match("/^\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td([=\d,%]+)?\]/", $message) && !preg_match("/^<tr[^>]*?>\s*<td[^>]*?>/", $message)) {
return str_replace('\\"', '"', preg_replace("/\[tr(?:=([\(\)\s%,#\w]+))?\]|\[td([=\d,%]+)?\]|\[\/td\]|\[\/tr\]/", '', $message));
}
return '<table class="dzcode_table" cellspacing="0" '.
($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>').
str_replace('\\"', '"', preg_replace(array(
"/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,4}%?))?\]/ie",
"/\[\/td\]\s*\[td(?:=(\d{1,4}%?))?\]/ie",
"/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie",
"/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie",
"/\[\/td\]\s*\[\/tr\]\s*/i"
), array(
"mobile_parsetrtd('\\1', '0', '0', '\\2')",
"mobile_parsetrtd('td', '0', '0', '\\1')",
"mobile_parsetrtd('\\1', '\\2', '\\3', '\\4')",
"mobile_parsetrtd('td', '\\1', '\\2', '\\3')",
'</td></tr>'
), $message)
).'</table>';
}
}
function mobile_parsetrtd($bgcolor, $colspan, $rowspan, $width) {
return ($bgcolor == 'td' ? '</td></tr>' : '<tr'.($bgcolor ? ' style="background-color:'.$bgcolor.'"' : '').'>').'<td class="dzcode_td">';
}
function mobile_parseed2k($url) {
global $_G;
list(,$type, $name, $size,) = explode('|', $url);
$name = addslashes($name);
if($type == 'file') {
return '<a ed2k="'.urlencode($url).'">'.$name.' ('.sizecount($size).')</a>';
} else {
return '<a ed2k="'.urlencode($url).'">'.$url.'</a>';
}
}
?>