1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 21:27:25 +02:00

Bugtracker #2230 - possible fix - manage database utf8 encoding

This commit is contained in:
marj
2009-07-17 14:20:26 +00:00
parent 9ab872b199
commit e4c1ecd33a
3 changed files with 618 additions and 464 deletions

View File

@@ -9,9 +9,9 @@
* mySQL Handler * mySQL Handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
* $Revision: 1.38 $ * $Revision: 1.39 $
* $Date: 2009-05-24 15:34:37 $ * $Date: 2009-07-17 14:20:26 $
* $Author: e107steved $ * $Author: marj_nl_fr $
*/ */
if(defined('MYSQL_LIGHT')) if(defined('MYSQL_LIGHT'))
@@ -44,8 +44,8 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
* MySQL Abstraction class * MySQL Abstraction class
* *
* @package e107 * @package e107
* @version $Revision: 1.38 $ * @version $Revision: 1.39 $
* @author $Author: e107steved $ * @author $Author: marj_nl_fr $
*/ */
class db { class db {
@@ -65,6 +65,11 @@ class db {
var $mySQLinfo; var $mySQLinfo;
var $tabset; var $tabset;
/**
* @public MySQL Charset
**/
var $mySQLcharset;
var $total_results; // Total number of results var $total_results; // Total number of results
/** /**
@@ -91,14 +96,10 @@ class db {
} }
/** /**
* @return null or string error code * @access public
* @param string $mySQLserver IP Or hostname of the MySQL server * Connects to mySQL server and selects database - generally not required if your table is in the main DB.<br />
* @param string $mySQLuser MySQL username
* @param string $mySQLpassword MySQL Password
* @param string $mySQLdefaultdb The database schema to connect to
* @desc Connects to mySQL server and selects database - generally not required if your table is in the main DB.<br />
* <br /> * <br />
* Example using e107 database with variables defined in config.php:<br /> * Example using e107 database with variables defined in e107_config.php:<br />
* <code>$sql = new db; * <code>$sql = new db;
* $sql->db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);</code> * $sql->db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);</code>
* <br /> * <br />
@@ -106,7 +107,13 @@ class db {
* <code>$sql = new db; * <code>$sql = new db;
* $sql->db_Connect('url_server_database', 'user_database', 'password_database', 'name_of_database');</code> * $sql->db_Connect('url_server_database', 'user_database', 'password_database', 'name_of_database');</code>
* *
* @access public * @param string $mySQLserver IP Or hostname of the MySQL server
* @param string $mySQLuser MySQL username
* @param string $mySQLpassword MySQL Password
* @param string $mySQLdefaultdb The database schema to connect to
* @param string $newLink force a new link connection if TRUE. Default FALSE
* @param string $mySQLPrefix Tables prefix. Default to $mySQLPrefix from e107_config.php
* @return null|string error code
*/ */
function db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb, $newLink = FALSE, $mySQLPrefix = MPREFIX) function db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb, $newLink = FALSE, $mySQLPrefix = MPREFIX)
{ {
@@ -121,9 +128,10 @@ class db {
$temp = $this->mySQLerror; $temp = $this->mySQLerror;
$this->mySQLerror = FALSE; $this->mySQLerror = FALSE;
if(defined("USE_PERSISTANT_DB") && USE_PERSISTANT_DB == true) if(defined("USE_PERSISTANT_DB") && USE_PERSISTANT_DB == TRUE)
{ {
if (!$this->mySQLaccess = @mysql_pconnect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword)) // No persistent link parameter permitted // No persistent link parameter permitted
if ( ! $this->mySQLaccess = @mysql_pconnect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword))
{ {
return 'e1'; return 'e1';
} }
@@ -136,6 +144,10 @@ class db {
} }
} }
// Set utf8 connection?
//@TODO: simplify when yet undiscovered side-effects will be fixed
$this->db_Set_Charset();
if ( ! @mysql_select_db($this->mySQLdefaultdb, $this->mySQLaccess)) if ( ! @mysql_select_db($this->mySQLdefaultdb, $this->mySQLaccess))
{ {
return 'e2'; return 'e2';
@@ -143,7 +155,9 @@ class db {
$this->dbError('dbConnect/SelectDB'); $this->dbError('dbConnect/SelectDB');
if ($db_ConnectionID == NULL) $db_ConnectionID = $this->mySQLaccess; // Save the connection resource // Save the connection resource
if ($db_ConnectionID == NULL)
$db_ConnectionID = $this->mySQLaccess;
return TRUE; return TRUE;
} }
@@ -1126,6 +1140,58 @@ class db {
{ {
return $this->mySQLlastErrText; // Text of last error (empty string if no error) return $this->mySQLlastErrText; // Text of last error (empty string if no error)
} }
/**
* Check if MySQL version is utf8 compatible and may be used as it accordingly to the user choice
*
* @TODO Simplify when the conversion script will be available
*
* @access public
* @param string MySQL charset may be forced in special occasion.
* UTF-8 encoding and decoding is left to the progammer
* @param bool TRUE enter debug mode. default FALSE
* @return string hardcoded error message
*/
function db_Set_Charset($charset = '', $debug = FALSE)
{
// Get the default user choice
global $mySQLcharset;
if (varset($mySQLcharset) != 'utf8')
{
// Only utf8 is accepted
$mySQLcharset = '';
}
$charset = ($charset ? $charset : $mySQLcharset);
$message = (( ! $charset && $debug) ? 'Empty charset!' : '');
if($charset)
{
if ( ! $debug)
{
@mysql_query("SET NAMES `$charset`");
}
else
{
// Check if MySQL version is utf8 compatible
preg_match('/^(.*?)($|-)/', mysql_get_server_info(), $mysql_version);
if (version_compare($mysql_version[1], '4.1.2', '<'))
{
// reset utf8
//@TODO reset globally? $mySQLcharset = '';
$charset = '';
$message = 'MySQL version is not utf8 compatible!';
}
else
{
// Use db_Query() debug handler
$this->db_Query("SET NAMES `$charset`", NULL, '', $debug);
}
}
}
// Save mySQLcharset for further uses within this connection
$this->mySQLcharset = $charset;
return $message;
}
} }
?> ?>

View File

@@ -21,7 +21,7 @@ define("LANINS_015", "PHP Version");
define("LANINS_016", "MySQL"); define("LANINS_016", "MySQL");
define("LANINS_017", "PASS"); define("LANINS_017", "PASS");
define("LANINS_018", "Ensure all the listed files exist and are writable by the server. This normally involves CHMODing them 777, but environments vary - contact your host if you have any problems."); define("LANINS_018", "Ensure all the listed files exist and are writable by the server. This normally involves CHMODing them 777, but environments vary - contact your host if you have any problems.");
define("LANINS_019", "The version of PHP installed on your server isn't capable of running e107. e107 requires a PHP version of at least 4.3.0 to run correctly. Either upgrade your PHP version, or contact your host for an upgrade."); define("LANINS_019", "The version of PHP installed on your server isn't capable of running e107. e107 requires a PHP version of at least ".MIN_PHP_VERSION." to run correctly. Either upgrade your PHP version, or contact your host for an upgrade.");
define("LANINS_020", "Continue Installation"); define("LANINS_020", "Continue Installation");
define("LANINS_021", "2"); define("LANINS_021", "2");
define("LANINS_022", "MySQL Server Details"); define("LANINS_022", "MySQL Server Details");

View File

@@ -9,14 +9,14 @@
* Installation file * Installation file
* *
* $Source: /cvs_backup/e107_0.8/install_.php,v $ * $Source: /cvs_backup/e107_0.8/install_.php,v $
* $Revision: 1.22 $ * $Revision: 1.23 $
* $Date: 2009-07-16 10:12:26 $ * $Date: 2009-07-17 14:20:26 $
* $Author: marj_nl_fr $ * $Author: marj_nl_fr $
* *
*/ */
define('MIN_PHP_VERSION','5.0'); define('MIN_PHP_VERSION','5.0');
define('MIN_MYSQL_VERSION','4.1'); define('MIN_MYSQL_VERSION','4.1.2');
/* Default Options and Paths for Installer */ /* Default Options and Paths for Installer */
@@ -132,7 +132,7 @@ if(!function_exists("print_a"))
header("Content-type: text/html; charset=utf-8"); header("Content-type: text/html; charset=utf-8");
$installer_folder_name = 'e107_install'; //obsolete $installer_folder_name = 'e107_install';
include_once("./{$HANDLERS_DIRECTORY}e107_class.php"); include_once("./{$HANDLERS_DIRECTORY}e107_class.php");
@@ -142,13 +142,13 @@ $e107 = e107::getInstance();
$e107->_init($e107_paths, realpath(dirname(__FILE__))); $e107->_init($e107_paths, realpath(dirname(__FILE__)));
unset($e107_paths); unset($e107_paths);
$e107->e107_dirs['INSTALLER'] = "{$installer_folder_name}/"; //obsolete $e107->e107_dirs['INSTALLER'] = "{$installer_folder_name}/";
$e_install = new e_install(); $e_install = new e_install();
$e_forms = new e_forms(); $e_forms = new e_forms();
$e_install->template->SetTag("installer_css_http", $_SERVER['PHP_SELF']."?object=stylesheet"); $e_install->template->SetTag("installer_css_http", $_SERVER['PHP_SELF']."?object=stylesheet");
$e_install->template->SetTag("installer_folder_http", e_HTTP.$installer_folder_name."/"); //obsolete $e_install->template->SetTag("installer_folder_http", e_HTTP.$installer_folder_name."/");
$e_install->template->SetTag("files_dir_http", e_FILE_ABS); $e_install->template->SetTag("files_dir_http", e_FILE_ABS);
if(!isset($_POST['stage'])) if(!isset($_POST['stage']))
@@ -236,7 +236,8 @@ class e_install
); );
} }
function stage_1(){ function stage_1()
{
global $e_forms; global $e_forms;
$this->stage = 1; $this->stage = 1;
$this->get_lan_file(); $this->get_lan_file();
@@ -251,7 +252,8 @@ class e_install
$this->template->SetTag("stage_content", "<div style='text-align: center;'><label for='language'>".LANINS_005."</label>\n<br /><br /><br />\n".$e_forms->return_form()."</div>"); $this->template->SetTag("stage_content", "<div style='text-align: center;'><label for='language'>".LANINS_005."</label>\n<br /><br /><br />\n".$e_forms->return_form()."</div>");
} }
function stage_2(){ function stage_2()
{
global $e_forms; global $e_forms;
$this->stage = 2; $this->stage = 2;
$this->previous_steps['language'] = $_POST['language']; $this->previous_steps['language'] = $_POST['language'];
@@ -284,7 +286,7 @@ class e_install
<tr> <tr>
<td class='row-border'><label for='db'>".LANINS_027."</label></td> <td class='row-border'><label for='db'>".LANINS_027."</label></td>
<td class='row-border'><input type='text' name='db' size='20' id='db' value='' maxlength='100' /> <td class='row-border'><input type='text' name='db' size='20' id='db' value='' maxlength='100' />
<label class='defaulttext'><input type='checkbox' name='createdb' value='1' />".LANINS_028."</label></td> <br /><label class='defaulttext'><input type='checkbox' name='createdb' value='1' />".LANINS_028."</label></td>
<td class='row-border'>".LANINS_033."</td> <td class='row-border'>".LANINS_033."</td>
</tr> </tr>
<tr> <tr>
@@ -305,7 +307,7 @@ class e_install
function stage_3() function stage_3()
{ {
global $e_forms; global $e_forms;
$success = true; $success = TRUE;
$this->stage = 3; $this->stage = 3;
$this->get_lan_file(); $this->get_lan_file();
$this->template->SetTag("installation_heading", LANINS_001); $this->template->SetTag("installation_heading", LANINS_001);
@@ -315,7 +317,7 @@ class e_install
$this->previous_steps['mysql']['user'] = trim($_POST['name']); $this->previous_steps['mysql']['user'] = trim($_POST['name']);
$this->previous_steps['mysql']['password'] = $_POST['password']; $this->previous_steps['mysql']['password'] = $_POST['password'];
$this->previous_steps['mysql']['db'] = trim($_POST['db']); $this->previous_steps['mysql']['db'] = trim($_POST['db']);
$this->previous_steps['mysql']['createdb'] = (isset($_POST['createdb']) && $_POST['createdb'] == true ? true : false); $this->previous_steps['mysql']['createdb'] = (isset($_POST['createdb']) && $_POST['createdb'] == TRUE ? TRUE : FALSE);
$this->previous_steps['mysql']['prefix'] = trim($_POST['prefix']); $this->previous_steps['mysql']['prefix'] = trim($_POST['prefix']);
$success = $this->check_name($this->previous_steps['mysql']['db'], FALSE) && $this->check_name($this->previous_steps['mysql']['prefix'], TRUE); $success = $this->check_name($this->previous_steps['mysql']['db'], FALSE) && $this->check_name($this->previous_steps['mysql']['prefix'], TRUE);
if(!$success || $this->previous_steps['mysql']['server'] == "" || $this->previous_steps['mysql']['user'] == "") if(!$success || $this->previous_steps['mysql']['server'] == "" || $this->previous_steps['mysql']['user'] == "")
@@ -346,7 +348,7 @@ class e_install
<tr> <tr>
<td class='row-border'><label for='db'>".LANINS_027."</label></td> <td class='row-border'><label for='db'>".LANINS_027."</label></td>
<td class='row-border'><input type='text' name='db' id='db' size='20' value='{$this->previous_steps['mysql']['db']}' maxlength='100' /> <td class='row-border'><input type='text' name='db' id='db' size='20' value='{$this->previous_steps['mysql']['db']}' maxlength='100' />
<label class='defaulttext'><input type='checkbox' name='createdb'".($this->previous_steps['mysql']['createdb'] == 1 ? " checked='checked'" : "")." value='1' />".LANINS_028."</label></td> <br /><label class='defaulttext'><input type='checkbox' name='createdb'".($this->previous_steps['mysql']['createdb'] == 1 ? " checked='checked'" : "")." value='1' />".LANINS_028."</label></td>
<td class='row-border'>".LANINS_033."</td> <td class='row-border'>".LANINS_033."</td>
</tr> </tr>
<tr> <tr>
@@ -371,25 +373,42 @@ class e_install
$this->template->SetTag("stage_title", LANINS_037.($this->previous_steps['mysql']['createdb'] == 1 ? LANINS_038 : "")); $this->template->SetTag("stage_title", LANINS_037.($this->previous_steps['mysql']['createdb'] == 1 ? LANINS_038 : ""));
if (!@mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password'])) if (!@mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']))
{ {
$success = false; $success = FALSE;
$page_content = LANINS_041.nl2br("\n\n<b>".LANINS_083."\n</b><i>".mysql_error()."</i>"); $page_content = LANINS_041.nl2br("\n\n<b>".LANINS_083."\n</b><i>".mysql_error()."</i>");
} }
else else
{ {
$page_content = LANINS_042; $page_content = LANINS_042;
// @TODO Check database version here?
/*
$mysql_note = mysql_get_server_info();
if (version_compare($mysql_note, MIN_MYSQL_VERSION, '>='))
{
$success = FALSE;
}
*/
// Do brute force for now - Should be enough
if($this->previous_steps['mysql']['createdb'] == 1) if($this->previous_steps['mysql']['createdb'] == 1)
{ {
if (!$this->dbqry("CREATE DATABASE ".$this->previous_steps['mysql']['db'])) $query = 'CREATE DATABASE '.$this->previous_steps['mysql']['db'].' CHARACTER SET `utf8` ';
}
else
{ {
$success = false; $query = 'ALTER DATABASE '.$this->previous_steps['mysql']['db'].' CHARACTER SET `utf8` ';
}
if ( ! $this->dbqry($query))
{
$success = FALSE;
$page_content .= "<br /><br />".LANINS_043.nl2br("\n\n<b>".LANINS_083."\n</b><i>".mysql_error()."</i>"); $page_content .= "<br /><br />".LANINS_043.nl2br("\n\n<b>".LANINS_083."\n</b><i>".mysql_error()."</i>");
} }
else else
{ {
$this->dbqry('SET NAMES `utf8`');
$page_content .= "<br /><br />".LANINS_044; $page_content .= "<br /><br />".LANINS_044;
} }
} }
}
if($success) if($success)
{ {
$e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : "")); $e_forms->start_form("versions", $_SERVER['PHP_SELF'].($_SERVER['QUERY_STRING'] == "debug" ? "?debug" : ""));
@@ -398,7 +417,10 @@ class e_install
} }
$head = $page_content; $head = $page_content;
} }
if ($success) $this->finish_form(); else $this->finish_form(3); if ($success)
$this->finish_form();
else
$this->finish_form(3);
$this->template->SetTag("stage_content", $head.$e_forms->return_form()); $this->template->SetTag("stage_content", $head.$e_forms->return_form());
} }
@@ -521,7 +543,8 @@ class e_install
function stage_5(){ function stage_5()
{
global $e_forms; global $e_forms;
$this->stage = 5; $this->stage = 5;
$this->get_lan_file(); $this->get_lan_file();
@@ -567,7 +590,8 @@ class e_install
$this->template->SetTag("stage_content", $e_forms->return_form()); $this->template->SetTag("stage_content", $e_forms->return_form());
} }
function stage_6(){ function stage_6()
{
global $e_forms; global $e_forms;
$this->get_lan_file(); $this->get_lan_file();
$this->stage = 6; $this->stage = 6;
@@ -576,15 +600,19 @@ class e_install
$_POST['d_name'] = str_replace(array("'", '"'), "", $_POST['d_name']); $_POST['d_name'] = str_replace(array("'", '"'), "", $_POST['d_name']);
$this->previous_steps['admin']['user'] = $_POST['u_name']; $this->previous_steps['admin']['user'] = $_POST['u_name'];
if ($_POST['d_name'] == "") { if ($_POST['d_name'] == "")
{
$this->previous_steps['admin']['display'] = $_POST['u_name']; $this->previous_steps['admin']['display'] = $_POST['u_name'];
} else { }
else
{
$this->previous_steps['admin']['display'] = $_POST['d_name']; $this->previous_steps['admin']['display'] = $_POST['d_name'];
} }
$this->previous_steps['admin']['email'] = $_POST['email']; $this->previous_steps['admin']['email'] = $_POST['email'];
$this->previous_steps['admin']['password'] = $_POST['pass1']; $this->previous_steps['admin']['password'] = $_POST['pass1'];
if(trim($_POST['u_name']) == "" || trim($_POST['email']) == "" || trim($_POST['pass1']) == "") { if(trim($_POST['u_name']) == "" || trim($_POST['email']) == "" || trim($_POST['pass1']) == "")
{
$this->template->SetTag("installation_heading", LANINS_001); $this->template->SetTag("installation_heading", LANINS_001);
$this->template->SetTag("stage_num", LANINS_046); $this->template->SetTag("stage_num", LANINS_046);
$this->template->SetTag("stage_pre", LANINS_002); $this->template->SetTag("stage_pre", LANINS_002);
@@ -594,7 +622,9 @@ class e_install
$this->finish_form(5); $this->finish_form(5);
$e_forms->add_button("submit", LANINS_048); $e_forms->add_button("submit", LANINS_048);
} elseif($_POST['pass1'] != $_POST['pass2']) { }
elseif($_POST['pass1'] != $_POST['pass2'])
{
$this->template->SetTag("installation_heading", LANINS_001); $this->template->SetTag("installation_heading", LANINS_001);
$this->template->SetTag("stage_num", LANINS_046); $this->template->SetTag("stage_num", LANINS_046);
$this->template->SetTag("stage_pre", LANINS_002); $this->template->SetTag("stage_pre", LANINS_002);
@@ -604,7 +634,9 @@ class e_install
$this->finish_form(5); $this->finish_form(5);
$e_forms->add_button("submit", LANINS_048); $e_forms->add_button("submit", LANINS_048);
} else { }
else
{
$this->template->SetTag("installation_heading", LANINS_001); $this->template->SetTag("installation_heading", LANINS_001);
$this->template->SetTag("stage_pre", LANINS_002); $this->template->SetTag("stage_pre", LANINS_002);
@@ -620,7 +652,8 @@ class e_install
$this->template->SetTag("stage_content", $page.$e_forms->return_form()); $this->template->SetTag("stage_content", $page.$e_forms->return_form());
} }
function stage_7(){ function stage_7()
{
global $e_forms; global $e_forms;
$this->get_lan_file(); $this->get_lan_file();
@@ -632,20 +665,16 @@ class e_install
$this->template->SetTag("stage_title", LANINS_071); $this->template->SetTag("stage_title", LANINS_071);
$config_file = "<?php $config_file = "<?php
/* /*
+----------------------------------------------------+ * e107 website system
| e107 website system *
| e107_config.php * Copyright (C) 2001-2008 e107 Inc (e107.org)
| * Released under the terms and conditions of the
| Copyright (C) 2001-2009 e107 Inc * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
| http://e107.org *
| jalist@e107.org * e107 configuration file
| *
| Released under the terms and conditions of the * This file has been generated by the installation script.
| GNU General Public License (http://gnu.org).
+----------------------------------------------------+
This file has been generated by the installation script.
*/ */
\$mySQLserver = '{$this->previous_steps['mysql']['server']}'; \$mySQLserver = '{$this->previous_steps['mysql']['server']}';
@@ -653,31 +682,41 @@ This file has been generated by the installation script.
\$mySQLpassword = '{$this->previous_steps['mysql']['password']}'; \$mySQLpassword = '{$this->previous_steps['mysql']['password']}';
\$mySQLdefaultdb = '{$this->previous_steps['mysql']['db']}'; \$mySQLdefaultdb = '{$this->previous_steps['mysql']['db']}';
\$mySQLprefix = '{$this->previous_steps['mysql']['prefix']}'; \$mySQLprefix = '{$this->previous_steps['mysql']['prefix']}';
// \$mySQLcharset can only contain 'utf8' or ''
\$ADMIN_DIRECTORY = \"{$this->e107->e107_dirs['ADMIN_DIRECTORY']}\"; //@TODO remove in the future
\$FILES_DIRECTORY = \"{$this->e107->e107_dirs['FILES_DIRECTORY']}\"; \$mySQLcharset = 'utf8';
\$IMAGES_DIRECTORY = \"{$this->e107->e107_dirs['IMAGES_DIRECTORY']}\";
\$THEMES_DIRECTORY = \"{$this->e107->e107_dirs['THEMES_DIRECTORY']}\";
\$PLUGINS_DIRECTORY = \"{$this->e107->e107_dirs['PLUGINS_DIRECTORY']}\";
\$HANDLERS_DIRECTORY = \"{$this->e107->e107_dirs['HANDLERS_DIRECTORY']}\";
\$LANGUAGES_DIRECTORY = \"{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}\";
\$HELP_DIRECTORY = \"{$this->e107->e107_dirs['HELP_DIRECTORY']}\";
\$CACHE_DIRECTORY = \"{$this->e107->e107_dirs['CACHE_DIRECTORY']}\";
\$DOWNLOADS_DIRECTORY = \"{$this->e107->e107_dirs['DOWNLOADS_DIRECTORY']}\";
\$UPLOADS_DIRECTORY = \"{$this->e107->e107_dirs['UPLOADS_DIRECTORY']}\";
?>"; \$ADMIN_DIRECTORY = '{$this->e107->e107_dirs['ADMIN_DIRECTORY']}';
\$FILES_DIRECTORY = '{$this->e107->e107_dirs['FILES_DIRECTORY']}';
\$IMAGES_DIRECTORY = '{$this->e107->e107_dirs['IMAGES_DIRECTORY']}';
\$THEMES_DIRECTORY = '{$this->e107->e107_dirs['THEMES_DIRECTORY']}';
\$PLUGINS_DIRECTORY = '{$this->e107->e107_dirs['PLUGINS_DIRECTORY']}';
\$HANDLERS_DIRECTORY = '{$this->e107->e107_dirs['HANDLERS_DIRECTORY']}';
\$LANGUAGES_DIRECTORY = '{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}';
\$HELP_DIRECTORY = '{$this->e107->e107_dirs['HELP_DIRECTORY']}';
\$CACHE_DIRECTORY = '{$this->e107->e107_dirs['CACHE_DIRECTORY']}';
\$DOWNLOADS_DIRECTORY = '{$this->e107->e107_dirs['DOWNLOADS_DIRECTORY']}';
\$UPLOADS_DIRECTORY = '{$this->e107->e107_dirs['UPLOADS_DIRECTORY']}';
";
$config_result = $this->write_config($config_file); $config_result = $this->write_config($config_file);
$e_forms->start_form("confirmation", "index.php"); $e_forms->start_form("confirmation", "index.php");
if ($config_result) { if ($config_result)
{
$page = $config_result."<br />"; $page = $config_result."<br />";
} else { }
else
{
$errors = $this->create_tables(); $errors = $this->create_tables();
if ($errors == true) { if ($errors == true)
{
$page = $errors."<br />"; $page = $errors."<br />";
} else { }
else
{
$page = nl2br(LANINS_069)."<br />"; $page = nl2br(LANINS_069)."<br />";
$e_forms->add_button("submit", LANINS_035); $e_forms->add_button("submit", LANINS_035);
} }
@@ -692,29 +731,40 @@ This file has been generated by the installation script.
// Empty string returns the value of $blank_ok (caller should set TRUE for prefix, FALSE for DB name) // Empty string returns the value of $blank_ok (caller should set TRUE for prefix, FALSE for DB name)
function check_name($str, $blank_ok = FALSE) function check_name($str, $blank_ok = FALSE)
{ {
if ($str == '') return $blank_ok; if ($str == '')
if (preg_match("#^\d+[e|E]#",$str)) return FALSE; return $blank_ok;
if (preg_match("#^\d+[e|E]#", $str))
return FALSE;
return TRUE; return TRUE;
} }
function get_lan_file(){ function get_lan_file()
if(!isset($this->previous_steps['language'])) { {
if(!isset($this->previous_steps['language']))
{
$this->previous_steps['language'] = "English"; $this->previous_steps['language'] = "English";
} }
$this->lan_file = "{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}{$this->previous_steps['language']}/lan_installer.php"; $this->lan_file = "{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}{$this->previous_steps['language']}/lan_installer.php";
if(is_readable($this->lan_file)){ if(is_readable($this->lan_file))
{
include($this->lan_file); include($this->lan_file);
} elseif(is_readable("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}English/lan_installer.php")) { }
elseif(is_readable("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}English/lan_installer.php"))
{
include("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}English/lan_installer.php"); include("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}English/lan_installer.php");
} else { }
else
{
$this->raise_error("Fatal: Could not get valid language file for installation."); $this->raise_error("Fatal: Could not get valid language file for installation.");
} }
} }
function get_languages() { function get_languages()
{
$handle = opendir("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}"); $handle = opendir("{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}");
while ($file = readdir($handle)) { while ($file = readdir($handle))
{
if ($file != "." && $file != ".." && $file != "/" && $file != "CVS") { if ($file != "." && $file != ".." && $file != "/" && $file != "CVS") {
if(file_exists("./{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}{$file}/lan_installer.php")){ if(file_exists("./{$this->e107->e107_dirs['LANGUAGES_DIRECTORY']}{$file}/lan_installer.php")){
$lanlist[] = $file; $lanlist[] = $file;
@@ -725,9 +775,11 @@ This file has been generated by the installation script.
return $lanlist; return $lanlist;
} }
function finish_form($force_stage = false) { function finish_form($force_stage = false)
{
global $e_forms; global $e_forms;
if($this->previous_steps) { if($this->previous_steps)
{
$e_forms->add_hidden_data("previous_steps", base64_encode(serialize($this->previous_steps))); $e_forms->add_hidden_data("previous_steps", base64_encode(serialize($this->previous_steps)));
} }
$e_forms->add_hidden_data("stage", ($force_stage ? $force_stage : ($this->stage + 1))); $e_forms->add_hidden_data("stage", ($force_stage ? $force_stage : ($this->stage + 1)));
@@ -758,15 +810,18 @@ This file has been generated by the installation script.
} }
function create_tables() { function create_tables()
{
$link = mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']); $link = mysql_connect($this->previous_steps['mysql']['server'], $this->previous_steps['mysql']['user'], $this->previous_steps['mysql']['password']);
if(!$link) { if(!$link)
{
return nl2br(LANINS_084."\n\n<b>".LANINS_083."\n</b><i>".mysql_error($link)."</i>"); return nl2br(LANINS_084."\n\n<b>".LANINS_083."\n</b><i>".mysql_error($link)."</i>");
} }
$db_selected = mysql_select_db($this->previous_steps['mysql']['db'], $link); $db_selected = mysql_select_db($this->previous_steps['mysql']['db'], $link);
if(!$db_selected) { if(!$db_selected)
{
return nl2br(LANINS_085." '{$this->previous_steps['mysql']['db']}'\n\n<b>".LANINS_083."\n</b><i>".mysql_error($link)."</i>"); return nl2br(LANINS_085." '{$this->previous_steps['mysql']['db']}'\n\n<b>".LANINS_083."\n</b><i>".mysql_error($link)."</i>");
} }
@@ -782,10 +837,15 @@ This file has been generated by the installation script.
preg_match_all("/create(.*?)myisam;/si", $sql_data, $result ); preg_match_all("/create(.*?)myisam;/si", $sql_data, $result );
// Force UTF-8 again
$this->dbqry('SET NAMES `utf8`');
foreach ($result[0] as $sql_table) foreach ($result[0] as $sql_table)
{ {
//@TODO is this still in use?
preg_match("/CREATE TABLE\s(.*?)\s\(/si", $sql_table, $match); preg_match("/CREATE TABLE\s(.*?)\s\(/si", $sql_table, $match);
$tablename = $match[1]; $tablename = $match[1];
preg_match_all("/create(.*?)myisam;/si", $sql_data, $result ); preg_match_all("/create(.*?)myisam;/si", $sql_data, $result );
$sql_table = preg_replace("/create table\s/si", "CREATE TABLE {$this->previous_steps['mysql']['prefix']}", $sql_table); $sql_table = preg_replace("/create table\s/si", "CREATE TABLE {$this->previous_steps['mysql']['prefix']}", $sql_table);
if (!$this->dbqry($sql_table, $link)) if (!$this->dbqry($sql_table, $link))
@@ -810,9 +870,12 @@ This file has been generated by the installation script.
$pref_language = isset($this->previous_steps['language']) ? $this->previous_steps['language'] : "English"; $pref_language = isset($this->previous_steps['language']) ? $this->previous_steps['language'] : "English";
if (file_exists($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$pref_language."/lan_prefs.php")) { if (file_exists($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$pref_language."/lan_prefs.php"))
{
include_once($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$pref_language."/lan_prefs.php"); include_once($this->e107->e107_dirs['LANGUAGES_DIRECTORY'].$pref_language."/lan_prefs.php");
} else { }
else
{
include_once($this->e107->e107_dirs['LANGUAGES_DIRECTORY']."English/lan_prefs.php"); include_once($this->e107->e107_dirs['LANGUAGES_DIRECTORY']."English/lan_prefs.php");
} }
@@ -838,9 +901,9 @@ This file has been generated by the installation script.
'comment_characters' => '50', 'comment_characters' => '50',
'comment_postfix' => LANINS_097, // '[more ...]' 'comment_postfix' => LANINS_097, // '[more ...]'
'comment_title' => 0, 'comment_title' => 0,
'article_caption' => LANINS_098, // 'Articles' //obsolete 'article_caption' => LANINS_098, // 'Articles'
'articles_display' => '10', //obsolete 'articles_display' => '10',
'articles_mainlink' => LANINS_099, // 'Articles Front Page ...' //obsolete 'articles_mainlink' => LANINS_099, // 'Articles Front Page ...'
'newforumposts_caption' => LANINS_100, // 'Latest Forum Posts' 'newforumposts_caption' => LANINS_100, // 'Latest Forum Posts'
'newforumposts_display' => '10', 'newforumposts_display' => '10',
'forum_no_characters' => '20', 'forum_no_characters' => '20',
@@ -850,12 +913,12 @@ This file has been generated by the installation script.
'newforumposts_characters' => '50', 'newforumposts_characters' => '50',
'newforumposts_postfix' => LANINS_097, // '[more ...]' 'newforumposts_postfix' => LANINS_097, // '[more ...]'
'newforumposts_title' => 0, 'newforumposts_title' => 0,
'clock_caption' => LANINS_102, // 'Date / Time' 'clock_caption' => LANINS_102 // 'Date / Time'
'reviews_caption' => LANINS_103, // 'Reviews' //obsolete 'reviews_caption' => LANINS_103, // 'Reviews'
'reviews_display' => '10', //obsolete 'reviews_display' => '10',
'reviews_parents' => '1', //obsolete 'reviews_parents' => '1',
'reviews_mainlink' => LANINS_104, // 'Review Front Page ...' //obsolete 'reviews_mainlink' => LANINS_104, // 'Review Front Page ...'
'articles_parents' => '1' //obsolete 'articles_parents' => '1'
); );
$menu_conf = serialize($new_block); $menu_conf = serialize($new_block);
@@ -863,9 +926,12 @@ This file has been generated by the installation script.
$this->dbqry("INSERT INTO {$this->previous_steps['mysql']['prefix']}core VALUES ('menu_pref', '{$menu_conf}') "); $this->dbqry("INSERT INTO {$this->previous_steps['mysql']['prefix']}core VALUES ('menu_pref', '{$menu_conf}') ");
preg_match("/^(.*?)($|-)/", mysql_get_server_info(), $mysql_version); preg_match("/^(.*?)($|-)/", mysql_get_server_info(), $mysql_version);
if (version_compare($mysql_version[1], '4.0.1', '<')) { if (version_compare($mysql_version[1], '4.0.1', '<'))
{
$search_prefs = 'a:12:{s:11:\"user_select\";s:1:\"1\";s:9:\"time_secs\";s:2:\"60\";s:13:\"time_restrict\";s:1:\"0\";s:8:\"selector\";s:1:\"2\";s:9:\"relevance\";s:1:\"0\";s:13:\"plug_handlers\";N;s:10:\"mysql_sort\";b:0;s:11:\"multisearch\";s:1:\"1\";s:6:\"google\";s:1:\"0\";s:13:\"core_handlers\";a:5:{s:4:\"news\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"1\";}s:8:\"comments\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"2\";}s:5:\"users\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"3\";}s:9:\"downloads\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"4\";}s:5:\"pages\";a:6:{s:5:\"class\";s:1:\"0\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"order\";s:1:\"5\";}}s:17:\"comments_handlers\";a:2:{s:4:\"news\";a:3:{s:2:\"id\";i:0;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}s:8:\"download\";a:3:{s:2:\"id\";i:2;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}}s:9:\"php_limit\";s:0:\"\";}'; $search_prefs = 'a:12:{s:11:\"user_select\";s:1:\"1\";s:9:\"time_secs\";s:2:\"60\";s:13:\"time_restrict\";s:1:\"0\";s:8:\"selector\";s:1:\"2\";s:9:\"relevance\";s:1:\"0\";s:13:\"plug_handlers\";N;s:10:\"mysql_sort\";b:0;s:11:\"multisearch\";s:1:\"1\";s:6:\"google\";s:1:\"0\";s:13:\"core_handlers\";a:5:{s:4:\"news\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"1\";}s:8:\"comments\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"2\";}s:5:\"users\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"3\";}s:9:\"downloads\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"4\";}s:5:\"pages\";a:6:{s:5:\"class\";s:1:\"0\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"order\";s:1:\"5\";}}s:17:\"comments_handlers\";a:2:{s:4:\"news\";a:3:{s:2:\"id\";i:0;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}s:8:\"download\";a:3:{s:2:\"id\";i:2;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}}s:9:\"php_limit\";s:0:\"\";}';
} else { }
else
{
$search_prefs = 'a:12:{s:11:\"user_select\";s:1:\"1\";s:9:\"time_secs\";s:2:\"60\";s:13:\"time_restrict\";s:1:\"0\";s:8:\"selector\";s:1:\"2\";s:9:\"relevance\";s:1:\"0\";s:13:\"plug_handlers\";N;s:10:\"mysql_sort\";b:1;s:11:\"multisearch\";s:1:\"1\";s:6:\"google\";s:1:\"0\";s:13:\"core_handlers\";a:5:{s:4:\"news\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"1\";}s:8:\"comments\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"2\";}s:5:\"users\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"3\";}s:9:\"downloads\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"4\";}s:5:\"pages\";a:6:{s:5:\"class\";s:1:\"0\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"order\";s:1:\"5\";}}s:17:\"comments_handlers\";a:2:{s:4:\"news\";a:3:{s:2:\"id\";i:0;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}s:8:\"download\";a:3:{s:2:\"id\";i:2;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}}s:9:\"php_limit\";s:0:\"\";}'; $search_prefs = 'a:12:{s:11:\"user_select\";s:1:\"1\";s:9:\"time_secs\";s:2:\"60\";s:13:\"time_restrict\";s:1:\"0\";s:8:\"selector\";s:1:\"2\";s:9:\"relevance\";s:1:\"0\";s:13:\"plug_handlers\";N;s:10:\"mysql_sort\";b:1;s:11:\"multisearch\";s:1:\"1\";s:6:\"google\";s:1:\"0\";s:13:\"core_handlers\";a:5:{s:4:\"news\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"1\";}s:8:\"comments\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"2\";}s:5:\"users\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"3\";}s:9:\"downloads\";a:6:{s:5:\"class\";s:1:\"0\";s:9:\"pre_title\";s:1:\"1\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:5:\"order\";s:1:\"4\";}s:5:\"pages\";a:6:{s:5:\"class\";s:1:\"0\";s:5:\"chars\";s:3:\"150\";s:7:\"results\";s:2:\"10\";s:9:\"pre_title\";s:1:\"0\";s:13:\"pre_title_alt\";s:0:\"\";s:5:\"order\";s:1:\"5\";}}s:17:\"comments_handlers\";a:2:{s:4:\"news\";a:3:{s:2:\"id\";i:0;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}s:8:\"download\";a:3:{s:2:\"id\";i:2;s:3:\"dir\";s:4:\"core\";s:5:\"class\";s:1:\"0\";}}s:9:\"php_limit\";s:0:\"\";}';
} }
$this->dbqry("INSERT INTO {$this->previous_steps['mysql']['prefix']}core VALUES ('search_prefs', '{$search_prefs}') "); $this->dbqry("INSERT INTO {$this->previous_steps['mysql']['prefix']}core VALUES ('search_prefs', '{$search_prefs}') ");
@@ -929,9 +995,11 @@ This file has been generated by the installation script.
return false; return false;
} }
function write_config($data) { function write_config($data)
{
$fp = @fopen("e107_config.php", "w"); $fp = @fopen("e107_config.php", "w");
if (!@fwrite($fp, $data)) { if (!@fwrite($fp, $data))
{
@fclose ($fp); @fclose ($fp);
return nl2br(LANINS_070); return nl2br(LANINS_070);
} }
@@ -959,34 +1027,42 @@ class e_forms {
var $form; var $form;
var $opened; var $opened;
function start_form($id, $action, $method = "post" ) { function start_form($id, $action, $method = "post" )
{
$this->form = "\n<form method='{$method}' id='{$id}' action='{$action}'>\n"; $this->form = "\n<form method='{$method}' id='{$id}' action='{$action}'>\n";
$this->opened = true; $this->opened = true;
} }
function add_select_item($id, $labels, $selected) { function add_select_item($id, $labels, $selected)
{
$this->form .= " $this->form .= "
<select name='{$id}' id='{$id}'>\n"; <select name='{$id}' id='{$id}'>\n";
foreach ($labels as $label) { foreach ($labels as $label)
{
$this->form .= "<option".($label == $selected ? " selected='selected'" : "").">{$label}</option>\n"; $this->form .= "<option".($label == $selected ? " selected='selected'" : "").">{$label}</option>\n";
} }
$this->form .= "</select>\n"; $this->form .= "</select>\n";
} }
function add_button($id, $title, $align = "right", $type = "submit") { function add_button($id, $title, $align = "right", $type = "submit")
{
$this->form .= "<div style='text-align: {$align}; z-index: 10;'><input type='{$type}' id='{$id}' value='{$title}' /></div>\n"; $this->form .= "<div style='text-align: {$align}; z-index: 10;'><input type='{$type}' id='{$id}' value='{$title}' /></div>\n";
} }
function add_hidden_data($id, $data) { function add_hidden_data($id, $data)
{
$this->form .= "<input type='hidden' name='{$id}' value='{$data}' />\n"; $this->form .= "<input type='hidden' name='{$id}' value='{$data}' />\n";
} }
function add_plain_html($html_data) { function add_plain_html($html_data)
{
$this->form .= $html_data; $this->form .= $html_data;
} }
function return_form() { function return_form()
if($this->opened == true) { {
if($this->opened == true)
{
$this->form .= "</form>\n"; $this->form .= "</form>\n";
} }
$this->opened = false; $this->opened = false;
@@ -1041,45 +1117,56 @@ function create_tables_unattended()
} }
class SimpleTemplate { class SimpleTemplate
{
var $Tags = array(); var $Tags = array();
var $open_tag = "{"; var $open_tag = "{";
var $close_tag = "}"; var $close_tag = "}";
function SimpleTemplate() { function SimpleTemplate()
{
define("TEMPLATE_TYPE_FILE", 0); define("TEMPLATE_TYPE_FILE", 0);
define("TEMPLATE_TYPE_DATA", 1); define("TEMPLATE_TYPE_DATA", 1);
} }
function SetTag($TagName, $Data) { function SetTag($TagName, $Data)
{
$this->Tags[$TagName] = array( 'Tag' => $TagName, $this->Tags[$TagName] = array( 'Tag' => $TagName,
'Data' => $Data 'Data' => $Data
); );
} }
function RemoveTag($TagName) { function RemoveTag($TagName)
{
unset($this->Tags[$TagName]); unset($this->Tags[$TagName]);
} }
function ClearTags() { function ClearTags()
{
$this->Tags = array(); $this->Tags = array();
} }
function ParseTemplate($Template, $template_type = TEMPLATE_TYPE_FILE) { function ParseTemplate($Template, $template_type = TEMPLATE_TYPE_FILE)
if($template_type == TEMPLATE_TYPE_DATA) { {
if($template_type == TEMPLATE_TYPE_DATA)
{
$TemplateData = $Template; $TemplateData = $Template;
} else { }
else
{
$TemplateData = file_get_contents($Template); $TemplateData = file_get_contents($Template);
} }
foreach ($this->Tags as $Tag) { foreach ($this->Tags as $Tag)
{
$TemplateData = str_replace($this->open_tag.$Tag['Tag'].$this->close_tag, $Tag['Data'], $TemplateData); $TemplateData = str_replace($this->open_tag.$Tag['Tag'].$this->close_tag, $Tag['Data'], $TemplateData);
} }
return $TemplateData; return $TemplateData;
} }
} }
function template_data() { function template_data()
{
$data = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"> $data = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\"> <html xmlns=\"http://www.w3.org/1999/xhtml\">
<head> <head>
@@ -1113,9 +1200,11 @@ function template_data() {
return $data; return $data;
} }
function get_object($name) { function get_object($name)
switch ($name) { {
case "stylesheet"; switch ($name)
{
case "stylesheet":
header("Content-type: text/css"); header("Content-type: text/css");
echo "#container{ echo "#container{
float:left; float:left;
@@ -2161,4 +2250,3 @@ R0lGODlhAwABAJEAAAAAAP///1xcXP///yH5BAEAAAMALAAAAAADAAEAAAIC1FYAOw=="));
break; break;
} }
} }
?>