BxDolStudioTemplate.php 7.3 KB

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