BxDolModuleTemplate.php 3.2 KB

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