BxDolModuleTemplate.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. bx_import('BxDolTemplate');
  10. class BxDolModuleTemplate extends BxDolTemplate
  11. {
  12. protected $_oDb;
  13. protected $_oConfig;
  14. protected $_bObStarted = 0;
  15. /*
  16. * Constructor.
  17. */
  18. 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. $this->addLocation($sName, $sHomePath, $sHomeUrl);
  27. $this->addLocationJs($sName, $sHomePath . 'js/', $sHomeUrl . 'js/');
  28. }
  29. function addCss($mixedFiles, $bDynamic = false)
  30. {
  31. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  32. }
  33. function addJs($mixedFiles, $bDynamic = false)
  34. {
  35. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  36. }
  37. function addJsTranslation($mixedKey)
  38. {
  39. BxDolTemplate::getInstance()->addJsTranslation($mixedKey);
  40. }
  41. function addStudioCss($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  42. {
  43. bx_import('BxDolStudioTemplate');
  44. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  45. }
  46. function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true)
  47. {
  48. bx_import('BxDolStudioTemplate');
  49. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  50. }
  51. function _addFiles($oTemplate, $sFuncAddFiles, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true)
  52. {
  53. $sLocationKey = $bSearchInModule ? $oTemplate->$sFuncAddLocation($this->_oConfig->getName(), $this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath) : '';
  54. $mixedResult = $oTemplate->$sFuncAddFiles($mixedFiles, $bDynamic);
  55. if($sLocationKey != '')
  56. $oTemplate->$sFuncRemoveLocation($sLocationKey);
  57. return $mixedResult;
  58. }
  59. function addStudioInjection($sKey, $sType, $sData, $iReplace = 0)
  60. {
  61. bx_import('BxDolStudioTemplate');
  62. BxDolStudioTemplate::getInstance()->aPage['injections']['page_0'][$sKey][] = array(
  63. 'page_index' => 0,
  64. 'key' => $sKey,
  65. 'type' => $sType,
  66. 'data' => $sData,
  67. 'replace' => $iReplace
  68. );
  69. }
  70. function pageStart ()
  71. {
  72. if (0 == $this->_bObStarted) {
  73. ob_start ();
  74. $this->_bObStarted = 1;
  75. }
  76. }
  77. function pageEnd ($isGetContent = true)
  78. {
  79. if (1 == $this->_bObStarted) {
  80. $sRet = '';
  81. if ($isGetContent)
  82. $sRet = ob_get_clean();
  83. else
  84. ob_end_clean();
  85. $this->_bObStarted = 0;
  86. return $sRet;
  87. }
  88. }
  89. }
  90. /** @} */