Better autoload for required files

Add autoload function to main config file.
Add better DIR declarations in config file based on __DIR__ for libs &
smarty classes.
Load all class files with the new autoload function in header & direct
file calls.
This commit is contained in:
Clemens Schwaighofer
2015-11-11 14:14:06 +09:00
parent 5a1c9f87c2
commit b2fdbc0571
13 changed files with 63 additions and 82 deletions

View File

@@ -26,12 +26,7 @@
*********************************************************************/
// try to include file from LIBS path, or from normal path
$include_file = 'Class.DB.IO.inc';
foreach (array('', LIBS, __DIR__.'/') as $folder)
{
if (file_exists($folder.$include_file))
require_once($folder.$include_file);
}
_spl_autoload('Class.DB.IO.inc');
class AdminBackend extends db_io
{
@@ -72,7 +67,7 @@
public function __construct($db_config, $lang, $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
{
// get the language sub class & init it
require_once(LIBS."Class.l10n.inc");
_spl_autoload('Class.l10n.inc');
$this->l = new l10n($lang);
@@ -144,8 +139,8 @@
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ";
$q .= "(".$_SESSION['EUID'].", NOW(), '".$this->db_escape_string($event)."', '".$data."', '".$data_binary."', '".$this->page_name."', ";
$q .= "'".$_SERVER["REMOTE_ADDR"]."', '".$this->db_escape_string($_SERVER['HTTP_USER_AGENT'])."', '".$this->db_escape_string($_SERVER['HTTP_REFERER'])."', '".$this->db_escape_string($_SERVER['SCRIPT_FILENAME'])."', '".$this->db_escape_string($_SERVER['QUERY_STRING'])."', '".$this->db_escape_string($_SERVER['SERVER_NAME'])."', '".$this->db_escape_string($_SERVER['HTTP_HOST'])."', '".$this->db_escape_string($_SERVER['HTTP_ACCEPT'])."', '".$this->db_escape_string($_SERVER['HTTP_ACCEPT_CHARSET'])."', '".$this->db_escape_string($_SERVER['HTTP_ACCEPT_ENCODING'])."', '".session_id()."', ";
$q .= "(".@$_SESSION['EUID'].", NOW(), '".$this->db_escape_string($event)."', '".$data."', '".$data_binary."', '".$this->page_name."', ";
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->db_escape_string(@$_SERVER['HTTP_USER_AGENT'])."', '".$this->db_escape_string(@$_SERVER['HTTP_REFERER'])."', '".$this->db_escape_string(@$_SERVER['SCRIPT_FILENAME'])."', '".$this->db_escape_string(@$_SERVER['QUERY_STRING'])."', '".$this->db_escape_string(@$_SERVER['SERVER_NAME'])."', '".$this->db_escape_string(@$_SERVER['HTTP_HOST'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_CHARSET'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_ENCODING'])."', '".session_id()."', ";
$q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->action_id)."', '".$this->db_escape_string($this->action_yes)."', '".$this->db_escape_string($this->action_flag)."', '".$this->db_escape_string($this->action_menu)."', '".$this->db_escape_string($this->action_loaded)."', '".$this->db_escape_string($this->action_value)."', '".$this->db_escape_string($this->action_error)."')";
$this->db_exec($q, 'edit_log_id');
}

View File

@@ -39,12 +39,7 @@
// put into separete function in this class)
// try to include file from LIBS path, or from normal path
$include_file = 'Class.DB.IO.inc';
foreach (array('', LIBS, __DIR__.'/') as $folder)
{
if (file_exists($folder.$include_file))
require_once($folder.$include_file);
}
_spl_autoload('Class.DB.IO.inc');
// subclass for one array handling
class db_array_io extends db_io

View File

@@ -241,12 +241,7 @@
*********************************************************************/
// try to include file from LIBS path, or from normal path
$include_file = 'Class.Basic.inc';
foreach (array('', LIBS, __DIR__.'/') as $folder)
{
if (file_exists($folder.$include_file))
require_once($folder.$include_file);
}
_spl_autoload('Class.Basic.inc');
class db_io extends basic
{

View File

@@ -213,12 +213,7 @@
*********************************************************************/
// try to include file from LIBS path, or from normal path
$include_file = 'Class.DB.Array.IO.inc';
foreach (array('', LIBS, __DIR__.'/') as $folder)
{
if (file_exists($folder.$include_file))
require_once($folder.$include_file);
}
_spl_autoload('Class.DB.Array.IO.inc');
class form extends db_array_io
{
@@ -260,7 +255,7 @@
{
$this->my_page_name = $this->get_page_name(1);
// init the language class
require_once(LIBS."Class.l10n.inc");
_spl_autoload('Class.l10n.inc');
$this->l = new l10n($lang);
// load config array
// get table array definitions for current page name

View File

@@ -60,12 +60,7 @@
*********************************************************************/
// try to include file from LIBS path, or from normal path
$include_file = 'Class.DB.IO.inc';
foreach (array('', LIBS, __DIR__.'/') as $folder)
{
if (file_exists($folder.$include_file))
require_once($folder.$include_file);
}
_spl_autoload('Class.DB.IO.inc');
class login extends db_io
{
@@ -118,7 +113,7 @@
$this->file_name_ext = '_login_'.date('Y-m-d').'.log';
// get the language sub class & init it
require_once(LIBS."Class.l10n.inc");
_spl_autoload('Class.l10n.inc');
$this->l = new l10n($lang);
// if we have a search path we need to set it, to use the correct DB to login

View File

@@ -11,12 +11,7 @@
// read in the Smarty class for definition
// use smarty BC for backwards compability
// try to include file from LIBS path, or from normal path
$include_file = 'SmartyBC.class.php';
foreach (array('', SMARTY, __DIR__.'/../'.SMARTY) as $folder)
{
if (file_exists($folder.$include_file))
require_once($folder.$include_file);
}
_spl_autoload('SmartyBC.class.php');
class SmartyML extends SmartyBC
{
@@ -26,7 +21,7 @@
public function __construct($lang)
{
SmartyBC::__construct();
require_once(LIBS."Class.l10n.inc");
_spl_autoload('Class.l10.inc');
$this->l10n = new l10n($lang);
// variable variable register
$this->register_modifier('getvar', array(&$this, 'get_template_vars'));

View File

@@ -26,12 +26,7 @@
*********************************************************************/
// try to include file from LIBS path, or from normal path
$include_file = 'Class.Basic.inc';
foreach (array('', LIBS, __DIR__.'/') as $folder)
{
if (file_exists($folder.$include_file))
require_once($folder.$include_file);
}
_spl_autoload('Class.Basic.inc');
class l10n extends basic
{
@@ -42,8 +37,8 @@
public function __construct($lang = '', $path = '')
{
require_once(LIBS.'streams.php');
require_once(LIBS.'gettext.php');
foreach (array('streas.php', 'gettext.php') as $include_file)
_spl_autoload($include_file);
if (!$lang)
$this->lang = 'en';
@@ -109,6 +104,4 @@
return $this->l10n->ngettext($single, $plural, $number);
}
}
//require(LIBS.'locale.php');
?>