PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/e107_handlers/e107_class.php

https://github.com/CasperGemini/e107
PHP | 3742 lines | 1991 code | 446 blank | 1305 comment | 316 complexity | a517ec26db31667465c4b0d116aef157 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2012 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. * e107 Main
  10. *
  11. * $URL$
  12. * $Id$
  13. */
  14. if (!defined('e107_INIT')) { exit; }
  15. /**
  16. *
  17. * @package e107
  18. * @category e107_handlers
  19. * @version $Id$
  20. * @author e107inc
  21. *
  22. * e107_class - core class with many system-related methods
  23. */
  24. class e107
  25. {
  26. /**
  27. * IPV6 string for localhost - as stored in DB
  28. */
  29. const LOCALHOST_IP = '0000:0000:0000:0000:0000:ffff:7f00:0001';
  30. public $server_path;
  31. public $e107_dirs = array();
  32. /**
  33. * @var array SQL connection data
  34. */
  35. protected $e107_config_mysql_info = array();
  36. public $http_path;
  37. public $https_path;
  38. public $base_path;
  39. public $file_path;
  40. public $site_path;
  41. public $relative_base_path;
  42. public $_ip_cache;
  43. public $_host_name_cache;
  44. public $site_theme; // class2 -> check valid theme
  45. public $http_theme_dir; // class2 -> check valid theme
  46. /**
  47. * Contains reference to global $_E107 array
  48. * Assignment is done inside prepare_request() method
  49. *
  50. * @var array
  51. */
  52. protected $_E107 = array();
  53. /**
  54. * @var string Current request type (http or https)
  55. */
  56. protected $HTTP_SCHEME;
  57. /**
  58. * Used for runtime caching of user extended struct
  59. *
  60. * @var array
  61. * @see get_user_data()
  62. */
  63. public $extended_struct;
  64. /**
  65. * User login name
  66. *
  67. * @var string
  68. * @see init_session()
  69. */
  70. public $currentUser = '';
  71. /**
  72. * Run once load core shortcodes
  73. * while initialize SC parser
  74. *
  75. * @var boolean
  76. */
  77. protected static $_sc_core_loaded = false;
  78. /**
  79. * Singleton instance
  80. * Allow class extends - override {@link getInstance()}
  81. *
  82. * @var e107
  83. */
  84. protected static $_instance = null;
  85. /**
  86. * e107 registry
  87. *
  88. * @var array
  89. */
  90. private static $_registry = array();
  91. /**
  92. * e107 core config object storage
  93. *
  94. * @var array
  95. */
  96. protected static $_core_config_arr = array();
  97. /**
  98. * e107 plugin config object storage
  99. *
  100. * @var array
  101. */
  102. protected static $_plug_config_arr = array();
  103. /**
  104. * Core handlers array
  105. * For new/missing handler add
  106. * 'class name' => 'path' pair
  107. *
  108. * Used to auto-load core/plugin handlers
  109. * NOTE: aplhabetically sorted! (by class name)
  110. *
  111. * @see addHandler()
  112. * @see setHandlerOverload()
  113. * @see getSingleton()
  114. * @see getObject()
  115. * @var array
  116. */
  117. protected static $_known_handlers = array(
  118. 'UserHandler' => '{e_HANDLER}user_handler.php',
  119. 'comment' => '{e_HANDLER}comment_class.php',
  120. 'convert' => '{e_HANDLER}date_handler.php',
  121. 'db' => '{e_HANDLER}mysql_class.php',
  122. 'e107Email' => '{e_HANDLER}mail.php',
  123. 'e107_event' => '{e_HANDLER}event_class.php',
  124. 'e107_db_debug' => '{e_HANDLER}db_debug_class.php',
  125. 'e107_traffic' => '{e_HANDLER}traffic_class.php',
  126. 'e107_user_extended' => '{e_HANDLER}user_extended_class.php',
  127. 'e107plugin' => '{e_HANDLER}plugin_class.php',
  128. 'e_chart' => '{e_HANDLER}chart_class.php',
  129. 'e_core_session' => '{e_HANDLER}session_handler.php',
  130. 'e_admin_controller' => '{e_HANDLER}admin_ui.php',
  131. 'e_admin_controller_ui' => '{e_HANDLER}admin_ui.php',
  132. 'e_admin_dispatcher' => '{e_HANDLER}admin_ui.php',
  133. 'e_admin_form_ui' => '{e_HANDLER}admin_ui.php',
  134. 'e_admin_log' => '{e_HANDLER}admin_log_class.php',
  135. 'e_admin_model' => '{e_HANDLER}model_class.php',
  136. 'e_admin_request' => '{e_HANDLER}admin_ui.php',
  137. 'e_admin_response' => '{e_HANDLER}admin_ui.php',
  138. 'e_admin_ui' => '{e_HANDLER}admin_ui.php',
  139. 'e_array' => '{e_HANDLER}core_functions.php', // Old ArrayStorage.
  140. 'e_bbcode' => '{e_HANDLER}bbcode_handler.php',
  141. 'e_bb_base' => '{e_HANDLER}bbcode_handler.php',
  142. 'e_file' => '{e_HANDLER}file_class.php',
  143. 'e_form' => '{e_HANDLER}form_handler.php',
  144. 'e_jshelper' => '{e_HANDLER}js_helper.php',
  145. 'e_media' => '{e_HANDLER}media_class.php',
  146. 'e_menu' => '{e_HANDLER}menu_class.php',
  147. 'e_model' => '{e_HANDLER}model_class.php',
  148. 'e_navigation' => '{e_HANDLER}sitelinks_class.php',
  149. 'e_news_item' => '{e_HANDLER}news_class.php',
  150. 'e_news_tree' => '{e_HANDLER}news_class.php',
  151. 'e_object' => '{e_HANDLER}model_class.php',
  152. 'e_online' => '{e_HANDLER}online_class.php',
  153. 'e_parse' => '{e_HANDLER}e_parse_class.php',
  154. 'e_parser' => '{e_HANDLER}e_parse_class.php',
  155. 'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php',
  156. 'e_ranks' => '{e_HANDLER}e_ranks_class.php',
  157. 'e_shortcode' => '{e_HANDLER}shortcode_handler.php',
  158. 'e_system_user' => '{e_HANDLER}user_model.php',
  159. 'e_upgrade' => '{e_HANDLER}e_upgrade_class.php',
  160. 'e_user_model' => '{e_HANDLER}user_model.php',
  161. 'e_user' => '{e_HANDLER}user_model.php',
  162. 'e_user_extended_structure_tree' => '{e_HANDLER}user_model.php',
  163. 'e_userperms' => '{e_HANDLER}user_handler.php',
  164. 'e_validator' => '{e_HANDLER}validator_class.php',
  165. 'e_vars' => '{e_HANDLER}model_class.php',
  166. 'ecache' => '{e_HANDLER}cache_handler.php',
  167. 'eController' => '{e_HANDLER}application.php',
  168. 'eDispatcher' => '{e_HANDLER}application.php',
  169. 'eException' => '{e_HANDLER}application.php',
  170. 'eFront' => '{e_HANDLER}application.php',
  171. 'eHelper' => '{e_HANDLER}application.php',
  172. 'eIPHandler' => '{e_HANDLER}iphandler_class.php',
  173. 'email_validation_class' => '{e_HANDLER}mail_validation_class.php',
  174. 'eMessage' => '{e_HANDLER}message_handler.php',
  175. 'eRequest' => '{e_HANDLER}application.php',
  176. 'eResponse' => '{e_HANDLER}application.php',
  177. 'eRouter' => '{e_HANDLER}application.php',
  178. 'eUrl' => '{e_HANDLER}e107Url.php',
  179. 'eUrlConfig' => '{e_HANDLER}application.php',
  180. 'eUrlRule' => '{e_HANDLER}application.php',
  181. 'Hybrid_Auth' => '{e_HANDLER}hybridauth/Hybrid/Auth.php',
  182. 'language' => '{e_HANDLER}language_class.php',
  183. 'news' => '{e_HANDLER}news_class.php',
  184. 'notify' => '{e_HANDLER}notify_class.php',
  185. 'override' => '{e_HANDLER}override_class.php',
  186. 'rater' => '{e_HANDLER}rate_class.php',
  187. 'redirection' => '{e_HANDLER}redirection_class.php',
  188. 'secure_image' => '{e_HANDLER}secure_img_handler.php',
  189. 'sitelinks' => '{e_HANDLER}sitelinks_class.php',
  190. 'themeHandler' => '{e_HANDLER}theme_handler.php',
  191. 'user_class' => '{e_HANDLER}userclass_class.php',
  192. 'userlogin' => '{e_HANDLER}login.php',
  193. 'validatorClass' => '{e_HANDLER}validator_class.php',
  194. 'xmlClass' => '{e_HANDLER}xml_class.php',
  195. );
  196. /**
  197. * Overload core handlers array
  198. * Format: 'core_class' => array('overload_class', 'overload_path');
  199. *
  200. * NOTE: to overload core singleton objects, you have to add record to
  201. * $_overload_handlers before the first singleton call.
  202. *
  203. * Example:
  204. * <code> array('e_form' => array('plugin_myplugin_form_handler' => '{e_PLUGIN}myplugin/includes/form/handler.php'));</code>
  205. *
  206. * Used to auto-load core handlers
  207. *
  208. * @var array
  209. */
  210. protected static $_overload_handlers = array();
  211. /**
  212. * Constructor
  213. *
  214. * Use {@link getInstance()}, direct instantiating
  215. * is not possible for singleton objects
  216. *
  217. * @return void
  218. */
  219. protected function __construct()
  220. {
  221. // FIXME registered shutdown functions not executed after the $page output in footer - investigate
  222. // Currently manually called in front-end/admin footer
  223. //register_shutdown_function(array($this, 'destruct'));
  224. }
  225. /**
  226. * Cloning is not allowed
  227. *
  228. */
  229. private function __clone()
  230. {
  231. }
  232. /**
  233. * Get singleton instance (php4 no more supported)
  234. *
  235. * @return e107
  236. */
  237. public static function getInstance()
  238. {
  239. if(null == self::$_instance)
  240. {
  241. self::$_instance = new self();
  242. }
  243. return self::$_instance;
  244. }
  245. /**
  246. * Initialize environment path constants
  247. * Public proxy to the protected method {@link _init()}
  248. *
  249. * @return e107
  250. */
  251. public function initCore($e107_paths, $e107_root_path, $e107_config_mysql_info, $e107_config_override = array())
  252. {
  253. return $this->_init($e107_paths, $e107_root_path, $e107_config_mysql_info, $e107_config_override);
  254. }
  255. /**
  256. * Initialize environment path constants while installing e107
  257. *
  258. * @return e107
  259. */
  260. public function initInstall($e107_paths, $e107_root_path, $e107_config_override = array())
  261. {
  262. $e107_config = 'e107_config.php';
  263. if (!file_exists($e107_config)) // prevent blank-page with missing file during install.
  264. {
  265. if(file_put_contents($e107_config, '')===false)
  266. {
  267. return false;
  268. }
  269. }
  270. // Do some security checks/cleanup, prepare the environment
  271. $this->prepare_request();
  272. //generated from mysql data at stage 5 of install.
  273. $this->site_path = isset($e107_config_override['site_path']) ? $e107_config_override['site_path'] : "[hash]"; // placeholder
  274. // folder info
  275. //$this->e107_dirs = $e107_paths;
  276. $this->setDirs($e107_paths, $e107_config_override);
  277. // build all paths
  278. $this->set_paths();
  279. $this->file_path = $this->fix_windows_paths($e107_root_path)."/";
  280. // set base path, SSL is auto-detected
  281. $this->set_base_path();
  282. // cleanup QUERY_STRING and friends, set related constants
  283. $this->set_request();
  284. // set some core URLs (e_LOGIN/SIGNUP)
  285. $this->set_urls();
  286. return $this;
  287. }
  288. /**
  289. * Resolve paths, will run only once
  290. *
  291. * @return e107
  292. */
  293. protected function _init($e107_paths, $e107_root_path, $e107_config_mysql_info, $e107_config_override = array())
  294. {
  295. if(empty($this->e107_dirs))
  296. {
  297. // Do some security checks/cleanup, prepare the environment
  298. $this->prepare_request();
  299. // mysql connection info
  300. $this->e107_config_mysql_info = $e107_config_mysql_info;
  301. // unique folder for e_MEDIA - support for multiple websites from single-install. Must be set before setDirs()
  302. $this->site_path = $this->makeSiteHash($e107_config_mysql_info['mySQLdefaultdb'], $e107_config_mysql_info['mySQLprefix']);
  303. // Set default folder (and override paths) if missing from e107_config.php
  304. $this->setDirs($e107_paths, $e107_config_override);
  305. // various constants - MAGIC_QUOTES_GPC, MPREFIX, ...
  306. $this->set_constants();
  307. // build all paths
  308. $this->set_paths();
  309. $this->file_path = $this->fix_windows_paths($e107_root_path)."/";
  310. // set base path, SSL is auto-detected
  311. $this->set_base_path();
  312. // cleanup QUERY_STRING and friends, set related constants
  313. $this->set_request();
  314. // set some core URLs (e_LOGIN/SIGNUP)
  315. $this->set_urls();
  316. }
  317. return $this;
  318. }
  319. // Create a unique hash for each database configuration (multi-site support)
  320. function makeSiteHash($db,$prefix) // also used by install.
  321. {
  322. return substr(md5($db.".".$prefix),0,10);
  323. }
  324. /**
  325. * Set system folders and override paths
  326. * $e107_paths is the 'compact' version of e107_config folder vars ($ADMIN_DIRECTORY, $IMAGES_DIRECTORY, etc)
  327. * $e107_config_override is the new override method - it can do it for all server and http paths via
  328. * the newly introduced $E107_CONFIG array.
  329. *
  330. * Overriding just replace _DIRECTORY with _SERVER or _HTTP:
  331. * - override server path example:
  332. * <code>$E107_CONFIG['SYSTEM_SERVER'] = '/home/user/system/';</code>
  333. *
  334. * - override http path example:
  335. * <code>$E107_CONFIG['MEDIA_VIDEOS_HTTP'] = 'http://static.mydomain.com/videos/';</code>
  336. *
  337. * @param array $e107_dirs Override folder instructions (*_DIRECTORY vars - e107_config.php)
  338. * @param array $e107_config_override Override path insructions ($E107_CONFIG array - e107_config.php)
  339. * @return e107
  340. */
  341. public function setDirs($e107_dirs, $e107_config_override = array())
  342. {
  343. $override = array_merge((array) $e107_dirs, (array) $e107_config_override);
  344. // override all
  345. $this->e107_dirs = array_merge($this->defaultDirs($override), $override);
  346. // TODO add e_MEDIA_BASE, e_SYSTEM_BASE (free of site path constants);
  347. if(strpos($this->e107_dirs['MEDIA_DIRECTORY'],$this->site_path) === false)
  348. {
  349. $this->e107_dirs['MEDIA_DIRECTORY'] .= $this->site_path."/"; // multisite support.
  350. }
  351. if(strpos($this->e107_dirs['SYSTEM_DIRECTORY'],$this->site_path) === false)
  352. {
  353. $this->e107_dirs['SYSTEM_DIRECTORY'] .= $this->site_path."/"; // multisite support.
  354. }
  355. // FIXME Quick fix - override base cache folder for legacy configs (e.g. e107_files/cache), discuss
  356. if(strpos($this->e107_dirs['CACHE_DIRECTORY'], $this->site_path) === false)
  357. {
  358. $this->e107_dirs['CACHE_DIRECTORY'] = $this->e107_dirs['SYSTEM_DIRECTORY']."cache/"; // multisite support.
  359. }
  360. return $this;
  361. }
  362. /**
  363. * Get default e107 folders, root folders can be overridden by passed override array
  364. *
  365. * @param array $override_root
  366. * @param boolean $return_root
  367. * @return array
  368. */
  369. public function defaultDirs($override_root = array(), $return_root = false)
  370. {
  371. $ret = array_merge(array(
  372. 'ADMIN_DIRECTORY' => 'e107_admin/',
  373. 'IMAGES_DIRECTORY' => 'e107_images/',
  374. 'THEMES_DIRECTORY' => 'e107_themes/',
  375. 'PLUGINS_DIRECTORY' => 'e107_plugins/',
  376. 'FILES_DIRECTORY' => 'e107_files/', // DEPRECATED!!!
  377. 'HANDLERS_DIRECTORY' => 'e107_handlers/',
  378. 'LANGUAGES_DIRECTORY' => 'e107_languages/',
  379. 'DOCS_DIRECTORY' => 'e107_docs/',
  380. 'MEDIA_DIRECTORY' => 'e107_media/',
  381. 'SYSTEM_DIRECTORY' => 'e107_system/',
  382. 'CORE_DIRECTORY' => 'e107_core/',
  383. 'WEB_DIRECTORY' => 'e107_web/',
  384. ), (array) $override_root);
  385. $ret['MEDIA_DIRECTORY'] .= $this->site_path."/"; // multisite support.
  386. $ret['SYSTEM_DIRECTORY'] .= $this->site_path."/"; // multisite support.
  387. if($return_root) return $ret;
  388. $ret['HELP_DIRECTORY'] = $ret['DOCS_DIRECTORY'].'help/';
  389. $ret['MEDIA_IMAGES_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'images/';
  390. $ret['MEDIA_ICONS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'icons/';
  391. $ret['MEDIA_VIDEOS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'videos/';
  392. $ret['MEDIA_FILES_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'files/';
  393. $ret['MEDIA_UPLOAD_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'temp/'; // security measure. Media is public, system is private.
  394. $ret['AVATARS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'avatars/';
  395. $ret['WEB_JS_DIRECTORY'] = $ret['WEB_DIRECTORY'].'js/';
  396. // $ret['WEB_JS_DIRECTORY'] = $ret['FILES_DIRECTORY'].'jslib/';
  397. $ret['WEB_CSS_DIRECTORY'] = $ret['WEB_DIRECTORY'].'css/';
  398. $ret['WEB_IMAGES_DIRECTORY'] = $ret['WEB_DIRECTORY'].'images/';
  399. // $ret['WEB_PACKS_DIRECTORY'] = $ret['WEB_DIRECTORY'].'packages/';
  400. $ret['DOWNLOADS_DIRECTORY'] = $ret['MEDIA_FILES_DIRECTORY'];
  401. $ret['UPLOADS_DIRECTORY'] = $ret['MEDIA_UPLOAD_DIRECTORY'];
  402. $ret['CACHE_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'cache/';
  403. $ret['CACHE_CONTENT_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'content/';
  404. $ret['CACHE_IMAGE_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'images/';
  405. $ret['CACHE_DB_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'db/';
  406. $ret['CACHE_URL_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'url/';
  407. $ret['AVATARS_UPLOAD_DIRECTORY'] = $ret['AVATARS_DIRECTORY'].'upload/';
  408. $ret['AVATARS_DEFAULT_DIRECTORY'] = $ret['AVATARS_DIRECTORY'].'default/';
  409. $ret['LOGS_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'logs/';
  410. $ret['BACKUP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'backup/';
  411. $ret['TEMP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'temp/';
  412. $ret['IMPORT_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'import/';
  413. //TODO create directories which don't exist.
  414. return $ret;
  415. }
  416. /**
  417. * Set mysql data
  418. *
  419. * @return e107
  420. */
  421. public function initInstallSql($e107_config_mysql_info)
  422. {
  423. // mysql connection info
  424. $this->e107_config_mysql_info = $e107_config_mysql_info;
  425. // various constants - MAGIC_QUOTES_GPC, MPREFIX, ...
  426. $this->set_constants();
  427. return $this;
  428. }
  429. /**
  430. * Get data from the registry
  431. * Returns $default if data not found
  432. * Replacement of cachevar()
  433. *
  434. * @param string $id
  435. * @return mixed
  436. */
  437. public static function getRegistry($id, $default = null)
  438. {
  439. if(isset(self::$_registry[$id]))
  440. {
  441. return self::$_registry[$id];
  442. }
  443. return $default;
  444. }
  445. /**
  446. * Add data to the registry - replacement of getcachedvars().
  447. * $id is path-like unique id bind to the passed data.
  448. * If $data argument is null, $id will be removed from the registry.
  449. * When removing objects from the registry, __destruct() method will be auto-executed
  450. * if available
  451. *
  452. * Naming standards (namespaces):
  453. * 'area/area_id/storage_type'<br>
  454. * where <br>
  455. * - area = 'core'|'plugin'|'external' (everything else)
  456. * - area_id = core handler id|plugin name (depends on area)
  457. * - (optional) storage_type = current data storage stack
  458. *
  459. * Examples:
  460. * - 'core/e107/' - reserved for this class
  461. * - 'core/e107/singleton/' - singleton objects repo {@link getSingleton()}
  462. *
  463. * @param string $id
  464. * @param mixed|null $data
  465. * @return void
  466. */
  467. public static function setRegistry($id, $data = null, $allow_override = true)
  468. {
  469. if(null === $data)
  470. {
  471. if(is_object(self::$_registry[$id]) && method_exists(self::$_registry[$id], '__destruct'))
  472. {
  473. self::$_registry[$id]->__destruct();
  474. }
  475. unset(self::$_registry[$id]);
  476. return;
  477. }
  478. if(!$allow_override && null !== self::getRegistry($id))
  479. {
  480. return;
  481. }
  482. self::$_registry[$id] = $data;
  483. }
  484. /**
  485. * Get folder name (e107_config)
  486. * Replaces all $(*)_DIRECTORY globals
  487. * Example: <code>$e107->getFolder('images')</code>;
  488. *
  489. * @param string $for
  490. * @return string
  491. */
  492. function getFolder($for)
  493. {
  494. $key = strtoupper($for).'_DIRECTORY';
  495. $self = self::getInstance();
  496. return (isset($self->e107_dirs[$key]) ? $self->e107_dirs[$key] : '');
  497. }
  498. /**
  499. * Get value from $_E107 config array
  500. * Note: will always return false if called before prepare_request() method!
  501. *
  502. * @param string $key
  503. * @return boolean
  504. */
  505. public static function getE107($key = null)
  506. {
  507. $self = self::getInstance();
  508. if(null === $key) return $self->_E107;
  509. return (isset($self->_E107[$key]) && $self->_E107[$key] ? true : false);
  510. }
  511. /**
  512. * Convenient proxy to $_E107 getter - check if
  513. * the system is currently running in cli mode
  514. * Note: will always return false if called before prepare_request() method!
  515. *
  516. * @return boolean
  517. */
  518. public static function isCli()
  519. {
  520. return self::getE107('cli');
  521. }
  522. /**
  523. * Get mysql config var (e107_config.php)
  524. * Replaces all $mySQL(*) globals
  525. * Example: <code>$e107->getMySQLConfig('prefix');</code>
  526. *
  527. * @param string $for prefix|server|user|password|defaultdb - leave blank for full array.
  528. * @return string or array
  529. */
  530. function getMySQLConfig($for='')
  531. {
  532. $key = 'mySQL'.$for;
  533. $self = self::getInstance();
  534. if($for == '')
  535. {
  536. return $self->e107_config_mysql_info;
  537. }
  538. return (isset($self->e107_config_mysql_info[$key]) ? $self->e107_config_mysql_info[$key] : '');
  539. }
  540. /**
  541. * Return a unique path based on database used. ie. multi-site support from single install.
  542. *
  543. * @return string
  544. * @author
  545. */
  546. function getSitePath()
  547. {
  548. $self = self::getInstance();
  549. return $self->site_path;
  550. }
  551. /**
  552. * Get known handler path
  553. *
  554. * @param string $class_name
  555. * @param boolean $parse_path [optional] parse path shortcodes
  556. * @return string|null
  557. */
  558. public static function getHandlerPath($class_name, $parse_path = true)
  559. {
  560. $ret = isset(self::$_known_handlers[$class_name]) ? self::$_known_handlers[$class_name] : null;
  561. if($parse_path && $ret)
  562. {
  563. $ret = self::getParser()->replaceConstants($ret);
  564. }
  565. return $ret;
  566. }
  567. /**
  568. * Add handler to $_known_handlers array on runtime
  569. * If class name is array, method will add it (recursion) and ignore $path argument
  570. *
  571. * @param array|string $class_name
  572. * @param string $path [optional]
  573. * @return void
  574. */
  575. public static function addHandler($class_name, $path = '')
  576. {
  577. if(is_array($class_name))
  578. {
  579. foreach ($class_name as $cname => $path)
  580. {
  581. self::addHandler($cname, $path);
  582. }
  583. return;
  584. }
  585. if(!self::isHandler($class_name))
  586. {
  587. self::$_known_handlers[$class_name] = $path;
  588. }
  589. }
  590. /**
  591. * Check handler presence
  592. *
  593. * @param string $class_name
  594. * @return boolean
  595. */
  596. public static function isHandler($class_name)
  597. {
  598. return isset(self::$_known_handlers[$class_name]);
  599. }
  600. /**
  601. * Get overlod class and path (if any)
  602. *
  603. * @param object $class_name
  604. * @param object $default_handler [optional] return data from $_known_handlers if no overload data available
  605. * @param object $parse_path [optional] parse path shortcodes
  606. * @return array
  607. */
  608. public static function getHandlerOverload($class_name, $default_handler = true, $parse_path = true)
  609. {
  610. $ret = (isset(self::$_overload_handlers[$class_name]) ? self::$_overload_handlers[$class_name] : ($default_handler ? array($class_name, self::getHandlerPath($class_name, false)) : array()));
  611. if ($parse_path && isset($ret[1]))
  612. {
  613. $ret[1] = self::getParser()->replaceConstants($ret[1]);
  614. }
  615. return $ret;
  616. }
  617. /**
  618. * Overload present handler.
  619. * If class name is array, method will add it (recursion) and
  620. * ignore $overload_class_name and $overload_path arguments
  621. *
  622. * @param string $class_name
  623. * @param string $overload_name [optional]
  624. * @param string $overload_path [optional]
  625. * @return void
  626. */
  627. public static function setHandlerOverload($class_name, $overload_class_name = '', $overload_path = '')
  628. {
  629. if(is_array($class_name))
  630. {
  631. foreach ($class_name as $cname => $overload_array)
  632. {
  633. self::setHandlerOverload($cname, $overload_array[0], $overload_array[1]);
  634. }
  635. return;
  636. }
  637. if(self::isHandler($class_name) && !self::isHandlerOverloadable($class_name))
  638. {
  639. self::$_overload_handlers[$class_name] = array($overload_class_name, $overload_path);
  640. }
  641. }
  642. /**
  643. * Check if handler is already overloaded
  644. *
  645. * @param string $class_name
  646. * @return boolean
  647. */
  648. public static function isHandlerOverloadable($class_name)
  649. {
  650. return isset(self::$_overload_handlers[$class_name]);
  651. }
  652. /**
  653. * Retrieve singleton object
  654. *
  655. * @param string $class_name
  656. * @param string|boolean $path optional script path
  657. * @param string $regpath additional registry path
  658. * @return Object
  659. */
  660. public static function getSingleton($class_name, $path = true, $regpath = '')
  661. {
  662. $id = 'core/e107/singleton/'.$class_name.$regpath;
  663. //singleton object found - overload not possible
  664. if(self::getRegistry($id))
  665. {
  666. return self::getRegistry($id);
  667. }
  668. //auto detection + overload check
  669. if(is_bool($path))
  670. {
  671. //overload allowed
  672. if(true === $path && self::isHandlerOverloadable($class_name))
  673. {
  674. $tmp = self::getHandlerOverload($class_name);
  675. $class_name = $tmp[0];
  676. $path = $tmp[1];
  677. }
  678. //overload not allowed
  679. else
  680. {
  681. $path = self::getHandlerPath($class_name);
  682. }
  683. }
  684. if($path && is_string($path) && !class_exists($class_name, false))
  685. {
  686. e107_require_once($path); //no existence/security checks here!
  687. //e107_require_once() is available without class2.php. - see core_functions.php
  688. }
  689. if(class_exists($class_name, false))
  690. {
  691. e107::setRegistry($id, new $class_name());
  692. }
  693. return self::getRegistry($id);
  694. }
  695. /**
  696. * Retrieve object
  697. * Prepare for __autoload
  698. *
  699. * @param string $class_name
  700. * @param mxed $arguments
  701. * @param string|boolean $path optional script path
  702. * @return object|null
  703. */
  704. public static function getObject($class_name, $arguments = null, $path = true)
  705. {
  706. if(true === $path)
  707. {
  708. if(isset(self::$_known_handlers[$class_name]))
  709. {
  710. $path = self::getParser()->replaceConstants(self::$_known_handlers[$class_name]);
  711. }
  712. }
  713. //auto detection + overload check
  714. if(is_bool($path))
  715. {
  716. //overload allowed
  717. if(true === $path && self::isHandlerOverloadable($class_name))
  718. {
  719. $tmp = self::getHandlerOverload($class_name);
  720. $class_name = $tmp[0];
  721. $path = $tmp[1];
  722. }
  723. //overload not allowed
  724. else
  725. {
  726. $path = self::getHandlerPath($class_name);
  727. }
  728. }
  729. if($path && is_string($path) && !class_exists($class_name, false))
  730. {
  731. e107_require_once($path); //no existence/security checks here!
  732. }
  733. if(class_exists($class_name, false))
  734. {
  735. if(null !== $arguments) return new $class_name($arguments);
  736. return new $class_name();
  737. }
  738. trigger_error("Class {$class_name} not found!", E_USER_ERROR);
  739. return null;
  740. }
  741. /**
  742. * Retrieve core config handlers.
  743. * List of allowed $name values (aliases) could be found
  744. * in {@link e_core_pref} class
  745. *
  746. * @param string $name core|core_backup|emote|menu|search|notify
  747. * @return e_core_pref
  748. */
  749. public static function getConfig($name = 'core', $load = true, $refresh=false)
  750. {
  751. if(isset(self::$_plug_config_arr[$name])) //FIXME Load pluginPref Object instead - Not quite working with calendar_menu.
  752. {
  753. return self::getPlugConfig($name);
  754. }
  755. if(!isset(self::$_core_config_arr[$name]) || ($refresh == true)) // required by update_routines to clear out earlier values.
  756. {
  757. e107_require_once(e_HANDLER.'pref_class.php');
  758. self::$_core_config_arr[$name] = new e_core_pref($name, $load);
  759. if($name == 'core') // prevent loop between pref and cache handlers.
  760. {
  761. e107::getCache()->UserCacheActive = self::getPref('cachestatus');
  762. e107::getCache()->SystemCacheActive = self::getPref('syscachestatus');
  763. }
  764. }
  765. return self::$_core_config_arr[$name];
  766. }
  767. /**
  768. * Retrieve core config handler preference value or the core preference array
  769. * Shorthand of self::getConfig()->get()
  770. *
  771. * @see e_core_pref::get()
  772. * @param string $pref_name
  773. * @param mixed $default default value if preference is not found
  774. * @return mixed
  775. */
  776. public static function getPref($pref_name = '', $default = null)
  777. {
  778. return empty($pref_name) ? self::getConfig()->getPref() : self::getConfig()->get($pref_name, $default);
  779. }
  780. /**
  781. * Advanced version of self::getPref(). $pref_name is parsed,
  782. * so that $pref_name = 'x/y/z' will search for value pref_data[x][y][z]
  783. * Shorthand of self::getConfig()->getPref()
  784. *
  785. * @see e_core_pref::getPref()
  786. * @param string $pref_name
  787. * @param mixed $default default value if preference is not found
  788. * @return mixed
  789. */
  790. public static function findPref($pref_name, $default = null, $index = null)
  791. {
  792. return self::getConfig()->getPref($pref_name, $default, $index);
  793. }
  794. /**
  795. * Retrieve plugin config handlers.
  796. * Multiple plugin preference DB rows are supported
  797. * Class overload is supported.
  798. * Examples:
  799. * - <code>e107::getPluginConfig('myplug');</code>
  800. * will search for e107_plugins/myplug/e_pref/myplug_pref.php which
  801. * should contain class 'e_plugin_myplug_pref' class (child of e_plugin_pref)
  802. * - <code>e107::getPluginConfig('myplug', 'row2');</code>
  803. * will search for e107_plugins/myplug/e_pref/myplug_row2_pref.php which
  804. * should contain class 'e_plugin_myplug_row2_pref' class (child of e_plugin_pref)
  805. *
  806. * @param string $plug_name
  807. * @param string $multi_row
  808. * @param boolean $load load from DB on startup
  809. * @return e_plugin_pref
  810. */
  811. public static function getPlugConfig($plug_name, $multi_row = '', $load = true)
  812. {
  813. if(!isset(self::$_plug_config_arr[$plug_name.$multi_row]))
  814. {
  815. e107_require_once(e_HANDLER.'pref_class.php');
  816. $override_id = $plug_name.($multi_row ? "_{$multi_row}" : '');
  817. //check (once) for custom plugin pref handler
  818. if(is_readable(e_PLUGIN.$plug_name.'/e_pref/'.$override_id.'_pref.php'))
  819. {
  820. require_once(e_PLUGIN.$plug_name.'/e_pref/'.$override_id.'_pref.php');
  821. $class_name = 'e_plugin_'.$override_id.'_pref';
  822. //PHPVER: string parameter for is_subclass_of require PHP 5.0.3+
  823. if(class_exists($class_name, false) && is_subclass_of('e_plugin_pref', $class_name)) //or e_pref ?
  824. {
  825. self::$_plug_config_arr[$plug_name.$multi_row] = new $class_name($load);
  826. return self::$_plug_config_arr[$plug_name.$multi_row];
  827. }
  828. }
  829. self::$_plug_config_arr[$plug_name.$multi_row] = new e_plugin_pref($plug_name, $multi_row, $load);
  830. }
  831. return self::$_plug_config_arr[$plug_name.$multi_row];
  832. }
  833. /**
  834. * Retrieve plugin preference value.
  835. * Shorthand of self::getPluginConfig()->get()
  836. * NOTE: Multiple plugin preference DB rows are NOT supported
  837. * This will only look for your default plugin config (empty $milti_row)
  838. *
  839. * @see e_plugin_pref::get()
  840. * @param string $plug_name
  841. * @param string $pref_name
  842. * @param mixed $default default value if preference is not found
  843. * @return mixed
  844. */
  845. public static function getPlugPref($plug_name, $pref_name = '', $default = null)
  846. {
  847. return empty($pref_name) ? self::getPlugConfig($plug_name)->getPref() : self::getPlugConfig($plug_name)->get($pref_name, $default);
  848. }
  849. /**
  850. * Advanced version of self::getPlugPref(). $pref_name is parsed,
  851. * so that $pref_name = 'x/y/z' will search for value pref_data[x][y][z]
  852. * Shorthand of self::getPluginConfig()->getPref()
  853. *
  854. * @see e_core_pref::getPref()
  855. * @param string $pref_name
  856. * @param mixed $default default value if preference is not found
  857. * @return mixed
  858. */
  859. public static function findPlugPref($plug_name, $pref_name, $default = null, $index = null)
  860. {
  861. return self::getPlugConfig($plug_name)->getPref($pref_name, $default, $index);
  862. }
  863. /**
  864. * Get current theme preference. $pref_name is parsed,
  865. * so that $pref_name = 'x/y/z' will search for value pref_data[x][y][z]
  866. * Shorthand of self::getConfig()->getPref('current_theme/sitetheme_pref/pref_name')
  867. *
  868. * @see e_core_pref::getPref()
  869. * @param string $pref_name
  870. * @param mixed $default default value if preference is not found
  871. * @return mixed
  872. */
  873. public static function getThemePref($pref_name = '', $default = null, $index = null)
  874. {
  875. if($pref_name) $pref_name = '/'.$pref_name;
  876. return e107::getConfig()->getPref('sitetheme_pref'.$pref_name, $default, $index);
  877. }
  878. /**
  879. * Set current theme preference. $pref_name is parsed,
  880. * so that $pref_name = 'x/y/z' will set value pref_data[x][y][z]
  881. *
  882. * @param string|array $pref_name
  883. * @param mixed $pref_value
  884. * @return e_pref
  885. */
  886. public static function setThemePref($pref_name, $pref_value = null)
  887. {
  888. if(is_array($pref_name)) return e107::getConfig()->set('sitetheme_pref', $pref_name);
  889. return e107::getConfig()->updatePref('sitetheme_pref/'.$pref_name, $pref_value, false);
  890. }
  891. /**
  892. * Retrieve text parser singleton object
  893. *
  894. * @return e_parse
  895. */
  896. public static function getParser()
  897. {
  898. return self::getSingleton('e_parse', e_HANDLER.'e_parse_class.php'); //WARNING - don't change this - infinite loop!!!
  899. }
  900. /**
  901. * Retrieve sc parser singleton object
  902. *
  903. * @return e_parse_shortcode
  904. */
  905. public static function getScParser()
  906. {
  907. return self::getSingleton('e_parse_shortcode', true);
  908. }
  909. /**
  910. * Retrieve secure_image singleton object
  911. *
  912. * @return secure_image
  913. */
  914. public static function getSecureImg()
  915. {
  916. return self::getSingleton('secure_image', true); // more flexible.
  917. // return self::getObject('secure_image');
  918. }
  919. /**
  920. * Retrieve registered sc object (batch) by class name
  921. * Note - '_shortcodes' part of the class/override is added by the method
  922. * Override is possible only if class is not already instantiated by shortcode parser
  923. *
  924. * <code><?php
  925. *
  926. * // Core news shortcodes (news_shortcodes.php using class news_shortcodes )
  927. * e107::getScObject('news');
  928. *
  929. * // Core page shortcodes (page_shortcodes.php.php with class cpage_shortcode)
  930. * e107::getScObject('page', null,'cpage');
  931. *
  932. * // object of plugin_myplugin_my_shortcodes class -> myplugin/shortcodes/batch/my_shortcodes.php
  933. * e107::getScObject('my', 'myplugin');
  934. *
  935. * // news override - plugin_myplugin_news_shortcodes extends news_shortcodes -> myplugin/shortcodes/batch/news_shortcodes.php
  936. * e107::getScObject('news', 'myplugin', true);
  937. *
  938. * // news override - plugin_myplugin_mynews_shortcodes extends news_shortcodes -> myplugin/shortcodes/batch/mynews_shortcodes.php
  939. * e107::getScObject('news', 'myplugin', 'mynews');
  940. * </code>
  941. *
  942. * @param string $className
  943. * @param string $pluginName
  944. * @param string|true $overrideClass
  945. * @return e_shortcode
  946. */
  947. public static function getScBatch($className, $pluginName = null, $overrideClass = null)
  948. {
  949. if(is_string($overrideClass)) $overrideClass .= '_shortcodes';
  950. return self::getScParser()->getScObject($className.'_shortcodes', $pluginName, $overrideClass);
  951. }
  952. /**
  953. * Retrieve DB singleton object based on the
  954. * $instance_id
  955. *
  956. * @param string $instance_id
  957. * @return e_db_mysql
  958. */
  959. public static function getDb($instance_id = '')
  960. {
  961. return self::getSingleton('db', true, $instance_id);
  962. }
  963. /**
  964. * Retrieve cache singleton object
  965. *
  966. * @return ecache
  967. */
  968. public static function getCache()
  969. {
  970. return self::getSingleton('ecache', true);
  971. }
  972. /**
  973. * Retrieve bbcode singleton object
  974. *
  975. * @return e_bbcode
  976. */
  977. public static function getBB()
  978. {
  979. return self::getSingleton('e_bbcode', true);
  980. }
  981. /**
  982. * Retrieve user-session singleton object
  983. *
  984. * @return UserHandler
  985. */
  986. public static function getUserSession()
  987. {
  988. return self::getSingleton('UserHandler', true);
  989. }
  990. /**
  991. * Retrieve core session singleton object(s)
  992. *
  993. * @return e_core_session
  994. */
  995. public static function getSession($namespace = null)
  996. {
  997. $id = 'core/e107/session/'.(null === $namespace ? 'e107' : $namespace);
  998. if(self::getRegistry($id))
  999. {
  1000. return self::getRegistry($id);
  1001. }
  1002. $session = self::getObject('e_core_session', array('namespace' => $namespace), true);
  1003. self::setRegistry($id, $session);
  1004. return $session;
  1005. }
  1006. /**
  1007. * Retrieve redirection singleton object
  1008. *
  1009. * @return redirection
  1010. */
  1011. public static function getRedirect()
  1012. {
  1013. return self::getSingleton('redirection', true);
  1014. }
  1015. /**
  1016. * Retrieve rater singleton object
  1017. *
  1018. * @return rate
  1019. */
  1020. public static function getRate()
  1021. {
  1022. return self::getSingleton('rater', true);
  1023. }
  1024. /**
  1025. * Retrieve sitelinks singleton object
  1026. *
  1027. * @return sitelinks
  1028. */
  1029. public static function getSitelinks()
  1030. {
  1031. return self::getSingleton('sitelinks', true);
  1032. }
  1033. /**
  1034. * Retrieve render singleton object
  1035. *
  1036. * @return e107table
  1037. */
  1038. public static function getRender()
  1039. {
  1040. return self::getSingleton('e107table');
  1041. }
  1042. /**
  1043. * Retrieve e107Email singleton object
  1044. *
  1045. * @return e107Email
  1046. */
  1047. public static function getEmail()
  1048. {
  1049. return self::getSingleton('e107Email', true);
  1050. }
  1051. /**
  1052. * Retrieve event singleton object
  1053. *
  1054. * @return e107_event
  1055. */
  1056. public static function getEvent()
  1057. {
  1058. return self::getSingleton('e107_event', true);
  1059. }
  1060. /**
  1061. * Retrieve array storage singleton object
  1062. *
  1063. * @return e_array
  1064. */
  1065. public static function getArrayStorage()
  1066. {
  1067. return self::getSingleton('e_array', true);
  1068. }
  1069. /**
  1070. * Retrieve menu handler singleton object
  1071. *
  1072. * @return e_menu
  1073. */
  1074. public static function getMenu()
  1075. {
  1076. return self::getSingleton('e_menu', true);
  1077. }
  1078. /**
  1079. * Retrieve URL singleton object
  1080. *
  1081. * @return eURL
  1082. */
  1083. public static function getUrl()
  1084. {
  1085. return self::getSingleton('eUrl', true);
  1086. }
  1087. /**
  1088. * Retrieve file handler singleton or new fresh object
  1089. *
  1090. * @param boolean $singleton default true
  1091. * @return e_file
  1092. */
  1093. public static function getFile($singleton = false)
  1094. {
  1095. if($singleton)
  1096. {
  1097. return self::getSingleton('e_file', true);
  1098. }
  1099. return self::getObject('e_file', null, true);
  1100. }
  1101. /**
  1102. * Retrieve form handler singleton or new fresh object
  1103. *
  1104. * @param boolean $singleton default false
  1105. * @param boolean $tabindex passed to e_form when initialized as an object (not singleton)
  1106. * @return e_form
  1107. */
  1108. public static function getForm($singleton = false, $tabindex = false)
  1109. {
  1110. if($singleton)
  1111. {
  1112. return self::getSingleton('e_form', true);
  1113. }
  1114. return self::getObject('e_form', $tabindex, true);
  1115. }
  1116. /**
  1117. * Retrieve admin log singleton object
  1118. *
  1119. * @return e_admin_log
  1120. */
  1121. public static function getAdminLog()
  1122. {
  1123. return self::getSingleton('e_admin_log', true);
  1124. }
  1125. /**
  1126. * Retrieve date handler singleton object
  1127. *
  1128. * @return convert
  1129. */
  1130. public static function getDateConvert()
  1131. {
  1132. return self::getSingleton('convert', true);
  1133. }
  1134. /**
  1135. * Retrieve date handler singleton object - preferred method.
  1136. *
  1137. * @return convert
  1138. */
  1139. public static function getDate()
  1140. {
  1141. return self::getSingleton('convert', true);
  1142. }
  1143. /**
  1144. * Retrieve date handler singleton object - preferred method.
  1145. *
  1146. * @return convert
  1147. */
  1148. public static function getDebug() //XXX Discuss - possible with current setup?
  1149. {
  1150. return self::getSingleton('e107_db_debug', true);
  1151. }
  1152. /**
  1153. * Retrieve notify handler singleton object
  1154. *
  1155. * @return notify
  1156. */
  1157. public static function getNotify()
  1158. {
  1159. return self::getSingleton('notify', true);
  1160. }
  1161. /**
  1162. * Retrieve override handler singleton object
  1163. *
  1164. * @return notify
  1165. */
  1166. public static function getOverride()
  1167. {
  1168. return self::getSingleton('override', true);
  1169. }
  1170. /**
  1171. * Retrieve Language handler singleton object
  1172. *
  1173. * @return language
  1174. */
  1175. public static function getLanguage()
  1176. {
  1177. return self::getSingleton('language', true);
  1178. }
  1179. /**
  1180. * Retrieve IP/ban handler singleton object
  1181. *
  1182. * @return eIPHandler
  1183. */
  1184. public static function getIPHandler()
  1185. {
  1186. return self::getSingleton('eIPHandler', true);
  1187. }
  1188. /**
  1189. * Retrieve Xml handler singleton or new instance object
  1190. * @param mixed $singleton false - new instance, true - singleton from default registry location, 'string' - registry path
  1191. * @return xmlClass
  1192. */
  1193. public static function getXml($singleton = true)
  1194. {
  1195. if($singleton)
  1196. {
  1197. return self::getSingleton('xmlClass', true, (true === $singleton ? '' : $singleton));
  1198. }
  1199. return self::getObject('xmlClass', null, true);
  1200. }
  1201. /**
  1202. * Retrieve HybridAuth object
  1203. *
  1204. * @return Hybrid_Auth
  1205. */
  1206. public static function getHybridAuth($config = null)
  1207. {
  1208. if(null === $config)
  1209. {
  1210. $config = array(
  1211. 'base_url' => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)),
  1212. 'providers' => e107::getPref('social_login', array()),
  1213. 'debug_mode' => false,
  1214. 'debug_file' => ''
  1215. );
  1216. }
  1217. return new Hybrid_Auth($config);
  1218. }
  1219. /**
  1220. * Retrieve userclass singleton object
  1221. *
  1222. * @return user_class
  1223. */
  1224. public static function getUserClass()
  1225. {
  1226. return self::getSingleton('user_class', true);
  1227. }
  1228. /**
  1229. * Retrieve user model object.
  1230. *
  1231. * @param integer $user_id target user
  1232. * @param boolean $checkIfCurrent if tru user_id will be compared to current user, if there is a match
  1233. * current user object will be returned
  1234. * @return e_system_user
  1235. */
  1236. public static function getSystemUser($user_id, $checkIfCurrent = true)
  1237. {
  1238. if($checkIfCurrent && $user_id && $user_id === self::getUser()->getId())
  1239. {
  1240. return self::getUser();
  1241. }
  1242. if(!$user_id) return self::getObject('e_system_user');
  1243. $user = self::getRegistry('core/e107/user/'.$user_id);
  1244. if(null === $user)
  1245. {
  1246. $user = self::getObject('e_system_user');
  1247. if($user_id) $user->load($user_id); // self registered on load
  1248. }
  1249. return $user;
  1250. }
  1251. /**
  1252. * Simple replacement for deprecated get_user_data(). e107::user();
  1253. * @param $uid integer user_id or leave empty for currently logged in user.
  1254. * @return array of user data
  1255. */
  1256. public static function user($uid=null)
  1257. {
  1258. if(!$uid){ return false; }
  1259. $user = self::getSystemUser($uid, true);
  1260. $var = array();
  1261. if($user)
  1262. {
  1263. $var = $user->getUserData();
  1264. }
  1265. return $var;
  1266. }
  1267. /**
  1268. * Return a string containg exported array data. - preferred.
  1269. *
  1270. * @param array $ArrayData array to be stored
  1271. * @param bool $AddSlashes default false, add slashes for db storage, else false
  1272. * @return string
  1273. */
  1274. public static function serialize($ArrayData, $AddSlashes = false)
  1275. {
  1276. return self::getArrayStorage()->serialize($ArrayData, $AddSlashes);
  1277. }
  1278. /**
  1279. * Returns an array from stored array data.
  1280. *
  1281. * @param string $ArrayData
  1282. * @return array stored data
  1283. */
  1284. public static function unserialize($ArrayData)
  1285. {
  1286. return self::getArrayStorage()->unserialize($ArrayData);
  1287. }
  1288. /**
  1289. * Retrieve current user model object.
  1290. *
  1291. * @return e_user
  1292. */
  1293. public static function getUser()
  1294. {
  1295. $user = self::getRegistry('core/e107/current_user');
  1296. if(null === $user)
  1297. {
  1298. $user = self::getObject('e_user');
  1299. self::setRegistry('core/e107/current_user', $user);
  1300. }
  1301. return $user;
  1302. }
  1303. /**
  1304. * Retrieve user model object.
  1305. *
  1306. * @param integer $user_id target user
  1307. * @return e_current_user
  1308. */
  1309. public static function getUserStructure()
  1310. {
  1311. return self::getSingleton('e_user_extended_structure_tree', true);
  1312. }
  1313. /**
  1314. * Retrieve User Extended handler singleton object
  1315. * @return e107_user_extended
  1316. */
  1317. public static function getUserExt()
  1318. {
  1319. return self::getSingleton('e107_user_extended', true);
  1320. }
  1321. /**
  1322. * Retrieve User Perms (admin perms) handler singleton object
  1323. * @return e_userperms
  1324. */
  1325. public static function getUserPerms()
  1326. {
  1327. return self::getSingleton('e_userperms', true);
  1328. }
  1329. /**
  1330. * Retrieve online users handler singleton object
  1331. * @return e_ranks
  1332. */
  1333. public static function getRank()
  1334. {
  1335. return self::getSingleton('e_ranks', true);
  1336. }
  1337. /**
  1338. * Retrieve plugin handler singleton object
  1339. * @return e107plugin
  1340. */
  1341. public static function getPlugin()
  1342. {
  1343. return self::getSingleton('e107plugin', true);
  1344. }
  1345. /**
  1346. * Retrieve online users handler singleton object
  1347. * @return e_online
  1348. */
  1349. public static function getOnline()
  1350. {
  1351. return self::getSingleton('e_online', true);
  1352. }
  1353. /**
  1354. * Retrieve chart handler singleton object
  1355. * @return e_chart
  1356. */
  1357. public static function getChart()
  1358. {
  1359. return self::getSingleton('e_chart', true);
  1360. }
  1361. /**
  1362. * Retrieve comments handler singleton object
  1363. * @return comment
  1364. */
  1365. public static function getComment()
  1366. {
  1367. return self::getSingleton('comment', true);
  1368. }
  1369. /**
  1370. * Retrieve Media handler singleton object
  1371. * @return e_media
  1372. */
  1373. public static function getMedia()
  1374. {
  1375. return self::getSingleton('e_media', true);
  1376. }
  1377. /**
  1378. * Retrieve Navigation Menu handler singleton object
  1379. * @return e_navigation
  1380. */
  1381. public static function getNav()
  1382. {
  1383. return self::getSingleton('e_navigation', true);
  1384. }
  1385. /**
  1386. * Retrieve message handler singleton
  1387. * @return eMessage
  1388. */
  1389. public static function getMessage()
  1390. {
  1391. // static $included = false;
  1392. // if(!$included)
  1393. // {
  1394. // e107_require_once(e_HANDLER.'message_handler.php');
  1395. // $included = true;
  1396. // }
  1397. // return eMessage::getInstance();
  1398. return self::getSingleton('eMessage', true);
  1399. }
  1400. /**
  1401. * Retrieve JS Manager singleton object
  1402. *
  1403. * @return e_jsmanager
  1404. */
  1405. public static function getJs()
  1406. {
  1407. static $included = false;
  1408. if(!$included)
  1409. {
  1410. e107_require_once(e_HANDLER.'js_manager.php');
  1411. $included = true;
  1412. }
  1413. return e_jsmanager::getInstance();
  1414. }
  1415. /**
  1416. * JS Common Public Function. Prefered is shortcode script path
  1417. * @param string $type core|theme|footer|inline|footer-inline|url or any existing plugin_name
  1418. * @param string $data depends on the type - path/url or inline js source
  1419. * @param integer $zone [optional] leave it null for default zone
  1420. * @param string $dep dependence : null | prototype | jquery
  1421. */
  1422. public static function js($type, $data, $dep = null, $zone = null, $pre = '', $post = '')
  1423. {
  1424. $jshandler = e107::getJs();
  1425. $jshandler->setDependency($dep);
  1426. switch ($type)
  1427. {
  1428. case 'core':
  1429. // data is e.g. 'core/tabs.js'
  1430. if(null !== $zone) $jshandler->requireCoreLib($data, $zone);
  1431. else $jshandler->requireCoreLib($data);
  1432. break;
  1433. case 'bootstrap': //TODO Eventually add own method and render for bootstrap.
  1434. if(null !== $zone) $jshandler->requireCoreLib('bootstrap/js/'.$data, $zone);
  1435. else $jshandler->requireCoreLib('bootstrap/js/'.$data);
  1436. break;
  1437. case 'theme':
  1438. // data is e.g. 'jslib/mytheme.js'
  1439. if(null !== $zone) $jshandler->headerTheme($data, $zone, $pre, $post);
  1440. else $jshandler->headerTheme($data, 5, $pre, $post);
  1441. break;
  1442. case 'inline':
  1443. // data is JS source (without script tags)
  1444. if(null !== $zone) $jshandler->headerInline($data, $zone);
  1445. else $jshandler->headerInline($data);
  1446. break;
  1447. case 'footer-inline':
  1448. // data is JS source (without script tags)
  1449. if(null !== $zone) $jshandler->footerInline($data, $zone);
  1450. else $jshandler->footerInline($data);
  1451. break;
  1452. case 'url':
  1453. // data is e.g. 'http://cdn.somesite.com/some.js'
  1454. if(null !== $zone) $jshandler->headerFile($data, $zone, $pre, $post);
  1455. else $jshandler->headerFile($data, 5, $pre, $post);
  1456. break;
  1457. case 'footer':
  1458. // data is e.g. '{e_PLUGIN}myplugin/jslib/myplug.js'
  1459. if(null !== $zone) $jshandler->footerFile($data, $zone);
  1460. else $jshandler->footerFile($data);
  1461. break;
  1462. // $type is plugin name
  1463. default:
  1464. // data is e.g. 'jslib/myplug.js'
  1465. if(!self::isInstalled($type)) return;
  1466. if(null !== $zone) $jshandler->requirePluginLib($type, $data, $zone);
  1467. else $jshandler->requirePluginLib($type, $data);
  1468. break;
  1469. }
  1470. $jshandler->resetDependency();
  1471. }
  1472. /**
  1473. * CSS Common Public Function. Prefered is shortcode script path
  1474. * @param string $type core|theme|footer|inline|footer-inline|url or any existing plugin_name
  1475. * @param string $data depends on the type - path/url or inline js source
  1476. * @param string $media any valid media attribute string - http://www.w3schools.com/TAGS/att_link_media.asp
  1477. * @param string $preComment possible comment e.g. <!--[if lt IE 7]>
  1478. * @param string $postComment possible comment e.g. <![endif]-->
  1479. */
  1480. public static function css($type, $data, $dep = null, $media = 'all', $preComment = '', $postComment = '', $dependence = null)
  1481. {
  1482. if((strstr($data,'bootstrap.css') || strstr($data,'bootstrap.min.css')) && !defined("BOOTSTRAP")) // detect bootstrap is enabled. - used in nextprev.sc and forum currently.
  1483. {
  1484. define("BOOTSTRAP", true);
  1485. }
  1486. $jshandler = e107::getJs();
  1487. $jshandler->setDependency($dep);
  1488. switch ($type)
  1489. {
  1490. case 'core':
  1491. // data is path relative to e_FILE/jslib/
  1492. $jshandler->coreCSS($data, $media, $preComment, $postComment);
  1493. break;
  1494. case 'bootstrap':
  1495. // data is path relative to e_FILE/jslib/
  1496. $jshandler->coreCSS('bootstrap/css/'.$data, $media, $preComment, $postComment);
  1497. break;
  1498. case 'theme':
  1499. // data is path relative to current theme
  1500. $jshandler->themeCSS($data, $media, $preComment, $postComment);
  1501. break;
  1502. case 'inline':
  1503. // data is CSS source (without style tags)
  1504. $jshandler->inlineCSS($data, $media);
  1505. break;
  1506. case 'url':
  1507. // data is e.g. 'http://cdn.somesite.com/some.css'
  1508. $jshandler->otherCSS($data, $media, $preComment, $postComment);
  1509. break;
  1510. // $type is plugin name
  1511. default:
  1512. // data is e.g. 'css/myplug.css'
  1513. if(self::isInstalled($type)) $jshandler->pluginCSS($type, $data, $media, $preComment, $postComment);
  1514. break;
  1515. }
  1516. $jshandler->resetDependency();
  1517. }
  1518. /**
  1519. * Retrieve JS Helper object
  1520. *
  1521. * @param boolean|string $singleton if true return singleton, if string return singleton object, use string as namespace, default false
  1522. * @return e_jshelper
  1523. */
  1524. public static function getJshelper($singleton = false)
  1525. {
  1526. if($singleton)
  1527. {
  1528. return self::getSingleton('e_jshelper', true, (true === $singleton ? '' : $singleton));
  1529. }
  1530. return self::getObject('e_jshelper', null, true);
  1531. }
  1532. /**
  1533. * @see eResponse::addMeta()
  1534. * @return eResponse
  1535. */
  1536. public static function meta($name = null, $content = null, $extended = array())
  1537. {
  1538. if($name == 'description')
  1539. {
  1540. e107::getUrl()->response()->addMetaDescription($content); //Cam: TBD
  1541. }
  1542. if($name == 'keywords')
  1543. {
  1544. e107::getUrl()->response()->addMetaKeywords($content); //Cam: TBD
  1545. }
  1546. return e107::getUrl()->response()->addMeta($name, $content, $extended);
  1547. }
  1548. /**
  1549. * Retrieve admin dispatcher instance.
  1550. * It's instance is self registered (for now, this could change in the future) on initialization (__construct())
  1551. *
  1552. * @see e_admin_dispatcher
  1553. * @return e_admin_dispatcher
  1554. */
  1555. public static function getAdminUI()
  1556. {
  1557. return self::getRegistry('admin/ui/dispatcher');
  1558. }
  1559. /**
  1560. * Retrieves class Object for specific plugin's addon such as e_url.php, e_cron.php, e_sitelink.php
  1561. * FIXME override from e.g. core/override/addons/
  1562. *
  1563. * @param string $pluginName e.g. faq, page
  1564. * @param string $addonName eg. e_cron, e_url, e_module
  1565. * @param mixed $className [optional] true - use default name, false - no object is returned (include only), any string will be used as class name
  1566. * @return none
  1567. */
  1568. public static function getAddon($pluginName, $addonName, $className = true)
  1569. {
  1570. $filename = $addonName; // e.g. 'e_cron';
  1571. // fixme, temporary adding 's' to className, should be core fixed, better naming
  1572. if(true === $className) $className = $pluginName.'_'.substr($addonName, 2); // remove 'e_'
  1573. $elist = self::getPref($filename.'_list');
  1574. if(!isset($elist[$pluginName])) return null;
  1575. // TODO override check comes here
  1576. $path = e_PLUGIN.$pluginName.'/'.$filename.'.php';
  1577. // e.g. include e_module, e_meta etc
  1578. if(false === $className) return include_once($path);
  1579. if(!class_exists($className, false))
  1580. {
  1581. include_once($path);
  1582. }
  1583. if(!class_exists($className, false))
  1584. {
  1585. return null;
  1586. }
  1587. return new $className;
  1588. }
  1589. /**
  1590. * Retrieves config() from all plugins for addons such as e_url.php, e_cron.php, e_sitelink.php
  1591. * @param string $addonName eg. e_cron, e_url
  1592. * @param string $className [optional] (if different from addonName)
  1593. * @return none
  1594. */
  1595. public function getAddonConfig($addonName, $className = '')
  1596. {
  1597. $new_addon = array();
  1598. $sql = e107::getDb(); // Might be used by older plugins.
  1599. $filename = $addonName; // e.g. 'e_cron';
  1600. if(!$className)
  1601. {
  1602. $className = substr($filename, 2); // remove 'e_'
  1603. }
  1604. $elist = self::getPref($filename.'_list');
  1605. if($e

Large files files are truncated, but you can click here to view the full file