BxDolModuleTemplate.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 addCss($mixedFiles, $bDynamic = false)
  39. {
  40. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  41. }
  42. function addJs($mixedFiles, $bDynamic = false)
  43. {
  44. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  45. }
  46. function addJsTranslation($mixedKey)
  47. {
  48. BxDolTemplate::getInstance()->addJsTranslation($mixedKey);
  49. }
  50. function addStudioCss($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  51. {
  52. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  53. }
  54. function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  55. {
  56. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  57. }
  58. function _addFiles($oTemplate, $sFuncAddFiles, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true)
  59. {
  60. $sLocationKey = '';
  61. $bLocationRemove = false;
  62. if($bSearchInModule) {
  63. if(strpos($sFuncAddLocation, 'Dynamic') === false) {
  64. $sLocationKey = $this->_oConfig->getName();
  65. if(!$oTemplate->isLocation($sLocationKey)) {
  66. $sLocationKey = $oTemplate->$sFuncAddLocation($sLocationKey, $this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
  67. $bLocationRemove = true;
  68. }
  69. }
  70. else {
  71. $sLocationKey = $oTemplate->$sFuncAddLocation($this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
  72. $bLocationRemove = true;
  73. }
  74. }
  75. $mixedResult = $oTemplate->$sFuncAddFiles($mixedFiles, $bDynamic);
  76. if($bLocationRemove && $sLocationKey != '')
  77. $oTemplate->$sFuncRemoveLocation($sLocationKey);
  78. return $mixedResult;
  79. }
  80. function addStudioInjection($sKey, $sType, $sData, $iReplace = 0)
  81. {
  82. BxDolStudioTemplate::getInstance()->aPage['injections']['page_0'][$sKey][] = array(
  83. 'page_index' => 0,
  84. 'key' => $sKey,
  85. 'type' => $sType,
  86. 'data' => $sData,
  87. 'replace' => $iReplace
  88. );
  89. }
  90. function pageStart ()
  91. {
  92. if (0 == $this->_bObStarted) {
  93. ob_start ();
  94. $this->_bObStarted = 1;
  95. }
  96. }
  97. function pageEnd ($isGetContent = true)
  98. {
  99. if (1 == $this->_bObStarted) {
  100. $sRet = '';
  101. if ($isGetContent)
  102. $sRet = ob_get_clean();
  103. else
  104. ob_end_clean();
  105. $this->_bObStarted = 0;
  106. return $sRet;
  107. }
  108. }
  109. }
  110. /** @} */