BxDolModuleTemplate.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. class BxDolModuleTemplate extends BxDolTemplate
  10. {
  11. protected $_oDb;
  12. protected $_oConfig;
  13. protected $_bObStarted = 0;
  14. protected $_oModule;
  15. /*
  16. * Constructor.
  17. */
  18. public function __construct(&$oConfig, &$oDb, $sRootPath = BX_DIRECTORY_PATH_ROOT, $sRootUrl = BX_DOL_URL_ROOT)
  19. {
  20. parent::__construct($sRootPath, $sRootUrl);
  21. $this->_oDb = &$oDb;
  22. $this->_oConfig = &$oConfig;
  23. $sName = $oConfig->getName();
  24. $sHomePath = $oConfig->getHomePath();
  25. $sHomeUrl = $oConfig->getHomeUrl();
  26. $this->addLocation($sName, $sHomePath, $sHomeUrl);
  27. $this->addLocationJs($sName, $sHomePath . 'js/', $sHomeUrl . 'js/');
  28. }
  29. public function getModule()
  30. {
  31. if (!$this->_oModule) {
  32. $sName = $this->_oConfig->getName();
  33. $this->_oModule = BxDolModule::getInstance($sName);
  34. }
  35. return $this->_oModule;
  36. }
  37. /**
  38. * Initialize module template engine.
  39. * Note. The method is executed with the system, you shouldn't execute it in your subclasses.
  40. */
  41. public function init()
  42. {
  43. $this->loadTemplates();
  44. bx_import('BxTemplFunctions');
  45. $this->_oTemplateFunctions = BxTemplFunctions::getInstance($this);
  46. }
  47. function addCssSystem($mixedFiles, $bDynamic = false)
  48. {
  49. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCssSystem', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  50. }
  51. function addCss($mixedFiles, $bDynamic = false)
  52. {
  53. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  54. }
  55. function addJsSystem($mixedFiles, $bDynamic = false)
  56. {
  57. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJsSystem', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  58. }
  59. function addJs($mixedFiles, $bDynamic = false)
  60. {
  61. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJs', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  62. }
  63. function addJsTranslation($mixedKey, $bDynamic = false)
  64. {
  65. return BxDolTemplate::getInstance()->addJsTranslation($mixedKey, $bDynamic);
  66. }
  67. function addStudioCss($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  68. {
  69. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCss', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  70. }
  71. function addStudioCssSystem($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  72. {
  73. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCssSystem', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  74. }
  75. function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  76. {
  77. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJs', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  78. }
  79. function addStudioJsSystem($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  80. {
  81. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJsSystem', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  82. }
  83. function addStudioJsTranslation($mixedKey)
  84. {
  85. BxDolStudioTemplate::getInstance()->addJsTranslation($mixedKey);
  86. }
  87. function _addFiles($oTemplate, $sFuncAddFiles, $sFuncIsLocation, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true)
  88. {
  89. $sLocationKey = '';
  90. $bLocationRemove = false;
  91. if($bSearchInModule) {
  92. if(strpos($sFuncAddLocation, 'Dynamic') === false) {
  93. $sLocationKey = $this->_oConfig->getName();
  94. if(!$oTemplate->$sFuncIsLocation($sLocationKey)) {
  95. $sLocationKey = $oTemplate->$sFuncAddLocation($sLocationKey, $this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
  96. $bLocationRemove = true;
  97. }
  98. }
  99. else {
  100. $sLocationKey = $oTemplate->$sFuncAddLocation($this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
  101. $bLocationRemove = true;
  102. }
  103. }
  104. $mixedResult = $oTemplate->$sFuncAddFiles($mixedFiles, $bDynamic);
  105. if($bLocationRemove && $sLocationKey != '')
  106. $oTemplate->$sFuncRemoveLocation($sLocationKey);
  107. return $mixedResult;
  108. }
  109. function addStudioInjection($sKey, $sType, $sData, $iReplace = 0)
  110. {
  111. BxDolStudioTemplate::getInstance()->aPage['injections']['page_0'][$sKey][] = array(
  112. 'page_index' => 0,
  113. 'key' => $sKey,
  114. 'type' => $sType,
  115. 'data' => $sData,
  116. 'replace' => $iReplace
  117. );
  118. }
  119. function pageStart ()
  120. {
  121. if (0 == $this->_bObStarted) {
  122. ob_start ();
  123. $this->_bObStarted = 1;
  124. }
  125. }
  126. function pageEnd ($isGetContent = true)
  127. {
  128. if (1 == $this->_bObStarted) {
  129. $sRet = '';
  130. if ($isGetContent)
  131. $sRet = ob_get_clean();
  132. else
  133. ob_end_clean();
  134. $this->_bObStarted = 0;
  135. return $sRet;
  136. }
  137. }
  138. public function addCssJs()
  139. {
  140. }
  141. public function isMethodExists($s)
  142. {
  143. return method_exists($this->_oProxifiedObject, $s);
  144. }
  145. }
  146. /** @} */