BxDolStudioTemplate.php 8.7 KB

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