BxDolStudioTemplate.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. {
  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. ));
  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->_oConfigTemplate = BxTemplStudioConfig::getInstance();
  68. }
  69. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  70. {
  71. $sRet = '';
  72. switch( $sKey ) {
  73. case 'version':
  74. $sRet = bx_get_ver();
  75. break;
  76. case 'page_breadcrumb':
  77. $sRet = $this->getPageBreadcrumb();
  78. break;
  79. case 'dol_images':
  80. $sRet = $this->_processJsImages();
  81. break;
  82. case 'dol_lang':
  83. $sRet = $this->_processJsTranslations();
  84. break;
  85. case 'dol_options':
  86. $sRet = $this->_processJsOptions();
  87. break;
  88. case 'menu_top':
  89. bx_import('BxTemplStudioMenuTop');
  90. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  91. break;
  92. case 'boonex_promo':
  93. if (getParam('enable_dolphin_footer'))
  94. $sRet = $this->parseHtmlByName('boonex_promo.html', array());
  95. break;
  96. case 'promo_code':
  97. if (defined('BX_PROMO_CODE'))
  98. $sRet = BX_PROMO_CODE;
  99. else
  100. $sRet = ' ';
  101. break;
  102. case 'copyright':
  103. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  104. break;
  105. default:
  106. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  107. }
  108. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  109. }
  110. function setPageBreadcrumb($aItems)
  111. {
  112. $this->aPage['breadcrumb'] = $aItems;
  113. }
  114. function getPageBreadcrumb()
  115. {
  116. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  117. return "";
  118. $aItems = array();
  119. foreach($this->aPage['breadcrumb'] as $aItem) {
  120. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  121. $aItems[] = array(
  122. 'bx_if:show_link' => array(
  123. 'condition' => $bLink,
  124. 'content' => array(
  125. 'link' => $bLink ? $aItem['link'] : '',
  126. 'title' => _t($aItem['title'])
  127. )
  128. ),
  129. 'bx_if:show_text' => array(
  130. 'condition' => !$bLink,
  131. 'content' => array(
  132. 'title' => _t($aItem['title'])
  133. )
  134. )
  135. );
  136. }
  137. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  138. }
  139. function getIcon($mixedId, $aParams = array())
  140. {
  141. return $this->_getImage('icon', $mixedId, $aParams);
  142. }
  143. function getImage($mixedId, $aParams = array())
  144. {
  145. return $this->_getImage('image', $mixedId, $aParams);
  146. }
  147. protected function _getImage($sType, $mixedId, $aParams = array())
  148. {
  149. $sUrl = "";
  150. $aType2Method = array('image' => 'getImageUrl', 'icon' => 'getIconUrl');
  151. //--- Check in System Storage.
  152. if(is_numeric($mixedId) && (int)$mixedId > 0) {
  153. bx_import('BxDolStorage');
  154. if(($sResult = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->getFileUrlById((int)$mixedId)) !== false)
  155. $sUrl = $sResult;
  156. }
  157. //--- Check in template folders.
  158. if($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false)
  159. $sUrl = $this->$aType2Method[$sType]($mixedId);
  160. if($sUrl != "") {
  161. $bClass = isset($aParams['class']) && !empty($aParams['class']);
  162. return $this->parseHtmlByName('bx_img.html', array(
  163. 'bx_if:class' => array(
  164. 'condition' => $bClass,
  165. 'content' => array(
  166. 'content' => $bClass ? $aParams['class'] : ''
  167. )
  168. ),
  169. 'src' => $sUrl,
  170. 'alt' => isset($aParams['alt']) ? $aParams['alt'] : ''
  171. ));
  172. }
  173. //--- Use iconic font.
  174. return $this->parseHtmlByName('bx_icon.html', array(
  175. 'name' => $mixedId
  176. ));
  177. }
  178. function displayMsg ($s, $bTranslate = false)
  179. {
  180. $sTitle = $bTranslate ? _t($s) : $s;
  181. $sContent = MsgBox($sTitle);
  182. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  183. 'content' => $sContent
  184. ));
  185. $this->setPageNameIndex(BX_PAGE_DEFAULT);
  186. $this->setPageHeader($sTitle);
  187. $this->setPageContent('page_main_code', $sContent);
  188. $this->getPageCode();
  189. exit;
  190. }
  191. }
  192. /** @} */