BxDolModuleTemplate.php 3.3 KB

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