BxDolStudioTemplate.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 $_sFolderModuleIcons;
  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. $aCode = self::retrieveCode();
  24. $this->_sCodeKey = BX_DOL_STUDIO_TEMPLATE_CODE_KEY;
  25. $aCodeStudio = self::retrieveCode($this->_sCodeKey, $this->_sMixKey, $this->_sRootPath);
  26. $sCodeDefault = getParam('template');
  27. if($aCodeStudio !== false && $aCodeStudio[0] != $sCodeDefault)
  28. $aCode = $aCodeStudio;
  29. list(
  30. $this->_sCode,
  31. $this->_sName,
  32. $this->_sSubPath
  33. ) = $aCode;
  34. $this->_iMix = 0;
  35. if(is_array($this->_sCode))
  36. list($this->_sCode, $this->_iMix) = $this->_sCode;
  37. $this->_sFolderModuleIcons = 'images/modules/';
  38. $this->addLocation('studio', $this->_sRootPath, $this->_sRootUrl);
  39. $this->addLocationJs('system_admin_js', $this->_sRootPath . 'js/' , $this->_sRootUrl . 'js/');
  40. }
  41. /**
  42. * Prevent cloning the instance
  43. */
  44. public function __clone()
  45. {
  46. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  47. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  48. }
  49. /**
  50. * Get singleton instance of the class
  51. */
  52. public static function getInstance()
  53. {
  54. if (!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  55. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolStudioTemplate();
  56. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  57. }
  58. return $GLOBALS['bxDolClasses'][__CLASS__];
  59. }
  60. function init()
  61. {
  62. parent::init();
  63. //--- Add default CSS in output
  64. $this->addCssSystem(array(
  65. 'common.less',
  66. 'default.less',
  67. 'general.css',
  68. 'menu.css',
  69. ));
  70. bx_import('BxTemplStudioConfig');
  71. $this->_oTemplateConfig = BxTemplStudioConfig::getInstance();
  72. bx_import('BxTemplStudioFunctions');
  73. $this->_oTemplateFunctions = BxTemplStudioFunctions::getInstance($this);
  74. }
  75. function getIconUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  76. {
  77. if(($sModuleIcon = $this->_getModuleIcon('url', $sName)) !== false)
  78. return $sModuleIcon;
  79. return parent::getIconUrl($sName, $sCheckIn);
  80. }
  81. function getIconPath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  82. {
  83. if(($sModuleIcon = $this->_getModuleIcon('path', $sName)) !== false)
  84. return $sModuleIcon;
  85. return parent::getIconUrl($sName, $sCheckIn);
  86. }
  87. function _getAbsoluteLocation($sType, $sFolder, $sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  88. {
  89. return parent::_getAbsoluteLocation($sType, $sFolder, $sName, BX_DOL_TEMPLATE_CHECK_IN_BASE);
  90. }
  91. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  92. {
  93. $sRet = '';
  94. switch( $sKey ) {
  95. case 'version':
  96. $sRet = bx_get_ver();
  97. break;
  98. case 'page_breadcrumb':
  99. $sRet = $this->getPageBreadcrumb();
  100. break;
  101. case 'popup_loading':
  102. $s = $this->parsePageByName('popup_loading.html', array());
  103. $sRet = BxTemplFunctions::getInstance()->transBox('bx-popup-loading', $s, true);
  104. break;
  105. case 'dol_images':
  106. $sRet = $this->_processJsImages();
  107. break;
  108. case 'dol_lang':
  109. $sRet = $this->_processJsTranslations();
  110. break;
  111. case 'dol_options':
  112. $sRet = $this->_processJsOptions();
  113. break;
  114. case 'menu_top':
  115. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  116. break;
  117. case 'copyright':
  118. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  119. break;
  120. case 'class_name':
  121. $sRet = 'bx-dir-' . strtolower(bx_lang_direction());
  122. break;
  123. default:
  124. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  125. }
  126. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  127. }
  128. function getModuleIconUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  129. {
  130. return $this->_getAbsoluteLocation('url', $this->_sFolderModuleIcons, $sName, $sCheckIn);
  131. }
  132. function getModuleIconPath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  133. {
  134. return $this->_getAbsoluteLocation('path', $this->_sFolderModuleIcons, $sName, $sCheckIn);
  135. }
  136. function setPageBreadcrumb($aItems)
  137. {
  138. $this->aPage['breadcrumb'] = $aItems;
  139. }
  140. function getPageBreadcrumb()
  141. {
  142. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  143. return "";
  144. $aItems = array();
  145. foreach($this->aPage['breadcrumb'] as $aItem) {
  146. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  147. $aItems[] = array(
  148. 'bx_if:show_link' => array(
  149. 'condition' => $bLink,
  150. 'content' => array(
  151. 'link' => $bLink ? $aItem['link'] : '',
  152. 'title' => _t($aItem['title'])
  153. )
  154. ),
  155. 'bx_if:show_text' => array(
  156. 'condition' => !$bLink,
  157. 'content' => array(
  158. 'title' => _t($aItem['title'])
  159. )
  160. )
  161. );
  162. }
  163. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  164. }
  165. function displayMsg ($mixed, $bTranslate = false, $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_CONTENT_ONLY)
  166. {
  167. $iCode = 200;
  168. $sMessage = '';
  169. if(is_array($mixed))
  170. list($iCode, $sMessage) = $mixed;
  171. else
  172. $sMessage = $mixed;
  173. switch($iCode) {
  174. case 403:
  175. header('HTTP/1.0 403 Forbidden');
  176. header('Status: 403 Forbidden');
  177. break;
  178. case 404:
  179. header('HTTP/1.0 404 Not Found');
  180. header('Status: 404 Not Found');
  181. break;
  182. }
  183. $sTitle = $bTranslate ? _t($sMessage) : $sMessage;
  184. $sContent = $this->parseHtmlByName('page_not_found.html', [
  185. 'content' => DesignBoxContent('', MsgBox($sTitle), $iDesignBox)
  186. ]);
  187. $this->setPageNameIndex($iPage);
  188. $this->setPageHeader($sTitle);
  189. $this->setPageContent('page_main_code', $sContent);
  190. $this->getPageCode();
  191. exit;
  192. }
  193. function displayPage(&$oPage)
  194. {
  195. if(($mixedResult = $oPage->checkAction()) !== false)
  196. return echoJson($mixedResult);
  197. $sPageMenu = $oPage->getPageMenu();
  198. $sPageCode = $oPage->getPageCode();
  199. if($sPageCode === false)
  200. $this->displayMsg(($sError = $oPage->getError(false)) !== false ? $sError : '_sys_txt_error_occured', true, BX_PAGE_DEFAULT, BX_DB_PADDING_NO_CAPTION);
  201. $this->setPageNameIndex($oPage->getPageIndex());
  202. $this->setPageHeader($oPage->getPageHeader());
  203. $this->setPageContent('page_caption_code', $oPage->getPageCaption());
  204. $this->setPageContent('page_attributes', $oPage->getPageAttributes());
  205. $this->setPageContent('page_menu_code', $sPageMenu);
  206. $this->setPageContent('page_main_code', $sPageCode);
  207. $this->addCss($oPage->getPageCss());
  208. $this->addJs($oPage->getPageJs());
  209. $this->getPageCode();
  210. }
  211. protected function _getModuleIcon($sType, $sName)
  212. {
  213. if(strpos($sName, '|') !== false) {
  214. list($sLocation, $sFile) = explode('|', $sName);
  215. if($sFile == 'std-icon.svg' && strpos($sLocation, '@') !== false) {
  216. list($sModule) = explode('@', $sLocation);
  217. if($sModule && ($sModuleIcon = $this->{'getModuleIcon' . ucfirst($sType)}($sModule . '.svg')))
  218. return $sModuleIcon;
  219. }
  220. }
  221. return false;
  222. }
  223. }
  224. /** @} */