BxDolStudioTemplate.php 5.8 KB

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