BxDolModuleTemplate.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolTemplate');
  10. class BxDolModuleTemplate extends BxDolTemplate {
  11. protected $_oDb;
  12. protected $_oConfig;
  13. protected $_bObStarted = 0;
  14. /*
  15. * Constructor.
  16. */
  17. function __construct(&$oConfig, &$oDb, $sRootPath = BX_DIRECTORY_PATH_ROOT, $sRootUrl = BX_DOL_URL_ROOT) {
  18. parent::__construct($sRootPath, $sRootUrl);
  19. $this->_oDb = &$oDb;
  20. $this->_oConfig = &$oConfig;
  21. $sName = $oConfig->getName();
  22. $sHomePath = $oConfig->getHomePath();
  23. $sHomeUrl = $oConfig->getHomeUrl();
  24. $this->addLocation($sName, $sHomePath, $sHomeUrl);
  25. $this->addLocationJs($sName, $sHomePath . 'js/', $sHomeUrl . 'js/');
  26. }
  27. function addCss($mixedFiles, $bDynamic = false) {
  28. return $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
  29. }
  30. function addJs($mixedFiles, $bDynamic = false) {
  31. return $this->_addFiles(BxDolTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, true);
  32. }
  33. function addJsTranslation($mixedKey) {
  34. BxDolTemplate::getInstance()->addJsTranslation($mixedKey);
  35. }
  36. function addStudioCss($mixedFiles, $bDynamic = false, $bSearchInModule = true) {
  37. bx_import('BxDolStudioTemplate');
  38. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCss', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
  39. }
  40. function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true) {
  41. bx_import('BxDolStudioTemplate');
  42. return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
  43. }
  44. function _addFiles($oTemplate, $sFuncAddFiles, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true) {
  45. $sLocationKey = $bSearchInModule ? $oTemplate->$sFuncAddLocation($this->_oConfig->getUri(), $this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath) : '';
  46. $mixedResult = $oTemplate->$sFuncAddFiles($mixedFiles, $bDynamic);
  47. if($sLocationKey != '')
  48. $oTemplate->$sFuncRemoveLocation($sLocationKey);
  49. return $mixedResult;
  50. }
  51. function addStudioInjection($sKey, $sType, $sData, $iReplace = 0) {
  52. bx_import('BxDolStudioTemplate');
  53. BxDolStudioTemplate::getInstance()->aPage['injections']['page_0'][$sKey][] = array(
  54. 'page_index' => 0,
  55. 'key' => $sKey,
  56. 'type' => $sType,
  57. 'data' => $sData,
  58. 'replace' => $iReplace
  59. );
  60. }
  61. function pageStart () {
  62. if (0 == $this->_bObStarted) {
  63. ob_start ();
  64. $this->_bObStarted = 1;
  65. }
  66. }
  67. function pageEnd ($isGetContent = true) {
  68. if (1 == $this->_bObStarted) {
  69. $sRet = '';
  70. if ($isGetContent)
  71. $sRet = ob_get_clean();
  72. else
  73. ob_end_clean();
  74. $this->_bObStarted = 0;
  75. return $sRet;
  76. }
  77. }
  78. }
  79. /** @} */