BxDolStudioTemplate.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentStudio Trident Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_TEMPLATE_DEFAULT_CODE', 'uni');
  10. define('BX_PAGE_COLUMN_DUAL', 3); ///< page, with 2 columns
  11. class BxDolStudioTemplate extends BxDolTemplate implements iBxDolSingleton
  12. {
  13. 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.css',
  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 parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  69. {
  70. $sRet = '';
  71. switch( $sKey ) {
  72. case 'version':
  73. $sRet = bx_get_ver();
  74. break;
  75. case 'page_breadcrumb':
  76. $sRet = $this->getPageBreadcrumb();
  77. break;
  78. case 'dol_images':
  79. $sRet = $this->_processJsImages();
  80. break;
  81. case 'dol_lang':
  82. $sRet = $this->_processJsTranslations();
  83. break;
  84. case 'dol_options':
  85. $sRet = $this->_processJsOptions();
  86. break;
  87. case 'menu_top':
  88. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  89. break;
  90. case 'copyright':
  91. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  92. break;
  93. default:
  94. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  95. }
  96. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  97. }
  98. function setPageBreadcrumb($aItems)
  99. {
  100. $this->aPage['breadcrumb'] = $aItems;
  101. }
  102. function getPageBreadcrumb()
  103. {
  104. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  105. return "";
  106. $aItems = array();
  107. foreach($this->aPage['breadcrumb'] as $aItem) {
  108. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  109. $aItems[] = array(
  110. 'bx_if:show_link' => array(
  111. 'condition' => $bLink,
  112. 'content' => array(
  113. 'link' => $bLink ? $aItem['link'] : '',
  114. 'title' => _t($aItem['title'])
  115. )
  116. ),
  117. 'bx_if:show_text' => array(
  118. 'condition' => !$bLink,
  119. 'content' => array(
  120. 'title' => _t($aItem['title'])
  121. )
  122. )
  123. );
  124. }
  125. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  126. }
  127. function getIcon($mixedId, $aParams = array())
  128. {
  129. return $this->_getImage('icon', $mixedId, $aParams);
  130. }
  131. function getImage($mixedId, $aParams = array())
  132. {
  133. return $this->_getImage('image', $mixedId, $aParams);
  134. }
  135. protected function _getImage($sType, $mixedId, $aParams = array())
  136. {
  137. $sUrl = "";
  138. $aType2Method = array('image' => 'getImageUrl', 'icon' => 'getIconUrl');
  139. //--- Check in System Storage.
  140. if(is_numeric($mixedId) && (int)$mixedId > 0)
  141. if(($sResult = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->getFileUrlById((int)$mixedId)) !== false)
  142. $sUrl = $sResult;
  143. //--- Check in template folders.
  144. if($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false)
  145. $sUrl = $this->$aType2Method[$sType]($mixedId);
  146. if($sUrl != "") {
  147. $bClass = isset($aParams['class']) && !empty($aParams['class']);
  148. return $this->parseHtmlByName('bx_img.html', array(
  149. 'bx_if:class' => array(
  150. 'condition' => $bClass,
  151. 'content' => array(
  152. 'content' => $bClass ? $aParams['class'] : ''
  153. )
  154. ),
  155. 'src' => $sUrl,
  156. 'alt' => isset($aParams['alt']) ? $aParams['alt'] : ''
  157. ));
  158. }
  159. //--- Use iconic font.
  160. return $this->parseHtmlByName('bx_icon.html', array(
  161. 'name' => $mixedId
  162. ));
  163. }
  164. function displayMsg ($s, $bTranslate = false)
  165. {
  166. $sTitle = $bTranslate ? _t($s) : $s;
  167. $sContent = MsgBox($sTitle);
  168. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  169. 'content' => $sContent
  170. ));
  171. $this->setPageNameIndex(BX_PAGE_DEFAULT);
  172. $this->setPageHeader($sTitle);
  173. $this->setPageContent('page_main_code', $sContent);
  174. $this->getPageCode();
  175. exit;
  176. }
  177. }
  178. /** @} */