BxDolStudioTemplate.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. $this->_sCodeKey = BX_DOL_STUDIO_TEMPLATE_CODE_KEY;
  23. $this->_sCode = isset($_COOKIE[$this->_sCodeKey]) && preg_match('/^[A-Za-z0-9_-]+$/', $_COOKIE[$this->_sCodeKey]) ? $_COOKIE[$this->_sCodeKey] : BX_DOL_STUDIO_TEMPLATE_DEFAULT_CODE;
  24. $this->_sCode = isset($_GET[$this->_sCodeKey]) && preg_match('/^[A-Za-z0-9_-]+$/', $_GET[$this->_sCodeKey]) ? $_GET[$this->_sCodeKey] : $this->_sCode;
  25. $this->addLocation('studio', $this->_sRootPath, $this->_sRootUrl);
  26. $this->addLocationJs('system_admin_js', $this->_sRootPath . 'js/' , $this->_sRootUrl . 'js/');
  27. }
  28. /**
  29. * Prevent cloning the instance
  30. */
  31. public function __clone()
  32. {
  33. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  34. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  35. }
  36. /**
  37. * Get singleton instance of the class
  38. */
  39. public static function getInstance()
  40. {
  41. if (!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  42. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolStudioTemplate();
  43. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  44. }
  45. return $GLOBALS['bxDolClasses'][__CLASS__];
  46. }
  47. function init()
  48. {
  49. parent::init();
  50. //--- Add default CSS in output
  51. $this->addCssSystem(array(
  52. 'common.less',
  53. 'default.less',
  54. 'general.css',
  55. 'menu.css',
  56. ));
  57. bx_import('BxTemplStudioConfig');
  58. $this->_oTemplateConfig = BxTemplStudioConfig::getInstance();
  59. bx_import('BxTemplStudioFunctions');
  60. $this->_oTemplateFunctions = BxTemplStudioFunctions::getInstance($this);
  61. }
  62. function _getAbsoluteLocation($sType, $sFolder, $sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  63. {
  64. return parent::_getAbsoluteLocation($sType, $sFolder, $sName, BX_DOL_TEMPLATE_CHECK_IN_BASE);
  65. }
  66. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  67. {
  68. $sRet = '';
  69. switch( $sKey ) {
  70. case 'version':
  71. $sRet = bx_get_ver();
  72. break;
  73. case 'page_breadcrumb':
  74. $sRet = $this->getPageBreadcrumb();
  75. break;
  76. case 'popup_loading':
  77. $s = $this->parsePageByName('popup_loading.html', array());
  78. $sRet = BxTemplFunctions::getInstance()->transBox('bx-popup-loading', $s, true);
  79. break;
  80. case 'dol_images':
  81. $sRet = $this->_processJsImages();
  82. break;
  83. case 'dol_lang':
  84. $sRet = $this->_processJsTranslations();
  85. break;
  86. case 'dol_options':
  87. $sRet = $this->_processJsOptions();
  88. break;
  89. case 'menu_top':
  90. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  91. break;
  92. case 'copyright':
  93. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  94. break;
  95. default:
  96. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  97. }
  98. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  99. }
  100. function setPageBreadcrumb($aItems)
  101. {
  102. $this->aPage['breadcrumb'] = $aItems;
  103. }
  104. function getPageBreadcrumb()
  105. {
  106. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  107. return "";
  108. $aItems = array();
  109. foreach($this->aPage['breadcrumb'] as $aItem) {
  110. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  111. $aItems[] = array(
  112. 'bx_if:show_link' => array(
  113. 'condition' => $bLink,
  114. 'content' => array(
  115. 'link' => $bLink ? $aItem['link'] : '',
  116. 'title' => _t($aItem['title'])
  117. )
  118. ),
  119. 'bx_if:show_text' => array(
  120. 'condition' => !$bLink,
  121. 'content' => array(
  122. 'title' => _t($aItem['title'])
  123. )
  124. )
  125. );
  126. }
  127. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  128. }
  129. function displayMsg ($s, $bTranslate = false, $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_PADDING_DEF)
  130. {
  131. $sTitle = $bTranslate ? _t($s) : $s;
  132. $sContent = MsgBox($sTitle);
  133. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  134. 'content' => $sContent
  135. ));
  136. $this->setPageNameIndex($iPage);
  137. $this->setPageHeader($sTitle);
  138. $this->setPageContent('page_main_code', $sContent);
  139. $this->getPageCode();
  140. exit;
  141. }
  142. }
  143. /** @} */