BxDolModuleTemplate.php 5.3 KB

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