1
0

BxDolModuleTemplate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. function addCss($mixedFiles, $bDynamic = false)
  29. {
  30. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  31. }
  32. function addJs($mixedFiles, $bDynamic = false)
  33. {
  34. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  35. }
  36. function addJsTranslation($mixedKey)
  37. {
  38. BxDolTemplate::getInstance()->addJsTranslation($mixedKey);
  39. }
  40. function addStudioCss($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  41. {
  42. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  43. }
  44. function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  45. {
  46. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  47. }
  48. function _addFiles($oTemplate, $sFuncAddFiles, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true)
  49. {
  50. $sLocationKey = $bSearchInModule ? $oTemplate->$sFuncAddLocation($this->_oConfig->getName(), $this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath) : '';
  51. $mixedResult = $oTemplate->$sFuncAddFiles($mixedFiles, $bDynamic);
  52. if($sLocationKey != '')
  53. $oTemplate->$sFuncRemoveLocation($sLocationKey);
  54. return $mixedResult;
  55. }
  56. function addStudioInjection($sKey, $sType, $sData, $iReplace = 0)
  57. {
  58. BxDolStudioTemplate::getInstance()->aPage['injections']['page_0'][$sKey][] = array(
  59. 'page_index' => 0,
  60. 'key' => $sKey,
  61. 'type' => $sType,
  62. 'data' => $sData,
  63. 'replace' => $iReplace
  64. );
  65. }
  66. function pageStart ()
  67. {
  68. if (0 == $this->_bObStarted) {
  69. ob_start ();
  70. $this->_bObStarted = 1;
  71. }
  72. }
  73. function pageEnd ($isGetContent = true)
  74. {
  75. if (1 == $this->_bObStarted) {
  76. $sRet = '';
  77. if ($isGetContent)
  78. $sRet = ob_get_clean();
  79. else
  80. ob_end_clean();
  81. $this->_bObStarted = 0;
  82. return $sRet;
  83. }
  84. }
  85. }
  86. /** @} */