PageRenderTime 25ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/root/install/index.php

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