PageRenderTime 60ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/install.php

https://github.com/CasperGemini/e107
PHP | 1973 lines | 1558 code | 227 blank | 188 comment | 153 complexity | c93628bb0be7c3d94b1794d78ae9a98d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2012 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. * e107 v2.x Installation file
  10. *
  11. */
  12. // minimal software version
  13. define('MIN_PHP_VERSION', '5.3');
  14. define('MIN_MYSQL_VERSION', '4.1.2');
  15. define('MAKE_INSTALL_LOG', false);
  16. // ensure CHARSET is UTF-8 if used
  17. //define('CHARSET', 'utf-8');
  18. /* Default Options and Paths for Installer */
  19. $MySQLprefix = 'e107_';
  20. $HANDLERS_DIRECTORY = "e107_handlers/"; // needed for e107 class init
  21. define("e107_INIT", TRUE);
  22. require_once("e107_admin/ver.php");
  23. define("e_VERSION", $e107info['e107_version']);
  24. /*define("e_UC_PUBLIC", 0);
  25. define("e_UC_MAINADMIN", 250);
  26. define("e_UC_READONLY", 251);
  27. define("e_UC_GUEST", 252);
  28. define("e_UC_MEMBER", 253);
  29. define("e_UC_ADMIN", 254);
  30. define("e_UC_NOBODY", 255);*/
  31. define("E107_INSTALL",TRUE);
  32. if($_SERVER['QUERY_STRING'] != "debug")
  33. {
  34. error_reporting(0); // suppress all errors unless debugging.
  35. }
  36. else
  37. {
  38. error_reporting(E_ALL);
  39. }
  40. //error_reporting(E_ALL);
  41. function e107_ini_set($var, $value)
  42. {
  43. if (function_exists('ini_set'))
  44. {
  45. ini_set($var, $value);
  46. }
  47. }
  48. // setup some php options
  49. e107_ini_set('magic_quotes_runtime', 0);
  50. e107_ini_set('magic_quotes_sybase', 0);
  51. e107_ini_set('arg_separator.output', '&amp;');
  52. e107_ini_set('session.use_only_cookies', 1);
  53. e107_ini_set('session.use_trans_sid', 0);
  54. define('MAGIC_QUOTES_GPC', (ini_get('magic_quotes_gpc') ? true : false));
  55. $php_version = phpversion();
  56. if(version_compare($php_version, MIN_PHP_VERSION, "<"))
  57. {
  58. die_fatal_error('A minimum version of PHP '.MIN_PHP_VERSION.' is required');
  59. }
  60. // Ensure that '.' is the first part of the include path
  61. $inc_path = explode(PATH_SEPARATOR, ini_get('include_path'));
  62. if($inc_path[0] != ".")
  63. {
  64. array_unshift($inc_path, ".");
  65. $inc_path = implode(PATH_SEPARATOR, $inc_path);
  66. e107_ini_set("include_path", $inc_path);
  67. }
  68. unset($inc_path);
  69. if(!function_exists("mysql_connect")) //FIXME Adjust this once PDO is fully functional.
  70. {
  71. die_fatal_error("e107 requires PHP to be installed or compiled with the MySQL extension to work correctly, please see the MySQL manual for more information.");
  72. }
  73. # Check for the realpath(). Some hosts (I'm looking at you, Awardspace) are totally dumb and
  74. # they think that disabling realpath() will somehow (I'm assuming) help improve their pathetic
  75. # local security. Fact is, it just prevents apps from doing their proper local inclusion security
  76. # checks. So, we refuse to work with these people.
  77. $functions_ok = true;
  78. $disabled_functions = ini_get('disable_functions');
  79. if (trim($disabled_functions) != '')
  80. {
  81. $disabled_functions = explode( ',', $disabled_functions );
  82. foreach ($disabled_functions as $function)
  83. {
  84. if(trim($function) == "realpath")
  85. {
  86. $functions_ok = false;
  87. }
  88. }
  89. }
  90. if($functions_ok == true && function_exists("realpath") == false)
  91. {
  92. $functions_ok = false;
  93. }
  94. if($functions_ok == false)
  95. {
  96. die_fatal_error("e107 requires the realpath() function to be enabled and your host appears to have disabled it. This function is required for some <b>important</b> security checks and there is <b>NO workaround</b>. Please contact your host for more information.");
  97. }
  98. //obsolete $installer_folder_name = 'e107_install';
  99. include_once("./{$HANDLERS_DIRECTORY}core_functions.php");
  100. include_once("./{$HANDLERS_DIRECTORY}e107_class.php");
  101. function check_class($whatever)
  102. {
  103. return TRUE;
  104. }
  105. $override = array();
  106. if(isset($_POST['previous_steps']))
  107. {
  108. $tmp = unserialize(base64_decode($_POST['previous_steps']));
  109. $override = (isset($tmp['paths']['hash'])) ? array('site_path'=>$tmp['paths']['hash']) : array();
  110. unset($tmp);
  111. }
  112. //$e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'CACHE_DIRECTORY', 'DOWNLOADS_DIRECTORY', 'UPLOADS_DIRECTORY', 'MEDIA_DIRECTORY', 'LOGS_DIRECTORY', 'SYSTEM_DIRECTORY', 'CORE_DIRECTORY');
  113. $e107_paths = array();
  114. $e107 = e107::getInstance();
  115. $ebase = realpath(dirname(__FILE__));
  116. if($e107->initInstall($e107_paths, $ebase, $override)===false)
  117. {
  118. die_fatal_error("Error creating the following empty file: <b>".$ebase.DIRECTORY_SEPARATOR."e107_config.php</b><br />Please create it manually and then run the installation again.");
  119. }
  120. unset($e107_paths,$override,$ebase);
  121. ### NEW Register Autoload - do it asap
  122. if(!function_exists('spl_autoload_register'))
  123. {
  124. // PHP >= 5.1.2 required
  125. die_fatal_error('Fatal exception - spl_autoload_* required.');
  126. }
  127. // register core autoload
  128. e107::autoload_register(array('e107', 'autoload'));
  129. // NEW - session handler
  130. require_once(e_HANDLER.'session_handler.php');
  131. define('e_SECURITY_LEVEL', e_session::SECURITY_LEVEL_NONE);
  132. define('e_COOKIE', 'e107install');
  133. e107::getSession(); // starts session, creates default namespace
  134. // session_start();
  135. function include_lan($path, $force = false)
  136. {
  137. return e107::includeLan($path, $force);
  138. }
  139. //obsolete $e107->e107_dirs['INSTALLER'] = "{$installer_folder_name}/";
  140. if(isset($_GET['create_tables']))
  141. {
  142. create_tables_unattended();
  143. exit;
  144. }
  145. header('Content-type: text/html; charset=utf-8');
  146. $e_install = new e_install();
  147. $e_forms = new e_forms();
  148. $e_install->template->SetTag("installer_css_http", $_SERVER['PHP_SELF']."?object=stylesheet");
  149. //obsolete $e_install->template->SetTag("installer_folder_http", e_HTTP.$installer_folder_name."/");
  150. $e_install->template->SetTag("files_dir_http", e_FILE_ABS);
  151. $e_install->renderPage();
  152. /**
  153. * Set Cookie
  154. * @param string $name
  155. * @param string $value
  156. * @param integer $expire seconds
  157. * @param string $path
  158. * @param string $domain
  159. * @param boolean $secure
  160. * @return void
  161. */
  162. function cookie($name, $value, $expire=0, $path = e_HTTP, $domain = '', $secure = 0)
  163. {
  164. setcookie($name, $value, $expire, $path, $domain, $secure);
  165. }
  166. class e_install
  167. {
  168. var $paths;
  169. var $template;
  170. var $debug_info;
  171. var $debug_db_info;
  172. var $e107;
  173. var $previous_steps;
  174. var $stage;
  175. var $post_data;
  176. var $required = ""; //TODO - use for highlighting required fields with css/js.
  177. var $logFile; // Name of log file, empty string if logging disabled
  178. var $dbLink = NULL; // DB link - needed for PHP5.3 bug
  179. var $session = null;
  180. // public function __construct()
  181. function e_install()
  182. {
  183. // notice removal, required from various core routines
  184. define('USERID', 1);
  185. define('USER', true);
  186. define('ADMIN', true);
  187. // session instance
  188. $this->session = e107::getSession();
  189. $this->logFile = '';
  190. if (MAKE_INSTALL_LOG)
  191. {
  192. if(is_writable(dirname(__FILE__)))
  193. {
  194. $this->logFile = dirname(__FILE__).'/e107InstallLog.log';
  195. }
  196. }
  197. // $this->logLine('Query string: ');
  198. $this->template = new SimpleTemplate();
  199. while (@ob_end_clean());
  200. global $e107;
  201. $this->e107 = $e107;
  202. if(isset($_POST['previous_steps']))
  203. {
  204. $this->previous_steps = unserialize(base64_decode($_POST['previous_steps']));
  205. unset($_POST['previous_steps']);
  206. }
  207. else
  208. {
  209. $this->previous_steps = array();
  210. }
  211. $this->get_lan_file();
  212. $this->post_data = $_POST;
  213. $this->template->SetTag('required', '');
  214. if(isset($this->previous_steps['language']))
  215. {
  216. define("e_LANGUAGE", $this->previous_steps['language']);
  217. include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_admin.php");
  218. }
  219. }
  220. /**
  221. * Write a line of text to the log file (if enabled) - prepend time/date, append \n
  222. * Can always call this routine - it will return if logging disabled
  223. *
  224. * @param string $logLine - text to log
  225. * @return none
  226. */
  227. protected function logLine($logLine)
  228. {
  229. if (!MAKE_INSTALL_LOG || ($this->logFile == '')) return;
  230. $logfp = fopen($this->logFile, 'a+');
  231. fwrite($logfp, ($now = time()).', '.gmstrftime('%y-%m-%d %H:%M:%S',$now).' '.$logLine."\n");
  232. fclose($logfp);
  233. }
  234. function renderPage()
  235. {
  236. if(!isset($_POST['stage']))
  237. {
  238. $_POST['stage'] = 1;
  239. }
  240. $_POST['stage'] = intval($_POST['stage']);
  241. switch ($_POST['stage'])
  242. {
  243. case 1:
  244. $this->stage_1();
  245. break;
  246. case 2:
  247. $this->stage_2();
  248. break;
  249. case 3:
  250. $this->stage_3();
  251. break;
  252. case 4:
  253. $this->stage_4();
  254. break;
  255. case 5:
  256. $this->stage_5();
  257. break;
  258. case 6:
  259. $this->stage_6();
  260. break;
  261. case 7:
  262. $this->stage_7();
  263. break;
  264. case 8:
  265. $this->stage_8();
  266. break;
  267. default:
  268. $this->raise_error("Install stage information from client makes no sense to me.");
  269. }
  270. if($_SERVER['QUERY_STRING'] == "debug")
  271. {
  272. $this->template->SetTag("debug_info", print_a($this,TRUE));
  273. }
  274. else
  275. {
  276. $this->template->SetTag("debug_info", (count($this->debug_info) ? print_a($this->debug_info,TRUE)."Backtrace:<br />".print_a($this,TRUE) : ""));
  277. }
  278. echo $this->template->ParseTemplate(template_data(), TEMPLATE_TYPE_DATA);
  279. }
  280. function raise_error($details)
  281. {
  282. $this->debug_info[] = array (
  283. 'info' => array (
  284. 'details' => $details,
  285. 'backtrace' => debug_backtrace()
  286. )
  287. );
  288. }
  289. function display_required()
  290. {
  291. if(!$this->required)
  292. {
  293. return;
  294. }
  295. $this->required = array_filter($this->required);
  296. if(vartrue($this->required))
  297. {
  298. $this->template->SetTag("required","<div class='message'>". implode("<br />",$this->required)."</div>");
  299. $this->required = array();
  300. }
  301. }
  302. private function stage_1()
  303. {
  304. global $e_forms;
  305. $this->stage = 1;
  306. $this->logLine('Stage 1 started');
  307. $this->template->SetTag("installation_heading", LANINS_001);
  308. $this->template->SetTag("stage_pre", LANINS_002);
  309. $this->template->SetTag("stage_num", LANINS_003);
  310. $this->template->SetTag("stage_title", LANINS_004);
  311. $this->template->SetTag("percent", 10);
  312. $this->template->SetTag("bartype", 'warning');
  313. $e_forms->start_form("language_select", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  314. $e_forms->add_select_item("language", $this->get_languages(), "English");
  315. $this->finish_form();
  316. $e_forms->add_button("start", LANINS_035);
  317. $output = "
  318. <div style='text-align: center;'>
  319. <div class='alert alert-info alert-block'>
  320. <label for='language'>".LANINS_005."</label>
  321. </div>\n
  322. <br /><br /><br />\n
  323. ".$e_forms->return_form()."
  324. </div>";
  325. $this->template->SetTag("stage_content", $output);
  326. $this->logLine('Stage 1 completed');
  327. }
  328. private function stage_2()
  329. {
  330. global $e_forms;
  331. $this->stage = 2;
  332. $this->logLine('Stage 2 started');
  333. $this->previous_steps['language'] = $_POST['language'];
  334. $this->template->SetTag("installation_heading", LANINS_001);
  335. $this->template->SetTag("stage_pre", LANINS_002);
  336. $this->template->SetTag("stage_num", LANINS_021);
  337. $this->template->SetTag("stage_title", LANINS_022);
  338. $this->template->SetTag("percent", 25);
  339. $this->template->SetTag("bartype", 'warning');
  340. // $this->template->SetTag("onload", "document.getElementById('name').focus()");
  341. // $page_info = nl2br(LANINS_023);
  342. $page_info = "<div class='alert alert-block alert-info'>Please fill in the form below with your MySQL details. If you do not know this information, please contact your hosting provider. You may hover over each field for additional information.</div>";
  343. $e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  344. $isrequired = (($_SERVER['SERVER_ADDR'] == "127.0.0.1") || ($_SERVER['SERVER_ADDR'] == "localhost") || ($_SERVER['SERVER_ADDR'] == "::1") || preg_match('^192\.168\.\d{1,3}\.\d{1,3}$',$_SERVER['SERVER_ADDR'])) ? "" : "required='required'"; // Deals with IP V6, and 192.168.x.x address ranges, could be improved to validate x.x to a valid IP but for this use, I dont think its required to be that picky.
  345. $output = "
  346. <div style='width: 100%; padding-left: auto; padding-right: auto;'>
  347. <table class='table table-striped' >
  348. <tr>
  349. <td style='border-top: 1px solid #999;'><label for='server'>".LANINS_024."</label></td>
  350. <td style='border-top: 1px solid #999;'>
  351. <input class='tbox' type='text' id='server' name='server' autofocus size='40' value='localhost' maxlength='100' required='required' />
  352. <span class='field-help'>".LANINS_030."</span>
  353. </td>
  354. </tr>
  355. <tr>
  356. <td><label for='name'>".LANINS_025."</label></td>
  357. <td>
  358. <input class='tbox' type='text' name='name' id='name' size='40' value='' maxlength='100' required='required' />
  359. <span class='field-help'>".LANINS_031."</span>
  360. </td>
  361. </tr>
  362. <tr>
  363. <td><label for='password'>".LANINS_026."</label></td>
  364. <td>
  365. <input class='tbox' type='password' name='password' size='40' id='password' value='' maxlength='100' {$isrequired} />
  366. <span class='field-help'>".LANINS_032."</span>
  367. </td>
  368. </tr>
  369. <tr>
  370. <td><label for='db'>".LANINS_027."</label></td>
  371. <td class='form-inline'>
  372. <input type='text' name='db' size='20' id='db' value='' maxlength='100' required='required' pattern='^[a-z][a-z0-9_-]*' />
  373. <label class='checkbox inline'><input type='checkbox' name='createdb' value='1' /><small>".LANINS_028."</small></label>
  374. <span class='field-help'>".LANINS_033."</span>
  375. </td>
  376. </tr>
  377. <tr>
  378. <td><label for='prefix'>".LANINS_029."</label></td>
  379. <td>
  380. <input type='text' name='prefix' size='20' id='prefix' value='e107_' pattern='[a-z0-9]*_$' maxlength='100' required='required' />
  381. <span class='field-help'>".LANINS_034."</span>
  382. </td>
  383. </tr>
  384. </table>
  385. <br /><br />
  386. </div>
  387. \n";
  388. $e_forms->add_plain_html($output);
  389. $this->finish_form();
  390. $e_forms->add_button("submit", LANINS_035);
  391. $this->template->SetTag("stage_content", $page_info.$e_forms->return_form());
  392. $this->logLine('Stage 2 completed');
  393. }
  394. /**
  395. * Replace hash paths and create folders if needed.
  396. *
  397. * @param none
  398. * @return none
  399. */
  400. private function updatePaths()
  401. {
  402. $hash = e107::makeSiteHash($this->previous_steps['mysql']['db'],$this->previous_steps['mysql']['prefix']);
  403. $this->e107->site_path = $hash;
  404. $this->previous_steps['paths']['hash'] = $hash;
  405. $omit = array('FILES_DIRECTORY','WEB_IMAGES_DIRECTORY');
  406. foreach($this->e107->e107_dirs as $dir => $p)
  407. {
  408. if(in_array($dir, $omit)) { continue; }
  409. $this->e107->e107_dirs[$dir] = str_replace("[hash]", $hash, $this->e107->e107_dirs[$dir]);
  410. if(!is_dir($this->e107->e107_dirs[$dir]))
  411. {
  412. @mkdir($this->e107->e107_dirs[$dir]);
  413. }
  414. }
  415. }
  416. private function stage_3()
  417. {
  418. global $e_forms;
  419. $success = TRUE;
  420. $this->stage = 3;
  421. $this->logLine('Stage 3 started');
  422. $this->template->SetTag("installation_heading", LANINS_001);
  423. $this->template->SetTag("stage_pre", LANINS_002);
  424. $this->template->SetTag("stage_num", LANINS_036);
  425. $this->template->SetTag("onload", "document.getElementById('name').focus()");
  426. $this->template->SetTag("percent", 40);
  427. $this->template->SetTag("bartype", 'warning');
  428. $this->previous_steps['mysql']['server'] = trim($_POST['server']);
  429. $this->previous_steps['mysql']['user'] = trim($_POST['name']);
  430. $this->previous_steps['mysql']['password'] = $_POST['password'];
  431. $this->previous_steps['mysql']['db'] = trim($_POST['db']);
  432. $this->previous_steps['mysql']['createdb'] = (isset($_POST['createdb']) && $_POST['createdb'] == TRUE ? TRUE : FALSE);
  433. $this->previous_steps['mysql']['prefix'] = trim($_POST['prefix']);
  434. $success = $this->check_name($this->previous_steps['mysql']['db'], FALSE) && $this->check_name($this->previous_steps['mysql']['prefix'], TRUE);
  435. if ($success)
  436. {
  437. $success = $this->checkDbFields($this->previous_steps['mysql']); // Check for invalid characters
  438. }
  439. if(!$success || $this->previous_steps['mysql']['server'] == "" || $this->previous_steps['mysql']['user'] == "")
  440. {
  441. $this->stage = 3;
  442. $this->template->SetTag("stage_num", LANINS_021);
  443. $e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  444. $head = LANINS_039."<br /><br />\n";
  445. $output = "
  446. <div style='width: 100%; padding-left: auto; padding-right: auto;'>
  447. <table cellspacing='0'>
  448. <tr>
  449. <td style='border-top: 1px solid #999;'><label for='server'>".LANINS_024."</label></td>
  450. <td style='border-top: 1px solid #999;'><input class='tbox' type='text' id='server' name='server' size='40' value='{$this->previous_steps['mysql']['server']}' maxlength='100' /></td>
  451. <td style='width: 40%; border-top: 1px solid #999;'>".LANINS_030."</td>
  452. </tr>
  453. <tr>
  454. <td><label for='name'>".LANINS_025."</label></td>
  455. <td><input class='tbox' type='text' name='name' id='name' size='40' value='{$this->previous_steps['mysql']['user']}' maxlength='100' onload='this.focus()' /></td>
  456. <td>".LANINS_031."</td>
  457. </tr>
  458. <tr>
  459. <td><label for='password'>".LANINS_026."</label></td>
  460. <td><input class='tbox' type='password' name='password' id='password' size='40' value='{$this->previous_steps['mysql']['password']}' maxlength='100' /></td>
  461. <td>".LANINS_032."</td>
  462. </tr>
  463. <tr>
  464. <td><label for='db'>".LANINS_027."</label></td>
  465. <td><input type='text' name='db' id='db' size='20' value='{$this->previous_steps['mysql']['db']}' maxlength='100' />
  466. <br /><label class='defaulttext'><input type='checkbox' name='createdb'".($this->previous_steps['mysql']['createdb'] == 1 ? " checked='checked'" : "")." value='1' />".LANINS_028."</label></td>
  467. <td>".LANINS_033."</td>
  468. </tr>
  469. <tr>
  470. <td><label for='prefix'>".LANINS_029."</label></td>
  471. <td><input type='text' name='prefix' id='prefix' size='20' value='{$this->previous_steps['mysql']['prefix']}' maxlength='100' /></td>
  472. <td>".LANINS_034."</td>
  473. </tr>";
  474. if (!$success)
  475. {
  476. $output .= "<tr><td colspan='3'>".LANINS_105."</td></tr>";
  477. }
  478. $output .= "
  479. </table>
  480. <br /><br />
  481. </div>
  482. \n";
  483. $e_forms->add_plain_html($output);
  484. $e_forms->add_button("submit", LANINS_035);
  485. $this->template->SetTag("stage_title", LANINS_040);
  486. }
  487. else
  488. {
  489. $this->template->SetTag("stage_title", LANINS_037.($this->previous_steps['mysql']['createdb'] == 1 ? LANINS_038 : ""));
  490. if (!$res = @mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']))
  491. {
  492. $success = FALSE;
  493. $page_content = LANINS_041.nl2br("\n\n<b>".LANINS_083."\n</b><i>".mysql_error()."</i>");
  494. $alertType = 'error';
  495. }
  496. else
  497. {
  498. $page_content = "<i class='icon-ok'></i> ".LANINS_042;
  499. // @TODO Check database version here?
  500. /*
  501. $mysql_note = mysql_get_server_info();
  502. if (version_compare($mysql_note, MIN_MYSQL_VERSION, '>='))
  503. {
  504. $success = FALSE;
  505. }
  506. */
  507. // Do brute force for now - Should be enough
  508. $DB_ALREADY_EXISTS = mysql_select_db($this->previous_steps['mysql']['db'], $res);
  509. //TODO Add option to continue install even if DB exists.
  510. if($this->previous_steps['mysql']['createdb'] == 1 || !$DB_ALREADY_EXISTS)
  511. {
  512. $query = 'CREATE DATABASE `'.$this->previous_steps['mysql']['db'].'` CHARACTER SET `utf8` ';
  513. }
  514. elseif($DB_ALREADY_EXISTS)
  515. {
  516. $query = 'ALTER DATABASE `'.$this->previous_steps['mysql']['db'].'` CHARACTER SET `utf8` ';
  517. }
  518. if (!$this->dbqry($query))
  519. {
  520. $success = FALSE;
  521. $page_content .= "<br /><br />".LANINS_043.nl2br("\n\n<b>".LANINS_083."\n</b><i>".mysql_error()."</i>");
  522. }
  523. else
  524. {
  525. $this->dbqry('SET NAMES `utf8`');
  526. $page_content .= "<br /><i class='icon-ok'></i> ".LANINS_044;
  527. }
  528. }
  529. if($success)
  530. {
  531. $e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  532. // $page_content .= "<br /><br />".LANINS_045."<br /><br />";
  533. $e_forms->add_button("submit", LANINS_035);
  534. $alertType = 'success';
  535. }
  536. else
  537. {
  538. $e_forms->add_button("back", LANINS_035);
  539. }
  540. $head = $page_content;
  541. }
  542. if ($success)
  543. $this->finish_form();
  544. else
  545. $this->finish_form(3);
  546. $this->template->SetTag("stage_content", "<div class='alert alert-block alert-{$alertType}'>".$head."</div>".$e_forms->return_form());
  547. $this->logLine('Stage 3 completed');
  548. }
  549. private function stage_4()
  550. {
  551. global $e_forms;
  552. $this->stage = 4;
  553. $this->logLine('Stage 4 started');
  554. $this->template->SetTag("installation_heading", LANINS_001);
  555. $this->template->SetTag("stage_pre", LANINS_002);
  556. $this->template->SetTag("stage_num", LANINS_007);
  557. $this->template->SetTag("stage_title", LANINS_008);
  558. $this->template->SetTag("percent", 50);
  559. $this->template->SetTag("bartype", 'warning');
  560. $not_writable = $this->check_writable_perms('must_write'); // Some directories MUST be writable
  561. $opt_writable = $this->check_writable_perms('can_write'); // Some directories CAN optionally be writable
  562. $version_fail = false;
  563. $perms_errors = "";
  564. $mysql_pass = false;
  565. if(count($not_writable))
  566. {
  567. $perms_pass = false;
  568. foreach ($not_writable as $file)
  569. {
  570. $perms_errors .= (substr($file, -1) == "/" ? LANINS_010a : LANINS_010)."<br /><b>{$file}</b><br />\n";
  571. }
  572. $perms_notes = LANINS_018;
  573. }
  574. elseif (count($opt_writable))
  575. {
  576. $perms_pass = true;
  577. foreach ($opt_writable as $file)
  578. {
  579. $perms_errors .= (substr($file, -1) == "/" ? LANINS_010a : LANINS_010)."<br /><b>{$file}</b><br />\n";
  580. }
  581. $perms_notes = LANINS_106;
  582. }
  583. elseif (filesize('e107_config.php') > 1)
  584. { // Must start from an empty e107_config.php
  585. $perms_pass = FALSE;
  586. $perms_errors = LANINS_121;
  587. $perms_notes = "<i class='icon-remove'></i> ".LANINS_122;
  588. }
  589. else
  590. {
  591. $perms_pass = true;
  592. $perms_errors = "&nbsp;";
  593. $perms_notes = "<i class='icon-ok'></i> ".LANINS_017;
  594. }
  595. if(!function_exists("mysql_connect"))
  596. {
  597. $version_fail = true;
  598. $mysql_note = LANINS_011;
  599. $mysql_help = LANINS_012;
  600. }
  601. elseif (!@mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']))
  602. {
  603. $mysql_note = LANINS_011;
  604. $mysql_help = LANINS_013;
  605. }
  606. else
  607. {
  608. $mysql_note = mysql_get_server_info();
  609. if (version_compare($mysql_note, MIN_MYSQL_VERSION, '>='))
  610. {
  611. $mysql_help = "<i class='icon-ok'></i> ".LANINS_017;
  612. $mysql_pass = true;
  613. }
  614. else
  615. {
  616. $mysql_help = "<i class='icon-remove'></i> ".LANINS_105;
  617. }
  618. }
  619. if(!function_exists('utf8_encode'))
  620. {
  621. $xml_installed = false;
  622. }
  623. else
  624. {
  625. $xml_installed = true;
  626. }
  627. $php_version = phpversion();
  628. if(version_compare($php_version, MIN_PHP_VERSION, ">="))
  629. {
  630. $php_help = "<i class='icon-ok'></i> ".LANINS_017;
  631. }
  632. else
  633. {
  634. $php_help = "<i class='icon-remove'></i> ".LANINS_019;
  635. }
  636. $e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  637. if(!$perms_pass)
  638. {
  639. $e_forms->add_button("retest_perms", LANINS_009);
  640. $this->stage = 3; // make the installer jump back a step
  641. }
  642. elseif ($perms_pass && !$version_fail && $xml_installed)
  643. {
  644. $e_forms->add_button("continue_install", LANINS_020);
  645. }
  646. $permColor = ($perms_pass == true) ? "text-success" : "text-error";
  647. $PHPColor = ($version_fail == false) ? "text-success" : "text-error";
  648. $xmlColor = ($xml_installed == true) ? "text-success" : "text-error";
  649. $mysqlColor = ($mysql_pass == true) ? "text-success" : "text-error";
  650. $output = "
  651. <table class='table table-striped' style='width: 100%; margin-left: auto; margin-right: auto;'>
  652. <tr>
  653. <td style='width: 20%;'>".LANINS_014."</td>
  654. <td style='width: 40%;'>{$perms_errors}</td>
  655. <td class='{$permColor}' style='width: 40%;'>{$perms_notes}</td>
  656. </tr>
  657. <tr>
  658. <td>".LANINS_015."</td>
  659. <td>{$php_version}</td>
  660. <td class='{$PHPColor}'>{$php_help}</td>
  661. </tr>
  662. <tr>
  663. <td>".LANINS_016."</td>
  664. <td>{$mysql_note}</td>
  665. <td class='{$mysqlColor}'>{$mysql_help}</td>
  666. </tr>
  667. <tr>
  668. <td>".LANINS_050."</td>
  669. <td>".($xml_installed ? LANINS_051 : LANINS_052)."</td>
  670. <td class='{$xmlColor}'>".($xml_installed ? "<i class='icon-ok'></i> ".LANINS_017 : LANINS_053)."</td>
  671. </tr>
  672. </table>\n";
  673. $this->finish_form();
  674. $this->template->SetTag("stage_content", $output.$e_forms->return_form());
  675. $this->logLine('Stage 4 completed');
  676. }
  677. /**
  678. * Install stage 5 - collect Admin Login Data.
  679. *
  680. * @return string HTML form of stage 5.
  681. */
  682. private function stage_5()
  683. {
  684. global $e_forms;
  685. $this->updatePaths(); // update dynamic paths and create media and system directories - requires mysql info.
  686. $this->stage = 5;
  687. $this->logLine('Stage 5 started');
  688. $this->display_required();
  689. $this->template->SetTag("installation_heading", LANINS_001);
  690. $this->template->SetTag("stage_pre", LANINS_002);
  691. $this->template->SetTag("stage_num", LANINS_046);
  692. $this->template->SetTag("stage_title", LANINS_047);
  693. // $this->template->SetTag("onload", "document.getElementById('u_name').focus()");
  694. $this->template->SetTag("percent", 60);
  695. $this->template->SetTag("bartype", 'warning');
  696. $e_forms->start_form("admin_info", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  697. $output = "
  698. <div style='width: 100%; padding-left: auto; padding-right: auto;'>
  699. <table class='table table-striped'>
  700. <tr>
  701. <td><label for='u_name'>".LANINS_072."</label></td>
  702. <td>
  703. <input class='tbox' type='text' autofocus name='u_name' id='u_name' placeholder='admin' size='30' required='required' value='".(isset($this->previous_steps['admin']['user']) ? $this->previous_steps['admin']['user'] : "")."' maxlength='60' />
  704. <span class='field-help'>".LANINS_073."</span>
  705. </td>
  706. </tr>
  707. <tr>
  708. <td><label for='d_name'>".LANINS_074."</label></td>
  709. <td>
  710. <input class='tbox' type='text' name='d_name' id='d_name' size='30' placeholder='Administrator' value='".(isset($this->previous_steps['admin']['display']) ? $this->previous_steps['admin']['display'] : "")."' maxlength='60' />
  711. <span class='field-help'>".LANINS_123."</span>
  712. </td>
  713. </tr>
  714. <tr>
  715. <td><label for='pass1'>".LANINS_076."</label></td>
  716. <td>
  717. <input type='password' name='pass1' size='30' id='pass1' value='' maxlength='60' required='required' />
  718. <span class='field-help'>".LANINS_124."</span>
  719. </td>
  720. </tr>
  721. <tr>
  722. <td><label for='pass2'>".LANINS_078."</label></td>
  723. <td>
  724. <input type='password' name='pass2' size='30' id='pass2' value='' maxlength='60' required='required' />
  725. <span class='field-help'>".LANINS_079."</span>
  726. </td>
  727. </tr>
  728. <tr>
  729. <td><label for='email'>".LANINS_080."</label></td>
  730. <td>
  731. <input type='text' name='email' size='30' id='email' required='required' placeholder='admin@mysite.com' value='".(isset($this->previous_steps['admin']['email']) ? $this->previous_steps['admin']['email'] : '')."' maxlength='100' />
  732. <span class='field-help'>".LANINS_081."</span>
  733. </td>
  734. </tr>
  735. </table>
  736. <br /><br />
  737. </div>
  738. \n";
  739. $e_forms->add_plain_html($output);
  740. $this->finish_form();
  741. $e_forms->add_button("submit", LANINS_035);
  742. $this->template->SetTag("stage_content", $e_forms->return_form());
  743. $this->logLine('Stage 5 completed');
  744. }
  745. /**
  746. * Collect User's Website Preferences
  747. *
  748. * @return string HTML form of stage 6.
  749. */
  750. private function stage_6()
  751. {
  752. global $e_forms;
  753. $this->stage = 6;
  754. $this->logLine('Stage 6 started');
  755. // -------------------- Save Step 5 Data -------------------------
  756. if(!vartrue($this->previous_steps['admin']['user']) || varset($_POST['u_name']))
  757. {
  758. $_POST['u_name'] = str_replace(array("'", '"'), "", $_POST['u_name']);
  759. $this->previous_steps['admin']['user'] = $_POST['u_name'];
  760. }
  761. if(!vartrue($this->previous_steps['admin']['display']) || varset($_POST['d_name']))
  762. {
  763. $_POST['d_name'] = str_replace(array("'", '"'), "", $_POST['d_name']);
  764. if ($_POST['d_name'] == "")
  765. {
  766. $this->previous_steps['admin']['display'] = $_POST['u_name'];
  767. }
  768. else
  769. {
  770. $this->previous_steps['admin']['display'] = $_POST['d_name'];
  771. }
  772. }
  773. if(!vartrue($this->previous_steps['admin']['email']) || varset($_POST['email']))
  774. {
  775. $this->previous_steps['admin']['email'] = $_POST['email'];
  776. }
  777. if(varset($_POST['pass1']) || !vartrue($this->previous_steps['admin']['password']))
  778. {
  779. if($_POST['pass1'] != $_POST['pass2'])
  780. {
  781. $this->required['pass1'] = LANINS_049; // passwords don't match.
  782. }
  783. elseif(!vartrue($_POST['pass1']))
  784. {
  785. $this->required['pass1'] = LANINS_077;
  786. }
  787. else
  788. {
  789. $this->previous_steps['admin']['password'] = $_POST['pass1'];
  790. }
  791. }
  792. // ------------- Validate Step 5 Data. --------------------------
  793. if(!vartrue($this->previous_steps['admin']['user']) || !vartrue($this->previous_steps['admin']['password']))
  794. {
  795. $this->required['u_name'] = LANINS_086; //
  796. }
  797. if(vartrue($this->required['u_name']) || vartrue($this->required['pass1']))
  798. {
  799. return $this->stage_5();
  800. }
  801. // required for various core routines
  802. if(!defined('USERNAME'))
  803. {
  804. define('USERNAME', $this->previous_steps['admin']['user']);
  805. define('USEREMAIL', $this->previous_steps['admin']['email']);
  806. }
  807. // ------------- Step 6 Form --------------------------------
  808. $this->display_required();
  809. $this->template->SetTag("installation_heading", LANINS_001);
  810. $this->template->SetTag("stage_pre", LANINS_002);
  811. $this->template->SetTag("stage_num", LANINS_056);
  812. $this->template->SetTag("stage_title", LANINS_117); // Website Preferences;
  813. // $this->template->SetTag("onload", "document.getElementById('sitename').focus()");
  814. $this->template->SetTag("percent", 70);
  815. $this->template->SetTag("bartype", 'warning');
  816. $e_forms->start_form("pref_info", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  817. $output = "
  818. <div style='width: 100%; padding-left: auto; padding-right: auto; margin-bottom:20px'>
  819. <table class='table table-striped'>
  820. <colgroup>
  821. <col class='col-label' />
  822. <col class='col-control' />
  823. </colgroup>
  824. <tr>
  825. <td><label for='sitename'>".LANINS_107."</label></td>
  826. <td>
  827. <input class='tbox' type='text' autofocus placeholder=\"My Website\" required='required' name='sitename' id='sitename' size='30' value='".(vartrue($_POST['sitename']) ? $_POST['sitename'] : "")."' maxlength='60' />
  828. </td>
  829. </tr>
  830. <tr>
  831. <td><label>".LANINS_109."</label><br />".LANINS_110."</td>
  832. <td>
  833. <table class='table' >
  834. <thead>
  835. <tr>
  836. <th>".LANINS_115."</th>
  837. <th>".LANINS_116."</th>
  838. </tr>
  839. </thead>
  840. <tbody>";
  841. $themes = $this->get_themes();
  842. foreach($themes as $val)
  843. {
  844. $themeInfo = $this->get_theme_xml($val);
  845. $title = vartrue($themeInfo['@attributes']['name']);
  846. $category = vartrue($themeInfo['category']);
  847. $output .= "
  848. <tr>
  849. <td>
  850. <label class='radio'><input type='radio' name='sitetheme' value='{$val}' required='required' />{$title}</label>
  851. </td>
  852. <td>{$category}</td>
  853. </tr>";
  854. }
  855. $output .= "
  856. </tbody>
  857. </table>
  858. </td>
  859. </tr>
  860. <tr>
  861. <td><label for='install_plugins'>".LANINS_118."</label></td>
  862. <td>
  863. <input type='checkbox' name='install_plugins' checked='checked' id='install_plugins' value='1' />
  864. <span class='field-help'>".LANINS_119."</span>
  865. </td>
  866. </tr>
  867. <tr>
  868. <td><label for='generate_content'>".LANINS_111."</label></td>
  869. <td>
  870. <input type='checkbox' name='generate_content' checked='checked' id='generate_content' value='1' />
  871. <span class='field-help'>".LANINS_112."</span>
  872. </td>
  873. </tr>
  874. </table>
  875. <br /><br />
  876. </div>
  877. \n";
  878. $e_forms->add_plain_html($output);
  879. $this->finish_form();
  880. $e_forms->add_button("submit", LANINS_035);
  881. $this->template->SetTag("stage_content", $e_forms->return_form());
  882. $this->logLine('Stage 6 completed');
  883. }
  884. private function stage_7()
  885. {
  886. global $e_forms;
  887. $this->e107->e107_dirs['SYSTEM_DIRECTORY'] = str_replace("[hash]",$this->e107->site_path,$this->e107->e107_dirs['SYSTEM_DIRECTORY']);
  888. $this->e107->e107_dirs['CACHE_DIRECTORY'] = str_replace("[hash]",$this->e107->site_path,$this->e107->e107_dirs['CACHE_DIRECTORY']);
  889. $this->e107->e107_dirs['SYSTEM_DIRECTORY'] = str_replace("/".$this->e107->site_path,"",$this->e107->e107_dirs['SYSTEM_DIRECTORY']);
  890. $this->e107->e107_dirs['MEDIA_DIRECTORY'] = str_replace("/".$this->e107->site_path,"",$this->e107->e107_dirs['MEDIA_DIRECTORY']);
  891. $this->stage = 7;
  892. $this->logLine('Stage 7 started');
  893. // required for various core routines
  894. if(!defined('USERNAME'))
  895. {
  896. define('USERNAME', $this->previous_steps['admin']['user']);
  897. define('USEREMAIL', $this->previous_steps['admin']['email']);
  898. }
  899. if(varset($_POST['sitename']))
  900. {
  901. $this->previous_steps['prefs']['sitename'] = $_POST['sitename'];
  902. }
  903. if(varset($_POST['sitetheme']))
  904. {
  905. $this->previous_steps['prefs']['sitetheme'] = $_POST['sitetheme'];
  906. }
  907. if(varset($_POST['generate_content']))
  908. {
  909. $this->previous_steps['generate_content'] = $_POST['generate_content'];
  910. }
  911. if(varset($_POST['install_plugins']))
  912. {
  913. $this->previous_steps['install_plugins'] = $_POST['install_plugins'];
  914. }
  915. // Validate
  916. if(!vartrue($this->previous_steps['prefs']['sitename']))
  917. {
  918. $this->required['sitename'] = LANINS_113; // 'Please enter a website name.'; // should be used to highlight the required field. (using css for example)
  919. }
  920. if(!vartrue($this->previous_steps['prefs']['sitetheme']))
  921. {
  922. $this->required['sitetheme'] = LANINS_114; // 'Please select a theme.';
  923. }
  924. if(vartrue($this->required['sitetheme']) || vartrue($this->required['sitename']))
  925. {
  926. return $this->stage_6();
  927. }
  928. $config_file = "<?php
  929. /*
  930. * e107 website system
  931. *
  932. * Copyright (C) 2008-".date('Y')." e107 Inc (e107.org)
  933. * Released under the terms and conditions of the
  934. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  935. *
  936. * e107 configuration file
  937. *
  938. * This file has been generated by the installation script.
  939. */
  940. \$mySQLserver = '{$this->previous_steps['mysql']['server']}';
  941. \$mySQLuser = '{$this->previous_steps['mysql']['user']}';
  942. \$mySQLpassword = '{$this->previous_steps['mysql']['password']}';
  943. \$mySQLdefaultdb = '{$this->previous_steps['mysql']['db']}';
  944. \$mySQLprefix = '{$this->previous_steps['mysql']['prefix']}';
  945. \$ADMIN_DIRECTORY = '{$this->e107->e107_dirs['ADMIN_DIRECTORY']}';
  946. \$FILES_DIRECTORY = '{$this->e107->e107_dirs['FILES_DIRECTORY']}';
  947. \$IMAGES_DIRECTORY = '{$this->e107->e107_dirs['IMAGES_DIRECTORY']}';
  948. \$THEMES_DIRECTORY = '{$this->e107->e107_dirs['THEMES_DIRECTORY']}';
  949. \$PLUGINS_DIRECTORY = '{$this->e107->e107_dirs['PLUGINS_DIRECTORY']}';
  950. \$HANDLERS_DIRECTORY = '{$this->e107->e107_dirs['HANDLERS_DIRECTORY']}';
  951. \$LANGUAGES_DIRECTORY = '{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}';
  952. \$HELP_DIRECTORY = '{$this->e107->e107_dirs['HELP_DIRECTORY']}';
  953. \$MEDIA_DIRECTORY = '{$this->e107->e107_dirs['MEDIA_DIRECTORY']}';
  954. \$SYSTEM_DIRECTORY = '{$this->e107->e107_dirs['SYSTEM_DIRECTORY']}';
  955. ";
  956. $config_result = $this->write_config($config_file);
  957. if ($config_result)
  958. {
  959. $page = $config_result."<br />";
  960. $this->logLine('Error writing config file: '.$config_result);
  961. $alertType = 'warning';
  962. } else {
  963. $this->logLine('Config file written successfully');
  964. }
  965. // Data is okay - Continue.
  966. // $this->previous_steps['prefs']['sitename'] = $_POST['sitename'];
  967. // $this->previous_steps['prefs']['sitetheme'] = $_POST['sitetheme'];
  968. // $this->previous_steps['generate_content'] = $_POST['generate_content'];
  969. $this->template->SetTag("installation_heading", LANINS_001);
  970. $this->template->SetTag("stage_pre", LANINS_002);
  971. $this->template->SetTag("stage_num", LANINS_058);
  972. $this->template->SetTag("stage_title", LANINS_055);
  973. $this->template->SetTag("percent", 80);
  974. $this->template->SetTag("bartype", 'warning');
  975. $e_forms->start_form("confirmation", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
  976. $page = '<div class="alert alert-success">'.nl2br(LANINS_057).'</div>';
  977. $this->finish_form();
  978. $e_forms->add_button("submit", LANINS_035);
  979. $this->template->SetTag("stage_content", $page.$e_forms->return_form());
  980. $this->logLine('Stage 7 completed');
  981. }
  982. /**
  983. * Stage 8 - actually create database and set up the site
  984. *
  985. * @return none
  986. */
  987. private function stage_8()
  988. {
  989. global $e_forms;
  990. //$system_dir = str_replace("/".$this->e107->site_path,"",$this->e107->e107_dirs['SYSTEM_DIRECTORY']);
  991. //$media_dir = str_replace("/".$this->e107->site_path,"",$this->e107->e107_dirs['MEDIA_DIRECTORY']);
  992. // required for various core routines
  993. if(!defined('USERNAME'))
  994. {
  995. define('USERNAME', $this->previous_steps['admin']['user']);
  996. define('USEREMAIL', $this->previous_steps['admin']['email']);
  997. }
  998. $this->stage = 8;
  999. $this->logLine('Stage 8 started');
  1000. $this->template->SetTag("installation_heading", LANINS_001);
  1001. $this->template->SetTag("stage_pre", LANINS_002);
  1002. $this->template->SetTag("stage_num", LANINS_120);
  1003. $this->template->SetTag("stage_title", LANINS_071);
  1004. $this->template->SetTag("percent", 100);
  1005. $this->template->SetTag("bartype", 'success');
  1006. $htaccessError = $this->htaccess();
  1007. $e_forms->start_form("confirmation", "index.php");
  1008. $errors = $this->create_tables();
  1009. if ($errors == true)
  1010. {
  1011. $this->logLine('Errors creating tables: '.$errors);
  1012. $page = $errors."<br />";
  1013. $alertType = 'error';
  1014. }
  1015. else
  1016. {
  1017. $alertType = 'success';
  1018. $this->logLine('Tables created successfully');
  1019. $this->import_configuration();
  1020. $page = nl2br(LANINS_125)."<br />";
  1021. $page .= (is_writable('e107_config.php')) ? "<br />".str_replace("e107_config.php","<b>e107_config.php</b>",LANINS_126) : "";
  1022. if($htaccessError)
  1023. {
  1024. $page .= "<p class='text-warning'>".$htaccessError."</p>";
  1025. }
  1026. $e_forms->add_button('submit', LANINS_035);
  1027. }
  1028. $this->finish_form();
  1029. $this->template->SetTag("stage_content", "<div class='alert alert-block alert-{$alertType}'>".$page."</div>".$e_forms->return_form());
  1030. $this->logLine('Stage 8 completed');
  1031. e107::getMessage()->reset(false, false, true);
  1032. }
  1033. /**
  1034. * htaccess - handle the .htaccess file
  1035. *
  1036. * @return string $error
  1037. */
  1038. protected function htaccess()
  1039. {
  1040. $error = "";
  1041. if(!file_exists(".htaccess"))
  1042. {
  1043. if(!rename("e107.htaccess",".htaccess"))
  1044. {
  1045. $error = "IMPORTANT: Please rename e107.htaccess to .htaccess";
  1046. }
  1047. elseif($_SERVER['QUERY_STRING'] == "debug")
  1048. {
  1049. rename(".htaccess","e107.htaccess");
  1050. $error = "DEBUG: Rename from e107.htaccess to .htaccess was successful";
  1051. }
  1052. }
  1053. else
  1054. {
  1055. $error = "IMPORTANT: Please copy and paste the contents of the <b>e107.htaccess</b> into your <b>.htaccess</b> file. Please take care NOT to overwrite any existing data that may be in it.";
  1056. }
  1057. return $error;
  1058. }
  1059. /**
  1060. * Import and generate preferences and default content.
  1061. *
  1062. * @return boolean
  1063. */
  1064. //FIXME always return FALSE???
  1065. public function import_configuration()
  1066. {
  1067. $this->logLine('Starting configuration import');
  1068. // PRE-CONFIG start - create and register blank config instances - do not load!
  1069. $config_aliases = array(
  1070. 'core',
  1071. 'core_backup',
  1072. 'emote',
  1073. 'menu',
  1074. 'search',
  1075. 'notify',
  1076. );
  1077. foreach ($config_aliases as $alias)
  1078. {
  1079. e107::getConfig($alias, false)->clearPrefCache();
  1080. }
  1081. // PRE-CONFIG end
  1082. // Basic stuff to get the handlers/classes to work.
  1083. // $udirs = "admin/|plugins/|temp";
  1084. // $e_SELF = $_SERVER['PHP_SELF'];
  1085. // $e_HTTP = preg_replace("#".$udirs."#i", "", substr($e_SELF, 0, strrpos($e_SELF, "/"))."/");
  1086. // define("MAGIC_QUOTES_GPC", (ini_get('magic_quotes_gpc') ? true : false));
  1087. // define('CHARSET', 'utf-8');
  1088. // define("e_LANGUAGE", $this->previous_steps['language']);
  1089. // define('e_SELF', 'http://'.$_SERVER['HTTP_HOST']) . ($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_FILENAME']);
  1090. $themeImportFile = array();
  1091. $themeImportFile[0] = $this->e107->e107_dirs['THEMES_DIRECTORY'].$this->previous_steps['prefs']['sitetheme']."/install.xml";
  1092. $themeImportFile[1] = $this->e107->e107_dirs['THEMES_DIRECTORY'].$this->previous_steps['prefs']['sitetheme']."/install/install.xml";
  1093. // $themeImportFile[3] = $this->e107->e107_dirs['CORE_DIRECTORY']. "xml/default_install.xml";
  1094. $XMLImportfile = false;
  1095. if(vartrue($this->previous_steps['generate_content']))
  1096. {
  1097. foreach($themeImportFile as $file)
  1098. {
  1099. if(is_readable($file))
  1100. {
  1101. $XMLImportfile = $file;
  1102. break;
  1103. }
  1104. }
  1105. }
  1106. $tp = e107::getParser();
  1107. define('PREVIEWTHEMENAME',""); // Notice Removal.
  1108. include_lan($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$this->previous_steps['language']."/lan_prefs.php");
  1109. include_lan($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$this->previous_steps['language']."/admin/lan_theme.php");
  1110. // [SecretR] should work now - fixed log errors (argument noLogs = true) change to false to enable log
  1111. $coreConfig = $this->e107->e107_dirs['CORE_DIRECTORY']. "xml/default_install.xml";
  1112. $ret = e107::getXml()->e107Import($coreConfig, 'replace', true, false); // Add core pref values
  1113. $this->logLine('Attempting to Write Core Prefs.');
  1114. $this->logLine(print_r($ret, true));
  1115. if($XMLImportfile) // We cannot rely on themes to include all prefs..so use 'replace'.
  1116. {
  1117. $ret2 = e107::getXml()->e107Import($XMLImportfile, 'replace', true, false); // Overwrite specific core pref and tables entries.
  1118. $this->logLine('Attempting to write Theme Prefs/Tables (install.xml)');
  1119. $this->logLine(print_r($ret2, true));
  1120. }
  1121. //Create default plugin-table entries.
  1122. // e107::getConfig('core')->clearPrefCache();
  1123. e107::getPlugin()->update_plugins_table('update');
  1124. $this->logLine('Plugins table updated');
  1125. // Install Theme-required plugins
  1126. if(vartrue($this->previous_steps['install_plugins']))
  1127. {
  1128. if($themeInfo = $this->get_theme_xml($this->previous_steps['prefs']['sitetheme']))
  1129. {
  1130. if(isset($themeInfo['plugins']['plugin']))
  1131. {
  1132. foreach($themeInfo['plugins']['plugin'] as $k=>$plug)
  1133. {
  1134. $this->install_plugin($plug['@attributes']['name']);
  1135. $this->logLine('Theme-related plugin installed: '.$plug['@attributes']['name']);
  1136. }
  1137. }
  1138. }
  1139. }
  1140. e107::getSingleton('e107plugin')->save_addon_prefs('update'); // save plugin addon pref-lists. eg. e_latest_list.
  1141. $this->logLine('Addon prefs saved');
  1142. $tm = e107::getSingleton('themeHandler');
  1143. $tm->noLog = true; // false to enable log
  1144. $tm->setTheme($this->previous_steps['prefs']['sitetheme'], false);
  1145. // Admin log fix - don't allow logs to be called inside pref handler
  1146. // FIX
  1147. e107::getConfig('core')->setParam('nologs', true); // change to false to enable log
  1148. $pref = e107::getConfig('core')->getPref();
  1149. // Set Preferences defined during install - overwriting those that may exist in the XML.
  1150. $this->previous_steps['prefs']['sitelanguage'] = $this->previous_steps['language'];
  1151. $this->previous_steps['prefs']['sitelang_init'] = $this->previous_steps['language'];
  1152. $this->previous_steps['prefs']['siteadmin'] = $this->previous_steps['admin']['display'];
  1153. $this->previous_steps['prefs']['siteadminemail'] = $this->previous_steps['admin']['email'];
  1154. $this->previous_steps['prefs']['install_date'] = time();
  1155. $this->previous_steps['prefs']['siteurl'] = e_HTTP;
  1156. $this->previous_steps['prefs']['sitetag'] = LAN_PREF_2;
  1157. $this->previous_steps['prefs']['sitedisclaimer'] = '';
  1158. $this->previous_steps['prefs']['replyto_name'] = $this->previous_steps['admin']['display'];
  1159. $this->previous_steps['prefs']['replyto_email'] = $this->previous_steps['admin']['email'];
  1160. // Cookie name fix, ended up with 406 error when non-latin words used
  1161. $cookiename = preg_replace('/[^a-z0-9]/i', '', trim($this->previous_steps['prefs']['sitename']));
  1162. $this->previous_steps['prefs']['cookie_name'] = ($cookiename ? substr($cookiename, 0, 4).'_' : 'e_').'cookie';
  1163. ### URL related prefs
  1164. // set all prefs so that they are available, required for adminReadModules() - it checks which plugins are installed
  1165. e107::getConfig('core')->setPref($this->previous_steps['prefs']);
  1166. $url_modules = eRouter::adminReadModules();
  1167. $url_locations = eRouter::adminBuildLocations($url_modules);
  1168. $url_config = eRouter::adminBuildConfig(array(), $url_modules);
  1169. $this->previous_steps['prefs']['url_aliases'] = array();
  1170. $this->previous_steps['prefs']['url_config'] = $url_config;
  1171. $this->previous_steps['prefs']['url_modules'] = $url_modules;
  1172. $this->previous_steps['prefs']['url_locations'] = $url_locations;
  1173. eRouter::clearCache();
  1174. $this->logLine('Core URL config set to default state');
  1175. // Set prefs, save
  1176. e107::getConfig('core')->setPref($this->previous_steps['prefs']);
  1177. e107::getConfig('core')->save(FALSE,TRUE, FALSE); // save preferences made during install.
  1178. $this->logLine('Core prefs set to install choices');
  1179. // Create the admin user - replacing any that may be been included in the XML.
  1180. $ip = $_SERVER['REMOTE_ADDR'];
  1181. $userp = "1, '{$this->previous_steps['admin']['display']}', '{$this->previous_steps['admin']['user']}', '', '".md5($this->previous_steps['admin']['password'])."', '', '{$this->previous_steps['admin']['email']}', '', '', 0, ".time().", 0, 0, 0, 0, 0, '{$ip}', 0, '', 0, 1, '', '', '0', '', ".time().", ''";
  1182. $qry = "REPLACE INTO {$this->previous_steps['mysql']['prefix']}user VALUES ({$userp})";
  1183. $this->dbqry("REPLACE INTO {$this->previous_steps['mysql']['prefix']}user VALUES ({$userp})" );
  1184. $this->logLine('Admin user created');
  1185. mysql_close($this->dbLink);
  1186. e107::getMessage()->reset(false, false, true);
  1187. return false;
  1188. }
  1189. /**
  1190. * Install a Theme required plugin.
  1191. *
  1192. * @param string $plugpath - plugin folder name
  1193. * @return void
  1194. */
  1195. public function install_plugin($plugpath) //FIXME - requires default plugin table entries, see above.
  1196. {
  1197. e107::getDb()->db_Select_gen("SELECT * FROM #plugin WHERE plugin_path = '".$plugpath."' LIMIT 1");
  1198. $row = e107::getDb()->db_Fetch(MYSQL_ASSOC);
  1199. e107::getSingleton('e107plugin')->install_plugin($row['plugin_id']);
  1200. e107::getMessage()->reset(false, false, true);
  1201. return;
  1202. }
  1203. /**
  1204. * Check a DB name or table prefix - anything starting with a numeric followed by 'e' causes problems.
  1205. * Return TRUE if acceptable, FALSE if unacceptable
  1206. * Empty string returns the value of $blank_ok (caller should set TRUE for prefix, FALSE for DB name)
  1207. *
  1208. * @param string $str
  1209. * @param boolean $blank_ok [optional]
  1210. * @return boolean
  1211. */
  1212. function check_name($str, $blank_ok = FALSE)
  1213. {
  1214. if ($str == '')
  1215. return $blank_ok;
  1216. if (preg_match("#^\d+[e|E]#", $str))
  1217. return FALSE;
  1218. return TRUE;
  1219. }
  1220. /**
  1221. * checkDbFields - Check an array of db-related fields for illegal characters
  1222. *
  1223. * @param array $fields
  1224. * @return boolean TRUE for OK, FALSE for invalid character
  1225. */
  1226. function checkDbFields($fields)
  1227. {
  1228. if (!is_array($fields)) return FALSE;
  1229. foreach (array('server', 'user', 'db', 'prefix') as $key)
  1230. {
  1231. if (isset($fields[$key]))
  1232. {
  1233. if (strtr($fields[$key],"';", ' ') != $fields[$key])
  1234. {
  1235. return FALSE; // Invalid character found
  1236. }
  1237. }
  1238. }
  1239. return TRUE;
  1240. }
  1241. function get_lan_file()
  1242. {
  1243. if(!isset($this->previous_steps['language']))
  1244. {
  1245. $this->previous_steps['language'] = "English";
  1246. }
  1247. include_lan($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$this->previous_steps['language']."/lan_installer.php");
  1248. // $this->lan_file = "{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}{$this->previous_steps['language']}/lan_installer.php";
  1249. // if(is_readable($this->lan_file))
  1250. // {
  1251. // include($this->lan_file);
  1252. // }
  1253. // elseif(is_readable("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}English/lan_installer.php"))
  1254. // {
  1255. // include("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}English/lan_installer.php");
  1256. // }
  1257. // else
  1258. // {
  1259. // $this->raise_error("Fatal: Could not get valid language file for installation.");
  1260. // }
  1261. }
  1262. /**
  1263. * get_languages - check language folder for language names
  1264. *
  1265. * @param none
  1266. * @return array $lanlist
  1267. */
  1268. function get_languages()
  1269. {
  1270. $handle = opendir($this->e107->e107_dirs['LANGUAGES_DIRECTORY']);
  1271. $lanlist = array();
  1272. while ($file = readdir($handle))
  1273. {
  1274. if ($file != "." && $file != ".." && $file != "/" && $file != "CVS" && $file != 'index.html')
  1275. {
  1276. if(file_exists("./{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}{$file}/lan_installer.php"))
  1277. {
  1278. $lanlist[] = $file;
  1279. }
  1280. }
  1281. }
  1282. closedir($handle);
  1283. return $lanlist;
  1284. }
  1285. /**
  1286. * get_themes - check theme folder for theme names
  1287. *
  1288. * @param none
  1289. * @return array $themelist
  1290. */
  1291. function get_themes()
  1292. {
  1293. $handle = opendir($this->e107->e107_dirs['THEMES_DIRECTORY']);
  1294. $themelist = array();
  1295. while ($file = readdir($handle))
  1296. {
  1297. if (is_dir($this->e107->e107_dirs['THEMES_DIRECTORY'].$file) && $file !='_blank')
  1298. {
  1299. if(is_readable("./{$this->e107->e107_dirs['THEMES_DIRECTORY']}{$file}/theme.xml"))
  1300. {
  1301. $themelist[] = $file;
  1302. }
  1303. }
  1304. }
  1305. closedir($handle);
  1306. return $themelist;
  1307. }
  1308. /**
  1309. * get_theme_xml - check theme.xml file of specific theme
  1310. *
  1311. * @param string $theme_folder
  1312. * @return array $xmlArray OR boolean FALSE if result is no array
  1313. */
  1314. function get_theme_xml($theme_folder)
  1315. {
  1316. if(!defined("SITEURL"))
  1317. {
  1318. define("SITEURL","");
  1319. }
  1320. $path = $this->e107->e107_dirs['THEMES_DIRECTORY'].$theme_folder."/theme.xml";
  1321. if(!is_readable($path))
  1322. {
  1323. return FALSE;
  1324. }
  1325. require_once($this->e107->e107_dirs['HANDLERS_DIRECTORY']."theme_handler.php");
  1326. $tm = new themeHandler;
  1327. $xmlArray = $tm->parse_theme_xml($theme_folder);
  1328. // $xml = e107::getXml();
  1329. // $xmlArray = $xml->loadXMLfile($path,'advanced');
  1330. return (is_array($xmlArray)) ? $xmlArray : FALSE;
  1331. }
  1332. /**
  1333. * finish_form - pass data along forms
  1334. *
  1335. * @param string $force_stage [optional]
  1336. * @return none
  1337. */
  1338. function finish_form($force_stage = false)
  1339. {
  1340. global $e_forms;
  1341. if($this->previous_steps)
  1342. {
  1343. $e_forms->add_hidden_data("previous_steps", base64_encode(serialize($this->previous_steps)));
  1344. }
  1345. $e_forms->add_hidden_data("stage", ($force_stage ? $force_stage : ($this->stage + 1)));
  1346. }
  1347. /**
  1348. * check_writable_perms - check writable permissions
  1349. *
  1350. * @param string $list [default 'must_write']
  1351. * @return array $bad_files
  1352. */
  1353. function check_writable_perms($list = 'must_write')
  1354. {
  1355. $bad_files = array();
  1356. $system_dirs = $this->e107->e107_dirs;
  1357. $system_dirs['MEDIA_DIRECTORY'] = str_replace("[hash]/","", $system_dirs['MEDIA_DIRECTORY']);
  1358. $system_dirs['SYSTEM_DIRECTORY'] = str_replace("[hash]/","", $system_dirs['SYSTEM_DIRECTORY']);
  1359. $data['must_write'] = 'e107_config.php|{$MEDIA_DIRECTORY}|{$SYSTEM_DIRECTORY}'; // all-sub folders are created on-the-fly
  1360. $data['can_write'] = '{$PLUGINS_DIRECTORY}|{$THEMES_DIRECTORY}';
  1361. if (!isset($data[$list])) return $bad_files;
  1362. foreach ($system_dirs as $dir_name => $value)
  1363. {
  1364. $find[] = "{\${$dir_name}}";
  1365. $replace[] = "./$value";
  1366. }
  1367. $data[$list] = str_replace($find, $replace, $data[$list]);
  1368. $files = explode("|", trim($data[$list]));
  1369. foreach ($files as $file)
  1370. {
  1371. if(!is_writable($file))
  1372. {
  1373. $bad_files[] = str_replace("./", "", $file);
  1374. }
  1375. }
  1376. return $bad_files;
  1377. }
  1378. /**
  1379. * Create Core MySQL tables
  1380. *
  1381. * @return string|FALSE error code or FALSE if no errors are detected
  1382. */
  1383. public function create_tables()
  1384. {
  1385. $link = mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']);
  1386. if(!$link)
  1387. {
  1388. return nl2br(LANINS_084."\n\n<b>".LANINS_083."\n</b><i>".mysql_error($link)."</i>");
  1389. }
  1390. $this->dbLink = $link; // Needed for mysql_close() to work round bug in PHP 5.3
  1391. $db_selected = mysql_select_db($this->previous_steps['mysql']['db'], $link);
  1392. if(!$db_selected)
  1393. {
  1394. return nl2br(LANINS_085." '{$this->previous_steps['mysql']['db']}'\n\n<b>".LANINS_083."\n</b><i>".mysql_error($link)."</i>");
  1395. }
  1396. $filename = "{$this->e107->e107_dirs['CORE_DIRECTORY']}sql/core_sql.php";
  1397. $fd = fopen ($filename, "r");
  1398. $sql_data = fread($fd, filesize($filename));
  1399. $sql_data = preg_replace("#\/\*.*?\*\/#mis", '', $sql_data); // Strip comments
  1400. fclose ($fd);
  1401. if (!$sql_data)
  1402. {
  1403. return nl2br(LANINS_060)."<br /><br />";
  1404. }
  1405. preg_match_all("/create(.*?)(?:myisam|innodb);/si", $sql_data, $result );
  1406. // Force UTF-8 again
  1407. $this->dbqry('SET NAMES `utf8`');
  1408. $srch = array("CREATE TABLE","(");
  1409. $repl = array("DROP TABLE IF EXISTS","");
  1410. foreach ($result[0] as $sql_table)
  1411. {
  1412. $sql_table = preg_replace("/create table\s/si", "CREATE TABLE {$this->previous_steps['mysql']['prefix']}", $sql_table);
  1413. // Drop existing tables before creating.
  1414. $tmp = explode("\n",$sql_table);
  1415. $drop_table = str_replace($srch,$repl,$tmp[0]);
  1416. $this->dbqry($drop_table);
  1417. if (!$this->dbqry($sql_table, $link))
  1418. {
  1419. return nl2br(LANINS_061."\n\n<b>".LANINS_083."\n</b><i>".mysql_error($link)."</i>");
  1420. }
  1421. }
  1422. return FALSE;
  1423. }
  1424. function write_config($data)
  1425. {
  1426. $e107_config = 'e107_config.php';
  1427. $fp = @fopen($e107_config, 'w');
  1428. if (!@fwrite($fp, $data))
  1429. {
  1430. @fclose ($fp);
  1431. return nl2br(LANINS_070);
  1432. }
  1433. @fclose ($fp);
  1434. @chmod($e107_config,0644); // correct permissions.
  1435. return false;
  1436. }
  1437. function dbqry($qry)
  1438. {
  1439. mysql_query($qry);
  1440. if(mysql_errno())
  1441. {
  1442. $errorInfo = 'Query Error [#'.mysql_errno().']: '.mysql_error()."\nQuery: {$qry}";
  1443. echo $errorInfo."<br />";
  1444. exit;
  1445. $this->debug_db_info['db_error_log'][] = $errorInfo;
  1446. //$this->debug_db_info['db_log'][] = $qry;
  1447. return false;
  1448. }
  1449. //$this->debug_db_info['db_log'][] = $qry;
  1450. return true;
  1451. }
  1452. }
  1453. class e_forms
  1454. {
  1455. var $form;
  1456. var $opened;
  1457. function start_form($id, $action, $method = "post" )
  1458. {
  1459. $this->form = "\n<form method='{$method}' id='{$id}' action='{$action}'>\n";
  1460. $this->opened = true;
  1461. }
  1462. function add_select_item($id, $labels, $selected)
  1463. {
  1464. $this->form .= "
  1465. <select name='{$id}' id='{$id}'>\n";
  1466. foreach ($labels as $label)
  1467. {
  1468. $this->form .= "<option".($label == $selected ? " selected='selected'" : "").">{$label}</option>\n";
  1469. }
  1470. $this->form .= "</select>\n";
  1471. }
  1472. function add_button($id, $title, $align = "right", $type = "submit")
  1473. {
  1474. $this->form .= "<div class='buttons-bar inline' style='text-align: {$align}; z-index: 10;'>";
  1475. if($id != 'start')
  1476. {
  1477. $this->form .= "<a class='btn btn-large ' href='javascript:history.go(-1)'>&laquo; Back</a>&nbsp;";
  1478. }
  1479. if($id != 'back')
  1480. {
  1481. $this->form .= "<input type='{$type}' id='{$id}' value='{$title} &raquo;' class='btn btn-large btn-primary' />";
  1482. }
  1483. $this->form .= "</div>\n";
  1484. }
  1485. function add_hidden_data($id, $data)
  1486. {
  1487. $this->form .= "<input type='hidden' name='{$id}' value='{$data}' />\n";
  1488. }
  1489. function add_plain_html($html_data)
  1490. {
  1491. $this->form .= $html_data;
  1492. }
  1493. function return_form()
  1494. {
  1495. if($this->opened == true)
  1496. {
  1497. $this->form .= "</form>\n";
  1498. }
  1499. $this->opened = false;
  1500. return $this->form;
  1501. }
  1502. }
  1503. function create_tables_unattended()
  1504. {
  1505. //If username or password not specified, exit
  1506. if(!isset($_GET['username']) || !isset($_GET['password']))
  1507. {
  1508. return false;
  1509. }
  1510. if(file_exists('e107_config.php'))
  1511. {
  1512. @include('e107_config.php');
  1513. } else {
  1514. return false;
  1515. }
  1516. //If mysql info not set, config file is not created properly
  1517. if(!isset($mySQLuser) || !isset($mySQLpassword) || !isset($mySQLdefaultdb) || !isset($mySQLprefix))
  1518. {
  1519. return false;
  1520. }
  1521. // If specified username and password does not match the ones in config, exit
  1522. if($_GET['username'] !== $mySQLuser || $_GET['password'] !== $mySQLpassword)
  1523. {
  1524. return false;
  1525. }
  1526. $einstall = new e_install();
  1527. $einstall->previous_steps['mysql']['server'] = $mySQLserver;
  1528. $einstall->previous_steps['mysql']['user'] = $mySQLuser;
  1529. $einstall->previous_steps['mysql']['password'] = $mySQLpassword;
  1530. $einstall->previous_steps['mysql']['db'] = $mySQLdefaultdb;
  1531. $einstall->previous_steps['mysql']['prefix'] = $mySQLprefix;
  1532. $einstall->previous_steps['language'] = (isset($_GET['language']) ? $_GET['language'] : 'English');
  1533. $einstall->previous_steps['admin']['display'] = (isset($_GET['admin_display']) ? $_GET['admin_display'] : 'admin');
  1534. $einstall->previous_steps['admin']['user'] = (isset($_GET['admin_user']) ? $_GET['admin_user'] : 'admin');
  1535. $einstall->previous_steps['admin']['password'] = (isset($_GET['admin_password']) ? $_GET['admin_password'] : 'admin_password');
  1536. $einstall->previous_steps['admin']['email'] = (isset($_GET['admin_email']) ? $_GET['admin_email'] : 'admin_email@xxx.com');
  1537. $einstall->previous_steps['generate_content'] = isset($_GET['gen']) ? intval($_GET['gen']) : 1;
  1538. $einstall->previous_steps['install_plugins'] = isset($_GET['plugins']) ? intval($_GET['plugins']) : 1;
  1539. $einstall->previous_steps['prefs']['sitename'] = isset($_GET['sitename']) ? urldecode($_GET['sitename']) : LANINS_113;
  1540. $einstall->previous_steps['prefs']['sitetheme'] = isset($_GET['theme']) ? urldecode($_GET['theme']) : 'jayya';
  1541. //@include_once("./{$HANDLERS_DIRECTORY}e107_class.php");
  1542. //$e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'CACHE_DIRECTORY', 'DOWNLOADS_DIRECTORY', 'UPLOADS_DIRECTORY');
  1543. //$e107 = e107::getInstance();
  1544. //$e107->init($e107_paths, realpath(dirname(__FILE__)));
  1545. //$einstall->e107 = &$e107;
  1546. //FIXME - does not appear to work for import_configuration. ie. tables are blank except for user table.
  1547. $einstall->create_tables();
  1548. $einstall->import_configuration();
  1549. return true;
  1550. }
  1551. class SimpleTemplate
  1552. {
  1553. var $Tags = array();
  1554. var $open_tag = "{";
  1555. var $close_tag = "}";
  1556. function SimpleTemplate()
  1557. {
  1558. define("TEMPLATE_TYPE_FILE", 0);
  1559. define("TEMPLATE_TYPE_DATA", 1);
  1560. }
  1561. function SetTag($TagName, $Data)
  1562. {
  1563. $this->Tags[$TagName] = array( 'Tag' => $TagName,
  1564. 'Data' => $Data
  1565. );
  1566. }
  1567. function RemoveTag($TagName)
  1568. {
  1569. unset($this->Tags[$TagName]);
  1570. }
  1571. function ClearTags()
  1572. {
  1573. $this->Tags = array();
  1574. }
  1575. function ParseTemplate($Template, $template_type = TEMPLATE_TYPE_FILE)
  1576. {
  1577. if($template_type == TEMPLATE_TYPE_DATA)
  1578. {
  1579. $TemplateData = $Template;
  1580. }
  1581. else
  1582. {
  1583. $TemplateData = file_get_contents($Template);
  1584. }
  1585. foreach ($this->Tags as $Tag)
  1586. {
  1587. $TemplateData = str_replace($this->open_tag.$Tag['Tag'].$this->close_tag, $Tag['Data'], $TemplateData);
  1588. }
  1589. return $TemplateData;
  1590. }
  1591. }
  1592. function template_data()
  1593. {
  1594. $data = '<!DOCTYPE html>
  1595. <html lang="en">
  1596. <head>
  1597. <meta charset="utf-8">
  1598. <title>{installation_heading} :: {stage_pre}{stage_num} - {stage_title}</title>
  1599. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1600. <link href="'.e_JS.'bootstrap/css/bootstrap.min.css" rel="stylesheet">
  1601. <link href="'.e_THEME.'bootstrap/admin_style.css" rel="stylesheet">
  1602. <style type="text/css">
  1603. body { padding-top: 40px; padding-bottom: 40px; background-color: #181818; }
  1604. .container-narrow { margin: 0 auto; max-width: 800px; }
  1605. .container-narrow > hr { margin: 30px 0; }
  1606. .nav { margin-top:35px; }
  1607. .buttons-bar { margin: 20px 30px 10px 0px }
  1608. .tooltip-inner { font-size:110%; }
  1609. div.masthead { margin-bottom:30px }
  1610. h4 { margin-left:10px; margin-bottom:20px; color:#181818; }
  1611. #version { position:relative; left:50px; top:-20px; }
  1612. .well { border-radius: 12px }
  1613. </style>
  1614. <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  1615. <!--[if lt IE 9]>
  1616. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  1617. <![endif]-->
  1618. </head>
  1619. <body>
  1620. <div class="container-narrow">
  1621. <div class="masthead">
  1622. <ul class="nav nav-pills pull-right" >
  1623. <li class="active" style="width:200px;text-align:center" ><a href="#" >Installation: {stage_pre} {stage_num} of 8</a>
  1624. <div class="progress progress-{bartype}">
  1625. <div class="bar" style="width: {percent}%"></div>
  1626. </div>
  1627. </li>
  1628. </ul>
  1629. <h3 class="muted">
  1630. <img src="'.e_IMAGE.'admin_images/credits_logo.png" alt="e107" />
  1631. </h3>
  1632. </div>
  1633. <div class="well">
  1634. <h4>{stage_title}</h4>
  1635. {stage_content}
  1636. </div>
  1637. <div class="footer">
  1638. <p class="pull-left">&copy; e107 Inc. '.date("Y").'</p>
  1639. <p class="pull-right">Version: '.e_VERSION.'</p>
  1640. </div>
  1641. <div>{debug_info}</div>
  1642. </div> <!-- /container -->
  1643. <!-- The javascript
  1644. ================================================== -->
  1645. <!-- Placed at the end of the document so the pages load faster -->
  1646. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  1647. <script src="'.e_JS.'bootstrap/js/bootstrap.min.js"></script>
  1648. <script type="text/javascript">
  1649. $(document).ready(function()
  1650. {
  1651. $("input,textarea,select,label,.e-tip").each(function(c) {
  1652. var t = $(this).nextAll(".field-help");
  1653. t.hide();
  1654. $(this).tooltip({
  1655. title: function() {
  1656. var tip = t.html();
  1657. return tip;
  1658. },
  1659. fade: true,
  1660. html: true,
  1661. placement: "right",
  1662. delay: { show: 200, hide: 200 }
  1663. });
  1664. });
  1665. });
  1666. </script>
  1667. </body>
  1668. </html>
  1669. ';
  1670. return $data;
  1671. }
  1672. /**
  1673. * Render a Fatal error and halt installation.
  1674. */
  1675. function die_fatal_error($error)
  1676. {
  1677. define("e_IMAGE","e107_images/");
  1678. define("e_JS","e107_web/js/");
  1679. define("e_THEME", "e107_themes/");
  1680. define("e_LANGUAGEDIR", "e107_languages/");
  1681. include(e_LANGUAGEDIR."English/English.php");
  1682. include(e_LANGUAGEDIR."English/lan_installer.php");
  1683. $var = array();
  1684. $var["installation_heading"] = LANINS_001;
  1685. $var["stage_pre"] = LANINS_002;
  1686. $var["stage_num"] = LANINS_003;
  1687. $var["stage_title"] = LAN_ERROR;
  1688. $var["percent"] = 10;
  1689. $var["bartype"] = 'danger';
  1690. $var['stage_content'] = "<div class='alert alert-error alert-block'>".$error."</div>";
  1691. $var['debug_info'] = '';
  1692. $template = template_data();
  1693. foreach($var as $k=>$val)
  1694. {
  1695. $template = str_replace("{".$k."}", $val, $template);
  1696. }
  1697. echo $template;
  1698. exit;
  1699. }