BxDolStudioTemplate.php 5.6 KB

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