BxDolStudioTemplate.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 UnaStudio UNA Studio
  7. * @{
  8. */
  9. define('BX_PAGE_COLUMN_DUAL', 3); ///< page, with 2 columns
  10. class BxDolStudioTemplate extends BxDolTemplate implements iBxDolSingleton
  11. {
  12. protected function __construct()
  13. {
  14. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  15. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  16. parent::__construct();
  17. $this->_sRootPath = BX_DOL_DIR_STUDIO;
  18. $this->_sRootUrl = BX_DOL_URL_STUDIO;
  19. $this->_sPrefix = 'BxDolStudioTemplate';
  20. $this->_sInjectionsTable = 'sys_injections_admin';
  21. $this->_sInjectionsCache = 'sys_injections_admin.inc';
  22. $aCode = self::retrieveCode();
  23. $this->_sCodeKey = BX_DOL_STUDIO_TEMPLATE_CODE_KEY;
  24. $aCodeStudio = self::retrieveCode($this->_sCodeKey, $this->_sMixKey, $this->_sRootPath);
  25. $sCodeDefault = getParam('template');
  26. if($aCodeStudio !== false && $aCodeStudio[0] != $sCodeDefault)
  27. $aCode = $aCodeStudio;
  28. list(
  29. $this->_sCode,
  30. $this->_sName,
  31. $this->_sSubPath
  32. ) = $aCode;
  33. $this->_iMix = 0;
  34. if(is_array($this->_sCode))
  35. list($this->_sCode, $this->_iMix) = $this->_sCode;
  36. $this->addLocation('studio', $this->_sRootPath, $this->_sRootUrl);
  37. $this->addLocationJs('system_admin_js', $this->_sRootPath . 'js/' , $this->_sRootUrl . 'js/');
  38. }
  39. /**
  40. * Prevent cloning the instance
  41. */
  42. public function __clone()
  43. {
  44. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  45. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  46. }
  47. /**
  48. * Get singleton instance of the class
  49. */
  50. public static function getInstance()
  51. {
  52. if (!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  53. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolStudioTemplate();
  54. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  55. }
  56. return $GLOBALS['bxDolClasses'][__CLASS__];
  57. }
  58. function init()
  59. {
  60. parent::init();
  61. //--- Add default CSS in output
  62. $this->addCssSystem(array(
  63. 'common.less',
  64. 'default.less',
  65. 'general.css',
  66. 'menu.css',
  67. ));
  68. bx_import('BxTemplStudioConfig');
  69. $this->_oTemplateConfig = BxTemplStudioConfig::getInstance();
  70. bx_import('BxTemplStudioFunctions');
  71. $this->_oTemplateFunctions = BxTemplStudioFunctions::getInstance($this);
  72. }
  73. function _getAbsoluteLocation($sType, $sFolder, $sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  74. {
  75. return parent::_getAbsoluteLocation($sType, $sFolder, $sName, BX_DOL_TEMPLATE_CHECK_IN_BASE);
  76. }
  77. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  78. {
  79. $sRet = '';
  80. switch( $sKey ) {
  81. case 'version':
  82. $sRet = bx_get_ver();
  83. break;
  84. case 'page_breadcrumb':
  85. $sRet = $this->getPageBreadcrumb();
  86. break;
  87. case 'popup_loading':
  88. $s = $this->parsePageByName('popup_loading.html', array());
  89. $sRet = BxTemplFunctions::getInstance()->transBox('bx-popup-loading', $s, true);
  90. break;
  91. case 'dol_images':
  92. $sRet = $this->_processJsImages();
  93. break;
  94. case 'dol_lang':
  95. $sRet = $this->_processJsTranslations();
  96. break;
  97. case 'dol_options':
  98. $sRet = $this->_processJsOptions();
  99. break;
  100. case 'menu_top':
  101. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  102. break;
  103. case 'copyright':
  104. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  105. break;
  106. default:
  107. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  108. }
  109. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  110. }
  111. function setPageBreadcrumb($aItems)
  112. {
  113. $this->aPage['breadcrumb'] = $aItems;
  114. }
  115. function getPageBreadcrumb()
  116. {
  117. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  118. return "";
  119. $aItems = array();
  120. foreach($this->aPage['breadcrumb'] as $aItem) {
  121. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  122. $aItems[] = array(
  123. 'bx_if:show_link' => array(
  124. 'condition' => $bLink,
  125. 'content' => array(
  126. 'link' => $bLink ? $aItem['link'] : '',
  127. 'title' => _t($aItem['title'])
  128. )
  129. ),
  130. 'bx_if:show_text' => array(
  131. 'condition' => !$bLink,
  132. 'content' => array(
  133. 'title' => _t($aItem['title'])
  134. )
  135. )
  136. );
  137. }
  138. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  139. }
  140. function displayMsg ($s, $bTranslate = false, $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_PADDING_DEF)
  141. {
  142. $sTitle = $bTranslate ? _t($s) : $s;
  143. $sContent = MsgBox($sTitle);
  144. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  145. 'content' => $sContent
  146. ));
  147. $this->setPageNameIndex($iPage);
  148. $this->setPageHeader($sTitle);
  149. $this->setPageContent('page_main_code', $sContent);
  150. $this->getPageCode();
  151. exit;
  152. }
  153. }
  154. /** @} */