6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 define('IN_PHPBB', true);
14 define('IN_INSTALL', true);
16 $phpbb_root_path = './../';
17 $phpEx = substr(strrchr(__FILE__
, '.'), 1);
19 // Report all errors, except notices
20 error_reporting(E_ALL ^ E_NOTICE
);
22 // @todo Review this test and see if we can find out what it is which prevents PHP 4.2.x from even displaying the page with requirements on it
23 if (version_compare(phpversion(), '4.3.0') < 0)
25 die('You are running an unsupported PHP version. Please upgrade to PHP 4.3.3 or higher before trying to install phpBB 3.0');
29 * Remove variables created by register_globals from the global scope
30 * Thanks to Matt Kavanagh
32 function deregister_globals()
45 'phpbb_root_path' => true
48 // Not only will array_merge and array_keys give a warning if
49 // a parameter is not an array, array_merge will actually fail.
50 // So we check if _SESSION has been initialised.
51 if (!isset($_SESSION) ||
!is_array($_SESSION))
56 // Merge all into one extremely huge array; unset
63 array_keys($_SESSION),
68 foreach ($input as $varname)
70 if (isset($not_unset[$varname]))
72 // Hacking attempt. No point in continuing.
76 unset($GLOBALS[$varname]);
82 // If we are on PHP >= 6.0.0 we do not need some code
83 if (version_compare(phpversion(), '6.0.0-dev', '>='))
88 define('STRIP', false);
92 set_magic_quotes_runtime(0);
94 // Be paranoid with passed vars
95 if (@ini_get
('register_globals') == '1' ||
strtolower(@ini_get
('register_globals')) == 'on')
100 define('STRIP', (get_magic_quotes_gpc()) ?
true : false);
103 @set_time_limit
(120);
105 // Include essential scripts
106 require($phpbb_root_path . 'includes/functions.' . $phpEx);
107 include($phpbb_root_path . 'includes/auth.' . $phpEx);
108 include($phpbb_root_path . 'includes/session.' . $phpEx);
109 include($phpbb_root_path . 'includes/template.' . $phpEx);
110 include($phpbb_root_path . 'includes/acm/acm_file.' . $phpEx);
111 include($phpbb_root_path . 'includes/cache.' . $phpEx);
112 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
114 // Try and load an appropriate language if required
115 $language = request_var('language', '');
117 if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !$language)
119 $accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
120 foreach ($accept_lang_ary as $accept_lang)
122 // Set correct format ... guess full xx_YY form
123 $accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2));
125 if (file_exists($phpbb_root_path . 'language/' . $accept_lang))
127 $language = $accept_lang;
132 // No match on xx_YY so try xx
133 $accept_lang = substr($accept_lang, 0, 2);
134 if (file_exists($phpbb_root_path . 'language/' . $accept_lang))
136 $language = $accept_lang;
143 // No appropriate language found ... so let's use the first one in the language
144 // dir, this may or may not be English
147 $dir = @opendir
($phpbb_root_path . 'language');
148 while (($file = readdir($dir)) !== false)
150 $path = $phpbb_root_path . 'language/' . $file;
152 if (!is_file($path) && !is_link($path) && file_exists($path . '/iso.txt'))
160 // And finally, load the relevant language files
161 include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
162 include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
163 include($phpbb_root_path . 'language/' . $language . '/acp/board.' . $phpEx);
164 include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
165 include($phpbb_root_path . 'language/' . $language . '/posting.' . $phpEx);
167 $mode = request_var('mode', 'overview');
168 $sub = request_var('sub', '');
170 // Set PHP error handler to ours
171 set_error_handler('msg_handler');
175 $cache = new cache();
176 $template = new template();
178 $template->set_custom_template('../adm/style', 'admin');
179 $template->assign_var('T_TEMPLATE_PATH', '../adm/style');
181 $install = new module();
183 $install->create('install', "index.$phpEx", $mode, $sub);
187 $install->page_header();
188 $install->generate_navigation();
190 $template->set_filenames(array(
191 'body' => $install->get_tpl_name())
194 $install->page_footer();
202 var $type = 'install';
203 var $module_ary = array();
205 var $module_url = '';
211 * Private methods, should not be overwritten
213 function create($module_type, $module_url, $selected_mod = false, $selected_submod = false)
215 global $db, $config, $phpEx, $phpbb_root_path;
219 // Grab module information using Bart's "neat-o-module" system (tm)
220 $dir = @opendir
('.');
223 while (($file = readdir($dir)) !== false)
225 if (preg_match('#^install_(.*?)\.' . $phpEx . '$#', $file))
234 if (!sizeof($module))
236 $this->error('No installation modules found', __LINE__
, __FILE__
);
239 foreach ($module as $row)
241 // Check any module pre-reqs
242 if ($row['module_reqs'] != '')
246 $this->module_ary
[$row['module_order']]['name'] = $row['module_title'];
247 $this->module_ary
[$row['module_order']]['filename'] = $row['module_filename'];
248 $this->module_ary
[$row['module_order']]['subs'] = $row['module_subs'];
249 $this->module_ary
[$row['module_order']]['stages'] = $row['module_stages'];
251 if (strtolower($selected_mod) == strtolower($row['module_title']))
253 $this->id
= (int) $row['module_order'];
254 $this->filename
= (string) $row['module_filename'];
255 $this->module_url
= (string) $module_url;
256 $this->mode
= (string) $selected_mod;
257 // Check that the sub-mode specified is valid or set a default if not
258 if (is_array($row['module_subs']))
260 $this->sub
= strtolower((in_array(strtoupper($selected_submod), $row['module_subs'])) ?
$selected_submod : $row['module_subs'][0]);
262 else if (is_array($row['module_stages']))
264 $this->sub
= strtolower((in_array(strtoupper($selected_submod), $row['module_stages'])) ?
$selected_submod : $row['module_stages'][0]);
275 * Load and run the relevant module if applicable
277 function load($mode = false, $run = true)
279 global $phpbb_root_path, $phpEx;
288 $module = $this->filename
;
289 $this->module
= new $module($this);
291 if (method_exists($this->module
, 'main'))
293 $this->module
->main($this->mode
, $this->sub
);
299 * Output the standard page header
301 function page_header()
303 if (defined('HEADER_INC'))
308 define('HEADER_INC', true);
309 global $template, $lang, $stage, $phpbb_root_path;
311 $template->assign_vars(array(
312 'L_CHANGE' => $lang['CHANGE'],
313 'L_INSTALL_PANEL' => $lang['INSTALL_PANEL'],
314 'L_SELECT_LANG' => $lang['SELECT_LANG'],
315 'PAGE_TITLE' => $this->get_page_title(),
316 'T_IMAGE_PATH' => $phpbb_root_path . 'adm/images/',
318 'S_CONTENT_DIRECTION' => $lang['DIRECTION'],
319 'S_CONTENT_ENCODING' => $lang['ENCODING'],
320 'S_CONTENT_DIR_LEFT' => $lang['LEFT'],
321 'S_CONTENT_DIR_RIGHT' => $lang['RIGHT'],
325 if (!empty($lang['ENCODING']))
327 header('Content-type: text/html; charset: ' . $lang['ENCODING']);
329 header('Cache-Control: private, no-cache="set-cookie"');
330 header('Expires: 0');
331 header('Pragma: no-cache');
337 * Output the standard page footer
339 function page_footer()
341 global $db, $template;
343 $template->display('body');
345 // Close our DB connection.
355 * Returns desired template name
357 function get_tpl_name()
359 return $this->module
->tpl_name
. '.html';
363 * Returns the desired page title
365 function get_page_title()
369 if (!isset($this->module
->page_title
))
374 return (isset($lang[$this->module
->page_title
])) ?
$lang[$this->module
->page_title
] : $this->module
->page_title
;
378 * Generate an HTTP/1.1 header to redirect the user to another page
379 * This is used during the installation when we do not have a database available to call the normal redirect function
380 * @param string $page The page to redirect to relative to the installer root path
382 function redirect($page)
384 $server_name = (!empty($_SERVER['SERVER_NAME'])) ?
$_SERVER['SERVER_NAME'] : getenv('SERVER_NAME');
385 $server_port = (!empty($_SERVER['SERVER_PORT'])) ?
(int) $_SERVER['SERVER_PORT'] : (int) getenv('SERVER_PORT');
386 $secure = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ?
1 : 0;
388 $script_name = (!empty($_SERVER['PHP_SELF'])) ?
$_SERVER['PHP_SELF'] : getenv('PHP_SELF');
391 $script_name = (!empty($_SERVER['REQUEST_URI'])) ?
$_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
394 // Replace backslashes and doubled slashes (could happen on some proxy setups)
395 $script_name = str_replace(array('\\', '//'), '/', $script_name);
396 $script_path = trim(dirname($script_name));
398 $url = (($secure) ?
'https://' : 'http://') . $server_name;
400 if ($server_port && (($secure && $server_port <> 443) ||
(!$secure && $server_port <> 80)))
402 $url .= ':' . $server_port;
405 $url .= $script_path . '/' . $page;
406 header('Location: ' . $url);
411 * Generate the navigation tabs
413 function generate_navigation()
415 global $lang, $template, $phpEx, $language;
417 if (is_array($this->module_ary
))
419 @ksort
($this->module_ary
);
420 foreach ($this->module_ary
as $cat_ary)
422 $cat = $cat_ary['name'];
423 $l_cat = (!empty($lang['CAT_' . $cat])) ?
$lang['CAT_' . $cat] : preg_replace('#_#', ' ', $cat);
424 $cat = strtolower($cat);
425 $url = $this->module_url
. "?mode=$cat&language=$language";
427 if ($this->mode
== $cat)
429 $template->assign_block_vars('t_block1', array(
431 'S_SELECTED' => true,
435 if (is_array($this->module_ary
[$this->id
]['subs']))
437 $subs = $this->module_ary
[$this->id
]['subs'];
438 foreach ($subs as $option)
440 $l_option = (!empty($lang['SUB_' . $option])) ?
$lang['SUB_' . $option] : preg_replace('#_#', ' ', $option);
441 $option = strtolower($option);
442 $url = $this->module_url
. '?mode=' . $this->mode
. "&sub=$option&language=$language";
444 $template->assign_block_vars('l_block1', array(
445 'L_TITLE' => $l_option,
446 'S_SELECTED' => ($this->sub
== $option),
452 if (is_array($this->module_ary
[$this->id
]['stages']))
454 $subs = $this->module_ary
[$this->id
]['stages'];
456 foreach ($subs as $option)
458 $l_option = (!empty($lang['STAGE_' . $option])) ?
$lang['STAGE_' . $option] : preg_replace('#_#', ' ', $option);
459 $option = strtolower($option);
460 $matched = ($this->sub
== $option) ?
true : $matched;
462 $template->assign_block_vars('l_block2', array(
463 'L_TITLE' => $l_option,
464 'S_SELECTED' => ($this->sub
== $option),
465 'S_COMPLETE' => !$matched,
472 $template->assign_block_vars('t_block1', array(
474 'S_SELECTED' => false,
483 * Output an error message
484 * If skip is true, return and continue execution, else exit
486 function error($error, $line, $file, $skip = false)
488 global $lang, $db, $template;
492 $template->assign_block_vars('checks', array(
494 'LEGEND' => $lang['INST_ERR'],
497 $template->assign_block_vars('checks', array(
498 'TITLE' => basename($file) . ' [ ' . $line . ' ]',
499 'RESULT' => '<b style="color:red">' . $error . '</b>',
505 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
506 echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">';
508 echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
509 echo '<title>' . $lang['INST_ERR_FATAL'] . '</title>';
510 echo '<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />';
512 echo '<body id="errorpage">';
513 echo '<div id="wrap">';
514 echo ' <div id="page-header">';
516 echo ' <div id="page-body">';
517 echo ' <div class="panel">';
518 echo ' <span class="corners-top"><span></span></span>';
519 echo ' <div id="content">';
520 echo ' <h1>' . $lang['INST_ERR_FATAL'] . '</h1>';
521 echo ' <p>' . $lang['INST_ERR_FATAL'] . "</p>\n";
522 echo ' <p>' . basename($file) . ' [ ' . $line . " ]</p>\n";
523 echo ' <p><b>' . $error . "</b></p>\n";
525 echo ' <span class="corners-bottom"><span></span></span>';
528 echo ' <div id="page-footer">';
529 echo ' Powered by phpBB © ' . date('Y') . ' <a href="http://www.phpbb.com/">phpBB Group</a>';
544 * Output an error message for a database related problem
545 * If skip is true, return and continue execution, else exit
547 function db_error($error, $sql, $line, $file, $skip = false)
549 global $lang, $db, $template;
553 $template->assign_block_vars('checks', array(
555 'LEGEND' => $lang['INST_ERR_FATAL'],
558 $template->assign_block_vars('checks', array(
559 'TITLE' => basename($file) . ' [ ' . $line . ' ]',
560 'RESULT' => '<b style="color:red">' . $error . '</b><br />» SQL:' . $sql,
566 $template->set_filenames(array(
567 'body' => 'install_error.html')
569 $this->page_header();
570 $this->generate_navigation();
572 $template->assign_vars(array(
573 'MESSAGE_TITLE' => $lang['INST_ERR_FATAL_DB'],
574 'MESSAGE_TEXT' => '<p>' . basename($file) . ' [ ' . $line . ' ]</p><p>SQL : ' . $sql . '</p><p><b>' . $error . '</b></p>',
577 // Rollback if in transaction
578 if ($db->transaction
)
580 $db->sql_transaction('rollback');
583 $this->page_footer();
587 * Generate the relevant HTML for an input field and the assosciated label and explanatory text
589 function input_field($name, $type, $value='', $options='')
592 $tpl_type = explode(':', $type);
595 switch ($tpl_type[0])
599 $size = (int) $tpl_type[1];
600 $maxlength = (int) $tpl_type[2];
602 $tpl = '<input id="' . $name . '" type="' . $tpl_type[0] . '"' . (($size) ?
' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ?
$maxlength : 255) . '" name="' . $name . '" value="' . $value . '" />';
606 $rows = (int) $tpl_type[1];
607 $cols = (int) $tpl_type[2];
609 $tpl = '<textarea id="' . $name . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $value . '</textarea>';
613 $key_yes = ($value) ?
' checked="checked"' : '';
614 $key_no = (!$value) ?
' checked="checked"' : '';
616 $tpl_type_cond = explode('_', $tpl_type[1]);
617 $type_no = ($tpl_type_cond[0] == 'disabled' ||
$tpl_type_cond[0] == 'enabled') ?
false : true;
619 $tpl_no = '<input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ?
$lang['NO'] : $lang['DISABLED']);
620 $tpl_yes = '<input type="radio" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ?
$lang['YES'] : $lang['ENABLED']);
622 $tpl = ($tpl_type_cond[0] == 'yes' ||
$tpl_type_cond[0] == 'enabled') ?
$tpl_yes . ' ' . $tpl_no : $tpl_no . ' ' . $tpl_yes;
626 eval('$s_options = ' . str_replace('{VALUE}', $value, $options) . ';');
627 $tpl = '<select id="' . $name . '" name="' . $name . '">' . $s_options . '</select>';
631 eval('$tpl = ' . str_replace('{VALUE}', $value, $options) . ';');
642 * Generate the drop down of available language packs
644 function inst_language_select($default = '')
646 global $phpbb_root_path, $phpEx;
648 $dir = @opendir
($phpbb_root_path . 'language');
650 while ($file = readdir($dir))
652 $path = $phpbb_root_path . 'language/' . $file;
654 if (is_file($path) ||
is_link($path) ||
$file == '.' ||
$file == '..' ||
$file == 'CVS')
659 if (file_exists($path . '/iso.txt'))
661 list($displayname) = @file
($path . '/iso.txt');
662 $lang[$displayname] = $file;
671 foreach ($lang as $displayname => $filename)
673 $selected = (strtolower($default) == strtolower($filename)) ?
' selected="selected"' : '';
674 $user_select .= '<option value="' . $filename . '"' . $selected . '>' . ucwords($displayname) . '</option>';