comparison forum/Sources/QueryString.php @ 76:e3e11437ecea website

Add forum code
author Chris Cannam
date Sun, 07 Jul 2013 11:25:48 +0200
parents
children
comparison
equal deleted inserted replaced
75:72f59aa7e503 76:e3e11437ecea
1 <?php
2
3 /**
4 * Simple Machines Forum (SMF)
5 *
6 * @package SMF
7 * @author Simple Machines http://www.simplemachines.org
8 * @copyright 2011 Simple Machines
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
10 *
11 * @version 2.0.3
12 */
13
14 if (!defined('SMF'))
15 die('Hacking attempt...');
16
17 /* This file does a lot of important stuff. Mainly, this means it handles
18 the query string, request variables, and session management. It contains
19 the following functions:
20
21 void cleanRequest()
22 - cleans the request variables (ENV, GET, POST, COOKIE, SERVER) and
23 makes sure the query string was parsed correctly.
24 - handles the URLs passed by the queryless URLs option.
25 - makes sure, regardless of php.ini, everything has slashes.
26 - sets up $board, $topic, and $scripturl and $_REQUEST['start'].
27 - determines, or rather tries to determine, the client's IP.
28
29 array escapestring__recursive(array var)
30 - returns the var, as an array or string, with escapes as required.
31 - importantly escapes all keys and values!
32 - calls itself recursively if necessary.
33
34 array htmlspecialchars__recursive(array var)
35 - adds entities (&quot;, &lt;, &gt;) to the array or string var.
36 - importantly, does not effect keys, only values.
37 - calls itself recursively if necessary.
38
39 array urldecode__recursive(array var)
40 - takes off url encoding (%20, etc.) from the array or string var.
41 - importantly, does it to keys too!
42 - calls itself recursively if there are any sub arrays.
43
44 array unescapestring__recursive(array var)
45 - unescapes, recursively, from the array or string var.
46 - effects both keys and values of arrays.
47 - calls itself recursively to handle arrays of arrays.
48
49 array stripslashes__recursive(array var)
50 - removes slashes, recursively, from the array or string var.
51 - effects both keys and values of arrays.
52 - calls itself recursively to handle arrays of arrays.
53
54 array htmltrim__recursive(array var)
55 - trims a string or an the var array using html characters as well.
56 - does not effect keys, only values.
57 - may call itself recursively if needed.
58
59 string cleanXml(string var)
60 - removes invalid XML characters to assure the input string being
61 parsed properly.
62
63 string ob_sessrewrite(string buffer)
64 - rewrites the URLs outputted to have the session ID, if the user
65 is not accepting cookies and is using a standard web browser.
66 - handles rewriting URLs for the queryless URLs option.
67 - can be turned off entirely by setting $scripturl to an empty
68 string, ''. (it wouldn't work well like that anyway.)
69 - because of bugs in certain builds of PHP, does not function in
70 versions lower than 4.3.0 - please upgrade if this hurts you.
71 */
72
73 // Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
74 function cleanRequest()
75 {
76 global $board, $topic, $boardurl, $scripturl, $modSettings, $smcFunc;
77
78 // Makes it easier to refer to things this way.
79 $scripturl = $boardurl . '/index.php';
80
81 // What function to use to reverse magic quotes - if sybase is on we assume that the database sensibly has the right unescape function!
82 $removeMagicQuoteFunction = @ini_get('magic_quotes_sybase') || strtolower(@ini_get('magic_quotes_sybase')) == 'on' ? 'unescapestring__recursive' : 'stripslashes__recursive';
83
84 // Save some memory.. (since we don't use these anyway.)
85 unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']);
86 unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
87
88 // These keys shouldn't be set...ever.
89 if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
90 die('Invalid request variable.');
91
92 // Same goes for numeric keys.
93 foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
94 if (is_numeric($key))
95 die('Numeric request keys are invalid.');
96
97 // Numeric keys in cookies are less of a problem. Just unset those.
98 foreach ($_COOKIE as $key => $value)
99 if (is_numeric($key))
100 unset($_COOKIE[$key]);
101
102 // Get the correct query string. It may be in an environment variable...
103 if (!isset($_SERVER['QUERY_STRING']))
104 $_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
105
106 // It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
107 if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
108 {
109 header('HTTP/1.1 400 Bad Request');
110 die;
111 }
112
113 // Are we going to need to parse the ; out?
114 if ((strpos(@ini_get('arg_separator.input'), ';') === false || @version_compare(PHP_VERSION, '4.2.0') == -1) && !empty($_SERVER['QUERY_STRING']))
115 {
116 // Get rid of the old one! You don't know where it's been!
117 $_GET = array();
118
119 // Was this redirected? If so, get the REDIRECT_QUERY_STRING.
120 // Do not urldecode() the querystring, unless you so much wish to break OpenID implementation. :)
121 $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'], 0, 5) === 'url=/' ? $_SERVER['REDIRECT_QUERY_STRING'] : $_SERVER['QUERY_STRING'];
122
123 // Replace ';' with '&' and '&something&' with '&something=&'. (this is done for compatibility...)
124 // !!! smflib
125 parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
126
127 // Magic quotes still applies with parse_str - so clean it up.
128 if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
129 $_GET = $removeMagicQuoteFunction($_GET);
130 }
131 elseif (strpos(@ini_get('arg_separator.input'), ';') !== false)
132 {
133 if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134 $_GET = $removeMagicQuoteFunction($_GET);
135
136 // Search engines will send action=profile%3Bu=1, which confuses PHP.
137 foreach ($_GET as $k => $v)
138 {
139 if (is_string($v) && strpos($k, ';') !== false)
140 {
141 $temp = explode(';', $v);
142 $_GET[$k] = $temp[0];
143
144 for ($i = 1, $n = count($temp); $i < $n; $i++)
145 {
146 @list ($key, $val) = @explode('=', $temp[$i], 2);
147 if (!isset($_GET[$key]))
148 $_GET[$key] = $val;
149 }
150 }
151
152 // This helps a lot with integration!
153 if (strpos($k, '?') === 0)
154 {
155 $_GET[substr($k, 1)] = $v;
156 unset($_GET[$k]);
157 }
158 }
159 }
160
161 // There's no query string, but there is a URL... try to get the data from there.
162 if (!empty($_SERVER['REQUEST_URI']))
163 {
164 // Remove the .html, assuming there is one.
165 if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
166 $request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
167 else
168 $request = $_SERVER['REQUEST_URI'];
169
170 // !!! smflib.
171 // Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
172 if (strpos($request, basename($scripturl) . '/') !== false)
173 {
174 parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
175 if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
176 $temp = $removeMagicQuoteFunction($temp);
177 $_GET += $temp;
178 }
179 }
180
181 // If magic quotes is on we have some work...
182 if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0)
183 {
184 $_ENV = $removeMagicQuoteFunction($_ENV);
185 $_POST = $removeMagicQuoteFunction($_POST);
186 $_COOKIE = $removeMagicQuoteFunction($_COOKIE);
187 foreach ($_FILES as $k => $dummy)
188 if (isset($_FILES[$k]['name']))
189 $_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
190 }
191
192 // Add entities to GET. This is kinda like the slashes on everything else.
193 $_GET = htmlspecialchars__recursive($_GET);
194
195 // Let's not depend on the ini settings... why even have COOKIE in there, anyway?
196 $_REQUEST = $_POST + $_GET;
197
198 // Make sure $board and $topic are numbers.
199 if (isset($_REQUEST['board']))
200 {
201 // Make sure its a string and not something else like an array
202 $_REQUEST['board'] = (string) $_REQUEST['board'];
203
204 // If there's a slash in it, we've got a start value! (old, compatible links.)
205 if (strpos($_REQUEST['board'], '/') !== false)
206 list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
207 // Same idea, but dots. This is the currently used format - ?board=1.0...
208 elseif (strpos($_REQUEST['board'], '.') !== false)
209 list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
210 // Now make absolutely sure it's a number.
211 $board = (int) $_REQUEST['board'];
212 $_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
213
214 // This is for "Who's Online" because it might come via POST - and it should be an int here.
215 $_GET['board'] = $board;
216 }
217 // Well, $board is going to be a number no matter what.
218 else
219 $board = 0;
220
221 // If there's a threadid, it's probably an old YaBB SE link. Flow with it.
222 if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
223 $_REQUEST['topic'] = $_REQUEST['threadid'];
224
225 // We've got topic!
226 if (isset($_REQUEST['topic']))
227 {
228 // Make sure its a string and not something else like an array
229 $_REQUEST['topic'] = (string) $_REQUEST['topic'];
230
231 // Slash means old, beta style, formatting. That's okay though, the link should still work.
232 if (strpos($_REQUEST['topic'], '/') !== false)
233 list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
234 // Dots are useful and fun ;). This is ?topic=1.15.
235 elseif (strpos($_REQUEST['topic'], '.') !== false)
236 list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
237
238 $topic = (int) $_REQUEST['topic'];
239
240 // Now make sure the online log gets the right number.
241 $_GET['topic'] = $topic;
242 }
243 else
244 $topic = 0;
245
246 // There should be a $_REQUEST['start'], some at least. If you need to default to other than 0, use $_GET['start'].
247 if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
248 $_REQUEST['start'] = 0;
249
250 // The action needs to be a string and not an array or anything else
251 if (isset($_REQUEST['action']))
252 $_REQUEST['action'] = (string) $_REQUEST['action'];
253 if (isset($_GET['action']))
254 $_GET['action'] = (string) $_GET['action'];
255
256 // Make sure we have a valid REMOTE_ADDR.
257 if (!isset($_SERVER['REMOTE_ADDR']))
258 {
259 $_SERVER['REMOTE_ADDR'] = '';
260 // A new magic variable to indicate we think this is command line.
261 $_SERVER['is_cli'] = true;
262 }
263 elseif (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER['REMOTE_ADDR']) === 0)
264 $_SERVER['REMOTE_ADDR'] = 'unknown';
265
266 // Try to calculate their most likely IP for those people behind proxies (And the like).
267 $_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
268
269 // Find the user's IP address. (but don't let it give you 'unknown'!)
270 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_CLIENT_IP']) && (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['HTTP_CLIENT_IP']) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['REMOTE_ADDR']) != 0))
271 {
272 // We have both forwarded for AND client IP... check the first forwarded for as the block - only switch if it's better that way.
273 if (strtok($_SERVER['HTTP_X_FORWARDED_FOR'], '.') != strtok($_SERVER['HTTP_CLIENT_IP'], '.') && '.' . strtok($_SERVER['HTTP_X_FORWARDED_FOR'], '.') == strrchr($_SERVER['HTTP_CLIENT_IP'], '.') && (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['HTTP_X_FORWARDED_FOR']) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['REMOTE_ADDR']) != 0))
274 $_SERVER['BAN_CHECK_IP'] = implode('.', array_reverse(explode('.', $_SERVER['HTTP_CLIENT_IP'])));
275 else
276 $_SERVER['BAN_CHECK_IP'] = $_SERVER['HTTP_CLIENT_IP'];
277 }
278 if (!empty($_SERVER['HTTP_CLIENT_IP']) && (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['HTTP_CLIENT_IP']) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['REMOTE_ADDR']) != 0))
279 {
280 // Since they are in different blocks, it's probably reversed.
281 if (strtok($_SERVER['REMOTE_ADDR'], '.') != strtok($_SERVER['HTTP_CLIENT_IP'], '.'))
282 $_SERVER['BAN_CHECK_IP'] = implode('.', array_reverse(explode('.', $_SERVER['HTTP_CLIENT_IP'])));
283 else
284 $_SERVER['BAN_CHECK_IP'] = $_SERVER['HTTP_CLIENT_IP'];
285 }
286 elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
287 {
288 // If there are commas, get the last one.. probably.
289 if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false)
290 {
291 $ips = array_reverse(explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']));
292
293 // Go through each IP...
294 foreach ($ips as $i => $ip)
295 {
296 // Make sure it's in a valid range...
297 if (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $ip) != 0 && preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['REMOTE_ADDR']) == 0)
298 continue;
299
300 // Otherwise, we've got an IP!
301 $_SERVER['BAN_CHECK_IP'] = trim($ip);
302 break;
303 }
304 }
305 // Otherwise just use the only one.
306 elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['HTTP_X_FORWARDED_FOR']) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown)~', $_SERVER['REMOTE_ADDR']) != 0)
307 $_SERVER['BAN_CHECK_IP'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
308 }
309
310 // Make sure we know the URL of the current request.
311 if (empty($_SERVER['REQUEST_URI']))
312 $_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
313 elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
314 $_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
315 else
316 $_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
317
318 // And make sure HTTP_USER_AGENT is set.
319 $_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : '';
320
321 // Some final checking.
322 if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER['BAN_CHECK_IP']) === 0)
323 $_SERVER['BAN_CHECK_IP'] = '';
324 if ($_SERVER['REMOTE_ADDR'] == 'unknown')
325 $_SERVER['REMOTE_ADDR'] = '';
326 }
327
328 // Adds slashes to the array/variable. Uses two underscores to guard against overloading.
329 function escapestring__recursive($var)
330 {
331 global $smcFunc;
332
333 if (!is_array($var))
334 return $smcFunc['db_escape_string']($var);
335
336 // Reindex the array with slashes.
337 $new_var = array();
338
339 // Add slashes to every element, even the indexes!
340 foreach ($var as $k => $v)
341 $new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
342
343 return $new_var;
344 }
345
346 // Adds html entities to the array/variable. Uses two underscores to guard against overloading.
347 function htmlspecialchars__recursive($var, $level = 0)
348 {
349 global $smcFunc;
350
351 if (!is_array($var))
352 return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
353
354 // Add the htmlspecialchars to every element.
355 foreach ($var as $k => $v)
356 $var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
357
358 return $var;
359 }
360
361 // Removes url stuff from the array/variable. Uses two underscores to guard against overloading.
362 function urldecode__recursive($var, $level = 0)
363 {
364 if (!is_array($var))
365 return urldecode($var);
366
367 // Reindex the array...
368 $new_var = array();
369
370 // Add the htmlspecialchars to every element.
371 foreach ($var as $k => $v)
372 $new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
373
374 return $new_var;
375 }
376 // Unescapes any array or variable. Two underscores for the normal reason.
377 function unescapestring__recursive($var)
378 {
379 global $smcFunc;
380
381 if (!is_array($var))
382 return $smcFunc['db_unescape_string']($var);
383
384 // Reindex the array without slashes, this time.
385 $new_var = array();
386
387 // Strip the slashes from every element.
388 foreach ($var as $k => $v)
389 $new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
390
391 return $new_var;
392 }
393
394 // Remove slashes recursively...
395 function stripslashes__recursive($var, $level = 0)
396 {
397 if (!is_array($var))
398 return stripslashes($var);
399
400 // Reindex the array without slashes, this time.
401 $new_var = array();
402
403 // Strip the slashes from every element.
404 foreach ($var as $k => $v)
405 $new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
406
407 return $new_var;
408 }
409
410 // Trim a string including the HTML space, character 160.
411 function htmltrim__recursive($var, $level = 0)
412 {
413 global $smcFunc;
414
415 // Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
416 if (!is_array($var))
417 return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
418
419 // Go through all the elements and remove the whitespace.
420 foreach ($var as $k => $v)
421 $var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
422
423 return $var;
424 }
425
426 // Clean up the XML to make sure it doesn't contain invalid characters.
427 function cleanXml($string)
428 {
429 global $context;
430
431 // http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char
432 return preg_replace('~[\x00-\x08\x0B\x0C\x0E-\x19' . ($context['utf8'] ? (@version_compare(PHP_VERSION, '4.3.3') != -1 ? '\x{FFFE}\x{FFFF}' : "\xED\xA0\x80-\xED\xBF\xBF\xEF\xBF\xBE\xEF\xBF\xBF") : '') . ']~' . ($context['utf8'] ? 'u' : ''), '', $string);
433 }
434
435 function JavaScriptEscape($string)
436 {
437 global $scripturl;
438
439 return '\'' . strtr($string, array(
440 "\r" => '',
441 "\n" => '\\n',
442 "\t" => '\\t',
443 '\\' => '\\\\',
444 '\'' => '\\\'',
445 '</' => '<\' + \'/',
446 'script' => 'scri\'+\'pt',
447 '<a href' => '<a hr\'+\'ef',
448 $scripturl => $scripturl . '\'+\'',
449 )) . '\'';
450 }
451
452 // Rewrite URLs to include the session ID.
453 function ob_sessrewrite($buffer)
454 {
455 global $scripturl, $modSettings, $user_info, $context;
456
457 // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
458 if ($scripturl == '' || !defined('SID'))
459 return $buffer;
460
461 // Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit(). This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
462 // !!! smflib
463 if (empty($_COOKIE) && SID != '' && empty($context['browser']['possibly_robot']) && @version_compare(PHP_VERSION, '4.3.0') != -1)
464 $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
465 // Debugging templates, are we?
466 elseif (isset($_GET['debug']))
467 $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
468
469 // This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
470 if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || @ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd']))
471 {
472 // Let's do something special for session ids!
473 if (defined('SID') && SID != '')
474 $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html?' . SID . '\$2\"'", $buffer);
475 else
476 $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", $buffer);
477 }
478
479 // Return the changed buffer.
480 return $buffer;
481 }
482
483 ?>