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