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()
9 if (!defined("LC_ALL")) {
11 define("LC_CTYPE", 2);
14 define ('_DEBUG_VERBOSE', 1); // verbose msgs and add validator links on footer
15 define ('_DEBUG_PAGELINKS', 2); // list the extraced pagelinks at the top of each pages
16 define ('_DEBUG_PARSER', 4); // verbose parsing steps
17 define ('_DEBUG_TRACE', 8); // test php memory usage, prints php debug backtraces
18 define ('_DEBUG_INFO', 16);
19 define ('_DEBUG_APD', 32); // APD tracing/profiling
20 define ('_DEBUG_LOGIN', 64); // verbose login debug-msg (settings and reason for failure)
21 define ('_DEBUG_SQL', 128); // force check db, force optimize, print some debugging logs
22 define ('_DEBUG_REMOTE', 256); // remote debug into subrequests (xmlrpc, ajax, wikiwyg, ...)
23 // or test local SearchHighlight.
24 // internal links have persistent ?start_debug=1
28 return (substr(php_sapi_name(), 0, 3) == 'cgi' and
29 isset($GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']) and
30 @preg_match('/CGI/', $GLOBALS['HTTP_ENV_VARS']['GATEWAY_INTERFACE']));
34 * Browser Detection Functions
38 function browserAgent()
40 static $HTTP_USER_AGENT = false;
41 if ($HTTP_USER_AGENT !== false) return $HTTP_USER_AGENT;
42 if (!$HTTP_USER_AGENT)
43 $HTTP_USER_AGENT = @$GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'];
44 if (!$HTTP_USER_AGENT) // CGI
45 $HTTP_USER_AGENT = @$GLOBALS['HTTP_ENV_VARS']['HTTP_USER_AGENT'];
46 if (!$HTTP_USER_AGENT) // local CGI testing
47 $HTTP_USER_AGENT = 'none';
48 return $HTTP_USER_AGENT;
51 function browserDetect($match)
53 return (strpos(strtolower(browserAgent()), strtolower($match)) !== false);
56 // returns a similar number for Netscape/Mozilla (gecko=5.0)/IE/Opera features.
57 function browserVersion()
59 $agent = browserAgent();
60 if (strstr($agent, "Mozilla/4.0 (compatible; MSIE"))
61 return (float)substr($agent, 30);
62 elseif (strstr($agent, "Mozilla/5.0 (compatible; Konqueror/"))
63 return (float)substr($agent, 36);
64 elseif (strstr($agent, "AppleWebKit/"))
65 return (float)substr($agent, strpos($agent, "AppleWebKit/") + 12);
67 return (float)substr($agent, 8);
70 function isBrowserIE()
72 return (browserDetect('Mozilla/') and
73 browserDetect('MSIE'));
76 // must omit display alternate stylesheets: konqueror 3.1.4
77 // http://sourceforge.net/tracker/index.php?func=detail&aid=945154&group_id=6121&atid=106121
78 function isBrowserKonqueror($version = false)
81 return browserDetect('Konqueror/') and browserVersion() >= $version;
82 return browserDetect('Konqueror/');
85 // MacOSX Safari has certain limitations. Need detection and patches.
86 // * no <object>, only <embed>
87 function isBrowserSafari($version = false)
89 $found = browserDetect('Spoofer/');
90 $found = browserDetect('AppleWebKit/') || $found;
92 return $found and browserVersion() >= $version;
96 function isBrowserOpera($version = false)
99 return browserDetect('Opera/') and browserVersion() >= $version;
100 return browserDetect('Opera/');
104 * If $LANG is undefined:
105 * Smart client language detection, based on our supported languages
106 * HTTP_ACCEPT_LANGUAGE="de-at,en;q=0.5"
108 * We should really check additionally if the i18n HomePage version is defined.
109 * So must defer this to the request loop.
111 * @param array $languages
114 function guessing_lang($languages = array())
118 $languages = array("en", "de", "es", "fr", "it", "ja", "zh", "nl", "sv");
122 if (isset($GLOBALS['request'])) // in fixup-dynamic-config there's no request yet
123 $accept = $GLOBALS['request']->get('HTTP_ACCEPT_LANGUAGE');
124 elseif (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
125 $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
128 $lang_list = array();
129 $list = explode(",", $accept);
130 for ($i = 0; $i < count($list); $i++) {
131 $pos = strchr($list[$i], ";");
132 if ($pos === false) {
133 // No Q it is only a locale...
134 $lang_list[$list[$i]] = 100;
137 $q = explode(";", $list[$i]);
139 $q = explode("=", $q[1]);
140 $lang_list[$loc] = $q[1] * 100;
147 // compare with languages, ignoring sublang and charset
148 foreach ($lang_list as $lang => $q) {
149 if (in_array($lang, $languages))
151 // de_DE.iso8859-1@euro => de_DE.iso8859-1, de_DE, de
152 // de-DE => de-DE, de
153 foreach (array('@', '.', '_') as $sep) {
154 if (($tail = strchr($lang, $sep))) {
155 $lang_short = substr($lang, 0, -strlen($tail));
156 if (in_array($lang_short, $languages))
160 if ($pos = strpos($lang, "-") and in_array(substr($lang, 0, $pos), $languages))
161 return substr($lang, 0, $pos);
164 return $languages[0];
170 * This is a version of the builtin setlocale() which is
171 * smart enough to try some alternatives...
173 * @param mixed $category
174 * @param string $locale
175 * @return string The new locale, or <code>false</code> if unable
176 * to set the requested locale.
180 function guessing_setlocale($category, $locale)
182 $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'),
183 'de' => array('de_DE', 'de_DE', 'de_DE@euro',
184 'de_AT@euro', 'de_AT', 'German_Austria.1252', 'deutsch',
186 'es' => array('es_ES', 'es_MX', 'es_AR', 'spanish'),
187 'nl' => array('nl_NL', 'dutch'),
188 'fr' => array('fr_FR', 'français', 'french'),
189 'it' => array('it_IT'),
190 'sv' => array('sv_SE'),
191 'ja.utf-8' => array('ja_JP', 'ja_JP.utf-8', 'japanese'),
192 'ja.euc-jp' => array('ja_JP', 'ja_JP.eucJP', 'japanese.euc'),
193 'zh' => array('zh_TW', 'zh_CN'),
195 if (!$locale or $locale == 'C') {
196 // do the reverse: return the detected locale collapsed to our LANG
197 $locale = setlocale($category, '');
199 if (strstr($locale, '_'))
200 list ($lang) = explode('_', $locale);
203 if (strlen($lang) > 2) {
204 foreach ($alt as $try => $locs) {
205 if (in_array($locale, $locs) or in_array($lang, $locs)) {
206 //if (empty($GLOBALS['LANG'])) $GLOBALS['LANG'] = $try;
213 if (strlen($locale) == 2)
216 list ($lang) = explode('_', $locale);
217 if (!isset($alt[$lang]))
220 foreach ($alt[$lang] as $try) {
221 if ($res = setlocale($category, $try))
223 // Try with charset appended...
224 $try = $try . '.' . 'UTF-8';
225 if ($res = setlocale($category, $try))
227 foreach (array(".", '@', '_') as $sep) {
228 if ($i = strpos($try, $sep)) {
229 $try = substr($try, 0, $i);
230 if (($res = setlocale($category, $try)))
236 // A standard locale name is typically of the form
237 // language[_territory][.codeset][@modifier], where language is
238 // an ISO 639 language code, territory is an ISO 3166 country code,
239 // and codeset is a character set or encoding identifier like
240 // ISO-8859-1 or UTF-8.
244 function update_locale($loc)
246 if ($loc == 'C' or $loc == 'en') {
249 // $LANG or DEFAULT_LANGUAGE is too less information, at least on unix for
250 // setlocale(), for bindtextdomain() to succeed.
251 $setlocale = guessing_setlocale(LC_ALL, $loc); // [56ms]
252 if (!$setlocale) { // system has no locale for this language, so gettext might fail
253 $setlocale = FileFinder::_get_lang();
254 list ($setlocale,) = explode('_', $setlocale, 2);
255 $setlocale = guessing_setlocale(LC_ALL, $setlocale); // try again
256 if (!$setlocale) $setlocale = $loc;
258 // Try to put new locale into environment (so any
259 // programs we run will get the right locale.)
260 if (function_exists('bindtextdomain')) {
261 // If PHP is in safe mode, this is not allowed,
263 @putenv("LC_ALL=$setlocale");
264 @putenv("LANG=$loc");
265 @putenv("LANGUAGE=$loc");
268 // To get the POSIX character classes in the PCRE's (e.g.
269 // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have
270 // to set the locale, using setlocale().
272 // The problem is which locale to set? We would like to recognize all
273 // upper-case characters in the iso-8859-1 character set as upper-case
274 // characters --- not just the ones which are in the current $LANG.
276 // As it turns out, at least on my system (Linux/glibc-2.2) as long as
277 // you setlocale() to anything but "C" it works fine. (I'm not sure
278 // whether this is how it's supposed to be, or whether this is a bug
281 // We don't currently use the locale setting for anything else, so for
282 // now, just set the locale to US English.
284 // FIXME: Not all environments may support en_US? We should probably
285 // have a list of locales to try.
286 if (setlocale(LC_CTYPE, 0) == 'C') {
287 setlocale(LC_CTYPE, 'en_US.UTF-8');
289 setlocale(LC_CTYPE, $setlocale);
295 function deduce_script_name()
298 $script = @$s['SCRIPT_NAME'];
299 if (empty($script) or $script[0] != '/') {
300 // Some places (e.g. Lycos) only supply a relative name in
301 // SCRIPT_NAME, but give what we really want in SCRIPT_URL.
302 if (!empty($s['SCRIPT_URL']))
303 $script = $s['SCRIPT_URL'];
308 function IsProbablyRedirectToIndex()
310 // This might be a redirect to the DirectoryIndex,
311 // e.g. REQUEST_URI = /dir/?some_action got redirected
312 // to SCRIPT_NAME = /dir/index.php
314 // In this case, the proper virtual path is still
315 // $SCRIPT_NAME, since pages appear at
316 // e.g. /dir/index.php/HomePage.
318 $requri = preg_replace('/\?.*$/', '', $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']);
319 $requri = preg_quote($requri, '%');
320 return preg_match("%^${requri}[^/]*$%", $GLOBALS['HTTP_SERVER_VARS']['SCRIPT_NAME']);
323 function getUploadFilePath()
326 if (defined('UPLOAD_FILE_PATH')) {
327 if (string_ends_with(UPLOAD_FILE_PATH, "/")
328 or string_ends_with(UPLOAD_FILE_PATH, "\\")
330 return UPLOAD_FILE_PATH;
332 return UPLOAD_FILE_PATH . "/";
335 return defined('PHPWIKI_DIR')
336 ? PHPWIKI_DIR . "/uploads/"
337 : realpath(dirname(__FILE__) . "/../uploads/");
340 function getUploadDataPath()
342 if (defined('UPLOAD_DATA_PATH')) {
343 return string_ends_with(UPLOAD_DATA_PATH, "/")
344 ? UPLOAD_DATA_PATH : UPLOAD_DATA_PATH . "/";
346 return SERVER_URL . (string_ends_with(DATA_PATH, "/") ? '' : "/")
347 . DATA_PATH . '/uploads/';
354 // c-hanging-comment-ender-p: nil
355 // indent-tabs-mode: nil