PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/root/install/index.php

https://github.com/grotevoet/phpbb-gallery
PHP | 463 lines | 334 code | 74 blank | 55 comment | 43 complexity | ae4aaea4ab55a2f9da7f868400068f65 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package phpBB Gallery
  5. * @version $Id$
  6. * @copyright (c) 2007 nickvergessen nickvergessen@gmx.de http://www.flying-bits.org
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. * borrowed from phpBB3
  10. * @author: phpBB Group
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. define('IN_PHPBB', true);
  17. define('IN_INSTALL', true);
  18. define('NEWEST_PG_VERSION', '1.0.5');//@todo
  19. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
  20. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  21. include($phpbb_root_path . 'common.'.$phpEx);
  22. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  23. include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
  24. include($phpbb_root_path . 'includes/acp/acp_bbcodes.' . $phpEx);
  25. include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
  26. include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  27. require($phpbb_root_path . 'includes/functions_install.' . $phpEx);
  28. // Start session management
  29. $user->session_begin();
  30. $auth->acl($user->data);
  31. $user->setup(array('install', 'mods/install_gallery'));
  32. if (!defined('GALLERY_ROOT_PATH'))
  33. {
  34. trigger_error('MISSING_CONSTANTS');
  35. }
  36. //need some module-names
  37. $user->add_lang(array('acp/common', 'ucp', 'mods/info_acp_gallery', 'mods/info_ucp_gallery'));
  38. $template->set_custom_template('../adm/style', 'admin');
  39. $template->assign_var('T_TEMPLATE_PATH', '../adm/style');
  40. $mode = request_var('mode', 'overview');
  41. $sub = request_var('sub', '');
  42. // the acp template is never stored in the database
  43. $user->theme['template_storedb'] = false;
  44. $install = new module();
  45. $install->create('install', "index.$phpEx", $mode, $sub);
  46. $install->load();
  47. // Generate the page
  48. $install->page_header();
  49. $install->generate_navigation();
  50. $template->set_filenames(array(
  51. 'body' => $install->get_tpl_name())
  52. );
  53. $install->page_footer();
  54. /**
  55. * @package install
  56. */
  57. class module
  58. {
  59. var $id = 0;
  60. var $type = 'install';
  61. var $module_ary = array();
  62. var $filename;
  63. var $module_url = '';
  64. var $tpl_name = '';
  65. var $mode;
  66. var $sub;
  67. /**
  68. * Private methods, should not be overwritten
  69. */
  70. function create($module_type, $module_url, $selected_mod = false, $selected_submod = false)
  71. {
  72. global $db, $config, $phpEx, $phpbb_root_path;
  73. $module = array();
  74. // Grab module information using Bart's "neat-o-module" system (tm)
  75. $dir = @opendir('.');
  76. if (!$dir)
  77. {
  78. $this->error('Unable to access the installation directory', __LINE__, __FILE__);
  79. }
  80. $setmodules = 1;
  81. while (($file = readdir($dir)) !== false)
  82. {
  83. if (preg_match('#^install_(.*?)\.' . $phpEx . '$#', $file))
  84. {
  85. include($file);
  86. }
  87. }
  88. closedir($dir);
  89. unset($setmodules);
  90. if (!sizeof($module))
  91. {
  92. $this->error('No installation modules found', __LINE__, __FILE__);
  93. }
  94. // Order to use and count further if modules get assigned to the same position or not having an order
  95. $max_module_order = 1000;
  96. foreach ($module as $row)
  97. {
  98. // Check any module pre-reqs
  99. if ($row['module_reqs'] != '')
  100. {
  101. }
  102. // Module order not specified or module already assigned at this position?
  103. if (!isset($row['module_order']) || isset($this->module_ary[$row['module_order']]))
  104. {
  105. $row['module_order'] = $max_module_order;
  106. $max_module_order++;
  107. }
  108. $this->module_ary[$row['module_order']]['name'] = $row['module_title'];
  109. $this->module_ary[$row['module_order']]['filename'] = $row['module_filename'];
  110. $this->module_ary[$row['module_order']]['subs'] = $row['module_subs'];
  111. $this->module_ary[$row['module_order']]['stages'] = $row['module_stages'];
  112. if (strtolower($selected_mod) == strtolower($row['module_title']))
  113. {
  114. $this->id = (int) $row['module_order'];
  115. $this->filename = (string) $row['module_filename'];
  116. $this->module_url = (string) $module_url;
  117. $this->mode = (string) $selected_mod;
  118. // Check that the sub-mode specified is valid or set a default if not
  119. if (is_array($row['module_subs']))
  120. {
  121. $this->sub = strtolower((in_array(strtoupper($selected_submod), $row['module_subs'])) ? $selected_submod : $row['module_subs'][0]);
  122. }
  123. else if (is_array($row['module_stages']))
  124. {
  125. $this->sub = strtolower((in_array(strtoupper($selected_submod), $row['module_stages'])) ? $selected_submod : $row['module_stages'][0]);
  126. }
  127. else
  128. {
  129. $this->sub = '';
  130. }
  131. }
  132. } // END foreach
  133. } // END create
  134. /**
  135. * Load and run the relevant module if applicable
  136. */
  137. function load($mode = false, $run = true)
  138. {
  139. global $phpbb_root_path, $phpEx;
  140. if ($run)
  141. {
  142. if (!empty($mode))
  143. {
  144. $this->mode = $mode;
  145. }
  146. $module = $this->filename;
  147. if (!class_exists($module))
  148. {
  149. $this->error('Module "' . htmlspecialchars($module) . '" not accessible.', __LINE__, __FILE__);
  150. }
  151. $this->module = new $module($this);
  152. if (method_exists($this->module, 'main'))
  153. {
  154. $this->module->main($this->mode, $this->sub);
  155. }
  156. }
  157. }
  158. /**
  159. * Output the standard page header
  160. */
  161. function page_header()
  162. {
  163. if (defined('HEADER_INC'))
  164. {
  165. return;
  166. }
  167. define('HEADER_INC', true);
  168. global $template, $user, $stage, $phpbb_root_path;
  169. $template->assign_vars(array(
  170. 'L_CHANGE' => $user->lang['CHANGE'],
  171. 'L_INSTALL_PANEL' => $user->lang['INSTALL_PANEL'],
  172. 'L_SELECT_LANG' => $user->lang['SELECT_LANG'],
  173. 'L_SKIP' => $user->lang['SKIP'],
  174. 'PAGE_TITLE' => $this->get_page_title(),
  175. 'T_IMAGE_PATH' => $phpbb_root_path . 'adm/images/',
  176. 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'],
  177. 'S_CONTENT_FLOW_BEGIN' => ($user->lang['DIRECTION'] == 'ltr') ? 'left' : 'right',
  178. 'S_CONTENT_FLOW_END' => ($user->lang['DIRECTION'] == 'ltr') ? 'right' : 'left',
  179. 'S_CONTENT_ENCODING' => 'UTF-8',
  180. 'S_USER_LANG' => $user->lang['USER_LANG'],
  181. )
  182. );
  183. header('Content-type: text/html; charset=UTF-8');
  184. header('Cache-Control: private, no-cache="set-cookie"');
  185. header('Expires: 0');
  186. header('Pragma: no-cache');
  187. return;
  188. }
  189. /**
  190. * Output the standard page footer
  191. */
  192. function page_footer()
  193. {
  194. global $db, $template;
  195. $template->display('body');
  196. // Close our DB connection.
  197. if (!empty($db) && is_object($db))
  198. {
  199. $db->sql_close();
  200. }
  201. if (function_exists('exit_handler'))
  202. {
  203. exit_handler();
  204. }
  205. }
  206. /**
  207. * Returns desired template name
  208. */
  209. function get_tpl_name()
  210. {
  211. return $this->module->tpl_name . '.html';
  212. }
  213. /**
  214. * Returns the desired page title
  215. */
  216. function get_page_title()
  217. {
  218. global $user;
  219. if (!isset($this->module->page_title))
  220. {
  221. return '';
  222. }
  223. return (isset($user->lang[$this->module->page_title])) ? $user->lang[$this->module->page_title] : $this->module->page_title;
  224. }
  225. /**
  226. * Generate the navigation tabs
  227. */
  228. function generate_navigation()
  229. {
  230. global $user, $template, $phpbb_root_path, $phpEx, $language;
  231. if (is_array($this->module_ary))
  232. {
  233. @ksort($this->module_ary);
  234. foreach ($this->module_ary as $cat_ary)
  235. {
  236. $cat = $cat_ary['name'];
  237. $l_cat = (!empty($user->lang['CAT_' . $cat])) ? $user->lang['CAT_' . $cat] : preg_replace('#_#', ' ', $cat);
  238. $cat = strtolower($cat);
  239. $url = append_sid("{$phpbb_root_path}install/index.$phpEx", "mode=$cat");
  240. if ($this->mode == $cat)
  241. {
  242. $template->assign_block_vars('t_block1', array(
  243. 'L_TITLE' => $l_cat,
  244. 'S_SELECTED' => true,
  245. 'U_TITLE' => $url,
  246. ));
  247. if (is_array($this->module_ary[$this->id]['subs']))
  248. {
  249. $subs = $this->module_ary[$this->id]['subs'];
  250. foreach ($subs as $option)
  251. {
  252. $l_option = (!empty($user->lang['SUB_' . $option])) ? $user->lang['SUB_' . $option] : preg_replace('#_#', ' ', $option);
  253. $option = strtolower($option);
  254. $url = append_sid("{$phpbb_root_path}install/index.$phpEx", 'mode=' . $this->mode . "&amp;sub=$option");
  255. $template->assign_block_vars('l_block1', array(
  256. 'L_TITLE' => $l_option,
  257. 'S_SELECTED' => ($this->sub == $option),
  258. 'U_TITLE' => $url,
  259. ));
  260. }
  261. }
  262. if (is_array($this->module_ary[$this->id]['stages']))
  263. {
  264. $subs = $this->module_ary[$this->id]['stages'];
  265. $matched = false;
  266. foreach ($subs as $option)
  267. {
  268. $l_option = (!empty($user->lang['STAGE_' . $option])) ? $user->lang['STAGE_' . $option] : preg_replace('#_#', ' ', $option);
  269. $option = strtolower($option);
  270. $matched = ($this->sub == $option) ? true : $matched;
  271. $template->assign_block_vars('l_block2', array(
  272. 'L_TITLE' => $l_option,
  273. 'S_SELECTED' => ($this->sub == $option),
  274. 'S_COMPLETE' => !$matched,
  275. ));
  276. }
  277. }
  278. }
  279. else
  280. {
  281. $template->assign_block_vars('t_block1', array(
  282. 'L_TITLE' => $l_cat,
  283. 'S_SELECTED' => false,
  284. 'U_TITLE' => $url,
  285. ));
  286. }
  287. }
  288. }
  289. }
  290. /**
  291. * Output an error message
  292. * If skip is true, return and continue execution, else exit
  293. */
  294. function error($error, $line, $file, $skip = false)
  295. {
  296. global $lang, $db, $template;
  297. if ($skip)
  298. {
  299. $template->assign_block_vars('checks', array(
  300. 'S_LEGEND' => true,
  301. 'LEGEND' => $lang['INST_ERR'],
  302. ));
  303. $template->assign_block_vars('checks', array(
  304. 'TITLE' => basename($file) . ' [ ' . $line . ' ]',
  305. 'RESULT' => '<b style="color:red">' . $error . '</b>',
  306. ));
  307. return;
  308. }
  309. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  310. echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">';
  311. echo '<head>';
  312. echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
  313. echo '<title>' . $lang['INST_ERR_FATAL'] . '</title>';
  314. echo '<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />';
  315. echo '</head>';
  316. echo '<body id="errorpage">';
  317. echo '<div id="wrap">';
  318. echo ' <div id="page-header">';
  319. echo ' </div>';
  320. echo ' <div id="page-body">';
  321. echo ' <div id="acp">';
  322. echo ' <div class="panel">';
  323. echo ' <span class="corners-top"><span></span></span>';
  324. echo ' <div id="content">';
  325. echo ' <h1>' . $lang['INST_ERR_FATAL'] . '</h1>';
  326. echo ' <p>' . $lang['INST_ERR_FATAL'] . "</p>\n";
  327. echo ' <p>' . basename($file) . ' [ ' . $line . " ]</p>\n";
  328. echo ' <p><b>' . $error . "</b></p>\n";
  329. echo ' </div>';
  330. echo ' <span class="corners-bottom"><span></span></span>';
  331. echo ' </div>';
  332. echo ' </div>';
  333. echo ' </div>';
  334. echo ' <div id="page-footer">';
  335. echo ' Powered by phpBB &copy; 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>';
  336. echo ' </div>';
  337. echo '</div>';
  338. echo '</body>';
  339. echo '</html>';
  340. if (!empty($db) && is_object($db))
  341. {
  342. $db->sql_close();
  343. }
  344. exit_handler();
  345. }
  346. /**
  347. * Generate the relevant HTML for an input field and the associated label and explanatory text
  348. */
  349. function input_field($name, $type, $value='', $options='')
  350. {
  351. global $user;
  352. $tpl_type = explode(':', $type);
  353. $tpl = '';
  354. switch ($tpl_type[0])
  355. {
  356. case 'text':
  357. case 'password':
  358. $size = (int) $tpl_type[1];
  359. $maxlength = (int) $tpl_type[2];
  360. $tpl = '<input id="' . $name . '" type="' . $tpl_type[0] . '"' . (($size) ? ' size="' . $size . '"' : '') . ' maxlength="' . (($maxlength) ? $maxlength : 255) . '" name="' . $name . '" value="' . $value . '" />';
  361. break;
  362. case 'textarea':
  363. $rows = (int) $tpl_type[1];
  364. $cols = (int) $tpl_type[2];
  365. $tpl = '<textarea id="' . $name . '" name="' . $name . '" rows="' . $rows . '" cols="' . $cols . '">' . $value . '</textarea>';
  366. break;
  367. case 'radio':
  368. $key_yes = ($value) ? ' checked="checked" id="' . $name . '"' : '';
  369. $key_no = (!$value) ? ' checked="checked" id="' . $name . '"' : '';
  370. $tpl_type_cond = explode('_', $tpl_type[1]);
  371. $type_no = ($tpl_type_cond[0] == 'disabled' || $tpl_type_cond[0] == 'enabled') ? false : true;
  372. $tpl_no = '<label><input type="radio" name="' . $name . '" value="0"' . $key_no . ' class="radio" /> ' . (($type_no) ? $user->lang['NO'] : $user->lang['DISABLED']) . '</label>';
  373. $tpl_yes = '<label><input type="radio" name="' . $name . '" value="1"' . $key_yes . ' class="radio" /> ' . (($type_no) ? $user->lang['YES'] : $user->lang['ENABLED']) . '</label>';
  374. $tpl = ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') ? $tpl_yes . '&nbsp;&nbsp;' . $tpl_no : $tpl_no . '&nbsp;&nbsp;' . $tpl_yes;
  375. break;
  376. case 'select':
  377. eval('$s_options = ' . str_replace('{VALUE}', $value, $options) . ';');
  378. $tpl = '<select id="' . $name . '" name="' . $name . '">' . $s_options . '</select>';
  379. break;
  380. case 'custom':
  381. eval('$tpl = ' . str_replace('{VALUE}', $value, $options) . ';');
  382. break;
  383. default:
  384. break;
  385. }
  386. return $tpl;
  387. }
  388. }
  389. ?>