Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
functions_install.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 /**
015 * @ignore
016 */
017 if (!defined('IN_PHPBB'))
018 {
019 exit;
020 }
021
022 /**
023 * Returns an array of available DBMS with some data, if a DBMS is specified it will only
024 * return data for that DBMS and will load its extension if necessary.
025 */
026 function get_available_dbms($dbms = false, $return_unavailable = false, $only_20x_options = false)
027 {
028 global $lang;
029 $available_dbms = array(
030 // Note: php 5.5 alpha 2 deprecated mysql.
031 // Keep mysqli before mysql in this list.
032 'mysqli' => array(
033 'LABEL' => 'MySQL with MySQLi Extension',
034 'SCHEMA' => 'mysql_41',
035 'MODULE' => 'mysqli',
036 'DELIM' => ';',
037 'DRIVER' => 'phpbb\db\driver\mysqli',
038 'AVAILABLE' => true,
039 '2.0.x' => true,
040 ),
041 'mysql' => array(
042 'LABEL' => 'MySQL',
043 'SCHEMA' => 'mysql',
044 'MODULE' => 'mysql',
045 'DELIM' => ';',
046 'DRIVER' => 'phpbb\db\driver\mysql',
047 'AVAILABLE' => true,
048 '2.0.x' => true,
049 ),
050 'mssql' => array(
051 'LABEL' => 'MS SQL Server 2000+',
052 'SCHEMA' => 'mssql',
053 'MODULE' => 'mssql',
054 'DELIM' => 'GO',
055 'DRIVER' => 'phpbb\db\driver\mssql',
056 'AVAILABLE' => true,
057 '2.0.x' => true,
058 ),
059 'mssql_odbc'=> array(
060 'LABEL' => 'MS SQL Server [ ODBC ]',
061 'SCHEMA' => 'mssql',
062 'MODULE' => 'odbc',
063 'DELIM' => 'GO',
064 'DRIVER' => 'phpbb\db\driver\mssql_odbc',
065 'AVAILABLE' => true,
066 '2.0.x' => true,
067 ),
068 'mssqlnative' => array(
069 'LABEL' => 'MS SQL Server 2005+ [ Native ]',
070 'SCHEMA' => 'mssql',
071 'MODULE' => 'sqlsrv',
072 'DELIM' => 'GO',
073 'DRIVER' => 'phpbb\db\driver\mssqlnative',
074 'AVAILABLE' => true,
075 '2.0.x' => false,
076 ),
077 'oracle' => array(
078 'LABEL' => 'Oracle',
079 'SCHEMA' => 'oracle',
080 'MODULE' => 'oci8',
081 'DELIM' => '/',
082 'DRIVER' => 'phpbb\db\driver\oracle',
083 'AVAILABLE' => true,
084 '2.0.x' => false,
085 ),
086 'postgres' => array(
087 'LABEL' => 'PostgreSQL 8.3+',
088 'SCHEMA' => 'postgres',
089 'MODULE' => 'pgsql',
090 'DELIM' => ';',
091 'DRIVER' => 'phpbb\db\driver\postgres',
092 'AVAILABLE' => true,
093 '2.0.x' => true,
094 ),
095 'sqlite' => array(
096 'LABEL' => 'SQLite',
097 'SCHEMA' => 'sqlite',
098 'MODULE' => 'sqlite',
099 'DELIM' => ';',
100 'DRIVER' => 'phpbb\db\driver\sqlite',
101 'AVAILABLE' => true,
102 '2.0.x' => false,
103 ),
104 'sqlite3' => array(
105 'LABEL' => 'SQLite3',
106 'SCHEMA' => 'sqlite',
107 'MODULE' => 'sqlite3',
108 'DELIM' => ';',
109 'DRIVER' => 'phpbb\db\driver\sqlite3',
110 'AVAILABLE' => true,
111 '2.0.x' => false,
112 ),
113 );
114
115 if ($dbms)
116 {
117 if (isset($available_dbms[$dbms]))
118 {
119 $available_dbms = array($dbms => $available_dbms[$dbms]);
120 }
121 else
122 {
123 return array();
124 }
125 }
126
127 // now perform some checks whether they are really available
128 foreach ($available_dbms as $db_name => $db_ary)
129 {
130 if ($only_20x_options && !$db_ary['2.0.x'])
131 {
132 if ($return_unavailable)
133 {
134 $available_dbms[$db_name]['AVAILABLE'] = false;
135 }
136 else
137 {
138 unset($available_dbms[$db_name]);
139 }
140 continue;
141 }
142
143 $dll = $db_ary['MODULE'];
144
145 if (!@extension_loaded($dll))
146 {
147 if ($return_unavailable)
148 {
149 $available_dbms[$db_name]['AVAILABLE'] = false;
150 }
151 else
152 {
153 unset($available_dbms[$db_name]);
154 }
155 continue;
156 }
157 $any_db_support = true;
158 }
159
160 if ($return_unavailable)
161 {
162 $available_dbms['ANY_DB_SUPPORT'] = $any_db_support;
163 }
164 return $available_dbms;
165 }
166
167 /**
168 * Generate the drop down of available database options
169 */
170 function dbms_select($default = '', $only_20x_options = false)
171 {
172 global $lang;
173
174 $available_dbms = get_available_dbms(false, false, $only_20x_options);
175 $dbms_options = '';
176 foreach ($available_dbms as $dbms_name => $details)
177 {
178 $selected = ($dbms_name == $default) ? ' selected="selected"' : '';
179 $dbms_options .= '<option value="' . $dbms_name . '"' . $selected .'>' . $lang['DLL_' . strtoupper($dbms_name)] . '</option>';
180 }
181 return $dbms_options;
182 }
183
184 /**
185 * Get tables of a database
186 *
187 * @deprecated
188 */
189 function get_tables(&$db)
190 {
191 $db_tools = new \phpbb\db\tools($db);
192
193 return $db_tools->sql_list_tables();
194 }
195
196 /**
197 * Used to test whether we are able to connect to the database the user has specified
198 * and identify any problems (eg there are already tables with the names we want to use
199 * @param array $dbms should be of the format of an element of the array returned by {@link get_available_dbms get_available_dbms()}
200 * necessary extensions should be loaded already
201 */
202 function connect_check_db($error_connect, &$error, $dbms_details, $table_prefix, $dbhost, $dbuser, $dbpasswd, $dbname, $dbport, $prefix_may_exist = false, $load_dbal = true, $unicode_check = true)
203 {
204 global $phpbb_root_path, $phpEx, $config, $lang;
205
206 $dbms = $dbms_details['DRIVER'];
207
208 // Instantiate it and set return on error true
209 $db = new $dbms();
210 $db->sql_return_on_error(true);
211
212 // Check that we actually have a database name before going any further.....
213 if ($dbms_details['DRIVER'] != 'phpbb\db\driver\sqlite' && $dbms_details['DRIVER'] != 'phpbb\db\driver\sqlite3' && $dbms_details['DRIVER'] != 'phpbb\db\driver\oracle' && $dbname === '')
214 {
215 $error[] = $lang['INST_ERR_DB_NO_NAME'];
216 return false;
217 }
218
219 // Make sure we don't have a daft user who thinks having the SQLite database in the forum directory is a good idea
220 if (($dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite' || $dbms_details['DRIVER'] == 'phpbb\db\driver\sqlite3') && stripos(phpbb_realpath($dbhost), phpbb_realpath('../')) === 0)
221 {
222 $error[] = $lang['INST_ERR_DB_FORUM_PATH'];
223 return false;
224 }
225
226 // Check the prefix length to ensure that index names are not too long and does not contain invalid characters
227 switch ($dbms_details['DRIVER'])
228 {
229 case 'phpbb\db\driver\mysql':
230 case 'phpbb\db\driver\mysqli':
231 if (strspn($table_prefix, '-./\\') !== 0)
232 {
233 $error[] = $lang['INST_ERR_PREFIX_INVALID'];
234 return false;
235 }
236
237 // no break;
238
239 case 'phpbb\db\driver\postgres':
240 $prefix_length = 36;
241 break;
242
243 case 'phpbb\db\driver\mssql':
244 case 'phpbb\db\driver\mssql_odbc':
245 case 'phpbb\db\driver\mssqlnative':
246 $prefix_length = 90;
247 break;
248
249 case 'phpbb\db\driver\sqlite':
250 case 'phpbb\db\driver\sqlite3':
251 $prefix_length = 200;
252 break;
253
254 case 'phpbb\db\driver\oracle':
255 $prefix_length = 6;
256 break;
257 }
258
259 if (strlen($table_prefix) > $prefix_length)
260 {
261 $error[] = sprintf($lang['INST_ERR_PREFIX_TOO_LONG'], $prefix_length);
262 return false;
263 }
264
265 // Try and connect ...
266 if (is_array($db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true)))
267 {
268 $db_error = $db->sql_error();
269 $error[] = $lang['INST_ERR_DB_CONNECT'] . '<br />' . (($db_error['message']) ? utf8_convert_message($db_error['message']) : $lang['INST_ERR_DB_NO_ERROR']);
270 }
271 else
272 {
273 // Likely matches for an existing phpBB installation
274 if (!$prefix_may_exist)
275 {
276 $temp_prefix = strtolower($table_prefix);
277 $table_ary = array($temp_prefix . 'attachments', $temp_prefix . 'config', $temp_prefix . 'sessions', $temp_prefix . 'topics', $temp_prefix . 'users');
278
279 $tables = get_tables($db);
280 $tables = array_map('strtolower', $tables);
281 $table_intersect = array_intersect($tables, $table_ary);
282
283 if (sizeof($table_intersect))
284 {
285 $error[] = $lang['INST_ERR_PREFIX'];
286 }
287 }
288
289 // Make sure that the user has selected a sensible DBAL for the DBMS actually installed
290 switch ($dbms_details['DRIVER'])
291 {
292 case 'phpbb\db\driver\mysqli':
293 if (version_compare(mysqli_get_server_info($db->get_db_connect_id()), '4.1.3', '<'))
294 {
295 $error[] = $lang['INST_ERR_DB_NO_MYSQLI'];
296 }
297 break;
298
299 case 'phpbb\db\driver\sqlite':
300 if (version_compare(sqlite_libversion(), '2.8.2', '<'))
301 {
302 $error[] = $lang['INST_ERR_DB_NO_SQLITE'];
303 }
304 break;
305
306 case 'phpbb\db\driver\sqlite3':
307 $version = \SQLite3::version();
308 if (version_compare($version['versionString'], '3.6.15', '<'))
309 {
310 $error[] = $lang['INST_ERR_DB_NO_SQLITE3'];
311 }
312 break;
313
314 case 'phpbb\db\driver\oracle':
315 if ($unicode_check)
316 {
317 $sql = "SELECT *
318 FROM NLS_DATABASE_PARAMETERS
319 WHERE PARAMETER = 'NLS_RDBMS_VERSION'
320 OR PARAMETER = 'NLS_CHARACTERSET'";
321 $result = $db->sql_query($sql);
322
323 while ($row = $db->sql_fetchrow($result))
324 {
325 $stats[$row['parameter']] = $row['value'];
326 }
327 $db->sql_freeresult($result);
328
329 if (version_compare($stats['NLS_RDBMS_VERSION'], '9.2', '<') && $stats['NLS_CHARACTERSET'] !== 'UTF8')
330 {
331 $error[] = $lang['INST_ERR_DB_NO_ORACLE'];
332 }
333 }
334 break;
335
336 case 'phpbb\db\driver\postgres':
337 if ($unicode_check)
338 {
339 $sql = "SHOW server_encoding;";
340 $result = $db->sql_query($sql);
341 $row = $db->sql_fetchrow($result);
342 $db->sql_freeresult($result);
343
344 if ($row['server_encoding'] !== 'UNICODE' && $row['server_encoding'] !== 'UTF8')
345 {
346 $error[] = $lang['INST_ERR_DB_NO_POSTGRES'];
347 }
348 }
349 break;
350 }
351
352 }
353
354 if ($error_connect && (!isset($error) || !sizeof($error)))
355 {
356 return true;
357 }
358 return false;
359 }
360
361 /**
362 * Removes "/* style" as well as "# style" comments from $input.
363 *
364 * @param string $input Input string
365 *
366 * @return string Input string with comments removed
367 */
368 function phpbb_remove_comments($input)
369 {
370 // Remove /* */ comments (http://ostermiller.org/findcomment.html)
371 $input = preg_replace('#/\*(.|[\r\n])*?\*/#', "\n", $input);
372
373 // Remove # style comments
374 $input = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $input));
375
376 return $input;
377 }
378
379 /**
380 * split_sql_file will split an uploaded sql file into single sql statements.
381 * Note: expects trim() to have already been run on $sql.
382 */
383 function split_sql_file($sql, $delimiter)
384 {
385 $sql = str_replace("\r" , '', $sql);
386 $data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
387
388 $data = array_map('trim', $data);
389
390 // The empty case
391 $end_data = end($data);
392
393 if (empty($end_data))
394 {
395 unset($data[key($data)]);
396 }
397
398 return $data;
399 }
400
401 /**
402 * For replacing {L_*} strings with preg_replace_callback
403 */
404 function adjust_language_keys_callback($matches)
405 {
406 if (!empty($matches[1]))
407 {
408 global $lang, $db;
409
410 return (!empty($lang[$matches[1]])) ? $db->sql_escape($lang[$matches[1]]) : $db->sql_escape($matches[1]);
411 }
412 }
413
414 /**
415 * Creates the output to be stored in a phpBB config.php file
416 *
417 * @param array $data Array containing the database connection information
418 * @param string $dbms The name of the DBAL class to use
419 * @param bool $debug If the debug constants should be enabled by default or not
420 * @param bool $debug_container If the container should be compiled on
421 * every page load or not
422 * @param bool $debug_test If the DEBUG_TEST constant should be added
423 * NOTE: Only for use within the testing framework
424 *
425 * @return string The output to write to the file
426 */
427 function phpbb_create_config_file_data($data, $dbms, $debug = false, $debug_container = false, $debug_test = false)
428 {
429 $config_data = "<?php\n";
430 $config_data .= "// phpBB 3.1.x auto-generated configuration file\n// Do not change anything in this file!\n";
431
432 $config_data_array = array(
433 'dbms' => $dbms,
434 'dbhost' => $data['dbhost'],
435 'dbport' => $data['dbport'],
436 'dbname' => $data['dbname'],
437 'dbuser' => $data['dbuser'],
438 'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']),
439 'table_prefix' => $data['table_prefix'],
440
441 'phpbb_adm_relative_path' => 'adm/',
442
443 'acm_type' => 'phpbb\cache\driver\file',
444 );
445
446 foreach ($config_data_array as $key => $value)
447 {
448 $config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n";
449 }
450
451 $config_data .= "\n@define('PHPBB_INSTALLED', true);\n";
452 $config_data .= "// @define('PHPBB_DISPLAY_LOAD_TIME', true);\n";
453
454 if ($debug)
455 {
456 $config_data .= "@define('DEBUG', true);\n";
457 }
458 else
459 {
460 $config_data .= "// @define('DEBUG', true);\n";
461 }
462
463 if ($debug_container)
464 {
465 $config_data .= "@define('DEBUG_CONTAINER', true);\n";
466 }
467 else
468 {
469 $config_data .= "// @define('DEBUG_CONTAINER', true);\n";
470 }
471
472 if ($debug_test)
473 {
474 $config_data .= "@define('DEBUG_TEST', true);\n";
475 }
476
477 return $config_data;
478 }
479
480 /**
481 * Check whether a file should be ignored on update
482 *
483 * We ignore new files in some circumstances:
484 * 1. The file is a language file, but the language is not installed
485 * 2. The file is a style file, but the style is not installed
486 * 3. The file is a style language file, but the language is not installed
487 *
488 * @param string $phpbb_root_path phpBB root path
489 * @param string $file File including path from phpbb root
490 * @return bool Should we ignore the new file or add it to the board?
491 */
492 function phpbb_ignore_new_file_on_update($phpbb_root_path, $file)
493 {
494 $ignore_new_file = false;
495
496 // We ignore new files in some circumstances:
497 // 1. The file is a language file, but the language is not installed
498 if (!$ignore_new_file && strpos($file, 'language/') === 0)
499 {
500 list($language_dir, $language_iso) = explode('/', $file);
501 $ignore_new_file = !file_exists($phpbb_root_path . $language_dir . '/' . $language_iso);
502 }
503
504 // 2. The file is a style file, but the style is not installed
505 if (!$ignore_new_file && strpos($file, 'styles/') === 0)
506 {
507 list($styles_dir, $style_name) = explode('/', $file);
508 $ignore_new_file = !file_exists($phpbb_root_path . $styles_dir . '/' . $style_name);
509 }
510
511 // 3. The file is a style language file, but the language is not installed
512 if (!$ignore_new_file && strpos($file, 'styles/') === 0)
513 {
514 $dirs = explode('/', $file);
515 if (sizeof($dirs) >= 5)
516 {
517 list($styles_dir, $style_name, $template_component, $language_iso) = explode('/', $file);
518 if ($template_component == 'theme' && $language_iso !== 'images')
519 {
520 $ignore_new_file = !file_exists($phpbb_root_path . 'language/' . $language_iso);
521 }
522 }
523 }
524
525 return $ignore_new_file;
526 }
527
528 /**
529 * Check whether phpBB is installed.
530 *
531 * @param string $phpbb_root_path Path to the phpBB board root.
532 * @param string $php_ext PHP file extension.
533 *
534 * @return bool Returns true if phpBB is installed.
535 */
536 function phpbb_check_installation_exists($phpbb_root_path, $php_ext)
537 {
538 // Try opening config file
539 if (file_exists($phpbb_root_path . 'config.' . $php_ext))
540 {
541 include($phpbb_root_path . 'config.' . $php_ext);
542 }
543
544 return defined('PHPBB_INSTALLED');
545 }
546