diff --git a/class2.php b/class2.php
index 01cfe524c..f5194bc0a 100644
--- a/class2.php
+++ b/class2.php
@@ -9,9 +9,9 @@
* General purpose file
*
* $Source: /cvs_backup/e107_0.8/class2.php,v $
-* $Revision: 1.111 $
-* $Date: 2009-07-21 14:20:12 $
-* $Author: e107coders $
+* $Revision: 1.112 $
+* $Date: 2009-07-21 16:11:02 $
+* $Author: secretr $
*
*/
//
@@ -195,7 +195,7 @@ if(!isset($ADMIN_DIRECTORY))
e107_require_once(realpath(dirname(__FILE__).'/'.$HANDLERS_DIRECTORY).'/e107_class.php');
$e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY');
$e107 = e107::getInstance();
-$e107->_init($e107_paths, realpath(dirname(__FILE__)));
+$e107->init($e107_paths, realpath(dirname(__FILE__)));
$inArray = array("'", ';', '/**/', '/UNION/', '/SELECT/', 'AS ');
if (strpos($_SERVER['PHP_SELF'], 'trackback') === false)
diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php
index c6a8a95b4..822929828 100644
--- a/e107_handlers/e107_class.php
+++ b/e107_handlers/e107_class.php
@@ -1,26 +1,23 @@
e107_dirs = $e107_paths;
- $this->set_paths();
- $this->file_path = $this->fix_windows_paths($e107_root_path)."/";
+ return $this->_init($e107_paths, $e107_root_path);
+ }
+
+ /**
+ * Resolve paths, will run only once
+ *
+ * @return e107
+ */
+ protected function _init($e107_paths, $e107_root_path)
+ {
+ if(empty($this->e107_dirs))
+ {
+ $this->e107_dirs = $e107_paths;
+ $this->set_paths();
+ $this->file_path = $this->fix_windows_paths($e107_root_path)."/";
+ }
+ return $this;
+ }
+
+ /**
+ * Get data from the registry
+ * Returns $default if data not found
+ * Replacement of cachevar()
+ *
+ * @param string $id
+ * @return mixed
+ */
+ public static function getRegistry($id, $default = null)
+ {
+ if(isset(self::$_registry[$id]))
+ {
+ return self::$_registry[$id];
+ }
+
+ return $default;
+ }
+
+ /**
+ * Add data to the registry - replacement of getcachedvars().
+ * $id is path-like unique id bind to the passed data.
+ * If $data argument is null, $id will be removed from the registry.
+ * When removing objects from the registry, __destruct() method will be auto-executed
+ * if available
+ *
+ * Naming standards (namespaces):
+ * 'area/area_id/storage_type'
+ * where
+ * - area = 'core'|'plugin'|'external' (everything else)
+ * - area_id = core handler id|plugin name (depends on area)
+ * - (optional) storage_type = current data storage stack
+ *
+ * Examples:
+ * - 'core/e107/' - reserved for this class
+ * - 'core/e107/singleton/' - singleton objects repo {@link getSingleton()}
+ *
+ * @param string $id
+ * @param mixed|null $data
+ * @return void
+ */
+ public static function setRegistry($id, $data = null, $allow_override = true)
+ {
+ if(null === $data)
+ {
+ if(is_object(self::$_registry[$id]) && method_exists(self::$_registry[$id], '__destruct'))
+ {
+ self::$_registry[$id]->__destruct();
+ }
+ unset(self::$_registry[$id]);
+ return;
+ }
+
+ if(!$allow_override && null !== self::getRegistry($id))
+ {
+ return;
+ }
+
+ self::$_registry[$id] = $data;
+ }
+
+ /**
+ * Retrieve singleton object
+ *
+ * @param string $class_name
+ * @param string $path optional script path
+ * @return Object
+ */
+ public static function getSingleton($class_name, $path = null)
+ {
+ $id = 'core/e107/singleton/'.$class_name;
+ if(!e107::getRegistry($id))
+ {
+ if(null !== $path)
+ {
+ require_once($path); //no existence/security checks here!
+ }
+ if(class_exists($class_name))
+ {
+ e107::setRegistry($id, new $class_name());
+ }
+ }
+
+ return self::getRegistry($id);
+ }
+
+ /**
+ * Retrieve object
+ * We prepare for __autoload
+ *
+ * @param string $class_name
+ * @param mxed $arguments
+ * @param string $path optional script path
+ * @return object|null
+ */
+ public static function getObject($class_name, $arguments = null, $path = null)
+ {
+ if(null !== $path)
+ {
+ require_once($path); //no existence/security checks here!
+ }
+ if(class_exists($class_name))
+ {
+ if(null !== $arguments) return $class_name($arguments);
+ return $class_name();
+ }
+
+ //trigger_error("Class {$class_name} not found!", E_USER_ERROR);
+ return null;
+ }
+
+ /**
+ * Retrieve text parser singleton object
+ *
+ * @return e_parse
+ */
+ public static function getParser()
+ {
+ return self::getSingleton('e_parse', e_HANDLER.'e_parse_class.php');
}
/**
- * Get instance - php4 singleton implementation
- *
- * @return singleton object
+ * @return e107
*/
- function &getInstance()
- {
- static $instance = array();//it's array because of an odd PHP 4 bug
-
- if(!$instance)
- {
- $instance[0] = new e107('e107_class_php4_very_long_hard_to_remember_check');
- }
- return $instance[0];
- }
-
- function set_base_path()
+ public function set_base_path()
{
global $pref;
- $this->base_path = ($pref['ssl_enabled']==1 ? $this->https_path : $this->http_path);
+ $this->base_path = ($pref['ssl_enabled'] == 1 ? $this->https_path : $this->http_path);
+ return $this;
}
- function set_paths()
+ /**
+ * Set all environment vars and constants
+ *
+ */
+ public function set_paths()
{
global $DOWNLOADS_DIRECTORY, $ADMIN_DIRECTORY, $IMAGES_DIRECTORY, $THEMES_DIRECTORY, $PLUGINS_DIRECTORY,
$FILES_DIRECTORY, $HANDLERS_DIRECTORY, $LANGUAGES_DIRECTORY, $HELP_DIRECTORY, $CACHE_DIRECTORY,
@@ -218,6 +382,12 @@ class e107
}
}
+ /**
+ * Fix Windows server path
+ *
+ * @param string $path resolved server path
+ * @return string fixed path
+ */
function fix_windows_paths($path)
{
$fixed_path = str_replace(array('\\\\', '\\'), array('/', '/'), $path);
@@ -227,159 +397,180 @@ class e107
/**
* Check if current user is banned
- *
+ *
+ * XXX add more description? return type e107?
+ * @return void
*/
- function ban()
+ public function ban()
{
- global $sql, $e107, $tp, $pref;
+ global $sql, $pref;
$ban_count = $sql->db_Count("banlist");
if($ban_count)
{
$vals = array();
- $ip = $this->getip(); // This will be in normalised IPV6 form
- if ($ip != 'x.x.x.x')
+ $ip = $this->getip(); // This will be in normalised IPV6 form
+ if($ip!='x.x.x.x')
{
- $vals[] = $ip; // Always look for exact match
- if (strpos($ip,'0000:0000:0000:0000:0000:ffff:') === 0)
- { // It's an IPV4 address
- $vals[] = substr($ip,0,-2).'*';
- $vals[] = substr($ip,0,-4).'*';
- $vals[] = substr($ip,0,-7).'*'; // Knock off colon as well here
+ $vals[] = $ip; // Always look for exact match
+ if(strpos($ip, '0000:0000:0000:0000:0000:ffff:')===0)
+ { // It's an IPV4 address
+ $vals[] = substr($ip, 0, -2).'*';
+ $vals[] = substr($ip, 0, -4).'*';
+ $vals[] = substr($ip, 0, -7).'*'; // Knock off colon as well here
}
else
- { // Its an IPV6 address - ban in blocks of 16 bits
- $vals[] = substr($ip,0,-4).'*';
- $vals[] = substr($ip,0,-9).'*';
- $vals[] = substr($ip,0,-14).'*';
+ { // Its an IPV6 address - ban in blocks of 16 bits
+ $vals[] = substr($ip, 0, -4).'*';
+ $vals[] = substr($ip, 0, -9).'*';
+ $vals[] = substr($ip, 0, -14).'*';
}
}
-
- if(varsettrue($pref['enable_rdns']))
- {
- $tmp = array_reverse(explode('.',$addr = $e107->get_host_name(getenv('REMOTE_ADDR'))));
- $line = '';
-// $vals[] = $addr;
- foreach ($tmp as $e)
- {
- $line = '.'.$e.$line;
- $vals[] = '*'.$line;
- }
+ if(varsettrue($pref['enable_rdns']))
+ {
+ $tmp = array_reverse(explode('.', $this->get_host_name(getenv('REMOTE_ADDR'))));
+ $line = '';
+ // $vals[] = $addr;
+ foreach($tmp as $e)
+ {
+ $line = '.'.$e.$line;
+ $vals[] = '*'.$line;
+ }
+ }
+ if((defined('USEREMAIL')&&USEREMAIL))
+ {
+ $vals[] = USEREMAIL;
+ }
+ if(($ip!='127.0.0.1')&&count($vals))
+ {
+ $match = "`banlist_ip`='".implode("' OR `banlist_ip`='", $vals)."'";
+ $this->check_ban($match);
+ }
}
-
- if ((defined('USEREMAIL') && USEREMAIL))
- {
- $vals[] = USEREMAIL;
- }
-
- if (($ip != '127.0.0.1') && count($vals))
- {
- $match = "`banlist_ip`='".implode("' OR `banlist_ip`='",$vals)."'";
- $this->check_ban($match);
- }
- }
}
-
- // Check the banlist table. $query is used to determine the match.
- // If $show_error, displays "HTTP/1.1 403 Forbidden"
- // If $do_return, will always return with ban status - TRUE for OK, FALSE for banned.
- // If return permitted, will never display a message for a banned user; otherwise will display any message then exit
- function check_ban($query,$show_error=TRUE, $do_return = FALSE)
+ /**
+ * Check the banlist table. $query is used to determine the match.
+ * If $do_return, will always return with ban status - TRUE for OK, FALSE for banned.
+ * If return permitted, will never display a message for a banned user; otherwise will display any message then exit
+ * XXX - clean up
+ *
+ * @param string $query
+ * @param boolean $show_error
+ * @param boolean $do_return
+ * @return boolean
+ */
+ public function check_ban($query, $show_error = TRUE, $do_return = FALSE)
{
- global $sql, $tp, $pref, $admin_log, $e107;
-// $admin_log->e_log_event(4,__FILE__."|".__FUNCTION__."@".__LINE__,"DBG","Check for Ban",$query,FALSE,LOG_TO_ROLLING);
- if ($sql->db_Select('banlist','*',$query.' ORDER BY `banlist_bantype` DESC'))
+ global $sql, $tp, $pref, $admin_log;
+ //$admin_log->e_log_event(4,__FILE__."|".__FUNCTION__."@".__LINE__,"DBG","Check for Ban",$query,FALSE,LOG_TO_ROLLING);
+ if($sql->db_Select('banlist', '*', $query.' ORDER BY `banlist_bantype` DESC'))
{
// Any whitelist entries will be first - so we can answer based on the first DB record read
- define('BAN_TYPE_WHITELIST',100); // Entry for whitelist
+ define('BAN_TYPE_WHITELIST', 100); // Entry for whitelist
$row = $sql->db_Fetch();
- if ($row['banlist_bantype'] >= BAN_TYPE_WHITELIST)
+ if($row['banlist_bantype']>=BAN_TYPE_WHITELIST)
{
- // $admin_log->e_log_event(4,__FILE__."|".__FUNCTION__."@".__LINE__,"DBG","Whitelist hit",$query,FALSE,LOG_TO_ROLLING);
+ //$admin_log->e_log_event(4,__FILE__."|".__FUNCTION__."@".__LINE__,"DBG","Whitelist hit",$query,FALSE,LOG_TO_ROLLING);
return TRUE;
}
-
// Found banlist entry in table here
- if (($row['banlist_banexpires'] > 0) && ($row['banlist_banexpires'] < time()))
- { // Ban has expired - delete from DB
+ if(($row['banlist_banexpires']>0)&&($row['banlist_banexpires']