]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/config.php
set_magic_quotes_runtime fix for php6.
[SourceForge/phpwiki.git] / lib / config.php
1 <?php
2 rcs_id('$Id$');
3 /*
4  * NOTE: The settings here should probably not need to be changed.
5  * The user-configurable settings have been moved to IniConfig.php
6  * The run-time code has been moved to lib/IniConfig.php:fix_configs()
7  */
8
9 if (!defined("LC_ALL")) {
10     // Backward compatibility (for PHP < 4.0.5)
11     if (!check_php_version(4,0,5)) {
12         define("LC_ALL",   "LC_ALL");
13         define("LC_CTYPE", "LC_CTYPE");
14     } else {
15         define("LC_ALL",   0);
16         define("LC_CTYPE", 2);
17     }
18 }
19 // debug flags:
20 define ('_DEBUG_VERBOSE',   1); // verbose msgs and add validator links on footer
21 define ('_DEBUG_PAGELINKS', 2); // list the extraced pagelinks at the top of each pages
22 define ('_DEBUG_PARSER',    4); // verbose parsing steps
23 define ('_DEBUG_TRACE',     8); // test php memory usage, prints php debug backtraces
24 define ('_DEBUG_INFO',     16);
25 define ('_DEBUG_APD',      32); // APD tracing/profiling
26 define ('_DEBUG_LOGIN',    64); // verbose login debug-msg (settings and reason for failure)
27 define ('_DEBUG_SQL',     128); // force check db, force optimize, print some debugging logs
28 define ('_DEBUG_REMOTE',  256); // remote debug into subrequests (xmlrpc, ajax, wikiwyg, ...) 
29                                 // or test local SearchHighlight.
30                                 // internal links have persistent ?start_debug=1 
31
32 function isCGI() {
33     return (substr(php_sapi_name(),0,3) == 'cgi' and 
34             isset($GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']) and
35             @preg_match('/CGI/',$GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']));
36 }
37
38 /*
39 // copy some $_ENV vars to $_SERVER for CGI compatibility. php does it automatically since when?
40 if (isCGI()) {
41     foreach (explode(':','SERVER_SOFTWARE:SERVER_NAME:GATEWAY_INTERFACE:SERVER_PROTOCOL:SERVER_PORT:REQUEST_METHOD:HTTP_ACCEPT:PATH_INFO:PATH_TRANSLATED:SCRIPT_NAME:QUERY_STRING:REMOTE_HOST:REMOTE_ADDR:REMOTE_USER:AUTH_TYPE:CONTENT_TYPE:CONTENT_LENGTH') as $key) {
42         $GLOBALS['HTTP_SERVER_VARS'][$key] = &$GLOBALS['HTTP_ENV_VARS'][$key];
43     }
44 }
45 */
46
47 // essential internal stuff
48 if (!check_php_version(6))
49     set_magic_quotes_runtime(0);
50
51 /**
52  * Browser Detection Functions
53  *
54  * Current Issues:
55  *  NS/IE < 4.0 doesn't accept < ? xml version="1.0" ? >
56  *  NS/IE < 4.0 cannot display PNG
57  *  NS/IE < 4.0 cannot display all XHTML tags
58  *  NS < 5.0 needs textarea wrap=virtual
59  *  IE55 has problems with transparent PNG's
60  * @author: ReiniUrban
61  */
62 function browserAgent() {
63     static $HTTP_USER_AGENT = false;
64     if ($HTTP_USER_AGENT !== false) return $HTTP_USER_AGENT;
65     if (!$HTTP_USER_AGENT)
66         $HTTP_USER_AGENT = @$GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'];
67     if (!$HTTP_USER_AGENT) // CGI
68         $HTTP_USER_AGENT = @$GLOBALS['HTTP_ENV_VARS']['HTTP_USER_AGENT'];
69     if (!$HTTP_USER_AGENT) // local CGI testing
70         $HTTP_USER_AGENT = 'none';
71     return $HTTP_USER_AGENT;
72 }
73 function browserDetect($match) {
74     return (strpos(strtolower(browserAgent()), strtolower($match)) !== false);
75 }
76 // returns a similar number for Netscape/Mozilla (gecko=5.0)/IE/Opera features.
77 function browserVersion() {
78     $agent = browserAgent();
79     if (strstr($agent, "Mozilla/4.0 (compatible; MSIE"))
80         return (float) substr($agent, 30);
81     elseif (strstr($agent, "Mozilla/5.0 (compatible; Konqueror/"))
82         return (float) substr($agent, 36);
83     else
84         return (float) substr($agent, 8);
85 }
86 function isBrowserIE() {
87     return (browserDetect('Mozilla/') and 
88             browserDetect('MSIE'));
89 }
90 // problem with transparent PNG's
91 function isBrowserIE55() {
92     return (isBrowserIE() and 
93             browserVersion() > 5.1 and browserVersion() < 6.0);
94 }
95 // old Netscape prior to Mozilla
96 function isBrowserNetscape($version = false) {
97     $agent = (browserDetect('Mozilla/') and 
98             ! browserDetect('Gecko/') and
99             ! browserDetect('MSIE'));
100     if ($version) return $agent and browserVersion() >= $version; 
101     else return $agent;
102 }
103 // NS3 or less
104 function isBrowserNS3() {
105     return (isBrowserNetscape() and browserVersion() < 4.0);
106 }
107 // NS4 or less
108 function isBrowserNS4() {
109     return (isBrowserNetscape() and browserVersion() < 5.0);
110 }
111 // must omit display alternate stylesheets: konqueror 3.1.4
112 // http://sourceforge.net/tracker/index.php?func=detail&aid=945154&group_id=6121&atid=106121
113 function isBrowserKonqueror($version = false) {
114     if ($version) return browserDetect('Konqueror/') and browserVersion() >= $version; 
115     return browserDetect('Konqueror/');
116 }
117 // MacOSX Safari has certain limitations. Need detection and patches.
118 // * no <object>, only <embed>
119 function isBrowserSafari($version = false) {
120     $found = browserDetect('Spoofer/');
121     $found = browserDetect('AppleWebKit/') or $found;
122     if ($version) return $found and browserVersion() >= $version; 
123     return $found;
124 }
125 function isBrowserOpera($version = false) {
126     if ($version) return browserDetect('Opera/') and browserVersion() >= $version; 
127     return browserDetect('Opera/');
128 }
129
130
131 /**
132  * If $LANG is undefined:
133  * Smart client language detection, based on our supported languages
134  * HTTP_ACCEPT_LANGUAGE="de-at,en;q=0.5"
135  *   => "de"
136  * We should really check additionally if the i18n HomePage version is defined.
137  * So must defer this to the request loop.
138  */
139 function guessing_lang ($languages=false) {
140     if (!$languages) {
141         // make this faster
142         $languages = array("en","de","es","fr","it","ja","zh","nl","sv");
143         // ignore possible "_<territory>" and codeset "ja.utf8"
144         /*
145         require_once("lib/WikiTheme.php");
146         $languages = listAvailableLanguages();
147         if (defined('DEFAULT_LANGUAGE') and in_array(DEFAULT_LANGUAGE, $languages))
148         {
149             // remove duplicates
150             if ($i = array_search(DEFAULT_LANGUAGE, $languages) !== false) {
151                 array_splice($languages, $i, 1);
152             }
153             array_unshift($languages, DEFAULT_LANGUAGE);
154             foreach ($languages as $lang) {
155                 $arr = FileFinder::locale_versions($lang);
156                 $languages = array_merge($languages, $arr);
157             }
158         }
159         */
160     }
161
162     $accept = false; 
163     if (isset($GLOBALS['request'])) // in fixup-dynamic-config there's no request yet
164         $accept = $GLOBALS['request']->get('HTTP_ACCEPT_LANGUAGE');
165     elseif (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
166         $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
167
168     if ($accept) {
169         $lang_list = array();
170         $list = explode(",", $accept);
171         for ($i=0; $i<count($list); $i++) {
172             $pos = strchr($list[$i], ";") ;
173             if ($pos === false) {
174                 // No Q it is only a locale...
175                 $lang_list[$list[$i]] = 100;
176             } else {
177                 // Has a Q rating        
178                 $q = explode(";",$list[$i]) ;
179                 $loc = $q[0] ;
180                 $q = explode("=",$q[1]) ;
181                 $lang_list[$loc] = $q[1]*100 ;
182             }
183         }
184
185         // sort by q desc
186         arsort($lang_list);
187
188         // compare with languages, ignoring sublang and charset
189         foreach ($lang_list as $lang => $q) {
190             if (in_array($lang, $languages))
191                 return $lang;
192             // de_DE.iso8859-1@euro => de_DE.iso8859-1, de_DE, de
193             // de-DE => de-DE, de
194             foreach (array('@', '.', '_') as $sep) {
195                 if ( ($tail = strchr($lang, $sep)) ) {
196                     $lang_short = substr($lang, 0, -strlen($tail));
197                     if (in_array($lang_short, $languages))
198                         return $lang_short;
199                 }
200             }
201             if ($pos = strchr($lang, "-") and in_array(substr($lang, 0, $pos), $languages))
202                 return substr($lang, 0, $pos);
203         }
204     }
205     return $languages[0];
206 }
207
208 /**
209  * Smart setlocale().
210  *
211  * This is a version of the builtin setlocale() which is
212  * smart enough to try some alternatives...
213  *
214  * @param mixed $category
215  * @param string $locale
216  * @return string The new locale, or <code>false</code> if unable
217  *  to set the requested locale.
218  * @see setlocale
219  * [56ms]
220  */
221 function guessing_setlocale ($category, $locale) {
222     $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
223                  'de' => array('de_DE', 'de_DE', 'de_DE@euro', 
224                                'de_AT@euro', 'de_AT', 'German_Austria.1252', 'deutsch', 
225                                'german', 'ge'),
226                  'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
227                  'nl' => array('nl_NL', 'dutch'),
228                  'fr' => array('fr_FR', 'français', 'french'),
229                  'it' => array('it_IT'),
230                  'sv' => array('sv_SE'),
231                  'ja.utf-8'  => array('ja_JP','ja_JP.utf-8','japanese'),
232                  'ja.euc-jp' => array('ja_JP','ja_JP.eucJP','japanese.euc'),
233                  'zh' => array('zh_TW', 'zh_CN'),
234                  );
235     if (!$locale or $locale=='C') { 
236         // do the reverse: return the detected locale collapsed to our LANG
237         $locale = setlocale($category, '');
238         if ($locale) {
239             if (strstr($locale, '_')) list ($lang) = split('_', $locale);
240             else $lang = $locale;
241             if (strlen($lang) > 2) { 
242                 foreach ($alt as $try => $locs) {
243                     if (in_array($locale, $locs) or in_array($lang, $locs)) {
244                         //if (empty($GLOBALS['LANG'])) $GLOBALS['LANG'] = $try;
245                         return $try;
246                     }
247                 }
248             }
249         }
250     }
251     if (strlen($locale) == 2)
252         $lang = $locale;
253     else 
254         list ($lang) = split('_', $locale);
255     if (!isset($alt[$lang]))
256         return false;
257         
258     foreach ($alt[$lang] as $try) {
259         if ($res = setlocale($category, $try))
260             return $res;
261         // Try with charset appended...
262         $try = $try . '.' . $GLOBALS['charset'];
263         if ($res = setlocale($category, $try))
264             return $res;
265         foreach (array(".", '@', '_') as $sep) {
266             if ($i = strpos($try, $sep)) {
267                 $try = substr($try, 0, $i);
268                 if (($res = setlocale($category, $try)))
269                     return $res;
270             }
271         }
272     }
273     return false;
274     // A standard locale name is typically of  the  form
275     // language[_territory][.codeset][@modifier],  where  language is
276     // an ISO 639 language code, territory is an ISO 3166 country code,
277     // and codeset  is  a  character  set or encoding identifier like
278     // ISO-8859-1 or UTF-8.
279 }
280
281 // [99ms]
282 function update_locale($loc) {
283     if ($loc == 'C' or $loc == 'en') return;
284     // $LANG or DEFAULT_LANGUAGE is too less information, at least on unix for
285     // setlocale(), for bindtextdomain() to succeed.
286     $setlocale = guessing_setlocale(LC_ALL, $loc); // [56ms]
287     if (!$setlocale) { // system has no locale for this language, so gettext might fail
288         $setlocale = FileFinder::_get_lang();
289         list ($setlocale,) = split('_', $setlocale, 2);
290         $setlocale = guessing_setlocale(LC_ALL, $setlocale); // try again
291         if (!$setlocale) $setlocale = $loc;
292     }
293     // Try to put new locale into environment (so any
294     // programs we run will get the right locale.)
295     if (!function_exists('bindtextdomain'))  {
296         // Reinitialize translation array.
297         global $locale;
298         $locale = array();
299         // do reinit to purge PHP's static cache [43ms]
300         if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok', 'reinit')) ) {
301             include($lcfile);
302         }
303     } else {
304         // If PHP is in safe mode, this is not allowed,
305         // so hide errors...
306         @putenv("LC_ALL=$setlocale");
307         @putenv("LANG=$loc");
308         @putenv("LANGUAGE=$loc");
309     }
310
311     // To get the POSIX character classes in the PCRE's (e.g.
312     // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
313     // to set the locale, using setlocale().
314     //
315     // The problem is which locale to set?  We would like to recognize all
316     // upper-case characters in the iso-8859-1 character set as upper-case
317     // characters --- not just the ones which are in the current $LANG.
318     //
319     // As it turns out, at least on my system (Linux/glibc-2.2) as long as
320     // you setlocale() to anything but "C" it works fine.  (I'm not sure
321     // whether this is how it's supposed to be, or whether this is a bug
322     // in the libc...)
323     //
324     // We don't currently use the locale setting for anything else, so for
325     // now, just set the locale to US English.
326     //
327     // FIXME: Not all environments may support en_US?  We should probably
328     // have a list of locales to try.
329     if (setlocale(LC_CTYPE, 0) == 'C') {
330         $x = setlocale(LC_CTYPE, 'en_US.' . $GLOBALS['charset']);
331     } else {
332         $x = setlocale(LC_CTYPE, $setlocale);
333     }
334
335     return $loc;
336 }
337
338 /** string pcre_fix_posix_classes (string $regexp)
339 *
340 * Older version (pre 3.x?) of the PCRE library do not support
341 * POSIX named character classes (e.g. [[:alnum:]]).
342 *
343 * This is a helper function which can be used to convert a regexp
344 * which contains POSIX named character classes to one that doesn't.
345 *
346 * All instances of strings like '[:<class>:]' are replaced by the equivalent
347 * enumerated character class.
348 *
349 * Implementation Notes:
350 *
351 * Currently we use hard-coded values which are valid only for
352 * ISO-8859-1.  Also, currently on the classes [:alpha:], [:alnum:],
353 * [:upper:] and [:lower:] are implemented.  (The missing classes:
354 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
355 * [:space:], and [:xdigit:] could easily be added if needed.)
356 *
357 * This is a hack.  I tried to generate these classes automatically
358 * using ereg(), but discovered that in my PHP, at least, ereg() is
359 * slightly broken w.r.t. POSIX character classes.  (It includes
360 * "\xaa" and "\xba" in [:alpha:].)
361 *
362 * So for now, this will do.  --Jeff <dairiki@dairiki.org> 14 Mar, 2001
363 */
364 function pcre_fix_posix_classes ($regexp) {
365     global $charset;
366
367     if (defined('GFORGE') and GFORGE) {
368         return $regexp;
369     }
370
371     if (!isset($charset))
372         $charset = CHARSET; // get rid of constant. pref is dynamic and language specific
373     if (in_array($GLOBALS['LANG'], array('zh')))
374         $charset = 'utf-8';
375     if (strstr($GLOBALS['LANG'],'.utf-8'))
376         $charset = 'utf-8';
377     elseif (strstr($GLOBALS['LANG'],'.euc-jp'))
378         $charset = 'euc-jp';
379     elseif (strstr($GLOBALS['LANG'], 'ja'))
380         $charset = 'euc-jp';
381
382     if (strtolower($charset) == 'utf-8') { // thanks to John McPherson
383         // until posix class names/pcre work with utf-8
384         if (preg_match('/[[:upper:]]/', '\xc4\x80'))
385             return $regexp;    
386         // utf-8 non-ascii chars: most common (eg western) latin chars are 0xc380-0xc3bf
387         // we currently ignore other less common non-ascii characters
388         // (eg central/east european) latin chars are 0xc432-0xcdbf and 0xc580-0xc5be
389         // and indian/cyrillic/asian languages
390         
391         // this replaces [[:lower:]] with utf-8 match (Latin only)
392         $regexp = preg_replace('/\[\[\:lower\:\]\]/','(?:[a-z]|\xc3[\x9f-\xbf]|\xc4[\x81\x83\x85\x87])',
393                                $regexp);
394         // this replaces [[:upper:]] with utf-8 match (Latin only)
395         $regexp = preg_replace('/\[\[\:upper\:\]\]/','(?:[A-Z]|\xc3[\x80-\x9e]|\xc4[\x80\x82\x84\x86])',
396                                $regexp);
397     } elseif (preg_match('/[[:upper:]]/', 'Ä')) {
398         // First check to see if our PCRE lib supports POSIX character
399         // classes.  If it does, there's nothing to do.
400         return $regexp;
401     }
402     static $classes = array(
403                             'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
404                             'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
405                             'upper' => "A-Z\xc0-\xd6\xd8-\xde",
406                             'lower' => "a-z\xdf-\xf6\xf8-\xff"
407                             );
408     $keys = join('|', array_keys($classes));
409     return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
410 }
411
412 function deduce_script_name() {
413     $s = &$GLOBALS['HTTP_SERVER_VARS'];
414     $script = @$s['SCRIPT_NAME'];
415     if (empty($script) or $script[0] != '/') {
416         // Some places (e.g. Lycos) only supply a relative name in
417         // SCRIPT_NAME, but give what we really want in SCRIPT_URL.
418         if (!empty($s['SCRIPT_URL']))
419             $script = $s['SCRIPT_URL'];
420     }
421     return $script;
422 }
423
424 function IsProbablyRedirectToIndex () {
425     // This might be a redirect to the DirectoryIndex,
426     // e.g. REQUEST_URI = /dir/?some_action got redirected
427     // to SCRIPT_NAME = /dir/index.php
428
429     // In this case, the proper virtual path is still
430     // $SCRIPT_NAME, since pages appear at
431     // e.g. /dir/index.php/HomePage.
432
433     $requri = preg_replace('/\?.*$/','',$GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']);
434     $requri = preg_quote($requri, '%');
435     return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
436 }
437
438 // >= php-4.1.0
439 if (!function_exists('array_key_exists')) { // lib/IniConfig.php, sqlite, adodb, ...
440     function array_key_exists($item, $array) {
441         return isset($array[$item]);
442     }
443 }
444
445 // => php-4.0.5
446 if (!function_exists('is_scalar')) { // lib/stdlib.php:wikihash()
447     function is_scalar($x) {
448         return is_numeric($x) or is_string($x) or is_float($x) or is_bool($x); 
449     }
450 }
451
452 // => php-4.2.0. pear wants to break old php's! DB uses it now.
453 if (!function_exists('is_a')) {
454     function is_a($item,$class) {
455         return isa($item,$class); 
456     }
457 }
458
459 // needed < php5
460 // by bradhuizenga at softhome dot net from the php docs
461 if (!function_exists('str_ireplace')) {
462   function str_ireplace($find, $replace, $string) {
463       if (!is_array($find)) $find = array($find);
464       if (!is_array($replace)) {
465           if (!is_array($find)) 
466               $replace = array($replace);
467           else {
468               // this will duplicate the string into an array the size of $find
469               $c = count($find);
470               $rString = $replace;
471               unset($replace);
472               for ($i = 0; $i < $c; $i++) {
473                   $replace[$i] = $rString;
474               }
475           }
476       }
477       foreach ($find as $fKey => $fItem) {
478           $between = explode(strtolower($fItem),strtolower($string));
479           $pos = 0;
480           foreach ($between as $bKey => $bItem) {
481               $between[$bKey] = substr($string,$pos,strlen($bItem));
482               $pos += strlen($bItem) + strlen($fItem);
483           }
484           $string = implode($replace[$fKey], $between);
485       }
486       return($string);
487   }
488 }
489
490 /**
491  * safe php4 definition for clone.
492  * php5 copies objects by reference, but we need to clone "deep copy" in some places.
493  * (BlockParser)
494  * We need to eval it as workaround for the php5 parser.
495  * See http://www.acko.net/node/54
496  */
497 if (!check_php_version(5)) {
498     eval('
499     function clone($object) {
500       return $object;
501     }
502     ');
503 }
504
505 /**
506  * array_diff_assoc() returns an array containing all the values from array1 that are not
507  * present in any of the other arguments. Note that the keys are used in the comparison 
508  * unlike array_diff(). In core since php-4.3.0
509  * Our fallback here supports only hashes and two args.
510  * $array1 = array("a" => "green", "b" => "brown", "c" => "blue");
511  * $array2 = array("a" => "green", "y" => "yellow", "r" => "red");
512  * => b => brown, c => blue
513  */
514 if (!function_exists('array_diff_assoc')) {
515     function array_diff_assoc($a1, $a2) {
516         $result = array();
517         foreach ($a1 as $k => $v) {
518             if (!isset($a2[$k]) or !$a2[$k])
519                 $result[$k] = $v;       
520         }
521         return $result;
522     }
523 }
524
525 /** 
526  * wordwrap() might crash between 4.1.2 and php-4.3.0RC2, fixed in 4.3.0
527  * See http://bugs.php.net/bug.php?id=20927 and 
528  * http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1396
529  * Improved version of wordwrap2() in the comments at http://www.php.net/wordwrap
530  */
531 function safe_wordwrap($str, $width=80, $break="\n", $cut=false) {
532     if (check_php_version(4,3))
533         return wordwrap($str, $width, $break, $cut);
534     elseif (!check_php_version(4,1,2))
535         return wordwrap($str, $width, $break, $cut);
536     else {
537         $len = strlen($str);
538         $tag = 0; $result = ''; $wordlen = 0;
539         for ($i = 0; $i < $len; $i++) {
540             $chr = $str[$i];
541             // don't break inside xml tags
542             if ($chr == '<') {
543                 $tag++;
544             } elseif ($chr == '>') {
545                 $tag--;
546             } elseif (!$tag) {
547                 if (!function_exists('ctype_space')) {
548                     if (preg_match('/^\s$/', $chr))
549                         $wordlen = 0;
550                     else
551                         $wordlen++;
552                 }
553                 elseif (ctype_space($chr)) {
554                     $wordlen = 0;
555                 } else {
556                     $wordlen++;
557                 }
558             }
559             if ((!$tag) && ($wordlen) && (!($wordlen % $width))) {
560                 $chr .= $break;
561             }
562             $result .= $chr;
563         }
564         return $result;
565         /*
566         if (isset($str) && isset($width)) {
567             $ex = explode(" ", $str); // wrong: must use preg_split \s+
568             $rp = array();
569             for ($i=0; $i<count($ex); $i++) {
570                 // $word_array = preg_split('//', $ex[$i], -1, PREG_SPLIT_NO_EMPTY);
571                 // delete #&& !is_numeric($ex[$i])# if you want force it anyway
572                 if (strlen($ex[$i]) > $width && !is_numeric($ex[$i])) {
573                     $where = 0;
574                     $rp[$i] = "";
575                     for($b=0; $b < (ceil(strlen($ex[$i]) / $width)); $b++) {
576                         $rp[$i] .= substr($ex[$i], $where, $width).$break;
577                         $where += $width;
578                     }
579                 } else {
580                     $rp[$i] = $ex[$i];
581                 }
582             }
583             return implode(" ",$rp);
584         }
585         return $text;
586         */
587     }
588 }
589
590 function getUploadFilePath() {
591
592     if (defined('UPLOAD_FILE_PATH')) {
593         // Force creation of the returned directory if it does not exist.
594         if (!file_exists(UPLOAD_FILE_PATH)) {
595             mkdir(UPLOAD_FILE_PATH, 0775);
596         }
597         if (string_ends_with(UPLOAD_FILE_PATH, "/") 
598             or string_ends_with(UPLOAD_FILE_PATH, "\\")) {
599             return UPLOAD_FILE_PATH;
600         } else {
601             return UPLOAD_FILE_PATH."/";
602         }
603     }
604     return defined('PHPWIKI_DIR') 
605         ? PHPWIKI_DIR . "/uploads/" 
606         : realpath(dirname(__FILE__) . "/../uploads/");
607 }
608 function getUploadDataPath() {
609     if (defined('UPLOAD_DATA_PATH')) {
610         return string_ends_with(UPLOAD_DATA_PATH, "/") 
611             ? UPLOAD_DATA_PATH : UPLOAD_DATA_PATH."/";
612     }
613     return SERVER_URL . (string_ends_with(DATA_PATH, "/") ? '' : "/") 
614          . DATA_PATH . '/uploads/';
615 }
616
617 /**
618  * htmlspecialchars doesn't support some special 8bit charsets, which we do want to support.
619  * Well it just prints a warning which we could circumvent.
620  * Note: unused, since php htmlspecialchars does the same, just prints a warning which we silence
621  */
622 /*
623 function htmlspecialchars_workaround($str, $quote=ENT_COMPAT, $charset='iso-8859-1') {
624     if (in_array(strtolower($charset), 
625                  array('iso-8859-2', 'iso8859-2', 'latin-2', 'latin2'))) 
626     {
627         if (! ($quote & ENT_NOQUOTES)) {
628             $str = str_replace("\"", "&quot;",
629                                $str);
630         }
631         if ($quote & ENT_QUOTES) {
632             $str = str_replace("\'", "&#039;",
633                                $str);
634         }
635         return str_replace(array("<", ">", "&"),
636                            array("&lt;", "&gt;", "&amp;"), $str);
637     }
638     else {
639         return htmlspecialchars($str, $quote, $charset);
640     }
641 }
642 */
643
644 /**
645  * htmlspecialchars doesn't support some special 8bit charsets, which we do want to support.
646  * Well it just prints a warning which we could circumvent.
647  * Note: unused, since php htmlspecialchars does the same, just prints a warning which we silence
648  */
649 /*
650 function htmlspecialchars_workaround($str, $quote=ENT_COMPAT, $charset='iso-8859-1') {
651     if (in_array(strtolower($charset), 
652                  array('iso-8859-2', 'iso8859-2', 'latin-2', 'latin2'))) 
653     {
654         if (! ($quote & ENT_NOQUOTES)) {
655             $str = str_replace("\"", "&quot;",
656                                $str);
657         }
658         if ($quote & ENT_QUOTES) {
659             $str = str_replace("\'", "&#039;",
660                                $str);
661         }
662         return str_replace(array("<", ">", "&"),
663                            array("&lt;", "&gt;", "&amp;"), $str);
664     }
665     else {
666         return htmlspecialchars($str, $quote, $charset);
667     }
668 }
669 */
670
671 // For emacs users
672 // Local Variables:
673 // mode: php
674 // tab-width: 8
675 // c-basic-offset: 4
676 // c-hanging-comment-ender-p: nil
677 // indent-tabs-mode: nil
678 // End:
679 ?>