2007-04-12 08:10:20 +00:00
< ? php
2006-12-02 04:36:16 +00:00
/*
2009-07-21 16:11:02 +00:00
* e107 website system
*
2012-01-11 13:18:22 +00:00
* Copyright ( C ) 2008 - 2012 e107 Inc ( e107 . org )
2009-07-21 16:11:02 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* e107 Main
*
2010-03-10 12:48:05 +00:00
* $URL $
* $Id $
2006-12-02 04:36:16 +00:00
*/
if ( ! defined ( 'e107_INIT' )) { exit ; }
2010-01-04 21:35:38 +00:00
2006-12-02 04:36:16 +00:00
/**
2010-02-09 20:43:54 +00:00
*
2010-01-04 21:35:38 +00:00
* @ package e107
2010-05-02 18:41:20 +00:00
* @ category e107_handlers
2010-03-10 12:48:05 +00:00
* @ version $Id $
* @ author e107inc
2006-12-02 04:36:16 +00:00
*
2010-01-04 21:35:38 +00:00
* e107_class - core class with many system - related methods
2006-12-02 04:36:16 +00:00
*/
2010-01-04 21:35:38 +00:00
2008-05-16 19:40:39 +00:00
class e107
{
2009-11-24 16:41:10 +00:00
/**
* IPV6 string for localhost - as stored in DB
*/
const LOCALHOST_IP = '0000:0000:0000:0000:0000:ffff:7f00:0001' ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
public $server_path ;
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
public $e107_dirs = array ();
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
/**
* @ var array SQL connection data
*/
protected $e107_config_mysql_info = array ();
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
public $http_path ;
public $https_path ;
public $base_path ;
public $file_path ;
2012-06-08 06:03:07 +00:00
public $site_path ;
2009-07-23 15:29:07 +00:00
public $relative_base_path ;
public $_ip_cache ;
public $_host_name_cache ;
2009-12-02 16:51:04 +00:00
2011-05-03 22:13:59 +00:00
public $site_theme ; // class2 -> check valid theme
public $http_theme_dir ; // class2 -> check valid theme
2009-12-02 16:51:04 +00:00
2010-05-13 15:47:31 +00:00
/**
* Contains reference to global $_E107 array
* Assignment is done inside prepare_request () method
*
* @ var array
*/
protected $_E107 = array ();
2009-11-24 16:30:08 +00:00
/**
* @ var string Current request type ( http or https )
*/
protected $HTTP_SCHEME ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
/**
* Used for runtime caching of user extended struct
*
* @ var array
* @ see get_user_data ()
*/
public $extended_struct ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
/**
* User login name
*
* @ var string
* @ see init_session ()
*/
public $currentUser = '' ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
/**
* Run once load core shortcodes
* while initialize SC parser
*
2009-09-04 20:38:36 +00:00
* @ var boolean
2009-07-23 15:29:07 +00:00
*/
protected static $_sc_core_loaded = false ;
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* Singleton instance
* Allow class extends - override { @ link getInstance ()}
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* @ var e107
*/
protected static $_instance = null ;
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* e107 registry
*
* @ var array
*/
private static $_registry = array ();
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
* e107 core config object storage
*
* @ var array
*/
protected static $_core_config_arr = array ();
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
* e107 plugin config object storage
*
* @ var array
*/
protected static $_plug_config_arr = array ();
2009-12-02 16:51:04 +00:00
2009-08-19 14:39:57 +00:00
/**
* Core handlers array
2009-12-02 16:51:04 +00:00
* For new / missing handler add
2009-08-20 12:24:47 +00:00
* 'class name' => 'path' pair
2009-12-02 16:51:04 +00:00
*
2010-02-02 15:25:22 +00:00
* Used to auto - load core / plugin handlers
* NOTE : aplhabetically sorted ! ( by class name )
2009-08-19 14:39:57 +00:00
*
2010-02-02 15:25:22 +00:00
* @ see addHandler ()
* @ see setHandlerOverload ()
2009-08-19 14:39:57 +00:00
* @ see getSingleton ()
* @ see getObject ()
* @ var array
*/
2010-02-02 15:49:09 +00:00
protected static $_known_handlers = array (
2010-02-02 15:25:22 +00:00
'UserHandler' => '{e_HANDLER}user_handler.php' ,
'comment' => '{e_HANDLER}comment_class.php' ,
'convert' => '{e_HANDLER}date_handler.php' ,
'db' => '{e_HANDLER}mysql_class.php' ,
'e107Email' => '{e_HANDLER}mail.php' ,
'e107_event' => '{e_HANDLER}event_class.php' ,
2013-03-01 15:50:31 -08:00
'e107_db_debug' => '{e_HANDLER}db_debug_class.php' ,
2010-02-02 15:25:22 +00:00
'e107_traffic' => '{e_HANDLER}traffic_class.php' ,
'e107_user_extended' => '{e_HANDLER}user_extended_class.php' ,
'e107plugin' => '{e_HANDLER}plugin_class.php' ,
2013-05-14 23:46:48 -07:00
'e_chart' => '{e_HANDLER}chart_class.php' ,
2011-05-03 22:13:59 +00:00
'e_core_session' => '{e_HANDLER}session_handler.php' ,
2010-02-02 15:25:22 +00:00
'e_admin_controller' => '{e_HANDLER}admin_ui.php' ,
'e_admin_controller_ui' => '{e_HANDLER}admin_ui.php' ,
'e_admin_dispatcher' => '{e_HANDLER}admin_ui.php' ,
'e_admin_form_ui' => '{e_HANDLER}admin_ui.php' ,
'e_admin_log' => '{e_HANDLER}admin_log_class.php' ,
'e_admin_model' => '{e_HANDLER}model_class.php' ,
'e_admin_request' => '{e_HANDLER}admin_ui.php' ,
'e_admin_response' => '{e_HANDLER}admin_ui.php' ,
'e_admin_ui' => '{e_HANDLER}admin_ui.php' ,
2013-02-26 19:12:17 -08:00
'e_array' => '{e_HANDLER}core_functions.php' , // Old ArrayStorage.
2012-05-11 03:52:57 +00:00
'e_bbcode' => '{e_HANDLER}bbcode_handler.php' ,
2013-10-24 02:50:45 +03:00
'e_bb_base' => '{e_HANDLER}bbcode_handler.php' ,
2010-02-02 15:25:22 +00:00
'e_file' => '{e_HANDLER}file_class.php' ,
'e_form' => '{e_HANDLER}form_handler.php' ,
'e_jshelper' => '{e_HANDLER}js_helper.php' ,
2010-03-22 15:45:47 +00:00
'e_media' => '{e_HANDLER}media_class.php' ,
2010-02-02 15:25:22 +00:00
'e_menu' => '{e_HANDLER}menu_class.php' ,
'e_model' => '{e_HANDLER}model_class.php' ,
2013-02-26 17:17:31 -08:00
'e_navigation' => '{e_HANDLER}sitelinks_class.php' ,
2010-02-02 15:25:22 +00:00
'e_news_item' => '{e_HANDLER}news_class.php' ,
'e_news_tree' => '{e_HANDLER}news_class.php' ,
2011-05-03 22:13:59 +00:00
'e_object' => '{e_HANDLER}model_class.php' ,
2010-02-02 15:25:22 +00:00
'e_online' => '{e_HANDLER}online_class.php' ,
'e_parse' => '{e_HANDLER}e_parse_class.php' ,
2010-04-23 15:54:11 +00:00
'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php' ,
2010-03-13 18:59:28 +00:00
'e_ranks' => '{e_HANDLER}e_ranks_class.php' ,
2010-04-24 11:39:14 +00:00
'e_shortcode' => '{e_HANDLER}shortcode_handler.php' ,
2011-11-25 17:24:42 +00:00
'e_system_user' => '{e_HANDLER}user_model.php' ,
2010-02-02 15:25:22 +00:00
'e_upgrade' => '{e_HANDLER}e_upgrade_class.php' ,
2010-03-22 15:45:47 +00:00
'e_user_model' => '{e_HANDLER}user_model.php' ,
'e_user' => '{e_HANDLER}user_model.php' ,
2010-05-02 18:41:20 +00:00
'e_user_extended_structure_tree' => '{e_HANDLER}user_model.php' ,
2010-02-02 15:25:22 +00:00
'e_userperms' => '{e_HANDLER}user_handler.php' ,
'e_validator' => '{e_HANDLER}validator_class.php' ,
2011-05-03 22:13:59 +00:00
'e_vars' => '{e_HANDLER}model_class.php' ,
2010-02-02 15:25:22 +00:00
'ecache' => '{e_HANDLER}cache_handler.php' ,
2011-11-25 17:24:42 +00:00
'eController' => '{e_HANDLER}application.php' ,
'eDispatcher' => '{e_HANDLER}application.php' ,
'eException' => '{e_HANDLER}application.php' ,
'eFront' => '{e_HANDLER}application.php' ,
'eHelper' => '{e_HANDLER}application.php' ,
2012-12-10 17:17:51 +02:00
'eIPHandler' => '{e_HANDLER}iphandler_class.php' ,
2012-12-10 01:20:38 +02:00
'email_validation_class' => '{e_HANDLER}mail_validation_class.php' ,
2012-12-10 17:17:51 +02:00
'eMessage' => '{e_HANDLER}message_handler.php' ,
2011-11-25 17:24:42 +00:00
'eRequest' => '{e_HANDLER}application.php' ,
'eResponse' => '{e_HANDLER}application.php' ,
'eRouter' => '{e_HANDLER}application.php' ,
'eUrl' => '{e_HANDLER}e107Url.php' ,
'eUrlConfig' => '{e_HANDLER}application.php' ,
'eUrlRule' => '{e_HANDLER}application.php' ,
2012-07-31 07:32:00 +00:00
'Hybrid_Auth' => '{e_HANDLER}hybridauth/Hybrid/Auth.php' ,
2011-11-25 17:24:42 +00:00
'language' => '{e_HANDLER}language_class.php' ,
2010-02-02 15:25:22 +00:00
'news' => '{e_HANDLER}news_class.php' ,
'notify' => '{e_HANDLER}notify_class.php' ,
2010-04-24 11:39:14 +00:00
'override' => '{e_HANDLER}override_class.php' ,
2012-05-27 10:42:16 +00:00
'rater' => '{e_HANDLER}rate_class.php' ,
2010-02-02 15:25:22 +00:00
'redirection' => '{e_HANDLER}redirection_class.php' ,
2012-12-10 17:17:51 +02:00
'secure_image' => '{e_HANDLER}secure_img_handler.php' ,
2010-02-02 15:25:22 +00:00
'sitelinks' => '{e_HANDLER}sitelinks_class.php' ,
'themeHandler' => '{e_HANDLER}theme_handler.php' ,
'user_class' => '{e_HANDLER}userclass_class.php' ,
2010-05-13 15:47:31 +00:00
'userlogin' => '{e_HANDLER}login.php' ,
2012-12-10 17:17:51 +02:00
'validatorClass' => '{e_HANDLER}validator_class.php' ,
2010-02-02 15:25:22 +00:00
'xmlClass' => '{e_HANDLER}xml_class.php' ,
2009-08-19 14:39:57 +00:00
);
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
/**
* Overload core handlers array
* Format : 'core_class' => array ( 'overload_class' , 'overload_path' );
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* NOTE : to overload core singleton objects , you have to add record to
* $_overload_handlers before the first singleton call .
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* Example :
2009-11-12 16:47:36 +00:00
* < code > array ( 'e_form' => array ( 'plugin_myplugin_form_handler' => '{e_PLUGIN}myplugin/includes/form/handler.php' )); </ code >
2009-12-02 16:51:04 +00:00
*
* Used to auto - load core handlers
*
* @ var array
2009-09-13 10:31:09 +00:00
*/
protected static $_overload_handlers = array ();
2008-11-24 18:06:03 +00:00
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* Constructor
2009-12-02 16:51:04 +00:00
*
* Use { @ link getInstance ()}, direct instantiating
2011-12-28 10:01:25 +00:00
* is not possible for singleton objects
2009-07-21 16:11:02 +00:00
*
* @ return void
*/
protected function __construct ()
{
2013-05-27 10:54:42 +03:00
// FIXME registered shutdown functions not executed after the $page output in footer - investigate
// Currently manually called in front-end/admin footer
//register_shutdown_function(array($this, 'destruct'));
2009-07-21 16:11:02 +00:00
}
/**
* Cloning is not allowed
*
*/
private function __clone ()
{
}
2009-12-02 16:51:04 +00:00
2006-12-02 04:36:16 +00:00
/**
2009-07-21 16:11:02 +00:00
* Get singleton instance ( php4 no more supported )
2006-12-02 04:36:16 +00:00
*
* @ return e107
*/
2009-07-21 16:11:02 +00:00
public static function getInstance ()
2008-11-24 18:06:03 +00:00
{
2009-07-21 16:11:02 +00:00
if ( null == self :: $_instance )
2008-11-25 14:36:33 +00:00
{
2009-07-21 16:11:02 +00:00
self :: $_instance = new self ();
2008-11-25 16:26:03 +00:00
}
2009-07-21 16:11:02 +00:00
return self :: $_instance ;
2008-11-24 18:06:03 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* Initialize environment path constants
* Public proxy to the protected method { @ link _init ()}
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* @ return e107
*/
2010-03-03 17:06:33 +00:00
public function initCore ( $e107_paths , $e107_root_path , $e107_config_mysql_info , $e107_config_override = array ())
2008-05-16 19:40:39 +00:00
{
2011-05-03 22:13:59 +00:00
return $this -> _init ( $e107_paths , $e107_root_path , $e107_config_mysql_info , $e107_config_override );
}
/**
* Initialize environment path constants while installing e107
*
* @ return e107
*/
public function initInstall ( $e107_paths , $e107_root_path , $e107_config_override = array ())
{
2013-03-14 17:31:56 -07:00
$e107_config = 'e107_config.php' ;
if ( ! file_exists ( $e107_config )) // prevent blank-page with missing file during install.
{
file_put_contents ( $e107_config , '' );
}
2011-05-03 22:13:59 +00:00
// Do some security checks/cleanup, prepare the environment
$this -> prepare_request ();
2012-06-23 10:08:17 +00:00
2012-07-18 02:24:34 +00:00
//generated from mysql data at stage 5 of install.
$this -> site_path = isset ( $e107_config_override [ 'site_path' ]) ? $e107_config_override [ 'site_path' ] : " [hash] " ; // placeholder
2011-05-03 22:13:59 +00:00
// folder info
//$this->e107_dirs = $e107_paths;
$this -> setDirs ( $e107_paths , $e107_config_override );
2012-07-18 02:24:34 +00:00
2011-05-03 22:13:59 +00:00
// build all paths
$this -> set_paths ();
$this -> file_path = $this -> fix_windows_paths ( $e107_root_path ) . " / " ;
// set base path, SSL is auto-detected
$this -> set_base_path ();
// cleanup QUERY_STRING and friends, set related constants
$this -> set_request ();
// set some core URLs (e_LOGIN/SIGNUP)
$this -> set_urls ();
2012-06-23 10:08:17 +00:00
2011-05-03 22:13:59 +00:00
return $this ;
2010-12-13 11:22:57 +00:00
}
2009-07-21 16:11:02 +00:00
/**
* Resolve paths , will run only once
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* @ return e107
*/
2010-03-03 17:06:33 +00:00
protected function _init ( $e107_paths , $e107_root_path , $e107_config_mysql_info , $e107_config_override = array ())
2009-07-21 16:11:02 +00:00
{
2010-02-09 20:43:54 +00:00
2009-07-21 16:11:02 +00:00
if ( empty ( $this -> e107_dirs ))
{
2009-11-24 16:30:08 +00:00
// Do some security checks/cleanup, prepare the environment
$this -> prepare_request ();
2012-06-08 06:03:07 +00:00
2009-11-24 16:30:08 +00:00
// mysql connection info
$this -> e107_config_mysql_info = $e107_config_mysql_info ;
2012-06-08 06:03:07 +00:00
// unique folder for e_MEDIA - support for multiple websites from single-install. Must be set before setDirs()
2012-06-23 10:08:17 +00:00
$this -> site_path = $this -> makeSiteHash ( $e107_config_mysql_info [ 'mySQLdefaultdb' ], $e107_config_mysql_info [ 'mySQLprefix' ]);
2012-06-08 06:03:07 +00:00
// Set default folder (and override paths) if missing from e107_config.php
$this -> setDirs ( $e107_paths , $e107_config_override );
2009-11-24 16:30:08 +00:00
// various constants - MAGIC_QUOTES_GPC, MPREFIX, ...
$this -> set_constants ();
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
// build all paths
2009-07-21 16:11:02 +00:00
$this -> set_paths ();
$this -> file_path = $this -> fix_windows_paths ( $e107_root_path ) . " / " ;
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
// set base path, SSL is auto-detected
2010-02-25 10:06:26 +00:00
$this -> set_base_path ();
2011-04-25 11:29:21 +00:00
2009-11-24 16:30:08 +00:00
// cleanup QUERY_STRING and friends, set related constants
$this -> set_request ();
2010-02-09 20:43:54 +00:00
2011-05-03 22:13:59 +00:00
// set some core URLs (e_LOGIN/SIGNUP)
$this -> set_urls ();
2009-07-21 16:11:02 +00:00
}
2010-02-09 20:43:54 +00:00
2012-06-23 10:08:17 +00:00
2009-07-21 16:11:02 +00:00
return $this ;
}
2009-12-02 16:51:04 +00:00
2012-06-23 10:08:17 +00:00
// Create a unique hash for each database configuration (multi-site support)
function makeSiteHash ( $db , $prefix ) // also used by install.
{
return substr ( md5 ( $db . " . " . $prefix ), 0 , 10 );
}
2010-03-03 17:06:33 +00:00
/**
* Set system folders and override paths
* $e107_paths is the 'compact' version of e107_config folder vars ( $ADMIN_DIRECTORY , $IMAGES_DIRECTORY , etc )
* $e107_config_override is the new override method - it can do it for all server and http paths via
* the newly introduced $E107_CONFIG array .
*
* Overriding just replace _DIRECTORY with _SERVER or _HTTP :
* - override server path example :
* < code > $E107_CONFIG [ 'SYSTEM_SERVER' ] = '/home/user/system/' ; </ code >
*
* - override http path example :
* < code > $E107_CONFIG [ 'MEDIA_VIDEOS_HTTP' ] = 'http://static.mydomain.com/videos/' ; </ code >
*
* @ param array $e107_dirs Override folder instructions ( * _DIRECTORY vars - e107_config . php )
* @ param array $e107_config_override Override path insructions ( $E107_CONFIG array - e107_config . php )
* @ return e107
*/
public function setDirs ( $e107_dirs , $e107_config_override = array ())
{
2011-05-03 22:13:59 +00:00
$override = array_merge (( array ) $e107_dirs , ( array ) $e107_config_override );
2012-07-18 03:47:28 +00:00
2011-05-03 22:13:59 +00:00
// override all
$this -> e107_dirs = array_merge ( $this -> defaultDirs ( $override ), $override );
2012-07-18 03:47:28 +00:00
2013-04-03 12:25:30 +03:00
// TODO add e_MEDIA_BASE, e_SYSTEM_BASE (free of site path constants);
2012-07-18 03:47:28 +00:00
if ( strpos ( $this -> e107_dirs [ 'MEDIA_DIRECTORY' ], $this -> site_path ) === false )
{
$this -> e107_dirs [ 'MEDIA_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
}
if ( strpos ( $this -> e107_dirs [ 'SYSTEM_DIRECTORY' ], $this -> site_path ) === false )
{
$this -> e107_dirs [ 'SYSTEM_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
}
2013-04-03 12:25:30 +03:00
// FIXME Quick fix - override base cache folder for legacy configs (e.g. e107_files/cache), discuss
if ( strpos ( $this -> e107_dirs [ 'CACHE_DIRECTORY' ], $this -> site_path ) === false )
{
$this -> e107_dirs [ 'CACHE_DIRECTORY' ] = $this -> e107_dirs [ 'SYSTEM_DIRECTORY' ] . " cache/ " ; // multisite support.
}
2012-07-18 03:47:28 +00:00
2010-03-03 17:06:33 +00:00
return $this ;
}
/**
* Get default e107 folders , root folders can be overridden by passed override array
*
* @ param array $override_root
* @ param boolean $return_root
* @ return array
*/
public function defaultDirs ( $override_root = array (), $return_root = false )
{
$ret = array_merge ( array (
'ADMIN_DIRECTORY' => 'e107_admin/' ,
'IMAGES_DIRECTORY' => 'e107_images/' ,
'THEMES_DIRECTORY' => 'e107_themes/' ,
'PLUGINS_DIRECTORY' => 'e107_plugins/' ,
'FILES_DIRECTORY' => 'e107_files/' , // DEPRECATED!!!
'HANDLERS_DIRECTORY' => 'e107_handlers/' ,
'LANGUAGES_DIRECTORY' => 'e107_languages/' ,
'DOCS_DIRECTORY' => 'e107_docs/' ,
'MEDIA_DIRECTORY' => 'e107_media/' ,
'SYSTEM_DIRECTORY' => 'e107_system/' ,
'CORE_DIRECTORY' => 'e107_core/' ,
'WEB_DIRECTORY' => 'e107_web/' ,
2011-05-03 22:13:59 +00:00
), ( array ) $override_root );
2012-06-08 06:03:07 +00:00
$ret [ 'MEDIA_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
$ret [ 'SYSTEM_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
2010-03-03 17:06:33 +00:00
if ( $return_root ) return $ret ;
2012-06-08 06:03:07 +00:00
2010-03-03 17:06:33 +00:00
$ret [ 'HELP_DIRECTORY' ] = $ret [ 'DOCS_DIRECTORY' ] . 'help/' ;
$ret [ 'MEDIA_IMAGES_DIRECTORY' ] = $ret [ 'MEDIA_DIRECTORY' ] . 'images/' ;
$ret [ 'MEDIA_ICONS_DIRECTORY' ] = $ret [ 'MEDIA_DIRECTORY' ] . 'icons/' ;
2013-04-19 22:50:41 -07:00
2010-03-03 17:06:33 +00:00
$ret [ 'MEDIA_VIDEOS_DIRECTORY' ] = $ret [ 'MEDIA_DIRECTORY' ] . 'videos/' ;
$ret [ 'MEDIA_FILES_DIRECTORY' ] = $ret [ 'MEDIA_DIRECTORY' ] . 'files/' ;
2012-11-12 21:46:10 +00:00
$ret [ 'MEDIA_UPLOAD_DIRECTORY' ] = $ret [ 'SYSTEM_DIRECTORY' ] . 'temp/' ; // security measure. Media is public, system is private.
2013-04-19 22:50:41 -07:00
$ret [ 'AVATARS_DIRECTORY' ] = $ret [ 'MEDIA_DIRECTORY' ] . 'avatars/' ;
2010-03-03 17:06:33 +00:00
2012-11-23 22:47:01 -08:00
$ret [ 'WEB_JS_DIRECTORY' ] = $ret [ 'WEB_DIRECTORY' ] . 'js/' ;
// $ret['WEB_JS_DIRECTORY'] = $ret['FILES_DIRECTORY'].'jslib/';
2012-06-08 06:03:07 +00:00
2010-03-10 13:11:29 +00:00
$ret [ 'WEB_CSS_DIRECTORY' ] = $ret [ 'WEB_DIRECTORY' ] . 'css/' ;
$ret [ 'WEB_IMAGES_DIRECTORY' ] = $ret [ 'WEB_DIRECTORY' ] . 'images/' ;
2012-12-16 13:02:19 -08:00
// $ret['WEB_PACKS_DIRECTORY'] = $ret['WEB_DIRECTORY'].'packages/';
2010-03-03 17:06:33 +00:00
$ret [ 'DOWNLOADS_DIRECTORY' ] = $ret [ 'MEDIA_FILES_DIRECTORY' ];
$ret [ 'UPLOADS_DIRECTORY' ] = $ret [ 'MEDIA_UPLOAD_DIRECTORY' ];
$ret [ 'CACHE_DIRECTORY' ] = $ret [ 'SYSTEM_DIRECTORY' ] . 'cache/' ;
$ret [ 'CACHE_CONTENT_DIRECTORY' ] = $ret [ 'CACHE_DIRECTORY' ] . 'content/' ;
2010-03-08 15:26:05 +00:00
$ret [ 'CACHE_IMAGE_DIRECTORY' ] = $ret [ 'CACHE_DIRECTORY' ] . 'images/' ;
2010-03-03 17:06:33 +00:00
$ret [ 'CACHE_DB_DIRECTORY' ] = $ret [ 'CACHE_DIRECTORY' ] . 'db/' ;
2012-06-08 08:18:03 +00:00
$ret [ 'CACHE_URL_DIRECTORY' ] = $ret [ 'CACHE_DIRECTORY' ] . 'url/' ;
2013-04-19 22:50:41 -07:00
$ret [ 'AVATARS_UPLOAD_DIRECTORY' ] = $ret [ 'AVATARS_DIRECTORY' ] . 'upload/' ;
$ret [ 'AVATARS_DEFAULT_DIRECTORY' ] = $ret [ 'AVATARS_DIRECTORY' ] . 'default/' ;
2010-03-03 17:06:33 +00:00
$ret [ 'LOGS_DIRECTORY' ] = $ret [ 'SYSTEM_DIRECTORY' ] . 'logs/' ;
2012-06-08 06:03:07 +00:00
$ret [ 'BACKUP_DIRECTORY' ] = $ret [ 'SYSTEM_DIRECTORY' ] . 'backup/' ;
2012-08-06 08:55:51 +00:00
$ret [ 'TEMP_DIRECTORY' ] = $ret [ 'SYSTEM_DIRECTORY' ] . 'temp/' ;
2013-05-17 18:17:04 -07:00
$ret [ 'IMPORT_DIRECTORY' ] = $ret [ 'SYSTEM_DIRECTORY' ] . 'import/' ;
2012-06-08 06:03:07 +00:00
//TODO create directories which don't exist.
2010-03-03 17:06:33 +00:00
return $ret ;
}
2009-12-02 16:51:04 +00:00
/**
* Set mysql data
*
* @ return e107
*/
public function initInstallSql ( $e107_config_mysql_info )
{
// mysql connection info
$this -> e107_config_mysql_info = $e107_config_mysql_info ;
// various constants - MAGIC_QUOTES_GPC, MPREFIX, ...
$this -> set_constants ();
return $this ;
}
2009-07-21 16:11:02 +00:00
/**
* Get data from the registry
* Returns $default if data not found
* Replacement of cachevar ()
2009-12-02 16:51:04 +00:00
*
* @ param string $id
2009-07-21 16:11:02 +00:00
* @ return mixed
*/
public static function getRegistry ( $id , $default = null )
{
if ( isset ( self :: $_registry [ $id ]))
{
return self :: $_registry [ $id ];
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
return $default ;
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* 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 .
2009-12-02 16:51:04 +00:00
* When removing objects from the registry , __destruct () method will be auto - executed
2009-07-21 16:11:02 +00:00
* if available
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* Naming standards ( namespaces ) :
* 'area/area_id/storage_type' < br >
* where < br >
* - area = 'core' | 'plugin' | 'external' ( everything else )
* - area_id = core handler id | plugin name ( depends on area )
* - ( optional ) storage_type = current data storage stack
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* Examples :
* - 'core/e107/' - reserved for this class
* - 'core/e107/singleton/' - singleton objects repo { @ link getSingleton ()}
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* @ 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 ;
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
if ( ! $allow_override && null !== self :: getRegistry ( $id ))
{
return ;
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
self :: $_registry [ $id ] = $data ;
}
2009-12-02 16:51:04 +00:00
2009-08-20 12:24:47 +00:00
/**
* Get folder name ( e107_config )
* Replaces all $ ( * ) _DIRECTORY globals
2009-11-24 16:30:08 +00:00
* Example : < code > $e107 -> getFolder ( 'images' ) </ code > ;
2009-08-20 12:24:47 +00:00
*
* @ param string $for
* @ return string
*/
function getFolder ( $for )
{
2009-11-24 16:30:08 +00:00
$key = strtoupper ( $for ) . '_DIRECTORY' ;
2011-05-03 22:13:59 +00:00
$self = self :: getInstance ();
return ( isset ( $self -> e107_dirs [ $key ]) ? $self -> e107_dirs [ $key ] : '' );
2009-11-24 16:30:08 +00:00
}
2009-12-02 16:51:04 +00:00
2010-05-13 15:47:31 +00:00
/**
* Get value from $_E107 config array
* Note : will always return false if called before prepare_request () method !
*
* @ param string $key
* @ return boolean
*/
2011-12-06 08:00:42 +00:00
public static function getE107 ( $key = null )
2010-05-13 15:47:31 +00:00
{
$self = self :: getInstance ();
2011-12-06 08:00:42 +00:00
if ( null === $key ) return $self -> _E107 ;
2010-05-13 15:47:31 +00:00
return ( isset ( $self -> _E107 [ $key ]) && $self -> _E107 [ $key ] ? true : false );
}
/**
* Convenient proxy to $_E107 getter - check if
* the system is currently running in cli mode
* Note : will always return false if called before prepare_request () method !
*
* @ return boolean
*/
public static function isCli ()
{
return self :: getE107 ( 'cli' );
}
2009-11-24 16:30:08 +00:00
/**
* Get mysql config var ( e107_config . php )
* Replaces all $mySQL ( * ) globals
* Example : < code > $e107 -> getMySQLConfig ( 'prefix' ); </ code >
*
2013-05-04 19:59:54 -07:00
* @ param string $for prefix | server | user | password | defaultdb - leave blank for full array .
* @ return string or array
2009-11-24 16:30:08 +00:00
*/
2013-05-04 19:59:54 -07:00
function getMySQLConfig ( $for = '' )
2009-11-24 16:30:08 +00:00
{
$key = 'mySQL' . $for ;
2012-06-08 06:03:07 +00:00
$self = self :: getInstance ();
2013-05-04 19:59:54 -07:00
if ( $for == '' )
{
return $self -> e107_config_mysql_info ;
}
return ( isset ( $self -> e107_config_mysql_info [ $key ]) ? $self -> e107_config_mysql_info [ $key ] : '' );
2012-06-08 06:03:07 +00:00
}
/**
* Return a unique path based on database used . ie . multi - site support from single install .
*
* @ return string
* @ author
*/
function getSitePath ()
{
$self = self :: getInstance ();
return $self -> site_path ;
2009-08-20 12:24:47 +00:00
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
/**
* Get known handler path
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* @ param string $class_name
* @ param boolean $parse_path [ optional ] parse path shortcodes
* @ return string | null
*/
public static function getHandlerPath ( $class_name , $parse_path = true )
{
$ret = isset ( self :: $_known_handlers [ $class_name ]) ? self :: $_known_handlers [ $class_name ] : null ;
if ( $parse_path && $ret )
{
$ret = self :: getParser () -> replaceConstants ( $ret );
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
return $ret ;
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
/**
* Add handler to $_known_handlers array on runtime
* If class name is array , method will add it ( recursion ) and ignore $path argument
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* @ param array | string $class_name
* @ param string $path [ optional ]
* @ return void
*/
public static function addHandler ( $class_name , $path = '' )
{
if ( is_array ( $class_name ))
{
foreach ( $class_name as $cname => $path )
{
self :: addHandler ( $cname , $path );
}
return ;
}
if ( ! self :: isHandler ( $class_name ))
{
self :: $_known_handlers [ $class_name ] = $path ;
}
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
/**
* Check handler presence
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* @ param string $class_name
* @ return boolean
*/
public static function isHandler ( $class_name )
{
return isset ( self :: $_known_handlers [ $class_name ]);
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
/**
* Get overlod class and path ( if any )
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* @ param object $class_name
* @ param object $default_handler [ optional ] return data from $_known_handlers if no overload data available
* @ param object $parse_path [ optional ] parse path shortcodes
* @ return array
*/
public static function getHandlerOverload ( $class_name , $default_handler = true , $parse_path = true )
{
$ret = ( isset ( self :: $_overload_handlers [ $class_name ]) ? self :: $_overload_handlers [ $class_name ] : ( $default_handler ? array ( $class_name , self :: getHandlerPath ( $class_name , false )) : array ()));
if ( $parse_path && isset ( $ret [ 1 ]))
{
$ret [ 1 ] = self :: getParser () -> replaceConstants ( $ret [ 1 ]);
}
return $ret ;
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
/**
* Overload present handler .
2009-12-02 16:51:04 +00:00
* If class name is array , method will add it ( recursion ) and
2009-09-13 10:31:09 +00:00
* ignore $overload_class_name and $overload_path arguments
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* @ param string $class_name
* @ param string $overload_name [ optional ]
* @ param string $overload_path [ optional ]
* @ return void
*/
public static function setHandlerOverload ( $class_name , $overload_class_name = '' , $overload_path = '' )
{
if ( is_array ( $class_name ))
{
foreach ( $class_name as $cname => $overload_array )
{
self :: setHandlerOverload ( $cname , $overload_array [ 0 ], $overload_array [ 1 ]);
}
return ;
}
2009-11-12 16:47:36 +00:00
if ( self :: isHandler ( $class_name ) && ! self :: isHandlerOverloadable ( $class_name ))
2009-09-13 10:31:09 +00:00
{
self :: $_overload_handlers [ $class_name ] = array ( $overload_class_name , $overload_path );
}
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
/**
* Check if handler is already overloaded
2009-12-02 16:51:04 +00:00
*
2009-09-13 10:31:09 +00:00
* @ param string $class_name
* @ return boolean
*/
2009-11-12 16:47:36 +00:00
public static function isHandlerOverloadable ( $class_name )
2009-09-13 10:31:09 +00:00
{
return isset ( self :: $_overload_handlers [ $class_name ]);
}
2009-12-02 16:51:04 +00:00
2009-01-09 17:25:50 +00:00
/**
2009-07-21 16:11:02 +00:00
* Retrieve singleton object
2009-01-09 17:25:50 +00:00
*
2009-07-21 16:11:02 +00:00
* @ param string $class_name
2009-08-19 14:39:57 +00:00
* @ param string | boolean $path optional script path
2009-07-22 00:49:35 +00:00
* @ param string $regpath additional registry path
2009-07-21 16:11:02 +00:00
* @ return Object
2009-01-09 17:25:50 +00:00
*/
2009-08-16 16:30:56 +00:00
public static function getSingleton ( $class_name , $path = true , $regpath = '' )
2009-01-09 17:25:50 +00:00
{
2010-05-05 15:05:32 +00:00
2009-09-13 10:31:09 +00:00
$id = 'core/e107/singleton/' . $class_name . $regpath ;
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
//singleton object found - overload not possible
if ( self :: getRegistry ( $id ))
2009-08-16 16:30:56 +00:00
{
2009-09-13 10:31:09 +00:00
return self :: getRegistry ( $id );
2009-08-16 16:30:56 +00:00
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
//auto detection + overload check
if ( is_bool ( $path ))
2009-07-21 16:11:02 +00:00
{
2009-09-13 10:31:09 +00:00
//overload allowed
2009-11-12 16:47:36 +00:00
if ( true === $path && self :: isHandlerOverloadable ( $class_name ))
2009-07-21 16:11:02 +00:00
{
2009-09-13 10:31:09 +00:00
$tmp = self :: getHandlerOverload ( $class_name );
$class_name = $tmp [ 0 ];
$path = $tmp [ 1 ];
2009-07-21 16:11:02 +00:00
}
2009-09-13 10:31:09 +00:00
//overload not allowed
else
2009-07-21 16:11:02 +00:00
{
2009-09-13 10:31:09 +00:00
$path = self :: getHandlerPath ( $class_name );
2009-07-21 16:11:02 +00:00
}
}
2008-11-25 16:26:03 +00:00
2009-09-13 10:31:09 +00:00
if ( $path && is_string ( $path ) && ! class_exists ( $class_name , false ))
2010-02-09 20:43:54 +00:00
{
2009-09-13 10:31:09 +00:00
e107_require_once ( $path ); //no existence/security checks here!
2010-02-09 20:43:54 +00:00
//e107_require_once() is available without class2.php. - see core_functions.php
2009-09-13 10:31:09 +00:00
}
if ( class_exists ( $class_name , false ))
{
e107 :: setRegistry ( $id , new $class_name ());
}
2009-07-21 16:11:02 +00:00
return self :: getRegistry ( $id );
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* Retrieve object
2009-09-13 10:31:09 +00:00
* Prepare for __autoload
2009-07-21 16:11:02 +00:00
*
* @ param string $class_name
* @ param mxed $arguments
2009-08-20 12:24:47 +00:00
* @ param string | boolean $path optional script path
2009-07-21 16:11:02 +00:00
* @ return object | null
*/
2009-08-20 12:24:47 +00:00
public static function getObject ( $class_name , $arguments = null , $path = true )
2009-07-21 16:11:02 +00:00
{
2009-08-20 12:24:47 +00:00
if ( true === $path )
{
if ( isset ( self :: $_known_handlers [ $class_name ]))
{
$path = self :: getParser () -> replaceConstants ( self :: $_known_handlers [ $class_name ]);
}
}
2009-12-02 16:51:04 +00:00
2009-09-13 10:31:09 +00:00
//auto detection + overload check
if ( is_bool ( $path ))
{
//overload allowed
2009-11-12 16:47:36 +00:00
if ( true === $path && self :: isHandlerOverloadable ( $class_name ))
2009-09-13 10:31:09 +00:00
{
$tmp = self :: getHandlerOverload ( $class_name );
$class_name = $tmp [ 0 ];
$path = $tmp [ 1 ];
}
//overload not allowed
else
{
$path = self :: getHandlerPath ( $class_name );
}
}
2009-12-02 16:51:04 +00:00
2009-08-20 12:24:47 +00:00
if ( $path && is_string ( $path ) && ! class_exists ( $class_name , false ))
2009-07-21 16:11:02 +00:00
{
2009-07-22 00:49:35 +00:00
e107_require_once ( $path ); //no existence/security checks here!
2009-07-21 16:11:02 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 00:49:35 +00:00
if ( class_exists ( $class_name , false ))
2009-01-09 17:25:50 +00:00
{
2009-08-20 12:24:47 +00:00
if ( null !== $arguments ) return new $class_name ( $arguments );
return new $class_name ();
2009-01-09 17:25:50 +00:00
}
2009-07-21 16:11:02 +00:00
2009-08-20 12:24:47 +00:00
trigger_error ( " Class { $class_name } not found! " , E_USER_ERROR );
2009-07-21 16:11:02 +00:00
return null ;
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
* Retrieve core config handlers .
2009-08-05 19:56:48 +00:00
* List of allowed $name values ( aliases ) could be found
2009-07-30 16:09:30 +00:00
* in { @ link e_core_pref } class
*
2012-12-06 16:36:22 -08:00
* @ param string $name core | core_backup | emote | menu | search | notify
2009-07-30 16:09:30 +00:00
* @ return e_core_pref
*/
2013-03-27 19:34:45 -07:00
public static function getConfig ( $name = 'core' , $load = true , $refresh = false )
2009-07-30 16:09:30 +00:00
{
2012-12-06 16:36:22 -08:00
if ( isset ( self :: $_plug_config_arr [ $name ])) //FIXME Load pluginPref Object instead - Not quite working with calendar_menu.
{
return self :: getPlugConfig ( $name );
}
2013-03-27 19:34:45 -07:00
if ( ! isset ( self :: $_core_config_arr [ $name ]) || ( $refresh == true )) // required by update_routines to clear out earlier values.
2009-07-30 16:09:30 +00:00
{
2012-12-06 16:36:22 -08:00
e107_require_once ( e_HANDLER . 'pref_class.php' );
self :: $_core_config_arr [ $name ] = new e_core_pref ( $name , $load );
2012-12-15 03:49:15 -08:00
if ( $name == 'core' ) // prevent loop between pref and cache handlers.
{
e107 :: getCache () -> UserCacheActive = self :: getPref ( 'cachestatus' );
e107 :: getCache () -> SystemCacheActive = self :: getPref ( 'syscachestatus' );
}
2009-07-30 16:09:30 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
return self :: $_core_config_arr [ $name ];
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
2009-08-05 19:56:48 +00:00
* Retrieve core config handler preference value or the core preference array
2009-07-30 16:09:30 +00:00
* Shorthand of self :: getConfig () -> get ()
*
* @ see e_core_pref :: get ()
* @ param string $pref_name
* @ param mixed $default default value if preference is not found
* @ return mixed
*/
2009-08-05 19:56:48 +00:00
public static function getPref ( $pref_name = '' , $default = null )
2009-07-30 16:09:30 +00:00
{
2009-08-05 19:56:48 +00:00
return empty ( $pref_name ) ? self :: getConfig () -> getPref () : self :: getConfig () -> get ( $pref_name , $default );
2009-07-30 16:09:30 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
* Advanced version of self :: getPref () . $pref_name is parsed ,
* so that $pref_name = 'x/y/z' will search for value pref_data [ x ][ y ][ z ]
* Shorthand of self :: getConfig () -> getPref ()
*
* @ see e_core_pref :: getPref ()
* @ param string $pref_name
* @ param mixed $default default value if preference is not found
* @ return mixed
*/
public static function findPref ( $pref_name , $default = null , $index = null )
{
return self :: getConfig () -> getPref ( $pref_name , $default , $index );
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
* Retrieve plugin config handlers .
* Multiple plugin preference DB rows are supported
* Class overload is supported .
* Examples :
2009-12-13 21:52:32 +00:00
* - < code > e107 :: getPluginConfig ( 'myplug' ); </ code >
2009-07-30 16:09:30 +00:00
* will search for e107_plugins / myplug / e_pref / myplug_pref . php which
* should contain class ' e_plugin_myplug_pref ' class ( child of e_plugin_pref )
2009-12-13 21:52:32 +00:00
* - < code > e107 :: getPluginConfig ( 'myplug' , 'row2' ); </ code >
2009-07-30 16:09:30 +00:00
* will search for e107_plugins / myplug / e_pref / myplug_row2_pref . php which
* should contain class ' e_plugin_myplug_row2_pref ' class ( child of e_plugin_pref )
2009-12-02 16:51:04 +00:00
*
2009-07-30 16:09:30 +00:00
* @ param string $plug_name
2009-12-02 16:51:04 +00:00
* @ param string $multi_row
2009-07-30 16:09:30 +00:00
* @ param boolean $load load from DB on startup
* @ return e_plugin_pref
*/
public static function getPlugConfig ( $plug_name , $multi_row = '' , $load = true )
{
if ( ! isset ( self :: $_plug_config_arr [ $plug_name . $multi_row ]))
{
e107_require_once ( e_HANDLER . 'pref_class.php' );
2009-09-08 12:13:00 +00:00
$override_id = $plug_name . ( $multi_row ? " _ { $multi_row } " : '' );
2009-12-02 16:51:04 +00:00
//check (once) for custom plugin pref handler
2009-07-30 16:09:30 +00:00
if ( is_readable ( e_PLUGIN . $plug_name . '/e_pref/' . $override_id . '_pref.php' ))
{
require_once ( e_PLUGIN . $plug_name . '/e_pref/' . $override_id . '_pref.php' );
2009-09-08 12:13:00 +00:00
$class_name = 'e_plugin_' . $override_id . '_pref' ;
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
//PHPVER: string parameter for is_subclass_of require PHP 5.0.3+
if ( class_exists ( $class_name , false ) && is_subclass_of ( 'e_plugin_pref' , $class_name )) //or e_pref ?
{
self :: $_plug_config_arr [ $plug_name . $multi_row ] = new $class_name ( $load );
return self :: $_plug_config_arr [ $plug_name . $multi_row ];
}
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
self :: $_plug_config_arr [ $plug_name . $multi_row ] = new e_plugin_pref ( $plug_name , $multi_row , $load );
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
return self :: $_plug_config_arr [ $plug_name . $multi_row ];
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
* Retrieve plugin preference value .
* Shorthand of self :: getPluginConfig () -> get ()
* NOTE : Multiple plugin preference DB rows are NOT supported
* This will only look for your default plugin config ( empty $milti_row )
*
* @ see e_plugin_pref :: get ()
* @ param string $plug_name
* @ param string $pref_name
* @ param mixed $default default value if preference is not found
* @ return mixed
*/
2009-09-08 12:13:00 +00:00
public static function getPlugPref ( $plug_name , $pref_name = '' , $default = null )
2009-07-30 16:09:30 +00:00
{
2009-08-17 14:40:23 +00:00
return empty ( $pref_name ) ? self :: getPlugConfig ( $plug_name ) -> getPref () : self :: getPlugConfig ( $plug_name ) -> get ( $pref_name , $default );
2009-07-30 16:09:30 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-30 16:09:30 +00:00
/**
* Advanced version of self :: getPlugPref () . $pref_name is parsed ,
* so that $pref_name = 'x/y/z' will search for value pref_data [ x ][ y ][ z ]
* Shorthand of self :: getPluginConfig () -> getPref ()
*
* @ see e_core_pref :: getPref ()
* @ param string $pref_name
* @ param mixed $default default value if preference is not found
* @ return mixed
*/
public static function findPlugPref ( $plug_name , $pref_name , $default = null , $index = null )
{
return self :: getPlugConfig ( $plug_name ) -> getPref ( $pref_name , $default , $index );
}
2009-12-02 16:51:04 +00:00
2009-08-05 19:56:48 +00:00
/**
* Get current theme preference . $pref_name is parsed ,
* so that $pref_name = 'x/y/z' will search for value pref_data [ x ][ y ][ z ]
* Shorthand of self :: getConfig () -> getPref ( 'current_theme/sitetheme_pref/pref_name' )
*
* @ see e_core_pref :: getPref ()
* @ param string $pref_name
* @ param mixed $default default value if preference is not found
* @ return mixed
*/
2009-08-17 14:40:23 +00:00
public static function getThemePref ( $pref_name = '' , $default = null , $index = null )
2009-08-05 19:56:48 +00:00
{
2011-11-29 12:11:27 +00:00
if ( $pref_name ) $pref_name = '/' . $pref_name ;
return e107 :: getConfig () -> getPref ( 'sitetheme_pref' . $pref_name , $default , $index );
}
/**
* Set current theme preference . $pref_name is parsed ,
* so that $pref_name = 'x/y/z' will set value pref_data [ x ][ y ][ z ]
*
* @ param string | array $pref_name
* @ param mixed $pref_value
* @ return e_pref
*/
public static function setThemePref ( $pref_name , $pref_value = null )
{
if ( is_array ( $pref_name )) return e107 :: getConfig () -> set ( 'sitetheme_pref' , $pref_name );
return e107 :: getConfig () -> updatePref ( 'sitetheme_pref/' . $pref_name , $pref_value , false );
2009-08-05 19:56:48 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* Retrieve text parser singleton object
*
* @ return e_parse
*/
public static function getParser ()
{
2011-12-28 10:01:25 +00:00
return self :: getSingleton ( 'e_parse' , e_HANDLER . 'e_parse_class.php' ); //WARNING - don't change this - infinite loop!!!
2009-01-09 17:25:50 +00:00
}
2009-11-22 14:10:09 +00:00
2009-07-23 15:29:07 +00:00
/**
* Retrieve sc parser singleton object
*
2010-04-23 15:54:11 +00:00
* @ return e_parse_shortcode
2009-07-23 15:29:07 +00:00
*/
public static function getScParser ()
{
2010-04-23 15:54:11 +00:00
return self :: getSingleton ( 'e_parse_shortcode' , true );
}
2012-06-13 04:58:43 +00:00
/**
* Retrieve secure_image singleton object
*
* @ return secure_image
*/
public static function getSecureImg ()
{
2012-06-19 13:20:30 +00:00
return self :: getSingleton ( 'secure_image' , true ); // more flexible.
// return self::getObject('secure_image');
2012-06-13 04:58:43 +00:00
}
2010-05-05 15:05:32 +00:00
2010-04-23 15:54:11 +00:00
/**
* Retrieve registered sc object ( batch ) by class name
2010-04-25 13:52:14 +00:00
* Note - '_shortcodes' part of the class / override is added by the method
* Override is possible only if class is not already instantiated by shortcode parser
2010-05-05 15:05:32 +00:00
*
* < code >< ? php
2013-02-01 17:35:56 -08:00
*
* // Core news shortcodes (news_shortcodes.php using class news_shortcodes )
2010-05-05 15:05:32 +00:00
* e107 :: getScObject ( 'news' );
2013-02-01 17:35:56 -08:00
*
* // Core page shortcodes (page_shortcodes.php.php with class cpage_shortcode)
* e107 :: getScObject ( 'page' , null , 'cpage' );
*
2012-01-06 10:05:32 +00:00
* // object of plugin_myplugin_my_shortcodes class -> myplugin/shortcodes/batch/my_shortcodes.php
2010-05-05 15:05:32 +00:00
* e107 :: getScObject ( 'my' , 'myplugin' );
2013-02-01 17:35:56 -08:00
*
2012-01-06 10:05:32 +00:00
* // news override - plugin_myplugin_news_shortcodes extends news_shortcodes -> myplugin/shortcodes/batch/news_shortcodes.php
2010-04-25 13:52:14 +00:00
* e107 :: getScObject ( 'news' , 'myplugin' , true );
2013-02-01 17:35:56 -08:00
*
2012-01-06 10:05:32 +00:00
* // news override - plugin_myplugin_mynews_shortcodes extends news_shortcodes -> myplugin/shortcodes/batch/mynews_shortcodes.php
2010-04-25 13:52:14 +00:00
* e107 :: getScObject ( 'news' , 'myplugin' , 'mynews' );
* </ code >
2010-05-05 15:05:32 +00:00
*
2010-04-25 13:52:14 +00:00
* @ param string $className
* @ param string $pluginName
* @ param string | true $overrideClass
2010-04-23 15:54:11 +00:00
* @ return e_shortcode
*/
2010-04-25 13:52:14 +00:00
public static function getScBatch ( $className , $pluginName = null , $overrideClass = null )
2010-04-23 15:54:11 +00:00
{
2010-04-25 13:52:14 +00:00
if ( is_string ( $overrideClass )) $overrideClass .= '_shortcodes' ;
return self :: getScParser () -> getScObject ( $className . '_shortcodes' , $pluginName , $overrideClass );
2009-07-23 15:29:07 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 00:49:35 +00:00
/**
2009-12-02 16:51:04 +00:00
* Retrieve DB singleton object based on the
2009-07-22 00:49:35 +00:00
* $instance_id
*
* @ param string $instance_id
2009-09-10 19:10:00 +00:00
* @ return e_db_mysql
2009-07-22 00:49:35 +00:00
*/
public static function getDb ( $instance_id = '' )
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'db' , true , $instance_id );
2009-07-22 00:49:35 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 00:49:35 +00:00
/**
2012-05-11 03:52:57 +00:00
* Retrieve cache singleton object
2009-07-22 00:49:35 +00:00
*
* @ return ecache
*/
public static function getCache ()
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'ecache' , true );
2009-07-22 00:49:35 +00:00
}
2009-12-02 16:51:04 +00:00
2012-05-11 03:52:57 +00:00
/**
* Retrieve bbcode singleton object
*
* @ return e_bbcode
*/
public static function getBB ()
{
return self :: getSingleton ( 'e_bbcode' , true );
}
2010-03-22 15:45:47 +00:00
/**
* Retrieve user - session singleton object
*
* @ return UserHandler
*/
2011-05-03 22:13:59 +00:00
public static function getUserSession ()
2010-03-22 15:45:47 +00:00
{
return self :: getSingleton ( 'UserHandler' , true );
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
/**
* Retrieve core session singleton object ( s )
*
* @ return e_core_session
*/
public static function getSession ( $namespace = null )
{
$id = 'core/e107/session/' . ( null === $namespace ? 'e107' : $namespace );
if ( self :: getRegistry ( $id ))
{
return self :: getRegistry ( $id );
}
$session = self :: getObject ( 'e_core_session' , array ( 'namespace' => $namespace ), true );
self :: setRegistry ( $id , $session );
return $session ;
}
2009-11-22 14:10:09 +00:00
/**
* Retrieve redirection singleton object
*
* @ return redirection
*/
public static function getRedirect ()
{
return self :: getSingleton ( 'redirection' , true );
2009-12-02 16:51:04 +00:00
}
2012-05-27 10:42:16 +00:00
/**
* Retrieve rater singleton object
*
* @ return rate
*/
public static function getRate ()
{
return self :: getSingleton ( 'rater' , true );
}
2009-12-02 16:51:04 +00:00
2009-11-21 11:36:10 +00:00
/**
* Retrieve sitelinks singleton object
*
2011-05-03 22:13:59 +00:00
* @ return sitelinks
2009-11-21 11:36:10 +00:00
*/
public static function getSitelinks ()
{
return self :: getSingleton ( 'sitelinks' , true );
2009-12-02 16:51:04 +00:00
}
2009-11-21 11:36:10 +00:00
2009-07-22 00:49:35 +00:00
/**
* Retrieve render singleton object
*
* @ return e107table
*/
public static function getRender ()
{
return self :: getSingleton ( 'e107table' );
}
2010-02-09 20:43:54 +00:00
2009-12-27 13:56:15 +00:00
/**
* Retrieve e107Email singleton object
*
* @ return e107Email
*/
public static function getEmail ()
{
return self :: getSingleton ( 'e107Email' , true );
}
2009-12-02 16:51:04 +00:00
2009-07-22 00:49:35 +00:00
/**
* Retrieve event singleton object
*
* @ return e107_event
*/
public static function getEvent ()
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'e107_event' , true );
2009-07-22 00:49:35 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 00:49:35 +00:00
/**
* Retrieve array storage singleton object
*
2013-05-28 15:41:05 +03:00
* @ return e_array
2009-07-22 00:49:35 +00:00
*/
public static function getArrayStorage ()
{
2013-02-26 19:12:17 -08:00
return self :: getSingleton ( 'e_array' , true );
2009-07-22 00:49:35 +00:00
}
2009-12-02 16:51:04 +00:00
2009-08-16 16:30:56 +00:00
/**
* Retrieve menu handler singleton object
*
* @ return e_menu
*/
public static function getMenu ()
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'e_menu' , true );
2009-08-16 16:30:56 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 00:49:35 +00:00
/**
* Retrieve URL singleton object
*
* @ return eURL
*/
public static function getUrl ()
{
2011-11-25 17:24:42 +00:00
return self :: getSingleton ( 'eUrl' , true );
2009-07-22 00:49:35 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 14:32:51 +00:00
/**
* Retrieve file handler singleton or new fresh object
*
2009-10-07 10:54:13 +00:00
* @ param boolean $singleton default true
2009-07-22 14:32:51 +00:00
* @ return e_file
*/
2013-02-09 17:22:19 +02:00
public static function getFile ( $singleton = false )
2009-07-22 14:32:51 +00:00
{
if ( $singleton )
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'e_file' , true );
2009-07-22 14:32:51 +00:00
}
2009-09-13 16:37:18 +00:00
return self :: getObject ( 'e_file' , null , true );
2009-07-22 14:32:51 +00:00
}
2009-12-02 16:51:04 +00:00
2009-10-07 10:54:13 +00:00
/**
* Retrieve form handler singleton or new fresh object
*
* @ param boolean $singleton default false
2009-10-23 18:14:42 +00:00
* @ param boolean $tabindex passed to e_form when initialized as an object ( not singleton )
2009-10-07 10:54:13 +00:00
* @ return e_form
*/
2009-10-23 18:14:42 +00:00
public static function getForm ( $singleton = false , $tabindex = false )
2009-10-07 10:54:13 +00:00
{
if ( $singleton )
{
return self :: getSingleton ( 'e_form' , true );
}
2009-10-23 18:14:42 +00:00
return self :: getObject ( 'e_form' , $tabindex , true );
2009-10-07 10:54:13 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 00:49:35 +00:00
/**
* Retrieve admin log singleton object
*
* @ return e_admin_log
*/
public static function getAdminLog ()
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'e_admin_log' , true );
2009-07-22 00:49:35 +00:00
}
2008-05-16 19:40:39 +00:00
2009-07-22 00:49:35 +00:00
/**
* Retrieve date handler singleton object
*
* @ return convert
*/
public static function getDateConvert ()
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'convert' , true );
2009-07-22 00:49:35 +00:00
}
2012-05-26 12:21:39 +00:00
/**
* Retrieve date handler singleton object - preferred method .
*
* @ return convert
*/
public static function getDate ()
{
return self :: getSingleton ( 'convert' , true );
}
2009-12-02 16:51:04 +00:00
2013-03-01 15:50:31 -08:00
/**
* Retrieve date handler singleton object - preferred method .
*
* @ return convert
*/
public static function getDebug () //XXX Discuss - possible with current setup?
{
return self :: getSingleton ( 'e107_db_debug' , true );
}
2009-07-23 15:29:07 +00:00
/**
* Retrieve notify handler singleton object
*
* @ return notify
*/
public static function getNotify ()
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'notify' , true );
2009-07-23 15:29:07 +00:00
}
2011-05-03 22:13:59 +00:00
2012-06-08 06:03:07 +00:00
/**
* Retrieve override handler singleton object
*
* @ return notify
*/
public static function getOverride ()
{
return self :: getSingleton ( 'override' , true );
}
2010-09-10 01:01:48 +00:00
/**
* Retrieve Language handler singleton object
*
* @ return language
*/
public static function getLanguage ()
{
return self :: getSingleton ( 'language' , true );
}
2009-12-02 16:51:04 +00:00
2011-12-28 10:01:25 +00:00
/**
* Retrieve IP / ban handler singleton object
*
2012-02-07 16:37:44 +00:00
* @ return eIPHandler
2011-12-28 10:01:25 +00:00
*/
public static function getIPHandler ()
{
return self :: getSingleton ( 'eIPHandler' , true );
}
2009-11-04 03:07:44 +00:00
/**
2009-11-26 17:14:07 +00:00
* Retrieve Xml handler singleton or new instance object
* @ param mixed $singleton false - new instance , true - singleton from default registry location , 'string' - registry path
* @ return xmlClass
2009-11-04 03:07:44 +00:00
*/
2009-11-26 17:14:07 +00:00
public static function getXml ( $singleton = true )
2009-11-04 03:07:44 +00:00
{
2009-11-26 17:14:07 +00:00
if ( $singleton )
{
return self :: getSingleton ( 'xmlClass' , true , ( true === $singleton ? '' : $singleton ));
}
return self :: getObject ( 'xmlClass' , null , true );
2009-11-04 03:07:44 +00:00
}
2012-07-31 07:32:00 +00:00
/**
* Retrieve HybridAuth object
*
* @ return Hybrid_Auth
*/
2012-12-20 10:45:22 +02:00
public static function getHybridAuth ( $config = null )
2012-07-31 07:32:00 +00:00
{
2012-12-20 10:45:22 +02:00
if ( null === $config )
{
$config = array (
'base_url' => e107 :: getUrl () -> create ( 'system/xup/endpoint' , array (), array ( 'full' => true )),
'providers' => e107 :: getPref ( 'social_login' , array ()),
'debug_mode' => false ,
'debug_file' => ''
);
}
2012-07-31 07:32:00 +00:00
return new Hybrid_Auth ( $config );
}
2009-12-02 16:51:04 +00:00
2010-05-02 18:41:20 +00:00
/**
* Retrieve userclass singleton object
*
* @ return user_class
*/
public static function getUserClass ()
{
return self :: getSingleton ( 'user_class' , true );
}
/**
* Retrieve user model object .
*
* @ param integer $user_id target user
2010-05-05 15:05:32 +00:00
* @ param boolean $checkIfCurrent if tru user_id will be compared to current user , if there is a match
* current user object will be returned
2010-05-02 18:41:20 +00:00
* @ return e_system_user
*/
2010-05-05 15:05:32 +00:00
public static function getSystemUser ( $user_id , $checkIfCurrent = true )
2010-05-02 18:41:20 +00:00
{
2010-05-05 15:05:32 +00:00
if ( $checkIfCurrent && $user_id && $user_id === self :: getUser () -> getId ())
{
return self :: getUser ();
}
2012-03-22 15:34:47 +00:00
if ( ! $user_id ) return self :: getObject ( 'e_system_user' );
2010-05-13 15:47:31 +00:00
$user = self :: getRegistry ( 'core/e107/user/' . $user_id );
2010-05-02 18:41:20 +00:00
if ( null === $user )
{
2010-05-05 15:05:32 +00:00
$user = self :: getObject ( 'e_system_user' );
2010-05-02 18:41:20 +00:00
if ( $user_id ) $user -> load ( $user_id ); // self registered on load
}
return $user ;
}
2010-05-05 15:05:32 +00:00
2013-03-31 04:21:49 -07:00
/**
* Simple replacement for deprecated get_user_data () . e107 :: user ();
* @ param $uid integer user_id or leave empty for currently logged in user .
* @ return array of user data
*/
public static function user ( $uid = null )
{
if ( ! $uid ){ return false ; }
$user = self :: getSystemUser ( $uid , true );
$var = array ();
if ( $user )
{
$var = $user -> getUserData ();
}
return $var ;
}
2013-03-31 05:55:08 -07:00
/**
* Return a string containg exported array data . - preferred .
*
* @ param array $ArrayData array to be stored
* @ param bool $AddSlashes default false , add slashes for db storage , else false
* @ return string
*/
public static function serialize ( $ArrayData , $AddSlashes = false )
{
return self :: getArrayStorage () -> serialize ( $ArrayData , $AddSlashes );
}
/**
* Returns an array from stored array data .
*
* @ param string $ArrayData
* @ return array stored data
*/
public static function unserialize ( $ArrayData )
{
return self :: getArrayStorage () -> unserialize ( $ArrayData );
}
2013-03-31 04:21:49 -07:00
2010-05-02 18:41:20 +00:00
/**
* Retrieve current user model object .
*
* @ return e_user
*/
public static function getUser ()
{
2010-05-13 15:47:31 +00:00
$user = self :: getRegistry ( 'core/e107/current_user' );
if ( null === $user )
{
$user = self :: getObject ( 'e_user' );
self :: setRegistry ( 'core/e107/current_user' , $user );
}
return $user ;
2010-05-02 18:41:20 +00:00
}
2010-05-05 15:05:32 +00:00
2010-05-02 18:41:20 +00:00
/**
* Retrieve user model object .
*
* @ param integer $user_id target user
* @ return e_current_user
*/
public static function getUserStructure ()
{
return self :: getSingleton ( 'e_user_extended_structure_tree' , true );
}
2009-11-10 23:13:30 +00:00
/**
* Retrieve User Extended handler singleton object
* @ return e107_user_extended
*/
public static function getUserExt ()
{
return self :: getSingleton ( 'e107_user_extended' , true );
}
2010-05-05 15:05:32 +00:00
2010-05-02 18:41:20 +00:00
/**
* Retrieve User Perms ( admin perms ) handler singleton object
2012-12-08 21:09:58 +02:00
* @ return e_userperms
2010-05-02 18:41:20 +00:00
*/
public static function getUserPerms ()
{
return self :: getSingleton ( 'e_userperms' , true );
}
2009-12-02 16:51:04 +00:00
2010-03-13 18:59:28 +00:00
/**
* Retrieve online users handler singleton object
2011-05-03 22:13:59 +00:00
* @ return e_ranks
2010-03-13 18:59:28 +00:00
*/
public static function getRank ()
{
return self :: getSingleton ( 'e_ranks' , true );
}
2011-05-18 08:58:35 +00:00
/**
* Retrieve plugin handler singleton object
2013-02-08 09:15:57 +02:00
* @ return e107plugin
2011-05-18 08:58:35 +00:00
*/
public static function getPlugin ()
{
return self :: getSingleton ( 'e107plugin' , true );
}
2009-07-23 15:29:07 +00:00
/**
* Retrieve online users handler singleton object
* @ return e_online
*/
public static function getOnline ()
{
2009-09-13 16:37:18 +00:00
return self :: getSingleton ( 'e_online' , true );
2009-07-23 15:29:07 +00:00
}
2009-11-12 05:11:47 +00:00
2013-05-14 23:46:48 -07:00
/**
* Retrieve chart handler singleton object
* @ return e_chart
*/
public static function getChart ()
{
return self :: getSingleton ( 'e_chart' , true );
}
2009-11-04 03:07:44 +00:00
/**
* Retrieve comments handler singleton object
* @ return comment
*/
public static function getComment ()
{
return self :: getSingleton ( 'comment' , true );
}
2010-03-16 13:04:23 +00:00
2010-03-14 02:11:23 +00:00
/**
* Retrieve Media handler singleton object
2010-04-15 15:38:16 +00:00
* @ return e_media
2010-03-14 02:11:23 +00:00
*/
public static function getMedia ()
{
return self :: getSingleton ( 'e_media' , true );
}
2012-12-03 01:40:47 -08:00
/**
* Retrieve Navigation Menu handler singleton object
2012-12-14 12:19:13 +02:00
* @ return e_navigation
2012-12-03 01:40:47 -08:00
*/
public static function getNav ()
{
return self :: getSingleton ( 'e_navigation' , true );
}
2009-12-02 16:51:04 +00:00
2009-09-19 15:27:26 +00:00
/**
* Retrieve message handler singleton
* @ return eMessage
*/
2009-09-29 17:43:13 +00:00
public static function getMessage ()
2009-09-19 15:27:26 +00:00
{
2011-11-25 17:24:42 +00:00
// static $included = false;
// if(!$included)
// {
// e107_require_once(e_HANDLER.'message_handler.php');
// $included = true;
// }
// return eMessage::getInstance();
return self :: getSingleton ( 'eMessage' , true );
2009-09-19 15:27:26 +00:00
}
2009-12-02 16:51:04 +00:00
2009-09-29 17:43:13 +00:00
/**
* Retrieve JS Manager singleton object
*
* @ return e_jsmanager
*/
public static function getJs ()
{
static $included = false ;
if ( ! $included )
{
e107_require_once ( e_HANDLER . 'js_manager.php' );
$included = true ;
}
return e_jsmanager :: getInstance ();
}
2012-05-14 06:26:52 +00:00
/**
2012-05-14 06:58:59 +00:00
* JS Common Public Function . Prefered is shortcode script path
2012-05-14 06:26:52 +00:00
* @ param string $type core | theme | footer | inline | footer - inline | url or any existing plugin_name
* @ param string $data depends on the type - path / url or inline js source
* @ param integer $zone [ optional ] leave it null for default zone
2012-05-15 09:55:27 +00:00
* @ param string $dep dependence : null | prototype | jquery
2012-05-14 06:26:52 +00:00
*/
2013-10-16 18:20:21 +03:00
public static function js ( $type , $data , $dep = null , $zone = null , $pre = '' , $post = '' )
2012-05-14 06:26:52 +00:00
{
$jshandler = e107 :: getJs ();
2012-05-15 09:55:27 +00:00
$jshandler -> setDependency ( $dep );
2012-05-14 06:26:52 +00:00
switch ( $type )
{
case 'core' :
// data is e.g. 'core/tabs.js'
if ( null !== $zone ) $jshandler -> requireCoreLib ( $data , $zone );
else $jshandler -> requireCoreLib ( $data );
break ;
2013-06-17 16:44:46 -07:00
case 'bootstrap' : //TODO Eventually add own method and render for bootstrap.
if ( null !== $zone ) $jshandler -> requireCoreLib ( 'bootstrap/js/' . $data , $zone );
else $jshandler -> requireCoreLib ( 'bootstrap/js/' . $data );
break ;
2012-05-14 06:26:52 +00:00
case 'theme' :
// data is e.g. 'jslib/mytheme.js'
2013-10-16 18:20:21 +03:00
if ( null !== $zone ) $jshandler -> headerTheme ( $data , $zone , $pre , $post );
else $jshandler -> headerTheme ( $data , 5 , $pre , $post );
2012-05-14 06:26:52 +00:00
break ;
case 'inline' :
// data is JS source (without script tags)
if ( null !== $zone ) $jshandler -> headerInline ( $data , $zone );
else $jshandler -> headerInline ( $data );
break ;
case 'footer-inline' :
// data is JS source (without script tags)
if ( null !== $zone ) $jshandler -> footerInline ( $data , $zone );
else $jshandler -> footerInline ( $data );
break ;
case 'url' :
// data is e.g. 'http://cdn.somesite.com/some.js'
2013-10-16 18:20:21 +03:00
if ( null !== $zone ) $jshandler -> headerFile ( $data , $zone , $pre , $post );
else $jshandler -> headerFile ( $data , 5 , $pre , $post );
2012-05-14 06:26:52 +00:00
break ;
case 'footer' :
// data is e.g. '{e_PLUGIN}myplugin/jslib/myplug.js'
if ( null !== $zone ) $jshandler -> footerFile ( $data , $zone );
else $jshandler -> footerFile ( $data );
break ;
// $type is plugin name
default :
// data is e.g. 'jslib/myplug.js'
2012-05-14 19:44:17 +00:00
if ( ! self :: isInstalled ( $type )) return ;
2012-05-14 06:26:52 +00:00
if ( null !== $zone ) $jshandler -> requirePluginLib ( $type , $data , $zone );
else $jshandler -> requirePluginLib ( $type , $data );
break ;
}
2012-05-15 09:55:27 +00:00
$jshandler -> resetDependency ();
2012-05-14 06:26:52 +00:00
}
/**
2012-05-14 06:58:59 +00:00
* CSS Common Public Function . Prefered is shortcode script path
2012-05-14 06:26:52 +00:00
* @ param string $type core | theme | footer | inline | footer - inline | url or any existing plugin_name
* @ param string $data depends on the type - path / url or inline js source
* @ param string $media any valid media attribute string - http :// www . w3schools . com / TAGS / att_link_media . asp
* @ param string $preComment possible comment e . g . <!-- [ if lt IE 7 ] >
* @ param string $postComment possible comment e . g . <! [ endif ] -->
*/
2012-05-15 09:55:27 +00:00
public static function css ( $type , $data , $dep = null , $media = 'all' , $preComment = '' , $postComment = '' , $dependence = null )
2012-05-14 06:26:52 +00:00
{
2013-06-17 16:03:33 -07:00
if (( strstr ( $data , 'bootstrap.css' ) || strstr ( $data , 'bootstrap.min.css' )) && ! defined ( " BOOTSTRAP " )) // detect bootstrap is enabled. - used in nextprev.sc and forum currently.
2013-03-14 04:05:33 -07:00
{
2013-06-17 16:03:33 -07:00
define ( " BOOTSTRAP " , true );
2013-03-14 04:05:33 -07:00
}
2012-05-14 06:26:52 +00:00
$jshandler = e107 :: getJs ();
2012-05-15 09:55:27 +00:00
$jshandler -> setDependency ( $dep );
2012-05-14 06:26:52 +00:00
switch ( $type )
{
case 'core' :
// data is path relative to e_FILE/jslib/
$jshandler -> coreCSS ( $data , $media , $preComment , $postComment );
break ;
2013-06-17 16:44:46 -07:00
case 'bootstrap' :
// data is path relative to e_FILE/jslib/
$jshandler -> coreCSS ( 'bootstrap/css/' . $data , $media , $preComment , $postComment );
break ;
2012-05-14 06:26:52 +00:00
case 'theme' :
// data is path relative to current theme
$jshandler -> themeCSS ( $data , $media , $preComment , $postComment );
break ;
case 'inline' :
// data is CSS source (without style tags)
$jshandler -> inlineCSS ( $data , $media );
break ;
case 'url' :
// data is e.g. 'http://cdn.somesite.com/some.css'
$jshandler -> otherCSS ( $data , $media , $preComment , $postComment );
break ;
// $type is plugin name
default :
// data is e.g. 'css/myplug.css'
2012-05-14 19:44:17 +00:00
if ( self :: isInstalled ( $type )) $jshandler -> pluginCSS ( $type , $data , $media , $preComment , $postComment );
2012-05-14 06:26:52 +00:00
break ;
}
2012-05-15 09:55:27 +00:00
$jshandler -> resetDependency ();
2012-05-14 06:26:52 +00:00
}
2010-02-09 20:43:54 +00:00
2010-01-26 12:25:59 +00:00
/**
* Retrieve JS Helper object
*
* @ param boolean | string $singleton if true return singleton , if string return singleton object , use string as namespace , default false
* @ return e_jshelper
*/
public static function getJshelper ( $singleton = false )
{
if ( $singleton )
{
return self :: getSingleton ( 'e_jshelper' , true , ( true === $singleton ? '' : $singleton ));
}
return self :: getObject ( 'e_jshelper' , null , true );
}
2012-05-11 09:54:12 +00:00
/**
* @ see eResponse :: addMeta ()
* @ return eResponse
*/
public static function meta ( $name = null , $content = null , $extended = array ())
{
2014-01-23 09:18:40 -08:00
if ( $name == 'description' )
{
e107 :: getUrl () -> response () -> addMetaDescription ( $content ); //Cam: TBD
}
if ( $name == 'keywords' )
{
e107 :: getUrl () -> response () -> addMetaKeywords ( $content ); //Cam: TBD
}
2012-05-11 09:54:12 +00:00
return e107 :: getUrl () -> response () -> addMeta ( $name , $content , $extended );
}
2009-12-02 16:51:04 +00:00
2009-10-31 17:57:15 +00:00
/**
* Retrieve admin dispatcher instance .
* It ' s instance is self registered ( for now , this could change in the future ) on initialization ( __construct ())
2009-12-02 16:51:04 +00:00
*
2009-10-31 17:57:15 +00:00
* @ see e_admin_dispatcher
* @ return e_admin_dispatcher
*/
public static function getAdminUI ()
{
return self :: getRegistry ( 'admin/ui/dispatcher' );
}
2009-12-02 16:51:04 +00:00
2013-02-14 15:37:42 +02:00
/**
2014-01-22 06:10:44 -08:00
* Retrieves class Object for specific plugin ' s addon such as e_url . php , e_cron . php , e_sitelink . php
2013-02-14 15:37:42 +02:00
* FIXME override from e . g . core / override / addons /
*
* @ param string $pluginName e . g . faq , page
* @ param string $addonName eg . e_cron , e_url , e_module
* @ param mixed $className [ optional ] true - use default name , false - no object is returned ( include only ), any string will be used as class name
* @ return none
*/
public static function getAddon ( $pluginName , $addonName , $className = true )
{
$filename = $addonName ; // e.g. 'e_cron';
// fixme, temporary adding 's' to className, should be core fixed, better naming
2013-02-14 16:18:22 +02:00
if ( true === $className ) $className = $pluginName . '_' . substr ( $addonName , 2 ); // remove 'e_'
2009-12-02 16:51:04 +00:00
2013-02-14 15:37:42 +02:00
$elist = self :: getPref ( $filename . '_list' );
if ( ! isset ( $elist [ $pluginName ])) return null ;
// TODO override check comes here
$path = e_PLUGIN . $pluginName . '/' . $filename . '.php' ;
// e.g. include e_module, e_meta etc
if ( false === $className ) return include_once ( $path );
if ( ! class_exists ( $className , false ))
{
include_once ( $path );
}
if ( ! class_exists ( $className , false ))
{
return null ;
}
return new $className ;
}
2009-12-02 16:51:04 +00:00
2009-11-20 05:01:51 +00:00
/**
2014-01-05 11:25:30 -08:00
* Retrieves config () from all plugins for addons such as e_url . php , e_cron . php , e_sitelink . php
2009-11-20 23:27:25 +00:00
* @ param string $addonName eg . e_cron , e_url
* @ param string $className [ optional ] ( if different from addonName )
2009-12-13 21:52:32 +00:00
* @ return none
2009-11-20 05:01:51 +00:00
*/
2009-12-02 16:51:04 +00:00
public function getAddonConfig ( $addonName , $className = '' )
2009-11-20 05:01:51 +00:00
{
2009-11-20 23:27:25 +00:00
$new_addon = array ();
2012-12-08 01:31:00 -08:00
$sql = e107 :: getDb (); // Might be used by older plugins.
2009-12-02 16:51:04 +00:00
2009-11-20 23:27:25 +00:00
$filename = $addonName ; // e.g. 'e_cron';
2009-11-20 05:01:51 +00:00
if ( ! $className )
{
2009-11-20 23:27:25 +00:00
$className = substr ( $filename , 2 ); // remove 'e_'
2009-12-02 16:51:04 +00:00
}
2009-11-20 23:27:25 +00:00
$elist = self :: getPref ( $filename . '_list' );
2014-01-05 11:25:30 -08:00
2009-11-20 23:27:25 +00:00
if ( $elist )
2009-12-02 16:51:04 +00:00
{
2009-11-20 23:27:25 +00:00
foreach ( array_keys ( $elist ) as $key )
2009-11-20 05:01:51 +00:00
{
2009-11-20 23:27:25 +00:00
if ( is_readable ( e_PLUGIN . $key . '/' . $filename . '.php' ))
2009-11-20 05:01:51 +00:00
{
2009-11-20 23:27:25 +00:00
include_once ( e_PLUGIN . $key . '/' . $filename . '.php' );
2009-12-02 16:51:04 +00:00
2009-11-20 23:27:25 +00:00
$class_name = $key . '_' . $className ;
$array = self :: callMethod ( $class_name , 'config' );
2009-12-02 16:51:04 +00:00
2009-11-20 23:27:25 +00:00
if ( $array )
2009-11-20 05:01:51 +00:00
{
2009-11-20 23:27:25 +00:00
$new_addon [ $key ] = $array ;
2009-11-20 05:01:51 +00:00
}
2009-12-02 16:51:04 +00:00
2009-11-20 05:01:51 +00:00
}
}
}
2009-12-02 16:51:04 +00:00
2009-11-20 23:27:25 +00:00
return $new_addon ;
2009-11-20 05:01:51 +00:00
}
2009-11-20 23:27:25 +00:00
2009-11-20 05:01:51 +00:00
/**
2009-12-02 16:51:04 +00:00
* Safe way to call user methods .
2009-11-20 23:27:25 +00:00
* @ param string $class_name
* @ param string $method_name
2009-12-13 21:52:32 +00:00
* @ return boolean FALSE
2009-11-20 05:01:51 +00:00
*/
2011-11-25 17:24:42 +00:00
public static function callMethod ( $class_name , $method_name , $param = '' )
2009-11-20 05:01:51 +00:00
{
$mes = e107 :: getMessage ();
if ( class_exists ( $class_name ))
{
$obj = new $class_name ;
2009-11-20 23:27:25 +00:00
if ( method_exists ( $obj , $method_name ))
2009-11-20 05:01:51 +00:00
{
2013-03-08 02:19:18 -08:00
if ( E107_DBG_INCLUDES )
{
$mes -> debug ( 'Executing <strong>' . $class_name . ' :: ' . $method_name . '()</strong>' );
}
2011-05-10 12:47:03 +00:00
return call_user_func ( array ( $obj , $method_name ), $param );
2009-11-20 05:01:51 +00:00
}
else
{
2009-12-02 16:51:04 +00:00
$mes -> debug ( 'Function <strong>' . $class_name . ' :: ' . $method_name . '()</strong> NOT found.' );
}
2009-11-20 05:01:51 +00:00
}
return FALSE ;
}
2009-11-20 23:27:25 +00:00
2009-11-28 15:34:46 +00:00
/**
* Get theme name or path .
2009-12-02 16:51:04 +00:00
*
2009-11-28 15:34:46 +00:00
* @ param mixed $for true ( default ) - auto - detect ( current ), admin - admin theme , front - site theme
* @ param string $path default empty string ( return name only ), 'abs' - absolute url path , 'rel' - relative server path
* @ return string
*/
public static function getThemeInfo ( $for = true , $path = '' )
{
global $user_pref ; // FIXME - user model, kill user_pref global
2009-12-02 16:51:04 +00:00
2009-11-28 15:34:46 +00:00
if ( true === $for )
{
$for = e_ADMIN_AREA ? 'admin' : 'front' ;
}
switch ( $for )
{
case 'admin' :
$for = e107 :: getPref ( 'admintheme' );
break ;
2009-12-02 16:51:04 +00:00
2009-11-28 15:34:46 +00:00
case 'front' :
$for = isset ( $user_pref [ 'sitetheme' ]) ? $user_pref [ 'sitetheme' ] : e107 :: getPref ( 'sitetheme' );
break ;
}
if ( ! $path ) return $for ;
switch ( $path )
{
case 'abs' :
$path = e_THEME_ABS . $for . '/' ;
break ;
2009-12-02 16:51:04 +00:00
2009-11-28 15:34:46 +00:00
case 'rel' :
default :
$path = e_THEME . $for . '/' ;
break ;
}
return $path ;
}
2009-11-12 16:47:36 +00:00
/**
* Retrieve core template path
* Example : < code > echo e107 :: coreTemplatePath ( 'admin_icons' ); </ code >
2009-12-02 16:51:04 +00:00
*
2009-11-28 15:34:46 +00:00
* @ see getThemeInfo ()
2009-11-12 16:47:36 +00:00
* @ param string $id part of the path / file name without _template . php part
* @ param boolean $override default true
* @ return string relative path
*/
public static function coreTemplatePath ( $id , $override = true )
{
$id = str_replace ( '..' , '' , $id ); //simple security, '/' is allowed
2012-12-11 15:08:29 -08:00
$override_path = $override ? self :: getThemeInfo ( $override , 'rel' ) . 'templates/' . $id . '_template.php' : null ;
$legacy_path = e_THEME . 'templates/' . $id . '_template.php' ;
$core_path = e_CORE . 'templates/' . $id . '_template.php' ;
if ( $override_path && is_readable ( $override_path ))
{
return $override_path ;
}
elseif ( is_readable ( $legacy_path ))
{
return $legacy_path ;
}
2009-12-02 16:51:04 +00:00
2012-12-11 15:08:29 -08:00
return $core_path ;
2009-11-12 16:47:36 +00:00
}
2009-12-02 16:51:04 +00:00
2009-11-12 16:47:36 +00:00
/**
* Retrieve plugin template path
2009-12-02 16:51:04 +00:00
* Override path could be forced to front - or back - end via
2009-11-28 15:34:46 +00:00
* the $override parameter e . g . < code > e107 :: templatePath ( plug_name , 'my' , 'front' ) </ code >
2009-12-02 16:51:04 +00:00
* Example :
2009-11-12 16:47:36 +00:00
* < code >
* echo e107 :: templatePath ( plug_name , 'my' );
* // result is something like:
* // e107_themes/current_theme/templates/plug_name/my_template.php
2009-12-02 16:51:04 +00:00
* // or if not found
2009-11-12 16:47:36 +00:00
* // e107_plugins/plug_name/templates/my_template.php
* </ code >
2009-12-02 16:51:04 +00:00
*
2009-11-28 15:34:46 +00:00
* @ see getThemeInfo ()
2009-11-12 16:47:36 +00:00
* @ param string $plug_name plugin name
* @ param string $id part of the path / file name without _template . php part
2009-11-28 15:34:46 +00:00
* @ param boolean | string $override default true
2009-11-12 16:47:36 +00:00
* @ return string relative path
*/
public static function templatePath ( $plug_name , $id , $override = true )
{
$id = str_replace ( '..' , '' , $id ); //simple security, '/' is allowed
$plug_name = preg_replace ( '#[^a-z0-9_]#i' , '' , $plug_name ); // only latin allowed, so \w not a solution since PHP5.3
2009-11-28 15:34:46 +00:00
$override_path = $override ? self :: getThemeInfo ( $override , 'rel' ) . 'templates/' . $plug_name . '/' . $id . '_template.php' : null ;
2009-11-12 16:47:36 +00:00
$default_path = e_PLUGIN . $plug_name . '/templates/' . $id . '_template.php' ;
2009-11-28 15:34:46 +00:00
2009-11-12 16:47:36 +00:00
return ( $override_path && is_readable ( $override_path ) ? $override_path : $default_path );
}
2009-12-02 16:51:04 +00:00
2009-07-22 14:32:51 +00:00
/**
2009-12-02 16:51:04 +00:00
* Get core template . Use this method for templates , which are following the
2009-07-22 14:32:51 +00:00
* new template standards :
2009-10-28 14:13:44 +00:00
* - template variables naming conventions
2009-07-22 14:32:51 +00:00
* - one array variable per template only
* - theme override is made now by current_theme / templates / folder
2009-12-02 16:51:04 +00:00
*
2009-07-22 14:32:51 +00:00
* < br >< br > Results are cached ( depending on $id and $override so it ' s safe to use
2009-12-02 16:51:04 +00:00
* this method e . g . in loop for retrieving a template string . If template ( or template key ) is not
2009-10-28 14:13:44 +00:00
* found , < b > NULL </ b > is returned .< br >< br >
2009-12-02 16:51:04 +00:00
*
2009-07-22 14:32:51 +00:00
* Example usage : < code > e107 :: getCoreTemplate ( 'user' , 'short_start' ); </ code >
* Will search for :
* - e107_themes / current_frontend_theme / templates / user_template . php ( if $override is true )
* - e107_themes / templates / user_template . php ( if override not found or $override is false )
* - $USER_TEMPLATE array which contains all user templates
* - $USER_TEMPLATE [ 'short_start' ] ( if key is null , $USER_TEMPLATE will be returned )
2009-12-02 16:51:04 +00:00
*
2009-10-28 14:13:44 +00:00
* @ param string $id - file prefix , e . g . user for user_template . php
2009-07-22 14:32:51 +00:00
* @ param string | null $key
2009-12-13 21:52:32 +00:00
* @ param boolean $override see { @ link getThemeInfo ()}
2009-12-09 18:33:43 +00:00
* @ param boolean $merge merge theme with core templates , default is false
2009-12-12 16:40:41 +00:00
* @ param boolean $info retrieve template info only
2009-07-22 14:32:51 +00:00
* @ return string | array
*/
2009-12-12 16:40:41 +00:00
public static function getCoreTemplate ( $id , $key = null , $override = true , $merge = false , $info = false )
2009-07-22 14:32:51 +00:00
{
2009-11-19 11:12:08 +00:00
$reg_path = 'core/e107/templates/' . $id . ( $override ? '/ext' : '' );
2009-11-28 15:34:46 +00:00
$path = self :: coreTemplatePath ( $id , $override );
2009-12-08 17:21:36 +00:00
$id = str_replace ( '/' , '_' , $id );
2009-12-12 16:40:41 +00:00
$ret = self :: _getTemplate ( $id , $key , $reg_path , $path , $info );
2013-06-01 14:02:46 -07:00
2013-10-16 18:46:41 +03:00
### Attempt to fix merge issues; in case we override - template array not found in theme,
### so we need to continue and merge with core templates
if ( $merge && $override && empty ( $ret ))
2009-12-09 18:33:43 +00:00
{
2013-10-16 18:46:41 +03:00
$ret = array ();
2009-12-09 18:33:43 +00:00
}
2013-06-01 14:02:46 -07:00
2013-10-16 18:46:41 +03:00
if (( ! $merge && ! $override ) || is_string ( $ret ))
2013-06-01 14:02:46 -07:00
{
2013-10-16 18:46:41 +03:00
return $ret ;
2013-06-01 14:02:46 -07:00
}
2009-12-09 18:33:43 +00:00
// merge
$reg_path = 'core/e107/templates/' . $id ;
$path = self :: coreTemplatePath ( $id , false );
$id = str_replace ( '/' , '_' , $id );
2009-12-12 16:40:41 +00:00
$ret_core = self :: _getTemplate ( $id , $key , $reg_path , $path , $info );
2013-06-01 14:02:46 -07:00
2009-12-09 18:33:43 +00:00
return ( is_array ( $ret_core ) ? array_merge ( $ret_core , $ret ) : $ret );
2009-07-22 14:32:51 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 14:32:51 +00:00
/**
2009-12-02 16:51:04 +00:00
* Get plugin template . Use this method for plugin templates , which are following the
2009-07-22 14:32:51 +00:00
* new template standards :
2012-04-23 01:21:06 +00:00
* - template variables naming conventions ie . $ { NAME IN CAPS } _TEMPLATE [ '{ID}' ] = " <div>...</div> " ;
2009-07-22 14:32:51 +00:00
* - one array variable per template only
* - theme override is made now by current_theme / templates / plugin_name / folder
2009-12-02 16:51:04 +00:00
*
2009-07-22 14:32:51 +00:00
* < br >< br > Results are cached ( depending on $id and $override so it ' s safe to use
2009-12-02 16:51:04 +00:00
* this method e . g . in loop for retrieving a template string . If template ( or template key ) is not
2009-10-28 14:13:44 +00:00
* found , < b > NULL </ b > is returned .< br >< br >
2009-12-02 16:51:04 +00:00
*
2009-07-22 14:32:51 +00:00
* Example usage : < code > e107 :: getTemplate ( 'user' , 'short_start' ); </ code >
* Will search for :
* - e107_themes / current_frontend_theme / templates / user_template . php ( if $override is true )
* - e107_themes / templates / user_template . php ( if override not found or $override is false )
* - $USER_TEMPLATE array which contains all user templates
* - $USER_TEMPLATE [ 'short_start' ] ( if key is null , $USER_TEMPLATE will be returned )
2009-12-02 16:51:04 +00:00
*
2010-02-27 19:05:07 +00:00
* @ param string $plug_name if null getCoreTemplate method will be called
2009-10-28 14:13:44 +00:00
* @ param string $id - file prefix , e . g . calendar for calendar_template . php
2009-07-22 14:32:51 +00:00
* @ param string | null $key
2009-12-13 21:52:32 +00:00
* @ param boolean $override see { @ link getThemeInfo ()}
2009-12-09 18:33:43 +00:00
* @ param boolean $merge merge theme with plugin templates , default is false
2009-12-12 16:40:41 +00:00
* @ param boolean $info retrieve template info only
2009-07-22 14:32:51 +00:00
* @ return string | array
*/
2012-04-23 01:21:06 +00:00
public static function getTemplate ( $plug_name , $id = null , $key = null , $override = true , $merge = false , $info = false )
2009-07-22 14:32:51 +00:00
{
2010-02-27 19:05:07 +00:00
if ( null === $plug_name )
{
return self :: getCoreTemplate ( $id , $key , $override , $merge , $info );
}
2013-03-07 10:22:03 +02:00
if ( null == $id || true === $id ) // loads {$plug_name}/templates/{$plug_name}_template.php and an array ${PLUG_NAME}_TEMPLATE
2012-04-23 01:21:06 +00:00
{
$id = $plug_name ;
}
2009-11-19 11:12:08 +00:00
$reg_path = 'plugin/' . $plug_name . '/templates/' . $id . ( $override ? '/ext' : '' );
2009-11-28 15:34:46 +00:00
$path = self :: templatePath ( $plug_name , $id , $override );
2013-06-22 18:24:43 -07:00
if ( ADMIN && E107_DBG_INCLUDES )
{
e107 :: getMessage () -> addDebug ( " template path= " . $path );
}
2009-12-08 17:21:36 +00:00
$id = str_replace ( '/' , '_' , $id );
2009-12-12 16:40:41 +00:00
$ret = self :: _getTemplate ( $id , $key , $reg_path , $path , $info );
2009-12-09 18:33:43 +00:00
if ( ! $merge || ! $override || ! is_array ( $ret ))
{
return $ret ;
}
2010-02-09 20:43:54 +00:00
2009-12-09 18:33:43 +00:00
// merge
$reg_path = 'plugin/' . $plug_name . '/templates/' . $id ;
$path = self :: templatePath ( $plug_name , $id , false );
2013-06-22 18:24:43 -07:00
2009-12-09 18:33:43 +00:00
$id = str_replace ( '/' , '_' , $id );
2009-12-12 16:40:41 +00:00
$ret_plug = self :: _getTemplate ( $id , $key , $reg_path , $path , $info );
2010-02-09 20:43:54 +00:00
2009-12-09 18:33:43 +00:00
return ( is_array ( $ret_plug ) ? array_merge ( $ret_plug , $ret ) : $ret );
2009-07-22 14:32:51 +00:00
}
2013-04-28 19:14:14 +03:00
/**
* Register sc_style registry
* @ param string $templateId e . g . 'contact/form' or 'contact' for all contact template wrappers
* @ param string $scName [ optional ] shortcode name - if provided , wrapper ( string ) for the corresponding code will be returned
* @ return array | string
*/
public static function templateWrapper ( $templateId , $scName = null )
{
if ( ! $templateId ) return array ();
list ( $templateId , $templateKey ) = explode ( '/' , $templateId , 2 );
$wrapperRegPath = 'templates/wrapper/' . $templateId ;
$wrapper = self :: getRegistry ( $wrapperRegPath );
if ( empty ( $wrapper ) || ! is_array ( $wrapper )) $wrapper = array ();
if ( $templateKey ) $wrapper = ( isset ( $wrapper [ $templateKey ]) ? $wrapper [ $templateKey ] : array ());
if ( null !== $scName )
{
$scName = strtoupper ( $scName );
return isset ( $wrapper [ $scName ]) ? $wrapper [ $scName ] : '' ;
}
return $wrapper ;
}
/**
* Retrieve / set sc_style array ( global shortcode wrapper )
* @ param array $set template defined $sc_style , will be merged with current registry content
* @ return array
*/
public static function scStyle ( $set = null )
{
$_sc_style = self :: getRegistry ( 'shortcodes/sc_style' );
if ( ! is_array ( $_sc_style )) $_sc_style = array ();
if ( is_array ( $set ) && ! empty ( $set ))
{
self :: setRegistry ( 'shortcodes/sc_style' , array_merge ( $_sc_style , $set ));
}
return $_sc_style ;
}
2010-02-09 20:43:54 +00:00
2009-12-12 16:40:41 +00:00
/**
* Get Template Info array .
* Note : Available only after getTemplate () / getCoreTemplate () call
2010-02-09 20:43:54 +00:00
*
2009-12-12 16:40:41 +00:00
* @ param string $plug_name if null - search for core template
* @ param string $id
* @ param string $key
* @ param boolean $override
* @ param boolean $merge
* @ return array
*/
public function getTemplateInfo ( $plug_name = null , $id , $key = null , $override = true , $merge = false )
{
if ( $plug_name )
{
$ret = self :: getTemplate ( $plug_name , $id , null , $override , $merge , true );
}
else
{
$ret = self :: getCoreTemplate ( $id , null , $override , $merge , true );
}
if ( $key && isset ( $ret [ $key ]) && is_array ( $ret [ $key ]))
{
return $ret [ $key ];
}
return $ret ;
}
2009-11-26 09:02:46 +00:00
/**
2009-11-28 15:34:46 +00:00
* Return a list of available template IDs for a plugin ( eg . $MYTEMPLATE [ 'my_id' ] -> array ( 'id' => 'My Id' ))
2011-12-07 21:07:21 +00:00
*
* FIXME - the format of $allinfo = true array is not usable at all , convert it so that it ' s compatible with e_form :: selectbox () method
*
2009-11-28 15:34:46 +00:00
* @ param string $plugin_name
* @ param string $template_id [ optional ] if different from $plugin_name ;
* @ param mixed $where true - current theme , 'admin' - admin theme , 'front' ( default ) - front theme
2009-12-09 18:33:43 +00:00
* @ param boolean $merge merge theme with core / plugin layouts , default is false
2010-02-09 20:43:54 +00:00
* @ param boolean $allinfo reutrn nimerical array of templates and all available template information
2009-12-02 16:51:04 +00:00
* @ return array
2009-11-26 09:02:46 +00:00
*/
2009-12-12 16:40:41 +00:00
public static function getLayouts ( $plugin_name , $template_id = '' , $where = 'front' , $filter_mask = '' , $merge = false , $allinfo = true )
2009-11-26 09:02:46 +00:00
{
2009-11-28 15:34:46 +00:00
if ( ! $plugin_name ) // Core template
2009-11-26 09:02:46 +00:00
{
2009-12-09 18:33:43 +00:00
$tmp = self :: getCoreTemplate ( $template_id , null , $where , $merge );
2009-12-12 16:40:41 +00:00
$tmp_info = self :: getTemplateInfo ( null , $template_id , null , $where , $merge );
2009-11-26 09:02:46 +00:00
}
2009-11-28 15:34:46 +00:00
else // Plugin template
{
$id = ( ! $template_id ) ? $plugin_name : $template_id ;
2009-12-09 18:33:43 +00:00
$tmp = self :: getTemplate ( $plugin_name , $id , null , $where , $merge );
2009-12-12 16:40:41 +00:00
$tmp_info = self :: getTemplateInfo ( $plugin_name , $id , null , $where , $merge );
2009-11-28 15:34:46 +00:00
}
2009-12-02 16:51:04 +00:00
2010-02-09 20:43:54 +00:00
$templates = array ();
if ( ! $filter_mask )
2009-12-09 18:33:43 +00:00
{
$filter_mask = array ();
}
elseif ( ! is_array ( $filter_mask ))
{
2010-02-09 20:43:54 +00:00
$filter_mask = array ( $filter_mask );
2009-12-09 18:33:43 +00:00
}
2009-11-28 15:34:46 +00:00
foreach ( $tmp as $key => $val )
2009-11-26 09:02:46 +00:00
{
2009-11-28 15:34:46 +00:00
$match = true ;
if ( $filter_mask )
{
2010-02-09 20:43:54 +00:00
$match = false ;
2009-11-28 15:34:46 +00:00
foreach ( $filter_mask as $mask )
{
2009-12-09 18:33:43 +00:00
if ( preg_match ( $mask , $key )) //e.g. retrieve only keys starting with 'layout_'
2009-11-28 15:34:46 +00:00
{
$match = true ;
break ;
}
}
if ( ! $match ) continue ;
}
2009-12-12 16:40:41 +00:00
if ( isset ( $tmp_info [ $key ]))
2009-11-28 15:34:46 +00:00
{
2009-12-12 16:40:41 +00:00
$templates [ $key ] = defset ( $tmp_info [ $key ][ 'title' ], $tmp_info [ $key ][ 'title' ]);
2009-11-28 15:34:46 +00:00
continue ;
2009-12-02 16:51:04 +00:00
}
2009-11-28 15:34:46 +00:00
$templates [ $key ] = implode ( ' ' , array_map ( 'ucfirst' , explode ( '_' , $key ))); //TODO add LANS?
2009-11-26 09:02:46 +00:00
}
2009-12-12 16:40:41 +00:00
return ( $allinfo ? array ( $templates , $tmp_info ) : $templates );
2009-11-26 09:02:46 +00:00
}
2009-07-22 14:32:51 +00:00
/**
* More abstsract template loader , used
* internal in { @ link getTemplate ()} and { @ link getCoreTemplate ()} methods
2010-02-09 20:43:54 +00:00
* If $info is set to true , only template informational array will be returned
2009-07-22 14:32:51 +00:00
*
* @ param string $id
* @ param string | null $key
* @ param string $reg_path
2009-12-12 16:40:41 +00:00
* @ param string $path
* @ param boolean $info
2009-07-22 14:32:51 +00:00
* @ return string | array
*/
2009-12-12 16:40:41 +00:00
public static function _getTemplate ( $id , $key , $reg_path , $path , $info = false )
2009-07-22 14:32:51 +00:00
{
2009-11-12 16:47:36 +00:00
$regPath = $reg_path ;
2009-07-22 14:32:51 +00:00
$var = strtoupper ( $id ) . '_TEMPLATE' ;
2009-12-12 16:40:41 +00:00
$regPathInfo = $reg_path . '/info' ;
$var_info = strtoupper ( $id ) . '_INFO' ;
2013-04-26 13:48:23 -07:00
$wrapper = strtoupper ( $id ) . '_WRAPPER' ; // see contact_template.php
2013-04-28 19:14:14 +03:00
$wrapperRegPath = 'templates/wrapper/' . $id ;
2013-04-26 13:48:23 -07:00
//FIXME XXX URGENT - Add support for _WRAPPER and $sc_style BC. - save in registry and retrieve in getScBatch()?
// Use: list($pre,$post) = explode("{---}",$text,2);
2010-02-09 20:43:54 +00:00
2009-11-28 15:34:46 +00:00
if ( null === self :: getRegistry ( $regPath ))
2009-07-22 14:32:51 +00:00
{
2009-11-19 11:12:08 +00:00
( deftrue ( 'E107_DEBUG_LEVEL' ) ? include_once ( $path ) : @ include_once ( $path ));
2009-11-28 15:34:46 +00:00
self :: setRegistry ( $regPath , ( isset ( $$var ) ? $$var : array ()));
2013-04-28 19:14:14 +03:00
// sc_style not a global anymore and uppercase
2013-04-29 13:31:21 +03:00
if ( isset ( $SC_WRAPPER ))
2013-04-28 19:14:14 +03:00
{
2013-04-29 13:31:21 +03:00
self :: scStyle ( $SC_WRAPPER );
2013-04-28 19:14:14 +03:00
}
// ID_WRAPPER support
if ( isset ( $$wrapper ) && ! empty ( $$wrapper ) && is_array ( $$wrapper ))
{
self :: setRegistry ( $wrapperRegPath , $$wrapper );
}
2009-07-22 14:32:51 +00:00
}
2009-12-12 16:40:41 +00:00
if ( null === self :: getRegistry ( $regPathInfo ))
{
self :: setRegistry ( $regPathInfo , ( isset ( $$var_info ) && is_array ( $$var_info ) ? $$var_info : array ()));
}
2009-12-02 16:51:04 +00:00
2009-12-12 16:40:41 +00:00
$ret = ( ! $info ? self :: getRegistry ( $regPath ) : self :: getRegistry ( $regPathInfo ));
2009-07-22 14:32:51 +00:00
if ( ! $key )
{
2009-12-12 16:40:41 +00:00
return $ret ;
2009-07-22 14:32:51 +00:00
}
2013-04-26 13:48:23 -07:00
2009-12-12 16:40:41 +00:00
return ( $ret && is_array ( $ret ) && isset ( $ret [ $key ]) ? $ret [ $key ] : '' );
2009-07-22 14:32:51 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-22 14:32:51 +00:00
/**
* Load language file , replacement of include_lan ()
*
* @ param string $path
* @ param boolean $force
* @ return string
*/
2009-09-19 15:27:26 +00:00
public static function includeLan ( $path , $force = false )
2009-07-22 14:32:51 +00:00
{
if ( ! is_readable ( $path ))
{
2009-10-09 10:18:07 +00:00
if ( self :: getPref ( 'noLanguageSubs' ) || ( e_LANGUAGE == 'English' ))
2009-07-22 14:32:51 +00:00
{
return FALSE ;
}
2014-02-05 06:14:13 -08:00
2012-11-29 22:03:36 -08:00
self :: getMessage () -> addDebug ( " Couldn't load language file: " . $path );
2014-02-05 06:14:13 -08:00
$path = str_replace ( e_LANGUAGE , 'English' , $path );
2014-02-07 05:07:49 -08:00
if ( ! is_readable ( $path ))
{
return ;
}
2009-07-22 14:32:51 +00:00
}
2014-02-07 17:57:55 -08:00
$adminLanguage = self :: getPref ( 'adminlanguage' );
if ( e_ADMIN_AREA && vartrue ( $adminLanguage ))
{
$path = str_replace ( e_LANGUAGE , $adminLanguage , $path );
}
2014-02-05 06:14:13 -08:00
2009-07-22 14:32:51 +00:00
$ret = ( $force ) ? include ( $path ) : include_once ( $path );
return ( isset ( $ret )) ? $ret : " " ;
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
/**
* Simplify importing of core Language files .
* All inputs are sanitized .
* Core Exceptions as e_LANGUAGE . '.php' and e_LANGUAGE . '_custom.php' are manually loaded . ( see class2 . php )
*
* Examples :
* < code >< ? php
* // import defeinitions from /e107_languages/[CurrentLanguage]/lan_comment.php</code>
* e107 :: coreLan ( 'comment' );
*
* // import defeinitions from /e107_languages/[CurrentLanguage]/admin/lan_banlist.php
* e107 :: coreLan ( 'banlist' , true );
* </ code >
*
* @ param string $fname filename without the extension part ( e . g . 'comment' )
* @ param boolean $admin true if it ' s an administration language file
* @ return void
*/
public static function coreLan ( $fname , $admin = false )
{
$cstring = 'corelan/' . e_LANGUAGE . '_' . $fname . ( $admin ? '_admin' : '_front' );
if ( e107 :: getRegistry ( $cstring )) return ;
2013-05-27 15:18:56 +03:00
$fname = ( $admin ? 'admin/' : '' ) . 'lan_' . preg_replace ( '/[^\w]/' , '' , trim ( $fname , '/' )) . '.php' ;
2011-05-03 22:13:59 +00:00
$path = e_LANGUAGEDIR . e_LANGUAGE . '/' . $fname ;
e107 :: setRegistry ( $cstring , true );
self :: includeLan ( $path , false );
}
/**
* Simplify importing of plugin Language files ( following e107 plugin structure standards ) .
* All inputs are sanitized .
*
* Examples :
* < code >< ? php
2011-11-29 12:11:27 +00:00
* // import defeinitions from /e107_plugins/forum/languages/[CurrentLanguage]/lan_forum.php
2011-05-03 22:13:59 +00:00
* e107 :: plugLan ( 'forum' , 'lan_forum' );
*
2011-11-29 12:11:27 +00:00
* // import defeinitions from /e107_plugins/featurebox/languages/[CurrentLanguage]_admin_featurebox.php
2012-12-12 18:46:34 -08:00
* // OR /e107_plugins/featurebox/languages/[CurrentLanguage]/[CurrentLanguage]_admin_featurebox.php (auto-detected)
2011-05-03 22:13:59 +00:00
* e107 :: plugLan ( 'featurebox' , 'admin_featurebox' , true );
*
2013-05-27 15:18:56 +03:00
* // import defeinitions from /e107_plugins/myplug/languages/[CurrentLanguage]_front.php
2011-05-03 22:13:59 +00:00
* e107 :: plugLan ( 'myplug' );
2013-05-27 15:18:56 +03:00
*
* // import defeinitions from /e107_plugins/myplug/languages/[CurrentLanguage]_admin.php
* e107 :: plugLan ( 'myplug' , true );
2011-05-03 22:13:59 +00:00
*
2011-11-29 12:11:27 +00:00
* // import defeinitions from /e107_plugins/myplug/languages/[CurrentLanguage]/admin/common.php
2011-05-03 22:13:59 +00:00
* e107 :: plugLan ( 'myplug' , 'admin/common' );
* </ code >
*
* @ param string $plugin plugin name
* @ param string $fname filename without the extension part ( e . g . 'common' )
* @ param boolean $flat false ( default , preferred ) Language folder structure ; true - prepend Language to file name
* @ return void
*/
public static function plugLan ( $plugin , $fname = '' , $flat = false )
{
$cstring = 'pluglan/' . e_LANGUAGE . '_' . $plugin . '_' . $fname . ( $flat ? '_1' : '_0' );
if ( e107 :: getRegistry ( $cstring )) return ;
$plugin = preg_replace ( '/[^\w]/' , '' , $plugin );
2012-11-29 22:03:36 -08:00
if ( $fname && is_string ( $fname ))
{
2013-05-27 15:18:56 +03:00
$fname = e_LANGUAGE . ( $flat ? '_' : '/' ) . preg_replace ( '#[^\w/]#' , '' , trim ( $fname , '/' ));
2012-11-29 22:03:36 -08:00
}
2012-11-30 13:23:55 +02:00
elseif ( $fname === true ) // admin file.
2012-11-29 22:03:36 -08:00
{
2013-05-26 15:48:16 -07:00
//$fname = "admin/".e_LANGUAGE;
2013-05-26 15:55:14 -07:00
$fname = e_LANGUAGE . " _admin " ;
2012-11-29 22:03:36 -08:00
}
else
{
2013-05-26 15:48:16 -07:00
// $fname = e_LANGUAGE;
2013-05-26 15:55:14 -07:00
$fname = e_LANGUAGE . " _front " ;
2012-11-29 22:03:36 -08:00
}
2011-05-03 22:13:59 +00:00
2012-12-12 18:46:34 -08:00
if ( $flat === true && is_dir ( e_PLUGIN . $plugin . " /languages/ " . e_LANGUAGE )) // support for alt_auth/languages/English/English_log.php etc.
{
$path = e_PLUGIN . $plugin . '/languages/' . e_LANGUAGE . '/' . $fname . '.php' ;
}
else
{
$path = e_PLUGIN . $plugin . '/languages/' . $fname . '.php' ;
}
2012-12-12 22:39:18 -08:00
if ( E107_DBG_INCLUDES )
{
e107 :: getMessage () -> addDebug ( " Attempting to Load: " . $path );
}
2012-11-29 22:03:36 -08:00
2011-05-03 22:13:59 +00:00
e107 :: setRegistry ( $cstring , true );
self :: includeLan ( $path , false );
}
2011-11-29 12:11:27 +00:00
/**
* Simplify importing of theme Language files ( following e107 plugin structure standards ) .
* All inputs are sanitized .
*
* Examples :
* < code >< ? php
* // import defeinitions from /e107_themes/[CurrentTheme]/languages/[CurrentLanguage]/lan.php
* e107 :: themeLan ( 'lan' );
*
* // import defeinitions from /e107_themes/[currentTheme]/languages/[CurrentLanguage].php
* e107 :: themeLan ();
*
* // import defeinitions from /e107_themes/[currentTheme]/languages/[CurrentLanguage]_lan.php
* e107 :: themeLan ( 'lan' , null , true );
*
* // import defeinitions from /e107_themes/[currentTheme]/languages/[CurrentLanguage]/admin/lan.php
* e107 :: themeLan ( 'admin/lan' );
*
* // import defeinitions from /e107_themes/some_theme/languages/[CurrentLanguage].php
* e107 :: themeLan ( '' , 'some_theme' );
* </ code >
*
* @ param string $fname filename without the extension part ( e . g . 'common' for common . php )
* @ param string $theme theme name , if null current theme will be used
* @ param boolean $flat false ( default , preferred ) Language folder structure ; true - prepend Language to file name
* @ return void
*/
public static function themeLan ( $fname = '' , $theme = null , $flat = false )
{
if ( null === $theme ) $theme = THEME . '/languages/' ;
else $theme = e_THEME . preg_replace ( '#[^\w/]#' , '' , $theme ) . '/languages/' ;
$cstring = 'themelan/' . $theme . $fname . ( $flat ? '_1' : '_0' );
if ( e107 :: getRegistry ( $cstring )) return ;
2013-05-27 15:18:56 +03:00
if ( $fname ) $fname = e_LANGUAGE . ( $flat ? '_' : '/' ) . preg_replace ( '#[^\w/]#' , '' , trim ( $fname , '/' ));
2011-11-29 12:11:27 +00:00
else $fname = e_LANGUAGE ;
$path = $theme . $fname . '.php' ;
2013-03-14 04:05:33 -07:00
if ( E107_DBG_INCLUDES )
{
e107 :: getMessage () -> addDebug ( " Attempting to Load: " . $path );
}
2011-11-29 12:11:27 +00:00
e107 :: setRegistry ( $cstring , true );
self :: includeLan ( $path , false );
}
2011-05-03 22:13:59 +00:00
2012-11-27 14:00:19 -08:00
/**
* PREFERRED Generic Language File Loading Function for use by theme and plugin developers .
* Language - file equivalent to e107 :: js , e107 :: meta and e107 :: css
2013-05-27 15:18:56 +03:00
* FIXME disallow themes and plugins named 'core' and 'theme'
2012-11-27 14:00:19 -08:00
* @ param string $type : 'theme' or plugin name
* @ param $string $fname ( optional ) : relative path to the theme or plugin language folder . ( same as in the other functions )
2013-05-27 15:18:56 +03:00
* when missing , [ e_LANGUAGE ] _front . php will be used , when true [ e_LANGUAGE ] _admin . php will be used
2013-02-22 21:34:06 -08:00
* @ param $options : Set to True for admin .
2012-11-27 14:00:19 -08:00
* @ example e107 :: lan ( 'theme' ); // Loads THEME."languages/English.php (if English is the current language)
2013-05-27 15:18:56 +03:00
* @ example e107 :: lan ( 'gallery' ); // Loads e_PLUGIN."gallery/languages/English_front.php (if English is the current language)
* @ example e107 :: lan ( 'gallery' , 'admin' ); // Loads e_PLUGIN."gallery/languages/English/admin.php (if English is the current language)
* @ example e107 :: lan ( 'gallery' , 'admin' , true ); // Loads e_PLUGIN."gallery/languages/English_admin.php (if English is the current language)
* @ example e107 :: lan ( 'gallery' , 'admin/example' ); // Loads e_PLUGIN."gallery/languages/English/admin/example.php (if English is the current language)
* @ example e107 :: lan ( 'gallery' , true ); // Loads e_PLUGIN."gallery/languages/English_admin.php (if English is the current language)
* @ example e107 :: lan ( 'gallery' , " something " , true ); // Loads e_PLUGIN."gallery/languages/English_something.php (if English is the current language)
2012-11-27 14:00:19 -08:00
*/
2012-12-20 12:06:28 +02:00
public static function lan ( $type , $fname = null , $options = null )
2012-11-27 14:00:19 -08:00
{
2012-12-20 12:06:28 +02:00
$options = $options ? true : false ;
2012-11-27 14:00:19 -08:00
switch ( $type )
{
case 'core' :
2012-12-20 12:06:28 +02:00
self :: coreLan ( $fname , $options );
2012-12-06 16:36:22 -08:00
break ;
2012-11-27 14:00:19 -08:00
case 'theme' :
2012-12-20 12:06:28 +02:00
self :: themeLan ( $fname , null , $options );
2012-11-27 14:00:19 -08:00
break ;
default :
2012-12-20 12:06:28 +02:00
self :: plugLan ( $type , $fname , $options );
2012-11-27 14:00:19 -08:00
break ;
}
}
2012-12-06 16:36:22 -08:00
/**
* Generic PREF retrieval Method for use by theme and plugin developers .
*/
2012-12-10 01:20:38 +02:00
public static function pref ( $type = 'core' , $pname = null , $default = null )
2012-12-06 16:36:22 -08:00
{
switch ( $type )
{
case 'core' :
2012-12-10 01:20:38 +02:00
return self :: getPref ( $pname , $default );
2012-12-06 16:36:22 -08:00
break ;
case 'theme' :
2012-12-10 01:20:38 +02:00
return self :: getThemePref ( $pname , $default );
2012-12-06 16:36:22 -08:00
break ;
2012-12-10 01:20:38 +02:00
default :
return self :: getPlugPref ( $type , $pname , $default );
2012-12-06 16:36:22 -08:00
break ;
}
}
2009-07-22 14:32:51 +00:00
/**
2009-12-02 16:51:04 +00:00
* Routine looks in standard paths for language files associated with a plugin or
2009-07-22 14:32:51 +00:00
* theme - primarily for core routines , which won ' t know for sure where the author has put them .
* $unitName is the name ( directory path ) of the plugin or theme
* $type determines what is to be loaded :
* - 'runtime' - the standard runtime language file for a plugin
* - 'admin' - the standard admin language file for a plugin
* - 'theme' - the standard language file for a plugin ( these are usually pretty small , so one is enough )
2009-12-02 16:51:04 +00:00
* Otherwise , $type is treated as part of a filename within the plugin ' s language directory ,
* prefixed with the current language .
2009-07-22 14:32:51 +00:00
* Returns FALSE on failure ( not found ) .
* Returns the include_once error return if there is one
* Otherwise returns an empty string .
* Note - if the code knows precisely where the language file is located , use { @ link getLan ()}
2009-12-02 16:51:04 +00:00
* $pref [ 'noLanguageSubs' ] can be set TRUE to prevent searching for the English files if
2009-07-22 14:32:51 +00:00
* the files for the current site language don ' t exist .
*
* @ param string $unitName
* @ param string $type predefined types are runtime | admin | theme
* @ return boolean | string
*/
public static function loadLanFiles ( $unitName , $type = 'runtime' )
{
2011-09-14 07:31:32 +00:00
//global $pref;
2009-07-22 14:32:51 +00:00
switch ( $type )
{
case 'runtime' :
$searchPath [ 1 ] = e_PLUGIN . $unitName . '/languages/' . e_LANGUAGE . '_' . $unitName . '.php' ;
$searchPath [ 2 ] = e_PLUGIN . $unitName . '/languages/' . e_LANGUAGE . '/' . $unitName . '.php' ;
2009-12-02 16:51:04 +00:00
$searchPath [ 3 ] = e_PLUGIN . $unitName . '/languages/' . e_LANGUAGE . '.php' ; // menu language file.
2009-07-22 14:32:51 +00:00
break ;
case 'admin' :
2013-02-22 21:34:06 -08:00
2014-02-07 17:57:55 -08:00
$adminLan = vartrue ( self :: getPref ( 'adminlanguage' ), e_LANGUAGE );
$searchPath [ 1 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '_admin_' . $unitName . '.php' ;
$searchPath [ 2 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '/' . 'admin_' . $unitName . '.php' ;
$searchPath [ 3 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '/admin/' . $adminLan . '.php' ;
$searchPath [ 4 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '/' . $adminLan . '_admin.php' ; // Preferred.
$searchPath [ 5 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '_admin.php' ; // consistent with English_global.php, English_log.php etc.
2013-02-22 21:34:06 -08:00
2009-07-22 14:32:51 +00:00
break ;
case 'theme' :
$searchPath [ 1 ] = e_THEME . $unitName . '/languages/' . e_LANGUAGE . '_' . $unitName . '.php' ;
$searchPath [ 2 ] = e_THEME . $unitName . '/languages/' . e_LANGUAGE . '/' . $unitName . '.php' ;
break ;
default :
$searchPath [ 1 ] = e_PLUGIN . $unitName . '/languages/' . e_LANGUAGE . '_' . $type . '.php' ;
$searchPath [ 2 ] = e_PLUGIN . $unitName . '/languages/' . e_LANGUAGE . '/' . $type . '.php' ;
}
foreach ( $searchPath as $s ) // Look for files in current language first - should usually be found
{
if ( is_readable ( $s ))
{
$ret = include_once ( $s );
return ( isset ( $ret )) ? $ret : " " ;
}
}
2011-09-14 07:31:32 +00:00
if ( e107 :: getPref ( 'noLanguageSubs' ) || ( e_LANGUAGE == 'English' ))
2009-07-22 14:32:51 +00:00
{
return FALSE ; // No point looking for the English files twice
}
2009-12-02 16:51:04 +00:00
2009-07-22 14:32:51 +00:00
foreach ( $searchPath as $s ) // Now look for the English files
{
$s = str_replace ( e_LANGUAGE , 'English' , $s );
if ( is_readable ( $s ))
{
$ret = include_once ( $s );
return ( isset ( $ret )) ? $ret : " " ;
}
}
return FALSE ; // Nothing found
}
2009-12-02 16:51:04 +00:00
2012-11-27 14:00:19 -08:00
2009-09-10 19:10:00 +00:00
/**
2009-11-24 16:30:08 +00:00
* Prepare e107 environment
* This is done before e107_dirs initilization and [ TODO ] config include
2011-05-03 22:13:59 +00:00
* @ param bool $checkS basic security check ( 0.7 like ), will be extended in the future
2009-11-24 16:30:08 +00:00
* @ return e107
2009-09-10 19:10:00 +00:00
*/
2011-05-03 22:13:59 +00:00
public function prepare_request ( $checkS = true )
2009-12-02 16:51:04 +00:00
{
2011-05-03 22:13:59 +00:00
// Block common bad agents / queries / php issues.
array_walk ( $_SERVER , array ( 'self' , 'filter_request' ), '_SERVER' );
if ( isset ( $_GET )) array_walk ( $_GET , array ( 'self' , 'filter_request' ), '_GET' );
2012-10-27 16:25:32 +00:00
if ( isset ( $_POST ))
{
array_walk ( $_POST , array ( 'self' , 'filter_request' ), '_POST' );
reset ( $_POST ); // Change of behaviour in PHP 5.3.17?
}
2011-05-03 22:13:59 +00:00
if ( isset ( $_COOKIE )) array_walk ( $_COOKIE , array ( 'self' , 'filter_request' ), '_COOKIE' );
if ( isset ( $_REQUEST )) array_walk ( $_REQUEST , array ( 'self' , 'filter_request' ), '_REQUEST' );
2012-07-20 07:31:16 +00:00
// A better way to detect an AJAX request. No need for "ajax_used=1";
if ( ! empty ( $_SERVER [ 'HTTP_X_REQUESTED_WITH' ]) && strtolower ( $_SERVER [ 'HTTP_X_REQUESTED_WITH' ]) == 'xmlhttprequest' )
{
define ( 'e_AJAX_REQUEST' , true );
}
else
{
define ( 'e_AJAX_REQUEST' , isset ( $_REQUEST [ 'ajax_used' ]));
}
2013-02-23 23:08:30 -08:00
2009-12-02 16:51:04 +00:00
unset ( $_REQUEST [ 'ajax_used' ]); // removed because it's auto-appended from JS (AJAX), could break something...
2009-11-24 16:30:08 +00:00
//$GLOBALS['_E107'] - minimal mode - here because of the e_AJAX_REQUEST
2013-02-23 23:08:30 -08:00
if ( isset ( $GLOBALS [ '_E107' ][ 'minimal' ]) || e_AJAX_REQUEST || deftrue ( 'e_MINIMAL' ))
2009-11-24 16:30:08 +00:00
{
$_e107vars = array ( 'forceuserupdate' , 'online' , 'theme' , 'menus' , 'prunetmp' );
2013-06-03 14:17:08 -07:00
$GLOBALS [ '_E107' ][ 'minimal' ] = true ;
2010-05-15 17:33:11 +00:00
// lame but quick - allow online when ajax request only, additonal checks are made in e_online class
if ( e_AJAX_REQUEST && ! isset ( $GLOBALS [ '_E107' ][ 'online' ]) && ! isset ( $GLOBALS [ '_E107' ][ 'minimal' ])) unset ( $_e107vars [ 1 ]);
2009-11-24 16:30:08 +00:00
foreach ( $_e107vars as $v )
{
$noname = 'no_' . $v ;
if ( ! isset ( $GLOBALS [ '_E107' ][ $v ]))
{
$GLOBALS [ '_E107' ][ $noname ] = 1 ;
}
unset ( $GLOBALS [ '_E107' ][ $v ]);
}
}
2009-12-02 16:51:04 +00:00
2010-05-13 15:47:31 +00:00
// we can now start use $e107->_E107
if ( isset ( $GLOBALS [ '_E107' ]) && is_array ( $GLOBALS [ '_E107' ])) $this -> _E107 = & $GLOBALS [ '_E107' ];
2009-11-24 16:30:08 +00:00
// remove ajax_used=1 from query string to avoid SELF problems, ajax should always be detected via e_AJAX_REQUEST constant
2010-05-13 15:47:31 +00:00
$_SERVER [ 'QUERY_STRING' ] = trim ( str_replace ( array ( 'ajax_used=1' , '&&' ), array ( '' , '&' ), $_SERVER [ 'QUERY_STRING' ]), '&' );
2009-12-02 16:51:04 +00:00
2011-05-03 22:13:59 +00:00
/* PathInfo doesn ' t break anything , URLs should be always absolute . Disabling the below forever .
2009-11-24 16:30:08 +00:00
// e107 uses relative url's, which are broken by "pretty" URL's. So for now we don't support / after .php
if (( $pos = strpos ( $_SERVER [ 'PHP_SELF' ], '.php/' )) !== false ) // redirect bad URLs to the correct one.
{
$new_url = substr ( $_SERVER [ 'PHP_SELF' ], 0 , $pos + 4 );
$new_loc = ( $_SERVER [ 'QUERY_STRING' ]) ? $new_url . '?' . $_SERVER [ 'QUERY_STRING' ] : $new_url ;
header ( 'Location: ' . $new_loc );
exit ();
}
2011-05-03 22:13:59 +00:00
*/
2009-11-24 16:30:08 +00:00
// If url contains a .php in it, PHP_SELF is set wrong (imho), affecting all paths. We need to 'fix' it if it does.
2011-05-03 22:13:59 +00:00
$_SERVER [ 'PHP_SELF' ] = (( $pos = stripos ( $_SERVER [ 'PHP_SELF' ], '.php' )) !== false ? substr ( $_SERVER [ 'PHP_SELF' ], 0 , $pos + 4 ) : $_SERVER [ 'PHP_SELF' ]);
2009-11-24 16:30:08 +00:00
// setup some php options
e107 :: ini_set ( 'magic_quotes_runtime' , 0 );
e107 :: ini_set ( 'magic_quotes_sybase' , 0 );
e107 :: ini_set ( 'arg_separator.output' , '&' );
e107 :: ini_set ( 'session.use_only_cookies' , 1 );
e107 :: ini_set ( 'session.use_trans_sid' , 0 );
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
// Ensure thet '.' is the first part of the include path
$inc_path = explode ( PATH_SEPARATOR , ini_get ( 'include_path' ));
if ( $inc_path [ 0 ] != '.' )
{
array_unshift ( $inc_path , '.' );
$inc_path = implode ( PATH_SEPARATOR , $inc_path );
2011-05-03 22:13:59 +00:00
e107 :: ini_set ( 'include_path' , $inc_path );
2009-11-24 16:30:08 +00:00
}
unset ( $inc_path );
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
return $this ;
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
/**
* Filter User Input - used by array_walk in prepare_request method above .
* @ param string $input array value
* @ param string $key array key
* @ param string $type array type _SESSION , _GET etc .
* @ return
*/
2011-11-29 23:37:44 +00:00
public static function filter_request ( $input , $key , $type , $base64 = FALSE )
2011-05-03 22:13:59 +00:00
{
2011-11-29 23:37:44 +00:00
if ( is_string ( $input ) && trim ( $input ) == " " )
{
return ;
}
2011-05-03 22:13:59 +00:00
if ( is_array ( $input ))
{
return array_walk ( $input , array ( 'self' , 'filter_request' ), $type );
}
2011-11-29 23:37:44 +00:00
if ( $type == " _POST " || ( $type == " _SERVER " && ( $key == " QUERY_STRING " )))
{
if ( $type == " _POST " && ( $base64 == FALSE ))
{
$input = preg_replace ( " /( \ [code \ ])(.*?)( \ [ \ /code \ ])/is " , " " , $input );
}
$regex = " /(document \ .location|document \ .write|base64_decode|chr|php_uname|fwrite|fopen|fputs|passthru|popen|proc_open|shell_exec|exec|proc_nice|proc_terminate|proc_get_status|proc_close|pfsockopen|apache_child_terminate|posix_kill|posix_mkfifo|posix_setpgid|posix_setsid|posix_setuid|phpinfo) *? \ ((.*) ? \ ;?/i " ;
if ( preg_match ( $regex , $input ))
{
header ( 'HTTP/1.0 400 Bad Request' , true , 400 );
exit ();
}
if ( preg_match ( " /system *? \ ((.*);.* \ )/i " , $input ))
{
header ( 'HTTP/1.0 400 Bad Request' , true , 400 );
exit ();
}
$regex = " /(wget |curl -o |fetch |lwp-download|onmouse)/i " ;
if ( preg_match ( $regex , $input ))
{
header ( 'HTTP/1.0 400 Bad Request' , true , 400 );
exit ();
}
}
2011-05-03 22:13:59 +00:00
if ( $type == " _SERVER " )
{
2011-11-29 23:37:44 +00:00
if (( $key == " QUERY_STRING " ) && (
strpos ( strtolower ( $input ), " ../../ " ) !== FALSE
|| strpos ( strtolower ( $input ), " =http " ) !== FALSE
|| strpos ( strtolower ( $input ), strtolower ( " http%3A%2F%2F " )) !== FALSE
|| strpos ( strtolower ( $input ), " php: " ) !== FALSE
|| strpos ( strtolower ( $input ), " data: " ) !== FALSE
|| strpos ( strtolower ( $input ), strtolower ( " %3Cscript " )) !== FALSE
))
2011-05-03 22:13:59 +00:00
{
2011-11-29 23:37:44 +00:00
header ( 'HTTP/1.0 400 Bad Request' , true , 400 );
2011-05-03 22:13:59 +00:00
exit ();
}
2011-11-29 23:37:44 +00:00
2011-05-03 22:13:59 +00:00
if (( $key == " HTTP_USER_AGENT " ) && strpos ( $input , " libwww-perl " ) !== FALSE )
{
2011-11-29 23:37:44 +00:00
header ( 'HTTP/1.0 400 Bad Request' , true , 400 );
exit ();
2011-05-03 22:13:59 +00:00
}
2011-11-29 23:37:44 +00:00
2011-05-03 22:13:59 +00:00
}
2011-11-29 23:37:44 +00:00
2011-05-03 22:13:59 +00:00
if ( strpos ( str_replace ( '.' , '' , $input ), '22250738585072011' ) !== FALSE ) // php-bug 53632
{
2011-11-29 23:37:44 +00:00
header ( 'HTTP/1.0 400 Bad Request' , true , 400 );
2011-05-03 22:13:59 +00:00
exit ();
2011-11-29 23:37:44 +00:00
}
if ( $base64 != TRUE )
{
self :: filter_request ( base64_decode ( $input ), $key , $type , TRUE );
2011-05-03 22:13:59 +00:00
}
}
2009-11-24 16:30:08 +00:00
/**
* Set base system path
* @ return e107
*/
public function set_base_path ( $force = null )
2009-07-22 14:32:51 +00:00
{
2009-11-24 16:30:08 +00:00
$ssl_enabled = ( null !== $force ) ? $force : $this -> isSecure (); //(self::getPref('ssl_enabled') == 1);
$this -> base_path = $ssl_enabled ? $this -> https_path : $this -> http_path ;
return $this ;
2009-07-22 14:32:51 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
2009-11-24 16:30:08 +00:00
* Set various system environment constants
2009-07-21 16:11:02 +00:00
* @ return e107
*/
2009-11-24 16:30:08 +00:00
public function set_constants ()
2006-12-02 04:36:16 +00:00
{
2009-11-24 16:30:08 +00:00
define ( 'MAGIC_QUOTES_GPC' , ( ini_get ( 'magic_quotes_gpc' ) ? true : false ));
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
define ( 'MPREFIX' , $this -> getMySQLConfig ( 'prefix' )); // mysql prefix
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
define ( 'CHARSET' , 'utf-8' ); // set CHARSET for backward compatibility
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
// Define the domain name and subdomain name.
2013-05-26 13:52:43 -07:00
if ( is_numeric ( str_replace ( " . " , " " , $_SERVER [ 'HTTP_HOST' ])))
2009-11-24 16:30:08 +00:00
{
2013-05-26 13:52:43 -07:00
$domain = FALSE ;
$subdomain = FALSE ;
2009-11-24 16:30:08 +00:00
}
else
2013-05-26 13:52:43 -07:00
{
if ( preg_match ( " / \ .?([a-z0-9-]+)( \ .(com|net|org|co|me|ltd|plc|gov) \ .[a-z] { 2}) $ /i " , $_SERVER [ 'HTTP_HOST' ], $m )) //eg. mysite.co.uk
{
$domain = $m [ 1 ] . $m [ 2 ];
}
elseif ( preg_match ( " / \ .?([a-z0-9-]+)( \ .[a-z] { 2,}) $ /i " , $_SERVER [ 'HTTP_HOST' ], $m )) // eg. .com/net/org/ws/biz/info
{
$domain = $m [ 1 ] . $m [ 2 ];
}
else
{
$domain = FALSE ; //invalid domain
}
$replace = array ( " . " . $domain , " www. " , " www " , $domain );
$subdomain = str_replace ( $replace , '' , $_SERVER [ 'HTTP_HOST' ]);
2009-11-24 16:30:08 +00:00
}
2009-12-02 16:51:04 +00:00
2013-05-26 13:52:43 -07:00
define ( " e_DOMAIN " , $domain );
define ( " e_SUBDOMAIN " ,( $subdomain ) ? $subdomain : FALSE );
2009-11-24 16:30:08 +00:00
define ( 'e_UC_PUBLIC' , 0 );
define ( 'e_UC_MAINADMIN' , 250 );
define ( 'e_UC_READONLY' , 251 );
define ( 'e_UC_GUEST' , 252 );
define ( 'e_UC_MEMBER' , 253 );
define ( 'e_UC_ADMIN' , 254 );
define ( 'e_UC_NOBODY' , 255 );
2013-03-11 02:32:19 -07:00
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
return $this ;
2006-12-02 04:36:16 +00:00
}
2010-03-03 17:06:33 +00:00
/**
* Relaitve server path - set_path () helper
* @ param string $dir
* @ return string
*/
public function get_override_rel ( $dir )
{
if ( isset ( $this -> e107_dirs [ $dir . '_SERVER' ]))
{
return $this -> e107_dirs [ $dir . '_SERVER' ];
}
2012-06-08 06:03:07 +00:00
$ret = e_BASE . $this -> e107_dirs [ $dir . '_DIRECTORY' ];
return $ret ;
2010-03-03 17:06:33 +00:00
}
/**
* Absolute HTTP path - set_path () helper
* @ param string $dir
* @ return string
*/
public function get_override_http ( $dir )
{
if ( isset ( $this -> e107_dirs [ $dir . '_HTTP' ]))
{
return $this -> e107_dirs [ $dir . '_HTTP' ];
}
return e_HTTP . $this -> e107_dirs [ $dir . '_DIRECTORY' ];
}
2009-07-21 16:11:02 +00:00
/**
* Set all environment vars and constants
2009-09-10 19:10:00 +00:00
* FIXME - remove globals
2009-11-24 16:30:08 +00:00
* @ return e107
2009-07-21 16:11:02 +00:00
*/
public function set_paths ()
2008-05-16 19:40:39 +00:00
{
2009-11-24 16:30:08 +00:00
// ssl_enabled pref not needed anymore, scheme is auto-detected
$this -> HTTP_SCHEME = 'http' ;
if ( isset ( $_SERVER [ 'HTTPS' ]) && $_SERVER [ 'HTTPS' ] == 'on' )
{
$this -> HTTP_SCHEME = 'https' ;
}
2009-12-02 16:51:04 +00:00
2006-12-02 04:36:16 +00:00
$path = " " ; $i = 0 ;
2008-01-21 03:54:10 +00:00
2010-03-03 17:06:33 +00:00
// FIXME - Again, what if someone moves handlers under the webroot?
2010-05-13 15:47:31 +00:00
if ( ! self :: isCli ())
2008-01-21 03:54:10 +00:00
{
while ( ! file_exists ( " { $path } class2.php " ))
{
$path .= " ../ " ;
$i ++ ;
}
2006-12-02 04:36:16 +00:00
}
if ( $_SERVER [ 'PHP_SELF' ] == " " ) { $_SERVER [ 'PHP_SELF' ] = $_SERVER [ 'SCRIPT_NAME' ]; }
$http_path = dirname ( $_SERVER [ 'PHP_SELF' ]);
$http_path = explode ( " / " , $http_path );
$http_path = array_reverse ( $http_path );
$j = 0 ;
2008-01-21 03:54:10 +00:00
while ( $j < $i )
{
2006-12-02 04:36:16 +00:00
unset ( $http_path [ $j ]);
$j ++ ;
}
$http_path = array_reverse ( $http_path );
$this -> server_path = implode ( " / " , $http_path ) . " / " ;
$this -> server_path = $this -> fix_windows_paths ( $this -> server_path );
2008-01-21 03:54:10 +00:00
if ( $this -> server_path == " // " )
{
2006-12-02 04:36:16 +00:00
$this -> server_path = " / " ;
}
2008-01-21 03:54:10 +00:00
// Absolute file-path of directory containing class2.php
2010-03-03 17:06:33 +00:00
// define("e_ROOT", realpath(dirname(__FILE__)."/../")."/");
2010-02-09 20:43:54 +00:00
2013-02-26 19:53:49 -08:00
$e_ROOT = realpath ( dirname ( __FILE__ ) . " /../ " );
2013-02-26 20:31:31 -08:00
2013-02-26 19:53:49 -08:00
if (( substr ( $e_ROOT , - 1 ) != '/' ) && ( substr ( $e_ROOT , - 1 ) != '\\' ) )
2009-12-27 13:56:15 +00:00
{
2013-02-26 20:31:31 -08:00
$e_ROOT .= DIRECTORY_SEPARATOR ; // Should function correctly on both windows and Linux now.
2009-12-27 13:56:15 +00:00
}
2013-02-26 19:53:49 -08:00
define ( 'e_ROOT' , $e_ROOT );
2008-01-21 03:54:10 +00:00
2010-05-13 15:47:31 +00:00
$this -> relative_base_path = ( ! self :: isCli ()) ? $path : e_ROOT ;
2006-12-02 04:36:16 +00:00
$this -> http_path = " http:// { $_SERVER [ 'HTTP_HOST' ] } { $this -> server_path } " ;
$this -> https_path = " https:// { $_SERVER [ 'HTTP_HOST' ] } { $this -> server_path } " ;
$this -> file_path = $path ;
2009-12-13 19:51:36 +00:00
if ( ! defined ( 'e_HTTP' ) || ! defined ( 'e_ADMIN' ) )
2006-12-02 04:36:16 +00:00
{
2009-12-13 19:51:36 +00:00
define ( 'e_HTTP' , $this -> server_path ); // Directory of site root relative to HTML base directory
define ( 'e_BASE' , $this -> relative_base_path );
// Base dir of web stuff in server terms. e_ROOT should always end with e_HTTP, even if e_HTTP = '/'
2010-02-09 20:43:54 +00:00
define ( 'SERVERBASE' , substr ( e_ROOT , 0 , - strlen ( e_HTTP ) + 1 ));
2007-03-04 14:59:28 +00:00
2007-04-11 22:23:43 +00:00
if ( isset ( $_SERVER [ 'DOCUMENT_ROOT' ]))
{
2010-03-03 17:06:33 +00:00
define ( 'e_DOCROOT' , $_SERVER [ 'DOCUMENT_ROOT' ] . " / " );
2007-04-11 22:23:43 +00:00
}
else
{
2010-03-03 17:06:33 +00:00
define ( 'e_DOCROOT' , false );
2007-02-24 18:45:31 +00:00
}
2008-01-21 03:54:10 +00:00
2010-03-03 17:06:33 +00:00
//BC temporary fixes
if ( ! isset ( $this -> e107_dirs [ 'UPLOADS_SERVER' ]) && $this -> e107_dirs [ 'UPLOADS_DIRECTORY' ]{ 0 } == " / " )
2008-01-21 03:54:10 +00:00
{
2010-03-03 17:06:33 +00:00
$this -> e107_dirs [ 'UPLOADS_SERVER' ] = $this -> e107_dirs [ 'UPLOADS_DIRECTORY' ];
2008-01-21 03:54:10 +00:00
}
2010-03-03 17:06:33 +00:00
if ( ! isset ( $this -> e107_dirs [ 'DOWNLOADS_SERVER' ]) && $this -> e107_dirs [ 'DOWNLOADS_DIRECTORY' ]{ 0 } == " / " )
2008-01-21 03:54:10 +00:00
{
2010-03-03 17:06:33 +00:00
$this -> e107_dirs [ 'DOWNLOADS_SERVER' ] = $this -> e107_dirs [ 'DOWNLOADS_DIRECTORY' ];
2006-12-02 04:36:16 +00:00
}
2007-02-18 02:22:29 +00:00
2010-03-03 17:06:33 +00:00
//
// HTTP relative paths
//
define ( 'e_ADMIN' , $this -> get_override_rel ( 'ADMIN' ));
define ( 'e_IMAGE' , $this -> get_override_rel ( 'IMAGES' ));
define ( 'e_THEME' , $this -> get_override_rel ( 'THEMES' ));
define ( 'e_PLUGIN' , $this -> get_override_rel ( 'PLUGINS' ));
define ( 'e_FILE' , $this -> get_override_rel ( 'FILES' ));
define ( 'e_HANDLER' , $this -> get_override_rel ( 'HANDLERS' ));
define ( 'e_LANGUAGEDIR' , $this -> get_override_rel ( 'LANGUAGES' ));
define ( 'e_DOCS' , $this -> get_override_rel ( 'HELP' )); // WILL CHANGE SOON - $this->_get_override_rel('DOCS')
define ( 'e_HELP' , $this -> get_override_rel ( 'HELP' ));
define ( 'e_MEDIA' , $this -> get_override_rel ( 'MEDIA' ));
define ( 'e_MEDIA_FILE' , $this -> get_override_rel ( 'MEDIA_FILES' ));
define ( 'e_MEDIA_VIDEO' , $this -> get_override_rel ( 'MEDIA_VIDEOS' ));
define ( 'e_MEDIA_IMAGE' , $this -> get_override_rel ( 'MEDIA_IMAGES' ));
define ( 'e_MEDIA_ICON' , $this -> get_override_rel ( 'MEDIA_ICONS' ));
2013-04-19 22:50:41 -07:00
// define('e_MEDIA_AVATAR', $this->get_override_rel('MEDIA_AVATARS'));
2010-03-03 17:06:33 +00:00
define ( 'e_DOWNLOAD' , $this -> get_override_rel ( 'DOWNLOADS' ));
define ( 'e_UPLOAD' , $this -> get_override_rel ( 'UPLOADS' ));
define ( 'e_CORE' , $this -> get_override_rel ( 'CORE' ));
define ( 'e_SYSTEM' , $this -> get_override_rel ( 'SYSTEM' ));
define ( 'e_WEB' , $this -> get_override_rel ( 'WEB' ));
define ( 'e_WEB_JS' , $this -> get_override_rel ( 'WEB_JS' ));
define ( 'e_WEB_CSS' , $this -> get_override_rel ( 'WEB_CSS' ));
define ( 'e_WEB_IMAGE' , $this -> get_override_rel ( 'WEB_IMAGES' ));
2012-12-16 13:02:19 -08:00
// define('e_WEB_PACK', $this->get_override_rel('WEB_PACKS'));
2010-03-03 17:06:33 +00:00
define ( 'e_CACHE' , $this -> get_override_rel ( 'CACHE' ));
define ( 'e_CACHE_CONTENT' , $this -> get_override_rel ( 'CACHE_CONTENT' ));
define ( 'e_CACHE_IMAGE' , $this -> get_override_rel ( 'CACHE_IMAGE' ));
define ( 'e_CACHE_DB' , $this -> get_override_rel ( 'CACHE_DB' ));
2012-06-08 08:18:03 +00:00
define ( 'e_CACHE_URL' , $this -> get_override_rel ( 'CACHE_URL' ));
2010-03-03 17:06:33 +00:00
define ( 'e_LOG' , $this -> get_override_rel ( 'LOGS' ));
2012-06-08 06:03:07 +00:00
define ( 'e_BACKUP' , $this -> get_override_rel ( 'BACKUP' ));
2012-08-06 08:55:51 +00:00
define ( 'e_TEMP' , $this -> get_override_rel ( 'TEMP' ));
2013-05-17 18:17:04 -07:00
define ( 'e_IMPORT' , $this -> get_override_rel ( 'IMPORT' ));
2010-03-03 17:06:33 +00:00
//
// HTTP absolute paths
//
define ( " e_ADMIN_ABS " , $this -> get_override_http ( 'ADMIN' ));
define ( " e_IMAGE_ABS " , $this -> get_override_http ( 'IMAGES' ));
define ( " e_THEME_ABS " , $this -> get_override_http ( 'THEMES' ));
define ( " e_PLUGIN_ABS " , $this -> get_override_http ( 'PLUGINS' ));
define ( " e_FILE_ABS " , $this -> get_override_http ( 'FILES' )); // Deprecated!
define ( " e_DOCS_ABS " , $this -> get_override_http ( 'DOCS' ));
define ( " e_HELP_ABS " , $this -> get_override_http ( 'HELP' ));
2013-05-20 04:51:45 -07:00
define ( " e_IMPORT_ABS " , false );
2010-03-03 17:06:33 +00:00
// DEPRECATED - not a legal http query now!
//define("e_HANDLER_ABS", $this->get_override_http('HANDLERS'));
//define("e_LANGUAGEDIR_ABS", $this->get_override_http('LANGUAGES'));
//define("e_LOG_ABS", $this->get_override_http('LOGS'));
define ( " e_MEDIA_ABS " , $this -> get_override_http ( 'MEDIA' ));
define ( 'e_MEDIA_FILE_ABS' , $this -> get_override_http ( 'MEDIA_FILES' ));
define ( 'e_MEDIA_VIDEO_ABS' , $this -> get_override_http ( 'MEDIA_VIDEOS' ));
define ( 'e_MEDIA_IMAGE_ABS' , $this -> get_override_http ( 'MEDIA_IMAGES' ));
define ( 'e_MEDIA_ICON_ABS' , $this -> get_override_http ( 'MEDIA_ICONS' ));
2013-04-19 22:50:41 -07:00
// define('e_MEDIA_AVATAR_ABS', $this->get_override_http('MEDIA_AVATARS'));
2010-03-03 17:06:33 +00:00
2010-03-10 12:48:05 +00:00
// XXX DISCUSSS - e_JS_ABS, e_CSS_ABS etc is not following the naming standards but they're more usable.
// Example: e_JS_ABS vs e_WEB_JS_ABS
2013-04-19 22:50:41 -07:00
//XXX Absolute is assumed.
2010-03-03 17:06:33 +00:00
define ( 'e_WEB_ABS' , $this -> get_override_http ( 'WEB' ));
2010-03-10 12:48:05 +00:00
define ( 'e_JS_ABS' , $this -> get_override_http ( 'WEB_JS' ));
2010-03-03 17:06:33 +00:00
define ( 'e_CSS_ABS' , $this -> get_override_http ( 'WEB_CSS' ));
2012-12-14 22:25:14 -08:00
// define('e_PACK_ABS', $this->get_override_http('WEB_PACKS'));
2010-03-03 17:06:33 +00:00
define ( 'e_WEB_IMAGE_ABS' , $this -> get_override_http ( 'WEB_IMAGES' ));
2012-06-08 06:03:07 +00:00
define ( 'e_JS' , $this -> get_override_http ( 'WEB_JS' )); // ABS Alias
define ( 'e_CSS' , $this -> get_override_http ( 'WEB_CSS' )); // ABS Alias
2013-04-19 22:50:41 -07:00
define ( 'e_AVATAR' , $this -> get_override_rel ( 'AVATARS' ));
define ( 'e_AVATAR_UPLOAD' , $this -> get_override_rel ( 'AVATARS_UPLOAD' ));
define ( 'e_AVATAR_DEFAULT' , $this -> get_override_rel ( 'AVATARS_DEFAULT' ));
define ( 'e_AVATAR_ABS' , $this -> get_override_http ( 'AVATARS' ));
define ( 'e_AVATAR_UPLOAD_ABS' , $this -> get_override_http ( 'AVATARS_UPLOAD' ));
define ( 'e_AVATAR_DEFAULT_ABS' , $this -> get_override_http ( 'AVATARS_DEFAULT' ));
2013-06-17 16:03:33 -07:00
// Special
define ( 'e_BOOTSTRAP' , e_WEB . " bootstrap/ " );
2010-03-10 12:48:05 +00:00
2006-12-02 04:36:16 +00:00
}
2009-11-24 16:30:08 +00:00
return $this ;
2006-12-02 04:36:16 +00:00
}
2009-07-21 16:11:02 +00:00
/**
* Fix Windows server path
*
* @ param string $path resolved server path
* @ return string fixed path
*/
2008-01-21 03:54:10 +00:00
function fix_windows_paths ( $path )
{
2006-12-02 04:36:16 +00:00
$fixed_path = str_replace ( array ( '\\\\' , '\\' ), array ( '/' , '/' ), $path );
$fixed_path = ( substr ( $fixed_path , 1 , 2 ) == " :/ " ? substr ( $fixed_path , 2 ) : $fixed_path );
return $fixed_path ;
}
2009-11-22 14:10:09 +00:00
/**
* Define e_PAGE , e_SELF , e_ADMIN_AREA and USER_AREA ;
* The following files are assumed to use admin theme :
* 1. Any file in the admin directory ( check for non - plugin added to avoid mismatches )
* 2. any plugin file starting with 'admin_'
* 3. any plugin file in a folder called admin /
2009-11-24 16:30:08 +00:00
* 4. any file that specifies $eplug_admin = TRUE ; or ADMIN_AREA = TRUE ;
* NOTE : USER_AREA = true ; will force e_ADMIN_AREA to FALSE
2011-05-03 22:13:59 +00:00
*
* @ param boolean $no_cbrace remove curly brackets from the url
2009-11-24 16:30:08 +00:00
* @ return e107
2009-11-22 14:10:09 +00:00
*/
2011-05-03 22:13:59 +00:00
public function set_urls ( $no_cbrace = true )
2009-11-22 14:10:09 +00:00
{
2009-11-24 16:30:08 +00:00
//global $PLUGINS_DIRECTORY,$ADMIN_DIRECTORY, $eplug_admin;
$PLUGINS_DIRECTORY = $this -> getFolder ( 'plugins' );
$ADMIN_DIRECTORY = $this -> getFolder ( 'admin' );
2011-05-03 22:13:59 +00:00
// Outdated
/* $requestQry = '' ;
$requestUrl = $_SERVER [ 'REQUEST_URI' ];
if ( strpos ( $_SERVER [ 'REQUEST_URI' ], '?' ) !== FALSE )
list ( $requestUrl , $requestQry ) = explode ( " ? " , $_SERVER [ 'REQUEST_URI' ], 2 ); */
2009-11-28 15:34:46 +00:00
$eplug_admin = vartrue ( $GLOBALS [ 'eplug_admin' ], false );
2009-12-02 16:51:04 +00:00
2011-05-03 22:13:59 +00:00
// Leave e_SELF BC, use e_REQUEST_SELF instead
/*// moved after page check - e_PAGE is important for BC
if ( $requestUrl && $requestUrl != $_SERVER [ 'PHP_SELF' ])
{
$_SERVER [ 'PHP_SELF' ] = $requestUrl ;
} */
$eSelf = $_SERVER [ 'PHP_SELF' ] ? $_SERVER [ 'PHP_SELF' ] : $_SERVER [ 'SCRIPT_FILENAME' ];
2011-06-17 01:13:05 +00:00
$_self = $this -> HTTP_SCHEME . '://' . $_SERVER [ 'HTTP_HOST' ] . $eSelf ;
2011-11-25 17:24:42 +00:00
if ( ! deftrue ( 'e_SINGLE_ENTRY' ))
2011-05-10 12:47:03 +00:00
{
2011-11-25 17:24:42 +00:00
$page = substr ( strrchr ( $_SERVER [ 'PHP_SELF' ], '/' ), 1 );
define ( 'e_PAGE' , $page );
2011-06-17 01:13:05 +00:00
define ( 'e_SELF' , $_self );
2011-05-10 12:47:03 +00:00
}
2011-05-03 22:13:59 +00:00
// START New - request uri/url detection, XSS protection
2011-12-01 22:08:23 +00:00
// TODO - move it to a separate method
2011-05-03 22:13:59 +00:00
$requestUri = $requestUrl = '' ;
if ( isset ( $_SERVER [ 'HTTP_X_REWRITE_URL' ]))
{
// check this first so IIS will catch
$requestUri = $_SERVER [ 'HTTP_X_REWRITE_URL' ];
$requestUrl = $this -> HTTP_SCHEME . '://' . $_SERVER [ 'HTTP_HOST' ] . $requestUri ;
// fix request uri
$_SERVER [ 'REQUEST_URI' ] = $requestUri ;
}
elseif ( isset ( $_SERVER [ 'REQUEST_URI' ]))
{
$requestUri = $_SERVER [ 'REQUEST_URI' ];
$requestUrl = $this -> HTTP_SCHEME . '://' . $_SERVER [ 'HTTP_HOST' ] . $requestUri ;
}
else
{
// go back to e_SELF
$requestUri = $eSelf ;
2011-12-01 22:08:23 +00:00
$requestUrl = $_self ;
2011-05-03 22:13:59 +00:00
if ( e_QUERY )
{
2011-12-01 22:08:23 +00:00
$requestUri .= '?' . e_QUERY ; // TODO e_SINGLE_ENTRY check, separate static method for cleaning QUERY_STRING
2011-05-03 22:13:59 +00:00
$requestUrl .= '?' . e_QUERY ;
}
}
// FIXME - basic security - add url sanitize method to e_parse
$check = rawurldecode ( $requestUri ); // urlencoded by default
// a bit aggressive XSS protection... convert to e.g. htmlentities if you are not a bad guy
$checkregx = $no_cbrace ? '[<>\{\}]' : '[<>]' ;
if ( preg_match ( '/' . $checkregx . '/' , $check ))
{
header ( 'HTTP/1.1 403 Forbidden' );
exit ;
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
// e_MENU fix
if ( e_MENU )
{
2012-01-02 12:45:21 +00:00
$requestUri = str_replace ( '[' . e_MENU . ']' , '' , $requestUri );
$requestUrl = str_replace ( '[' . e_MENU . ']' , '' , $requestUrl );
2013-05-17 18:41:28 -07:00
parse_str ( e_QUERY , $_GET );
2011-05-03 22:13:59 +00:00
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
// the last anti-XSS measure, XHTML compliant URL to be used in forms instead e_SELF
define ( 'e_REQUEST_URL' , str_replace ( array ( " ' " , '"' ), array ( '%27' , '%22' ), $requestUrl )); // full request url string (including domain)
define ( 'e_REQUEST_SELF' , array_shift ( explode ( '?' , e_REQUEST_URL ))); // full URL without the QUERY string
define ( 'e_REQUEST_URI' , str_replace ( array ( " ' " , '"' ), array ( '%27' , '%22' ), $requestUri )); // absolute http path + query string
define ( 'e_REQUEST_HTTP' , array_shift ( explode ( '?' , e_REQUEST_URI ))); // SELF URL without the QUERY string and leading domain part
unset ( $requestUrl , $requestUri );
// END request uri/url detection, XSS protection
2009-11-22 14:10:09 +00:00
// e_SELF has the full HTML path
$inAdminDir = FALSE ;
2011-06-17 01:13:05 +00:00
$isPluginDir = strpos ( $_self , '/' . $PLUGINS_DIRECTORY ) !== FALSE ; // True if we're in a plugin
$e107Path = str_replace ( $this -> base_path , '' , $_self ); // Knock off the initial bits
2009-12-02 16:51:04 +00:00
2009-11-22 14:10:09 +00:00
if (
( ! $isPluginDir && strpos ( $e107Path , $ADMIN_DIRECTORY ) === 0 ) // Core admin directory
2012-01-11 13:18:22 +00:00
|| ( $isPluginDir && ( strpos ( e_PAGE , '_admin.php' ) !== false || strpos ( e_PAGE , 'admin_' ) === 0 || strpos ( $e107Path , 'admin/' ) !== FALSE )) // Plugin admin file or directory
2009-11-22 14:10:09 +00:00
|| ( varsettrue ( $eplug_admin ) || defsettrue ( 'ADMIN_AREA' )) // Admin forced
2014-03-13 00:21:34 +01:00
|| ( preg_match ( '/^\/(.*?)\/user(settings\.php|\/edit)(\?|\/)(\d+)$/i' , $_SERVER [ 'REQUEST_URI' ]) && ADMIN )
2009-11-22 14:10:09 +00:00
)
{
2009-12-02 16:51:04 +00:00
$inAdminDir = TRUE ;
2009-11-22 14:10:09 +00:00
}
2009-12-13 19:51:36 +00:00
if ( $isPluginDir )
{
$temp = substr ( $e107Path , strpos ( $e107Path , '/' ) + 1 );
$plugDir = substr ( $temp , 0 , strpos ( $temp , '/' ));
define ( 'e_CURRENT_PLUGIN' , $plugDir );
define ( 'e_PLUGIN_DIR' , e_PLUGIN . e_CURRENT_PLUGIN . '/' );
define ( 'e_PLUGIN_DIR_ABS' , e_PLUGIN_ABS . e_CURRENT_PLUGIN . '/' );
}
else
{
define ( 'e_CURRENT_PLUGIN' , '' );
define ( 'e_PLUGIN_DIR' , '' );
define ( 'e_PLUGIN_DIR_ABS' , '' );
}
2009-12-02 16:51:04 +00:00
2014-03-13 00:21:34 +01:00
define ( 'e_ADMIN_AREA' , $inAdminDir );
2009-11-24 16:30:08 +00:00
define ( 'ADMINDIR' , $ADMIN_DIRECTORY );
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
define ( 'SITEURLBASE' , $this -> HTTP_SCHEME . '://' . $_SERVER [ 'HTTP_HOST' ]);
define ( 'SITEURL' , SITEURLBASE . e_HTTP );
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
// login/signup
define ( 'e_SIGNUP' , SITEURL . ( file_exists ( e_BASE . 'customsignup.php' ) ? 'customsignup.php' : 'signup.php' ));
2011-06-07 02:20:27 +00:00
if ( ! defined ( 'e_LOGIN' ))
{
define ( 'e_LOGIN' , SITEURL . ( file_exists ( e_BASE . 'customlogin.php' ) ? 'customlogin.php' : 'login.php' ));
}
2009-11-24 16:30:08 +00:00
return $this ;
2009-11-22 14:10:09 +00:00
}
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
/**
* Set request related constants
2011-05-03 22:13:59 +00:00
* @ param boolean $no_cbrace remove curly brackets from the url
2009-11-24 16:30:08 +00:00
* @ return e107
*/
2011-05-03 22:13:59 +00:00
public function set_request ( $no_cbrace = true )
2009-11-24 16:30:08 +00:00
{
2010-02-09 20:43:54 +00:00
2009-11-24 16:30:08 +00:00
$inArray = array ( " ' " , ';' , '/**/' , '/UNION/' , '/SELECT/' , 'AS ' );
if ( strpos ( $_SERVER [ 'PHP_SELF' ], 'trackback' ) === false )
{
foreach ( $inArray as $res )
{
if ( stristr ( $_SERVER [ 'QUERY_STRING' ], $res ))
{
die ( 'Access denied.' );
}
}
}
2009-12-02 16:51:04 +00:00
2011-05-03 22:13:59 +00:00
if ( strpos ( $_SERVER [ 'QUERY_STRING' ], ']' ) && preg_match ( '#\[(.*?)](.*)#' , $_SERVER [ 'QUERY_STRING' ], $matches ))
2009-11-24 16:30:08 +00:00
{
define ( 'e_MENU' , $matches [ 1 ]);
$e_QUERY = $matches [ 2 ];
}
else
{
define ( 'e_MENU' , '' );
$e_QUERY = $_SERVER [ 'QUERY_STRING' ];
}
2010-05-05 15:05:32 +00:00
2011-05-03 22:13:59 +00:00
if ( $no_cbrace ) $e_QUERY = str_replace ( array ( '{' , '}' , '%7B' , '%7b' , '%7D' , '%7d' ), '' , rawurldecode ( $e_QUERY ));
2012-08-10 11:37:20 +00:00
$e_QUERY = htmlentities ( self :: getParser () -> post_toForm ( $e_QUERY ));
2011-05-10 12:47:03 +00:00
2013-07-23 11:30:22 +03:00
// e_QUERY SHOULD NOT BE DEFINED IF IN SNIGLE ENTRY MODE OR ALL URLS WILL BE BROKEN - it's defined later within the the router
2011-11-25 17:24:42 +00:00
if ( ! deftrue ( " e_SINGLE_ENTRY " ))
2011-05-10 12:47:03 +00:00
{
2013-07-23 11:30:22 +03:00
define ( 'e_QUERY' , $e_QUERY );
2011-06-17 01:13:05 +00:00
$_SERVER [ 'QUERY_STRING' ] = e_QUERY ;
}
2010-02-09 20:43:54 +00:00
2011-11-25 17:24:42 +00:00
define ( 'e_TBQS' , $_SERVER [ 'QUERY_STRING' ]);
2009-11-24 16:30:08 +00:00
}
2012-12-15 10:25:14 +02:00
/**
* Basic implementation of Browser cache control per user session . Awaiting improvement in future versions
* If no argument is passed it returns
* boolean ( if current page is cacheable ) .
* If string is passed , it ' s asumed to be aboslute request path ( e_REQUEST_URI alike )
* If true is passed , e_REQUEST_URI is registered
*/
public static function canCache ( $set = null )
{
$_data = e107 :: getSession () -> get ( '__sessionBrowserCache' );
if ( ! is_array ( $_data )) $_data = array ();
if ( null === $set )
{
return in_array ( e_REQUEST_URI , $_data );
}
// remove e_REQUEST_URI from the set
if ( false === $set )
{
$check = array_search ( e_REQUEST_URI , $_data );
if ( false !== $check )
{
unset ( $_data [ $check ]);
e107 :: getSession () -> set ( '__sessionBrowserCache' , $_data );
return ;
}
}
if ( true === $set )
{
$set = e_REQUEST_URI ;
}
if ( empty ( $set ) || ! is_string ( $set ) || in_array ( $set , $_data )) return ;
$_data [] = $set ;
e107 :: getSession () -> set ( '__sessionBrowserCache' , array_unique ( $_data ));
}
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
/**
* Check if current request is secure ( https )
2009-12-13 21:52:32 +00:00
* @ return boolean TRUE if https , FALSE if http
2009-11-24 16:30:08 +00:00
*/
public function isSecure ()
{
return ( $this -> HTTP_SCHEME === 'https' );
}
2009-12-02 16:51:04 +00:00
2006-12-02 04:36:16 +00:00
/**
* Check if current user is banned
2009-12-02 16:51:04 +00:00
*
2009-11-16 20:40:39 +00:00
* Generates the queries to interrogate the ban list , then calls $this -> check_ban () .
* If the user is banned , $check_ban () never returns - so a return from this routine indicates a non - banned user .
2012-01-02 13:12:48 +00:00
* FIXME - moved to ban helper , replace all calls
2009-07-21 16:11:02 +00:00
* @ return void
2006-12-02 04:36:16 +00:00
*/
2011-12-28 10:01:25 +00:00
/* No longer required - moved to eIPHelper class
2009-07-21 16:11:02 +00:00
public function ban ()
2008-01-13 10:51:42 +00:00
{
2011-12-28 10:01:25 +00:00
} */
2006-12-02 04:36:16 +00:00
2009-07-21 16:11:02 +00:00
/**
* 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
2012-01-02 13:12:48 +00:00
* FIXME - moved to ban helper , replace all calls
2011-11-25 17:24:42 +00:00
*
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* @ param string $query
* @ param boolean $show_error
* @ param boolean $do_return
* @ return boolean
*/
2011-12-28 10:01:25 +00:00
/* No longer required - moved to eIPHelper class
2009-07-21 16:11:02 +00:00
public function check_ban ( $query , $show_error = TRUE , $do_return = FALSE )
2007-12-09 16:42:23 +00:00
{
2011-12-28 10:01:25 +00:00
} */
2008-11-25 16:26:03 +00:00
2009-11-16 20:40:39 +00:00
2009-07-21 16:11:02 +00:00
/**
* Add an entry to the banlist . $bantype = 1 for manual , 2 for flooding , 4 for multiple logins
* Returns TRUE if ban accepted .
* Returns FALSE if ban not accepted ( i . e . because on whitelist , or invalid IP specified )
2012-01-02 13:12:48 +00:00
* FIXME - moved to IP handler , replace all calls
2009-07-21 16:11:02 +00:00
* @ param string $bantype
* @ param string $ban_message
* @ param string $ban_ip
* @ param integer $ban_user
* @ param string $ban_notes
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* @ return boolean check result
*/
2012-01-02 22:06:22 +00:00
/*
2009-07-21 16:11:02 +00:00
public function add_ban ( $bantype , $ban_message = '' , $ban_ip = '' , $ban_user = 0 , $ban_notes = '' )
2007-12-09 16:42:23 +00:00
{
2011-12-28 10:01:25 +00:00
return e107 :: getIPHandler () -> add_ban ( $bantype , $ban_message , $ban_ip , $ban_user , $ban_notes );
2012-01-02 22:06:22 +00:00
} */
2007-12-09 16:42:23 +00:00
2006-12-02 04:36:16 +00:00
/**
* Get the current user ' s IP address
2008-11-22 12:57:42 +00:00
* returns the address in internal 'normalised' IPV6 format - so most code should continue to work provided the DB Field is big enougn
2012-01-02 22:06:22 +00:00
* FIXME - call ipHandler directly ( done for core - left temporarily for BC )
2009-07-21 16:11:02 +00:00
* @ return string
2006-12-02 04:36:16 +00:00
*/
2009-07-21 16:11:02 +00:00
public function getip ()
2008-11-22 12:57:42 +00:00
{
2011-12-28 10:01:25 +00:00
return e107 :: getIPHandler () -> getIP ( FALSE );
2006-12-02 04:36:16 +00:00
}
2009-07-21 16:11:02 +00:00
/**
* Encode an IP address to internal representation . Returns string if successful ; FALSE on error
* Default separates fields with ':' ; set $div = '' to produce a 32 - char packed hex string
2011-12-28 10:01:25 +00:00
* FIXME - moved to ipHandler - check for calls elsewhere
2009-07-21 16:11:02 +00:00
* @ param string $ip
* @ param string $div divider
* @ return string encoded IP
*/
2012-11-29 00:35:33 +02:00
2009-07-21 16:11:02 +00:00
public function ipEncode ( $ip , $div = ':' )
2008-11-22 12:57:42 +00:00
{
2012-11-29 00:35:33 +02:00
return e107 :: getIPHandler () -> ipEncode ( $ip );
}
2008-11-25 16:26:03 +00:00
2009-07-21 16:11:02 +00:00
/**
* Takes an encoded IP address - returns a displayable one
2009-12-02 16:51:04 +00:00
* Set $IP4Legacy TRUE to display 'old' ( IPv4 ) addresses in the familiar dotted format ,
2009-07-21 16:11:02 +00:00
* FALSE to display in standard IPV6 format
* Should handle most things that can be thrown at it .
2012-01-02 22:06:22 +00:00
* FIXME - moved to ipHandler - check for calls elsewhere - core done ; left temporarily for BC
2009-07-21 16:11:02 +00:00
* @ param string $ip encoded IP
* @ param boolean $IP4Legacy
* @ return string decoded IP
*/
2011-12-28 10:01:25 +00:00
public function ipdecode ( $ip , $IP4Legacy = TRUE )
2008-11-22 12:57:42 +00:00
{
2011-12-28 10:01:25 +00:00
return e107 :: getIPHandler () -> ipDecode ( $ip , $IP4Legacy );
2008-11-22 12:57:42 +00:00
}
2009-12-02 16:51:04 +00:00
2009-07-21 16:11:02 +00:00
/**
* Given a string which may be IP address , email address etc , tries to work out what it is
2011-12-28 10:01:25 +00:00
* Movet to eIPHandler class
* FIXME - moved to ipHandler - check for calls elsewhere
2009-07-21 16:11:02 +00:00
* @ param string $string
* @ return string ip | email | url | ftp | unknown
*/
2011-12-28 10:01:25 +00:00
/*
2009-07-21 16:11:02 +00:00
public function whatIsThis ( $string )
2008-11-22 12:57:42 +00:00
{
2011-12-28 10:01:25 +00:00
//return e107::getIPHandler()->whatIsThis($string);
} */
2008-10-19 11:35:00 +00:00
2009-07-21 16:11:02 +00:00
/**
* Retrieve & cache host name
*
* @ param string $ip_address
* @ return string host name
2011-12-28 10:01:25 +00:00
* FIXME - moved to ipHandler - check for calls elsewhere
2009-07-21 16:11:02 +00:00
*/
2011-12-28 10:01:25 +00:00
/*
2009-07-21 16:11:02 +00:00
public function get_host_name ( $ip_address )
2008-10-19 11:35:00 +00:00
{
2012-01-02 13:12:48 +00:00
2011-12-28 10:01:25 +00:00
} */
2006-12-02 04:36:16 +00:00
2009-07-21 16:11:02 +00:00
/**
2011-11-25 17:24:42 +00:00
* MOVED TO eHelper :: parseMemorySize ()
* FIXME - find all calls , replace with eHelper :: parseMemorySize () ( once eHelper lives in a separate file )
2009-07-21 16:11:02 +00:00
*
* @ param integer $size
* @ param integer $dp
* @ return string formatted size
*/
public function parseMemorySize ( $size , $dp = 2 )
2007-07-12 21:34:39 +00:00
{
2012-01-02 13:12:48 +00:00
return eHelper :: parseMemorySize ( $size , $dp );
2011-11-25 17:24:42 +00:00
}
2008-11-25 16:26:03 +00:00
2006-12-02 04:36:16 +00:00
/**
2012-01-02 13:12:48 +00:00
* Removed , see eHelper :: getMemoryUsage ()
2006-12-02 04:36:16 +00:00
* Get the current memory usage of the code
2009-07-21 16:11:02 +00:00
* If $separator argument is null , raw data ( array ) will be returned
2009-12-02 16:51:04 +00:00
*
2009-07-21 16:11:02 +00:00
* @ param null | string $separator
* @ return string | array memory usage
2006-12-02 04:36:16 +00:00
*/
2012-01-02 13:12:48 +00:00
/*
2009-07-21 16:11:02 +00:00
public function get_memory_usage ( $separator = '/' )
2008-10-19 11:35:00 +00:00
{
2012-01-02 13:12:48 +00:00
return eHelper :: getMemoryUsage ( $separator );
} */
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
/**
* Check if plugin is installed
* @ param string $plugname
* @ return boolean
*/
public static function isInstalled ( $plugname )
{
// Could add more checks here later if appropriate
return self :: getConfig () -> isData ( 'plug_installed/' . $plugname );
}
2009-12-02 16:51:04 +00:00
2009-11-24 16:30:08 +00:00
/**
* Safe way to set ini var
* @ param string $var
* @ param string $value
2009-12-13 21:52:32 +00:00
* @ return TBD
2009-11-24 16:30:08 +00:00
*/
public static function ini_set ( $var , $value )
{
if ( function_exists ( 'ini_set' ))
{
return ini_set ( $var , $value );
}
return false ;
}
2011-11-25 17:24:42 +00:00
/**
* Register autoload function ( string ) or static class method - array ( 'ClassName' , 'MethodName' )
* @ param string | array $function
*/
public static function autoload_register ( $function , $prepend = false )
{
if ( ! $prepend || false === ( $registered = spl_autoload_functions ()))
{
return spl_autoload_register ( $function );
}
foreach ( $registered as $r )
{
spl_autoload_unregister ( $r );
}
$result = spl_autoload_register ( $function );
foreach ( $registered as $r )
{
if ( ! spl_autoload_register ( $r )) $result = false ;
}
return $result ;
}
/**
* Former __autoload , generic core autoload logic
*
* Magic class autoload .
* We are raising plugin structure standard here - plugin auto - loading works ONLY if
* classes live inside 'includes' folder .
* Example : plugin_myplug_admin_ui ->
* < code >
* < ? php
* // __autoload() will look in e_PLUGIN.'myplug/includes/admin/ui.php for this class
* // e_admin_ui is core handler, so it'll be autoloaded as well
* class plugin_myplug_admin_ui extends e_admin_ui
* {
*
* }
*
* // __autoload() will look in e_PLUGIN.'myplug/shortcodes/my_shortcodes.php for this class
* // e_admin_ui is core handler, so it'll be autoloaded as well
* class plugin_myplug_my_shortcodes extends e_admin_ui
* {
*
* }
* </ code >
* We use now spl_autoload [ _ * ] for core autoloading ( PHP5 > 5.1 . 2 )
* TODO - at this time we could create e107 version of spl_autoload_register - e_event -> register / trigger ( 'autoload' )
*
* @ todo plugname / e_shortcode . php auto - detection ( hard , near impossible at this time ) - we need 'plugin_' prefix to
* distinguish them from the core batches
*
* @ param string $className
* @ return void
*/
public static function autoload ( $className )
{
//Security...
if ( strpos ( $className , '/' ) !== false )
{
return ;
}
$tmp = explode ( '_' , $className );
$filename = '' ;
//echo 'autoloding...'.$className.'<br />';
switch ( $tmp [ 0 ])
{
case 'plugin' : // plugin handlers/shortcode batches
array_shift ( $tmp ); // remove 'plugin'
$end = array_pop ( $tmp ); // check for 'shortcodes' end phrase
if ( ! isset ( $tmp [ 0 ]) || ! $tmp [ 0 ])
{
if ( $end )
{
// plugin root - e.g. plugin_myplug -> plugins/myplug/myplug.php, class plugin_myplug
$filename = e_PLUGIN . $end . '/' . $end . '.php' ;
break ;
}
return ; // In case we get an empty class part
}
// Currently only batches inside shortcodes/ folder are auto-detected,
// read the todo for e_shortcode.php related problems
if ( 'shortcodes' == $end )
{
2012-01-06 10:05:32 +00:00
$filename = e_PLUGIN . $tmp [ 0 ] . '/shortcodes/batch/' ; // plugname/shortcodes/batch/
2011-11-25 17:24:42 +00:00
unset ( $tmp [ 0 ]);
$filename .= implode ( '_' , $tmp ) . '_shortcodes.php' ; // my_shortcodes.php
break ;
}
if ( $end )
{
$tmp [] = $end ; // not a shortcode batch - append the end phrase again
}
// Handler check
$tmp [ 0 ] .= '/includes' ; //folder 'includes' is not part of the class name
$filename = e_PLUGIN . implode ( '/' , $tmp ) . '.php' ;
//TODO add debug screen Auto-loaded classes - ['plugin: '.$filename.' - '.$className];
break ;
default : //core libraries, core shortcode batches
// core SC batch check
$end = array_pop ( $tmp );
if ( 'shortcodes' == $end )
{
$filename = e_CORE . 'shortcodes/batch/' . $className . '.php' ; // core shortcode batch
break ;
}
$filename = e107 :: getHandlerPath ( $className , true );
//TODO add debug screen Auto-loaded classes - ['core: '.$filename.' - '.$className];
break ;
}
2013-06-01 14:02:46 -07:00
if ( $filename && is_file ( $filename )) // Test with chatbox_menu
2011-11-25 17:24:42 +00:00
{
// autoload doesn't REQUIRE files, because this will break things like call_user_func()
include ( $filename );
}
}
2006-12-02 04:36:16 +00:00
2009-07-23 15:29:07 +00:00
public function __get ( $name )
{
2009-12-02 16:51:04 +00:00
switch ( $name )
2009-07-23 15:29:07 +00:00
{
case 'tp' :
$ret = e107 :: getParser ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'sql' :
$ret = e107 :: getDb ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'ecache' :
$ret = e107 :: getCache ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'arrayStorage' :
$ret = e107 :: getArrayStorage ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'e_event' :
$ret = e107 :: getEvent ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'ns' :
$ret = e107 :: getRender ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'url' :
$ret = e107 :: getUrl ();
break ;
case 'admin_log' :
$ret = e107 :: getAdminLog ();
break ;
case 'override' :
$ret = e107 :: getSingleton ( 'override' , e_HANDLER . 'override_class.php' );
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'notify' :
$ret = e107 :: getNotify ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'e_online' :
$ret = e107 :: getOnline ();
break ;
2009-12-02 16:51:04 +00:00
2011-12-28 10:01:25 +00:00
case 'eIPHandler' :
$ret = e107 :: getIPHandler ();
break ;
2009-07-23 15:29:07 +00:00
case 'user_class' :
$ret = e107 :: getUserClass ();
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
default :
trigger_error ( '$e107->$' . $name . ' not defined' , E_USER_WARNING );
2009-12-02 16:51:04 +00:00
return null ;
2009-07-23 15:29:07 +00:00
break ;
}
2009-12-02 16:51:04 +00:00
2009-10-20 16:05:03 +00:00
$this -> { $name } = $ret ;
2009-07-23 15:29:07 +00:00
return $ret ;
}
2013-05-27 10:54:42 +03:00
public function destruct ()
{
if ( null === self :: $_instance ) return ;
$print = defined ( 'E107_DBG_TIMEDETAILS' ) && E107_DBG_TIMEDETAILS ;
! $print || print ( 'Destructing $e107: <br />' );
$vars = get_object_vars ( $this );
foreach ( $vars as $name => $value )
{
if ( is_object ( $value ))
{
if ( method_exists ( $value , '__destruct' ))
{
! $print || print ( 'object [property] using __destruct(): ' . $path . ' - ' . get_class ( $value ) . '<br />' );
$value -> __destruct ();
}
else ! $print || print ( 'object [property]: ' . $name . ' - ' . get_class ( $value ) . '<br />' );
$this -> $name = null ;
}
}
foreach ( self :: $_registry as $path => $reg )
{
if ( is_object ( $reg ))
{
if ( method_exists ( $reg , '__destruct' ))
{
! $print || print ( 'object [registry] using __destruct(): ' . $path . ' - ' . get_class ( $reg ) . '<br />' );
$reg -> __destruct ();
}
else ! $print || print ( 'object [registry]: ' . $path . ' - ' . get_class ( $reg ) . '<br />' );
unset ( self :: $_registry [ $path ]);
}
}
self :: $_registry = null ;
self :: $_instance = null ;
}
2006-12-02 04:36:16 +00:00
}