BxDolStudioTemplate.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. bx_import('BxDolTemplate');
  12. class BxDolStudioTemplate extends BxDolTemplate implements iBxDolSingleton
  13. {
  14. function __construct()
  15. {
  16. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  17. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  18. parent::__construct();
  19. $this->_sRootPath = BX_DOL_DIR_STUDIO;
  20. $this->_sRootUrl = BX_DOL_URL_STUDIO;
  21. $this->_sPrefix = 'BxDolStudioTemplate';
  22. $this->_sInjectionsTable = 'sys_injections_admin';
  23. $this->_sInjectionsCache = 'sys_injections_admin.inc';
  24. $this->_sCodeKey = 'sskin';
  25. $this->_sCode = isset($_COOKIE[$this->_sCodeKey]) && preg_match('/^[A-Za-z0-9_-]+$/', $_COOKIE[$this->_sCodeKey]) ? $_COOKIE[$this->_sCodeKey] : BX_DOL_STUDIO_TEMPLATE_DEFAULT_CODE;
  26. $this->_sCode = isset($_GET[$this->_sCodeKey]) && preg_match('/^[A-Za-z0-9_-]+$/', $_GET[$this->_sCodeKey]) ? $_GET[$this->_sCodeKey] : $this->_sCode;
  27. $this->addLocation('studio', $this->_sRootPath, $this->_sRootUrl);
  28. $this->addLocationJs('system_admin_js', $this->_sRootPath . 'js/' , $this->_sRootUrl . 'js/');
  29. }
  30. /**
  31. * Prevent cloning the instance
  32. */
  33. public function __clone()
  34. {
  35. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  36. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  37. }
  38. /**
  39. * Get singleton instance of the class
  40. */
  41. public static function getInstance()
  42. {
  43. if (!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  44. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolStudioTemplate();
  45. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  46. }
  47. return $GLOBALS['bxDolClasses'][__CLASS__];
  48. }
  49. function init()
  50. {
  51. parent::init();
  52. //--- Add default CSS in output
  53. $this->addCssSystem(array(
  54. 'common.css',
  55. 'default.less',
  56. 'general.css',
  57. 'menu.css',
  58. ));
  59. //--- Add default JS in output
  60. $this->addJsSystem(array(
  61. 'jquery/jquery.min.js',
  62. 'jquery/jquery-migrate.min.js',
  63. 'jquery-ui/jquery.ui.position.min.js',
  64. 'spin.min.js',
  65. 'jquery.dolPopup.js',
  66. ));
  67. bx_import('BxTemplStudioConfig');
  68. $this->_oConfigTemplate = BxTemplStudioConfig::getInstance();
  69. }
  70. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  71. {
  72. $sRet = '';
  73. switch( $sKey ) {
  74. case 'version':
  75. $sRet = bx_get_ver();
  76. break;
  77. case 'page_breadcrumb':
  78. $sRet = $this->getPageBreadcrumb();
  79. break;
  80. case 'dol_images':
  81. $sRet = $this->_processJsImages();
  82. break;
  83. case 'dol_lang':
  84. $sRet = $this->_processJsTranslations();
  85. break;
  86. case 'dol_options':
  87. $sRet = $this->_processJsOptions();
  88. break;
  89. case 'menu_top':
  90. bx_import('BxTemplStudioMenuTop');
  91. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  92. break;
  93. case 'boonex_promo':
  94. if (getParam('enable_dolphin_footer'))
  95. $sRet = $this->parseHtmlByName('boonex_promo.html', array());
  96. break;
  97. case 'promo_code':
  98. if (defined('BX_PROMO_CODE'))
  99. $sRet = BX_PROMO_CODE;
  100. else
  101. $sRet = ' ';
  102. break;
  103. case 'copyright':
  104. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  105. break;
  106. default:
  107. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  108. }
  109. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  110. }
  111. function setPageBreadcrumb($aItems)
  112. {
  113. $this->aPage['breadcrumb'] = $aItems;
  114. }
  115. function getPageBreadcrumb()
  116. {
  117. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  118. return "";
  119. $aItems = array();
  120. foreach($this->aPage['breadcrumb'] as $aItem) {
  121. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  122. $aItems[] = array(
  123. 'bx_if:show_link' => array(
  124. 'condition' => $bLink,
  125. 'content' => array(
  126. 'link' => $bLink ? $aItem['link'] : '',
  127. 'title' => _t($aItem['title'])
  128. )
  129. ),
  130. 'bx_if:show_text' => array(
  131. 'condition' => !$bLink,
  132. 'content' => array(
  133. 'title' => _t($aItem['title'])
  134. )
  135. )
  136. );
  137. }
  138. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  139. }
  140. function getIcon($mixedId, $aParams = array())
  141. {
  142. return $this->_getImage('icon', $mixedId, $aParams);
  143. }
  144. function getImage($mixedId, $aParams = array())
  145. {
  146. return $this->_getImage('image', $mixedId, $aParams);
  147. }
  148. protected function _getImage($sType, $mixedId, $aParams = array())
  149. {
  150. $sUrl = "";
  151. $aType2Method = array('image' => 'getImageUrl', 'icon' => 'getIconUrl');
  152. //--- Check in System Storage.
  153. if(is_numeric($mixedId) && (int)$mixedId > 0) {
  154. bx_import('BxDolStorage');
  155. if(($sResult = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->getFileUrlById((int)$mixedId)) !== false)
  156. $sUrl = $sResult;
  157. }
  158. //--- Check in template folders.
  159. if($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false)
  160. $sUrl = $this->$aType2Method[$sType]($mixedId);
  161. if($sUrl != "") {
  162. $bClass = isset($aParams['class']) && !empty($aParams['class']);
  163. return $this->parseHtmlByName('bx_img.html', array(
  164. 'bx_if:class' => array(
  165. 'condition' => $bClass,
  166. 'content' => array(
  167. 'content' => $bClass ? $aParams['class'] : ''
  168. )
  169. ),
  170. 'src' => $sUrl,
  171. 'alt' => isset($aParams['alt']) ? $aParams['alt'] : ''
  172. ));
  173. }
  174. //--- Use iconic font.
  175. return $this->parseHtmlByName('bx_icon.html', array(
  176. 'name' => $mixedId
  177. ));
  178. }
  179. function displayMsg ($s, $bTranslate = false)
  180. {
  181. $sTitle = $bTranslate ? _t($s) : $s;
  182. $sContent = MsgBox($sTitle);
  183. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  184. 'content' => $sContent
  185. ));
  186. $this->setPageNameIndex(BX_PAGE_DEFAULT);
  187. $this->setPageHeader($sTitle);
  188. $this->setPageContent('page_main_code', $sContent);
  189. $this->getPageCode();
  190. exit;
  191. }
  192. }
  193. /** @} */