BxDolStudioTemplate.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  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. defined('BX_DOL') or die('hack attempt');
  10. define('BX_DOL_STUDIO_TEMPLATE_DEFAULT_CODE', 'uni');
  11. define('BX_PAGE_COLUMN_DUAL', 3); ///< page, with 2 columns
  12. bx_import('BxDolTemplate');
  13. class BxDolStudioTemplate extends BxDolTemplate implements iBxDolSingleton {
  14. function BxDolStudioTemplate() {
  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::BxDolTemplate();
  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. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  34. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  35. }
  36. /**
  37. * Get singleton instance of the class
  38. */
  39. public static function getInstance() {
  40. if (!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  41. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolStudioTemplate();
  42. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  43. }
  44. return $GLOBALS['bxDolClasses'][__CLASS__];
  45. }
  46. function init() {
  47. parent::init();
  48. //--- Add default CSS in output
  49. $this->addCssSystem(array(
  50. 'common.css',
  51. 'default.less',
  52. 'general.css',
  53. ));
  54. //--- Add default JS in output
  55. $this->addJsSystem(array(
  56. 'jquery.js',
  57. 'jquery.migrate.js',
  58. 'jquery.dolPopup.js',
  59. 'jquery.ui.position.min.js',
  60. BX_DOL_URL_PLUGINS . 'spin.min.js',
  61. ));
  62. }
  63. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null) {
  64. global $logged;
  65. $aKeyWrappers = $this->_getKeyWrappers($mixedKeyWrapperHtml);
  66. $sRet = '';
  67. switch( $sKey ) {
  68. case 'version':
  69. $sRet = BX_DOL_VERSION;
  70. break;
  71. case 'page_charset':
  72. $sRet = 'UTF-8';
  73. break;
  74. case 'page_robots':
  75. if(!empty($this->aPage['robots']) && is_string($this->aPage['robots']))
  76. $sRet = '<meta name="robots" content="' . bx_html_attribute($this->aPage['robots']) . '" />';
  77. break;
  78. case 'page_keywords':
  79. if(!empty($this->aPage['keywords']) && is_array($this->aPage['keywords']))
  80. $sRet = '<meta name="keywords" content="' . bx_html_attribute(implode(',', $this->aPage['keywords'])) . '" />';
  81. break;
  82. case 'page_description':
  83. if(!empty($this->aPage['description']) && is_string($this->aPage['description']))
  84. $sRet = '<meta name="description" content="' . bx_html_attribute($this->aPage['description']) . '" />';
  85. break;
  86. case 'page_header':
  87. if(isset($this->aPage['header']))
  88. $sRet = bx_process_output($this->aPage['header']);
  89. break;
  90. case 'page_header_text':
  91. if(isset($this->aPage['header_text']))
  92. $sRet = bx_process_output($this->aPage['header_text']);
  93. break;
  94. case 'page_icons':
  95. bx_import('BxTemplFunctions');
  96. $sRet = BxTemplFunctions::getInstance()->getMetaIcons();
  97. break;
  98. case 'page_breadcrumb':
  99. $sRet = $this->getPageBreadcrumb();
  100. break;
  101. case 'dol_images':
  102. $sRet = $this->_processJsImages();
  103. break;
  104. case 'dol_lang':
  105. $sRet = $this->_processJsTranslations();
  106. break;
  107. case 'dol_options':
  108. $sRet = $this->_processJsOptions();
  109. break;
  110. case 'menu_top':
  111. bx_import('BxTemplStudioMenuTop');
  112. $sRet = BxTemplStudioMenuTop::getInstance()->getCode();
  113. break;
  114. case 'boonex_footers':
  115. $sRet = $this->getBoonexFooter();
  116. break;
  117. case 'boonex_promo':
  118. if (getParam('enable_dolphin_footer'))
  119. $sRet = $this->parseHtmlByName('boonex_promo.html', array());
  120. break;
  121. case 'promo_code':
  122. if (defined('BX_PROMO_CODE'))
  123. $sRet = BX_PROMO_CODE;
  124. else
  125. $sRet = ' ';
  126. break;
  127. case 'copyright':
  128. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  129. break;
  130. }
  131. $sRet = $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  132. return $sRet;
  133. }
  134. function setPageBreadcrumb($aItems) {
  135. $this->aPage['breadcrumb'] = $aItems;
  136. }
  137. function getPageBreadcrumb() {
  138. if(empty($this->aPage['breadcrumb']) || !is_array($this->aPage['breadcrumb']))
  139. return "";
  140. $aItems = array();
  141. foreach($this->aPage['breadcrumb'] as $aItem) {
  142. $bLink = isset($aItem['link']) && $aItem['link'] != '';
  143. $aItems[] = array(
  144. 'bx_if:show_link' => array(
  145. 'condition' => $bLink,
  146. 'content' => array(
  147. 'link' => $bLink ? $aItem['link'] : '',
  148. 'title' => _t($aItem['title'])
  149. )
  150. ),
  151. 'bx_if:show_text' => array(
  152. 'condition' => !$bLink,
  153. 'content' => array(
  154. 'title' => _t($aItem['title'])
  155. )
  156. )
  157. );
  158. }
  159. return $this->parseHtmlByName('breadcrumb.html', array('bx_repeat:items' => $aItems));
  160. }
  161. function getIcon($mixedId, $aParams = array()) {
  162. return $this->_getImage('icon', $mixedId, $aParams);
  163. }
  164. function getImage($mixedId, $aParams = array()) {
  165. return $this->_getImage('image', $mixedId, $aParams);
  166. }
  167. protected function _getImage($sType, $mixedId, $aParams = array()) {
  168. $sUrl = "";
  169. $aType2Method = array('image' => 'getImageUrl', 'icon' => 'getIconUrl');
  170. //--- Check in System Storage.
  171. if(is_numeric($mixedId) && (int)$mixedId > 0) {
  172. bx_import('BxDolStorage');
  173. if(($sResult = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES)->getFileUrlById((int)$mixedId)) !== false)
  174. $sUrl = $sResult;
  175. }
  176. //--- Check in template folders.
  177. if($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false)
  178. $sUrl = $this->$aType2Method[$sType]($mixedId);
  179. if($sUrl != "") {
  180. $bClass = isset($aParams['class']) && !empty($aParams['class']);
  181. return $this->parseHtmlByName('bx_img.html', array(
  182. 'bx_if:class' => array(
  183. 'condition' => $bClass,
  184. 'content' => array(
  185. 'content' => $bClass ? $aParams['class'] : ''
  186. )
  187. ),
  188. 'src' => $sUrl,
  189. 'alt' => isset($aParams['alt']) ? $aParams['alt'] : ''
  190. ));
  191. }
  192. //--- Use iconic font.
  193. return $this->parseHtmlByName('bx_icon.html', array(
  194. 'name' => $mixedId
  195. ));
  196. }
  197. function displayMsg ($s, $bTranslate = false) {
  198. $sTitle = $bTranslate ? _t($s) : $s;
  199. $sContent = MsgBox($sTitle);
  200. $sContent = $this->parseHtmlByName('page_not_found.html', array (
  201. 'content' => $sContent
  202. ));
  203. $this->setPageNameIndex(BX_PAGE_DEFAULT);
  204. $this->setPageHeader($sTitle);
  205. $this->setPageContent('page_main_code', $sContent);
  206. $this->getPageCode();
  207. exit;
  208. }
  209. }
  210. /** @} */