2 rcs_id('$Id: config.php,v 1.99 2004-04-21 14:04:24 zorloc 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 require_once 'lib/FileFinder.php';
11 if (!defined("LC_ALL")) {
12 // Backward compatibility (for PHP < 4.0.5)
14 define("LC_CTYPE", 2);
18 return @preg_match('/CGI/',$GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']);
22 // copy some $_ENV vars to $_SERVER for CGI compatibility. php does it automatically since when?
24 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) {
25 $GLOBALS['HTTP_SERVER_VARS'][$key] = &$GLOBALS['HTTP_ENV_VARS'][$key];
30 // essential internal stuff
31 set_magic_quotes_runtime(0);
34 * Browser Detection Functions
37 * NS/IE < 4.0 doesn't accept < ? xml version="1.0" ? >
38 * NS/IE < 4.0 cannot display PNG
39 * NS/IE < 4.0 cannot display all XHTML tags
40 * NS < 5.0 needs textarea wrap=virtual
41 * IE55 has problems with transparent PNG's
44 function browserAgent() {
45 static $HTTP_USER_AGENT = false;
46 if (!$HTTP_USER_AGENT)
47 $HTTP_USER_AGENT = @$GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'];
48 if (!$HTTP_USER_AGENT) // CGI
49 $HTTP_USER_AGENT = $GLOBALS['HTTP_ENV_VARS']['HTTP_USER_AGENT'];
50 return $HTTP_USER_AGENT;
52 function browserDetect($match) {
53 return strstr(browserAgent(), $match);
55 // returns a similar number for Netscape/Mozilla (gecko=5.0)/IE/Opera features.
56 function browserVersion() {
57 if (strstr(browserAgent(),"Mozilla/4.0 (compatible; MSIE"))
58 return (float) substr(browserAgent(),30);
60 return (float) substr(browserAgent(),8);
62 function isBrowserIE() {
63 return (browserDetect('Mozilla/') and
64 browserDetect('MSIE'));
66 // problem with transparent PNG's
67 function isBrowserIE55() {
68 return (isBrowserIE() and
69 browserVersion() > 5.1 and browserVersion() < 6.0);
71 function isBrowserNetscape() {
72 return (browserDetect('Mozilla/') and
73 ! browserDetect('Gecko/') and
74 ! browserDetect('MSIE'));
77 function isBrowserNS3() {
78 return (isBrowserNetscape() and browserVersion() < 4.0);
84 * This is a version of the builtin setlocale() which is
85 * smart enough to try some alternatives...
87 * @param mixed $category
88 * @param string $locale
89 * @return string The new locale, or <code>false</code> if unable
90 * to set the requested locale.
93 function guessing_setlocale ($category, $locale) {
94 if ($res = setlocale($category, $locale))
96 $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
97 'de' => array('de_DE', 'de_DE', 'de_DE@euro',
98 'de_AT@euro', 'de_AT', 'German_Austria.1252', 'deutsch',
100 'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
101 'nl' => array('nl_NL', 'dutch'),
102 'fr' => array('fr_FR', 'français', 'french'),
103 'it' => array('it_IT'),
104 'sv' => array('sv_SE'),
105 'ja' => array('ja_JP','ja_JP.eucJP','japanese.euc'),
106 //'zh' => array('zh_TW', 'zh_CN')
108 if (strlen($locale) == 2)
111 list ($lang) = split('_', $locale);
112 if (!isset($alt[$lang]))
115 foreach ($alt[$lang] as $try) {
116 if ($res = setlocale($category, $try))
118 // Try with charset appended...
119 $try = $try . '.' . $GLOBALS['charset'];
120 if ($res = setlocale($category, $try))
122 foreach (array('@', ".", '_') as $sep) {
123 list ($try) = split($sep, $try);
124 if ($res = setlocale($category, $try))
130 // A standard locale name is typically of the form
131 // language[_territory][.codeset][@modifier], where language is
132 // an ISO 639 language code, territory is an ISO 3166 country code,
133 // and codeset is a character set or encoding identifier like
134 // ISO-8859-1 or UTF-8.
137 function update_locale($loc) {
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 // First check to see if our PCRE lib supports POSIX character
226 // classes. If it does, there's nothing to do.
227 if (preg_match('/[[:upper:]]/', 'Ä'))
230 static $classes = array(
231 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
232 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
233 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
234 'lower' => "a-z\xdf-\xf6\xf8-\xff"
236 if (!isset($charset))
237 $charset = CHARSET; // FIXME: get rid of constant. pref is dynamic and language specific
238 if (in_array($GLOBALS['LANG'],array('ja','zh')))
240 if (strtolower($charset) == 'utf-8') { // thanks to John McPherson
241 // until posix class names/pcre work with utf-8
242 // utf-8 non-ascii chars: most common (eg western) latin chars are 0xc380-0xc3bf
243 // we currently ignore other less common non-ascii characters
244 // (eg central/east european) latin chars are 0xc432-0xcdbf and 0xc580-0xc5be
245 // and indian/cyrillic/asian languages
247 // this replaces [[:lower:]] with utf-8 match (Latin only)
248 $regexp = preg_replace('/\[\[\:lower\:\]\]/','(?:[a-z]|\xc3[\x9f-\xbf]|\xc4[\x81\x83\x85\x87])',
250 // this replaces [[:upper:]] with utf-8 match (Latin only)
251 $regexp = preg_replace('/\[\[\:upper\:\]\]/','(?:[A-Z]|\xc3[\x80-\x9e]|\xc4[\x80\x82\x84\x86])',
255 $keys = join('|', array_keys($classes));
257 return preg_replace("/\[:($keys):]/e", '$classes["\1"]', $regexp);
260 function deduce_script_name() {
261 $s = &$GLOBALS['HTTP_SERVER_VARS'];
262 $script = @$s['SCRIPT_NAME'];
263 if (empty($script) or $script[0] != '/') {
264 // Some places (e.g. Lycos) only supply a relative name in
265 // SCRIPT_NAME, but give what we really want in SCRIPT_URL.
266 if (!empty($s['SCRIPT_URL']))
267 $script = $s['SCRIPT_URL'];
272 function IsProbablyRedirectToIndex () {
273 // This might be a redirect to the DirectoryIndex,
274 // e.g. REQUEST_URI = /dir/ got redirected
275 // to SCRIPT_NAME = /dir/index.php
277 // In this case, the proper virtual path is still
278 // $SCRIPT_NAME, since pages appear at
279 // e.g. /dir/index.php/HomePage.
281 $requri = preg_quote($GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'], '%');
282 return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
285 // $Log: not supported by cvs2svn $
286 // Revision 1.98 2004/04/20 18:10:28 rurban
287 // config refactoring:
288 // FileFinder is needed for WikiFarm scripts calling index.php
289 // config run-time calls moved to lib/IniConfig.php:fix_configs()
290 // added PHPWIKI_DIR smart-detection code (Theme finder)
291 // moved FileFind to lib/FileFinder.php
292 // cleaned lib/config.php
294 // Revision 1.97 2004/04/18 01:11:52 rurban
295 // more numeric pagename fixes.
296 // fixed action=upload with merge conflict warnings.
297 // charset changed from constant to global (dynamic utf-8 switching)
305 // c-hanging-comment-ender-p: nil
306 // indent-tabs-mode: nil