1
0

BxDolStudioTemplate.php 8.2 KB

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