|
From: Benjamin C. <bc...@us...> - 2003-09-05 12:11:37
|
Update of /cvsroot/phpbt/phpbt
In directory sc8-pr-cvs1:/tmp/cvs-serv18351
Modified Files:
Tag: htmltemplates
install.php
Log Message:
cleanup, dumping smarty
Index: install.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/install.php,v
retrieving revision 1.39.2.1
retrieving revision 1.39.2.2
diff -u -r1.39.2.1 -r1.39.2.2
--- install.php 30 Aug 2003 22:07:12 -0000 1.39.2.1
+++ install.php 5 Sep 2003 12:11:32 -0000 1.39.2.2
@@ -3,7 +3,7 @@
// install.php -- Web-based installation script
// Thanks to the phpBB crew for an example on how this can be done.
// ------------------------------------------------------------------------
-// Copyright (c) 2001, 2002 The phpBugTracker Group
+// Copyright (c) 2001 - 2003 The phpBugTracker Group
// ------------------------------------------------------------------------
// This file is part of phpBugTracker
//
@@ -23,35 +23,34 @@
// ------------------------------------------------------------------------
// $Id$
-// Location of smarty templates class
-define ('SMARTY_PATH','./inc/smarty/');
+// Template class
+class template {
+ var $vars;
-if (!@include(SMARTY_PATH . 'Smarty.class.php')) { // Template class
- include('templates/default/base/smartymissing.html');
- exit;
-}
-if (!@is_writeable('c_templates')) {
- include('templates/default/base/templatesperm.html');
- exit;
-}
+ function template() {
+ $this->vars = array();
+ }
-// Template class
-class extSmarty extends Smarty {
+ function render($content_template, $page_title, $wrap_file = '') {
+ extract($this->vars);
+ $path = defined('TEMPLATE_PATH')
+ ? './templates/'.THEME.'/'.TEMPLATE_PATH.'/'
+ : './templates/'.THEME.'/';
+ include($wrap_file ? $path.$wrap_file : $path.'wrap.html');
+ }
- function fetch($_smarty_tpl_file, $_smarty_cache_id = null, $_smarty_compile_id = null, $_smarty_display = false) {
- error_reporting(E_ALL ^ E_NOTICE); // Clobber Smarty warnings
- return Smarty::fetch($_smarty_tpl_file, $_smarty_cache_id, $_smarty_compile_id, $_smarty_display);
+ function assign($var, $value = '') {
+ if (is_array($var)) {
+ foreach ($var as $k => $v) {
+ $this->vars[$k] = $v;
+ }
+ } else {
+ $this->vars[$var] = $value;
+ }
}
}
-$t = new extSmarty;
-$t->template_dir = 'templates/default';
-$t->compile_dir = 'c_templates';
-$t->config_dir = '.';
-$t->register_function('build_select', 'build_select');
-
-$_gv =& $HTTP_GET_VARS;
-$_pv =& $HTTP_POST_VARS;
+$t = new template();
$db_types = array(
'mysql' => 'MySQL',
@@ -61,49 +60,47 @@
ini_set("magic_quotes_runtime", 0); // runtime quotes will kill the included sql
ini_set("magic_quotes_sybase", 0);
-if (!empty($_pv)) {
+if (!empty($_POST)) {
$tables = array(
'/^#.*/' => '',
'/^--.*/' => '',
- '/TBL_ACTIVE_SESSIONS/' => $_pv['tbl_prefix'].'active_sessions',
- '/TBL_DB_SEQUENCE/' => $_pv['tbl_prefix'].'db_sequence',
- '/TBL_ATTACHMENT/' => $_pv['tbl_prefix'].'attachment',
- '/TBL_AUTH_GROUP/' => $_pv['tbl_prefix'].'auth_group',
- '/TBL_AUTH_PERM/' => $_pv['tbl_prefix'].'auth_perm',
- '/TBL_AUTH_USER/' => $_pv['tbl_prefix'].'auth_user',
- '/TBL_BUG_CC/' => $_pv['tbl_prefix'].'bug_cc',
- '/TBL_BUG_DEPENDENCY/' => $_pv['tbl_prefix'].'bug_dependency',
- '/TBL_BUG_GROUP/' => $_pv['tbl_prefix'].'bug_group',
- '/TBL_BUG_HISTORY/' => $_pv['tbl_prefix'].'bug_history',
- '/TBL_BUG_VOTE/' => $_pv['tbl_prefix'].'bug_vote',
- '/TBL_BUG/' => $_pv['tbl_prefix'].'bug',
- '/TBL_COMMENT/' => $_pv['tbl_prefix'].'comment',
- '/TBL_COMPONENT/' => $_pv['tbl_prefix'].'component',
- '/TBL_CONFIGURATION/' => $_pv['tbl_prefix'].'configuration',
- '/TBL_GROUP_PERM/' => $_pv['tbl_prefix'].'group_perm',
- '/TBL_OS/' => $_pv['tbl_prefix'].'os',
- '/TBL_PROJECT_GROUP/' => $_pv['tbl_prefix'].'project_group',
- '/TBL_PROJECT_PERM/' => $_pv['tbl_prefix'].'project_perm',
- '/TBL_PROJECT/' => $_pv['tbl_prefix'].'project',
- '/TBL_RESOLUTION/' => $_pv['tbl_prefix'].'resolution',
- '/TBL_SAVED_QUERY/' => $_pv['tbl_prefix'].'saved_query',
- '/TBL_SEVERITY/' => $_pv['tbl_prefix'].'severity',
- '/TBL_STATUS/' => $_pv['tbl_prefix'].'status',
- '/TBL_USER_GROUP/' => $_pv['tbl_prefix'].'user_group',
- '/TBL_USER_PERM/' => $_pv['tbl_prefix'].'user_perm',
- '/TBL_USER_PREF/' => $_pv['tbl_prefix'].'user_pref',
- '/TBL_VERSION/' => $_pv['tbl_prefix'].'version',
- '/TBL_PROJECT_PERM/' => $_pv['tbl_prefix'].'project_perm',
- '/TBL_DATABASE/' => $_pv['tbl_prefix'].'database_server',
- '/TBL_SITE/' => $_pv['tbl_prefix'].'site',
- '/OPTION_ADMIN_EMAIL/' => $_pv['admin_login'],
- '/OPTION_ADMIN_PASS/' => $_pv['encrypt_pass'] ? md5($_pv['admin_pass'])
- : $_pv['admin_pass'],
- '/OPTION_PHPBT_EMAIL/' => $_pv['phpbt_email'],
- '/OPTION_ENCRYPT_PASS/' => $_pv['encrypt_pass'],
- '/OPTION_INSTALL_URL/' => 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].
- dirname($HTTP_SERVER_VARS['SCRIPT_NAME']),
- );
+ '/TBL_ACTIVE_SESSIONS/' => $_POST['tbl_prefix'].'active_sessions',
+ '/TBL_DB_SEQUENCE/' => $_POST['tbl_prefix'].'db_sequence',
+ '/TBL_ATTACHMENT/' => $_POST['tbl_prefix'].'attachment',
+ '/TBL_AUTH_GROUP/' => $_POST['tbl_prefix'].'auth_group',
+ '/TBL_AUTH_PERM/' => $_POST['tbl_prefix'].'auth_perm',
+ '/TBL_AUTH_USER/' => $_POST['tbl_prefix'].'auth_user',
+ '/TBL_BUG_CC/' => $_POST['tbl_prefix'].'bug_cc',
+ '/TBL_BUG_DEPENDENCY/' => $_POST['tbl_prefix'].'bug_dependency',
+ '/TBL_BUG_GROUP/' => $_POST['tbl_prefix'].'bug_group',
+ '/TBL_BUG_HISTORY/' => $_POST['tbl_prefix'].'bug_history',
+ '/TBL_BUG_VOTE/' => $_POST['tbl_prefix'].'bug_vote',
+ '/TBL_BUG/' => $_POST['tbl_prefix'].'bug',
+ '/TBL_COMMENT/' => $_POST['tbl_prefix'].'comment',
+ '/TBL_COMPONENT/' => $_POST['tbl_prefix'].'component',
+ '/TBL_CONFIGURATION/' => $_POST['tbl_prefix'].'configuration',
+ '/TBL_GROUP_PERM/' => $_POST['tbl_prefix'].'group_perm',
+ '/TBL_OS/' => $_POST['tbl_prefix'].'os',
+ '/TBL_PROJECT_GROUP/' => $_POST['tbl_prefix'].'project_group',
+ '/TBL_PROJECT_PERM/' => $_POST['tbl_prefix'].'project_perm',
+ '/TBL_PROJECT/' => $_POST['tbl_prefix'].'project',
+ '/TBL_RESOLUTION/' => $_POST['tbl_prefix'].'resolution',
+ '/TBL_SAVED_QUERY/' => $_POST['tbl_prefix'].'saved_query',
+ '/TBL_SEVERITY/' => $_POST['tbl_prefix'].'severity',
+ '/TBL_STATUS/' => $_POST['tbl_prefix'].'status',
+ '/TBL_USER_GROUP/' => $_POST['tbl_prefix'].'user_group',
+ '/TBL_USER_PERM/' => $_POST['tbl_prefix'].'user_perm',
+ '/TBL_USER_PREF/' => $_POST['tbl_prefix'].'user_pref',
+ '/TBL_VERSION/' => $_POST['tbl_prefix'].'version',
+ '/TBL_PROJECT_PERM/' => $_POST['tbl_prefix'].'project_perm',
+ '/TBL_DATABASE/' => $_POST['tbl_prefix'].'database_server',
+ '/TBL_SITE/' => $_POST['tbl_prefix'].'site',
+ '/OPTION_ADMIN_EMAIL/' => $_POST['admin_login'],
+ '/OPTION_ADMIN_PASS/' => $_POST['encrypt_pass'] ? md5($_POST['admin_pass']) : $_POST['admin_pass'],
+ '/OPTION_PHPBT_EMAIL/' => $_POST['phpbt_email'],
+ '/OPTION_ENCRYPT_PASS/' => $_POST['encrypt_pass'],
+ '/OPTION_INSTALL_URL/' => 'http://'.$HTTP_SERVER_VARS['SERVER_NAME'].dirname($HTTP_SERVER_VARS['SCRIPT_NAME']),
+ );
}
@include_once('config.php');
@@ -114,32 +111,27 @@
function build_select($selected = 0) {
global $db_types;
- $text = '';
foreach ($db_types as $val => $item) {
if ($selected == $val and $selected != '') $sel = ' selected';
else $sel = '';
- $text .= "<option value=\"$val\"$sel>$item</option>";
+ echo "<option value=\"$val\"$sel>$item</option>";
}
- echo $text;
}
///
/// Check the validity of an email address
/// (From zend.com user russIndr)
function bt_valid_email($email) {
- return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$', $email);
+ return eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$', $email);
}
function grab_config_file() {
- global $t, $_pv;
+ global $t, $_POST;
- foreach ($_pv as $key => $val) {
+ foreach ($_POST as $key => $val) {
$patterns[] = '{'.$key.'}';
$replacements[] = $val;
}
- // Smarty
- $patterns[] = '{smarty_path}';
- $replacements[] = SMARTY_PATH;
$contents = join('', file('config-dist.php'));
return str_replace($patterns, $replacements, $contents);
@@ -173,21 +165,21 @@
}
function create_tables() {
- global $_pv, $tables;
+ global $_POST, $tables;
- $db = test_database($_pv);
+ $db = test_database($_POST);
$db->setOption('optimize', 'portability');
- $q_temp_ary = file('schemas/'.$_pv['db_type'].'.in');
+ $q_temp_ary = file('schemas/'.$_POST['db_type'].'.in');
$queries = preg_replace(array_keys($tables), array_values($tables),
- $q_temp_ary);
+ $q_temp_ary);
$do_query = '';
foreach ($queries as $query) {
// First, collect multi-line queries into one line, then run the query
$do_query .= chop($query);
if (empty($do_query) or substr($do_query, -1) != ';') continue;
- if ($_pv['db_type'] == 'oci8' ) {
- $do_query = substr($do_query, 0, -1);
+ if ($_POST['db_type'] == 'oci8' ) {
+ $do_query = substr($do_query, 0, -1);
}
$db->query(stripslashes($do_query));
$do_query = '';
@@ -201,27 +193,27 @@
}
function check_vars() {
- global $_pv;
+ global $_POST;
$error = '';
- if (!$_pv['db_host'] = trim($_pv['db_host'])) {
- $error = 'Please enter the host name for your database server';
- } elseif (!$_pv['db_database'] = trim($_pv['db_database'])) {
- $error = 'Please enter the name of the database you will be using';
- } elseif (!$_pv['db_user'] = trim($_pv['db_user'])) {
- $error = 'Please enter the user name for connecting to the database';
- } elseif (!$_pv['phpbt_email'] = trim($_pv['phpbt_email'])) {
- $error = 'Please enter the phpBT email address';
- } elseif (!$_pv['admin_login'] = trim($_pv['admin_login'])) {
- $error = 'Please enter the admin login';
- } elseif (!bt_valid_email($_pv['admin_login'])) {
- $error = 'Please use a valid email address for the admin login';
- } elseif (!$_pv['admin_pass'] = trim($_pv['admin_pass'])) {
- $error = 'Please enter the admin password';
- } elseif (!$_pv['admin_pass2'] = trim($_pv['admin_pass2'])) {
- $error = 'Please confirm the admin password';
- } elseif ($_pv['admin_pass'] != $_pv['admin_pass2']) {
- $error = 'The admin passwords don\'t match';
+ if (!$_POST['db_host'] = trim($_POST['db_host'])) {
+ $error = translate("Please enter the host name for your database server");
+ } elseif (!$_POST['db_database'] = trim($_POST['db_database'])) {
+ $error = translate("Please enter the name of the database you will be using");
+ } elseif (!$_POST['db_user'] = trim($_POST['db_user'])) {
+ $error = translate("Please enter the user name for connecting to the database");
+ } elseif (!$_POST['phpbt_email'] = trim($_POST['phpbt_email'])) {
+ $error = translate("Please enter the phpBT email address");
+ } elseif (!$_POST['admin_login'] = trim($_POST['admin_login'])) {
+ $error = translate("Please enter the admin login");
+ } elseif (!bt_valid_email($_POST['admin_login'])) {
+ $error = translate("Please use a valid email address for the admin login");
+ } elseif (!$_POST['admin_pass'] = trim($_POST['admin_pass'])) {
+ $error = translate("Please enter the admin password");
+ } elseif (!$_POST['admin_pass2'] = trim($_POST['admin_pass2'])) {
+ $error = translate("Please confirm the admin password");
+ } elseif ($_POST['admin_pass'] != $_POST['admin_pass2']) {
+ $error = translate("The admin passwords don't match");
}
if (!empty($error)) {
@@ -236,9 +228,9 @@
if (!check_vars()) return;
create_tables();
- header('Content-Type: text/x-delimtext; name="config.php"');
- header('Content-disposition: attachment; filename=config.php');
- echo grab_config_file();
+ header('Content-Type: text/x-delimtext; name="config.php"');
+ header('Content-disposition: attachment; filename=config.php');
+ echo grab_config_file();
}
function save_config_file() {
@@ -246,7 +238,7 @@
if (!check_vars()) return;
create_tables();
if (!$fp = @fopen('config.php', 'w')) {
- show_front('Error writing to config.php');
+ show_front(translate("Error writing to config.php"));
} else {
fwrite($fp, grab_config_file());
fclose($fp);
@@ -255,29 +247,29 @@
}
function show_finished() {
- global $t, $_pv;
+ global $t, $_POST;
- $t->assign('login', $_pv['admin_login']);
+ $t->assign('login', $_POST['admin_login']);
$t->display('install-complete.html');
}
function show_front($error = '') {
- global $t, $_pv, $select, $HTTP_SERVER_VARS;
+ global $t, $_POST, $select, $HTTP_SERVER_VARS;
- $t->assign($_pv);
+ $t->assign($_POST);
$t->assign('error', $error);
$t->assign('default_email', 'phpbt@'.$HTTP_SERVER_VARS['SERVER_NAME']);
$t->display('install.html');
}
-if (isset($_pv['op'])) {
- switch ($_pv['op']) {
+if (isset($_POST['op'])) {
+ switch ($_POST['op']) {
case 'save_config_file' : save_config_file(); break;
case 'dump_config_file' : dump_config_file(); break;
}
-} elseif (isset($_gv['op'])) {
- switch ($_gv['op']) {
- case 'dbtest' : test_database($_gv, true); break;
+} elseif (isset($_GET['op'])) {
+ switch ($_GET['op']) {
+ case 'dbtest' : test_database($_GET, true); break;
}
} else {
show_front();
|