|
indvdum@0
|
1 |
<?php
|
|
indvdum@0
|
2 |
/**
|
|
indvdum@0
|
3 |
*
|
|
indvdum@0
|
4 |
* @package phpBB3
|
|
indvdum@0
|
5 |
* @version $Id$
|
|
indvdum@0
|
6 |
* @copyright (c) 2005 phpBB Group
|
|
indvdum@0
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
indvdum@0
|
8 |
*
|
|
indvdum@0
|
9 |
*/
|
|
indvdum@0
|
10 |
|
|
indvdum@0
|
11 |
/**
|
|
indvdum@0
|
12 |
* @ignore
|
|
indvdum@0
|
13 |
*/
|
|
indvdum@0
|
14 |
if (!defined('IN_PHPBB'))
|
|
indvdum@0
|
15 |
{
|
|
indvdum@0
|
16 |
exit;
|
|
indvdum@0
|
17 |
}
|
|
indvdum@0
|
18 |
|
|
indvdum@0
|
19 |
/**
|
|
indvdum@0
|
20 |
* BBCode class
|
|
indvdum@0
|
21 |
* @package phpBB3
|
|
indvdum@0
|
22 |
*/
|
|
indvdum@0
|
23 |
class bbcode
|
|
indvdum@0
|
24 |
{
|
|
indvdum@0
|
25 |
var $bbcode_uid = '';
|
|
indvdum@0
|
26 |
var $bbcode_bitfield = '';
|
|
indvdum@0
|
27 |
var $bbcode_cache = array();
|
|
indvdum@0
|
28 |
var $bbcode_template = array();
|
|
indvdum@0
|
29 |
|
|
indvdum@0
|
30 |
var $bbcodes = array();
|
|
indvdum@0
|
31 |
|
|
indvdum@0
|
32 |
var $template_bitfield;
|
|
indvdum@0
|
33 |
var $template_filename = '';
|
|
indvdum@0
|
34 |
|
|
indvdum@0
|
35 |
/**
|
|
indvdum@0
|
36 |
* Constructor
|
|
indvdum@0
|
37 |
* Init bbcode cache entries if bitfield is specified
|
|
indvdum@0
|
38 |
*/
|
|
indvdum@0
|
39 |
function bbcode($bitfield = '')
|
|
indvdum@0
|
40 |
{
|
|
indvdum@0
|
41 |
if ($bitfield)
|
|
indvdum@0
|
42 |
{
|
|
indvdum@0
|
43 |
$this->bbcode_bitfield = $bitfield;
|
|
indvdum@0
|
44 |
$this->bbcode_cache_init();
|
|
indvdum@0
|
45 |
}
|
|
indvdum@0
|
46 |
}
|
|
indvdum@0
|
47 |
|
|
indvdum@0
|
48 |
/**
|
|
indvdum@0
|
49 |
* Second pass bbcodes
|
|
indvdum@0
|
50 |
*/
|
|
indvdum@0
|
51 |
function bbcode_second_pass(&$message, $bbcode_uid = '', $bbcode_bitfield = false)
|
|
indvdum@0
|
52 |
{
|
|
indvdum@0
|
53 |
if ($bbcode_uid)
|
|
indvdum@0
|
54 |
{
|
|
indvdum@0
|
55 |
$this->bbcode_uid = $bbcode_uid;
|
|
indvdum@0
|
56 |
}
|
|
indvdum@0
|
57 |
|
|
indvdum@0
|
58 |
if ($bbcode_bitfield !== false)
|
|
indvdum@0
|
59 |
{
|
|
indvdum@0
|
60 |
$this->bbcode_bitfield = $bbcode_bitfield;
|
|
indvdum@0
|
61 |
|
|
indvdum@0
|
62 |
// Init those added with a new bbcode_bitfield (already stored codes will not get parsed again)
|
|
indvdum@0
|
63 |
$this->bbcode_cache_init();
|
|
indvdum@0
|
64 |
}
|
|
indvdum@0
|
65 |
|
|
indvdum@0
|
66 |
if (!$this->bbcode_bitfield)
|
|
indvdum@0
|
67 |
{
|
|
indvdum@0
|
68 |
// Remove the uid from tags that have not been transformed into HTML
|
|
indvdum@0
|
69 |
if ($this->bbcode_uid)
|
|
indvdum@0
|
70 |
{
|
|
indvdum@0
|
71 |
$message = str_replace(':' . $this->bbcode_uid, '', $message);
|
|
indvdum@0
|
72 |
}
|
|
indvdum@0
|
73 |
|
|
indvdum@0
|
74 |
return;
|
|
indvdum@0
|
75 |
}
|
|
indvdum@0
|
76 |
|
|
indvdum@0
|
77 |
$str = array('search' => array(), 'replace' => array());
|
|
indvdum@0
|
78 |
$preg = array('search' => array(), 'replace' => array());
|
|
indvdum@0
|
79 |
|
|
indvdum@0
|
80 |
$bitfield = new bitfield($this->bbcode_bitfield);
|
|
indvdum@0
|
81 |
$bbcodes_set = $bitfield->get_all_set();
|
|
indvdum@0
|
82 |
|
|
indvdum@0
|
83 |
$undid_bbcode_specialchars = false;
|
|
indvdum@0
|
84 |
foreach ($bbcodes_set as $bbcode_id)
|
|
indvdum@0
|
85 |
{
|
|
indvdum@0
|
86 |
if (!empty($this->bbcode_cache[$bbcode_id]))
|
|
indvdum@0
|
87 |
{
|
|
indvdum@0
|
88 |
foreach ($this->bbcode_cache[$bbcode_id] as $type => $array)
|
|
indvdum@0
|
89 |
{
|
|
indvdum@0
|
90 |
foreach ($array as $search => $replace)
|
|
indvdum@0
|
91 |
{
|
|
indvdum@0
|
92 |
${$type}['search'][] = str_replace('$uid', $this->bbcode_uid, $search);
|
|
indvdum@0
|
93 |
${$type}['replace'][] = $replace;
|
|
indvdum@0
|
94 |
}
|
|
indvdum@0
|
95 |
|
|
indvdum@0
|
96 |
if (sizeof($str['search']))
|
|
indvdum@0
|
97 |
{
|
|
indvdum@0
|
98 |
$message = str_replace($str['search'], $str['replace'], $message);
|
|
indvdum@0
|
99 |
$str = array('search' => array(), 'replace' => array());
|
|
indvdum@0
|
100 |
}
|
|
indvdum@0
|
101 |
|
|
indvdum@0
|
102 |
if (sizeof($preg['search']))
|
|
indvdum@0
|
103 |
{
|
|
indvdum@0
|
104 |
// we need to turn the entities back into their original form to allow the
|
|
indvdum@0
|
105 |
// search patterns to work properly
|
|
indvdum@0
|
106 |
if (!$undid_bbcode_specialchars)
|
|
indvdum@0
|
107 |
{
|
|
indvdum@0
|
108 |
$message = str_replace(array(':', '.'), array(':', '.'), $message);
|
|
indvdum@0
|
109 |
$undid_bbcode_specialchars = true;
|
|
indvdum@0
|
110 |
}
|
|
indvdum@0
|
111 |
|
|
indvdum@0
|
112 |
$message = preg_replace($preg['search'], $preg['replace'], $message);
|
|
indvdum@0
|
113 |
$preg = array('search' => array(), 'replace' => array());
|
|
indvdum@0
|
114 |
}
|
|
indvdum@0
|
115 |
}
|
|
indvdum@0
|
116 |
}
|
|
indvdum@0
|
117 |
}
|
|
indvdum@0
|
118 |
|
|
indvdum@0
|
119 |
// Remove the uid from tags that have not been transformed into HTML
|
|
indvdum@0
|
120 |
$message = str_replace(':' . $this->bbcode_uid, '', $message);
|
|
indvdum@0
|
121 |
}
|
|
indvdum@0
|
122 |
|
|
indvdum@0
|
123 |
/**
|
|
indvdum@0
|
124 |
* Init bbcode cache
|
|
indvdum@0
|
125 |
*
|
|
indvdum@0
|
126 |
* requires: $this->bbcode_bitfield
|
|
indvdum@0
|
127 |
* sets: $this->bbcode_cache with bbcode templates needed for bbcode_bitfield
|
|
indvdum@0
|
128 |
*/
|
|
indvdum@0
|
129 |
function bbcode_cache_init()
|
|
indvdum@0
|
130 |
{
|
|
indvdum@0
|
131 |
global $phpbb_root_path, $template, $user;
|
|
indvdum@0
|
132 |
|
|
indvdum@0
|
133 |
if (empty($this->template_filename))
|
|
indvdum@0
|
134 |
{
|
|
indvdum@0
|
135 |
$this->template_bitfield = new bitfield($user->theme['bbcode_bitfield']);
|
|
indvdum@0
|
136 |
$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html';
|
|
indvdum@0
|
137 |
|
|
indvdum@0
|
138 |
if (!@file_exists($this->template_filename))
|
|
indvdum@0
|
139 |
{
|
|
indvdum@0
|
140 |
if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
|
|
indvdum@0
|
141 |
{
|
|
indvdum@0
|
142 |
$this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/bbcode.html';
|
|
indvdum@0
|
143 |
if (!@file_exists($this->template_filename))
|
|
indvdum@0
|
144 |
{
|
|
indvdum@0
|
145 |
trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
|
|
indvdum@0
|
146 |
}
|
|
indvdum@0
|
147 |
}
|
|
indvdum@0
|
148 |
else
|
|
indvdum@0
|
149 |
{
|
|
indvdum@0
|
150 |
trigger_error('The file ' . $this->template_filename . ' is missing.', E_USER_ERROR);
|
|
indvdum@0
|
151 |
}
|
|
indvdum@0
|
152 |
}
|
|
indvdum@0
|
153 |
}
|
|
indvdum@0
|
154 |
|
|
indvdum@0
|
155 |
$bbcode_ids = $rowset = $sql = array();
|
|
indvdum@0
|
156 |
|
|
indvdum@0
|
157 |
$bitfield = new bitfield($this->bbcode_bitfield);
|
|
indvdum@0
|
158 |
$bbcodes_set = $bitfield->get_all_set();
|
|
indvdum@0
|
159 |
|
|
indvdum@0
|
160 |
foreach ($bbcodes_set as $bbcode_id)
|
|
indvdum@0
|
161 |
{
|
|
indvdum@0
|
162 |
if (isset($this->bbcode_cache[$bbcode_id]))
|
|
indvdum@0
|
163 |
{
|
|
indvdum@0
|
164 |
// do not try to re-cache it if it's already in
|
|
indvdum@0
|
165 |
continue;
|
|
indvdum@0
|
166 |
}
|
|
indvdum@0
|
167 |
$bbcode_ids[] = $bbcode_id;
|
|
indvdum@0
|
168 |
|
|
indvdum@0
|
169 |
if ($bbcode_id > NUM_CORE_BBCODES)
|
|
indvdum@0
|
170 |
{
|
|
indvdum@0
|
171 |
$sql[] = $bbcode_id;
|
|
indvdum@0
|
172 |
}
|
|
indvdum@0
|
173 |
}
|
|
indvdum@0
|
174 |
|
|
indvdum@0
|
175 |
if (sizeof($sql))
|
|
indvdum@0
|
176 |
{
|
|
indvdum@0
|
177 |
global $db;
|
|
indvdum@0
|
178 |
|
|
indvdum@0
|
179 |
$sql = 'SELECT *
|
|
indvdum@0
|
180 |
FROM ' . BBCODES_TABLE . '
|
|
indvdum@0
|
181 |
WHERE ' . $db->sql_in_set('bbcode_id', $sql);
|
|
indvdum@0
|
182 |
$result = $db->sql_query($sql, 3600);
|
|
indvdum@0
|
183 |
|
|
indvdum@0
|
184 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
185 |
{
|
|
indvdum@0
|
186 |
// To circumvent replacing newlines with <br /> for the generated html,
|
|
indvdum@0
|
187 |
// we use carriage returns here. They are later changed back to newlines
|
|
indvdum@0
|
188 |
$row['bbcode_tpl'] = str_replace("\n", "\r", $row['bbcode_tpl']);
|
|
indvdum@0
|
189 |
$row['second_pass_replace'] = str_replace("\n", "\r", $row['second_pass_replace']);
|
|
indvdum@0
|
190 |
|
|
indvdum@0
|
191 |
$rowset[$row['bbcode_id']] = $row;
|
|
indvdum@0
|
192 |
}
|
|
indvdum@0
|
193 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
194 |
}
|
|
indvdum@0
|
195 |
|
|
indvdum@0
|
196 |
foreach ($bbcode_ids as $bbcode_id)
|
|
indvdum@0
|
197 |
{
|
|
indvdum@0
|
198 |
switch ($bbcode_id)
|
|
indvdum@0
|
199 |
{
|
|
indvdum@0
|
200 |
case 0:
|
|
indvdum@0
|
201 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
202 |
'str' => array(
|
|
indvdum@0
|
203 |
'[/quote:$uid]' => $this->bbcode_tpl('quote_close', $bbcode_id)
|
|
indvdum@0
|
204 |
),
|
|
indvdum@0
|
205 |
'preg' => array(
|
|
indvdum@0
|
206 |
'#\[quote(?:="(.*?)")?:$uid\]((?!\[quote(?:=".*?")?:$uid\]).)?#ise' => "\$this->bbcode_second_pass_quote('\$1', '\$2')"
|
|
indvdum@0
|
207 |
)
|
|
indvdum@0
|
208 |
);
|
|
indvdum@0
|
209 |
break;
|
|
indvdum@0
|
210 |
|
|
indvdum@0
|
211 |
case 1:
|
|
indvdum@0
|
212 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
213 |
'str' => array(
|
|
indvdum@0
|
214 |
'[b:$uid]' => $this->bbcode_tpl('b_open', $bbcode_id),
|
|
indvdum@0
|
215 |
'[/b:$uid]' => $this->bbcode_tpl('b_close', $bbcode_id),
|
|
indvdum@0
|
216 |
)
|
|
indvdum@0
|
217 |
);
|
|
indvdum@0
|
218 |
break;
|
|
indvdum@0
|
219 |
|
|
indvdum@0
|
220 |
case 2:
|
|
indvdum@0
|
221 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
222 |
'str' => array(
|
|
indvdum@0
|
223 |
'[i:$uid]' => $this->bbcode_tpl('i_open', $bbcode_id),
|
|
indvdum@0
|
224 |
'[/i:$uid]' => $this->bbcode_tpl('i_close', $bbcode_id),
|
|
indvdum@0
|
225 |
)
|
|
indvdum@0
|
226 |
);
|
|
indvdum@0
|
227 |
break;
|
|
indvdum@0
|
228 |
|
|
indvdum@0
|
229 |
case 3:
|
|
indvdum@0
|
230 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
231 |
'preg' => array(
|
|
indvdum@0
|
232 |
'#\[url:$uid\]((.*?))\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
|
|
indvdum@0
|
233 |
'#\[url=([^\[]+?):$uid\](.*?)\[/url:$uid\]#s' => $this->bbcode_tpl('url', $bbcode_id),
|
|
indvdum@0
|
234 |
)
|
|
indvdum@0
|
235 |
);
|
|
indvdum@0
|
236 |
break;
|
|
indvdum@0
|
237 |
|
|
indvdum@0
|
238 |
case 4:
|
|
indvdum@0
|
239 |
if ($user->optionget('viewimg'))
|
|
indvdum@0
|
240 |
{
|
|
indvdum@0
|
241 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
242 |
'preg' => array(
|
|
indvdum@0
|
243 |
'#\[img:$uid\](.*?)\[/img:$uid\]#s' => $this->bbcode_tpl('img', $bbcode_id),
|
|
indvdum@0
|
244 |
)
|
|
indvdum@0
|
245 |
);
|
|
indvdum@0
|
246 |
}
|
|
indvdum@0
|
247 |
else
|
|
indvdum@0
|
248 |
{
|
|
indvdum@0
|
249 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
250 |
'preg' => array(
|
|
indvdum@0
|
251 |
'#\[img:$uid\](.*?)\[/img:$uid\]#s' => str_replace('$2', '[ img ]', $this->bbcode_tpl('url', $bbcode_id, true)),
|
|
indvdum@0
|
252 |
)
|
|
indvdum@0
|
253 |
);
|
|
indvdum@0
|
254 |
}
|
|
indvdum@0
|
255 |
break;
|
|
indvdum@0
|
256 |
|
|
indvdum@0
|
257 |
case 5:
|
|
indvdum@0
|
258 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
259 |
'preg' => array(
|
|
indvdum@0
|
260 |
'#\[size=([\-\+]?\d+):$uid\](.*?)\[/size:$uid\]#s' => $this->bbcode_tpl('size', $bbcode_id),
|
|
indvdum@0
|
261 |
)
|
|
indvdum@0
|
262 |
);
|
|
indvdum@0
|
263 |
break;
|
|
indvdum@0
|
264 |
|
|
indvdum@0
|
265 |
case 6:
|
|
indvdum@0
|
266 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
267 |
'preg' => array(
|
|
indvdum@0
|
268 |
'!\[color=(#[0-9a-f]{3}|#[0-9a-f]{6}|[a-z\-]+):$uid\](.*?)\[/color:$uid\]!is' => $this->bbcode_tpl('color', $bbcode_id),
|
|
indvdum@0
|
269 |
)
|
|
indvdum@0
|
270 |
);
|
|
indvdum@0
|
271 |
break;
|
|
indvdum@0
|
272 |
|
|
indvdum@0
|
273 |
case 7:
|
|
indvdum@0
|
274 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
275 |
'str' => array(
|
|
indvdum@0
|
276 |
'[u:$uid]' => $this->bbcode_tpl('u_open', $bbcode_id),
|
|
indvdum@0
|
277 |
'[/u:$uid]' => $this->bbcode_tpl('u_close', $bbcode_id),
|
|
indvdum@0
|
278 |
)
|
|
indvdum@0
|
279 |
);
|
|
indvdum@0
|
280 |
break;
|
|
indvdum@0
|
281 |
|
|
indvdum@0
|
282 |
case 8:
|
|
indvdum@0
|
283 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
284 |
'preg' => array(
|
|
indvdum@0
|
285 |
'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise' => "\$this->bbcode_second_pass_code('\$1', '\$2')",
|
|
indvdum@0
|
286 |
)
|
|
indvdum@0
|
287 |
);
|
|
indvdum@0
|
288 |
break;
|
|
indvdum@0
|
289 |
|
|
indvdum@0
|
290 |
case 9:
|
|
indvdum@0
|
291 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
292 |
'preg' => array(
|
|
indvdum@0
|
293 |
'#(\[\/?(list|\*):[mou]?:?$uid\])[\n]{1}#' => "\$1",
|
|
indvdum@0
|
294 |
'#(\[list=([^\[]+):$uid\])[\n]{1}#' => "\$1",
|
|
indvdum@0
|
295 |
'#\[list=([^\[]+):$uid\]#e' => "\$this->bbcode_list('\$1')",
|
|
indvdum@0
|
296 |
),
|
|
indvdum@0
|
297 |
'str' => array(
|
|
indvdum@0
|
298 |
'[list:$uid]' => $this->bbcode_tpl('ulist_open_default', $bbcode_id),
|
|
indvdum@0
|
299 |
'[/list:u:$uid]' => $this->bbcode_tpl('ulist_close', $bbcode_id),
|
|
indvdum@0
|
300 |
'[/list:o:$uid]' => $this->bbcode_tpl('olist_close', $bbcode_id),
|
|
indvdum@0
|
301 |
'[*:$uid]' => $this->bbcode_tpl('listitem', $bbcode_id),
|
|
indvdum@0
|
302 |
'[/*:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id),
|
|
indvdum@0
|
303 |
'[/*:m:$uid]' => $this->bbcode_tpl('listitem_close', $bbcode_id)
|
|
indvdum@0
|
304 |
),
|
|
indvdum@0
|
305 |
);
|
|
indvdum@0
|
306 |
break;
|
|
indvdum@0
|
307 |
|
|
indvdum@0
|
308 |
case 10:
|
|
indvdum@0
|
309 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
310 |
'preg' => array(
|
|
indvdum@0
|
311 |
'#\[email:$uid\]((.*?))\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id),
|
|
indvdum@0
|
312 |
'#\[email=([^\[]+):$uid\](.*?)\[/email:$uid\]#is' => $this->bbcode_tpl('email', $bbcode_id)
|
|
indvdum@0
|
313 |
)
|
|
indvdum@0
|
314 |
);
|
|
indvdum@0
|
315 |
break;
|
|
indvdum@0
|
316 |
|
|
indvdum@0
|
317 |
case 11:
|
|
indvdum@0
|
318 |
if ($user->optionget('viewflash'))
|
|
indvdum@0
|
319 |
{
|
|
indvdum@0
|
320 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
321 |
'preg' => array(
|
|
indvdum@0
|
322 |
'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => $this->bbcode_tpl('flash', $bbcode_id),
|
|
indvdum@0
|
323 |
)
|
|
indvdum@0
|
324 |
);
|
|
indvdum@0
|
325 |
}
|
|
indvdum@0
|
326 |
else
|
|
indvdum@0
|
327 |
{
|
|
indvdum@0
|
328 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
329 |
'preg' => array(
|
|
indvdum@0
|
330 |
'#\[flash=([0-9]+),([0-9]+):$uid\](.*?)\[/flash:$uid\]#' => str_replace('$1', '$3', str_replace('$2', '[ flash ]', $this->bbcode_tpl('url', $bbcode_id, true)))
|
|
indvdum@0
|
331 |
)
|
|
indvdum@0
|
332 |
);
|
|
indvdum@0
|
333 |
}
|
|
indvdum@0
|
334 |
break;
|
|
indvdum@0
|
335 |
|
|
indvdum@0
|
336 |
case 12:
|
|
indvdum@0
|
337 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
338 |
'str' => array(
|
|
indvdum@0
|
339 |
'[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)
|
|
indvdum@0
|
340 |
),
|
|
indvdum@0
|
341 |
'preg' => array(
|
|
indvdum@0
|
342 |
'#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)
|
|
indvdum@0
|
343 |
)
|
|
indvdum@0
|
344 |
);
|
|
indvdum@0
|
345 |
break;
|
|
indvdum@0
|
346 |
|
|
indvdum@0
|
347 |
default:
|
|
indvdum@0
|
348 |
if (isset($rowset[$bbcode_id]))
|
|
indvdum@0
|
349 |
{
|
|
indvdum@0
|
350 |
if ($this->template_bitfield->get($bbcode_id))
|
|
indvdum@0
|
351 |
{
|
|
indvdum@0
|
352 |
// The bbcode requires a custom template to be loaded
|
|
indvdum@0
|
353 |
if (!$bbcode_tpl = $this->bbcode_tpl($rowset[$bbcode_id]['bbcode_tag'], $bbcode_id))
|
|
indvdum@0
|
354 |
{
|
|
indvdum@0
|
355 |
// For some reason, the required template seems not to be available, use the default template
|
|
indvdum@0
|
356 |
$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
|
|
indvdum@0
|
357 |
}
|
|
indvdum@0
|
358 |
else
|
|
indvdum@0
|
359 |
{
|
|
indvdum@0
|
360 |
// In order to use templates with custom bbcodes we need
|
|
indvdum@0
|
361 |
// to replace all {VARS} to corresponding backreferences
|
|
indvdum@0
|
362 |
// Note that backreferences are numbered from bbcode_match
|
|
indvdum@0
|
363 |
if (preg_match_all('/\{(URL|LOCAL_URL|EMAIL|TEXT|SIMPLETEXT|INTTEXT|IDENTIFIER|COLOR|NUMBER)[0-9]*\}/', $rowset[$bbcode_id]['bbcode_match'], $m))
|
|
indvdum@0
|
364 |
{
|
|
indvdum@0
|
365 |
foreach ($m[0] as $i => $tok)
|
|
indvdum@0
|
366 |
{
|
|
indvdum@0
|
367 |
$bbcode_tpl = str_replace($tok, '$' . ($i + 1), $bbcode_tpl);
|
|
indvdum@0
|
368 |
}
|
|
indvdum@0
|
369 |
}
|
|
indvdum@0
|
370 |
}
|
|
indvdum@0
|
371 |
}
|
|
indvdum@0
|
372 |
else
|
|
indvdum@0
|
373 |
{
|
|
indvdum@0
|
374 |
// Default template
|
|
indvdum@0
|
375 |
$bbcode_tpl = (!empty($rowset[$bbcode_id]['second_pass_replace'])) ? $rowset[$bbcode_id]['second_pass_replace'] : $rowset[$bbcode_id]['bbcode_tpl'];
|
|
indvdum@0
|
376 |
}
|
|
indvdum@0
|
377 |
|
|
indvdum@0
|
378 |
// Replace {L_*} lang strings
|
|
indvdum@0
|
379 |
$bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);
|
|
indvdum@0
|
380 |
|
|
indvdum@0
|
381 |
if (!empty($rowset[$bbcode_id]['second_pass_replace']))
|
|
indvdum@0
|
382 |
{
|
|
indvdum@0
|
383 |
// The custom BBCode requires second-pass pattern replacements
|
|
indvdum@0
|
384 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
385 |
'preg' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
|
|
indvdum@0
|
386 |
);
|
|
indvdum@0
|
387 |
}
|
|
indvdum@0
|
388 |
else
|
|
indvdum@0
|
389 |
{
|
|
indvdum@0
|
390 |
$this->bbcode_cache[$bbcode_id] = array(
|
|
indvdum@0
|
391 |
'str' => array($rowset[$bbcode_id]['second_pass_match'] => $bbcode_tpl)
|
|
indvdum@0
|
392 |
);
|
|
indvdum@0
|
393 |
}
|
|
indvdum@0
|
394 |
}
|
|
indvdum@0
|
395 |
else
|
|
indvdum@0
|
396 |
{
|
|
indvdum@0
|
397 |
$this->bbcode_cache[$bbcode_id] = false;
|
|
indvdum@0
|
398 |
}
|
|
indvdum@0
|
399 |
break;
|
|
indvdum@0
|
400 |
}
|
|
indvdum@0
|
401 |
}
|
|
indvdum@0
|
402 |
}
|
|
indvdum@0
|
403 |
|
|
indvdum@0
|
404 |
/**
|
|
indvdum@0
|
405 |
* Return bbcode template
|
|
indvdum@0
|
406 |
*/
|
|
indvdum@0
|
407 |
function bbcode_tpl($tpl_name, $bbcode_id = -1, $skip_bitfield_check = false)
|
|
indvdum@0
|
408 |
{
|
|
indvdum@0
|
409 |
static $bbcode_hardtpl = array();
|
|
indvdum@0
|
410 |
if (empty($bbcode_hardtpl))
|
|
indvdum@0
|
411 |
{
|
|
indvdum@0
|
412 |
global $user;
|
|
indvdum@0
|
413 |
|
|
indvdum@0
|
414 |
$bbcode_hardtpl = array(
|
|
indvdum@0
|
415 |
'b_open' => '<span style="font-weight: bold">',
|
|
indvdum@0
|
416 |
'b_close' => '</span>',
|
|
indvdum@0
|
417 |
'i_open' => '<span style="font-style: italic">',
|
|
indvdum@0
|
418 |
'i_close' => '</span>',
|
|
indvdum@0
|
419 |
'u_open' => '<span style="text-decoration: underline">',
|
|
indvdum@0
|
420 |
'u_close' => '</span>',
|
|
indvdum@0
|
421 |
'img' => '<img src="$1" alt="' . $user->lang['IMAGE'] . '" />',
|
|
indvdum@0
|
422 |
'size' => '<span style="font-size: $1%; line-height: normal">$2</span>',
|
|
indvdum@0
|
423 |
'color' => '<span style="color: $1">$2</span>',
|
|
indvdum@0
|
424 |
'email' => '<a href="mailto:$1">$2</a>'
|
|
indvdum@0
|
425 |
);
|
|
indvdum@0
|
426 |
}
|
|
indvdum@0
|
427 |
|
|
indvdum@0
|
428 |
if ($bbcode_id != -1 && !$skip_bitfield_check && !$this->template_bitfield->get($bbcode_id))
|
|
indvdum@0
|
429 |
{
|
|
indvdum@0
|
430 |
return (isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false;
|
|
indvdum@0
|
431 |
}
|
|
indvdum@0
|
432 |
|
|
indvdum@0
|
433 |
if (empty($this->bbcode_template))
|
|
indvdum@0
|
434 |
{
|
|
indvdum@0
|
435 |
if (($tpl = file_get_contents($this->template_filename)) === false)
|
|
indvdum@0
|
436 |
{
|
|
indvdum@0
|
437 |
trigger_error('Could not load bbcode template', E_USER_ERROR);
|
|
indvdum@0
|
438 |
}
|
|
indvdum@0
|
439 |
|
|
indvdum@0
|
440 |
// replace \ with \\ and then ' with \'.
|
|
indvdum@0
|
441 |
$tpl = str_replace('\\', '\\\\', $tpl);
|
|
indvdum@0
|
442 |
$tpl = str_replace("'", "\'", $tpl);
|
|
indvdum@0
|
443 |
|
|
indvdum@0
|
444 |
// strip newlines and indent
|
|
indvdum@0
|
445 |
$tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
|
|
indvdum@0
|
446 |
|
|
indvdum@0
|
447 |
// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
|
|
indvdum@0
|
448 |
$this->bbcode_template = array();
|
|
indvdum@0
|
449 |
|
|
indvdum@0
|
450 |
$matches = preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match);
|
|
indvdum@0
|
451 |
|
|
indvdum@0
|
452 |
for ($i = 0; $i < $matches; $i++)
|
|
indvdum@0
|
453 |
{
|
|
indvdum@0
|
454 |
if (empty($match[1][$i]))
|
|
indvdum@0
|
455 |
{
|
|
indvdum@0
|
456 |
continue;
|
|
indvdum@0
|
457 |
}
|
|
indvdum@0
|
458 |
|
|
indvdum@0
|
459 |
$this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
|
|
indvdum@0
|
460 |
}
|
|
indvdum@0
|
461 |
}
|
|
indvdum@0
|
462 |
|
|
indvdum@0
|
463 |
return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);
|
|
indvdum@0
|
464 |
}
|
|
indvdum@0
|
465 |
|
|
indvdum@0
|
466 |
/**
|
|
indvdum@0
|
467 |
* Return bbcode template replacement
|
|
indvdum@0
|
468 |
*/
|
|
indvdum@0
|
469 |
function bbcode_tpl_replace($tpl_name, $tpl)
|
|
indvdum@0
|
470 |
{
|
|
indvdum@0
|
471 |
global $user;
|
|
indvdum@0
|
472 |
|
|
indvdum@0
|
473 |
static $replacements = array(
|
|
indvdum@0
|
474 |
'quote_username_open' => array('{USERNAME}' => '$1'),
|
|
indvdum@0
|
475 |
'color' => array('{COLOR}' => '$1', '{TEXT}' => '$2'),
|
|
indvdum@0
|
476 |
'size' => array('{SIZE}' => '$1', '{TEXT}' => '$2'),
|
|
indvdum@0
|
477 |
'img' => array('{URL}' => '$1'),
|
|
indvdum@0
|
478 |
'flash' => array('{WIDTH}' => '$1', '{HEIGHT}' => '$2', '{URL}' => '$3'),
|
|
indvdum@0
|
479 |
'url' => array('{URL}' => '$1', '{DESCRIPTION}' => '$2'),
|
|
indvdum@0
|
480 |
'email' => array('{EMAIL}' => '$1', '{DESCRIPTION}' => '$2')
|
|
indvdum@0
|
481 |
);
|
|
indvdum@0
|
482 |
|
|
indvdum@0
|
483 |
$tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);
|
|
indvdum@0
|
484 |
|
|
indvdum@0
|
485 |
if (!empty($replacements[$tpl_name]))
|
|
indvdum@0
|
486 |
{
|
|
indvdum@0
|
487 |
$tpl = strtr($tpl, $replacements[$tpl_name]);
|
|
indvdum@0
|
488 |
}
|
|
indvdum@0
|
489 |
|
|
indvdum@0
|
490 |
return trim($tpl);
|
|
indvdum@0
|
491 |
}
|
|
indvdum@0
|
492 |
|
|
indvdum@0
|
493 |
/**
|
|
indvdum@0
|
494 |
* Second parse list bbcode
|
|
indvdum@0
|
495 |
*/
|
|
indvdum@0
|
496 |
function bbcode_list($type)
|
|
indvdum@0
|
497 |
{
|
|
indvdum@0
|
498 |
if ($type == '')
|
|
indvdum@0
|
499 |
{
|
|
indvdum@0
|
500 |
$tpl = 'ulist_open_default';
|
|
indvdum@0
|
501 |
$type = 'default';
|
|
indvdum@0
|
502 |
}
|
|
indvdum@0
|
503 |
else if ($type == 'i')
|
|
indvdum@0
|
504 |
{
|
|
indvdum@0
|
505 |
$tpl = 'olist_open';
|
|
indvdum@0
|
506 |
$type = 'lower-roman';
|
|
indvdum@0
|
507 |
}
|
|
indvdum@0
|
508 |
else if ($type == 'I')
|
|
indvdum@0
|
509 |
{
|
|
indvdum@0
|
510 |
$tpl = 'olist_open';
|
|
indvdum@0
|
511 |
$type = 'upper-roman';
|
|
indvdum@0
|
512 |
}
|
|
indvdum@0
|
513 |
else if (preg_match('#^(disc|circle|square)$#i', $type))
|
|
indvdum@0
|
514 |
{
|
|
indvdum@0
|
515 |
$tpl = 'ulist_open';
|
|
indvdum@0
|
516 |
$type = strtolower($type);
|
|
indvdum@0
|
517 |
}
|
|
indvdum@0
|
518 |
else if (preg_match('#^[a-z]$#', $type))
|
|
indvdum@0
|
519 |
{
|
|
indvdum@0
|
520 |
$tpl = 'olist_open';
|
|
indvdum@0
|
521 |
$type = 'lower-alpha';
|
|
indvdum@0
|
522 |
}
|
|
indvdum@0
|
523 |
else if (preg_match('#[A-Z]#', $type))
|
|
indvdum@0
|
524 |
{
|
|
indvdum@0
|
525 |
$tpl = 'olist_open';
|
|
indvdum@0
|
526 |
$type = 'upper-alpha';
|
|
indvdum@0
|
527 |
}
|
|
indvdum@0
|
528 |
else if (is_numeric($type))
|
|
indvdum@0
|
529 |
{
|
|
indvdum@0
|
530 |
$tpl = 'olist_open';
|
|
indvdum@0
|
531 |
$type = 'decimal';
|
|
indvdum@0
|
532 |
}
|
|
indvdum@0
|
533 |
else
|
|
indvdum@0
|
534 |
{
|
|
indvdum@0
|
535 |
$tpl = 'olist_open';
|
|
indvdum@0
|
536 |
$type = 'decimal';
|
|
indvdum@0
|
537 |
}
|
|
indvdum@0
|
538 |
|
|
indvdum@0
|
539 |
return str_replace('{LIST_TYPE}', $type, $this->bbcode_tpl($tpl));
|
|
indvdum@0
|
540 |
}
|
|
indvdum@0
|
541 |
|
|
indvdum@0
|
542 |
/**
|
|
indvdum@0
|
543 |
* Second parse quote tag
|
|
indvdum@0
|
544 |
*/
|
|
indvdum@0
|
545 |
function bbcode_second_pass_quote($username, $quote)
|
|
indvdum@0
|
546 |
{
|
|
indvdum@0
|
547 |
// when using the /e modifier, preg_replace slashes double-quotes but does not
|
|
indvdum@0
|
548 |
// seem to slash anything else
|
|
indvdum@0
|
549 |
$quote = str_replace('\"', '"', $quote);
|
|
indvdum@0
|
550 |
$username = str_replace('\"', '"', $username);
|
|
indvdum@0
|
551 |
|
|
indvdum@0
|
552 |
// remove newline at the beginning
|
|
indvdum@0
|
553 |
if ($quote == "\n")
|
|
indvdum@0
|
554 |
{
|
|
indvdum@0
|
555 |
$quote = '';
|
|
indvdum@0
|
556 |
}
|
|
indvdum@0
|
557 |
|
|
indvdum@0
|
558 |
$quote = (($username) ? str_replace('$1', $username, $this->bbcode_tpl('quote_username_open')) : $this->bbcode_tpl('quote_open')) . $quote;
|
|
indvdum@0
|
559 |
|
|
indvdum@0
|
560 |
return $quote;
|
|
indvdum@0
|
561 |
}
|
|
indvdum@0
|
562 |
|
|
indvdum@0
|
563 |
/**
|
|
indvdum@0
|
564 |
* Second parse code tag
|
|
indvdum@0
|
565 |
*/
|
|
indvdum@0
|
566 |
function bbcode_second_pass_code($type, $code)
|
|
indvdum@0
|
567 |
{
|
|
indvdum@0
|
568 |
// when using the /e modifier, preg_replace slashes double-quotes but does not
|
|
indvdum@0
|
569 |
// seem to slash anything else
|
|
indvdum@0
|
570 |
$code = str_replace('\"', '"', $code);
|
|
indvdum@0
|
571 |
|
|
indvdum@0
|
572 |
switch ($type)
|
|
indvdum@0
|
573 |
{
|
|
indvdum@0
|
574 |
case 'php':
|
|
indvdum@0
|
575 |
// Not the english way, but valid because of hardcoded syntax highlighting
|
|
indvdum@0
|
576 |
if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
|
|
indvdum@0
|
577 |
{
|
|
indvdum@0
|
578 |
$code = substr($code, 41);
|
|
indvdum@0
|
579 |
}
|
|
indvdum@0
|
580 |
|
|
indvdum@0
|
581 |
// no break;
|
|
indvdum@0
|
582 |
|
|
indvdum@0
|
583 |
default:
|
|
indvdum@0
|
584 |
$code = str_replace("\t", ' ', $code);
|
|
indvdum@0
|
585 |
$code = str_replace(' ', ' ', $code);
|
|
indvdum@0
|
586 |
$code = str_replace(' ', ' ', $code);
|
|
indvdum@0
|
587 |
$code = str_replace("\n ", "\n ", $code);
|
|
indvdum@0
|
588 |
|
|
indvdum@0
|
589 |
// keep space at the beginning
|
|
indvdum@0
|
590 |
if (!empty($code) && $code[0] == ' ')
|
|
indvdum@0
|
591 |
{
|
|
indvdum@0
|
592 |
$code = ' ' . substr($code, 1);
|
|
indvdum@0
|
593 |
}
|
|
indvdum@0
|
594 |
|
|
indvdum@0
|
595 |
// remove newline at the beginning
|
|
indvdum@0
|
596 |
if (!empty($code) && $code[0] == "\n")
|
|
indvdum@0
|
597 |
{
|
|
indvdum@0
|
598 |
$code = substr($code, 1);
|
|
indvdum@0
|
599 |
}
|
|
indvdum@0
|
600 |
break;
|
|
indvdum@0
|
601 |
}
|
|
indvdum@0
|
602 |
|
|
indvdum@0
|
603 |
$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
|
|
indvdum@0
|
604 |
|
|
indvdum@0
|
605 |
return $code;
|
|
indvdum@0
|
606 |
}
|
|
indvdum@0
|
607 |
}
|
|
indvdum@0
|
608 |
|
|
indvdum@0
|
609 |
?> |