]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/config.php
Various minor bug fixes and cleanups.
[SourceForge/phpwiki.git] / lib / config.php
1 <?php
2 rcs_id('$Id: config.php,v 1.32 2001-02-14 22:02:05 dairiki Exp $');
3 /*
4  * NOTE: the settings here should probably not need to be changed.
5  *
6  *
7  * (The user-configurable settings have been moved to index.php.)
8  */
9
10 // essential internal stuff
11
12 set_magic_quotes_runtime(0);
13
14 // Some constants.
15
16 // "\x80"-"\x9f" (and "\x00" - "\x1f") are non-printing control
17 // chars in iso-8859-*
18 // $FieldSeparator = "\263"; //this is a superscript 3 in ISO-8859-1.
19 $FieldSeparator = "\x81";
20
21
22 // constants for flags in $pagehash
23 define("FLAG_PAGE_LOCKED", 1);
24
25 //////////////////////////////////////////////////////////////////
26 //
27 // Set up localization
28 //
29
30 if (empty($LANG))
31    $LANG = "C";
32
33    
34 // Search PHP's include_path to find file or directory.
35 function FindFile ($file, $missing_okay = false)
36 {
37    // FIXME: This wont work for DOS filenames.
38    if (ereg('^/', $file))
39    {
40       // absolute path.
41       if (file_exists($file))
42          return $file;
43    }
44    else
45    {
46       $include_path = ini_get('include_path');
47       if (empty($include_path))
48          $include_path = '.';
49       // FIXME: This wont work for DOS filenames.
50       $path = explode(':', $include_path);
51       while (list($i, $dir) = each ($path))
52          if (file_exists("$dir/$file"))
53             return "$dir/$file";
54    }
55    
56    if (!$missing_okay)
57       ExitWiki("$file: file not found");
58    return false;
59 }
60
61 // Search PHP's include_path to find file or directory.
62 // Searches for "locale/$LANG/$file", then for "$file".
63 function FindLocalizedFile ($file, $missing_okay = false)
64 {
65    global $LANG;
66    
67    // FIXME: This wont work for DOS filenames.
68    if (!ereg('^/', $file))
69    {
70       if ( ($path = FindFile("locale/$LANG/$file", 'missing_is_okay')) )
71          return $path;
72    }
73    return FindFile($file, $missing_okay);
74 }
75
76 if (!function_exists ('gettext'))
77 {
78    $locale = array();
79
80    function gettext ($text) { 
81       global $locale;
82       if (!empty ($locale[$text]))
83          return $locale[$text];
84       return $text;
85    }
86
87    if ( ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok')) )
88    {
89       include($lcfile);
90    }
91 }
92 else
93 {
94    putenv ("LANG=$LANG");
95    bindtextdomain ("phpwiki", "./locale");
96    textdomain ("phpwiki");
97 }
98
99 //////////////////////////////////////////////////////////////////
100 // Autodetect URL settings:
101 //
102 if (!defined('SERVER_NAME')) define('SERVER_NAME', $SERVER_NAME);
103 if (!defined('SERVER_PORT')) define('SERVER_PORT', $SERVER_PORT);
104 if (!defined('SCRIPT_NAME')) define('SCRIPT_NAME', $SCRIPT_NAME);
105 if (!defined('DATA_PATH'))
106    define('DATA_PATH', dirname(SCRIPT_NAME));
107 if (!defined('USE_PATH_INFO'))
108 {
109    /*
110     * If SCRIPT_NAME does not look like php source file,
111     * or user cgi we assume that php is getting run by an
112     * action handler in /cgi-bin.  In this case,
113     * I think there is no way to get Apache to pass
114     * useful PATH_INFO to the php script (PATH_INFO
115     * is used to the the php interpreter where the
116     * php script is...)
117     */
118    if (php_sapi_name() == 'apache')
119       define('USE_PATH_INFO', true);
120    else
121       define('USE_PATH_INFO', ereg('\.(php3?|cgi)$', $SCRIPT_NAME));
122 }
123 if (!defined('VIRTUAL_PATH'))
124 {
125    if (USE_PATH_INFO and isset($REDIRECT_URL))
126    {
127       // FIXME: This is a hack, and won't work if the requested
128       // pagename has a slash in it.
129       define('VIRTUAL_PATH', dirname($REDIRECT_URL . 'x'));
130    }
131    else
132       define('VIRTUAL_PATH', SCRIPT_NAME);
133 }
134
135 if (SERVER_PORT && SERVER_PORT != 80)
136    define('SERVER_URL',
137           "http://" . SERVER_NAME . ':' . SERVER_PORT);
138 else
139    define('SERVER_URL',
140           "http://" . SERVER_NAME);
141
142 if (VIRTUAL_PATH != SCRIPT_NAME)
143 {
144    // Apache action handlers are used.
145    define('PATH_INFO_PREFIX', VIRTUAL_PATH . "/");
146 }
147 else
148    define("PATH_INFO_PREFIX", '/');
149
150
151 //////////////////////////////////////////////////////////////////
152 // Select database
153 //
154 if (empty($DBParams['dbtype']))
155 {
156    if ( floor(phpversion()) == 3) {
157       $DBParams['dbtype'] = 'dbm';
158    } else {
159       $DBParams['dbtype'] = 'dba';
160    }
161 }
162
163 switch ($DBParams['dbtype']) 
164 {
165    case 'dbm':
166       include 'lib/dbmlib.php';
167       break;
168    case 'dba':
169       include 'lib/dbalib.php';
170       break;
171    case 'mysql':
172       include 'lib/mysql.php';
173       break;
174    case 'pgsql':
175       include 'lib/pgsql.php';
176       break;
177    case 'msql':
178       include 'lib/msql.php';
179       break;
180    case 'file':
181       include "lib/db_filesystem.php";
182       break;
183    default:
184       ExitWiki($DBParams['dbtype'] . ": unknown DBTYPE");
185 }
186
187 // InterWiki linking -- wiki-style links to other wikis on the web
188 //
189 if (defined('INTERWIKI_MAP_FILE'))
190 {
191    include ('lib/interwiki.php');
192 }
193
194 // For emacs users
195 // Local Variables:
196 // mode: php
197 // c-file-style: "ellemtel"
198 // End:   
199 ?>