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