BxDolModuleTemplate.php 6.3 KB

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