BxDolPreloader.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. bx_import('BxDolLanguages');
  10. define('BX_PRELOADER_TYPE_CSS', 'css_system');
  11. define('BX_PRELOADER_TYPE_JS', 'js_system');
  12. define('BX_PRELOADER_TYPE_JS_OPTION', 'js_option');
  13. define('BX_PRELOADER_TYPE_JS_TRANSLATION', 'js_translation');
  14. define('BX_PRELOADER_TYPE_JS_IMAGE', 'js_image');
  15. class BxDolPreloader extends BxDolFactory implements iBxDolSingleton
  16. {
  17. protected $_oDb;
  18. protected $_aEntries;
  19. protected $_aTypes;
  20. protected $_aMarkers;
  21. protected function __construct()
  22. {
  23. parent::__construct();
  24. $this->_oDb = new BxDolPreloaderQuery();
  25. $this->_aEntries = $this->_oDb->getEntries();
  26. $this->_aTypes = array(
  27. BX_PRELOADER_TYPE_CSS => '',
  28. BX_PRELOADER_TYPE_JS => '',
  29. BX_PRELOADER_TYPE_JS_OPTION => '',
  30. BX_PRELOADER_TYPE_JS_TRANSLATION => '',
  31. BX_PRELOADER_TYPE_JS_IMAGE => ''
  32. );
  33. foreach($this->_aTypes as $sType => $sValue)
  34. $this->_aTypes[$sType] = 'add' . bx_gen_method_name($sType);
  35. $this->_aMarkers = array(
  36. 'dir_plugins_public' => BX_DIRECTORY_PATH_PLUGINS_PUBLIC,
  37. 'dir_plugins_modules' => BX_DIRECTORY_PATH_MODULES,
  38. );
  39. }
  40. public function __clone()
  41. {
  42. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  43. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  44. }
  45. public static function getInstance()
  46. {
  47. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  48. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolPreloader();
  49. return $GLOBALS['bxDolClasses'][__CLASS__];
  50. }
  51. public function perform($oTemplateSystem)
  52. {
  53. $aTypesAvail = array_keys($this->_aTypes);
  54. foreach($this->_aEntries as $aEntry) {
  55. $sType = $aEntry['type'];
  56. if(!in_array($sType, $aTypesAvail))
  57. continue;
  58. if(BxDolService::isSerializedService($aEntry['content']))
  59. $aEntry['content'] = BxDolService::callSerialized($aEntry['content']);
  60. $sContent = bx_replace_markers($aEntry['content'], $this->_aMarkers);
  61. if(empty($sContent))
  62. continue;
  63. $oTemplateSystem->{$this->_aTypes[$sType]}($sContent);
  64. }
  65. }
  66. }
  67. /** @} */