BxDolStudioTemplate.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. //--- Add default JS in output
  59. $this->addJsSystem(array(
  60. 'jquery/jquery.min.js',
  61. 'jquery/jquery-migrate.min.js',
  62. 'jquery-ui/jquery.ui.position.min.js',
  63. 'spin.min.js',
  64. 'jquery.dolPopup.js',
  65. ));
  66. $this->_oConfigTemplate = BxTemplStudioConfig::getInstance();
  67. }
  68. function _getAbsoluteLocation($sType, $sFolder, $sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  69. {
  70. return parent::_getAbsoluteLocation($sType, $sFolder, $sName, BX_DOL_TEMPLATE_CHECK_IN_BASE);
  71. }
  72. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  73. {
  74. $sRet = '';
  75. switch( $sKey ) {
  76. case 'version':
  77. $sRet = bx_get_ver();
  78. break;
  79. case 'page_breadcrumb':
  80. $sRet = $this->getPageBreadcrumb();
  81. break;
  82. case 'popup_loading':
  83. $s = $this->parsePageByName('popup_loading.html', array());
  84. $sRet = BxTemplFunctions::getInstance()->transBox('bx-popup-loading', $s, true);
  85. break;
  86. case 'dol_images':
  87. $sRet = $this->_processJsImages();
  88. break;
  89. case 'dol_lang':
  90. $sRet = $this->_processJsTranslations();
  91. break;
  92. case 'dol_options':
  93. $sRet = $this->_processJsOptions();
  94. break;
  95. case 'menu_top':
  96. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  97. break;
  98. case 'copyright':
  99. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  100. break;
  101. default:
  102. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  103. }
  104. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  105. }
  106. function setPageBreadcrumb($aItems)
  107. {
  108. $this->aPage['breadcrumb'] = $aItems;
  109. }
  110. function getPageBreadcrumb()
  111. {
  112. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  113. return "";
  114. $aItems = array();
  115. foreach($this->aPage['breadcrumb'] as $aItem) {
  116. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  117. $aItems[] = array(
  118. 'bx_if:show_link' => array(
  119. 'condition' => $bLink,
  120. 'content' => array(
  121. 'link' => $bLink ? $aItem['link'] : '',
  122. 'title' => _t($aItem['title'])
  123. )
  124. ),
  125. 'bx_if:show_text' => array(
  126. 'condition' => !$bLink,
  127. 'content' => array(
  128. 'title' => _t($aItem['title'])
  129. )
  130. )
  131. );
  132. }
  133. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  134. }
  135. function displayMsg ($s, $bTranslate = false)
  136. {
  137. $sTitle = $bTranslate ? _t($s) : $s;
  138. $sContent = MsgBox($sTitle);
  139. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  140. 'content' => $sContent
  141. ));
  142. $this->setPageNameIndex(BX_PAGE_DEFAULT);
  143. $this->setPageHeader($sTitle);
  144. $this->setPageContent('page_main_code', $sContent);
  145. $this->getPageCode();
  146. exit;
  147. }
  148. }
  149. /** @} */