2 rcs_id('$Id: config.php,v 1.103 2004-04-30 00:04:14 rurban Exp $');
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 have been moved to lib/IniConfig.php:fix_configs()
9 if (!defined("LC_ALL")) {
10 // Backward compatibility (for PHP < 4.0.5)
12 define("LC_CTYPE", 2);
16 return @preg_match('/CGI/',$GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']);
20 // copy some $_ENV vars to $_SERVER for CGI compatibility. php does it automatically since when?
22 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) {
23 $GLOBALS['HTTP_SERVER_VARS'][$key] = &$GLOBALS['HTTP_ENV_VARS'][$key];
28 // essential internal stuff
29 set_magic_quotes_runtime(0);
32 * Browser Detection Functions
35 * NS/IE < 4.0 doesn't accept < ? xml version="1.0" ? >
36 * NS/IE < 4.0 cannot display PNG
37 * NS/IE < 4.0 cannot display all XHTML tags
38 * NS < 5.0 needs textarea wrap=virtual
39 * IE55 has problems with transparent PNG's
42 function browserAgent() {
43 static $HTTP_USER_AGENT = false;
44 if (!$HTTP_USER_AGENT)
45 $HTTP_USER_AGENT = @$GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'];
46 if (!$HTTP_USER_AGENT) // CGI
47 $HTTP_USER_AGENT = $GLOBALS['HTTP_ENV_VARS']['HTTP_USER_AGENT'];
48 return $HTTP_USER_AGENT;
50 function browserDetect($match) {
51 return strstr(browserAgent(), $match);
53 // returns a similar number for Netscape/Mozilla (gecko=5.0)/IE/Opera features.
54 function browserVersion() {
55 if (strstr(browserAgent(),"Mozilla/4.0 (compatible; MSIE"))
56 return (float) substr(browserAgent(),30);
58 return (float) substr(browserAgent(),8);
60 function isBrowserIE() {
61 return (browserDetect('Mozilla/') and
62 browserDetect('MSIE'));
64 // problem with transparent PNG's
65 function isBrowserIE55() {
66 return (isBrowserIE() and
67 browserVersion() > 5.1 and browserVersion() < 6.0);
69 // old Netscape prior to Mozilla
70 function isBrowserNetscape() {
71 return (browserDetect('Mozilla/') and
72 ! browserDetect('Gecko/') and
73 ! browserDetect('MSIE'));
76 function isBrowserNS3() {
77 return (isBrowserNetscape() and browserVersion() < 4.0);
83 * This is a version of the builtin setlocale() which is
84 * smart enough to try some alternatives...
86 * @param mixed $category
87 * @param string $locale
88 * @return string The new locale, or <code>false</code> if unable
89 * to set the requested locale.
92 function guessing_setlocale ($category, $locale) {
93 if ($res = setlocale($category, $locale))
95 $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
96 'de' => array('de_DE', 'de_DE', 'de_DE@euro',
97 'de_AT@euro', 'de_AT', 'German_Austria.1252', 'deutsch',
99 'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
100 'nl' => array('nl_NL', 'dutch'),
101 'fr' => array('fr_FR', 'français', 'french'),
102 'it' => array('it_IT'),
103 'sv' => array('sv_SE'),
104 'ja' => array('ja_JP','ja_JP.eucJP','japanese.euc'),
105 'zh' => array('zh_TW', 'zh_CN'),
107 if (strlen($locale) == 2)
110 list ($lang) = split('_', $locale);
111 if (!isset($alt[$lang]))
114 foreach ($alt[$lang] as $try) {
115 if ($res = setlocale($category, $try))
117 // Try with charset appended...
118 $try = $try . '.' . $GLOBALS['charset'];
119 if ($res = setlocale($category, $try))
121 foreach (array('@', ".", '_') as $sep) {
122 list ($try) = split($sep, $try);
123 if ($res = setlocale($category, $try))
129 // A standard locale name is typically of the form
130 // language[_territory][.codeset][@modifier], where language is
131 // an ISO 639 language code, territory is an ISO 3166 country code,
132 // and codeset is a character set or encoding identifier like
133 // ISO-8859-1 or UTF-8.
136 function update_locale($loc) {
137 require_once(dirname(__FILE__)."/FileFinder.php");
138 $newlocale = guessing_setlocale(LC_ALL, $loc);
140 //trigger_error(sprintf(_("Can't setlocale(LC_ALL,'%s')"), $loc), E_USER_NOTICE);
141 // => LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C
142 //$loc = setlocale(LC_CTYPE, ''); // pull locale from environment.
143 $newlocale = FileFinder::_get_lang();
144 list ($newlocale,) = split('_', $newlocale, 2);
145 //$GLOBALS['LANG'] = $loc;
149 //if (substr($newlocale,0,2) == $loc) // don't update with C or failing setlocale
150 $GLOBALS['LANG'] = $loc;
151 // Try to put new locale into environment (so any
152 // programs we run will get the right locale.)
154 // If PHP is in safe mode, this is not allowed,
156 @putenv("LC_ALL=$newlocale");
157 @putenv("LANG=$newlocale");
158 @putenv("LANGUAGE=$newlocale");
160 if (!function_exists ('bindtextdomain')) {
161 // Reinitialize translation array.
164 // do reinit to purge PHP's static cache
165 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok','reinit')) ) {
170 // To get the POSIX character classes in the PCRE's (e.g.
171 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
172 // to set the locale, using setlocale().
174 // The problem is which locale to set? We would like to recognize all
175 // upper-case characters in the iso-8859-1 character set as upper-case
176 // characters --- not just the ones which are in the current $LANG.
178 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
179 // you setlocale() to anything but "C" it works fine. (I'm not sure
180 // whether this is how it's supposed to be, or whether this is a bug
183 // We don't currently use the locale setting for anything else, so for
184 // now, just set the locale to US English.
186 // FIXME: Not all environments may support en_US? We should probably
187 // have a list of locales to try.
188 if (setlocale(LC_CTYPE, 0) == 'C') {
189 $x = setlocale(LC_CTYPE, 'en_US.' . $GLOBALS['charset']);
191 $x = setlocale(LC_CTYPE, $newlocale);
197 /** string pcre_fix_posix_classes (string $regexp)
199 * Older version (pre 3.x?) of the PCRE library do not support
200 * POSIX named character classes (e.g. [[:alnum:]]).
202 * This is a helper function which can be used to convert a regexp
203 * which contains POSIX named character classes to one that doesn't.
205 * All instances of strings like '[:<class>:]' are replaced by the equivalent
206 * enumerated character class.
208 * Implementation Notes:
210 * Currently we use hard-coded values which are valid only for
211 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
212 * [:upper:] and [:lower:] are implemented. (The missing classes:
213 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
214 * [:space:], and [:xdigit:] could easily be added if needed.)
216 * This is a hack. I tried to generate these classes automatically
217 * using ereg(), but discovered that in my PHP, at least, ereg() is
218 * slightly broken w.r.t. POSIX character classes. (It includes
219 * "\xaa" and "\xba" in [:alpha:].)
221 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
223 function pcre_fix_posix_classes ($regexp) {
225 if (!isset($charset))
226 $charset = CHARSET; // get rid of constant. pref is dynamic and language specific
227 if (in_array($GLOBALS['LANG'],array('ja','zh')))
229 if (strtolower($charset) == 'utf-8') { // thanks to John McPherson
230 // until posix class names/pcre work with utf-8
231 if (preg_match('/[[:upper:]]/', '\xc4\x80'))
233 // utf-8 non-ascii chars: most common (eg western) latin chars are 0xc380-0xc3bf
234 // we currently ignore other less common non-ascii characters
235 // (eg central/east european) latin chars are 0xc432-0xcdbf and 0xc580-0xc5be
236 // and indian/cyrillic/asian languages
238 // this replaces [[:lower:]] with utf-8 match (Latin only)
239 $regexp = preg_replace('/\[\[\:lower\:\]\]/','(?:[a-z]|\xc3[\x9f-\xbf]|\xc4[\x81\x83\x85\x87])',
241 // this replaces [[:upper:]] with utf-8 match (Latin only)
242 $regexp = preg_replace('/\[\[\:upper\:\]\]/','(?:[A-Z]|\xc3[\x80-\x9e]|\xc4[\x80\x82\x84\x86])',
244 } elseif (preg_match('/[[:upper:]]/', 'Ä')) {
245 // First check to see if our PCRE lib supports POSIX character
246 // classes. If it does, there's nothing to do.
249 static $classes = array(
250 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
251 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
252 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
253 'lower' => "a-z\xdf-\xf6\xf8-\xff"
255 $keys = join('|', array_keys($classes));
256 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
259 function deduce_script_name() {
260 $s = &$GLOBALS['HTTP_SERVER_VARS'];
261 $script = @$s['SCRIPT_NAME'];
262 if (empty($script) or $script[0] != '/') {
263 // Some places (e.g. Lycos) only supply a relative name in
264 // SCRIPT_NAME, but give what we really want in SCRIPT_URL.
265 if (!empty($s['SCRIPT_URL']))
266 $script = $s['SCRIPT_URL'];
271 function IsProbablyRedirectToIndex () {
272 // This might be a redirect to the DirectoryIndex,
273 // e.g. REQUEST_URI = /dir/ got redirected
274 // to SCRIPT_NAME = /dir/index.php
276 // In this case, the proper virtual path is still
277 // $SCRIPT_NAME, since pages appear at
278 // e.g. /dir/index.php/HomePage.
280 $requri = preg_quote($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'], '%');
281 return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
284 // $Log: not supported by cvs2svn $
285 // Revision 1.102 2004/04/29 23:25:12 rurban
286 // re-ordered locale init (as in 1.3.9)
287 // fixed loadfile with subpages, and merge/restore anyway
288 // (sf.net bug #844188)
290 // Revision 1.101 2004/04/26 13:22:32 rurban
291 // calculate bool old or dynamic constants later
293 // Revision 1.100 2004/04/26 12:15:01 rurban
294 // check default config values
296 // Revision 1.99 2004/04/21 14:04:24 zorloc
297 // 'Require lib/FileFinder.php' necessary to allow for call to FindLocalizedFile().
299 // Revision 1.98 2004/04/20 18:10:28 rurban
300 // config refactoring:
301 // FileFinder is needed for WikiFarm scripts calling index.php
302 // config run-time calls moved to lib/IniConfig.php:fix_configs()
303 // added PHPWIKI_DIR smart-detection code (Theme finder)
304 // moved FileFind to lib/FileFinder.php
305 // cleaned lib/config.php
307 // Revision 1.97 2004/04/18 01:11:52 rurban
308 // more numeric pagename fixes.
309 // fixed action=upload with merge conflict warnings.
310 // charset changed from constant to global (dynamic utf-8 switching)
318 // c-hanging-comment-ender-p: nil
319 // indent-tabs-mode: nil