]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/config.php
add Opera (untested)
[SourceForge/phpwiki.git] / lib / config.php
1 <?php
2 rcs_id('$Id: config.php,v 1.144 2007-06-01 06:34:54 rurban Exp $');
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);
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(browserAgent(), $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     if ($version) return browserDetect('Safari/') and browserVersion() >= $version; 
120     return browserDetect('Safari/');
121 }
122 function isBrowserOpera($version = false) {
123     if ($version) return browserDetect('Opera/') and browserVersion() >= $version; 
124     return browserDetect('Opera/');
125 }
126
127
128 /**
129  * If $LANG is undefined:
130  * Smart client language detection, based on our supported languages
131  * HTTP_ACCEPT_LANGUAGE="de-at,en;q=0.5"
132  *   => "de"
133  * We should really check additionally if the i18n HomePage version is defined.
134  * So must defer this to the request loop.
135  */
136 function guessing_lang ($languages=false) {
137     if (!$languages) {
138         // make this faster
139         $languages = array("en","de","es","fr","it","ja","zh","nl","sv");
140         // ignore possible "_<territory>" and codeset "ja.utf8"
141         /*
142         require_once("lib/Theme.php");
143         $languages = listAvailableLanguages();
144         if (defined('DEFAULT_LANGUAGE') and in_array(DEFAULT_LANGUAGE, $languages))
145         {
146             // remove duplicates
147             if ($i = array_search(DEFAULT_LANGUAGE, $languages) !== false) {
148                 array_splice($languages, $i, 1);
149             }
150             array_unshift($languages, DEFAULT_LANGUAGE);
151             foreach ($languages as $lang) {
152                 $arr = FileFinder::locale_versions($lang);
153                 $languages = array_merge($languages, $arr);
154             }
155         }
156         */
157     }
158
159     $accept = false; 
160     if (isset($GLOBALS['request'])) // in fixup-dynamic-config there's no request yet
161         $accept = $GLOBALS['request']->get('HTTP_ACCEPT_LANGUAGE');
162     elseif (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
163         $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
164
165     if ($accept) {
166         $lang_list = array();
167         $list = explode(",", $accept);
168         for ($i=0; $i<count($list); $i++) {
169             $pos = strchr($list[$i], ";") ;
170             if ($pos === false) {
171                 // No Q it is only a locale...
172                 $lang_list[$list[$i]] = 100;
173             } else {
174                 // Has a Q rating        
175                 $q = explode(";",$list[$i]) ;
176                 $loc = $q[0] ;
177                 $q = explode("=",$q[1]) ;
178                 $lang_list[$loc] = $q[1]*100 ;
179             }
180         }
181
182         // sort by q desc
183         arsort($lang_list);
184
185         // compare with languages, ignoring sublang and charset
186         foreach ($lang_list as $lang => $q) {
187             if (in_array($lang, $languages))
188                 return $lang;
189             // de_DE.iso8859-1@euro => de_DE.iso8859-1, de_DE, de
190             // de-DE => de-DE, de
191             foreach (array('@', '.', '_') as $sep) {
192                 if ( ($tail = strchr($lang, $sep)) ) {
193                     $lang_short = substr($lang, 0, -strlen($tail));
194                     if (in_array($lang_short, $languages))
195                         return $lang_short;
196                 }
197             }
198             if ($pos = strchr($lang, "-") and in_array(substr($lang, 0, $pos), $languages))
199                 return substr($lang, 0, $pos);
200         }
201     }
202     return $languages[0];
203 }
204
205 /**
206  * Smart setlocale().
207  *
208  * This is a version of the builtin setlocale() which is
209  * smart enough to try some alternatives...
210  *
211  * @param mixed $category
212  * @param string $locale
213  * @return string The new locale, or <code>false</code> if unable
214  *  to set the requested locale.
215  * @see setlocale
216  * [56ms]
217  */
218 function guessing_setlocale ($category, $locale) {
219     $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
220                  'de' => array('de_DE', 'de_DE', 'de_DE@euro', 
221                                'de_AT@euro', 'de_AT', 'German_Austria.1252', 'deutsch', 
222                                'german', 'ge'),
223                  'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
224                  'nl' => array('nl_NL', 'dutch'),
225                  'fr' => array('fr_FR', 'français', 'french'),
226                  'it' => array('it_IT'),
227                  'sv' => array('sv_SE'),
228                  'ja.utf-8'  => array('ja_JP','ja_JP.utf-8','japanese'),
229                  'ja.euc-jp' => array('ja_JP','ja_JP.eucJP','japanese.euc'),
230                  'zh' => array('zh_TW', 'zh_CN'),
231                  );
232     if (!$locale or $locale=='C') { 
233         // do the reverse: return the detected locale collapsed to our LANG
234         $locale = setlocale($category, '');
235         if ($locale) {
236             if (strstr($locale, '_')) list ($lang) = split('_', $locale);
237             else $lang = $locale;
238             if (strlen($lang) > 2) { 
239                 foreach ($alt as $try => $locs) {
240                     if (in_array($locale, $locs) or in_array($lang, $locs)) {
241                         //if (empty($GLOBALS['LANG'])) $GLOBALS['LANG'] = $try;
242                         return $try;
243                     }
244                 }
245             }
246         }
247     }
248     if (strlen($locale) == 2)
249         $lang = $locale;
250     else 
251         list ($lang) = split('_', $locale);
252     if (!isset($alt[$lang]))
253         return false;
254         
255     foreach ($alt[$lang] as $try) {
256         if ($res = setlocale($category, $try))
257             return $res;
258         // Try with charset appended...
259         $try = $try . '.' . $GLOBALS['charset'];
260         if ($res = setlocale($category, $try))
261             return $res;
262         foreach (array(".", '@', '_') as $sep) {
263             if ($i = strpos($try, $sep)) {
264                 $try = substr($try, 0, $i);
265                 if (($res = setlocale($category, $try)))
266                     return $res;
267             }
268         }
269     }
270     return false;
271     // A standard locale name is typically of  the  form
272     // language[_territory][.codeset][@modifier],  where  language is
273     // an ISO 639 language code, territory is an ISO 3166 country code,
274     // and codeset  is  a  character  set or encoding identifier like
275     // ISO-8859-1 or UTF-8.
276 }
277
278 // [99ms]
279 function update_locale($loc) {
280     // $LANG or DEFAULT_LANGUAGE is too less information, at least on unix for
281     // setlocale(), for bindtextdomain() to succeed.
282     $setlocale = guessing_setlocale(LC_ALL, $loc); // [56ms]
283     if (!$setlocale) { // system has no locale for this language, so gettext might fail
284         $setlocale = FileFinder::_get_lang();
285         list ($setlocale,) = split('_', $setlocale, 2);
286         $setlocale = guessing_setlocale(LC_ALL, $setlocale); // try again
287         if (!$setlocale) $setlocale = $loc;
288     }
289     // Try to put new locale into environment (so any
290     // programs we run will get the right locale.)
291     if (!function_exists('bindtextdomain'))  {
292         // Reinitialize translation array.
293         global $locale;
294         $locale = array();
295         // do reinit to purge PHP's static cache [43ms]
296         if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok', 'reinit')) ) {
297             include($lcfile);
298         }
299     } else {
300         // If PHP is in safe mode, this is not allowed,
301         // so hide errors...
302         @putenv("LC_ALL=$setlocale");
303         @putenv("LANG=$loc");
304         @putenv("LANGUAGE=$loc");
305     }
306
307     // To get the POSIX character classes in the PCRE's (e.g.
308     // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
309     // to set the locale, using setlocale().
310     //
311     // The problem is which locale to set?  We would like to recognize all
312     // upper-case characters in the iso-8859-1 character set as upper-case
313     // characters --- not just the ones which are in the current $LANG.
314     //
315     // As it turns out, at least on my system (Linux/glibc-2.2) as long as
316     // you setlocale() to anything but "C" it works fine.  (I'm not sure
317     // whether this is how it's supposed to be, or whether this is a bug
318     // in the libc...)
319     //
320     // We don't currently use the locale setting for anything else, so for
321     // now, just set the locale to US English.
322     //
323     // FIXME: Not all environments may support en_US?  We should probably
324     // have a list of locales to try.
325     if (setlocale(LC_CTYPE, 0) == 'C') {
326         $x = setlocale(LC_CTYPE, 'en_US.' . $GLOBALS['charset']);
327     } else {
328         $x = setlocale(LC_CTYPE, $setlocale);
329     }
330
331     return $loc;
332 }
333
334 /** string pcre_fix_posix_classes (string $regexp)
335 *
336 * Older version (pre 3.x?) of the PCRE library do not support
337 * POSIX named character classes (e.g. [[:alnum:]]).
338 *
339 * This is a helper function which can be used to convert a regexp
340 * which contains POSIX named character classes to one that doesn't.
341 *
342 * All instances of strings like '[:<class>:]' are replaced by the equivalent
343 * enumerated character class.
344 *
345 * Implementation Notes:
346 *
347 * Currently we use hard-coded values which are valid only for
348 * ISO-8859-1.  Also, currently on the classes [:alpha:], [:alnum:],
349 * [:upper:] and [:lower:] are implemented.  (The missing classes:
350 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
351 * [:space:], and [:xdigit:] could easily be added if needed.)
352 *
353 * This is a hack.  I tried to generate these classes automatically
354 * using ereg(), but discovered that in my PHP, at least, ereg() is
355 * slightly broken w.r.t. POSIX character classes.  (It includes
356 * "\xaa" and "\xba" in [:alpha:].)
357 *
358 * So for now, this will do.  --Jeff <dairiki@dairiki.org> 14 Mar, 2001
359 */
360 function pcre_fix_posix_classes ($regexp) {
361     global $charset;
362     if (!isset($charset))
363         $charset = CHARSET; // get rid of constant. pref is dynamic and language specific
364     if (in_array($GLOBALS['LANG'], array('zh')))
365         $charset = 'utf-8';
366     if (strstr($GLOBALS['LANG'],'.utf-8'))
367         $charset = 'utf-8';
368     elseif (strstr($GLOBALS['LANG'],'.euc-jp'))
369         $charset = 'euc-jp';
370     elseif (in_array($GLOBALS['LANG'], array('ja')))
371         //$charset = 'utf-8';
372         $charset = 'euc-jp';
373
374     if (strtolower($charset) == 'utf-8') { // thanks to John McPherson
375         // until posix class names/pcre work with utf-8
376         if (preg_match('/[[:upper:]]/', '\xc4\x80'))
377             return $regexp;    
378         // utf-8 non-ascii chars: most common (eg western) latin chars are 0xc380-0xc3bf
379         // we currently ignore other less common non-ascii characters
380         // (eg central/east european) latin chars are 0xc432-0xcdbf and 0xc580-0xc5be
381         // and indian/cyrillic/asian languages
382         
383         // this replaces [[:lower:]] with utf-8 match (Latin only)
384         $regexp = preg_replace('/\[\[\:lower\:\]\]/','(?:[a-z]|\xc3[\x9f-\xbf]|\xc4[\x81\x83\x85\x87])',
385                                $regexp);
386         // this replaces [[:upper:]] with utf-8 match (Latin only)
387         $regexp = preg_replace('/\[\[\:upper\:\]\]/','(?:[A-Z]|\xc3[\x80-\x9e]|\xc4[\x80\x82\x84\x86])',
388                                $regexp);
389     } elseif (preg_match('/[[:upper:]]/', 'Ä')) {
390         // First check to see if our PCRE lib supports POSIX character
391         // classes.  If it does, there's nothing to do.
392         return $regexp;
393     }
394     static $classes = array(
395                             'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
396                             'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
397                             'upper' => "A-Z\xc0-\xd6\xd8-\xde",
398                             'lower' => "a-z\xdf-\xf6\xf8-\xff"
399                             );
400     $keys = join('|', array_keys($classes));
401     return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
402 }
403
404 function deduce_script_name() {
405     $s = &$GLOBALS['HTTP_SERVER_VARS'];
406     $script = @$s['SCRIPT_NAME'];
407     if (empty($script) or $script[0] != '/') {
408         // Some places (e.g. Lycos) only supply a relative name in
409         // SCRIPT_NAME, but give what we really want in SCRIPT_URL.
410         if (!empty($s['SCRIPT_URL']))
411             $script = $s['SCRIPT_URL'];
412     }
413     return $script;
414 }
415
416 function IsProbablyRedirectToIndex () {
417     // This might be a redirect to the DirectoryIndex,
418     // e.g. REQUEST_URI = /dir/?some_action got redirected
419     // to SCRIPT_NAME = /dir/index.php
420
421     // In this case, the proper virtual path is still
422     // $SCRIPT_NAME, since pages appear at
423     // e.g. /dir/index.php/HomePage.
424
425     $requri = preg_replace('/\?.*$/','',$GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']);
426     $requri = preg_quote($requri, '%');
427     return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
428 }
429
430 // >= php-4.1.0
431 if (!function_exists('array_key_exists')) { // lib/IniConfig.php, sqlite, adodb, ...
432     function array_key_exists($item, $array) {
433         return isset($array[$item]);
434     }
435 }
436
437 // => php-4.0.5
438 if (!function_exists('is_scalar')) { // lib/stdlib.php:wikihash()
439     function is_scalar($x) {
440         return is_numeric($x) or is_string($x) or is_float($x) or is_bool($x); 
441     }
442 }
443
444 // => php-4.2.0. pear wants to break old php's! DB uses it now.
445 if (!function_exists('is_a')) {
446     function is_a($item,$class) {
447         return isa($item,$class); 
448     }
449 }
450
451 // needed < php5
452 // by bradhuizenga at softhome dot net from the php docs
453 if (!function_exists('str_ireplace')) {
454   function str_ireplace($find, $replace, $string) {
455       if (!is_array($find)) $find = array($find);
456       if (!is_array($replace)) {
457           if (!is_array($find)) 
458               $replace = array($replace);
459           else {
460               // this will duplicate the string into an array the size of $find
461               $c = count($find);
462               $rString = $replace;
463               unset($replace);
464               for ($i = 0; $i < $c; $i++) {
465                   $replace[$i] = $rString;
466               }
467           }
468       }
469       foreach ($find as $fKey => $fItem) {
470           $between = explode(strtolower($fItem),strtolower($string));
471           $pos = 0;
472           foreach ($between as $bKey => $bItem) {
473               $between[$bKey] = substr($string,$pos,strlen($bItem));
474               $pos += strlen($bItem) + strlen($fItem);
475           }
476           $string = implode($replace[$fKey], $between);
477       }
478       return($string);
479   }
480 }
481
482 /**
483  * safe php4 definition for clone.
484  * php5 copies objects by reference, but we need to clone "deep copy" in some places.
485  * (BlockParser)
486  * We need to eval it as workaround for the php5 parser.
487  * See http://www.acko.net/node/54
488  */
489 if (!check_php_version(5)) {
490     eval('
491     function clone($object) {
492       return $object;
493     }
494     ');
495 }
496
497 /**
498  * array_diff_assoc() returns an array containing all the values from array1 that are not
499  * present in any of the other arguments. Note that the keys are used in the comparison 
500  * unlike array_diff(). In core since php-4.3.0
501  * Our fallback here supports only hashes and two args.
502  * $array1 = array("a" => "green", "b" => "brown", "c" => "blue");
503  * $array2 = array("a" => "green", "y" => "yellow", "r" => "red");
504  * => b => brown, c => blue
505  */
506 if (!function_exists('array_diff_assoc')) {
507     function array_diff_assoc($a1, $a2) {
508         $result = array();
509         foreach ($a1 as $k => $v) {
510             if (!isset($a2[$k]) or !$a2[$k])
511                 $result[$k] = $v;       
512         }
513         return $result;
514     }
515 }
516
517 /** 
518  * wordwrap() might crash between 4.1.2 and php-4.3.0RC2, fixed in 4.3.0
519  * See http://bugs.php.net/bug.php?id=20927 and 
520  * http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1396
521  * Improved version of wordwrap2() in the comments at http://www.php.net/wordwrap
522  */
523 function safe_wordwrap($str, $width=80, $break="\n", $cut=false) {
524     if (check_php_version(4,3))
525         return wordwrap($str, $width, $break, $cut);
526     elseif (!check_php_version(4,1,2))
527         return wordwrap($str, $width, $break, $cut);
528     else {
529         $len = strlen($str);
530         $tag = 0; $result = ''; $wordlen = 0;
531         for ($i = 0; $i < $len; $i++) {
532             $chr = $str[$i];
533             // don't break inside xml tags
534             if ($chr == '<') {
535                 $tag++;
536             } elseif ($chr == '>') {
537                 $tag--;
538             } elseif (!$tag) {
539                 if (!function_exists('ctype_space')) {
540                     if (preg_match('/^\s$/', $chr))
541                         $wordlen = 0;
542                     else
543                         $wordlen++;
544                 }
545                 elseif (ctype_space($chr)) {
546                     $wordlen = 0;
547                 } else {
548                     $wordlen++;
549                 }
550             }
551             if ((!$tag) && ($wordlen) && (!($wordlen % $width))) {
552                 $chr .= $break;
553             }
554             $result .= $chr;
555         }
556         return $result;
557         /*
558         if (isset($str) && isset($width)) {
559             $ex = explode(" ", $str); // wrong: must use preg_split \s+
560             $rp = array();
561             for ($i=0; $i<count($ex); $i++) {
562                 // $word_array = preg_split('//', $ex[$i], -1, PREG_SPLIT_NO_EMPTY);
563                 // delete #&& !is_numeric($ex[$i])# if you want force it anyway
564                 if (strlen($ex[$i]) > $width && !is_numeric($ex[$i])) {
565                     $where = 0;
566                     $rp[$i] = "";
567                     for($b=0; $b < (ceil(strlen($ex[$i]) / $width)); $b++) {
568                         $rp[$i] .= substr($ex[$i], $where, $width).$break;
569                         $where += $width;
570                     }
571                 } else {
572                     $rp[$i] = $ex[$i];
573                 }
574             }
575             return implode(" ",$rp);
576         }
577         return $text;
578         */
579     }
580 }
581
582 function getUploadFilePath() {
583     if (defined('UPLOAD_FILE_PATH')) return UPLOAD_FILE_PATH;
584     return defined('PHPWIKI_DIR') 
585         ? PHPWIKI_DIR . "/uploads/" 
586         : realpath(dirname(__FILE__) . "/../uploads/");
587 }
588 function getUploadDataPath() {
589     if (defined('UPLOAD_DATA_PATH')) return UPLOAD_DATA_PATH;
590     return SERVER_URL . ((substr(DATA_PATH,0,1)=='/') ? '' : "/") . DATA_PATH . '/uploads/';
591 }
592
593 /**
594  * htmlspecialchars doesn't support some special 8bit charsets, which we do want to support.
595  * Well it just prints a warning which we could circumvent.
596  * Note: unused, since php htmlspecialchars does the same, just prints a warning which we silence
597  */
598 /*
599 function htmlspecialchars_workaround($str, $quote=ENT_COMPAT, $charset='iso-8859-1') {
600     if (in_array(strtolower($charset), 
601                  array('iso-8859-2', 'iso8859-2', 'latin-2', 'latin2'))) 
602     {
603         if (! ($quote & ENT_NOQUOTES)) {
604             $str = str_replace("\"", "&quot;",
605                                $str);
606         }
607         if ($quote & ENT_QUOTES) {
608             $str = str_replace("\'", "&#039;",
609                                $str);
610         }
611         return str_replace(array("<", ">", "&"),
612                            array("&lt;", "&gt;", "&amp;"), $str);
613     }
614     else {
615         return htmlspecialchars($str, $quote, $charset);
616     }
617 }
618 */
619
620 /**
621  * htmlspecialchars doesn't support some special 8bit charsets, which we do want to support.
622  * Well it just prints a warning which we could circumvent.
623  * Note: unused, since php htmlspecialchars does the same, just prints a warning which we silence
624  */
625 /*
626 function htmlspecialchars_workaround($str, $quote=ENT_COMPAT, $charset='iso-8859-1') {
627     if (in_array(strtolower($charset), 
628                  array('iso-8859-2', 'iso8859-2', 'latin-2', 'latin2'))) 
629     {
630         if (! ($quote & ENT_NOQUOTES)) {
631             $str = str_replace("\"", "&quot;",
632                                $str);
633         }
634         if ($quote & ENT_QUOTES) {
635             $str = str_replace("\'", "&#039;",
636                                $str);
637         }
638         return str_replace(array("<", ">", "&"),
639                            array("&lt;", "&gt;", "&amp;"), $str);
640     }
641     else {
642         return htmlspecialchars($str, $quote, $charset);
643     }
644 }
645 */
646
647 // $Log: not supported by cvs2svn $
648 // Revision 1.143  2007/05/24 18:36:56  rurban
649 // *** empty log message ***
650 //
651 // Revision 1.142  2007/03/04 14:07:17  rurban
652 // Added SearchHighlight comment
653 //
654 // Revision 1.141  2007/01/07 18:41:42  rurban
655 // Add array_diff_assoc() fallback: fixes Blog with php < 4.3.x. Support UPLOAD_FILE_PATH, UPLOAD_DATA_PATH overrides.
656 //
657 // Revision 1.140  2007/01/02 13:21:30  rurban
658 // added _DEBUG_REMOTE flag, omit want_content if not necessary
659 //
660 // Revision 1.139  2006/03/19 14:50:42  rurban
661 // sf.net patch #1438442 by Matt Brown: Unitialised variable reference in config.php
662 //
663 // Revision 1.138  2006/03/07 20:45:43  rurban
664 // wikihash for php-5.1
665 //
666 // Revision 1.137  2005/08/06 14:31:10  rurban
667 // ensure absolute uploads path
668 //
669 // Revision 1.136  2005/05/06 16:49:24  rurban
670 // Safari comment
671 //
672 // Revision 1.135  2005/04/01 15:22:20  rurban
673 // Implement icase and regex options.
674 // Change checkbox case message from "Case-Sensitive" to "Case-Insensitive"
675 //
676 // Revision 1.134  2005/03/27 18:23:39  rurban
677 // compute locale only for setlocale and LC_ALL
678 //
679 // Revision 1.133  2005/02/08 13:26:59  rurban
680 //  improve the locale splitter
681 //
682 // Revision 1.132  2005/02/07 15:39:02  rurban
683 // another locale fix
684 //
685 // Revision 1.131  2005/02/05 15:32:09  rurban
686 // force guessing_setlocale (again)
687 //
688 // Revision 1.130  2005/01/29 20:36:44  rurban
689 // very important php5 fix! clone objects
690 //
691 // Revision 1.129  2005/01/08 22:53:50  rurban
692 // hardcode list of langs (file access is slow)
693 // fix client detection
694 // set proper locale on empty locale
695 //
696 // Revision 1.128  2005/01/04 20:22:46  rurban
697 // guess $LANG based on client
698 //
699 // Revision 1.127  2004/12/26 17:15:32  rurban
700 // new reverse locale detection on DEFAULT_LANGUAGE="", ja default euc-jp again
701 //
702 // Revision 1.126  2004/12/20 16:05:00  rurban
703 // gettext msg unification
704 //
705 // Revision 1.125  2004/11/21 11:59:18  rurban
706 // remove final \n to be ob_cache independent
707 //
708 // Revision 1.124  2004/11/09 17:11:16  rurban
709 // * revert to the wikidb ref passing. there's no memory abuse there.
710 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
711 //   store page ids with getPageLinks (GleanDescription) of all existing pages, which
712 //   are also needed at the rendering for linkExistingWikiWord().
713 //   pass options to pageiterator.
714 //   use this cache also for _get_pageid()
715 //   This saves about 8 SELECT count per page (num all pagelinks).
716 // * fix passing of all page fields to the pageiterator.
717 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
718 //
719 // Revision 1.123  2004/11/05 21:03:27  rurban
720 // new DEBUG flag: _DEBUG_LOGIN (64)
721 //   verbose login debug-msg (settings and reason for failure)
722 //
723 // Revision 1.122  2004/10/14 17:49:58  rurban
724 // fix warning in safe_wordwrap
725 //
726 // Revision 1.121  2004/10/14 17:48:19  rurban
727 // typo in safe_wordwrap
728 //
729 // Revision 1.120  2004/09/22 13:46:26  rurban
730 // centralize upload paths.
731 // major WikiPluginCached feature enhancement:
732 //   support _STATIC pages in uploads/ instead of dynamic getimg.php? subrequests.
733 //   mainly for debugging, cache problems and action=pdf
734 //
735 // Revision 1.119  2004/09/16 07:50:37  rurban
736 // wordwrap() might crash between 4.1.2 and php-4.3.0RC2, fixed in 4.3.0
737 // See http://bugs.php.net/bug.php?id=20927 and
738 //     http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1396
739 // Improved version of wordwrap2() from the comments at http://www.php.net/wordwrap
740 //
741 // Revision 1.118  2004/07/13 14:03:31  rurban
742 // just some comments
743 //
744 // Revision 1.117  2004/06/21 17:29:17  rurban
745 // pear DB introduced a is_a requirement. so pear lost support for php < 4.2.0
746 //
747 // Revision 1.116  2004/06/21 08:39:37  rurban
748 // pear/Cache update from Cache-1.5.4 (added db and trifile container)
749 // pear/DB update from DB-1.6.1 (mysql bugfixes, php5 compat, DB_PORTABILITY features)
750 //
751 // Revision 1.115  2004/06/20 14:42:54  rurban
752 // various php5 fixes (still broken at blockparser)
753 //
754 // Revision 1.114  2004/06/19 11:48:05  rurban
755 // moved version check forwards: already needed in XmlElement::_quote
756 //
757 // Revision 1.113  2004/06/03 12:59:41  rurban
758 // simplify translation
759 // NS4 wrap=virtual only
760 //
761 // Revision 1.112  2004/06/02 18:01:46  rurban
762 // init global FileFinder to add proper include paths at startup
763 //   adds PHPWIKI_DIR if started from another dir, lib/pear also
764 // fix slashify for Windows
765 // fix USER_AUTH_POLICY=old, use only USER_AUTH_ORDER methods (besides HttpAuth)
766 //
767 // Revision 1.111  2004/05/17 17:43:29  rurban
768 // CGI: no PATH_INFO fix
769 //
770 // Revision 1.110  2004/05/16 23:10:44  rurban
771 // update_locale wrongly resetted LANG, which broke japanese.
772 // japanese now correctly uses EUC_JP, not utf-8.
773 // more charset and lang headers to help the browser.
774 //
775 // Revision 1.109  2004/05/08 14:06:12  rurban
776 // new support for inlined image attributes: [image.jpg size=50x30 align=right]
777 // minor stability and portability fixes
778 //
779 // Revision 1.108  2004/05/08 11:25:16  rurban
780 // php-4.0.4 fixes
781 //
782 // Revision 1.107  2004/05/06 17:30:38  rurban
783 // CategoryGroup: oops, dos2unix eol
784 // improved phpwiki_version:
785 //   pre -= .0001 (1.3.10pre: 1030.099)
786 //   -p1 += .001 (1.3.9-p1: 1030.091)
787 // improved InstallTable for mysql and generic SQL versions and all newer tables so far.
788 // abstracted more ADODB/PearDB methods for action=upgrade stuff:
789 //   backend->backendType(), backend->database(),
790 //   backend->listOfFields(),
791 //   backend->listOfTables(),
792 //
793 // Revision 1.106  2004/05/02 19:12:14  rurban
794 // fix sf.net bug #945154 Konqueror alt css
795 //
796 // Revision 1.105  2004/05/02 15:10:06  rurban
797 // new finally reliable way to detect if /index.php is called directly
798 //   and if to include lib/main.php
799 // new global AllActionPages
800 // SetupWiki now loads all mandatory pages: HOME_PAGE, action pages, and warns if not.
801 // WikiTranslation what=buttons for Carsten to create the missing MacOSX buttons
802 // PageGroupTestOne => subpages
803 // renamed PhpWikiRss to PhpWikiRecentChanges
804 // more docs, default configs, ...
805 //
806 // Revision 1.104  2004/05/01 11:26:37  rurban
807 // php-4.0.x support: array_key_exists (PHP 4 >= 4.1.0)
808 //
809 // Revision 1.103  2004/04/30 00:04:14  rurban
810 // zh (chinese language) support
811 //
812 // Revision 1.102  2004/04/29 23:25:12  rurban
813 // re-ordered locale init (as in 1.3.9)
814 // fixed loadfile with subpages, and merge/restore anyway
815 //   (sf.net bug #844188)
816 //
817 // Revision 1.101  2004/04/26 13:22:32  rurban
818 // calculate bool old or dynamic constants later
819 //
820 // Revision 1.100  2004/04/26 12:15:01  rurban
821 // check default config values
822 //
823 // Revision 1.99  2004/04/21 14:04:24  zorloc
824 // 'Require lib/FileFinder.php' necessary to allow for call to FindLocalizedFile().
825 //
826 // Revision 1.98  2004/04/20 18:10:28  rurban
827 // config refactoring:
828 //   FileFinder is needed for WikiFarm scripts calling index.php
829 //   config run-time calls moved to lib/IniConfig.php:fix_configs()
830 //   added PHPWIKI_DIR smart-detection code (Theme finder)
831 //   moved FileFind to lib/FileFinder.php
832 //   cleaned lib/config.php
833 //
834 // Revision 1.97  2004/04/18 01:11:52  rurban
835 // more numeric pagename fixes.
836 // fixed action=upload with merge conflict warnings.
837 // charset changed from constant to global (dynamic utf-8 switching)
838 //
839
840 // For emacs users
841 // Local Variables:
842 // mode: php
843 // tab-width: 8
844 // c-basic-offset: 4
845 // c-hanging-comment-ender-p: nil
846 // indent-tabs-mode: nil
847 // End:
848 ?>