2 rcs_id('$Id: config.php,v 1.100 2004-04-26 12:15:01 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 function isBrowserNetscape() {
70 return (browserDetect('Mozilla/') and
71 ! browserDetect('Gecko/') and
72 ! browserDetect('MSIE'));
75 function isBrowserNS3() {
76 return (isBrowserNetscape() and browserVersion() < 4.0);
82 * This is a version of the builtin setlocale() which is
83 * smart enough to try some alternatives...
85 * @param mixed $category
86 * @param string $locale
87 * @return string The new locale, or <code>false</code> if unable
88 * to set the requested locale.
91 function guessing_setlocale ($category, $locale) {
92 if ($res = setlocale($category, $locale))
94 $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
95 'de' => array('de_DE', 'de_DE', 'de_DE@euro',
96 'de_AT@euro', 'de_AT', 'German_Austria.1252', 'deutsch',
98 'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
99 'nl' => array('nl_NL', 'dutch'),
100 'fr' => array('fr_FR', 'français', 'french'),
101 'it' => array('it_IT'),
102 'sv' => array('sv_SE'),
103 'ja' => array('ja_JP','ja_JP.eucJP','japanese.euc'),
104 //'zh' => array('zh_TW', 'zh_CN')
106 if (strlen($locale) == 2)
109 list ($lang) = split('_', $locale);
110 if (!isset($alt[$lang]))
113 foreach ($alt[$lang] as $try) {
114 if ($res = setlocale($category, $try))
116 // Try with charset appended...
117 $try = $try . '.' . $GLOBALS['charset'];
118 if ($res = setlocale($category, $try))
120 foreach (array('@', ".", '_') as $sep) {
121 list ($try) = split($sep, $try);
122 if ($res = setlocale($category, $try))
128 // A standard locale name is typically of the form
129 // language[_territory][.codeset][@modifier], where language is
130 // an ISO 639 language code, territory is an ISO 3166 country code,
131 // and codeset is a character set or encoding identifier like
132 // ISO-8859-1 or UTF-8.
135 function update_locale($loc) {
136 require_once(dirname(__FILE__)."/FileFinder.php");
137 $newlocale = guessing_setlocale(LC_ALL, $loc);
139 //trigger_error(sprintf(_("Can't setlocale(LC_ALL,'%s')"), $loc), E_USER_NOTICE);
140 // => LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C
141 //$loc = setlocale(LC_CTYPE, ''); // pull locale from environment.
142 $newlocale = FileFinder::_get_lang();
143 list ($newlocale,) = split('_', $newlocale, 2);
144 //$GLOBALS['LANG'] = $loc;
148 //if (substr($newlocale,0,2) == $loc) // don't update with C or failing setlocale
149 $GLOBALS['LANG'] = $loc;
150 // Try to put new locale into environment (so any
151 // programs we run will get the right locale.)
153 // If PHP is in safe mode, this is not allowed,
155 @putenv("LC_ALL=$newlocale");
156 @putenv("LANG=$newlocale");
157 @putenv("LANGUAGE=$newlocale");
159 if (!function_exists ('bindtextdomain')) {
160 // Reinitialize translation array.
163 // do reinit to purge PHP's static cache
164 if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok','reinit')) ) {
169 // To get the POSIX character classes in the PCRE's (e.g.
170 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
171 // to set the locale, using setlocale().
173 // The problem is which locale to set? We would like to recognize all
174 // upper-case characters in the iso-8859-1 character set as upper-case
175 // characters --- not just the ones which are in the current $LANG.
177 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
178 // you setlocale() to anything but "C" it works fine. (I'm not sure
179 // whether this is how it's supposed to be, or whether this is a bug
182 // We don't currently use the locale setting for anything else, so for
183 // now, just set the locale to US English.
185 // FIXME: Not all environments may support en_US? We should probably
186 // have a list of locales to try.
187 if (setlocale(LC_CTYPE, 0) == 'C') {
188 $x = setlocale(LC_CTYPE, 'en_US.' . $GLOBALS['charset']);
190 $x = setlocale(LC_CTYPE, $newlocale);
196 /** string pcre_fix_posix_classes (string $regexp)
198 * Older version (pre 3.x?) of the PCRE library do not support
199 * POSIX named character classes (e.g. [[:alnum:]]).
201 * This is a helper function which can be used to convert a regexp
202 * which contains POSIX named character classes to one that doesn't.
204 * All instances of strings like '[:<class>:]' are replaced by the equivalent
205 * enumerated character class.
207 * Implementation Notes:
209 * Currently we use hard-coded values which are valid only for
210 * ISO-8859-1. Also, currently on the classes [:alpha:], [:alnum:],
211 * [:upper:] and [:lower:] are implemented. (The missing classes:
212 * [:blank:], [:cntrl:], [:digit:], [:graph:], [:print:], [:punct:],
213 * [:space:], and [:xdigit:] could easily be added if needed.)
215 * This is a hack. I tried to generate these classes automatically
216 * using ereg(), but discovered that in my PHP, at least, ereg() is
217 * slightly broken w.r.t. POSIX character classes. (It includes
218 * "\xaa" and "\xba" in [:alpha:].)
220 * So for now, this will do. --Jeff <dairiki@dairiki.org> 14 Mar, 2001
222 function pcre_fix_posix_classes ($regexp) {
224 // First check to see if our PCRE lib supports POSIX character
225 // classes. If it does, there's nothing to do.
226 if (preg_match('/[[:upper:]]/', 'Ä'))
229 static $classes = array(
230 'alnum' => "0-9A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
231 'alpha' => "A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\xff",
232 'upper' => "A-Z\xc0-\xd6\xd8-\xde",
233 'lower' => "a-z\xdf-\xf6\xf8-\xff"
235 if (!isset($charset))
236 $charset = CHARSET; // FIXME: get rid of constant. pref is dynamic and language specific
237 if (in_array($GLOBALS['LANG'],array('ja','zh')))
239 if (strtolower($charset) == 'utf-8') { // thanks to John McPherson
240 // until posix class names/pcre work with utf-8
241 // utf-8 non-ascii chars: most common (eg western) latin chars are 0xc380-0xc3bf
242 // we currently ignore other less common non-ascii characters
243 // (eg central/east european) latin chars are 0xc432-0xcdbf and 0xc580-0xc5be
244 // and indian/cyrillic/asian languages
246 // this replaces [[:lower:]] with utf-8 match (Latin only)
247 $regexp = preg_replace('/\[\[\:lower\:\]\]/','(?:[a-z]|\xc3[\x9f-\xbf]|\xc4[\x81\x83\x85\x87])',
249 // this replaces [[:upper:]] with utf-8 match (Latin only)
250 $regexp = preg_replace('/\[\[\:upper\:\]\]/','(?:[A-Z]|\xc3[\x80-\x9e]|\xc4[\x80\x82\x84\x86])',
254 $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.99 2004/04/21 14:04:24 zorloc
286 // 'Require lib/FileFinder.php' necessary to allow for call to FindLocalizedFile().
288 // Revision 1.98 2004/04/20 18:10:28 rurban
289 // config refactoring:
290 // FileFinder is needed for WikiFarm scripts calling index.php
291 // config run-time calls moved to lib/IniConfig.php:fix_configs()
292 // added PHPWIKI_DIR smart-detection code (Theme finder)
293 // moved FileFind to lib/FileFinder.php
294 // cleaned lib/config.php
296 // Revision 1.97 2004/04/18 01:11:52 rurban
297 // more numeric pagename fixes.
298 // fixed action=upload with merge conflict warnings.
299 // charset changed from constant to global (dynamic utf-8 switching)
307 // c-hanging-comment-ender-p: nil
308 // indent-tabs-mode: nil