BxBaseStudioDesigner.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  8. * @{
  9. */
  10. defined('BX_DOL') or die('hack attempt');
  11. bx_import('BxTemplPaginate');
  12. bx_import('BxDolStudioDesigner');
  13. bx_import('BxTemplStudioFormView');
  14. class BxBaseStudioDesigner extends BxDolStudioDesigner {
  15. protected $sLogoFormId = 'adm-dsg-logo-form';
  16. protected $sLogoIframeId = 'adm-dsg-logo-iframe';
  17. protected $sIconFormId = 'adm-dsg-icon-form';
  18. protected $sIconIframeId = 'adm-dsg-icon-iframe';
  19. function BxBaseStudioDesigner($sPage = '') {
  20. parent::BxDolStudioDesigner($sPage);
  21. }
  22. function getPageCss() {
  23. return array_merge(parent::getPageCss(), array('forms.css', 'designer.css'));
  24. }
  25. function getPageJs() {
  26. return array_merge(parent::getPageJs(), array('settings.js', 'designer.js'));
  27. }
  28. function getPageJsObject() {
  29. return 'oBxDolStudioDesigner';
  30. }
  31. function getPageMenu($aMenu = array(), $aMarkers = array()) {
  32. $sJsObject = $this->getPageJsObject();
  33. $aMenu = array();
  34. $aMenuItems = array(
  35. BX_DOL_STUDIO_DSG_TYPE_GENERAL,
  36. BX_DOL_STUDIO_DSG_TYPE_LOGO,
  37. BX_DOL_STUDIO_DSG_TYPE_ICON
  38. );
  39. foreach($aMenuItems as $sMenuItem)
  40. $aMenu[] = array(
  41. 'name' => $sMenuItem,
  42. 'icon' => 'mi-dsg-' . $sMenuItem . '.png',
  43. 'link' => BX_DOL_URL_STUDIO . 'designer.php?page=' . $sMenuItem,
  44. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  45. 'selected' => $sMenuItem == $this->sPage
  46. );
  47. return parent::getPageMenu($aMenu);
  48. }
  49. function getPageCode($bHidden = false) {
  50. $sMethod = 'get' . ucfirst($this->sPage);
  51. if(!method_exists($this, $sMethod))
  52. return '';
  53. return $this->$sMethod();
  54. }
  55. protected function getGeneral() {
  56. $oTemplate = BxDolStudioTemplate::getInstance();
  57. bx_import('BxTemplStudioSettings');
  58. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  59. $aTmplVars = array(
  60. 'js_object' => $this->getPageJsObject(),
  61. 'bx_repeat:blocks' => $oPage->getPageCode(),
  62. );
  63. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  64. }
  65. protected function getLogo() {
  66. $oTemplate = BxDolStudioTemplate::getInstance();
  67. $sAlt = $this->oDb->getParam('sys_site_logo_alt');
  68. $aForm = array(
  69. 'form_attrs' => array(
  70. 'id' => $this->sLogoFormId,
  71. 'name' => $this->sLogoFormId,
  72. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  73. 'method' => 'post',
  74. 'enctype' => 'multipart/form-data',
  75. 'target' => $this->sLogoIframeId
  76. ),
  77. 'params' => array(
  78. 'db' => array(
  79. 'table' => '',
  80. 'key' => '',
  81. 'uri' => '',
  82. 'uri_title' => '',
  83. 'submit_name' => 'save'
  84. ),
  85. ),
  86. 'inputs' => array(
  87. 'page' => array(
  88. 'type' => 'hidden',
  89. 'name' => 'page',
  90. 'value' => $this->sPage
  91. ),
  92. 'image' => array(
  93. 'type' => 'image_uploader',
  94. 'name' => 'image',
  95. 'caption' => _t('_adm_dsg_txt_upload_image'),
  96. 'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
  97. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
  98. 'value' => (int)$this->oDb->getParam('sys_site_logo')
  99. ),
  100. 'alt' => array(
  101. 'type' => 'text',
  102. 'name' => 'alt',
  103. 'caption' => _t('_adm_dsg_txt_alt_text'),
  104. 'info' => _t('_adm_dsg_dsc_alt_text'),
  105. 'value' => $sAlt,
  106. 'checker' => array(
  107. 'func' => '',
  108. 'params' => array(),
  109. 'error' => ''
  110. ),
  111. 'db' => array (
  112. 'pass' => 'Xss',
  113. ),
  114. ),
  115. 'save' => array(
  116. 'type' => 'submit',
  117. 'name' => 'save',
  118. 'value' => _t('_adm_btn_designer_submit'),
  119. )
  120. )
  121. );
  122. $oForm = new BxTemplStudioFormView($aForm);
  123. $oForm->initChecker();
  124. if($oForm->isSubmittedAndValid()) {
  125. echo $this->submitLogo($oForm);
  126. exit;
  127. }
  128. $aTmplVars = array(
  129. 'js_object' => $this->getPageJsObject(),
  130. 'bx_repeat:blocks' => array(
  131. array(
  132. 'caption' => '',
  133. 'panel_top' => '',
  134. 'items' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  135. 'panel_bottom' => ''
  136. )
  137. )
  138. );
  139. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  140. }
  141. protected function getIcon() {
  142. $oTemplate = BxDolStudioTemplate::getInstance();
  143. $sPreview = "";
  144. $aTmplVars = array('bx_repeat:images' => array());
  145. if(($iId = (int)$this->oDb->getParam('sys_site_icon')) != 0) {
  146. $aTranscoders = array(
  147. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  148. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  149. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  150. );
  151. bx_import('BxDolImageTranscoder');
  152. foreach($aTranscoders as $sTranscoder => $sTitle) {
  153. $oTranscoder = BxDolImageTranscoder::getObjectInstance($sTranscoder);
  154. $sImageUrl = $oTranscoder->getImageUrl($iId);
  155. if($sImageUrl === false) {
  156. $this->oDb->setParam('sys_site_icon', 0);
  157. break;
  158. }
  159. $aTmplVars['bx_repeat:images'][] = array(
  160. 'caption' => _t($sTitle),
  161. 'url' => $sImageUrl
  162. );
  163. }
  164. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  165. }
  166. $aForm = array(
  167. 'form_attrs' => array(
  168. 'id' => $this->sIconFormId,
  169. 'name' => $this->sIconFormId,
  170. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  171. 'method' => 'post',
  172. 'enctype' => 'multipart/form-data',
  173. 'target' => $this->sIconIframeId
  174. ),
  175. 'params' => array(
  176. 'db' => array(
  177. 'table' => '',
  178. 'key' => '',
  179. 'uri' => '',
  180. 'uri_title' => '',
  181. 'submit_name' => 'save'
  182. ),
  183. ),
  184. 'inputs' => array(
  185. 'page' => array(
  186. 'type' => 'hidden',
  187. 'name' => 'page',
  188. 'value' => $this->sPage
  189. ),
  190. 'preview' => array(
  191. 'type' => 'custom',
  192. 'name' => 'preview',
  193. 'content' => $sPreview
  194. ),
  195. 'image' => array(
  196. 'type' => 'file',
  197. 'name' => 'image',
  198. 'caption' => _t('_adm_dsg_txt_upload_icon')
  199. ),
  200. 'save' => array(
  201. 'type' => 'submit',
  202. 'name' => 'save',
  203. 'value' => _t('_adm_btn_designer_submit'),
  204. )
  205. )
  206. );
  207. $oForm = new BxTemplStudioFormView($aForm);
  208. $oForm->initChecker();
  209. if($oForm->isSubmittedAndValid()) {
  210. echo $this->submitIcon($oForm);
  211. exit;
  212. }
  213. $aTmplVars = array(
  214. 'js_object' => $this->getPageJsObject(),
  215. 'bx_repeat:blocks' => array(
  216. array(
  217. 'caption' => '',
  218. 'panel_top' => '',
  219. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  220. 'panel_bottom' => ''
  221. )
  222. )
  223. );
  224. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  225. }
  226. }
  227. /** @} */