BxDolModuleTemplate.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. {
  51. }
  52. function addCssSystem($mixedFiles, $bDynamic = false)
  53. {
  54. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCssSystem', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  55. }
  56. function addCss($mixedFiles, $bDynamic = false)
  57. {
  58. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  59. }
  60. function addJsSystem($mixedFiles, $bDynamic = false)
  61. {
  62. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJsSystem', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  63. }
  64. function addJs($mixedFiles, $bDynamic = false)
  65. {
  66. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJs', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  67. }
  68. function addJsTranslation($mixedKey, $bDynamic = false)
  69. {
  70. return BxDolTemplate::getInstance()->addJsTranslation($mixedKey, $bDynamic);
  71. }
  72. function addStudioCss($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  73. {
  74. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCss', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  75. }
  76. function addStudioCssSystem($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  77. {
  78. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCssSystem', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  79. }
  80. function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  81. {
  82. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJs', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  83. }
  84. function addStudioJsSystem($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  85. {
  86. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJsSystem', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  87. }
  88. function addStudioJsTranslation($mixedKey)
  89. {
  90. BxDolStudioTemplate::getInstance()->addJsTranslation($mixedKey);
  91. }
  92. function _addFiles($oTemplate, $sFuncAddFiles, $sFuncIsLocation, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true)
  93. {
  94. $sLocationKey = '';
  95. $bLocationRemove = false;
  96. if($bSearchInModule) {
  97. if(strpos($sFuncAddLocation, 'Dynamic') === false) {
  98. $sLocationKey = $this->_oConfig->getName();
  99. if(!$oTemplate->$sFuncIsLocation($sLocationKey)) {
  100. $sLocationKey = $oTemplate->$sFuncAddLocation($sLocationKey, $this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
  101. $bLocationRemove = true;
  102. }
  103. }
  104. else {
  105. $sLocationKey = $oTemplate->$sFuncAddLocation($this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
  106. $bLocationRemove = true;
  107. }
  108. }
  109. $mixedResult = $oTemplate->$sFuncAddFiles($mixedFiles, $bDynamic);
  110. if($bLocationRemove && $sLocationKey != '')
  111. $oTemplate->$sFuncRemoveLocation($sLocationKey);
  112. return $mixedResult;
  113. }
  114. function addStudioInjection($sKey, $sType, $sData, $iReplace = 0)
  115. {
  116. BxDolStudioTemplate::getInstance()->aPage['injections']['page_0'][$sKey][] = array(
  117. 'page_index' => 0,
  118. 'key' => $sKey,
  119. 'type' => $sType,
  120. 'data' => $sData,
  121. 'replace' => $iReplace
  122. );
  123. }
  124. function pageStart ()
  125. {
  126. if (0 == $this->_bObStarted) {
  127. ob_start ();
  128. $this->_bObStarted = 1;
  129. }
  130. }
  131. function pageEnd ($isGetContent = true)
  132. {
  133. if (1 == $this->_bObStarted) {
  134. $sRet = '';
  135. if ($isGetContent)
  136. $sRet = ob_get_clean();
  137. else
  138. ob_end_clean();
  139. $this->_bObStarted = 0;
  140. return $sRet;
  141. }
  142. }
  143. public function addCssJs()
  144. {
  145. }
  146. public function isMethodExists($s)
  147. {
  148. return method_exists($this->_oProxifiedObject, $s);
  149. }
  150. }
  151. /** @} */