BxDolStudioTemplate.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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/jquery.min.js',
  56. 'jquery/jquery-migrate.min.js',
  57. 'jquery-ui/jquery.ui.position.min.js',
  58. 'spin.min.js',
  59. 'jquery.dolPopup.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_promo':
  87. if (getParam('enable_dolphin_footer'))
  88. $sRet = $this->parseHtmlByName('boonex_promo.html', array());
  89. break;
  90. case 'promo_code':
  91. if (defined('BX_PROMO_CODE'))
  92. $sRet = BX_PROMO_CODE;
  93. else
  94. $sRet = ' ';
  95. break;
  96. case 'copyright':
  97. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  98. break;
  99. default:
  100. $sRet = parent::parseSystemKey($sKey, $mixedKeyWrapperHtml, false);
  101. }
  102. return $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  103. }
  104. function setPageBreadcrumb($aItems) {
  105. $this->aPage['breadcrumb'] = $aItems;
  106. }
  107. function getPageBreadcrumb() {
  108. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  109. return "";
  110. $aItems = array();
  111. foreach($this->aPage['breadcrumb'] as $aItem) {
  112. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  113. $aItems[] = array(
  114. 'bx_if:show_link' => array(
  115. 'condition' => $bLink,
  116. 'content' => array(
  117. 'link' => $bLink ? $aItem['link'] : '',
  118. 'title' => _t($aItem['title'])
  119. )
  120. ),
  121. 'bx_if:show_text' => array(
  122. 'condition' => !$bLink,
  123. 'content' => array(
  124. 'title' => _t($aItem['title'])
  125. )
  126. )
  127. );
  128. }
  129. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  130. }
  131. function getIcon($mixedId, $aParams = array()) {
  132. return $this->_getImage('icon', $mixedId, $aParams);
  133. }
  134. function getImage($mixedId, $aParams = array()) {
  135. return $this->_getImage('image', $mixedId, $aParams);
  136. }
  137. protected function _getImage($sType, $mixedId, $aParams = array()) {
  138. $sUrl = "";
  139. $aType2Method = array('image' => 'getImageUrl', 'icon' => 'getIconUrl');
  140. //--- Check in System Storage.
  141. if(is_numeric($mixedId) && (int)$mixedId > 0) {
  142. bx_import('BxDolStorage');
  143. if(($sResult = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->getFileUrlById((int)$mixedId)) !== false)
  144. $sUrl = $sResult;
  145. }
  146. //--- Check in template folders.
  147. if($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false)
  148. $sUrl = $this->$aType2Method[$sType]($mixedId);
  149. if($sUrl != "") {
  150. $bClass = isset($aParams['class']) && !empty($aParams['class']);
  151. return $this->parseHtmlByName('bx_img.html', array(
  152. 'bx_if:class' => array(
  153. 'condition' => $bClass,
  154. 'content' => array(
  155. 'content' => $bClass ? $aParams['class'] : ''
  156. )
  157. ),
  158. 'src' => $sUrl,
  159. 'alt' => isset($aParams['alt']) ? $aParams['alt'] : ''
  160. ));
  161. }
  162. //--- Use iconic font.
  163. return $this->parseHtmlByName('bx_icon.html', array(
  164. 'name' => $mixedId
  165. ));
  166. }
  167. function displayMsg ($s, $bTranslate = false) {
  168. $sTitle = $bTranslate ? _t($s) : $s;
  169. $sContent = MsgBox($sTitle);
  170. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  171. 'content' => $sContent
  172. ));
  173. $this->setPageNameIndex(BX_PAGE_DEFAULT);
  174. $this->setPageHeader($sTitle);
  175. $this->setPageContent('page_main_code', $sContent);
  176. $this->getPageCode();
  177. exit;
  178. }
  179. }
  180. /** @} */