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' ;
2015-07-07 12:07:17 -07:00
const LOCALHOST_IP2 = '0000:0000:0000:0000:0000:0000:0000: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 ;
2021-01-24 15:33:39 -08:00
// 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
2020-12-21 17:46:32 -08:00
// 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
2015-01-26 18:03:14 -08:00
* @ see e107 :: user ()
2009-07-23 15:29:07 +00:00
*/
public $extended_struct ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
/**
* User login name
*
2019-05-26 17:05:29 -07:00
* @ var array
2009-07-23 15:29:07 +00:00
* @ see init_session ()
*/
2019-05-26 17:05:29 -07:00
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
*/
2021-01-24 15:33:39 -08: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
*/
2020-12-19 09:50:29 -08:00
protected static $_instance ;
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
2016-12-31 10:10:41 -08:00
/**
* e107 theme config object storage
*
* @ var array
*/
protected static $_theme_config_arr = array ();
2017-01-03 11:02:09 -08:00
/**
* e107 e107 :: css () on / off flag .
*
* @ var bool
*/
protected static $_css_enabled = true ;
/**
* e107 e107 :: js () on / off flag .
*
* @ var bool
*/
protected static $_js_enabled = true ;
2019-06-14 14:32:58 -07:00
protected static $_breadcrumb = array ();
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 (
2016-12-15 10:06:54 +01:00
'UserHandler' => '{e_HANDLER}user_handler.php' ,
'comment' => '{e_HANDLER}comment_class.php' ,
2018-05-11 08:39:01 -07:00
'e_date' => '{e_HANDLER}date_handler.php' ,
2018-05-11 14:58:04 -07:00
'convert' => '{e_HANDLER}date_handler.php' , // BC Fix.
2019-06-03 15:27:36 -07:00
'db' => '{e_HANDLER}e_db_pdo_class.php' ,
// 'db' => '{e_HANDLER}mysql_class.php',
2016-12-15 10:06:54 +01:00
'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' ,
2016-12-15 10:06:54 +01:00
'e107_traffic' => '{e_HANDLER}traffic_class.php' ,
'e107_user_extended' => '{e_HANDLER}user_extended_class.php' ,
'e107plugin' => '{e_HANDLER}plugin_class.php' ,
'e_chart' => '{e_HANDLER}chart_class.php' ,
'e_core_session' => '{e_HANDLER}session_handler.php' ,
'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_front_model' => '{e_HANDLER}model_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' ,
2021-01-05 08:54:09 -08:00
'e_ajax' => '{e_HANDLER}e_ajax_class.php' ,
2016-12-15 10:06:54 +01:00
'e_array' => '{e_HANDLER}core_functions.php' , // Old ArrayStorage.
'e_bbcode' => '{e_HANDLER}bbcode_handler.php' ,
'e_bb_base' => '{e_HANDLER}bbcode_handler.php' ,
2017-01-24 19:53:40 -08:00
'e_customfields' => '{e_HANDLER}e_customfields_class.php' ,
2021-01-14 17:26:15 -08:00
'e_emote' => '{e_HANDLER}e_emote_class.php' ,
2016-12-15 10:06:54 +01:00
'e_file' => '{e_HANDLER}file_class.php' ,
2020-03-27 00:27:46 -05:00
'e_file_inspector_json_phar' => '{e_HANDLER}e_file_inspector_json_phar.php' ,
2016-12-15 10:06:54 +01:00
'e_form' => '{e_HANDLER}form_handler.php' ,
'e_jshelper' => '{e_HANDLER}js_helper.php' ,
'e_media' => '{e_HANDLER}media_class.php' ,
'e_menu' => '{e_HANDLER}menu_class.php' ,
'e_model' => '{e_HANDLER}model_class.php' ,
'e_navigation' => '{e_HANDLER}sitelinks_class.php' ,
'e_news_item' => '{e_HANDLER}news_class.php' ,
'e_news_tree' => '{e_HANDLER}news_class.php' ,
2017-02-12 09:33:22 -08:00
'e_news_category_tree' => '{e_HANDLER}news_class.php' ,
2016-12-15 10:06:54 +01:00
'e_object' => '{e_HANDLER}model_class.php' ,
'e_online' => '{e_HANDLER}online_class.php' ,
'e_parse' => '{e_HANDLER}e_parse_class.php' ,
'e_parser' => '{e_HANDLER}e_parse_class.php' ,
'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php' ,
2017-02-03 20:18:45 -08:00
'e_plugin' => '{e_HANDLER}plugin_class.php' ,
2021-01-18 08:52:10 -08:00
'e_profanity' => '{e_HANDLER}e_profanity_class.php' ,
2016-12-15 10:06:54 +01:00
'e_ranks' => '{e_HANDLER}e_ranks_class.php' ,
2021-01-18 08:52:10 -08:00
'e_render' => '{e_HANDLER}e_render_class.php' ,
2021-01-19 18:52:56 -08:00
'e_search' => '{e_HANDLER}search_class.php' ,
2016-12-15 10:06:54 +01:00
'e_shortcode' => '{e_HANDLER}shortcode_handler.php' ,
'e_system_user' => '{e_HANDLER}user_model.php' ,
2017-01-04 18:08:58 -08:00
'e_theme' => '{e_HANDLER}theme_handler.php' ,
2016-12-15 10:06:54 +01:00
'e_upgrade' => '{e_HANDLER}e_upgrade_class.php' ,
'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' ,
2020-02-19 18:25:25 +01:00
'e_user_provider' => '{e_HANDLER}user_handler.php' ,
2016-12-15 10:06:54 +01:00
'e_userperms' => '{e_HANDLER}user_handler.php' ,
'e_validator' => '{e_HANDLER}validator_class.php' ,
'e_vars' => '{e_HANDLER}model_class.php' ,
2017-04-19 13:20:59 -07:00
'e_url' => '{e_HANDLER}application.php' ,
2016-12-15 10:06:54 +01:00
'ecache' => '{e_HANDLER}cache_handler.php' ,
'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' ,
'eIPHandler' => '{e_HANDLER}iphandler_class.php' ,
'email_validation_class' => '{e_HANDLER}mail_validation_class.php' ,
'eMessage' => '{e_HANDLER}message_handler.php' ,
'eRequest' => '{e_HANDLER}application.php' ,
'eResponse' => '{e_HANDLER}application.php' ,
'eRouter' => '{e_HANDLER}application.php' ,
2018-10-31 12:24:45 -05:00
'eShims' => '{e_HANDLER}Shims/eShims.php' ,
2016-12-15 10:06:54 +01:00
'eUrl' => '{e_HANDLER}e107Url.php' ,
'eUrlConfig' => '{e_HANDLER}application.php' ,
'eUrlRule' => '{e_HANDLER}application.php' ,
'language' => '{e_HANDLER}language_class.php' ,
'news' => '{e_HANDLER}news_class.php' ,
'notify' => '{e_HANDLER}notify_class.php' ,
'override' => '{e_HANDLER}override_class.php' ,
'rater' => '{e_HANDLER}rate_class.php' ,
'redirection' => '{e_HANDLER}redirection_class.php' ,
'secure_image' => '{e_HANDLER}secure_img_handler.php' ,
'sitelinks' => '{e_HANDLER}sitelinks_class.php' ,
'themeHandler' => '{e_HANDLER}theme_handler.php' ,
'user_class' => '{e_HANDLER}userclass_class.php' ,
2015-03-01 12:43:02 -08:00
'user_class_admin' => '{e_HANDLER}userclass_class.php' ,
2016-12-15 10:06:54 +01:00
'userlogin' => '{e_HANDLER}login.php' ,
'validatorClass' => '{e_HANDLER}validator_class.php' ,
'xmlClass' => '{e_HANDLER}xml_class.php' ,
2016-02-13 15:33:23 -08:00
'e107MailManager' => '{e_HANDLER}mail_manager_class.php' ,
2016-12-15 10:06:54 +01:00
'e_library_manager' => '{e_HANDLER}library_manager.php' ,
'error_page' => '{e_HANDLER}error_page_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
*
*/
protected function __construct ()
{
2021-01-16 08:43:51 -08:00
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
}
2020-02-17 10:36:03 +01:00
private static function die_http_400 ()
{
header ( 'HTTP/1.0 400 Bad Request' , true , 400 );
header ( 'Content-Type: text/plain' );
if ( deftrue ( 'e_DEBUG' ))
{
echo " Bad Request: " ;
debug_print_backtrace ( 0 , 1 );
}
exit ();
}
2020-12-20 13:25:03 -08:00
/**
* Render layout - replacement for legacy parseheader () function in header_default . php
* @ param string $LAYOUT
2021-01-26 11:55:10 -08:00
* @ param array $opts - 'magicSC' => array of magic shortcode key => value pair replacements and 'bodyStart' - code to place after body tag .
2020-12-20 13:25:03 -08:00
* @ return void
*/
public static function renderLayout ( $LAYOUT , $opts = array ())
{
$tp = self :: getParser ();
$tmp = explode ( " \n " , $LAYOUT );
2021-01-26 11:55:10 -08:00
2021-01-27 12:20:58 -08:00
$sc = isset ( $opts [ 'sc' ]) ? self :: getScBatch ( $opts [ 'sc' ]) : self :: getScBatch ( '_theme_' ); // include the theme shortcodes.
2020-12-20 13:25:03 -08:00
2021-01-26 11:55:10 -08:00
$parseMagic = false ;
$bodyStart = false ;
$bodyTag = false ;
if ( isset ( $opts [ 'magicSC' ]))
{
$search = array_keys ( $opts [ 'magicSC' ]);
$replace = array_values ( $opts [ 'magicSC' ]);
$parseMagic = true ;
}
if ( isset ( $opts [ 'bodyStart' ]) && ! empty ( $opts [ 'bodyStart' ]))
{
$bodyStart = true ;
}
2020-12-20 13:25:03 -08:00
2021-01-26 11:55:10 -08:00
foreach ( $tmp as $k => $line )
2020-12-20 13:25:03 -08:00
{
2021-01-26 11:55:10 -08:00
2020-12-20 13:44:18 -08:00
if ( empty ( $line ))
{
continue ;
}
2021-01-26 11:55:10 -08:00
if ( $bodyStart )
{
if ( $bodyTag )
{
echo " \n <!-- Start custom body-start tag --> \n " ;
echo trim ( $opts [ 'bodyStart' ]) . " \n " ;
echo " <!-- End custom body-start tag --> \n \n " ;
}
$bodyTag = ( strpos ( trim ( $line ), '<body' ) === 0 ) ? true : false ;
}
if ( $parseMagic )
{
$line = str_replace ( $search , $replace , $line ); // Quick-fix allow for use of {THEME} shortcode.
}
2020-12-20 13:25:03 -08:00
if ( strpos ( $line , '{' ) === false )
{
echo $line . " \n " ; // retain line-breaks.
continue ;
}
2021-01-26 11:55:10 -08:00
else
2020-12-20 13:25:03 -08:00
{
echo $tp -> parseTemplate ( $line , true , $sc ) . " \n " ; // retain line-breaks.
}
}
}
2021-01-16 08:43:51 -08:00
/**
* @ param string $plug_name
*/
private static function _loadPluginLans ( $plug_name )
{
if ( is_dir ( e_PLUGIN . $plug_name . " /languages " ))
{
self :: plugLan ( $plug_name , '' , true ); // English/English_front.php
self :: plugLan ( $plug_name , null , true ); // English/English.php
2021-01-22 13:44:10 -08:00
// self::plugLan($plug_name, 'front'); // English_front.php
self :: plugLan ( $plug_name , null ); // English.php
2021-01-16 08:43:51 -08:00
self :: plugLan ( $plug_name , 'global' , true ); // English/English_global.php
self :: plugLan ( $plug_name , 'global' ); // English_global.php
}
}
2021-01-19 13:31:20 -08:00
/**
* Returns the frontpage setting ( ie . selected in e107_admin / frontpage . php ) for the current user .
* @ return string
*/
public static function getFrontpage ()
{
$fpref = e107 :: getPref ( 'frontpage' );
$location = '' ;
$class_list = explode ( ',' , USERCLASS_LIST );
if ( isset ( $fpref [ 'all' ]) && $fpref [ 'all' ])
{ // 0.7 method
$location = $fpref [ 'all' ];
}
else
{ // This is the 'new' method - assumes $fpref is an ordered list of rules
if ( ! empty ( $fpref ))
{
foreach ( $fpref as $fk => $fp )
{
if ( in_array ( $fk , $class_list ))
{
$location = $fp ;
break ;
}
}
}
}
if ( ! $location )
{ // Try and use the 'old' method (this bit can go later)
if ( ADMIN )
{
$location = $fpref [ e_UC_ADMIN ];
}
elseif ( USER )
{ // This is the key bit - what to do for a 'normal' logged in user
// We have USERCLASS_LIST - comma separated. Also e_CLASS_REGEXP
$inclass = false ;
foreach ( $class_list as $fp_class )
{
if ( ! $inclass && check_class ( $fp_class [ 'userclass_id' ]))
{
$location = $fpref [ $fp_class [ 'userclass_id' ]];
$inclass = true ;
}
}
$location = $location ? $location : $fpref [ e_UC_MEMBER ];
}
else
{
$location = $fpref [ e_UC_GUEST ];
}
}
$location = trim ( $location );
// Defaults to news
if ( ! $location )
{
$location = 'url:/news' ;
}
// Former Welcome Message front-page. Should be handled by current theme layout
elseif ( $location == 'index.php' || $location == 'url:/' || $location == 'route:/' || $location == '/' )
{
$location = false ;
}
elseif ( $location [ 0 ] === '{' )
{
$location = e107 :: getParser () -> replaceConstants ( $location , true );
}
return $location ;
}
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
{
2020-12-19 09:50:29 -08:00
if ( self :: $_instance == null )
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
*
2015-03-09 15:05:34 -07:00
* @ param $e107_paths
* @ param $e107_root_path
* @ param $e107_config_mysql_info
* @ param array $e107_config_override
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
{
2018-02-04 18:42:39 -08: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
*
2015-03-09 15:05:34 -07:00
* @ param $e107_paths
* @ param $e107_root_path
* @ param array $e107_config_override
2020-02-28 10:33:50 -08:00
* @ return object | boolean e107
2011-05-03 22:13:59 +00:00
*/
public function initInstall ( $e107_paths , $e107_root_path , $e107_config_override = array ())
{
2014-05-28 03:05:27 -07:00
2013-03-14 17:31:56 -07:00
$e107_config = 'e107_config.php' ;
2020-12-19 09:50:29 -08:00
if ( ! file_exists ( $e107_config ) && file_put_contents ( $e107_config , '' ) === false ) // prevent blank-page with missing file during install.
2018-09-03 14:35:03 -07:00
{
2020-12-19 09:50:29 -08:00
return false ;
2018-09-03 14:35:03 -07:00
}
2011-05-03 22:13:59 +00:00
// Do some security checks/cleanup, prepare the environment
$this -> prepare_request ();
2018-09-03 14:35:03 -07:00
//generated from mysql data at stage 5 of install.
2012-07-18 02:24:34 +00:00
$this -> site_path = isset ( $e107_config_override [ 'site_path' ]) ? $e107_config_override [ 'site_path' ] : " [hash] " ; // placeholder
2018-09-03 14:35:03 -07:00
2011-05-03 22:13:59 +00:00
// folder info
//$this->e107_dirs = $e107_paths;
$this -> setDirs ( $e107_paths , $e107_config_override );
2018-09-03 14:35:03 -07: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 ();
2018-09-03 14:35:03 -07: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
*
2015-03-09 15:05:34 -07:00
* @ param $e107_paths
* @ param $e107_root_path
* @ param $e107_config_mysql_info
* @ param array $e107_config_override
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
{
2020-12-19 09:50:29 -08:00
if ( ! empty ( $this -> e107_dirs ))
{
return $this ;
}
2015-03-29 20:26:35 -07:00
2018-02-12 06:50:43 -06:00
// Do some security checks/cleanup, prepare the environment
$this -> prepare_request ();
2017-08-04 10:18:40 +02:00
2018-02-12 06:50:43 -06:00
// mysql connection info
$this -> e107_config_mysql_info = $e107_config_mysql_info ;
2018-02-04 18:42:39 -08:00
2018-02-12 06:50:43 -06:00
// unique folder for e_MEDIA - support for multiple websites from single-install. Must be set before setDirs()
2018-11-07 16:31:08 -08:00
/* if ( ! empty ( $e107_config_override [ 'site_path' ]))
2018-02-12 06:50:43 -06:00
{
// $E107_CONFIG['site_path']
$this -> site_path = $e107_config_override [ 'site_path' ];
2018-11-07 16:31:08 -08:00
} */
if ( empty ( $e107_config_override [ 'site_path' ]))
2018-02-12 06:50:43 -06:00
{
$this -> site_path = $this -> makeSiteHash ( $e107_config_mysql_info [ 'mySQLdefaultdb' ], $e107_config_mysql_info [ 'mySQLprefix' ]);
}
2009-12-02 16:51:04 +00:00
2018-02-12 06:50:43 -06:00
// Set default folder (and override paths) if missing from e107_config.php
$this -> setDirs ( $e107_paths , $e107_config_override );
2018-09-03 14:35:03 -07:00
2018-02-12 06:50:43 -06:00
// various constants - MAGIC_QUOTES_GPC, MPREFIX, ...
$this -> set_constants ();
2009-12-02 16:51:04 +00:00
2018-02-12 06:50:43 -06:00
// build all paths
$this -> set_paths ();
$this -> file_path = $this -> fix_windows_paths ( $e107_root_path );
2011-04-25 11:29:21 +00:00
2018-02-12 06:50:43 -06:00
// set base path, SSL is auto-detected
$this -> set_base_path ();
2010-02-09 20:43:54 +00:00
2018-02-12 06:50:43 -06:00
// cleanup QUERY_STRING and friends, set related constants
$this -> set_request ();
2017-02-08 22:52:18 -08:00
2018-02-12 06:50:43 -06:00
// set some core URLs (e_LOGIN/SIGNUP)
$this -> set_urls ();
2017-02-08 22:52:18 -08:00
2018-02-12 06:50:43 -06:00
if ( ! is_dir ( e_SYSTEM ))
{
2020-01-17 15:10:18 +01:00
mkdir ( e_SYSTEM , 0755 , true );
2018-02-12 06:50:43 -06:00
}
2017-10-25 15:17:53 -07:00
2018-02-12 06:50:43 -06:00
if ( ! is_dir ( e_CACHE_IMAGE ))
{
2020-01-17 15:10:18 +01:00
mkdir ( e_CACHE_IMAGE , 0755 , true );
2009-07-21 16:11:02 +00:00
}
2010-02-09 20:43:54 +00:00
2018-02-12 06:50:43 -06:00
// Prepare essential directories.
$this -> prepareDirs ();
2018-02-04 18:42:39 -08:00
2009-07-21 16:11:02 +00:00
return $this ;
}
2009-12-02 16:51:04 +00:00
2017-08-04 10:18:40 +02:00
/**
* Create a unique hash for each database configuration ( multi - site support ) .
*/
function makeSiteHash ( $db , $prefix ) // also used by install.
2012-06-23 10:08:17 +00:00
{
2017-08-04 10:18:40 +02:00
return substr ( md5 ( $db . " . " . $prefix ), 0 , 10 );
2012-06-23 10:08:17 +00:00
}
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 ())
{
2018-11-07 16:31:08 -08:00
if ( ! empty ( $e107_config_override [ 'site_path' ])) // $E107_CONFIG['site_path']
{
$this -> site_path = $e107_config_override [ 'site_path' ];
}
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 );
2018-09-03 14:35:03 -07:00
2015-10-06 09:17:15 +03:00
// Required for e_MEDIA_BASE, e_SYSTEM_BASE (free of site path constants);
2018-02-19 13:46:09 -08:00
// $this->e107_dirs['MEDIA_BASE_DIRECTORY'] = $this->e107_dirs['MEDIA_DIRECTORY'];
// $this->e107_dirs['SYSTEM_BASE_DIRECTORY'] = $this->e107_dirs['SYSTEM_BASE_DIRECTORY'];
2015-10-06 09:17:15 +03:00
2017-08-04 10:18:40 +02:00
// $this->site_path is appended to MEDIA_DIRECTORY in defaultDirs(), which is called above.
2012-07-18 03:47:28 +00:00
if ( strpos ( $this -> e107_dirs [ 'MEDIA_DIRECTORY' ], $this -> site_path ) === false )
{
2018-09-03 14:35:03 -07:00
$this -> e107_dirs [ 'MEDIA_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
2012-07-18 03:47:28 +00:00
}
2017-08-04 10:18:40 +02:00
// FIXME - remove this condition because:
// $this->site_path is appended to SYSTEM_DIRECTORY in defaultDirs(), which is called above.
2012-07-18 03:47:28 +00:00
if ( strpos ( $this -> e107_dirs [ 'SYSTEM_DIRECTORY' ], $this -> site_path ) === false )
{
2018-09-03 14:35:03 -07:00
$this -> e107_dirs [ 'SYSTEM_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
2012-07-18 03:47:28 +00:00
}
2013-04-03 12:25:30 +03:00
if ( strpos ( $this -> e107_dirs [ 'CACHE_DIRECTORY' ], $this -> site_path ) === false )
{
2018-09-03 14:35:03 -07:00
$this -> e107_dirs [ 'CACHE_DIRECTORY' ] = $this -> e107_dirs [ 'SYSTEM_DIRECTORY' ] . " cache/ " ; // multisite support.
2013-04-03 12:25:30 +03:00
}
2018-09-03 14:35:03 -07:00
2017-08-07 09:47:00 +02:00
return $this ;
}
/**
* Prepares essential directories .
*/
public function prepareDirs ()
{
2020-12-19 09:50:29 -08:00
$file = self :: getFile ();
2017-08-04 10:18:40 +02:00
// Essential directories which should be created and writable.
$essential_directories = array (
'MEDIA_DIRECTORY' ,
'SYSTEM_DIRECTORY' ,
'CACHE_DIRECTORY' ,
'CACHE_CONTENT_DIRECTORY' ,
'CACHE_IMAGE_DIRECTORY' ,
'CACHE_DB_DIRECTORY' ,
'CACHE_URL_DIRECTORY' ,
'LOGS_DIRECTORY' ,
'BACKUP_DIRECTORY' ,
'TEMP_DIRECTORY' ,
'IMPORT_DIRECTORY' ,
);
// Create directories which don't exist.
foreach ( $essential_directories as $directory )
{
if ( ! isset ( $this -> e107_dirs [ $directory ])) {
continue ;
}
2017-08-07 19:25:33 +02:00
$path = e_ROOT . $this -> e107_dirs [ $directory ];
$file -> prepareDirectory ( $path , FILE_CREATE_DIRECTORY );
2017-08-04 10:18:40 +02:00
}
2010-03-03 17:06:33 +00:00
}
/**
* 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 );
2018-02-19 13:46:09 -08:00
$ret [ 'MEDIA_BASE_DIRECTORY' ] = $ret [ 'MEDIA_DIRECTORY' ];
$ret [ 'SYSTEM_BASE_DIRECTORY' ] = $ret [ 'SYSTEM_DIRECTORY' ];
2018-09-03 14:35:03 -07:00
$ret [ 'MEDIA_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
$ret [ 'SYSTEM_DIRECTORY' ] .= $this -> site_path . " / " ; // multisite support.
2020-12-19 09:50:29 -08:00
if ( $return_root )
{
return $ret ;
}
2018-09-03 14:35:03 -07: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/' ;
2018-09-03 14:35:03 -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/' ;
2018-09-03 14:35:03 -07: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/';
2018-09-03 14:35:03 -07: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/' ;
2017-10-25 15:17:53 -07:00
if ( defined ( 'e_MEDIA_STATIC' )) // experimental - subject to change.
{
$ret [ 'CACHE_IMAGE_DIRECTORY' ] = $ret [ 'MEDIA_IMAGES_DIRECTORY' ] . 'cache/' ;
}
else
{
$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/' ;
2018-09-03 14:35:03 -07:00
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/' ;
2010-03-03 17:06:33 +00:00
return $ret ;
}
2009-12-02 16:51:04 +00:00
/**
* Set mysql data
*
2015-03-09 15:05:34 -07:00
* @ param $e107_config_mysql_info
2009-12-02 16:51:04 +00:00
* @ 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
2015-03-09 15:05:34 -07:00
* @ param null $default
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
2017-01-29 18:43:52 -08:00
if ( $id === '_all_' )
2016-02-28 20:50:09 -08:00
{
return self :: $_registry ;
}
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
2015-03-09 15:05:34 -07:00
* @ param bool $allow_override
2009-07-21 16:11:02 +00:00
*/
public static function setRegistry ( $id , $data = null , $allow_override = true )
{
2020-12-19 09:50:29 -08:00
if ( $data === null )
2009-07-21 16:11:02 +00:00
{
2017-12-10 12:03:48 +01:00
if ( isset ( self :: $_registry [ $id ]) && is_object ( self :: $_registry [ $id ]) && method_exists ( self :: $_registry [ $id ], '__destruct' ))
2009-07-21 16:11:02 +00:00
{
self :: $_registry [ $id ] -> __destruct ();
}
unset ( self :: $_registry [ $id ]);
return ;
}
2009-12-02 16:51:04 +00:00
2020-12-19 09:50:29 -08:00
if ( ! $allow_override && self :: getRegistry ( $id ) !== null )
2009-07-21 16:11:02 +00:00
{
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 )
2021-01-19 07:54:13 -08:00
* Replaces all $ ( * ) _DIRECTORY globals .
2021-01-16 14:49:56 -08:00
* @ example
2009-11-24 16:30:08 +00:00
* Example : < code > $e107 -> getFolder ( 'images' ) </ code > ;
2009-08-20 12:24:47 +00:00
*
2021-01-19 07:54:13 -08:00
* @ param string $for admin | plugins | themes | files | handlers
2009-08-20 12:24:47 +00:00
* @ return string
*/
2015-02-15 02:37:36 -08:00
public static function getFolder ( $for )
2009-08-20 12:24:47 +00:00
{
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
2020-12-06 11:33:09 -08:00
* @ return boolean | array
2010-05-13 15:47:31 +00:00
*/
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 ();
2020-12-19 09:50:29 -08:00
if ( $key === null )
{
return $self -> _E107 ;
}
return (( isset ( $self -> _E107 [ $key ]) && $self -> _E107 [ $key ]));
2010-05-13 15:47:31 +00:00
}
/**
* 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 ()
{
2021-01-05 12:25:28 -08:00
if ( PHP_SAPI === 'cli' )
{
return true ;
}
2010-05-13 15:47:31 +00:00
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 >
*
2018-09-03 14:35:03 -07:00
* @ param string $for prefix | server | user | password | defaultdb - leave blank for full array .
2018-09-12 11:46:23 -07:00
* @ return string | array
2009-11-24 16:30:08 +00:00
*/
2016-02-12 19:28:35 -08:00
public static 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 ();
2018-09-03 14:35:03 -07:00
2013-05-04 19:59:54 -07:00
if ( $for == '' )
{
return $self -> e107_config_mysql_info ;
}
2018-09-03 14:35:03 -07:00
2013-05-04 19:59:54 -07:00
return ( isset ( $self -> e107_config_mysql_info [ $key ]) ? $self -> e107_config_mysql_info [ $key ] : '' );
2012-06-08 06:03:07 +00:00
}
2018-09-03 14:35:03 -07:00
2012-06-08 06:03:07 +00:00
/**
2018-09-03 14:35:03 -07:00
* Return a unique path based on database used . ie . multi - site support from single install .
2012-06-08 06:03:07 +00:00
*
* @ return string
2018-09-03 14:35:03 -07:00
* @ author
2012-06-08 06:03:07 +00:00
*/
function getSitePath ()
{
2021-01-24 17:00:02 -08:00
return self :: getInstance () -> 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 ))
{
2020-12-19 09:50:29 -08:00
foreach ( $class_name as $cname => $pathb )
2009-09-13 10:31:09 +00:00
{
2020-12-19 09:50:29 -08:00
self :: addHandler ( $cname , $pathb );
2009-09-13 10:31:09 +00:00
}
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
*
2015-03-09 15:05:34 -07:00
* @ param string $class_name
* @ param bool | object $default_handler [ optional ] return data from $_known_handlers if no overload data available
* @ param bool | object $parse_path [ optional ] parse path shortcodes
2009-09-13 10:31:09 +00:00
* @ 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
*
2020-12-19 09:50:29 -08:00
* @ param string | array $class_name
2015-03-09 15:05:34 -07:00
* @ param string $overload_class_name [ optional ]
2009-09-13 10:31:09 +00:00
* @ 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
2020-12-10 15:52:48 -08:00
* @ return mixed
2009-01-09 17:25:50 +00:00
*/
2016-04-14 14:48:02 -07:00
public static function getSingleton ( $class_name , $path = true , $regpath = '' , $vars = null )
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
2016-04-14 14:48:02 -07:00
if ( ! empty ( $vars ))
{
$id .= '/' ;
$id .= is_array ( $vars ) ? crc32 ( serialize ( $vars )) : crc32 ( $vars );
}
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
2020-12-19 09:50:29 -08:00
if ( $path === true && 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
{
2020-04-26 13:32:18 -07:00
global $_E107 ;
2016-02-12 19:28:35 -08:00
2020-04-26 13:32:18 -07:00
if (( ! empty ( $_E107 [ 'debug' ]) || ( defined ( 'e_DEBUG' ) && e_DEBUG === true ) ))
2016-02-12 19:28:35 -08:00
{
require_once ( $path );
}
else
{
@ require_once ( $path );
}
// remove the need for external function.
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 ))
{
2017-01-27 11:14:11 -08:00
self :: setRegistry ( $id , new $class_name ( $vars ));
2009-09-13 10:31:09 +00:00
}
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
2015-03-09 15:05:34 -07:00
* @ param mixed $arguments
2009-08-20 12:24:47 +00:00
* @ param string | boolean $path optional script path
2020-12-10 15:52:48 -08:00
* @ return mixed
2009-07-21 16:11:02 +00:00
*/
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
{
2020-12-19 09:50:29 -08:00
if (( true === $path ) && isset ( self :: $_known_handlers [ $class_name ]))
2009-08-20 12:24:47 +00:00
{
2020-12-19 09:50:29 -08:00
$path = self :: getParser () -> replaceConstants ( self :: $_known_handlers [ $class_name ]);
2009-08-20 12:24:47 +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 ))
{
//overload allowed
2020-12-19 09:50:29 -08:00
if ( $path === true && 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
{
2020-12-19 09:50:29 -08:00
if ( $arguments !== null )
{
return new $class_name ( $arguments );
}
2009-08-20 12:24:47 +00:00
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
*
2015-03-09 15:05:34 -07:00
* @ param string $name core | core_backup | emote | menu | search | notify
* @ param bool $load
* @ param bool $refresh
2020-12-06 11:33:09 -08:00
* @ return e_core_pref | e_plugin_pref
2009-07-30 16:09:30 +00:00
*/
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
{
2018-09-03 14:35:03 -07:00
2021-01-16 08:43:51 -08:00
if ( isset ( self :: $_plug_config_arr [ $name ]))
2012-12-06 16:36:22 -08:00
{
return self :: getPlugConfig ( $name );
}
2018-09-03 14:35:03 -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
{
2018-09-03 14:35:03 -07:00
e107_require_once ( e_HANDLER . 'pref_class.php' );
self :: $_core_config_arr [ $name ] = new e_core_pref ( $name , $load );
2017-01-29 18:43:52 -08:00
if ( $name === 'core' ) // prevent loop between pref and cache handlers.
2012-12-15 03:49:15 -08:00
{
2017-01-27 11:14:11 -08:00
self :: getCache () -> UserCacheActive = self :: getPref ( 'cachestatus' );
self :: getCache () -> SystemCacheActive = self :: getPref ( 'syscachestatus' );
2012-12-15 03:49:15 -08:00
}
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
2015-03-09 15:05:34 -07:00
* @ param null $index
2009-07-30 16:09:30 +00:00
* @ 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
2017-04-12 15:52:43 -07:00
/**
* Retrieve the global LAN for a specific plugin .
* @ param $dir
* @ param string $type
* @ return mixed
*/
public static function getPlugLan ( $dir , $type = 'name' )
{
$lan = " LAN_PLUGIN_ " . strtoupper ( $dir ) . " _ " . strtoupper ( $type );
return defset ( $lan , false );
}
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 ()
2015-03-09 15:05:34 -07:00
* @ param $plug_name
2009-07-30 16:09:30 +00:00
* @ param string $pref_name
* @ param mixed $default default value if preference is not found
2015-03-09 15:05:34 -07:00
* @ param null $index
2009-07-30 16:09:30 +00:00
* @ 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
2016-12-31 10:10:41 -08:00
/**
* Retrieve theme config handlers .
* Multiple theme preference DB rows are supported
* Class overload is supported .
* Examples :
* - < code > e107 :: getTHemeConfig ( 'mytheme' ); </ code >
* 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 )
* - < code > e107 :: getPluginConfig ( 'myplug' , 'row2' ); </ code >
* 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 )
*
* @ param string $theme_name
* @ param string $multi_row
* @ param boolean $load load from DB on startup
* @ return e_plugin_pref
*/
public static function getThemeConfig ( $theme_name = null , $multi_row = '' , $load = true )
{
if ( empty ( $theme_name ))
{
$theme_name = self :: getPref ( 'sitetheme' );
}
if ( ! isset ( self :: $_theme_config_arr [ $theme_name . $multi_row ]))
{
e107_require_once ( e_HANDLER . 'pref_class.php' );
self :: $_theme_config_arr [ $theme_name . $multi_row ] = new e_theme_pref ( $theme_name , $multi_row , $load );
}
return self :: $_theme_config_arr [ $theme_name . $multi_row ];
}
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
2015-03-09 15:05:34 -07:00
* @ param null $index
2009-08-05 19:56:48 +00:00
* @ 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
{
2016-12-31 10:10:41 -08:00
// new storage method in it's own core table row. eg. theme_bootstrap3
$theme_name = self :: getPref ( 'sitetheme' );
if ( self :: getThemeConfig ( $theme_name ) -> hasData () === true )
{
return empty ( $pref_name ) ? self :: getThemeConfig ( $theme_name ) -> getPref () : self :: getThemeConfig ( $theme_name ) -> get ( $pref_name , $default );
}
// old storage method in core prefs.
$legacy_pref_name = ( $pref_name ) ? $pref_name = '/' . $pref_name : '' ;
$tprefs = self :: getConfig () -> getPref ( 'sitetheme_pref' . $legacy_pref_name , $default , $index );
2015-11-05 12:25:16 -08:00
2017-01-25 17:57:38 -08:00
return ! empty ( $tprefs ) ? $tprefs : $default ;
2016-12-31 10:10:41 -08:00
2011-11-29 12:11:27 +00:00
}
2018-09-03 14:35:03 -07:00
2011-11-29 12:11:27 +00:00
/**
* Set current theme preference . $pref_name is parsed ,
* so that $pref_name = 'x/y/z' will set value pref_data [ x ][ y ][ z ]
2018-09-03 14:35:03 -07:00
*
2011-11-29 12:11:27 +00:00
* @ param string | array $pref_name
* @ param mixed $pref_value
* @ return e_pref
*/
public static function setThemePref ( $pref_name , $pref_value = null )
{
2020-12-19 09:50:29 -08:00
if ( is_array ( $pref_name ))
{
return self :: getConfig () -> set ( 'sitetheme_pref' , $pref_name );
}
return self :: getConfig () -> updatePref ( 'sitetheme_pref/' . $pref_name , $pref_value );
2009-08-05 19:56:48 +00:00
}
2009-12-02 16:51:04 +00:00
2017-01-01 08:13:42 -08:00
public static function getThemeGlyphs ()
{
$custom = self :: getConfig () -> getPref ( 'sitetheme_glyphicons' , false );
$theme = self :: getConfig () -> getPref ( 'sitetheme' , false );
$arr = array ();
if ( ! empty ( $custom ))
{
foreach ( $custom as $glyphConfig )
{
2020-12-19 09:50:29 -08:00
if ( strpos ( $glyphConfig [ 'path' ], 'http' ) !== 0 )
2017-01-01 08:13:42 -08:00
{
$glyphConfig [ 'path' ] = e_THEME . " $theme / " . $glyphConfig [ 'path' ];
}
$arr [] = $glyphConfig ;
2017-11-03 18:52:49 -07:00
if ( E107_DBG_INCLUDES )
{
2020-12-19 09:50:29 -08:00
self :: getDebug () -> log ( " Loading Glyph Icons: " . print_a ( $glyphConfig , true ));
2017-11-03 18:52:49 -07:00
}
2017-01-01 08:13:42 -08:00
}
}
return $arr ;
}
2009-07-21 16:11:02 +00:00
/**
* Retrieve text parser singleton object
*
2020-12-06 11:33:09 -08:00
* @ return e_parse | array
2009-07-21 16:11:02 +00:00
*/
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
*
2020-12-10 15:52:48 -08:00
* @ return e_parse_shortcode | array
2009-07-23 15:29:07 +00:00
*/
public static function getScParser ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_parse_shortcode' );
2010-04-23 15:54:11 +00:00
}
2018-09-03 14:35:03 -07:00
2021-01-19 18:52:56 -08:00
/**
* Retrieve search class singleton object
*
* @ return array | Object | secure_image
*/
public static function getSearch ()
{
return self :: getSingleton ( 'e_search' ); // more flexible.
// return self::getObject('secure_image');
}
2018-09-03 14:35:03 -07:00
2012-06-13 04:58:43 +00:00
/**
* Retrieve secure_image singleton object
*
2020-12-10 15:52:48 -08:00
* @ return array | Object | secure_image
2012-06-13 04:58:43 +00:00
*/
public static function getSecureImg ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'secure_image' ); // more flexible.
2012-06-19 13:20:30 +00:00
// 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
2018-09-03 14:35:03 -07:00
*
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' );
2018-09-03 14:35:03 -07: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' );
2018-09-03 14:35:03 -07: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 );
2018-09-03 14:35:03 -07: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
{
2020-12-19 09:50:29 -08:00
if ( is_string ( $overrideClass ))
{
$overrideClass .= '_shortcodes' ;
}
2010-04-25 13:52:14 +00:00
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
2020-12-18 19:55:12 -08:00
* @ return mixed | e_db
2009-07-22 00:49:35 +00:00
*/
public static function getDb ( $instance_id = '' )
{
2019-06-03 15:27:36 -07: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
*
2018-09-03 14:35:03 -07:00
* @ return ecache
2009-07-22 00:49:35 +00:00
*/
public static function getCache ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'ecache' );
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
*
2018-09-03 14:35:03 -07:00
* @ return e_bbcode
2012-05-11 03:52:57 +00:00
*/
public static function getBB ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_bbcode' );
2012-05-11 03:52:57 +00:00
}
2010-03-22 15:45:47 +00:00
/**
2021-01-17 09:10:00 -08:00
* Retrieve user - session 'UserHandler' singleton object
2010-03-22 15:45:47 +00:00
*
2018-09-03 14:35:03 -07:00
* @ return UserHandler
2010-03-22 15:45:47 +00:00
*/
2011-05-03 22:13:59 +00:00
public static function getUserSession ()
2010-03-22 15:45:47 +00:00
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'UserHandler' );
2010-03-22 15:45:47 +00:00
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
/**
* Retrieve core session singleton object ( s )
*
2015-03-09 15:05:34 -07:00
* @ param null $namespace
2018-09-03 14:35:03 -07:00
* @ return e_core_session
2011-05-03 22:13:59 +00:00
*/
public static function getSession ( $namespace = null )
{
2020-12-19 09:50:29 -08:00
$id = 'core/e107/session/' . ( $namespace === null ? 'e107' : $namespace );
2011-05-03 22:13:59 +00:00
if ( self :: getRegistry ( $id ))
{
return self :: getRegistry ( $id );
}
2020-12-19 09:50:29 -08:00
$session = self :: getObject ( 'e_core_session' , array ( 'namespace' => $namespace ));
2011-05-03 22:13:59 +00:00
self :: setRegistry ( $id , $session );
return $session ;
}
2009-11-22 14:10:09 +00:00
/**
* Retrieve redirection singleton object
*
2018-09-03 14:35:03 -07:00
* @ return redirection
2009-11-22 14:10:09 +00:00
*/
public static function getRedirect ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'redirection' );
2009-12-02 16:51:04 +00:00
}
2018-09-03 14:35:03 -07:00
2017-01-04 18:08:58 -08:00
/**
2012-05-27 10:42:16 +00:00
* Retrieve rater singleton object
*
2018-09-03 14:35:03 -07:00
* @ return rater
2012-05-27 10:42:16 +00:00
*/
public static function getRate ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'rater' );
2012-05-27 10:42:16 +00:00
}
2009-12-02 16:51:04 +00:00
2009-11-21 11:36:10 +00:00
/**
* Retrieve sitelinks singleton object
*
2018-09-03 14:35:03 -07:00
* @ return sitelinks
2009-11-21 11:36:10 +00:00
*/
public static function getSitelinks ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'sitelinks' );
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
*
2021-01-18 08:52:10 -08:00
* @ return e_render
2009-07-22 00:49:35 +00:00
*/
public static function getRender ()
{
2021-01-18 08:52:10 -08:00
return self :: getSingleton ( 'e_render' );
2009-07-22 00:49:35 +00:00
}
2010-02-09 20:43:54 +00:00
2009-12-27 13:56:15 +00:00
/**
* Retrieve e107Email singleton object
*
2018-09-03 14:35:03 -07:00
* @ return e107Email
2009-12-27 13:56:15 +00:00
*/
2016-04-14 14:48:02 -07:00
public static function getEmail ( $overrides = null )
2009-12-27 13:56:15 +00:00
{
2016-04-14 14:48:02 -07:00
return self :: getSingleton ( 'e107Email' , true , null , $overrides );
2009-12-27 13:56:15 +00:00
}
2009-12-02 16:51:04 +00:00
2015-05-16 19:17:24 -07:00
2020-03-09 13:41:00 -07:00
/**
* Retrieves PhpThumbFactory object
*
* @ param $src
2020-12-06 11:33:09 -08:00
* @ deprecated - use Intervention class instead @ see
* @ example use Intervention\Image\ImageManagerStatic as Image ;
* @ example $img = Image :: make ( $this -> _src_path ); .
2020-03-09 13:41:00 -07:00
* @ return bool | GdThumb
*/
2020-12-06 11:33:09 -08:00
/* public static function getThumb ( $src )
2020-03-09 13:41:00 -07:00
{
require_once ( e_HANDLER . 'phpthumb/ThumbLib.inc.php' );
try
{
return PhpThumbFactory :: create ( $src );
}
catch ( Exception $e )
{
return false ;
}
2020-12-06 11:33:09 -08:00
} */
2020-03-09 13:41:00 -07:00
2015-05-16 19:17:24 -07:00
/**
* Retrieve e107Email mail mailer object .
*
2018-09-03 14:35:03 -07:00
* @ return e107MailManager
2015-05-16 19:17:24 -07:00
*/
public static function getBulkEmail ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e107MailManager' );
2015-05-16 19:17:24 -07:00
}
2009-07-22 00:49:35 +00:00
/**
* Retrieve event singleton object
*
2018-09-03 14:35:03 -07:00
* @ return e107_event
2009-07-22 00:49:35 +00:00
*/
public static function getEvent ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e107_event' );
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
*
2018-09-03 14:35:03 -07:00
* @ return e_array
2009-07-22 00:49:35 +00:00
*/
public static function getArrayStorage ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_array' );
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
*
2018-09-03 14:35:03 -07:00
* @ return e_menu
2009-08-16 16:30:56 +00:00
*/
public static function getMenu ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_menu' );
2009-08-16 16:30:56 +00:00
}
2009-12-02 16:51:04 +00:00
2017-01-04 18:08:58 -08:00
2017-02-02 16:42:11 -08:00
/**
* Retrieve e_theme singleton object
2018-09-03 14:35:03 -07:00
* @ return e_theme
2017-01-04 18:08:58 -08:00
*/
2017-02-02 16:42:11 -08:00
public static function getTheme ( $themedir = 'front' , $clearCache = false )
2017-01-04 18:08:58 -08:00
{
2017-02-02 16:42:11 -08:00
2017-02-03 07:39:20 -08:00
if ( ! defined ( 'E107_INSTALL' ))
2017-02-02 16:42:11 -08:00
{
2017-02-03 07:39:20 -08:00
if ( $themedir === 'front' )
{
$themedir = self :: getPref ( 'sitetheme' );
}
if ( $themedir === 'admin' )
{
$themedir = self :: getPref ( 'admintheme' );
}
2017-02-02 16:42:11 -08:00
}
2017-03-02 20:55:31 +01:00
// Get the currently used theme.
2020-12-10 15:52:48 -08:00
if ( $themedir === 'current' )
2017-03-02 20:55:31 +01:00
{
// If we are in the admin area.
if ( deftrue ( 'e_ADMIN_AREA' , false ))
{
$themedir = self :: getPref ( 'admintheme' );
}
2021-01-01 14:05:51 -08:00
elseif ( defined ( 'PREVIEWTHEME' ))
{
$themedir = PREVIEWTHEME ;
}
2017-03-02 20:55:31 +01:00
else
{
2021-01-01 12:29:43 -08:00
$themedir = deftrue ( 'USERTHEME' , self :: getPref ( 'sitetheme' ));
2017-03-02 20:55:31 +01:00
}
}
2017-02-03 07:39:20 -08:00
2019-01-23 19:06:03 -08:00
// e107::getDb()->db_Mark_time('start e_theme');
/** @var e_theme $ret */
$ret = self :: getSingleton ( 'e_theme' , true , null , array ( 'themedir' => $themedir , 'force' => $clearCache ));
// e107::getDb()->db_Mark_time('end e_theme');
/* echo " <pre> " ;
debug_print_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS );
echo " </pre> " ; */
return $ret ;
2017-01-04 18:08:58 -08:00
}
2009-07-22 00:49:35 +00:00
/**
* Retrieve URL singleton object
*
2018-09-03 14:35:03 -07:00
* @ return eURL
2009-07-22 00:49:35 +00:00
*/
public static function getUrl ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'eUrl' );
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
2018-09-03 14:35:03 -07:00
* @ return e_file
2009-07-22 14:32:51 +00:00
*/
2013-02-09 17:22:19 +02:00
public static function getFile ( $singleton = false )
2009-07-22 14:32:51 +00:00
{
if ( $singleton )
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_file' );
2009-07-22 14:32:51 +00:00
}
2020-12-19 09:50:29 -08:00
return self :: getObject ( 'e_file' );
2009-07-22 14:32:51 +00:00
}
2009-12-02 16:51:04 +00:00
2020-03-15 14:57:43 -05:00
/**
* Create a new file inspector object
*
* Note : Only the core file inspector is supported right now .
*
* @ return e_file_inspector
*/
2020-03-29 13:49:18 -05:00
public static function getFileInspector ( $type = 'core' )
{
2020-05-13 16:13:41 -05:00
$fileInspectorPath = realpath ( e_SYSTEM_BASE . " core_image.phar " );
2020-03-29 13:49:18 -05:00
/** @var e_file_inspector $fileInspector */
$fileInspector = self :: getObject ( 'e_file_inspector_json_phar' , $fileInspectorPath );
try
{
$fileInspector -> loadDatabase ();
}
catch ( Exception $e )
{
// TODO: LAN
self :: getMessage () -> addWarning (
" The core integrity image is corrupt. " .
" File Inspector will be inoperative. " .
" Resolve this issue by uploading a good copy of the core image to " .
escapeshellarg ( $fileInspectorPath ) . " . " .
2020-04-29 10:50:50 -05:00
" If uploading with FTP, use binary transfer mode. " .
2020-03-29 13:49:18 -05:00
" Error message: " .
$e -> getMessage ()
);
}
return $fileInspector ;
2020-03-15 14:57:43 -05: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 )
2018-09-03 14:35:03 -07:00
* @ return e_form
2009-10-07 10:54:13 +00:00
*/
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 )
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_form' );
2009-10-07 10:54:13 +00:00
}
2020-12-19 09:50:29 -08:00
return self :: getObject ( 'e_form' , $tabindex );
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
2020-12-21 10:00:28 -08:00
* @ deprecated - use e107 :: getLog ();
2018-09-03 14:35:03 -07:00
* @ return e_admin_log
2009-07-22 00:49:35 +00:00
*/
public static function getAdminLog ()
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>' . __METHOD__ . ' is deprecated.</b> Use e107::getLog() instead' , E_USER_DEPRECATED ); // NO LAN
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_admin_log' );
2009-07-22 00:49:35 +00:00
}
2008-05-16 19:40:39 +00:00
2014-10-22 13:26:03 -07:00
/**
* Retrieve admin log singleton object
*
2018-09-03 14:35:03 -07:00
* @ return e_admin_log
2014-10-22 13:26:03 -07:00
*/
public static function getLog ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_admin_log' );
2014-10-22 13:26:03 -07:00
}
2009-07-22 00:49:35 +00:00
/**
* Retrieve date handler singleton object
2021-01-07 13:24:55 -08:00
* @ deprecated Use e107 :: getDate ();
2018-09-03 14:35:03 -07:00
* @ return convert
2009-07-22 00:49:35 +00:00
*/
public static function getDateConvert ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_date' );
2009-07-22 00:49:35 +00:00
}
2018-09-03 14:35:03 -07:00
2012-05-26 12:21:39 +00:00
/**
2018-09-03 14:35:03 -07:00
* Retrieve date handler singleton object - preferred method .
2012-05-26 12:21:39 +00:00
*
2018-09-03 14:35:03 -07:00
* @ return convert
2012-05-26 12:21:39 +00:00
*/
public static function getDate ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_date' );
2012-05-26 12:21:39 +00:00
}
2009-12-02 16:51:04 +00:00
2013-03-01 15:50:31 -08:00
/**
2018-09-03 14:35:03 -07:00
* Retrieve date handler singleton object - preferred method .
2013-03-01 15:50:31 -08:00
*
2018-09-03 14:35:03 -07:00
* @ return e107_db_debug
2013-03-01 15:50:31 -08:00
*/
2019-02-10 16:19:25 -08:00
public static function getDebug ()
2013-03-01 15:50:31 -08:00
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e107_db_debug' );
2013-03-01 15:50:31 -08:00
}
2009-07-23 15:29:07 +00:00
/**
* Retrieve notify handler singleton object
*
2018-09-03 14:35:03 -07:00
* @ return notify
2009-07-23 15:29:07 +00:00
*/
public static function getNotify ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'notify' );
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
*
2018-09-03 14:35:03 -07:00
* @ return override
2012-06-08 06:03:07 +00:00
*/
public static function getOverride ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'override' );
2012-06-08 06:03:07 +00:00
}
2010-09-10 01:01:48 +00:00
/**
* Retrieve Language handler singleton object
*
2018-09-03 14:35:03 -07:00
* @ return language
2010-09-10 01:01:48 +00:00
*/
public static function getLanguage ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'language' );
2010-09-10 01:01:48 +00:00
}
2009-12-02 16:51:04 +00:00
2011-12-28 10:01:25 +00:00
/**
* Retrieve IP / ban handler singleton object
*
2018-09-03 14:35:03 -07:00
* @ return eIPHandler
2011-12-28 10:01:25 +00:00
*/
public static function getIPHandler ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'eIPHandler' );
2011-12-28 10:01:25 +00:00
}
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
2018-09-03 14:35:03 -07:00
* @ 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 )
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'xmlClass' , true , ( $singleton === true ? '' : $singleton ));
2009-11-26 17:14:07 +00:00
}
2020-12-19 09:50:29 -08:00
return self :: getObject ( 'xmlClass' );
2009-11-04 03:07:44 +00:00
}
2018-09-03 14:35:03 -07:00
2012-07-31 07:32:00 +00:00
/**
2020-02-14 12:25:15 +01:00
* Create a new Hybridauth object based on the provided configuration
2012-07-31 07:32:00 +00:00
*
2020-02-14 12:25:15 +01:00
* @ return Hybridauth\Hybridauth
2020-02-19 16:54:21 +01:00
* @ throws \Hybridauth\Exception\InvalidArgumentException if Hybridauth rejects the provided config
* @ throws ReflectionException if this method is unintentionally broken
2020-02-19 18:25:25 +01:00
* @ deprecated v2 . 3.0 Use the e_user_provider interfaces instead ( e107 :: getUserProvider ()) .
* It ' s the e107 wrapper around Hybridauth .
* @ see e_user_provider for social login features .
2020-02-17 10:36:03 +01:00
* @ see e107 :: getUser () for getting a user object that may or may not have a social login .
2012-07-31 07:32:00 +00:00
*/
2012-12-20 10:45:22 +02:00
public static function getHybridAuth ( $config = null )
2012-07-31 07:32:00 +00:00
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>' . __METHOD__ . ' is deprecated.</b> Use the e_user_provider interfaces instead (e107::getUserProvider())' , E_USER_DEPRECATED ); // NO LAN
2020-02-19 16:54:21 +01:00
$e_user_provider = new e_user_provider ( null , $config );
$reflection = new ReflectionClass ( 'e_user_provider' );
$reflection_property = $reflection -> getProperty ( 'hybridauth' );
$reflection_property -> setAccessible ( true );
return $reflection_property -> getValue ( $e_user_provider );
2012-07-31 07:32:00 +00:00
}
2009-12-02 16:51:04 +00:00
2020-02-19 18:25:25 +01:00
/**
* Create a new social login handler
* @ param string | null $providerName
* @ return e_user_provider
*/
public static function getUserProvider ( $providerName = null )
{
return self :: getObject ( 'e_user_provider' , $providerName );
}
2010-05-02 18:41:20 +00:00
/**
* Retrieve userclass singleton object
*
2018-09-03 14:35:03 -07:00
* @ return user_class
2010-05-02 18:41:20 +00:00
*/
public static function getUserClass ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'user_class' );
2010-05-02 18:41:20 +00:00
}
/**
2021-01-17 09:10:00 -08:00
* Retrieve user model 'e_user' object .
2010-05-02 18:41:20 +00:00
*
* @ 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
2020-12-10 15:52:48 -08:00
* @ return e_system_user | e_user
2010-05-02 18:41:20 +00:00
*/
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 ();
}
2018-09-03 14:35:03 -07:00
2020-12-19 09:50:29 -08:00
if ( ! $user_id )
{
return self :: getObject ( 'e_system_user' );
}
2018-09-03 14:35:03 -07:00
2010-05-13 15:47:31 +00:00
$user = self :: getRegistry ( 'core/e107/user/' . $user_id );
2020-12-19 09:50:29 -08:00
if ( $user === null )
2010-05-02 18:41:20 +00:00
{
2010-05-05 15:05:32 +00:00
$user = self :: getObject ( 'e_system_user' );
2020-12-19 09:50:29 -08:00
$user -> load ( $user_id );
2010-05-02 18:41:20 +00:00
}
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 ();
2021-01-26 18:53:36 +01:00
* @ param $uid integer user_id . Use e107 :: user ( USERID ) for currently logged in user .
2020-12-10 15:52:48 -08:00
* @ return array | false of user data
2013-03-31 04:21:49 -07:00
*/
public static function user ( $uid = null )
{
2020-12-10 15:52:48 -08:00
$uid = ( int ) $uid ;
2018-09-03 14:35:03 -07:00
2015-01-26 18:03:14 -08:00
if ( empty ( $uid )){ return false ; }
2018-09-03 14:35:03 -07:00
2020-12-19 09:50:29 -08:00
$user = self :: getSystemUser ( $uid );
2013-03-31 04:21:49 -07:00
$var = array ();
if ( $user )
{
$var = $user -> getUserData ();
}
2018-09-03 14:35:03 -07:00
2013-03-31 04:21:49 -07:00
return $var ;
}
2013-03-31 05:55:08 -07:00
/**
2018-09-03 14:35:03 -07:00
* Return a string containg exported array data . - preferred .
2013-03-31 05:55:08 -07:00
*
* @ param array $ArrayData array to be stored
2018-07-22 10:39:01 -07:00
* @ param bool | string $mode true = var_export with addedslashes , false = var_export ( default ), 'json' = json encoded
* @ return array | string
2013-03-31 05:55:08 -07:00
*/
2018-07-22 10:39:01 -07:00
public static function serialize ( $ArrayData , $mode = false )
2014-11-14 18:13:18 -08:00
{
2018-07-22 10:39:01 -07:00
return self :: getArrayStorage () -> serialize ( $ArrayData , $mode );
2013-03-31 05:55:08 -07:00
}
2018-09-03 14:35:03 -07:00
2013-03-31 05:55:08 -07:00
/**
* Returns an array from stored array data .
*
* @ param string $ArrayData
* @ return array stored data
*/
2018-09-03 14:35:03 -07:00
public static function unserialize ( $ArrayData )
2014-11-14 18:13:18 -08:00
{
if ( empty ( $ArrayData ))
{
2018-09-03 14:35:03 -07:00
return array ();
}
return self :: getArrayStorage () -> unserialize ( $ArrayData );
2013-03-31 05:55:08 -07:00
}
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' );
2020-12-19 09:50:29 -08:00
if ( $user === null )
2010-05-13 15:47:31 +00:00
{
$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
2016-05-07 20:23:26 -07:00
/**
* Retrieve front or admin Model .
* @ param string $type
* @ return object e_front_model or e_admin_model ;
*/
public static function getModel ( $type = 'front' )
{
if ( $type === 'front' )
{
return self :: getObject ( 'e_front_model' );
}
return self :: getObject ( 'e_admin_model' );
}
2010-05-02 18:41:20 +00:00
/**
* Retrieve user model object .
*
* @ param integer $user_id target user
2018-09-03 14:35:03 -07:00
* @ return e_user_extended_structure_tree
2010-05-02 18:41:20 +00:00
*/
public static function getUserStructure ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_user_extended_structure_tree' );
2010-05-02 18:41:20 +00:00
}
2009-11-10 23:13:30 +00:00
/**
* Retrieve User Extended handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e107_user_extended
2009-11-10 23:13:30 +00:00
*/
public static function getUserExt ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e107_user_extended' );
2009-11-10 23:13:30 +00:00
}
2010-05-05 15:05:32 +00:00
2010-05-02 18:41:20 +00:00
/**
* Retrieve User Perms ( admin perms ) handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e_userperms
2010-05-02 18:41:20 +00:00
*/
public static function getUserPerms ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_userperms' );
2010-05-02 18:41:20 +00:00
}
2009-12-02 16:51:04 +00:00
2010-03-13 18:59:28 +00:00
/**
* Retrieve online users handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e_ranks
2010-03-13 18:59:28 +00:00
*/
public static function getRank ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_ranks' );
2010-03-13 18:59:28 +00:00
}
2018-09-03 14:35:03 -07:00
2011-05-18 08:58:35 +00:00
/**
* Retrieve plugin handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e107plugin
2011-05-18 08:58:35 +00:00
*/
public static function getPlugin ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e107plugin' );
2011-05-18 08:58:35 +00:00
}
2017-02-03 20:18:45 -08:00
/**
* Retrieve plugin class singleton object
2018-09-03 14:35:03 -07:00
* @ return e_plugin
2017-02-03 20:18:45 -08:00
*/
public static function getPlug ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_plugin' );
2017-02-03 20:18:45 -08:00
}
2009-07-23 15:29:07 +00:00
/**
* Retrieve online users handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e_online
2009-07-23 15:29:07 +00:00
*/
public static function getOnline ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_online' );
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
2018-09-03 14:35:03 -07:00
* @ return e_chart
2013-05-14 23:46:48 -07:00
*/
public static function getChart ()
{
2020-12-19 09:50:29 -08:00
return self :: getObject ( 'e_chart' );
2013-05-14 23:46:48 -07:00
}
2009-11-04 03:07:44 +00:00
/**
* Retrieve comments handler singleton object
2018-09-03 14:35:03 -07:00
* @ return comment
2009-11-04 03:07:44 +00:00
*/
public static function getComment ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'comment' );
2009-11-04 03:07:44 +00:00
}
2010-03-16 13:04:23 +00:00
2017-01-24 19:53:40 -08:00
/**
* Retrieve comments handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e_customfields
2017-01-24 19:53:40 -08:00
*/
public static function getCustomFields ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_customfields' );
2017-01-24 19:53:40 -08:00
}
2010-03-14 02:11:23 +00:00
/**
* Retrieve Media handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e_media
2010-03-14 02:11:23 +00:00
*/
public static function getMedia ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_media' );
2010-03-14 02:11:23 +00:00
}
2018-09-03 14:35:03 -07:00
2012-12-03 01:40:47 -08:00
/**
* Retrieve Navigation Menu handler singleton object
2018-09-03 14:35:03 -07:00
* @ return e_navigation
2012-12-03 01:40:47 -08:00
*/
public static function getNav ()
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_navigation' );
2012-12-03 01:40:47 -08:00
}
2009-12-02 16:51:04 +00:00
2009-09-19 15:27:26 +00:00
/**
* Retrieve message handler singleton
2018-09-03 14:35:03 -07:00
* @ return eMessage
2009-09-19 15:27:26 +00:00
*/
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();
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'eMessage' );
2009-09-19 15:27:26 +00:00
}
2009-12-02 16:51:04 +00:00
2016-03-03 11:50:36 +01:00
/**
* Retrieve ajax singleton object
*
2020-06-13 13:18:37 -07:00
* @ return e_ajax
2016-03-03 11:50:36 +01:00
*/
2016-03-07 22:21:19 +01:00
public static function getAjax ()
2016-03-03 11:50:36 +01:00
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_ajax' );
2016-03-03 11:50:36 +01:00
}
2016-02-12 10:18:13 +01:00
/**
2016-02-13 15:33:23 -08:00
* Retrieve Library Manager singleton object ( internal use only . Use e107 :: library ())
2016-02-12 10:18:13 +01:00
*
2018-09-03 14:35:03 -07:00
* @ return e_library_manager
2016-02-12 10:18:13 +01:00
*/
2017-01-27 13:50:44 -08:00
public static function getLibrary ()
2016-02-12 10:18:13 +01:00
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_library_manager' );
2016-02-12 10:18:13 +01:00
}
/**
* Library Common Public Function .
*
2016-02-12 10:26:36 +01:00
* @ param string $action
* - 'detect' : Tries to detect a library and its installed version .
* - 'load' : Loads a library .
2020-12-02 13:17:23 -08:00
* - 'info' : Load library information array
* - 'preload' : Activate preloading of the library ( when detected ) using a < link rel = 'preload' ...> tag .
2016-02-12 10:18:13 +01:00
* @ param string $library
2016-02-12 10:26:36 +01:00
* The name of the library to detect / load .
2016-06-25 08:36:22 +02:00
* @ param string $variant
* ( Optional for 'load' ) The name of the variant to load . Note that only one variant of a library can be loaded
* within a single request . The variant that has been passed first is used ; different variant names in subsequent
* calls are ignored .
2016-02-12 10:26:36 +01:00
*
* @ return array | boolean
2016-02-12 14:50:13 +01:00
* - In case of 'detect' : An associative array containing registered information for the library specified by
* $name , or FALSE if the library $name is not registered .
* - In case of 'load' : An associative array of the library information .
2016-06-25 08:36:22 +02:00
* - In case of 'info' : An associative array containing registered information for all libraries , the registered
* information for the library specified by $name , or FALSE if the library $name is not registered .
2016-02-12 10:18:13 +01:00
*/
2021-10-11 12:33:59 -07:00
public static function library ( $action = '' , $library = null , $variant = null , $types = null )
2016-02-12 10:18:13 +01:00
{
2017-01-27 11:14:11 -08:00
$libraryHandler = self :: getLibrary ();
2016-02-12 10:18:13 +01:00
2021-10-11 12:33:59 -07:00
if ( empty ( $types ))
{
$types = array ( 'js' , 'css' );
}
2017-01-27 11:51:28 +01:00
switch ( $action )
2016-02-12 10:18:13 +01:00
{
case 'detect' :
2016-02-14 11:27:34 +01:00
return $libraryHandler -> detect ( $library );
2016-02-12 10:18:13 +01:00
break ;
case 'load' :
2017-01-27 11:14:11 -08:00
$cdn = ( bool ) self :: getPref ( 'e_jslib_cdn' , true );
2017-01-27 11:51:28 +01:00
$debug = ( bool ) deftrue ( 'e_DEBUG' );
2017-01-27 23:32:28 +01:00
$admin = ( bool ) defset ( 'e_ADMIN_AREA' , false );
2017-01-27 11:51:28 +01:00
// Try to detect and load CDN version.
2018-01-26 18:12:12 -08:00
if ( ! $admin && $cdn && strpos ( $library , 'cdn.' ) !== 0 )
2017-01-27 11:51:28 +01:00
{
$lib = $libraryHandler -> detect ( 'cdn.' . $library );
// If CDN version is available.
if ( $lib && ! empty ( $lib [ 'installed' ]))
{
// If a variant is specified, we need to check if it's installed.
if ( ! empty ( $variant ) && ! empty ( $lib [ 'variants' ][ $variant ][ 'installed' ]))
{
// Load CDN version with the variant.
2021-10-11 12:33:59 -07:00
return $libraryHandler -> load ( 'cdn.' . $library , $variant , $types );
2017-01-27 11:51:28 +01:00
}
// If CDN version is available, but no variant is specified,
// and debug mode is on, try to load 'debug' variant.
if ( empty ( $variant ) && $debug && ! empty ( $lib [ 'variants' ][ 'dev' ][ 'installed' ]))
{
// Load CDN version with 'debug' variant.
2021-10-11 12:33:59 -07:00
return $libraryHandler -> load ( 'cdn.' . $library , 'dev' , $types );
2017-01-27 11:51:28 +01:00
}
// Load CDN version without variant.
2021-10-11 12:33:59 -07:00
return $libraryHandler -> load ( 'cdn.' . $library , $variant , $types );
2017-01-27 11:51:28 +01:00
}
}
// If no variant is specified, and CDN version is not available, and debug mode is on.
if ( empty ( $variant ) && $debug )
{
$lib = $libraryHandler -> detect ( $library );
// If 'debug' variant is available.
if ( $lib && ! empty ( $lib [ 'variants' ][ 'dev' ][ 'installed' ]))
{
// Load library with 'debug' variant.
2021-10-11 12:33:59 -07:00
return $libraryHandler -> load ( $library , 'dev' , $types );
2017-01-27 11:51:28 +01:00
}
}
2021-10-11 12:33:59 -07:00
return $libraryHandler -> load ( $library , $variant , $types );
2016-02-12 10:18:13 +01:00
break ;
2016-06-20 11:12:25 +02:00
case 'info' :
2016-06-21 10:40:41 +02:00
return $libraryHandler -> info ( $library );
2016-06-20 11:12:25 +02:00
break ;
2021-02-11 08:51:02 -08:00
case 'files' :
$info = $libraryHandler -> info ( $library );
$ret = [];
2021-10-11 12:33:59 -07:00
foreach ( $types as $t )
2021-02-11 08:51:02 -08:00
{
2021-10-11 12:33:59 -07:00
if ( ! empty ( $info [ 'files' ][ $t ]))
2021-02-11 08:51:02 -08:00
{
2021-10-11 12:33:59 -07:00
foreach ( $info [ 'files' ][ $t ] as $path => $other )
{
$file = $info [ 'library_path' ] . '/' ;
$file .= ! empty ( $info [ 'path' ]) ? $info [ 'path' ] . '/' : '' ;
$file .= $path ;
$ret [ $t ][] = $file ;
}
2021-02-11 08:51:02 -08:00
}
}
2021-10-11 12:33:59 -07:00
2021-02-11 08:51:02 -08:00
return $ret ;
break ;
2020-12-02 13:17:23 -08:00
case 'preload' :
$info = $libraryHandler -> info ( $library );
if ( empty ( $info [ 'preload' ]))
{
return null ;
}
2020-12-03 08:22:51 -08:00
$tp = self :: getParser ();
2020-12-03 10:31:19 -08:00
$libraryPath = $info [ 'library_path' ] . '/' . $info [ 'path' ] . '/' ;
2020-12-02 13:17:23 -08:00
foreach ( $info [ 'preload' ] as $pre )
{
$linkArr = [
'rel' => 'preload' ,
'href' => $libraryPath . $pre [ 'path' ]
];
2021-01-24 15:33:39 -08:00
$browserCache = ! empty ( $pre [ 'browsercache' ]);
2020-12-02 13:17:23 -08:00
unset ( $pre [ 'path' ], $pre [ 'browsercache' ]);
$linkArr2 = array_merge ( $linkArr , $pre );
self :: link ( $linkArr2 , $browserCache );
}
break ;
2016-02-12 10:18:13 +01: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 ();
}
2017-01-03 11:02:09 -08:00
public static function set ( $type = null , $val = true )
{
if ( $type === 'js_enabled' )
{
self :: $_js_enabled = ( bool ) $val ;
}
if ( $type === 'css_enabled' )
{
self :: $_css_enabled = ( bool ) $val ;
}
}
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
2018-09-03 15:22:04 -07:00
* @ param string | array $data depends on the type - path / url or inline js source
2021-10-12 08:00:41 -07:00
* @ param string | array $parm parameters . BC string dependence : null | prototype | jquery OR array of parameters . tbd
2012-05-14 06:26:52 +00:00
* @ param integer $zone [ optional ] leave it null for default zone
*/
2021-10-12 08:00:41 -07:00
public static function js ( $type , $data , $parm = null , $zone = null , $pre = '' , $post = '' )
2012-05-14 06:26:52 +00:00
{
2017-01-03 11:02:09 -08:00
if ( self :: $_js_enabled === false )
{
return null ;
}
2017-01-27 11:14:11 -08:00
$jshandler = self :: getJs ();
2021-10-12 08:00:41 -07:00
if ( is_string ( $parm ))
{
$jshandler -> setDependency ( $parm );
$parm = null ;
}
2018-09-03 14:35:03 -07:00
switch ( $type )
2012-05-14 06:26:52 +00:00
{
2015-12-02 14:23:48 +01:00
case 'settings' :
$jshandler -> jsSettings ( $data );
break ;
2012-05-14 06:26:52 +00:00
case 'core' :
// data is e.g. 'core/tabs.js'
2020-12-19 09:50:29 -08:00
if ( $zone !== null )
{
$jshandler -> requireCoreLib ( $data , $zone );
}
else
{
$jshandler -> requireCoreLib ( $data );
}
2021-10-11 12:33:59 -07:00
2012-05-14 06:26:52 +00:00
break ;
2013-06-17 16:44:46 -07:00
2018-09-03 14:35:03 -07:00
case 'bootstrap' : //TODO Eventually add own method and render for bootstrap.
2020-12-19 09:50:29 -08:00
if ( $zone !== null )
{
$jshandler -> requireCoreLib ( 'bootstrap/js/' . $data , $zone );
}
else
{
$jshandler -> requireCoreLib ( 'bootstrap/js/' . $data );
}
2013-06-17 16:44:46 -07:00
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
case 'theme' :
// data is e.g. 'jslib/mytheme.js'
2020-12-19 09:50:29 -08:00
if ( $zone !== null )
{
$jshandler -> headerTheme ( $data , $zone , $pre , $post );
}
else
{
$jshandler -> footerTheme ( $data , 5 , $pre , $post );
}
2012-05-14 06:26:52 +00:00
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
case 'inline' :
// data is JS source (without script tags)
2020-12-19 09:50:29 -08:00
if ( $zone !== null )
{
$jshandler -> headerInline ( $data , $zone );
}
else
{
$jshandler -> headerInline ( $data );
}
2012-05-14 06:26:52 +00:00
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
case 'footer-inline' :
// data is JS source (without script tags)
2020-12-19 09:50:29 -08:00
if ( $zone !== null )
{
$jshandler -> footerInline ( $data , $zone );
}
else
{
$jshandler -> footerInline ( $data );
}
2012-05-14 06:26:52 +00:00
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
case 'url' :
// data is e.g. 'http://cdn.somesite.com/some.js'
2020-12-19 09:50:29 -08:00
if ( $zone !== null )
{
2021-10-12 08:00:41 -07:00
$jshandler -> headerFile ( $data , $zone , $pre , $post , $parm );
2020-12-19 09:50:29 -08:00
}
else
{
2021-10-12 08:00:41 -07:00
$jshandler -> headerFile ( $data , 5 , $pre , $post , $parm );
2020-12-19 09:50:29 -08:00
}
2021-10-11 12:33:59 -07:00
2012-05-14 06:26:52 +00:00
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
case 'footer' :
// data is e.g. '{e_PLUGIN}myplugin/jslib/myplug.js'
2020-12-19 09:50:29 -08:00
if ( $zone !== null )
{
2021-10-12 08:00:41 -07:00
$jshandler -> footerFile ( $data , $zone , $pre , $post , $parm );
2020-12-19 09:50:29 -08:00
}
else
{
2021-10-12 08:00:41 -07:00
$jshandler -> footerFile ( $data , 5 , $pre , $post , $parm );
2020-12-19 09:50:29 -08:00
}
2012-05-14 06:26:52 +00:00
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
// $type is plugin name
default :
// data is e.g. 'jslib/myplug.js'
2020-12-19 09:50:29 -08:00
if ( ! self :: isInstalled ( $type ))
{
return ;
}
if ( $zone !== null )
{
$jshandler -> requirePluginLib ( $type , $data , $zone );
}
else
{
$jshandler -> requirePluginLib ( $type , $data );
}
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
}
2015-03-09 15:05:34 -07:00
2016-02-09 15:57:07 -08:00
/**
* Add a < link > tag to the head of the html document .
2020-12-03 08:22:51 -08:00
* @ param array | string $attributes
* @ param bool $browserCache set to true to add the cacheId to the href . ( when an array is used )
2016-02-09 15:57:07 -08:00
* @ example e107 :: link ( array ( 'rel' => " dns-prefetch " , " href " => " http://example-domain.com/ " ));
2020-12-03 08:22:51 -08:00
* @ example e107 :: link ( 'rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin' );
2016-02-09 15:57:07 -08:00
*/
2020-12-03 08:22:51 -08:00
public static function link ( $attributes , $browserCache = false )
2016-02-09 15:57:07 -08:00
{
2020-12-02 13:17:23 -08:00
self :: getJs () -> addLink ( $attributes , $browserCache );
2016-02-09 15:57:07 -08:00
}
2021-07-14 12:18:42 -07:00
/**
* @ param string $type eg . 'active'
* @ param mixed $value eg . existing link - url value .
*/
public static function nav ( $type , $value = null )
{
if ( $value === null )
{
return e107 :: getRegistry ( 'core/e107/navigation/' . $type );
}
return e107 :: setRegistry ( 'core/e107/navigation/' . $type , $value );
}
2016-02-09 15:57:07 -08:00
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
2015-03-09 15:05:34 -07:00
* @ param null $dep
2012-05-14 06:26:52 +00:00
* @ 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 ] -->
2015-03-09 15:05:34 -07:00
* @ param null $dependence
2012-05-14 06:26:52 +00:00
*/
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
{
2018-01-26 18:12:12 -08:00
2019-02-22 14:56:47 -08:00
/* if (( strpos ( $data , 'bootstrap.css' ) !== false || strpos ( $data , 'bootstrap.min.css' ) !== false ) && ! defined ( " BOOTSTRAP " )) // detect bootstrap is enabled. - used in nextprev.sc and forum currently.
2013-03-14 04:05:33 -07:00
{
2018-09-03 14:35:03 -07:00
define ( " BOOTSTRAP " , true );
2019-02-22 14:56:47 -08:00
} */
2017-01-03 11:02:09 -08:00
if ( self :: $_css_enabled === false )
{
return null ;
}
2018-09-03 14:35:03 -07:00
2017-01-27 11:14:11 -08:00
$jshandler = self :: getJs ();
2012-05-15 09:55:27 +00:00
$jshandler -> setDependency ( $dep );
2017-01-31 16:39:00 -08:00
2017-01-31 16:58:46 -08:00
if ( strpos ( $data , 'http' ) === 0 )
2017-01-31 16:39:00 -08:00
{
$type = 'url' ;
}
2018-09-03 14:35:03 -07:00
switch ( $type )
2012-05-14 06:26:52 +00:00
{
case 'core' :
// data is path relative to e_FILE/jslib/
$jshandler -> coreCSS ( $data , $media , $preComment , $postComment );
break ;
2018-09-03 14:35:03 -07:00
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 );
2018-09-03 14:35:03 -07:00
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 ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
case 'inline' :
// data is CSS source (without style tags)
$jshandler -> inlineCSS ( $data , $media );
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
case 'url' :
// data is e.g. 'http://cdn.somesite.com/some.css'
$jshandler -> otherCSS ( $data , $media , $preComment , $postComment );
break ;
2018-09-03 14:35:03 -07:00
2012-05-14 06:26:52 +00:00
// $type is plugin name
default :
// data is e.g. 'css/myplug.css'
2020-12-19 09:50:29 -08: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
2016-03-26 10:14:57 -07:00
/**
* Throw log / info / warnings / errors to the Chrome / Firefox Console .
* @ param $name
* @ param null $var
* @ param string $type
*/
2016-03-29 14:55:38 -07:00
public static function debug ( $name , $var = null , $type = 'log' )
2016-03-26 10:14:57 -07:00
{
$nl = " \r \n " ;
// echo "alert('hi');";
2016-03-29 14:55:38 -07:00
$text = '' ;
2016-03-26 10:14:57 -07:00
switch ( $type ) {
case 'log' :
2016-03-29 14:55:38 -07:00
$text .= 'console.log("' . $name . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'info' :
2016-03-29 14:55:38 -07:00
$text .= 'console.info("' . $name . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'warning' :
2016-03-29 14:55:38 -07:00
$text .= 'console.warn("' . $name . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'error' :
2016-03-29 14:55:38 -07:00
$text .= 'console.error("' . $name . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
}
if ( ! empty ( $var ))
{
if ( is_object ( $var ) || is_array ( $var ))
{
$object = json_encode ( $var );
2016-03-29 14:55:38 -07:00
$text .= 'var object' . preg_replace ( '~[^A-Z|0-9]~i' , " _ " , $name ) . ' = \'' . str_replace ( " ' " , " \ ' " , $object ) . '\';' . $nl ;
$text .= 'var val' . preg_replace ( '~[^A-Z|0-9]~i' , " _ " , $name ) . ' = eval("(" + object' . preg_replace ( '~[^A-Z|0-9]~i' , " _ " , $name ) . ' + ")" );' . $nl ;
2016-03-26 10:14:57 -07:00
switch ( $type )
{
case 'log' :
2016-03-29 14:55:38 -07:00
$text .= 'console.debug(val' . preg_replace ( '~[^A-Z|0-9]~i' , " _ " , $name ) . ');' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'info' :
2016-03-29 14:55:38 -07:00
$text .= 'console.info(val' . preg_replace ( '~[^A-Z|0-9]~i' , " _ " , $name ) . ');' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'warning' :
2016-03-29 14:55:38 -07:00
$text .= 'console.warn(val' . preg_replace ( '~[^A-Z|0-9]~i' , " _ " , $name ) . ');' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'error' :
2016-03-29 14:55:38 -07:00
$text .= 'console.error(val' . preg_replace ( '~[^A-Z|0-9]~i' , " _ " , $name ) . ');' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
}
}
else
{
switch ( $type )
{
case 'log' :
2016-03-29 14:55:38 -07:00
$text .= 'console.debug("' . str_replace ( '"' , '\\"' , $var ) . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'info' :
2016-03-29 14:55:38 -07:00
$text .= 'console.info("' . str_replace ( '"' , '\\"' , $var ) . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'warning' :
2016-03-29 14:55:38 -07:00
$text .= 'console.warn("' . str_replace ( '"' , '\\"' , $var ) . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
case 'error' :
2016-03-29 14:55:38 -07:00
$text .= 'console.error("' . str_replace ( '"' , '\\"' , $var ) . '");' . $nl ;
2016-03-26 10:14:57 -07:00
break ;
}
}
}
2016-03-29 14:55:38 -07:00
2017-01-27 11:14:11 -08:00
self :: js ( 'footer-inline' , $text );
2016-03-26 10:14:57 -07: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
2018-09-03 14:35:03 -07:00
* @ return e_jshelper
2010-01-26 12:25:59 +00:00
*/
public static function getJshelper ( $singleton = false )
{
if ( $singleton )
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'e_jshelper' , true , ( $singleton === true ? '' : $singleton ));
2010-01-26 12:25:59 +00:00
}
2020-12-19 09:50:29 -08:00
return self :: getObject ( 'e_jshelper' );
2010-01-26 12:25:59 +00:00
}
2015-03-09 15:05:34 -07:00
2012-05-11 09:54:12 +00:00
/**
* @ see eResponse :: addMeta ()
2015-03-09 15:05:34 -07:00
* @ param null $name
* @ param null $content
* @ param array $extended
2012-05-11 09:54:12 +00:00
* @ return eResponse
*/
public static function meta ( $name = null , $content = null , $extended = array ())
{
2019-07-05 13:35:36 -07:00
/** @var eResponse $response */
2017-06-05 17:49:49 -07:00
$response = self :: getSingleton ( 'eResponse' );
2017-01-29 18:43:52 -08:00
if ( $name === 'description' )
2014-01-23 09:18:40 -08:00
{
2020-12-08 18:15:08 -08:00
$response -> addMetaDescription ( $content );
2014-01-23 09:18:40 -08:00
}
2018-09-03 14:35:03 -07:00
2017-01-29 18:43:52 -08:00
if ( $name === 'keywords' )
2014-01-23 09:18:40 -08:00
{
2020-12-08 18:15:08 -08:00
$response -> addMetaKeywords ( $content );
2014-01-23 09:18:40 -08:00
}
2017-06-05 17:49:49 -07:00
return $response -> addMeta ( $name , $content , $extended );
2020-12-08 18:15:08 -08:00
}
/**
* Set the Page Title ie . < title > Whatever </ title >
* @ param string $title
*/
public static function title ( $title )
{
/** @var eResponse $response */
$response = self :: getSingleton ( 'eResponse' );
$response -> addMetaTitle ( $title , true );
2012-05-11 09:54:12 +00:00
}
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
2021-01-16 08:43:51 -08:00
* *
2013-02-14 15:37:42 +02:00
* @ 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
2019-03-04 12:41:10 -08:00
* @ param mixed $param [ optional ] construct () param
2015-03-09 15:05:34 -07:00
* @ return object
2013-02-14 15:37:42 +02:00
*/
public static function getAddon ( $pluginName , $addonName , $className = true )
{
$filename = $addonName ; // e.g. 'e_cron';
2018-09-03 14:35:03 -07:00
2021-01-16 08:43:51 -08:00
2020-12-19 09:50:29 -08:00
if ( $className === true )
{
$className = $pluginName . '_' . substr ( $addonName , 2 );
} // remove 'e_'
2009-12-02 16:51:04 +00:00
2016-01-12 15:44:54 -08:00
$elist = self :: getPref ( $filename . '_list' );
2017-01-29 18:43:52 -08:00
if ( $filename === 'e_menu' )
2016-01-12 15:44:54 -08:00
{
2020-12-19 09:50:29 -08:00
if ( ! in_array ( $pluginName , $elist ))
{
return null ;
}
2016-01-12 15:44:54 -08:00
}
2020-12-19 09:50:29 -08:00
elseif ( ! isset ( $elist [ $pluginName ]))
2016-01-12 15:44:54 -08:00
{
2020-12-19 09:50:29 -08:00
return null ;
2016-01-12 15:44:54 -08:00
}
2018-09-03 14:35:03 -07:00
2013-02-14 15:37:42 +02:00
$path = e_PLUGIN . $pluginName . '/' . $filename . '.php' ;
// e.g. include e_module, e_meta etc
2020-12-19 09:50:29 -08:00
if ( $className === false )
{
return include_once ( $path );
}
2013-02-14 15:37:42 +02:00
if ( ! class_exists ( $className , false ))
{
include_once ( $path );
}
2018-09-03 14:35:03 -07:00
2013-02-14 15:37:42 +02:00
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 )
2014-10-14 02:09:53 -07:00
* @ param string $methodName [ optional ] ( if different from 'config' )
2015-03-09 15:05:34 -07:00
* @ return array
2009-11-20 05:01:51 +00:00
*/
2015-12-12 00:16:16 -08:00
public static function getAddonConfig ( $addonName , $className = '' , $methodName = 'config' , $param = null , $param2 = null )
2009-11-20 05:01:51 +00:00
{
2009-11-20 23:27:25 +00:00
$new_addon = array ();
2015-03-09 15:05:34 -07:00
2017-01-27 11:14:11 -08:00
$sql = self :: 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' );
2018-09-03 14:35:03 -07:00
2016-04-06 19:43:31 -07:00
if ( ! empty ( $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 ;
2015-12-12 00:16:16 -08:00
$array = self :: callMethod ( $class_name , $methodName , $param , $param2 );
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
2014-10-22 13:26:03 -07:00
2009-11-20 05:01:51 +00:00
/**
2009-12-02 16:51:04 +00:00
* Safe way to call user methods .
2015-03-09 15:05:34 -07:00
* @ param string | object $class_name
2009-11-20 23:27:25 +00:00
* @ param string $method_name
2015-12-12 00:16:16 -08:00
* @ param mixed $param - 1 st parameter sent to method
* @ param mixed $param2 - 2 nd parameter sent to method
2015-03-09 15:05:34 -07:00
* @ return array | bool FALSE
2009-11-20 05:01:51 +00:00
*/
2015-12-12 00:16:16 -08:00
public static function callMethod ( $class_name , $method_name , $param = null , $param2 = null )
2009-11-20 05:01:51 +00:00
{
2017-01-27 11:14:11 -08:00
$mes = self :: getMessage ();
2009-11-20 05:01:51 +00:00
2014-10-22 13:26:03 -07:00
if ( is_object ( $class_name ) || class_exists ( $class_name ))
2009-11-20 05:01:51 +00:00
{
2018-09-03 14:35:03 -07:00
2014-10-22 13:26:03 -07:00
if ( is_object ( $class_name ))
{
$obj = $class_name ;
$class_name = get_class ( $obj );
}
2018-09-03 14:35:03 -07:00
else
2014-10-22 13:26:03 -07:00
{
2018-09-03 14:35:03 -07:00
$obj = new $class_name ;
2014-10-22 13:26:03 -07:00
}
2018-09-03 14:35:03 -07:00
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 )
{
2016-04-06 19:43:31 -07:00
//$debug_backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
2015-03-09 15:05:34 -07:00
$mes -> addDebug ( 'Executing <strong>' . $class_name . ' :: ' . $method_name . '()</strong>' );
2013-03-08 02:19:18 -08:00
}
2020-12-10 15:52:48 -08:00
return $obj -> $method_name ( $param , $param2 );
2009-12-02 16:51:04 +00:00
}
2020-12-10 15:52:48 -08:00
2009-11-20 05:01:51 +00:00
}
return FALSE ;
}
2009-11-20 23:27:25 +00:00
2017-03-27 10:38:51 -07:00
/**
* Retrieves the e_url config - new v2 . 1.6
2017-04-10 13:28:06 -07:00
* @ param string $mode config | alias | profile
2017-03-27 10:38:51 -07:00
* @ return array
*/
public static function getUrlConfig ( $mode = 'config' )
{
$new_addon = array ();
$filename = 'e_url' ;
$elist = self :: getPref ( $filename . '_list' );
$className = substr ( $filename , 2 ); // remove 'e_'
$methodName = 'config' ;
2020-12-19 09:50:29 -08:00
$url_profiles = self :: getPref ( 'url_profiles' );
2017-03-27 10:38:51 -07:00
if ( ! empty ( $elist ))
{
foreach ( array_keys ( $elist ) as $key )
{
if ( is_readable ( e_PLUGIN . $key . '/' . $filename . '.php' ))
{
2017-04-10 13:28:06 -07:00
2017-03-27 10:38:51 -07:00
include_once ( e_PLUGIN . $key . '/' . $filename . '.php' );
$class_name = $key . '_' . $className ;
if ( is_object ( $class_name ))
{
$obj = $class_name ;
$class_name = get_class ( $obj );
}
2018-10-29 12:57:35 -07:00
elseif ( class_exists ( $class_name ))
2017-03-27 10:38:51 -07:00
{
$obj = new $class_name ;
}
2018-10-29 12:57:35 -07:00
else
{
2020-01-27 12:13:02 -08:00
continue ;
2018-10-29 12:57:35 -07:00
}
2017-03-27 10:38:51 -07:00
if ( $mode === 'alias' )
{
if ( ! empty ( $obj -> alias ))
{
$new_addon [ $key ] = $obj -> alias ;
}
continue ;
}
2017-04-10 13:28:06 -07:00
if ( $mode === 'profiles' )
{
if ( ! empty ( $obj -> profiles ))
{
$new_addon [ $key ] = $obj -> profiles ;
}
continue ;
}
2017-04-14 11:55:41 -07:00
if ( $mode === 'generate' )
{
if ( ! empty ( $obj -> generate ))
{
$new_addon [ $key ] = $obj -> generate ;
}
continue ;
}
2017-04-10 13:28:06 -07:00
$profile = ! empty ( $url_profiles [ $key ]) ? $url_profiles [ $key ] : null ;
2017-03-27 10:38:51 -07:00
$array = self :: callMethod ( $obj , $methodName , $profile );
2021-02-17 14:33:35 -08:00
if ( $mode === 'route' && ! empty ( $array ))
{
foreach ( $array as $k => $v )
{
if ( empty ( $v [ 'alias' ]) && ! empty ( $obj -> alias ))
{
$v [ 'alias' ] = $obj -> alias ;
}
$new_addon [ $key . '/' . $k ] = $v ;
}
continue ;
}
2017-03-27 10:38:51 -07:00
if ( $array )
{
foreach ( $array as $k => $v )
{
if ( empty ( $v [ 'alias' ]) && ! empty ( $obj -> alias ))
{
$v [ 'alias' ] = $obj -> alias ;
}
$new_addon [ $key ][ $k ] = $v ;
}
}
}
}
}
return $new_addon ;
}
2014-10-22 13:26:03 -07: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 = '' )
{
2009-12-02 16:51:04 +00:00
2020-12-19 09:50:29 -08:00
if ( $for === true )
2009-11-28 15:34:46 +00:00
{
$for = e_ADMIN_AREA ? 'admin' : 'front' ;
}
switch ( $for )
{
case 'admin' :
2017-01-27 11:14:11 -08:00
$for = self :: getPref ( 'admintheme' );
2009-11-28 15:34:46 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-11-28 15:34:46 +00:00
case 'front' :
2016-09-19 13:39:26 -07:00
if ( defined ( 'USERTHEME' ) && USERTHEME !== false )
{
$for = USERTHEME ;
}
else
{
2018-06-14 17:03:03 -07:00
$user_pref = self :: getUser () -> getPref ();
$for = ! empty ( $user_pref [ 'sitetheme' ]) ? $user_pref [ 'sitetheme' ] : self :: getPref ( 'sitetheme' );
2016-09-19 13:39:26 -07:00
}
2009-11-28 15:34:46 +00:00
break ;
}
2020-12-19 09:50:29 -08:00
if ( ! $path )
{
return $for ;
}
2009-11-28 15:34:46 +00:00
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 ;
}
2021-01-24 10:44:30 -08:00
/**
* Load admin icons template and define their constants
2021-01-24 15:33:39 -08:00
* @ return array ;
2021-01-24 10:44:30 -08:00
*/
public static function loadAdminIcons ()
{
2021-01-24 15:33:39 -08:00
$regID = 'core/e107/templates/admin_icons' ;
2021-01-24 10:44:30 -08:00
2021-01-24 15:33:39 -08:00
if ( $temp = self :: getRegistry ( $regID ))
2021-01-24 10:44:30 -08:00
{
2021-01-24 15:33:39 -08:00
return $temp ;
2021-01-24 10:44:30 -08:00
}
$ADMIN_ICONS_TEMPLATE = self :: getCoreTemplate ( 'admin_icons' , null , false );
2021-01-26 19:06:09 -08:00
if ( self :: getPref ( 'admincss' ) === 'css/kadmin.css' )
2021-01-24 10:44:30 -08:00
{
2021-01-27 14:34:02 -08:00
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_INSTALLPLUGIN_ICON' ] = " <i class='fa fa-cog fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_UNINSTALLPLUGIN_ICON' ] = " <i class='fa fa-times fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_UPGRADEPLUGIN_ICON' ] = " <i class='fa fa-caret-up fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_REPAIRPLUGIN_ICON' ] = " <i class='fa fa-wrench fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_CONFIGURE_ICON' ] = " <i class='fa fa-cog fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_EDIT_ICON' ] = " <i class='fa fa-edit fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_DELETE_ICON' ] = " <i class='fa fa-trash fa-2x fa-fw text-danger'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_EXECUTE_ICON' ] = " <i class='fa fa-power-off fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_SORT_ICON' ] = " <i class='fa fa-sort fa-2x fa-fw'></i> " ;
$ADMIN_ICONS_TEMPLATE [ 'ADMIN_PAGES_ICON' ] = " <i class='fa fa-file-text-o fa-2x fa-fw'></i> " ;
2021-01-24 10:44:30 -08:00
}
foreach ( $ADMIN_ICONS_TEMPLATE as $def => $val )
{
define ( $def , $val );
}
2021-01-24 15:33:39 -08:00
self :: setRegistry ( $regID , $ADMIN_ICONS_TEMPLATE );
return $ADMIN_ICONS_TEMPLATE ;
2021-01-24 10:44:30 -08:00
}
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 )
{
2014-03-14 17:25:40 -07:00
$id = str_replace ( '..' , '' , $id ); //simple security, '/' is allowed
$curTheme = self :: getThemeInfo ( $override , 'rel' );
2018-09-03 14:35:03 -07:00
$override_path = $override ? $curTheme . 'templates/' . $id . '_template.php' : null ;
$legacy_override_path = $override ? $curTheme . $id . '_template.php' : null ;
2014-03-14 17:25:40 -07:00
2020-05-08 14:34:34 -07:00
$core_path = e_CORE . 'templates/' . $id . '_template.php' ; // default
$core_path_legacy = e_CORE . 'templates/legacy/' . $id . '_template.php' ;
$core_path_bs4 = e_CORE . 'templates/bootstrap4/' . $id . '_template.php' ;
2020-12-30 07:16:18 -08:00
$core_path_bs5 = e_CORE . 'templates/bootstrap5/' . $id . '_template.php' ;
2018-09-03 14:35:03 -07:00
2020-12-31 11:46:53 -08:00
$ret = $core_path ;
2018-09-03 14:35:03 -07:00
if ( $override_path && is_readable ( $override_path )) // v2 override template.
2014-03-14 17:25:40 -07:00
{
2020-12-31 11:46:53 -08:00
$ret = $override_path ;
2014-03-14 17:25:40 -07:00
}
2018-09-03 14:35:03 -07:00
elseif ( $legacy_override_path && is_readable ( $legacy_override_path )) //v1 override template.
2012-12-11 15:08:29 -08:00
{
2020-12-31 11:46:53 -08:00
$ret = $legacy_override_path ;
2012-12-11 15:08:29 -08:00
}
2021-01-05 10:04:26 -08:00
elseif ( deftrue ( 'THEME_LEGACY' ) && is_readable ( $core_path_legacy )) //v1 core template.
2012-12-11 15:08:29 -08:00
{
2020-12-31 11:46:53 -08:00
$ret = $core_path_legacy ;
2012-12-11 15:08:29 -08:00
}
2020-12-31 11:46:53 -08:00
elseif ( defset ( 'BOOTSTRAP' ) > 3 )
2020-12-30 07:16:18 -08:00
{
2020-12-31 11:46:53 -08:00
if ( is_readable ( $core_path_bs5 ))
{
$ret = $core_path_bs5 ;
}
elseif ( is_readable ( $core_path_bs4 ))
{
$ret = $core_path_bs4 ;
}
2020-12-30 07:16:18 -08:00
}
2009-12-02 16:51:04 +00:00
2020-12-31 11:46:53 -08:00
return $ret ;
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
2018-09-03 14:35:03 -07:00
* @ param mixed $override see { @ link getThemeInfo ()} true / false , front or admin .
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 );
2018-01-18 16:19:40 -08:00
2018-09-03 14:35:03 -07:00
### Attempt to fix merge issues; in case we override - template array not found in theme,
2013-10-16 18:46:41 +03:00
### 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
}
2018-09-03 14:35:03 -07:00
2018-01-18 16:19:40 -08: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
}
2018-09-03 14:35:03 -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 );
2014-11-04 22:47:24 +02:00
// Introducing noWrapper when merging
$ret_core = self :: _getTemplate ( $id , $key , $reg_path , $path , $info , true );
2018-01-18 16:19:40 -08: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 :
2019-05-04 14:50:02 -07:00
* - e107_themes / { current_frontend_theme } / templates / user_template . php ( if $override is true ) - this is the default .
* - e107_core / templates / user_template . php ( if override not found or $override is false )
2009-07-22 14:32:51 +00:00
* - $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
2021-01-22 15:43:57 -08:00
* @ param string | null $key $YOURTEMPLATE_TEMPLATE [ $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
2020-12-29 12:43:25 -08:00
* @ return array
2009-07-22 14:32:51 +00:00
*/
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
{
2020-01-18 11:00:18 +01:00
if ( ! $plug_name )
2010-02-27 19:05:07 +00:00
{
return self :: getCoreTemplate ( $id , $key , $override , $merge , $info );
}
2021-01-22 15:43:57 -08:00
2020-12-19 09:50:29 -08:00
if ( $id == null || $id === true ) // 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 ;
}
2021-01-22 15:43:57 -08:00
2021-01-22 13:44:10 -08:00
$reg_path = 'plugin/' . $plug_name . '/templates/' . $id ;
$reg_path .= ( $override ) ? '/ext' : '' ;
2009-11-28 15:34:46 +00:00
$path = self :: templatePath ( $plug_name , $id , $override );
2018-09-03 14:35:03 -07:00
2013-06-22 18:24:43 -07:00
if ( ADMIN && E107_DBG_INCLUDES )
{
2017-01-27 11:14:11 -08:00
self :: getMessage () -> addDebug ( " Attempting to load Template File: " . $path );
2013-06-22 18:24:43 -07:00
}
2018-09-03 14:35:03 -07:00
2020-01-18 11:55:13 +01:00
/**
* " front " and " global " LANs might not be loaded come self :: _getTemplate (),
* so the following calls to self :: plugLan () fix that .
*/
2021-01-16 08:43:51 -08:00
self :: _loadPluginLans ( $plug_name );
2020-01-18 11:55:13 +01:00
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 );
2018-01-18 16:19:40 -08:00
if ( $merge === false || $override === false )
2009-12-09 18:33:43 +00:00
{
2020-12-29 12:43:25 -08:00
return ( $ret === false ) ? array () : $ret ;
2009-12-09 18:33:43 +00:00
}
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 );
2018-01-18 16:19:40 -08:00
2009-12-09 18:33:43 +00:00
$id = str_replace ( '/' , '_' , $id );
2014-11-04 22:47:24 +02:00
// Introduced noWrapper when merging
$ret_plug = self :: _getTemplate ( $id , $key , $reg_path , $path , $info , true );
2010-02-09 20:43:54 +00:00
2018-01-18 16:19:40 -08:00
if ( $merge === true && $key !== null && $ret === false ) // key not set, so send 'core' version instead.
{
return $ret_plug ;
}
if ( $ret === false )
{
2020-12-29 12:43:25 -08:00
return array ();
2018-01-18 16:19:40 -08: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
}
2018-09-03 14:35:03 -07: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
2018-09-03 14:35:03 -07:00
* @ param string $scName [ optional ] shortcode name - if provided , wrapper ( string ) for the corresponding code will be returned
2013-04-28 19:14:14 +03:00
* @ return array | string
*/
public static function templateWrapper ( $templateId , $scName = null )
{
2020-12-19 09:50:29 -08:00
if ( ! $templateId )
{
return array ();
}
2018-09-03 14:35:03 -07:00
2021-01-01 10:45:26 -08:00
if ( strpos ( $templateId , '/' ) !== false )
{
list ( $templateId , $templateKey ) = explode ( '/' , $templateId , 2 );
}
else
{
$templateKey = '' ;
}
2018-09-03 14:35:03 -07:00
2013-04-28 19:14:14 +03:00
$wrapperRegPath = 'templates/wrapper/' . $templateId ;
2015-08-22 00:17:07 -07:00
2013-04-28 19:14:14 +03:00
$wrapper = self :: getRegistry ( $wrapperRegPath );
2015-08-22 00:17:07 -07:00
2020-12-19 09:50:29 -08:00
if ( empty ( $wrapper ) || ! is_array ( $wrapper ))
{
$wrapper = array ();
}
2015-08-22 00:17:07 -07:00
if ( strpos ( $templateKey , '/' ) !== false ) // quick fix support for 3 keys eg. news/view/item
{
list ( $templateKey , $templateKey2 ) = explode ( " / " , $templateKey , 2 );
if ( $templateKey && $templateKey2 )
{
$wrapper = ( isset ( $wrapper [ $templateKey ][ $templateKey2 ]) ? $wrapper [ $templateKey ][ $templateKey2 ] : array ());
}
}
else // support for 2 keys. eg. contact/form
2020-12-19 09:50:29 -08:00
if ( $templateKey )
{
$wrapper = ( isset ( $wrapper [ $templateKey ]) ? $wrapper [ $templateKey ] : array ());
}
2015-08-22 00:17:07 -07:00
2020-12-19 09:50:29 -08:00
if ( $scName !== null )
2013-04-28 19:14:14 +03:00
{
$scName = strtoupper ( $scName );
return isset ( $wrapper [ $scName ]) ? $wrapper [ $scName ] : '' ;
}
2015-08-22 00:17:07 -07:00
2013-04-28 19:14:14 +03:00
return $wrapper ;
}
2018-09-03 14:35:03 -07:00
2013-04-28 19:14:14 +03:00
/**
* 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' );
2020-12-19 09:50:29 -08:00
if ( ! is_array ( $_sc_style ))
{
$_sc_style = array ();
}
2013-04-28 19:14:14 +03:00
if ( is_array ( $set ) && ! empty ( $set ))
{
self :: setRegistry ( 'shortcodes/sc_style' , array_merge ( $_sc_style , $set ));
}
2018-09-03 14:35:03 -07:00
2013-04-28 19:14:14 +03:00
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
*/
2020-11-27 17:00:32 +01:00
public static function getTemplateInfo ( $plug_name , $id , $key = null , $override = true , $merge = false )
2009-12-12 16:40:41 +00:00
{
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' ))
2015-03-09 15:05:34 -07:00
*
*
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
2015-03-09 15:05:34 -07:00
* @ param string $filter_mask
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
{
2021-01-16 08:43:51 -08:00
self :: _loadPluginLans ( $plugin_name );
2009-11-28 15:34:46 +00:00
$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 ;
}
}
2020-12-19 09:50:29 -08:00
if ( ! $match )
{
continue ;
}
2009-11-28 15:34:46 +00:00
}
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
}
2021-01-16 08:43:51 -08:00
$templates [ $key ] = implode ( ' ' , array_map ( 'ucfirst' , explode ( '_' , $key )));
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
2014-11-04 22:47:24 +02:00
* @ param boolean $noWrapper
2009-07-22 14:32:51 +00:00
* @ return string | array
*/
2014-11-04 22:47:24 +02:00
public static function _getTemplate ( $id , $key , $reg_path , $path , $info = false , $noWrapper = 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' ;
2018-09-03 14:35:03 -07:00
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 ;
2015-03-09 15:05:34 -07:00
2018-09-03 14:35:03 -07:00
// Use: list($pre,$post) = explode("{---}",$text,2);
$tp = self :: getParser (); // BC FIx - avoid breaking old templates due to missing globals.
2010-02-09 20:43:54 +00:00
2020-12-19 09:50:29 -08:00
if ( self :: getRegistry ( $regPath ) === null )
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 ()));
2018-09-03 14:35:03 -07:00
2013-04-28 19:14:14 +03:00
// sc_style not a global anymore and uppercase
2014-11-04 22:47:24 +02:00
// Fix template merge issue - no-wrapper sent to avoid sc wrappers confusions
if ( ! $noWrapper )
{
if ( isset ( $SC_WRAPPER ))
{
2016-04-05 13:15:58 -07:00
if ( E107_DBG_BBSC )
{
2021-01-03 11:01:54 -08:00
self :: getMessage () -> addDebug ( " Found deprecated \$ SC_WRAPPER: " . print_a ( $SC_WRAPPER , true ));
2016-04-05 13:15:58 -07:00
}
2014-11-04 22:47:24 +02:00
self :: scStyle ( $SC_WRAPPER );
}
// ID_WRAPPER support
if ( isset ( $$wrapper ) && ! empty ( $$wrapper ) && is_array ( $$wrapper ))
{
2016-04-05 13:15:58 -07:00
if ( E107_DBG_BBSC )
{
2017-01-27 11:14:11 -08:00
self :: getMessage () -> addDebug ( " Found ID wrapper: " . $wrapper );
2016-04-05 13:15:58 -07:00
}
2014-11-04 22:47:24 +02:00
self :: setRegistry ( $wrapperRegPath , $$wrapper );
}
}
2009-07-22 14:32:51 +00:00
}
2020-12-19 09:50:29 -08:00
if ( self :: getRegistry ( $regPathInfo ) === null )
2009-12-12 16:40:41 +00:00
{
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 ));
2018-01-18 16:19:40 -08:00
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
}
2018-09-03 14:35:03 -07:00
2021-01-22 15:43:57 -08:00
return ( $ret && is_array ( $ret ) && isset ( $ret [ $key ])) ? $ret [ $key ] : false ;
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 ()
2017-01-23 09:41:23 -08:00
* @ outdated use e107 :: lan () or e107 :: coreLan (), e107 :: plugLan (), e107 :: themeLan ()
2009-07-22 14:32:51 +00:00
* @ 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 ))
{
2020-12-27 09:48:02 -08:00
if (( e_LANGUAGE === 'English' ) || self :: getPref ( 'noLanguageSubs' ))
2009-07-22 14:32:51 +00:00
{
2015-03-09 15:05:34 -07:00
return false ;
2009-07-22 14:32:51 +00:00
}
2018-09-03 14:35:03 -07:00
2019-01-17 15:37:53 +01:00
self :: getDebug () -> log ( " Couldn't load language file: " . $path );
2017-01-16 16:14:49 -08:00
2014-02-05 06:14:13 -08:00
$path = str_replace ( e_LANGUAGE , 'English' , $path );
2017-01-16 16:14:49 -08:00
2019-01-17 15:37:53 +01:00
self :: getDebug () -> log ( " Attempts to load default language file: " . $path );
2017-01-16 16:14:49 -08:00
2014-02-07 05:07:49 -08:00
if ( ! is_readable ( $path ))
{
2019-01-17 15:37:53 +01:00
self :: getDebug () -> log ( " Couldn't load default language file: " . $path );
2015-03-09 15:05:34 -07:00
return false ;
2014-02-07 05:07:49 -08:00
}
2009-07-22 14:32:51 +00:00
}
2018-09-03 14:35:03 -07:00
2014-02-07 17:57:55 -08:00
$adminLanguage = self :: getPref ( 'adminlanguage' );
2018-09-03 14:35:03 -07:00
2014-02-07 17:57:55 -08:00
if ( e_ADMIN_AREA && vartrue ( $adminLanguage ))
{
2018-09-03 14:35:03 -07:00
$path = str_replace ( e_LANGUAGE , $adminLanguage , $path );
2014-02-07 17:57:55 -08:00
}
2018-09-03 14:35:03 -07: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
2017-01-27 11:14:11 -08:00
* self :: coreLan ( 'banlist' , true );
2011-05-03 22:13:59 +00:00
* </ code >
*
* @ param string $fname filename without the extension part ( e . g . 'comment' )
* @ param boolean $admin true if it ' s an administration language file
2020-12-10 15:52:48 -08:00
* @ return bool | null
2011-05-03 22:13:59 +00:00
*/
public static function coreLan ( $fname , $admin = false )
{
2020-01-17 17:11:26 +01:00
if ( $admin )
{
2020-12-19 09:50:29 -08:00
self :: includeLan ( e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_admin.php' );
2020-01-17 17:11:26 +01:00
}
2021-01-18 19:04:55 -08:00
$cstring = 'core/e107/corelan/' . e_LANGUAGE . '_' . $fname . ( $admin ? '_admin' : '_front' );
2020-12-19 09:50:29 -08:00
if ( self :: getRegistry ( $cstring ))
{
return null ;
}
2011-05-03 22:13:59 +00:00
2020-12-14 16:21:48 -08: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 ;
2017-01-27 11:14:11 -08:00
self :: setRegistry ( $cstring , true );
2017-12-16 12:25:18 -08:00
2020-12-19 09:50:29 -08:00
return self :: includeLan ( $path );
2011-05-03 22:13:59 +00:00
}
/**
* Simplify importing of plugin Language files ( following e107 plugin structure standards ) .
* All inputs are sanitized .
*
* Examples :
2021-01-07 09:42:19 -08:00
* @ example
2011-05-03 22:13:59 +00:00
* < 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' );
2018-09-03 14:35:03 -07:00
*
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
*
2021-01-07 13:24:55 -08:00
* // import defeinitions from /e107_plugins/myplug/languages/[CurrentLanguage].php // FOR BC only.
* e107 :: plugLan ( 'myplug' , null );
*
2021-01-07 09:42:19 -08:00
* // import defeinitions from /e107_plugins/myplug/languages/[CurrentLanguage]/[CurrentLanguage]_front.php
* e107 :: plugLan ( 'myplug' , 'front' , true );
*
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
2021-01-22 13:44:10 -08:00
* @ param string | bool | null $fname filename without the extension part ( e . g . 'common' )
2011-05-03 22:13:59 +00:00
* @ param boolean $flat false ( default , preferred ) Language folder structure ; true - prepend Language to file name
2021-01-22 13:44:10 -08:00
* @ param boolean $return When true , returns the path , but does not include the file or set the registry .
2020-12-10 15:52:48 -08:00
* @ return bool | null
2011-05-03 22:13:59 +00:00
*/
2021-01-22 13:44:10 -08:00
public static function plugLan ( $plugin , $fname = '' , $flat = false , $returnPath = false )
2011-05-03 22:13:59 +00:00
{
2021-01-18 19:04:55 -08:00
// $cstring = 'pluglan/'.e_LANGUAGE.'_'.$plugin.'_'.$fname.($flat ? '_1' : '_0');
2021-01-22 13:44:10 -08:00
$cstring = 'core/e107/pluglan/' . $plugin . '/' . e_LANGUAGE . '/' ;
$cstring .= ( $fname === null ) ? 'null' : '' ;
$cstring .= ( $fname === true ) ? 'true' : '' ;
$cstring .= is_string ( $fname ) ? $fname : '' ;
$cstring .= ( $flat ) ? '/flat' : '/noflat' ;
if ( self :: getRegistry ( $cstring ) && ( $returnPath === false ))
2020-12-19 09:50:29 -08:00
{
return null ;
}
2011-05-03 22:13:59 +00:00
2020-12-14 16:21:48 -08:00
$plugin = preg_replace ( '/[\W]/' , '' , $plugin );
2011-05-03 22:13:59 +00:00
2017-12-16 12:25:18 -08:00
if ( $fname === 'global' ) // fix ambiguity
{
$fname = e_LANGUAGE . " _global " ;
}
elseif ( $fname && is_string ( $fname ))
2012-11-29 22:03:36 -08:00
{
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
}
2018-09-03 14:35:03 -07:00
elseif ( $fname === true ) // admin file.
2012-11-29 22:03:36 -08:00
{
2013-05-26 15:55:14 -07:00
$fname = e_LANGUAGE . " _admin " ;
2012-11-29 22:03:36 -08:00
}
2021-01-08 09:56:33 -08:00
elseif ( $fname === null ) // BC usage. English.php
2021-01-07 13:24:55 -08:00
{
$fname = e_LANGUAGE ;
}
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
2017-12-13 20:28:07 +01:00
if ( $flat === true ) // support for alt_auth/languages/English/English_log.php etc.
2012-12-12 18:46:34 -08:00
{
2018-09-03 14:35:03 -07:00
$path = e_PLUGIN . $plugin . '/languages/' . e_LANGUAGE . '/' . $fname . '.php' ;
}
2012-12-12 18:46:34 -08:00
else
{
2018-09-03 14:35:03 -07:00
$path = e_PLUGIN . $plugin . '/languages/' . $fname . '.php' ;
2012-12-12 18:46:34 -08:00
}
2018-09-03 14:35:03 -07:00
2021-01-22 13:44:10 -08:00
if ( $returnPath === true )
{
return $path ;
}
2016-02-12 19:28:35 -08:00
if ( deftrue ( 'E107_DBG_INCLUDES' ))
2012-12-12 22:39:18 -08:00
{
2020-11-02 10:30:41 -08:00
$adminLanguage = self :: getPref ( 'adminlanguage' );
if ( e_ADMIN_AREA && ! empty ( $adminLanguage ))
{
$path = str_replace ( e_LANGUAGE , $adminLanguage , $path );
}
2017-01-27 11:14:11 -08:00
self :: getMessage () -> addDebug ( " Attempting to Load: " . $path );
2018-09-03 14:35:03 -07:00
}
2021-01-22 13:44:10 -08:00
self :: setRegistry ( $cstring , true );
2017-12-16 12:25:18 -08:00
2021-01-08 09:56:33 -08:00
$ret = self :: includeLan ( $path );
2021-01-16 08:43:51 -08:00
2021-02-02 19:18:44 -08:00
if (( $ret === false ) && deftrue ( 'E107_DBG_INCLUDES' ) && strpos ( $path , '_global.php' ) === false )
2021-01-08 09:56:33 -08:00
{
2021-01-09 09:09:12 -08:00
$result = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 4 );
2021-01-14 07:54:16 -08:00
self :: getDebug () -> log ( " Couldn't load: " . $path . print_a ( $result , true ));
2021-01-08 09:56:33 -08:00
}
return $ret ;
2011-05-03 22:13:59 +00:00
}
2018-09-03 14:35:03 -07:00
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' );
2018-09-03 14:35:03 -07:00
*
2011-11-29 12:11:27 +00:00
* // 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
2020-12-10 15:52:48 -08:00
* @ return bool | null
2011-11-29 12:11:27 +00:00
*/
public static function themeLan ( $fname = '' , $theme = null , $flat = false )
{
2020-12-19 09:50:29 -08:00
if ( $theme === null )
{
$theme = THEME . 'languages/' ;
}
else
{
2021-02-20 12:15:28 -08:00
$theme = e_THEME . filter_var ( $theme ) . '/languages/' ;
2020-12-19 09:50:29 -08:00
}
2018-09-03 14:35:03 -07:00
2011-11-29 12:11:27 +00:00
$cstring = 'themelan/' . $theme . $fname . ( $flat ? '_1' : '_0' );
2020-12-19 09:50:29 -08:00
if ( self :: getRegistry ( $cstring ))
{
return null ;
}
2011-11-29 12:11:27 +00:00
2020-12-19 09:50:29 -08:00
if ( $fname )
{
$fname = e_LANGUAGE . ( $flat ? '_' : '/' ) . preg_replace ( '#[^\w/]#' , '' , trim ( $fname , '/' ));
}
else
{
$fname = e_LANGUAGE ;
}
2011-11-29 12:11:27 +00:00
$path = $theme . $fname . '.php' ;
2018-09-03 14:35:03 -07:00
2017-02-07 17:54:22 -08:00
if ( deftrue ( 'E107_DBG_INCLUDES' ))
2013-03-14 04:05:33 -07:00
{
2017-01-27 11:14:11 -08:00
self :: getMessage () -> addDebug ( " Attempting to Load: " . $path );
2018-09-03 14:35:03 -07:00
}
2011-11-29 12:11:27 +00:00
2017-01-27 11:14:11 -08:00
self :: setRegistry ( $cstring , true );
2017-12-16 12:25:18 -08:00
2020-12-19 09:50:29 -08:00
return self :: includeLan ( $path );
2011-11-29 12:11:27 +00:00
}
2011-05-03 22:13:59 +00:00
2012-11-27 14:00:19 -08:00
/**
2018-09-03 14:35:03 -07:00
* PREFERRED Generic Language File Loading Function for use by theme and plugin developers .
2012-11-27 14:00:19 -08:00
* Language - file equivalent to e107 :: js , e107 :: meta and e107 :: css
2017-12-13 20:28:07 +01:00
*
2013-05-27 15:18:56 +03:00
* FIXME disallow themes and plugins named 'core' and 'theme'
2017-12-13 20:28:07 +01: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 )
* when missing , [ e_LANGUAGE ] _front . php will be used , when true [ e_LANGUAGE ] _admin . php will be used
* @ 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)
2020-12-25 10:23:56 -08:00
* @ example e107 :: lan ( 'gallery' , 'admin' , true ); // Loads e_PLUGIN."gallery/languages/English/English_admin.php (if English is the current language)
2013-05-27 15:18:56 +03:00
* @ 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)
2017-12-13 20:28:07 +01:00
* @ example e107 :: lan ( 'gallery' , true , true ); // Loads e_PLUGIN."gallery/languages/English/English_admin.php (if English is the current language)
* @ example e107 :: lan ( 'gallery' , false , true ); // Loads e_PLUGIN."gallery/languages/English/English_front.php (if English is the current language)
2012-11-27 14:00:19 -08:00
*/
2021-01-08 09:56:33 -08:00
public static function lan ( $type , $fname = '' , $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' :
2020-12-25 10:23:56 -08:00
$result = self :: coreLan ( $fname , $options );
2012-12-06 16:36:22 -08:00
break ;
2018-09-03 14:35:03 -07:00
2012-11-27 14:00:19 -08:00
case 'theme' :
2020-12-25 10:23:56 -08:00
$result = self :: themeLan ( $fname , null , $options );
2012-11-27 14:00:19 -08:00
break ;
default :
2020-12-25 10:23:56 -08:00
$result = self :: plugLan ( $type , $fname , $options );
2012-11-27 14:00:19 -08:00
break ;
2018-09-03 14:35:03 -07:00
}
2020-12-25 10:23:56 -08:00
return $result ;
2012-11-27 14:00:19 -08:00
}
2012-12-06 16:36:22 -08:00
/**
2015-03-09 15:05:34 -07:00
* Generic PREF retrieval Method for use by theme and plugin developers .
* @ param string $type : 'core' , 'theme' , plugin - name
* @ param $pname : name of specific preference , or leave blank for full array .
* @ param null $default
* @ return mixed
2012-12-06 16:36:22 -08:00
*/
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
{
2018-09-03 14:35:03 -07:00
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 ;
2018-09-03 14:35:03 -07:00
2012-12-06 16:36:22 -08:00
case 'theme' :
2018-09-03 14:35:03 -07:00
return self :: getThemePref ( $pname , $default );
2012-12-06 16:36:22 -08:00
break ;
2018-09-03 14:35:03 -07:00
default :
2012-12-10 01:20:38 +02:00
return self :: getPlugPref ( $type , $pname , $default );
2012-12-06 16:36:22 -08:00
break ;
2018-09-03 14:35:03 -07:00
}
2012-12-06 16:36:22 -08:00
}
2019-06-14 14:32:58 -07:00
/**
* Set or Get the current breadcrumb array .
* @ param array $array
* @ return array | null
*/
public static function breadcrumb ( $array = array ())
{
2019-06-15 16:45:03 -07:00
if ( empty ( $array )) // read
2019-06-14 14:32:58 -07:00
{
2019-06-15 16:45:03 -07:00
if ( empty ( self :: $_breadcrumb )) //Guess what it should be..
{
if ( defined ( 'PAGE_NAME' )) // BC search for "PAGE_NAME"
{
return array ( 0 => array ( 'text' => PAGE_NAME , 'url' => null ));
}
2020-12-19 09:50:29 -08:00
elseif ( $caption = self :: getRender () -> getMainCaption ()) // BC search for primary render caption
2019-06-15 16:45:03 -07:00
{
return array ( 0 => array ( 'text' => $caption , 'url' => null ));
}
}
2019-06-14 14:32:58 -07:00
return self :: $_breadcrumb ;
}
2019-06-15 16:45:03 -07:00
self :: $_breadcrumb = $array ; // write.
2019-06-14 14:32:58 -07:00
return null ;
}
2021-01-19 07:54:13 -08:00
/**
* Quick method to set alias - uses e107 :: url format .
2021-01-19 13:31:20 -08:00
* @ param string $plugin if empty will return the last assigned canonical url . _SITEURL_ will set canonical to the SITEURL .
2021-01-19 09:50:02 -08:00
* @ param string | array $key
2021-01-19 07:54:13 -08:00
* @ param array $row
*/
public static function canonical ( $plugin = '' , $key = 'index' , $row = array ())
{
2021-01-19 18:52:56 -08:00
if ( $plugin === '_RESET_' ) // for testing only, may be removed in future.
{
2021-09-29 18:43:20 -07:00
self :: setRegistry ( 'core/e107/canonical' );
2021-01-19 18:52:56 -08:00
}
2021-01-19 09:50:02 -08:00
2021-09-29 18:43:20 -07:00
$alreadyDone = self :: getRegistry ( 'core/e107/canonical' );
2021-01-19 09:50:02 -08:00
if ( empty ( $plugin ))
{
return $alreadyDone ;
}
2021-01-19 13:31:20 -08:00
if ( empty ( $alreadyDone ))
2021-01-19 07:54:13 -08:00
{
2021-01-19 13:31:20 -08:00
if ( $plugin === '_SITEURL_' )
{
$url = SITEURL ;
}
else
{
2021-09-29 18:43:20 -07:00
$url = self :: url ( $plugin , $key , $row , array ( 'mode' => 'full' ));
2021-01-19 13:31:20 -08:00
}
if ( ! empty ( $url ))
{
self :: getJs () -> addLink ( array ( 'rel' => " canonical " , " href " => $url ));
2021-09-29 18:43:20 -07:00
self :: meta ( 'og:url' , $url );
self :: meta ( 'twitter:url' , $url );
self :: setRegistry ( 'core/e107/canonical' , $url );
2021-01-19 13:31:20 -08:00
$message = " Debug: Setting Canonical URL: <b><a href=' " . $url . " '> " . $url . " </a></b> " ;
}
2021-01-19 07:54:13 -08:00
}
2021-01-19 09:50:02 -08:00
if ( ! empty ( $alreadyDone ))
{
$backtrace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 2 );
2021-01-19 13:31:20 -08:00
$message = " Debug: More than one canonical was attempted. This was ignored: " . print_a ( $backtrace [ 1 ], true );
2021-01-19 09:50:02 -08:00
}
2021-01-19 13:31:20 -08:00
if ( deftrue ( 'e_DEBUG_CANONICAL' ) && ! empty ( $message ))
2021-01-19 07:54:13 -08:00
{
2021-01-19 13:31:20 -08:00
self :: getMessage () -> addInfo ( $message );
2021-01-19 07:54:13 -08:00
}
}
2021-02-21 14:10:47 -08:00
/**
* Reverse lookup of current URI against legacy e_url entry for the specified plugin .
* Useful for when SEF ( e_SINGLE_ENTRY ) is not in use .
* @ param string $route eg . forum / index ( must match SEF route )
*/
public static function detectRoute ( $plugin = null , $uri = null )
{
if ( empty ( $plugin ) || empty ( $uri ))
{
return null ;
}
2021-09-29 18:43:20 -07:00
if ( ! $addon = self :: getAddon ( $plugin , 'e_url' ))
2021-02-21 14:10:47 -08:00
{
trigger_error ( " Couldn't load e_url for " . $plugin );
return null ;
}
2021-09-29 18:43:20 -07:00
if ( ! $result = self :: callMethod ( $addon , 'config' ))
2021-02-21 14:10:47 -08:00
{
trigger_error ( $plugin . ' - e_url::config() method returned nothing' );
return null ;
}
foreach ( $result as $key => $var )
{
if ( empty ( $var [ 'legacy' ]))
{
continue ;
}
$legacy = self :: getParser () -> replaceConstants ( $var [ 'legacy' ], 'abs' ); // remove {e_PLUGIN}
$legacy = preg_replace ( '/\{[\w]*\}/' , '__XXX__' , $legacy ); // replace {fields} with placeholder.
$legacy = preg_quote ( $legacy , '/' ); // add slashes
$pattern = '/' . str_replace ( '__XXX__' , '([\w]*)' , $legacy ) . '/' ; // replace placeholder with regexp
if ( preg_match ( $pattern , $uri ))
{
return $plugin . '/' . $key ;
}
}
return null ;
}
2021-06-01 16:36:09 -07:00
/**
* Set the route or get the current route when $route is null .
* @ param string $route
* @ return string | null
*/
public static function route ( $route = null )
2021-02-21 14:10:47 -08:00
{
2021-11-01 15:46:39 -07:00
if ( $route === null )
2021-02-21 14:10:47 -08:00
{
2021-11-01 15:46:39 -07:00
return self :: getRegistry ( 'core/e107/route' , false );
2021-02-21 14:10:47 -08:00
}
2021-11-01 15:46:39 -07:00
self :: setRegistry ( 'core/e107/route' , $route );
2021-06-01 16:36:09 -07:00
return null ;
2021-02-21 14:10:47 -08:00
}
2014-06-06 02:39:44 -07:00
/**
2020-01-14 23:10:29 +01:00
* Generate a plugin ' s search engine - friendly URL with HTML special characters escaped
*
* Can be spliced directly into HTML code like < a href = " … " ></ a >
*
* Output is generated based on the plugin ' s e_url . php configuration
2016-06-08 19:27:08 -07:00
*
* @ param string $plugin - plugin folder name
* @ param string $key assigned in e_url . php configuration .
* @ param array $row Array of variables in url config .
2020-01-14 23:10:29 +01:00
* @ param array $options = [ // (optional) An associative array of additional options
* 'mode' => 'abs | full' , // @see e_parse::replaceConstants()
* 'query' => [], // An array of query key/value-pairs (without any URL encoding) to append to the URL
* 'fragment' => '' , // A fragment identifier (named anchor) to append to the URL. Do not include the leading '#' character
* 'legacy' => false , // When true, legacy URLs will be generated regardless of mod_rewrite status
* ]
* @ return string The SEF URL with HTML special characters escaped
* ( equivalent to the htmlspecialchars () output )
2015-03-09 15:05:34 -07:00
*/
2020-01-12 23:15:25 +01:00
public static function url ( $plugin = '' , $key = null , $row = array (), $options = array ())
2014-06-06 02:39:44 -07:00
{
2016-01-24 20:11:32 -08:00
2016-03-08 13:53:58 -08:00
/* backward compat - core keys. ie. news/xxx/xxx user/xxx/xxx etc, */
2020-01-12 23:15:25 +01:00
$legacy = array ( 'news' , 'page' , 'search' , 'user' , 'download' , 'gallery' );
2016-01-24 20:11:32 -08:00
2021-01-13 11:20:58 -08:00
if ( $plugin === 'search' )
{
$plugin = 'search/index' ;
}
2020-01-13 01:04:10 +01:00
if ( strpos ( $plugin , '/' ) !== false )
{
2020-01-12 23:15:25 +01:00
$tmp = explode ( " / " , $plugin , 2 );
2016-01-24 20:11:32 -08:00
2020-01-13 01:04:10 +01:00
if ( in_array ( $tmp [ 0 ], $legacy ))
{
2021-01-19 07:54:13 -08:00
if ( isset ( $options [ 'mode' ]) && $options [ 'mode' ] === 'full' )
{
if ( is_array ( $row ))
{
$row [ 'full' ] = 1 ;
}
elseif ( is_string ( $row ))
{
$row .= '&full=1' ;
}
elseif ( is_null ( $row ))
{
$row = 'full=1' ;
}
}
2016-03-08 13:53:58 -08:00
return self :: getUrl () -> create ( $plugin , $key , $row );
2016-01-24 20:11:32 -08:00
}
2016-03-08 13:53:58 -08:00
// shorthand - for internal use.
$plugin = $tmp [ 0 ];
$row = $key ;
$key = $tmp [ 1 ];
}
2016-01-24 20:11:32 -08:00
2020-01-13 01:04:10 +01:00
if ( ! $tmp = self :: getRegistry ( 'core/e107/addons/e_url' ))
{
2017-03-27 10:38:51 -07:00
$tmp = self :: getUrlConfig ();
2020-01-12 23:15:25 +01:00
self :: setRegistry ( 'core/e107/addons/e_url' , $tmp );
2016-04-06 19:43:31 -07:00
}
2017-01-27 11:14:11 -08:00
$tp = self :: getParser ();
2012-12-06 16:36:22 -08:00
2015-06-16 15:14:39 -07:00
$pref = self :: getPref ( 'e_url_alias' );
2016-12-06 06:55:47 -08:00
$sefActive = self :: getPref ( 'e_url_list' );
2017-03-27 10:38:51 -07:00
$rootNamespace = self :: getPref ( 'url_main_module' );
2015-04-25 12:57:00 -07:00
2020-01-12 23:15:25 +01:00
if ( is_string ( $options )) // backwards compat.
2015-07-22 09:10:14 +02:00
{
$options = array (
'mode' => $options ,
);
}
// Merge in defaults.
$options += array (
2020-01-12 23:15:25 +01:00
'mode' => 'abs' ,
2015-07-22 09:10:14 +02:00
'fragment' => '' ,
2020-01-12 23:15:25 +01:00
'query' => array (),
2015-07-22 09:10:14 +02:00
);
2020-01-13 01:04:10 +01:00
if ( isset ( $options [ 'fragment' ]) && $options [ 'fragment' ] !== '' )
{
2015-07-22 09:10:14 +02:00
$options [ 'fragment' ] = '#' . $options [ 'fragment' ];
}
2020-01-13 01:04:10 +01:00
if ( ! empty ( $plugin ) && empty ( $tmp [ $plugin ][ $key ][ 'sef' ]))
{
2020-01-12 23:15:25 +01:00
self :: getMessage () -> addDebug ( " e_url.php in <b> " . e_PLUGIN . $plugin . " </b> is missing the key: <b> " . $key . " </b>. Or, you may need to <a href=' " . e_ADMIN . " db.php?mode=plugin_scan'>scan your plugin directories</a> to register e_url.php " );
return false ;
}
2017-03-27 10:38:51 -07:00
2020-01-13 01:04:10 +01:00
if ( ! empty ( $tmp [ $plugin ][ $key ][ 'alias' ]))
{
2020-01-12 23:15:25 +01:00
$alias = ( ! empty ( $pref [ e_LAN ][ $plugin ][ $key ])) ? $pref [ e_LAN ][ $plugin ][ $key ] : $tmp [ $plugin ][ $key ][ 'alias' ];
2017-03-27 10:38:51 -07:00
2020-01-13 01:04:10 +01:00
if ( ! empty ( $rootNamespace ) && $rootNamespace === $plugin )
{
2020-01-12 23:15:25 +01:00
$replaceAlias = array ( '{alias}\/' , '{alias}/' );
$tmp [ $plugin ][ $key ][ 'sef' ] = str_replace ( $replaceAlias , '' , $tmp [ $plugin ][ $key ][ 'sef' ]);
2020-01-13 01:04:10 +01:00
}
else
{
2020-01-12 23:15:25 +01:00
$tmp [ $plugin ][ $key ][ 'sef' ] = str_replace ( '{alias}' , $alias , $tmp [ $plugin ][ $key ][ 'sef' ]);
2015-06-16 15:14:39 -07:00
}
2020-01-12 23:15:25 +01:00
}
2015-04-25 12:57:00 -07:00
2020-01-12 23:15:25 +01:00
preg_match_all ( '#{([a-z_]*)}#' , $tmp [ $plugin ][ $key ][ 'sef' ], $matches );
2015-04-25 12:57:00 -07:00
2020-01-12 23:15:25 +01:00
$active = true ;
2015-04-25 12:57:00 -07:00
2020-01-13 00:21:59 +01:00
foreach ( $matches [ 1 ] as $k => $v ) // check if a field value is missing, if so, revert to legacy url.
2020-01-12 23:15:25 +01:00
{
2020-01-13 01:04:10 +01:00
if ( ! isset ( $row [ $v ]))
{
2020-01-12 23:15:25 +01:00
self :: getMessage () -> addDebug ( " Missing value for " . $v . " in " . $plugin . " /e_url.php - ' " . $key . " ' " );
2016-12-06 06:55:47 -08:00
$active = false ;
2020-01-12 23:15:25 +01:00
break ;
2016-12-06 06:55:47 -08:00
}
2020-01-12 23:15:25 +01:00
}
2016-12-06 06:55:47 -08:00
2020-01-12 23:15:25 +01:00
if ( empty ( $sefActive [ $plugin ])) // SEF disabled.
{
self :: getDebug () -> log ( 'SEF URL for <b>' . $plugin . '</b> disabled.' );
2021-01-13 16:16:50 -08:00
// trigger_error('SEF URL for ' . $plugin . ' disabled.', E_USER_NOTICE);
2020-01-12 23:15:25 +01:00
$active = false ;
}
2016-12-06 06:55:47 -08:00
2020-08-12 14:09:42 -07:00
$e_MOD_REWRITE = ( self :: isCli () !== true ) ? deftrue ( 'e_MOD_REWRITE' ) : true ;
if ( $e_MOD_REWRITE && ( $active == true ) && empty ( $options [ 'legacy' ])) // Search-Engine-Friendly URLs active.
2020-01-12 23:15:25 +01:00
{
$rawUrl = $tp -> simpleParse ( $tmp [ $plugin ][ $key ][ 'sef' ], $row );
2015-07-22 09:10:14 +02:00
2020-01-13 01:04:10 +01:00
if ( $options [ 'mode' ] === 'full' )
{
2020-01-12 23:15:25 +01:00
$sefUrl = SITEURL . $rawUrl ;
2020-01-13 01:04:10 +01:00
}
elseif ( $options [ 'mode' ] === 'raw' )
{
2020-01-12 23:15:25 +01:00
$sefUrl = $rawUrl ;
2020-01-13 01:04:10 +01:00
}
else
{
2020-01-12 23:15:25 +01:00
$sefUrl = e_HTTP . $rawUrl ;
}
2020-01-13 01:04:10 +01:00
}
else // Legacy URL.
2020-01-12 23:15:25 +01:00
{
2015-03-31 06:24:14 -07:00
2020-01-12 23:15:25 +01:00
$srch = array ();
$repl = array ();
2015-03-31 06:24:14 -07:00
2020-01-13 01:04:10 +01:00
foreach ( $matches [ 0 ] as $k => $val )
{
2020-01-12 23:15:25 +01:00
$srch [] = '$' . ( $k + 1 );
$repl [] = $val ;
}
2015-04-25 12:57:00 -07:00
2020-01-12 23:15:25 +01:00
$template = isset ( $tmp [ $plugin ][ $key ][ 'legacy' ]) ? $tmp [ $plugin ][ $key ][ 'legacy' ] : $tmp [ $plugin ][ $key ][ 'redirect' ];
2015-03-31 06:24:14 -07:00
2020-01-12 23:15:25 +01:00
$urlTemplate = str_replace ( $srch , $repl , $template );
$urlTemplate = $tp -> replaceConstants ( $urlTemplate , $options [ 'mode' ]);
$legacyUrl = $tp -> simpleParse ( $urlTemplate , $row );
2015-04-25 12:57:00 -07:00
2020-12-10 15:52:48 -08:00
$legacyUrl = preg_replace ( '/&?\$[\d]/' , " " , $legacyUrl ); // remove any left-over $x (including prefix of '&')
2017-12-12 10:58:41 -08:00
2020-01-12 23:15:25 +01:00
// Avoid duplicate query keys. eg. URL has ?id=x and $options['query']['id'] exists.
// @see forum/e_url.php - topic/redirect and forum/view_shortcodes.php sc_post_url()
2020-01-18 19:20:48 +01:00
list ( $legacyUrl , $tmp ) = array_pad ( explode ( " ? " , $legacyUrl ), 2 , null );
2020-01-12 23:15:25 +01:00
2020-01-13 01:04:10 +01:00
if ( ! empty ( $tmp ))
{
if ( strpos ( $tmp , '=' ) === false )
{
2020-01-12 23:15:25 +01:00
// required for legacy urls of type "request.php?download.43"
// @see: issue #3275
$legacyUrl .= '?' . $tmp ;
$options [ 'query' ] = null ;
2020-01-13 01:04:10 +01:00
}
else
{
2018-07-13 23:38:17 +02:00
2020-01-12 23:15:25 +01:00
parse_str ( $tmp , $qry );
2018-07-13 23:38:17 +02:00
2020-01-13 01:04:10 +01:00
foreach ( $qry as $k => $v )
{
2020-01-12 23:15:25 +01:00
if ( ! isset ( $options [ 'query' ][ $k ])) // $options['query'] overrides any in the original URL.
2017-12-12 10:58:41 -08:00
{
2020-01-12 23:15:25 +01:00
$options [ 'query' ][ $k ] = $v ;
2017-12-12 10:58:41 -08:00
}
}
2015-07-22 09:10:14 +02:00
}
2015-03-31 06:24:14 -07:00
}
2020-01-13 00:21:59 +01:00
$sefUrl = $legacyUrl ;
}
2015-03-31 06:24:14 -07:00
2020-01-13 00:21:59 +01:00
// Append the query.
2020-01-13 01:04:10 +01:00
if ( is_array ( $options [ 'query' ]) && ! empty ( $options [ 'query' ]))
{
2020-01-14 23:54:34 +01:00
$sefUrl .= ( strpos ( $sefUrl , '?' ) !== FALSE ? '&' : '?' ) . self :: httpBuildQuery ( $options [ 'query' ]);
2015-03-31 14:48:07 -07:00
}
2020-01-13 00:21:59 +01:00
2020-12-19 09:50:29 -08:00
return htmlspecialchars ( $sefUrl . $options [ 'fragment' ], ENT_QUOTES );
2014-06-06 02:39:44 -07:00
}
2012-12-06 16:36:22 -08:00
2015-04-11 18:52:07 -07:00
2016-01-13 19:17:37 -08:00
/**
* Simple redirect method for developers .
2016-12-14 15:01:51 +01:00
*
* @ param string $url
* 'admin' to redirect to admin entry page or leave blank to go to home page
* ( SITEURL ) .
* @ param int $http_response_code
* The HTTP status code to use for the redirection , defaults to 302.
* The valid values for 3 xx redirection status codes are defined in RFC 2616
* and the draft for the new HTTP status codes :
* - 301 : Moved Permanently ( the recommended value for most redirects ) .
* - 302 : Found ( default in PHP , sometimes used for spamming search engines ) .
* - 303 : See Other .
* - 304 : Not Modified .
* - 305 : Use Proxy .
* - 307 : Temporary Redirect .
* @ see https :// www . w3 . org / Protocols / rfc2616 / rfc2616 - sec10 . html #sec10.3
* @ see https :// tools . ietf . org / html / draft - reschke - http - status - 308 - 07
*/
2018-08-23 09:21:38 +02:00
public static function redirect ( $url = '' , $http_response_code = 301 )
2016-12-14 15:01:51 +01:00
{
self :: getRedirect () -> go ( $url , true , $http_response_code );
2016-01-13 19:17:37 -08:00
}
2016-12-15 10:06:54 +01:00
/**
2016-12-15 19:11:50 +01:00
* Retrieve error page handler .
2016-12-15 10:06:54 +01:00
*
2018-09-03 14:35:03 -07:00
* @ return error_page
2016-12-15 10:06:54 +01:00
*/
2016-12-15 19:11:50 +01:00
public static function getError ()
2016-12-15 10:06:54 +01:00
{
2020-12-19 09:50:29 -08:00
return self :: getSingleton ( 'error_page' );
2016-12-15 10:06:54 +01:00
}
2018-09-03 14:35:03 -07:00
2021-01-14 17:26:15 -08:00
/**
* Retrieve e_emote filter .
*
* @ return e_emote
*/
public static function getEmote ()
{
return self :: getSingleton ( 'e_emote' );
}
/**
* Retrieve Profanity filter .
*
* @ return e_profanity
*/
public static function getProfanity ()
{
return self :: getSingleton ( 'e_profanity' );
}
2016-01-13 19:17:37 -08:00
2015-07-22 09:10:14 +02:00
/**
* Parses an array into a valid , rawurlencoded query string . This differs from http_build_query () as we need to
* rawurlencode () ( instead of urlencode ()) all query parameters .
* @ param array $query The query parameter array to be processed , e . g . $_GET .
* @ param string $parent Internal use only . Used to build the $query array key for nested items .
2020-01-12 23:15:25 +01:00
* @ return string A rawurlencoded string which can be used as or appended to the URL query string .
2015-07-22 09:10:14 +02:00
*/
public static function httpBuildQuery ( array $query , $parent = '' )
{
$params = array ();
foreach ( $query as $key => $value )
{
$key = ( $parent ? $parent . '[' . rawurlencode ( $key ) . ']' : rawurlencode ( $key ));
// Recurse into children.
if ( is_array ( $value ))
{
$params [] = self :: httpBuildQuery ( $value , $key );
}
// If a query parameter value is NULL, only append its key.
elseif ( ! isset ( $value ))
{
$params [] = $key ;
}
else
{
// For better readability of paths in query strings, we decode slashes.
$params [] = $key . '=' . str_replace ( '%2F' , '/' , rawurlencode ( $value ));
}
}
2020-01-14 23:54:34 +01:00
return implode ( '&' , $params );
2015-07-22 09:10:14 +02:00
}
2018-09-03 14:35:03 -07:00
public static function minify ( $js , $options = array ())
2015-04-11 18:52:07 -07:00
{
if ( empty ( $js ))
{
2016-02-06 10:35:56 -08:00
return null ;
2015-04-11 18:52:07 -07:00
}
2020-02-29 11:56:05 -08:00
try
{
2020-11-27 17:11:10 +01:00
$minifier = new MatthiasMullie\Minify\JS ( $js );
$minified = $minifier -> minify ();
2020-02-29 11:56:05 -08:00
}
catch ( Exception $e )
{
$minified = $js ;
}
return $minified ;
2015-04-11 18:52:07 -07:00
}
2015-01-29 11:26:56 -08:00
/**
2015-03-09 15:05:34 -07:00
* Set or Retrieve WYSIWYG active status . ( replaces constant e_WYSIWYG )
2018-07-30 22:17:03 +02:00
*
2018-07-29 15:11:40 +02:00
* @ param bool / string $val if null , return current value , otherwise define editor to use
* @ param bool $returnEditor true = return name of active editor , false = return " false " for non wysiwyg editor , return " true " if wysiwyg editor should be used
2018-07-30 22:17:03 +02:00
* @ return bool | mixed
2015-01-29 11:26:56 -08:00
*/
2018-07-29 15:11:40 +02:00
public static function wysiwyg ( $val = null , $returnEditor = false )
2015-01-29 11:26:56 -08:00
{
2018-07-30 22:17:03 +02:00
static $editor = 'bbcode' ;
2018-07-29 15:11:40 +02:00
static $availEditors ;
$fallbackEditor = 'bbcode' ;
2018-07-30 22:17:03 +02:00
2015-02-01 17:41:53 -08:00
if ( self :: getPref ( 'wysiwyg' , false ) != true )
2015-01-29 11:26:56 -08:00
{
2018-07-30 22:17:03 +02:00
// wysiwyg disabled by global pref
2018-07-29 15:11:40 +02:00
$editor = $fallbackEditor ;
}
2018-07-30 22:17:03 +02:00
else
2018-07-29 15:11:40 +02:00
{
2018-07-30 22:17:03 +02:00
if ( ! isset ( $availEditors ))
{
// init list of installed wysiwyg editors
2020-12-12 20:10:41 -08:00
$default = self :: isInstalled ( 'tinymce4' ) ? array ( 'tinymce4' => 'TinyMce4' ) : array (); // if missing pref fallback.
$availEditors = self :: getPref ( 'wysiwyg_list' , $default );
2020-12-12 12:40:26 -08:00
// $availEditors = array_keys(e107::getPlug()->getInstalledWysiwygEditors()); // very slow.
2018-07-30 22:17:03 +02:00
}
2020-12-19 09:50:29 -08:00
if ( $val !== null )
2018-07-30 22:17:03 +02:00
{
// set editor if value given
$editor = empty ( $val ) ? $fallbackEditor : ( $val === 'default' ? true : $val );
}
// check if choosen editor is installed,
// if not, but a different editor is available use that one (e.g. tinymce4 choosen, but only simplemde available available, use simplemde)
// if no wysiwyg editor available, use fallback editor (bbcode)
if ( is_bool ( $editor ) || ( $editor !== $fallbackEditor && ! in_array ( $editor , $availEditors )))
{
2020-12-12 12:40:26 -08:00
$names = array_keys ( $availEditors );
2020-12-12 20:10:41 -08:00
// $editor = count($availEditors) > 0 ? $availEditors[0] : $fallbackEditor;
2020-12-12 12:40:26 -08:00
$editor = count ( $availEditors ) > 0 ? reset ( $names ) : $fallbackEditor ;
2018-07-30 22:17:03 +02:00
}
2018-07-29 15:11:40 +02:00
}
2020-12-12 20:10:41 -08:00
2018-07-29 15:11:40 +02:00
// $returnEditor => false:
// false => fallback editor (bbcode)
// true => default wysiwyg editor
// $returnEditor => true:
// return name of the editor
2018-07-30 22:17:03 +02:00
//return $returnEditor ? $editor : ($editor === $fallbackEditor || $editor === false ? false : true);
return $returnEditor ? $editor : ( $editor !== $fallbackEditor );
2015-01-29 11:26:56 -08:00
}
2012-12-06 16:36:22 -08:00
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' :
2016-02-14 19:00:12 -08:00
$aLangPref = self :: getPref ( 'adminlanguage' );
$adminLan = vartrue ( $aLangPref , e_LANGUAGE );
2018-09-03 14:35:03 -07:00
$searchPath [ 1 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '_admin_' . $unitName . '.php' ;
$searchPath [ 2 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '/' . 'admin_' . $unitName . '.php' ;
2014-02-07 17:57:55 -08:00
$searchPath [ 3 ] = e_PLUGIN . $unitName . '/languages/' . $adminLan . '/admin/' . $adminLan . '.php' ;
2018-09-03 14:35:03 -07:00
$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.
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 : " " ;
}
}
2020-12-27 09:48:02 -08:00
if (( e_LANGUAGE === 'English' ) || self :: getPref ( 'noLanguageSubs' ))
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
2015-03-09 15:05:34 -07:00
* This is done before e107_dirs initilization and 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' );
2020-12-19 09:50:29 -08:00
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?
}
2020-12-19 09:50:29 -08:00
if ( isset ( $_COOKIE ))
{
array_walk ( $_COOKIE , array ( 'self' , 'filter_request' ), '_COOKIE' );
}
if ( isset ( $_REQUEST ))
{
array_walk ( $_REQUEST , array ( 'self' , 'filter_request' ), '_REQUEST' );
}
2011-05-03 22:13:59 +00:00
2012-07-20 07:31:16 +00:00
// A better way to detect an AJAX request. No need for "ajax_used=1";
2017-01-29 18:43:52 -08:00
if ( ! empty ( $_SERVER [ 'HTTP_X_REQUESTED_WITH' ]) && strtolower ( $_SERVER [ 'HTTP_X_REQUESTED_WITH' ]) === 'xmlhttprequest' )
2012-07-20 07:31:16 +00:00
{
define ( 'e_AJAX_REQUEST' , true );
}
else
{
2018-09-03 14:35:03 -07:00
define ( 'e_AJAX_REQUEST' , isset ( $_REQUEST [ 'ajax_used' ]));
2012-07-20 07:31:16 +00:00
}
2015-03-29 20:26:35 -07: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
{
2021-01-05 10:04:26 -08:00
$_e107vars = array ( 'forceuserupdate' , 'online' , '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
2020-12-19 09:50:29 -08:00
if ( e_AJAX_REQUEST && ! isset ( $GLOBALS [ '_E107' ][ 'online' ]) && ! isset ( $GLOBALS [ '_E107' ][ 'minimal' ]))
{
unset ( $_e107vars [ 1 ]);
}
2010-05-15 17:33:11 +00:00
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
2020-12-19 09:50:29 -08:00
if ( isset ( $GLOBALS [ '_E107' ]) && is_array ( $GLOBALS [ '_E107' ]))
{
$this -> _E107 = & $GLOBALS [ '_E107' ];
}
2010-05-13 15:47:31 +00:00
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
2020-01-17 15:04:29 +01:00
$_SERVER [ 'QUERY_STRING' ] = trim (
str_replace (
array ( 'ajax_used=1' , '&&' ),
array ( '' , '&' ),
( isset ( $_SERVER [ 'QUERY_STRING' ]) ? $_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
2017-01-27 11:14:11 -08:00
self :: ini_set ( 'magic_quotes_runtime' , 0 );
self :: ini_set ( 'magic_quotes_sybase' , 0 );
2018-05-04 17:57:43 -07:00
// self::ini_set('arg_separator.output', '&'); // non-standard and bad for third-party script compatibility. @see https://github.com/e107inc/e107/issues/3116
2017-01-27 11:14:11 -08:00
self :: ini_set ( 'session.use_only_cookies' , 1 );
self :: ini_set ( 'session.use_trans_sid' , 0 );
self :: ini_set ( 'session.cookie_httponly' , 1 ); // cookie won't be accessible by scripting languages, such as JavaScript. Can effectively help to reduce identity theft through XSS attacks
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' ));
2020-12-10 15:52:48 -08:00
if ( $inc_path [ 0 ] !== '.' )
2009-11-24 16:30:08 +00:00
{
array_unshift ( $inc_path , '.' );
$inc_path = implode ( PATH_SEPARATOR , $inc_path );
2017-01-27 11:14:11 -08:00
self :: 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
2015-03-09 15:05:34 -07:00
* @ param string $key array key
* @ param string $type array type _SESSION , _GET etc .
* @ param bool $base64
2018-09-03 12:08:44 -07:00
* @ return bool | null
2011-05-03 22:13:59 +00:00
*/
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 ) == " " )
{
2015-03-09 15:05:34 -07:00
return '' ;
2011-11-29 23:37:44 +00:00
}
2018-09-03 14:35:03 -07:00
2011-05-03 22:13:59 +00:00
if ( is_array ( $input ))
{
return array_walk ( $input , array ( 'self' , 'filter_request' ), $type );
}
2016-08-19 16:13:38 -07:00
2020-12-10 15:52:48 -08:00
if ( $type === " _POST " || ( $type === " _SERVER " && ( $key === " QUERY_STRING " )))
2011-11-29 23:37:44 +00:00
{
2020-12-10 15:52:48 -08:00
if ( $type === " _POST " && ( $base64 === false ))
2011-11-29 23:37:44 +00:00
{
$input = preg_replace ( " /( \ [code \ ])(.*?)( \ [ \ /code \ ])/is " , " " , $input );
}
2018-09-03 14:35:03 -07:00
2015-02-21 13:12:17 -08:00
$regex = " /(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 " ;
2011-11-29 23:37:44 +00:00
if ( preg_match ( $regex , $input ))
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2011-11-29 23:37:44 +00:00
}
2015-02-21 13:12:17 -08:00
// Check for XSS JS
$regex = " /(document \ .location|document \ .write|document \ .cookie)/i " ;
if ( preg_match ( $regex , $input ))
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2015-02-21 13:12:17 -08:00
}
2015-04-24 11:41:58 -07:00
// Suspicious HTML.
if ( strpos ( $input , '<body/onload' ) !== false )
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2015-04-24 11:41:58 -07:00
}
2015-03-29 20:26:35 -07:00
if ( preg_match ( " /system \ ((.*);.* \ )/i " , $input ))
2011-11-29 23:37:44 +00:00
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2011-11-29 23:37:44 +00:00
}
2018-09-03 14:35:03 -07:00
2016-12-28 18:51:34 -08:00
$regex = " /(wget |curl -o |lwp-download|onmouse)/i " ;
2011-11-29 23:37:44 +00:00
if ( preg_match ( $regex , $input ))
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2011-11-29 23:37:44 +00:00
}
2018-09-03 14:35:03 -07:00
2011-11-29 23:37:44 +00:00
}
2016-08-19 16:13:38 -07:00
2017-01-29 18:43:52 -08:00
if ( $type === '_GET' ) // Basic XSS check.
2016-08-19 16:13:38 -07:00
{
if ( stripos ( $input , " <script " ) !== false || stripos ( $input , " %3Cscript " ) !== false )
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2016-08-19 16:13:38 -07:00
}
}
2018-09-03 14:35:03 -07:00
2020-12-10 15:52:48 -08:00
if ( $type === " _SERVER " )
2011-05-03 22:13:59 +00:00
{
2020-12-19 09:50:29 -08:00
$input = strtolower ( $input );
2016-08-19 16:13:38 -07:00
2020-12-10 15:52:48 -08:00
if (( $key === " QUERY_STRING " ) && (
2020-12-19 09:50:29 -08:00
strpos ( $input , " ../../ " ) !== FALSE
2016-08-19 16:13:38 -07:00
|| stripos ( $input , " php: " ) !== FALSE
|| stripos ( $input , " data: " ) !== FALSE
|| stripos ( $input , " %3cscript " ) !== FALSE
2011-11-29 23:37:44 +00:00
))
2011-05-03 22:13:59 +00:00
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2016-02-28 12:22:13 -08:00
}
2018-09-03 14:35:03 -07:00
2020-12-10 15:52:48 -08:00
if (( $key === " HTTP_USER_AGENT " ) && strpos ( $input , " libwww-perl " ) !== FALSE )
2011-05-03 22:13:59 +00:00
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2011-05-03 22:13:59 +00:00
}
2018-09-03 14:35:03 -07:00
2011-05-03 22:13:59 +00:00
}
2018-09-03 14:35:03 -07:00
2011-05-03 22:13:59 +00:00
if ( strpos ( str_replace ( '.' , '' , $input ), '22250738585072011' ) !== FALSE ) // php-bug 53632
{
2020-02-17 10:36:03 +01:00
self :: die_http_400 ();
2018-09-03 14:35:03 -07:00
}
2016-08-19 16:13:38 -07:00
if ( $base64 != true )
2011-11-29 23:37:44 +00:00
{
2019-01-07 16:46:01 -08:00
self :: filter_request ( base64_decode ( $input , true ), $key , $type , true );
2011-05-03 22:13:59 +00:00
}
2016-08-19 16:13:38 -07:00
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
{
2020-12-19 09:50:29 -08:00
$ssl_enabled = ( $force !== null ) ? $force : $this -> isSecure (); //(self::getPref('ssl_enabled') == 1);
2009-11-24 16:30:08 +00:00
$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
{
2019-06-03 15:27:36 -07:00
if ( ! defined ( 'MAGIC_QUOTES_GPC' ))
{
2020-12-18 09:39:02 -08:00
define ( 'MAGIC_QUOTES_GPC' , false ); // (Removed in PHP 5.4 ini_get('magic_quotes_gpc') ? true : false));
2019-06-03 15:27:36 -07:00
}
2009-12-02 16:51:04 +00:00
2016-02-12 19:28:35 -08:00
define ( 'MPREFIX' , self :: 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
2015-04-01 02:09:25 -07:00
if ( ! defined ( 'e_MOD_REWRITE' )) // Allow e107_config.php to override.
{
2020-12-19 09:50:29 -08:00
define ( 'e_MOD_REWRITE' , (( getenv ( 'HTTP_MOD_REWRITE' ) === 'On' || getenv ( 'REDIRECT_HTTP_MOD_REWRITE' ) === 'On' )));
2015-04-01 02:09:25 -07:00
}
2016-02-03 18:17:14 -08:00
if ( ! defined ( 'e_MOD_REWRITE_MEDIA' )) // Allow e107_config.php to override.
{
2020-12-19 09:50:29 -08:00
define ( 'e_MOD_REWRITE_MEDIA' , (( getenv ( 'HTTP_MOD_REWRITE_MEDIA' ) === 'On' || getenv ( 'REDIRECT_HTTP_MOD_REWRITE_MEDIA' ) === 'On' )));
2016-02-03 18:17:14 -08:00
}
2017-04-26 13:58:01 -07:00
if ( ! defined ( 'e_MOD_REWRITE_STATIC' )) // Allow e107_config.php to override.
{
2020-12-19 09:50:29 -08:00
define ( 'e_MOD_REWRITE_STATIC' , (( getenv ( 'HTTP_MOD_REWRITE_STATIC' ) === 'On' || getenv ( 'REDIRECT_HTTP_MOD_REWRITE_STATIC' ) === 'On' )));
2017-04-26 13:58:01 -07:00
}
2017-11-07 12:10:06 -08:00
$subdomain = false ;
2009-11-24 16:30:08 +00:00
// Define the domain name and subdomain name.
2020-01-17 15:04:29 +01:00
if ( is_numeric ( str_replace ( " . " , " " ,
( isset ( $_SERVER [ 'HTTP_HOST' ]) ? $_SERVER [ 'HTTP_HOST' ] : '' )
)))
2009-11-24 16:30:08 +00:00
{
2017-11-07 12:10:06 -08:00
$domain = false ;
$subdomain = false ;
2009-11-24 16:30:08 +00:00
}
else
2017-11-07 12:10:06 -08:00
{
2020-01-17 15:04:29 +01:00
$_SERVER [ 'SERVER_NAME' ] = isset ( $_SERVER [ 'SERVER_NAME' ]) ? $_SERVER [ 'SERVER_NAME' ] : '' ;
2017-11-10 11:27:45 -08:00
$host = ! empty ( $_SERVER [ 'HTTP_HOST' ]) ? $_SERVER [ 'HTTP_HOST' ] : $_SERVER [ 'SERVER_NAME' ];
$domain = preg_replace ( '/^www\.|:\d*$/' , '' , $host ); // remove www. and port numbers.
2017-11-07 12:10:06 -08:00
$dtemp = explode ( " . " , $domain );
if ( count ( $dtemp ) > 2 && strlen ( $dtemp [ 0 ]) === 2 ) // eg. fr.mysite.com or fr.mysite.com.fr
2013-05-26 13:52:43 -07:00
{
2017-11-07 12:10:06 -08:00
$subdomain = $dtemp [ 0 ];
unset ( $dtemp [ 0 ]);
$domain = implode ( '.' , $dtemp ); // remove subdomain because it's a language-code.
2013-05-26 13:52:43 -07:00
}
2017-11-07 12:10:06 -08:00
2009-11-24 16:30:08 +00:00
}
2009-12-02 16:51:04 +00:00
2017-12-01 14:10:51 -08:00
if ( $domain === 'localhost' ) // Fix for chrome.
{
$domain = false ;
}
2013-05-26 13:52:43 -07:00
define ( " e_DOMAIN " , $domain );
2020-12-19 09:50:29 -08:00
define ( " e_SUBDOMAIN " , ( $subdomain ) ? : false );
2018-09-03 14:35:03 -07:00
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 );
2016-02-12 19:28:35 -08: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
2021-01-24 15:33:39 -08:00
return e_BASE . $this -> e107_dirs [ $dir . '_DIRECTORY' ];
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' ];
}
2017-10-25 16:14:12 -07:00
2017-10-25 19:02:10 -07:00
return e_HTTP . $this -> e107_dirs [ $dir . '_DIRECTORY' ];
2010-03-03 17:06:33 +00:00
}
2009-07-21 16:11:02 +00:00
/**
* Set all environment vars and constants
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' ;
2020-01-17 15:04:29 +01:00
if (
2020-12-10 15:52:48 -08:00
( ! empty ( $_SERVER [ 'HTTPS' ]) && $_SERVER [ 'HTTPS' ] !== 'off' ) ||
2020-01-17 15:04:29 +01:00
( ! empty ( $_SERVER [ 'SERVER_PORT' ]) && $_SERVER [ 'SERVER_PORT' ] == 443 )
)
2009-11-24 16:30:08 +00:00
{
2020-01-17 15:04:29 +01:00
$this -> HTTP_SCHEME = 'https' ;
2009-11-24 16:30:08 +00:00
}
2009-12-02 16:51:04 +00:00
2021-01-02 02:13:11 +01:00
$path = " " ;
2021-01-16 08:43:51 -08:00
$target_path = '' ;
2008-01-21 03:54:10 +00:00
2021-01-02 02:13:11 +01:00
$needle = " /class2.php " ;
if ( file_exists ( __DIR__ . " /.. " . $needle ))
2008-01-21 03:54:10 +00:00
{
2021-01-02 02:13:11 +01:00
$target_path = realpath ( __DIR__ . " /.. " . $needle );
}
else
{
$debug_backtrace = array_reverse ( debug_backtrace ());
foreach ( $debug_backtrace as $stack_item )
2008-01-21 03:54:10 +00:00
{
2021-01-02 02:13:11 +01:00
$target_path = isset ( $stack_item [ " file " ]) ? $stack_item [ " file " ] : " " ;
if ( substr_compare ( $target_path , $needle , - strlen ( $needle )) === 0 ) break ;
break ;
2008-01-21 03:54:10 +00:00
}
2006-12-02 04:36:16 +00:00
}
2017-02-09 07:39:19 -08:00
2021-01-05 16:40:01 -08:00
if ( self :: isCli ()) // Maintain relative path consistency in CLI mode
{
chdir ( e_ROOT );
2021-01-13 11:20:58 -08:00
define ( 'e_HTTP' , '/' ); // fixes generate URLs by not using $this->server_path
2021-01-05 16:40:01 -08:00
}
$path = dirname ( self :: getRelativePath ( getcwd (), $target_path )) . " / " ;
2006-12-02 04:36:16 +00:00
2021-01-02 02:13:11 +01:00
$http_path = dirname ( $_SERVER [ 'SCRIPT_NAME' ]);
2006-12-02 04:36:16 +00:00
$http_path = explode ( " / " , $http_path );
2021-01-02 02:13:11 +01:00
for ( $i = 0 ; $i < substr_count ( $path , " ../ " ); $i ++ )
2008-01-21 03:54:10 +00:00
{
2021-01-02 02:13:11 +01:00
array_pop ( $http_path );
2006-12-02 04:36:16 +00:00
}
2017-02-09 07:39:19 -08:00
2006-12-02 04:36:16 +00:00
$this -> server_path = implode ( " / " , $http_path ) . " / " ;
$this -> server_path = $this -> fix_windows_paths ( $this -> server_path );
2017-02-09 07:39:19 -08:00
//var_dump($this->server_path);
//exit;
2020-12-10 15:52:48 -08:00
if ( $this -> server_path === " // " )
2008-01-21 03:54:10 +00:00
{
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
2021-01-02 02:13:11 +01:00
$this -> relative_base_path = $path ;
2020-01-17 15:04:29 +01:00
$_SERVER [ 'HTTP_HOST' ] = isset ( $_SERVER [ 'HTTP_HOST' ]) ? $_SERVER [ 'HTTP_HOST' ] : 'localhost' ;
2016-12-01 15:38:40 -08:00
$this -> http_path = filter_var ( " http:// { $_SERVER [ 'HTTP_HOST' ] } { $this -> server_path } " , FILTER_SANITIZE_URL );
$this -> https_path = filter_var ( " https:// { $_SERVER [ 'HTTP_HOST' ] } { $this -> server_path } " , FILTER_SANITIZE_URL );
2006-12-02 04:36:16 +00:00
$this -> file_path = $path ;
2020-12-19 09:50:29 -08:00
if ( defined ( 'e_HTTP' ) && defined ( 'e_ADMIN' ))
{
return $this ;
}
2007-03-04 14:59:28 +00:00
2018-02-12 06:50:43 -06:00
if ( ! defined ( 'e_HTTP' ))
{
define ( 'e_HTTP' , $this -> server_path ); // Directory of site root relative to HTML base directory
}
2010-03-03 17:06:33 +00:00
2018-02-12 06:50:43 -06:00
define ( 'e_BASE' , $this -> relative_base_path );
2017-10-25 15:17:53 -07:00
2018-02-12 06:50:43 -06:00
// Base dir of web stuff in server terms. e_ROOT should always end with e_HTTP, even if e_HTTP = '/'
define ( 'SERVERBASE' , substr ( e_ROOT , 0 , - strlen ( e_HTTP ) + 1 ));
2017-02-08 22:52:18 -08:00
2018-02-12 06:50:43 -06:00
if ( isset ( $_SERVER [ 'DOCUMENT_ROOT' ]))
{
define ( 'e_DOCROOT' , $_SERVER [ 'DOCUMENT_ROOT' ] . " / " );
}
else
{
define ( 'e_DOCROOT' , false );
}
//BC temporary fixes
2020-12-10 15:52:48 -08:00
if ( ! isset ( $this -> e107_dirs [ 'UPLOADS_SERVER' ]) && $this -> e107_dirs [ 'UPLOADS_DIRECTORY' ][ 0 ] === " / " )
2018-02-12 06:50:43 -06:00
{
$this -> e107_dirs [ 'UPLOADS_SERVER' ] = $this -> e107_dirs [ 'UPLOADS_DIRECTORY' ];
}
2020-12-10 15:52:48 -08:00
if ( ! isset ( $this -> e107_dirs [ 'DOWNLOADS_SERVER' ]) && $this -> e107_dirs [ 'DOWNLOADS_DIRECTORY' ][ 0 ] === " / " )
2018-02-12 06:50:43 -06:00
{
$this -> e107_dirs [ 'DOWNLOADS_SERVER' ] = $this -> e107_dirs [ 'DOWNLOADS_DIRECTORY' ];
}
//
// 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_BASE' , $this -> get_override_rel ( 'MEDIA_BASE' ));
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' ));
// define('e_MEDIA_AVATAR', $this->get_override_rel('MEDIA_AVATARS'));
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_SYSTEM_BASE' , $this -> get_override_rel ( 'SYSTEM_BASE' ));
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' ));
// define('e_WEB_PACK', $this->get_override_rel('WEB_PACKS'));
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' ));
define ( 'e_CACHE_URL' , $this -> get_override_rel ( 'CACHE_URL' ));
define ( 'e_LOG' , $this -> get_override_rel ( 'LOGS' ));
define ( 'e_BACKUP' , $this -> get_override_rel ( 'BACKUP' ));
define ( 'e_TEMP' , $this -> get_override_rel ( 'TEMP' ));
define ( 'e_IMPORT' , $this -> get_override_rel ( 'IMPORT' ));
//
// 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' ));
define ( " e_IMPORT_ABS " , false );
// 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' ));
// define('e_MEDIA_AVATAR_ABS', $this->get_override_http('MEDIA_AVATARS'));
// 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
2018-09-03 14:35:03 -07:00
//XXX Absolute is assumed.
2018-02-12 06:50:43 -06:00
define ( 'e_WEB_ABS' , $this -> get_override_http ( 'WEB' ));
define ( 'e_JS_ABS' , $this -> get_override_http ( 'WEB_JS' ));
define ( 'e_CSS_ABS' , $this -> get_override_http ( 'WEB_CSS' ));
// define('e_PACK_ABS', $this->get_override_http('WEB_PACKS'));
define ( 'e_WEB_IMAGE_ABS' , $this -> get_override_http ( 'WEB_IMAGES' ));
2018-09-03 14:35:03 -07:00
define ( 'e_JS' , $this -> get_override_http ( 'WEB_JS' )); // ABS Alias
define ( 'e_CSS' , $this -> get_override_http ( 'WEB_CSS' )); // ABS Alias
2018-02-12 06:50:43 -06: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' ));
2018-09-03 14:35:03 -07:00
2018-02-12 06:50:43 -06:00
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' ));
2010-03-10 12:48:05 +00:00
2020-12-03 14:20:34 -08:00
define ( 'e_CACHE_IMAGE_ABS' , $this -> get_override_http ( 'CACHE_IMAGE' ));
2018-09-03 14:35:03 -07:00
2018-02-12 06:50:43 -06:00
// Special
2018-09-03 14:35:03 -07:00
2018-02-12 06:50:43 -06:00
define ( 'e_BOOTSTRAP' , e_WEB . " bootstrap/ " );
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 );
2020-12-10 15:52:48 -08:00
$fixed_path = ( substr ( $fixed_path , 1 , 2 ) === " :/ " ? substr ( $fixed_path , 2 ) : $fixed_path );
2006-12-02 04:36:16 +00:00
return $fixed_path ;
}
2021-01-02 02:13:11 +01:00
/**
* Convert two absolute paths to a relative path between them
* @ license https :// creativecommons . org / licenses / by - sa / 3.0 / CC BY - SA 3.0
* @ see https :// stackoverflow . com / a / 2638272
* @ param $from string Absolute path of traversal source
* @ param $to string Absolute path of traversal destination
* @ return string Relative path from the source to the destination
*/
private static function getRelativePath ( $from , $to )
{
$from = is_dir ( $from ) ? rtrim ( $from , '\/' ) . '/' : $from ;
$to = is_dir ( $to ) ? rtrim ( $to , '\/' ) . '/' : $to ;
$from = str_replace ( '\\' , '/' , $from );
$to = str_replace ( '\\' , '/' , $to );
$from = explode ( '/' , $from );
$to = explode ( '/' , $to );
$relPath = $to ;
foreach ( $from as $depth => $dir )
{
if ( $dir === $to [ $depth ])
{
array_shift ( $relPath );
}
else
{
$remaining = count ( $from ) - $depth ;
if ( $remaining > 1 )
{
$padLength = ( count ( $relPath ) + $remaining - 1 ) * - 1 ;
$relPath = array_pad ( $relPath , $padLength , '..' );
break ;
}
else
{
$relPath [ 0 ] = './' . $relPath [ 0 ];
}
}
}
return implode ( '/' , $relPath );
}
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;
2020-12-19 09:50:29 -08:00
$PLUGINS_DIRECTORY = self :: getFolder ( 'plugins' );
$ADMIN_DIRECTORY = self :: getFolder ( 'admin' );
2020-12-27 11:25:48 -08:00
define ( 'ADMINDIR' , $ADMIN_DIRECTORY );
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 ); */
2020-12-27 11:25:48 -08:00
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 ;
} */
2021-01-05 12:25:28 -08:00
if ( self :: isCli ())
2020-08-11 09:57:39 -07:00
{
2021-01-05 12:25:28 -08:00
if ( ! empty ( $_SERVER [ 'argv' ]) && empty ( $_GET ))
{
parse_str ( $_SERVER [ 'argv' ][ 1 ], $_GET ); // convert argv to $_GET for script testing via CLI.
}
if ( ! empty ( $_SERVER [ '_' ]) && empty ( $_SERVER [ 'SCRIPT_FILENAME' ]))
{
$_SERVER [ 'SCRIPT_FILENAME' ] = $_SERVER [ '_' ];
}
2020-08-11 09:57:39 -07:00
}
2021-01-05 12:25:28 -08:00
2020-08-11 09:36:21 -07:00
$eSelf = ! empty ( $_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 ;
2015-05-17 12:26:53 -07:00
2018-09-03 14:35:03 -07:00
2011-05-03 22:13:59 +00:00
// START New - request uri/url detection, XSS protection
2021-01-16 08:43:51 -08:00
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 ;
2014-07-24 20:43:01 +03:00
if ( defset ( 'e_QUERY' ))
2011-05-03 22:13:59 +00:00
{
2021-01-16 08:43:51 -08:00
$requestUri .= '?' . e_QUERY ;
2011-05-03 22:13:59 +00:00
$requestUrl .= '?' . e_QUERY ;
}
}
2021-01-16 08:43:51 -08:00
2011-05-03 22:13:59 +00:00
$check = rawurldecode ( $requestUri ); // urlencoded by default
2016-08-09 11:07:49 -07:00
2011-05-03 22:13:59 +00:00
// 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 ))
{
2016-08-09 11:07:49 -07:00
// header('HTTP/1.1 403 Forbidden');
$requestUri = filter_var ( $requestUri , FILTER_SANITIZE_URL );
// exit;
2011-05-03 22:13:59 +00:00
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
// e_MENU fix
2021-02-06 12:48:19 -08:00
if ( deftrue ( 'e_MENU' ))
2011-05-03 22:13:59 +00:00
{
2012-01-02 12:45:21 +00:00
$requestUri = str_replace ( '[' . e_MENU . ']' , '' , $requestUri );
$requestUrl = str_replace ( '[' . e_MENU . ']' , '' , $requestUrl );
2020-12-19 09:50:29 -08:00
if ( defset ( 'e_QUERY' ))
{
2021-02-06 12:48:19 -08:00
parse_str ( str_replace ( '&' , '&' , e_QUERY ), $_GET );
2020-12-19 09:50:29 -08:00
}
2011-05-03 22:13:59 +00:00
}
2011-04-25 11:29:21 +00:00
2011-05-03 22:13:59 +00:00
define ( 'e_REQUEST_URL' , str_replace ( array ( " ' " , '"' ), array ( '%27' , '%22' ), $requestUrl )); // full request url string (including domain)
2016-02-14 19:00:12 -08:00
$tmp = explode ( '?' , e_REQUEST_URL );
$requestSelf = array_shift ( $tmp );
2018-09-03 14:35:03 -07:00
2015-02-02 16:57:39 -08:00
if ( substr ( $requestSelf , - 4 ) !== '.php' && substr ( $requestSelf , - 1 ) !== '/' )
{
2018-09-03 14:35:03 -07:00
$requestSelf .= '/' ; // Always include a trailing slash on SEF Urls so that e_REQUEST_SELF."?".e_QUERY doesn't break.
2015-02-02 16:57:39 -08:00
}
// the last anti-XSS measure, XHTML compliant URL to be used in forms instead e_SELF
2016-02-14 19:00:12 -08:00
2016-12-01 15:38:40 -08:00
define ( 'e_REQUEST_SELF' , filter_var ( $requestSelf , FILTER_SANITIZE_URL )); // full URL without the QUERY string
2011-05-03 22:13:59 +00:00
define ( 'e_REQUEST_URI' , str_replace ( array ( " ' " , '"' ), array ( '%27' , '%22' ), $requestUri )); // absolute http path + query string
2016-02-14 19:00:12 -08:00
$tmp2 = explode ( '?' , e_REQUEST_URI );
define ( 'e_REQUEST_HTTP' , array_shift ( $tmp2 )); // SELF URL without the QUERY string and leading domain part
2015-05-20 11:45:52 -07:00
2017-02-10 07:39:03 -08:00
if ( ! deftrue ( 'e_SINGLE_ENTRY' ) && ! deftrue ( 'e_SELF_OVERRIDE' ) )
2015-05-20 11:45:52 -07:00
{
$page = substr ( strrchr ( $_SERVER [ 'PHP_SELF' ], '/' ), 1 );
2020-12-27 09:48:02 -08:00
if ( ! empty ( $_SERVER [ '_' ]) && self :: isCli ())
2015-05-20 11:45:52 -07:00
{
$page = basename ( $_SERVER [ '_' ]);
}
define ( 'e_PAGE' , $page );
2016-12-01 15:38:40 -08:00
define ( 'e_SELF' , filter_var ( $_self , FILTER_SANITIZE_URL ));
2015-05-20 11:45:52 -07:00
}
else
{
define ( 'e_SELF' , e_REQUEST_SELF );
2017-02-10 07:39:03 -08:00
if ( deftrue ( 'e_SELF_OVERRIDE' )) // see multisite plugin.
{
define ( 'e_PAGE' , basename ( $_SERVER [ 'SCRIPT_FILENAME' ]));
}
2015-05-20 11:45:52 -07:00
}
2011-05-03 22:13:59 +00:00
unset ( $requestUrl , $requestUri );
// END request uri/url detection, XSS protection
2020-12-27 11:25:48 -08:00
$curPage = ! empty ( $_SERVER [ 'SCRIPT_FILENAME' ]) ? basename ( $_SERVER [ 'SCRIPT_FILENAME' ]) : '' ;
$_SERVER [ 'REQUEST_URI' ] = isset ( $_SERVER [ 'REQUEST_URI' ]) ? $_SERVER [ 'REQUEST_URI' ] : '' ;
2009-11-22 14:10:09 +00:00
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
2020-12-27 11:25:48 -08:00
$inAdminDir = $this -> inAdminDir ( $e107Path , $curPage , $isPluginDir );
// e_SELF has the full HTML path
2009-12-02 16:51:04 +00:00
2009-12-13 19:51:36 +00:00
if ( $isPluginDir )
{
$temp = substr ( $e107Path , strpos ( $e107Path , '/' ) + 1 );
$plugDir = substr ( $temp , 0 , strpos ( $temp , '/' ));
2016-08-29 14:39:48 -07:00
define ( 'e_CURRENT_PLUGIN' , rtrim ( $plugDir , '/' ));
2009-12-13 19:51:36 +00:00
define ( 'e_PLUGIN_DIR' , e_PLUGIN . e_CURRENT_PLUGIN . '/' );
define ( 'e_PLUGIN_DIR_ABS' , e_PLUGIN_ABS . e_CURRENT_PLUGIN . '/' );
}
else
{
2015-04-03 18:41:21 -07:00
// define('e_CURRENT_PLUGIN', ''); // leave it undefined so it can be added later during sef-url detection.
2009-12-13 19:51:36 +00:00
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
2015-04-20 11:27:31 -07:00
if ( ! defined ( 'e_ADMIN_AREA' ))
{
define ( 'e_ADMIN_AREA' , ( $inAdminDir && ! deftrue ( 'USER_AREA' )));
}
2018-02-12 06:50:43 -06:00
return $this ;
}
2015-04-16 20:25:18 -07:00
2020-12-27 11:25:48 -08:00
/**
* Internal Use Only .
2020-12-27 12:13:51 -08:00
* @ param string $e107Path
* @ param string $curPage
* @ param bool $isPluginDir
2020-12-27 11:25:48 -08:00
* @ return bool
*/
public function inAdminDir ( $e107Path , $curPage , $isPluginDir )
{
$inAdminDir = false ;
$eplug_admin = ! empty ( $GLOBALS [ 'eplug_admin' ]);
2020-12-27 12:13:51 -08:00
if ( $eplug_admin || deftrue ( 'ADMIN_AREA' ))
2020-12-27 11:25:48 -08:00
{
2020-12-27 12:13:51 -08:00
return true ;
2020-12-27 11:25:48 -08:00
}
2020-12-27 12:13:51 -08:00
if ( strpos ( $e107Path , ADMINDIR ) === 0 ) // core admin.
{
$inAdminDir = true ;
}
elseif ( $isPluginDir ) // plugin admin areas
{
if ( $curPage === 'prefs.php' || $curPage === 'config.php' || strpos ( $curPage , 'admin_' ) === 0 )
{
$inAdminDir = true ;
}
elseif ( strpos ( $e107Path , 'admin/' ) !== false || strpos ( $curPage , '_admin.php' ) !== false || strpos ( $curPage , '_config.php' ) !== false )
{
$inAdminDir = true ;
}
}
2020-12-27 11:25:48 -08:00
return $inAdminDir ;
2020-12-27 12:13:51 -08:00
2020-12-27 11:25:48 -08:00
}
2018-02-12 06:50:43 -06:00
/**
* The second part of e107 :: set_urls ()
* Supposed to load after database has been initialized
*
* Implemented out of necessity due to
* https :// github . com / e107inc / e107 / issues / 3033
*
* @ return e107
*/
public function set_urls_deferred ()
{
2015-04-16 20:25:18 -07:00
if ( self :: isCli ())
{
2015-05-17 12:26:53 -07:00
define ( 'SITEURL' , self :: getPref ( 'siteurl' ));
define ( 'SITEURLBASE' , rtrim ( SITEURL , '/' ));
2015-04-16 20:25:18 -07:00
}
else
{
2016-12-02 12:04:08 -08:00
define ( 'SITEURLBASE' , $this -> HTTP_SCHEME . '://' . filter_var ( $_SERVER [ 'HTTP_HOST' ], FILTER_SANITIZE_URL ));
2015-04-16 20:25:18 -07:00
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' ));
2018-09-03 14:35:03 -07:00
2011-06-07 02:20:27 +00:00
if ( ! defined ( 'e_LOGIN' ))
{
2018-09-03 14:35:03 -07:00
define ( 'e_LOGIN' , SITEURL . ( file_exists ( e_BASE . 'customlogin.php' ) ? 'customlogin.php' : 'login.php' ));
2011-06-07 02:20:27 +00:00
}
2016-04-06 19:43:31 -07:00
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
/**
2021-02-06 12:48:19 -08:00
* Defines e_QUERY in a format that can be used in HTML and defines e_MENU
2011-05-03 22:13:59 +00:00
* @ param boolean $no_cbrace remove curly brackets from the url
2021-02-06 12:48:19 -08:00
* @ return string parsed query string .
2009-11-24 16:30:08 +00:00
*/
2021-02-06 12:48:19 -08:00
public function set_request ( $no_cbrace = true , $queryString = null )
2009-11-24 16:30:08 +00:00
{
2010-02-09 20:43:54 +00:00
2021-02-06 12:48:19 -08:00
if ( $queryString === null )
{
$queryString = $_SERVER [ 'QUERY_STRING' ] ;
}
2020-01-19 12:21:13 -08:00
$inArray = array ( " ' " , '/**/' , '/UNION/' , '/SELECT/' , 'AS ' );
2020-12-29 10:04:33 -08:00
foreach ( $inArray as $res )
2009-11-24 16:30:08 +00:00
{
2021-02-06 12:48:19 -08:00
if ( stripos ( $queryString , $res ) !== false )
2020-12-29 10:04:33 -08:00
{
die ( 'Access denied.' );
2009-11-24 16:30:08 +00:00
}
}
2009-12-02 16:51:04 +00:00
2021-02-06 12:48:19 -08:00
$eMENUQry = str_replace ( array ( '%5B' , '%5D' ), array ( '[' , ']' ), $queryString ); //FIX for urlencoded QUERY_STRING without breaking the '+' used by debug.
2015-01-20 17:01:57 -08:00
if ( strpos ( $eMENUQry , ']' ) && preg_match ( '#\[(.*?)](.*)#' , $eMENUQry , $matches ))
2009-11-24 16:30:08 +00:00
{
2021-02-06 12:48:19 -08:00
if ( ! defined ( 'e_MENU' ))
{
define ( 'e_MENU' , $matches [ 1 ]);
}
2009-11-24 16:30:08 +00:00
$e_QUERY = $matches [ 2 ];
}
else
{
2021-02-06 12:48:19 -08:00
if ( ! defined ( 'e_MENU' ))
{
define ( 'e_MENU' , '' );
}
$e_QUERY = $queryString ;
2009-11-24 16:30:08 +00:00
}
2010-05-05 15:05:32 +00:00
2020-12-19 09:50:29 -08:00
if ( $no_cbrace )
{
$e_QUERY = str_replace ( array ( '{' , '}' , '%7B' , '%7b' , '%7D' , '%7d' ), '' , rawurldecode ( $e_QUERY ));
}
2018-09-03 14:35:03 -07:00
$e_QUERY = htmlspecialchars ( self :: getParser () -> post_toForm ( $e_QUERY ));
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
{
2021-02-06 12:48:19 -08:00
if ( ! defined ( 'e_QUERY' ))
{
define ( 'e_QUERY' , $e_QUERY );
$_SERVER [ 'QUERY_STRING' ] = $e_QUERY ;
}
2011-06-17 01:13:05 +00:00
}
2020-12-10 15:52:48 -08:00
2021-02-06 12:48:19 -08:00
if ( ! defined ( 'e_TBQS' )) // for the unit tests.
{
define ( 'e_TBQS' , $_SERVER [ 'QUERY_STRING' ]);
}
2018-09-03 14:35:03 -07:00
2021-02-06 12:48:19 -08:00
return $e_QUERY ;
2009-11-24 16:30:08 +00:00
}
2015-03-09 15:05:34 -07:00
2012-12-15 10:25:14 +02:00
/**
* Basic implementation of Browser cache control per user session . Awaiting improvement in future versions
2015-03-09 15:05:34 -07:00
* If no argument is passed it returns
2012-12-15 10:25:14 +02:00
* 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
2015-03-09 15:05:34 -07:00
* @ param null $set
2018-09-03 12:08:44 -07:00
* @ return bool | null
2012-12-15 10:25:14 +02:00
*/
public static function canCache ( $set = null )
{
2017-01-27 11:14:11 -08:00
$_data = self :: getSession () -> get ( '__sessionBrowserCache' );
2020-12-19 09:50:29 -08:00
if ( ! is_array ( $_data ))
{
$_data = array ();
}
2018-10-31 07:27:38 -05:00
2020-12-19 09:50:29 -08:00
if ( $set === null )
2012-12-15 10:25:14 +02:00
{
return in_array ( e_REQUEST_URI , $_data );
}
2018-10-31 07:27:38 -05:00
2012-12-15 10:25:14 +02:00
// remove e_REQUEST_URI from the set
2020-12-19 09:50:29 -08:00
if ( $set === false )
2012-12-15 10:25:14 +02:00
{
$check = array_search ( e_REQUEST_URI , $_data );
2020-12-19 09:50:29 -08:00
if ( $check !== false )
2012-12-15 10:25:14 +02:00
{
unset ( $_data [ $check ]);
2017-01-27 11:14:11 -08:00
self :: getSession () -> set ( '__sessionBrowserCache' , $_data );
2020-12-10 15:52:48 -08:00
return null ;
2012-12-15 10:25:14 +02:00
}
}
2018-10-31 07:27:38 -05:00
2020-12-19 09:50:29 -08:00
if ( $set === true )
2012-12-15 10:25:14 +02:00
{
$set = e_REQUEST_URI ;
}
2018-10-31 07:27:38 -05:00
2020-12-19 09:50:29 -08:00
if ( empty ( $set ) || ! is_string ( $set ) || in_array ( $set , $_data ))
{
return null ;
}
2018-10-31 07:27:38 -05:00
2012-12-15 10:25:14 +02:00
$_data [] = $set ;
2017-01-27 11:14:11 -08:00
self :: getSession () -> set ( '__sessionBrowserCache' , array_unique ( $_data ));
2012-12-15 10:25:14 +02:00
}
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
2009-07-21 16:11:02 +00:00
/**
2009-12-02 16:51:04 +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
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
{
2020-12-19 09:50:29 -08:00
return self :: getIPHandler () -> getIP ();
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
2021-01-16 08:43:51 -08:00
* @ deprecated Use getIPHandler () -> ipEncode ( $ip ) instead .
2009-07-21 16:11:02 +00:00
* @ param string $ip
* @ param string $div divider
* @ return string encoded IP
*/
2018-10-31 07:27:38 -05:00
2009-07-21 16:11:02 +00:00
public function ipEncode ( $ip , $div = ':' )
2008-11-22 12:57:42 +00:00
{
2017-01-27 11:14:11 -08:00
return self :: getIPHandler () -> ipEncode ( $ip );
2018-10-31 07:27:38 -05:00
}
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 .
2021-01-16 08:43:51 -08:00
* @ deprecated Use getIPHandler () -> ipDecode ( $ip , $IP4Legacy ); instead .
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
{
2017-01-27 11:14:11 -08:00
return self :: getIPHandler () -> ipDecode ( $ip , $IP4Legacy );
2008-11-22 12:57:42 +00:00
}
2009-12-02 16:51:04 +00:00
2008-10-19 11:35:00 +00:00
2009-07-21 16:11:02 +00:00
/**
* Retrieve & cache host name
2020-12-14 16:21:48 -08:00
* @ deprecated Use getIPHandler () -> get_host_name () instead . Still needed by some old plugins / menus .
2009-07-21 16:11:02 +00:00
* @ param string $ip_address
* @ return string host name
*/
public function get_host_name ( $ip_address )
2008-10-19 11:35:00 +00:00
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>' . __METHOD__ . ' is deprecated.</b> Use getIPHandler()->get_host_name() instead.' , E_USER_DEPRECATED ); // NO LAN
2017-12-11 17:11:22 -08:00
return self :: getIPHandler () -> get_host_name ( $ip_address );
}
2006-12-02 04:36:16 +00:00
2009-07-21 16:11:02 +00:00
/**
2021-01-16 08:43:51 -08:00
* @ deprecated Use eHelper :: parseMemorySize () instead .
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
2020-12-20 13:25:03 -08: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
2021-01-23 14:20:51 -08:00
/**
* Returns true if the number is compatible with this version of e107 .
* @ param string $version The minimum version requirement
2021-02-13 06:15:42 -08:00
* @ param string theme | plugin
2021-01-23 14:20:51 -08:00
* @ return bool
*/
2021-02-13 06:15:42 -08:00
public static function isCompatible ( $version , $mode )
2021-01-23 14:20:51 -08:00
{
2021-02-13 06:15:42 -08:00
2021-01-23 14:20:51 -08:00
$tp = e107 :: getParser ();
$e107info = [];
include ( e_ADMIN . " ver.php " ); // $e107info['e107_version'];
$e107 = $tp -> filter ( $e107info [ 'e107_version' ], 'version' );
$version = $tp -> filter ( $version , 'version' );
2021-02-13 06:15:42 -08:00
if ((( int ) $version === 1 )) // version 1, assumed to be incompatible.
2021-01-23 14:20:51 -08:00
{
2021-02-13 06:15:42 -08:00
return ( $mode === 'plugin' ) ? false : true ;
2021-01-23 14:20:51 -08:00
}
2021-01-23 15:48:09 -08:00
return version_compare ( $e107 , $version , '>=' );
2021-01-23 14:20:51 -08:00
}
2009-11-24 16:30:08 +00:00
/**
* Safe way to set ini var
* @ param string $var
* @ param string $value
2015-03-09 15:05:34 -07:00
* @ return mixed
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 ;
}
2015-03-09 15:05:34 -07:00
2011-11-25 17:24:42 +00:00
/**
* Register autoload function ( string ) or static class method - array ( 'ClassName' , 'MethodName' )
* @ param string | array $function
2015-03-09 15:05:34 -07:00
* @ param bool $prepend
* @ return bool
2011-11-25 17:24:42 +00:00
*/
public static function autoload_register ( $function , $prepend = false )
{
2018-10-31 08:22:14 -05:00
### NEW Register Autoload - do it asap
if ( ! function_exists ( 'spl_autoload_register' ))
{
// PHP >= 5.1.2 required
die_fatal_error ( 'Fatal exception - spl_autoload_* required.' );
}
2020-12-19 09:50:29 -08:00
if ( ! $prepend || ( $registered = spl_autoload_functions ()) === false )
2011-11-25 17:24:42 +00:00
{
return spl_autoload_register ( $function );
}
2018-10-31 07:27:38 -05:00
foreach ( $registered as $r )
2011-11-25 17:24:42 +00:00
{
spl_autoload_unregister ( $r );
}
2018-10-31 07:27:38 -05:00
2011-11-25 17:24:42 +00:00
$result = spl_autoload_register ( $function );
2018-10-31 07:27:38 -05:00
foreach ( $registered as $r )
2011-11-25 17:24:42 +00:00
{
2020-12-19 09:50:29 -08:00
if ( ! spl_autoload_register ( $r ))
{
$result = false ;
}
2011-11-25 17:24:42 +00:00
}
return $result ;
}
/**
* Former __autoload , generic core autoload logic
2018-10-31 07:27:38 -05:00
*
2011-11-25 17:24:42 +00:00
* 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 )
2021-01-16 08:43:51 -08:00
* At this time we could create e107 version of spl_autoload_register - e_event -> register / trigger ( 'autoload' )
2011-11-25 17:24:42 +00:00
*
* @ 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 ;
}
2018-10-31 07:27:38 -05:00
// Detect namespaced class
if ( strpos ( $className , '\\' ) !== false )
{
self :: autoload_namespaced ( $className );
return ;
}
2011-11-25 17:24:42 +00:00
$tmp = explode ( '_' , $className );
2015-03-09 15:05:34 -07:00
2011-11-25 17:24:42 +00:00
//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
2018-10-31 07:27:38 -05:00
2011-11-25 17:24:42 +00:00
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
}
2018-10-31 07:27:38 -05:00
2011-11-25 17:24:42 +00:00
// Currently only batches inside shortcodes/ folder are auto-detected,
// read the todo for e_shortcode.php related problems
2020-12-19 09:50:29 -08:00
if ( $end === 'shortcodes' )
2011-11-25 17:24:42 +00:00
{
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
}
2018-10-31 07:27:38 -05:00
2011-11-25 17:24:42 +00:00
// 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 ;
2018-10-31 07:27:38 -05:00
2011-11-25 17:24:42 +00:00
default : //core libraries, core shortcode batches
// core SC batch check
$end = array_pop ( $tmp );
2020-12-19 09:50:29 -08:00
if ( $end === 'shortcodes' )
2011-11-25 17:24:42 +00:00
{
$filename = e_CORE . 'shortcodes/batch/' . $className . '.php' ; // core shortcode batch
break ;
}
2018-10-31 07:27:38 -05:00
2020-12-19 09:50:29 -08:00
$filename = self :: getHandlerPath ( $className );
2011-11-25 17:24:42 +00:00
//TODO add debug screen Auto-loaded classes - ['core: '.$filename.' - '.$className];
break ;
}
2018-10-31 07:27:38 -05:00
2015-03-09 15:05:34 -07:00
if ( ! empty ( $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
2018-10-31 07:27:38 -05:00
/**
* Autoloading logic for namespaced classes
*
* @ param $className
* @ return void
*/
private static function autoload_namespaced ( $className )
{
$levels = explode ( '\\' , $className );
// Guard against classes that are not ours
2020-12-19 09:50:29 -08:00
if ( $levels [ 0 ] !== 'e107' )
{
return ;
}
2018-10-31 07:27:38 -05:00
$levels [ 0 ] = e_HANDLER ;
$classPath = implode ( '/' , $levels ) . '.php' ;
if ( is_file ( $classPath ) && is_readable ( $classPath ))
{
include ( $classPath );
}
}
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' :
2017-01-27 11:14:11 -08:00
$ret = self :: getParser ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'sql' :
2017-01-27 11:14:11 -08:00
$ret = self :: getDb ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'ecache' :
2017-01-27 11:14:11 -08:00
$ret = self :: getCache ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'arrayStorage' :
2017-01-27 11:14:11 -08:00
$ret = self :: getArrayStorage ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'e_event' :
2017-01-27 11:14:11 -08:00
$ret = self :: getEvent ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'ns' :
2017-01-27 11:14:11 -08:00
$ret = self :: getRender ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'url' :
2017-01-27 11:14:11 -08:00
$ret = self :: getUrl ();
2009-07-23 15:29:07 +00:00
break ;
case 'admin_log' :
2020-12-21 17:46:32 -08:00
$ret = self :: getLog ();
2009-07-23 15:29:07 +00:00
break ;
case 'override' :
2017-01-27 11:14:11 -08:00
$ret = self :: getSingleton ( 'override' , e_HANDLER . 'override_class.php' );
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'notify' :
2017-01-27 11:14:11 -08:00
$ret = self :: getNotify ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2009-07-23 15:29:07 +00:00
case 'e_online' :
2017-01-27 11:14:11 -08:00
$ret = self :: getOnline ();
2009-07-23 15:29:07 +00:00
break ;
2009-12-02 16:51:04 +00:00
2011-12-28 10:01:25 +00:00
case 'eIPHandler' :
2017-01-27 11:14:11 -08:00
$ret = self :: getIPHandler ();
2011-12-28 10:01:25 +00:00
break ;
2009-07-23 15:29:07 +00:00
case 'user_class' :
2017-01-27 11:14:11 -08:00
$ret = self :: getUserClass ();
2009-07-23 15:29:07 +00:00
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
2020-01-18 18:26:35 +01:00
$this -> $name = $ret ;
2009-07-23 15:29:07 +00:00
return $ret ;
}
2013-05-27 10:54:42 +03:00
2015-03-09 15:05:34 -07:00
/**
*
*/
2021-01-16 08:43:51 -08:00
public function destruct ()
2013-05-27 10:54:42 +03:00
{
2020-12-19 09:50:29 -08:00
if ( self :: $_instance === null )
{
return ;
}
2013-05-27 10:54:42 +03:00
$print = defined ( 'E107_DBG_TIMEDETAILS' ) && E107_DBG_TIMEDETAILS ;
2016-05-08 08:59:54 -07:00
! $print || print ( '<table class="table table-striped table-condensed"><tr><td colspan="3"><b>Destructing $e107</b></td></tr>' );
2013-05-27 10:54:42 +03:00
$vars = get_object_vars ( $this );
foreach ( $vars as $name => $value )
{
if ( is_object ( $value ))
{
if ( method_exists ( $value , '__destruct' ))
{
2016-05-08 08:59:54 -07:00
! $print || print ( '<tr><td>object [property] using __destruct()</td><td>' . $name . '</td><td>' . get_class ( $value ) . '</td></tr>' );
2013-05-27 10:54:42 +03:00
$value -> __destruct ();
}
2020-12-19 09:50:29 -08:00
else
{
! $print || print ( '<tr><td>object [property]</td><td>' . $name . '</td><td>' . get_class ( $value ) . '</td></tr>' );
}
2013-05-27 10:54:42 +03:00
$this -> $name = null ;
}
}
foreach ( self :: $_registry as $path => $reg )
{
if ( is_object ( $reg ))
{
if ( method_exists ( $reg , '__destruct' ))
{
2016-05-08 08:59:54 -07:00
! $print || print ( '<tr><td>object [registry] using __destruct()</td><td>' . $path . '</td><td>' . get_class ( $reg ) . '</td></tr>' );
2013-05-27 10:54:42 +03:00
$reg -> __destruct ();
}
2020-12-19 09:50:29 -08:00
else
{
! $print || print ( '<tr><td>object [registry]</td><td>' . $path . '</td><td>' . get_class ( $reg ) . '</td></tr>' );
}
2013-05-27 10:54:42 +03:00
unset ( self :: $_registry [ $path ]);
}
2016-05-08 08:59:54 -07:00
2013-05-27 10:54:42 +03:00
}
2016-05-08 08:59:54 -07:00
if ( $print )
{
echo " </table> " ;
}
2013-05-27 10:54:42 +03:00
self :: $_registry = null ;
self :: $_instance = null ;
}
2016-12-22 17:59:29 -08:00
/**
* Check if there ' s a core e107 release available
* @ return array | bool - return array of data or false if no update available .
*/
public static function coreUpdateAvailable ()
{
// Get site version
$e107info = array ();
if ( is_readable ( e_ADMIN . " ver.php " ))
{
include ( e_ADMIN . " ver.php " ); // $e107info['e107_version'];
}
else
{
return false ;
}
2017-01-27 11:14:11 -08:00
$xml = self :: getXml ();
2016-12-22 17:59:29 -08:00
$file = " https://e107.org/releases.php " ;
2020-12-19 09:50:29 -08:00
if ( ! $xdata = $xml -> loadXMLfile ( $file , true ))
2016-12-22 17:59:29 -08:00
{
return false ;
}
$curVersion = str_replace ( ' (git)' , '' , $e107info [ 'e107_version' ]);
if ( empty ( $xdata [ 'core' ][ 0 ][ '@attributes' ][ 'version' ]))
{
return false ;
}
else
{
$newVersion = $xdata [ 'core' ][ 0 ][ '@attributes' ][ 'version' ];
}
2017-01-27 11:14:11 -08:00
self :: getDebug () -> log ( " New Version: " . $newVersion );
2016-12-22 17:59:29 -08:00
if ( version_compare ( $curVersion , $newVersion ) === - 1 )
{
2021-01-24 15:33:39 -08:00
return array (
2016-12-22 17:59:29 -08:00
'name' => $xdata [ 'core' ][ 0 ][ '@attributes' ][ 'name' ],
'url' => $xdata [ 'core' ][ 0 ][ '@attributes' ][ 'url' ],
'date' => $xdata [ 'core' ][ 0 ][ '@attributes' ][ 'date' ],
'version' => $xdata [ 'core' ][ 0 ][ '@attributes' ][ 'version' ],
'infourl' => $xdata [ 'core' ][ 0 ][ '@attributes' ][ 'infourl' ],
'description' => $xdata [ 'core' ][ 0 ][ 'description' ],
);
}
return false ;
}
2006-12-02 04:36:16 +00:00
}
2018-10-31 08:22:14 -05:00
2021-01-05 08:54:09 -08:00
if ( ! isset ( $GLOBALS [ '_E107' ][ 'no_autoload' ]))
2018-12-23 03:24:09 -06:00
{
2021-01-05 08:54:09 -08:00
e107 :: autoload_register ( array ( e107 :: class , 'autoload' ));
// Forward compatibility with e107 v3 Composer autoloading
$vendor_autoload_file = __DIR__ . " /vendor/autoload.php " ;
if ( file_exists ( $vendor_autoload_file ))
{
include_once ( $vendor_autoload_file );
}
2018-12-23 03:24:09 -06:00
}
2019-03-04 12:41:10 -08:00
/**
* Interface e_admin_addon_interface @ move to separate addons file ?
*/
interface e_admin_addon_interface
{
/**
* Return a list of values for the currently viewed list page .
* @ param string $event
* @ param string $ids comma separated primary ids to return in the array .
* @ return array with primary id as keys and array of fields key / pair values .
*/
public function load ( $event , $ids );
/**
* Extend Admin - ui Parameters
* @ param $ui admin - ui object
* @ return array
*/
public function config ( e_admin_ui $ui );
/**
* Process Posted Data .
* @ param $ui admin - ui object
* @ param int $id
*/
public function process ( e_admin_ui $ui , $id = 0 );
}