BxDolStudioTemplate.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. case 'class_name':
  107. $sRet = 'bx-dir-' . strtolower(bx_lang_direction());
  108. break;
  109. default:
  110. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  111. }
  112. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  113. }
  114. function setPageBreadcrumb($aItems)
  115. {
  116. $this->aPage['breadcrumb'] = $aItems;
  117. }
  118. function getPageBreadcrumb()
  119. {
  120. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  121. return "";
  122. $aItems = array();
  123. foreach($this->aPage['breadcrumb'] as $aItem) {
  124. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  125. $aItems[] = array(
  126. 'bx_if:show_link' => array(
  127. 'condition' => $bLink,
  128. 'content' => array(
  129. 'link' => $bLink ? $aItem['link'] : '',
  130. 'title' => _t($aItem['title'])
  131. )
  132. ),
  133. 'bx_if:show_text' => array(
  134. 'condition' => !$bLink,
  135. 'content' => array(
  136. 'title' => _t($aItem['title'])
  137. )
  138. )
  139. );
  140. }
  141. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  142. }
  143. function displayMsg ($mixed, $bTranslate = false, $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_CONTENT_ONLY)
  144. {
  145. $iCode = 200;
  146. $sMessage = '';
  147. if(is_array($mixed))
  148. list($iCode, $sMessage) = $mixed;
  149. else
  150. $sMessage = $mixed;
  151. switch($iCode) {
  152. case 403:
  153. header('HTTP/1.0 403 Forbidden');
  154. header('Status: 403 Forbidden');
  155. break;
  156. case 404:
  157. header('HTTP/1.0 404 Not Found');
  158. header('Status: 404 Not Found');
  159. break;
  160. }
  161. $sTitle = $bTranslate ? _t($sMessage) : $sMessage;
  162. $sContent = $this->parseHtmlByName('page_not_found.html', [
  163. 'content' => DesignBoxContent('', MsgBox($sTitle), $iDesignBox)
  164. ]);
  165. $this->setPageNameIndex($iPage);
  166. $this->setPageHeader($sTitle);
  167. $this->setPageContent('page_main_code', $sContent);
  168. $this->getPageCode();
  169. exit;
  170. }
  171. function displayPage(&$oPage)
  172. {
  173. if(($mixedResult = $oPage->checkAction()) !== false)
  174. return echoJson($mixedResult);
  175. $sPageCode = $oPage->getPageCode();
  176. if($sPageCode === false)
  177. $this->displayMsg(($sError = $oPage->getError(false)) !== false ? $sError : '_sys_txt_error_occured', true, BX_PAGE_DEFAULT, BX_DB_PADDING_NO_CAPTION);
  178. $this->setPageNameIndex($oPage->getPageIndex());
  179. $this->setPageHeader($oPage->getPageHeader());
  180. $this->setPageContent('page_caption_code', $oPage->getPageCaption());
  181. $this->setPageContent('page_attributes', $oPage->getPageAttributes());
  182. $this->setPageContent('page_menu_code', $oPage->getPageMenu());
  183. $this->setPageContent('page_main_code', $sPageCode);
  184. $this->addCss($oPage->getPageCss());
  185. $this->addJs($oPage->getPageJs());
  186. $this->getPageCode();
  187. }
  188. }
  189. /** @} */