BxBaseStudioDesigner.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. BX_DOL_STUDIO_DSG_TYPE_SETTINGS
  39. );
  40. foreach($aMenuItems as $sMenuItem)
  41. $aMenu[] = array(
  42. 'name' => $sMenuItem,
  43. 'icon' => 'mi-dsg-' . $sMenuItem . '.png',
  44. 'link' => BX_DOL_URL_STUDIO . 'designer.php?page=' . $sMenuItem,
  45. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  46. 'selected' => $sMenuItem == $this->sPage
  47. );
  48. return parent::getPageMenu($aMenu);
  49. }
  50. function getPageCode($bHidden = false) {
  51. $sMethod = 'get' . ucfirst($this->sPage);
  52. if(!method_exists($this, $sMethod))
  53. return '';
  54. return $this->$sMethod();
  55. }
  56. protected function getGeneral() {
  57. $sJsObject = $this->getPageJsObject();
  58. $oTemplate = BxDolStudioTemplate::getInstance();
  59. $sResult = '';
  60. $sTemplate = getParam('template');
  61. $aTemplates = get_templates_array(true, false);
  62. $aTmplVarsTemplates = array ();
  63. foreach($aTemplates as $sUri => $aTemplate) {
  64. $aTmplVarsTemplates[] = array(
  65. 'uri' => $sUri,
  66. 'title' => htmlspecialchars_adv($aTemplate['title']),
  67. 'version' => htmlspecialchars_adv($aTemplate['version']),
  68. 'vendor' => htmlspecialchars_adv($aTemplate['vendor']),
  69. 'icon' => $this->getModuleIcon($aTemplate['name'], 'store'),
  70. 'bx_if:default' => array (
  71. 'condition' => $sUri == $sTemplate,
  72. 'content' => array (),
  73. ),
  74. 'bx_if:make_default' => array (
  75. 'condition' => $sUri != $sTemplate,
  76. 'content' => array(
  77. 'js_object' => $sJsObject,
  78. 'uri' => $sUri
  79. ),
  80. )
  81. );
  82. }
  83. $sContent = $sResult ? MsgBox($sResult, 10) : '';
  84. $sContent .= $oTemplate->parseHtmlByName('templates.html', array(
  85. 'bx_repeat:templates' => $aTmplVarsTemplates,
  86. ));
  87. $aTmplVars = array(
  88. 'js_object' => $this->getPageJsObject(),
  89. 'bx_repeat:blocks' => $sContent,
  90. );
  91. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  92. }
  93. protected function getLogo() {
  94. $oTemplate = BxDolStudioTemplate::getInstance();
  95. $sAlt = $this->oDb->getParam('sys_site_logo_alt');
  96. $aForm = array(
  97. 'form_attrs' => array(
  98. 'id' => $this->sLogoFormId,
  99. 'name' => $this->sLogoFormId,
  100. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  101. 'method' => 'post',
  102. 'enctype' => 'multipart/form-data',
  103. 'target' => $this->sLogoIframeId
  104. ),
  105. 'params' => array(
  106. 'db' => array(
  107. 'table' => '',
  108. 'key' => '',
  109. 'uri' => '',
  110. 'uri_title' => '',
  111. 'submit_name' => 'save'
  112. ),
  113. ),
  114. 'inputs' => array(
  115. 'page' => array(
  116. 'type' => 'hidden',
  117. 'name' => 'page',
  118. 'value' => $this->sPage
  119. ),
  120. 'image' => array(
  121. 'type' => 'image_uploader',
  122. 'name' => 'image',
  123. 'caption' => _t('_adm_dsg_txt_upload_image'),
  124. 'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
  125. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
  126. 'value' => (int)$this->oDb->getParam('sys_site_logo')
  127. ),
  128. 'alt' => array(
  129. 'type' => 'text',
  130. 'name' => 'alt',
  131. 'caption' => _t('_adm_dsg_txt_alt_text'),
  132. 'info' => _t('_adm_dsg_dsc_alt_text'),
  133. 'value' => $sAlt,
  134. 'checker' => array(
  135. 'func' => '',
  136. 'params' => array(),
  137. 'error' => ''
  138. ),
  139. 'db' => array (
  140. 'pass' => 'Xss',
  141. ),
  142. ),
  143. 'save' => array(
  144. 'type' => 'submit',
  145. 'name' => 'save',
  146. 'value' => _t('_adm_btn_designer_submit'),
  147. )
  148. )
  149. );
  150. $oForm = new BxTemplStudioFormView($aForm);
  151. $oForm->initChecker();
  152. if($oForm->isSubmittedAndValid()) {
  153. echo $this->submitLogo($oForm);
  154. exit;
  155. }
  156. $aTmplVars = array(
  157. 'js_object' => $this->getPageJsObject(),
  158. 'bx_repeat:blocks' => array(
  159. array(
  160. 'caption' => '',
  161. 'panel_top' => '',
  162. 'items' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  163. 'panel_bottom' => ''
  164. )
  165. )
  166. );
  167. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  168. }
  169. protected function getIcon() {
  170. $oTemplate = BxDolStudioTemplate::getInstance();
  171. $sPreview = "";
  172. $aTmplVars = array('bx_repeat:images' => array());
  173. if(($iId = (int)$this->oDb->getParam('sys_site_icon')) != 0) {
  174. $aTranscoders = array(
  175. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  176. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  177. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  178. );
  179. bx_import('BxDolImageTranscoder');
  180. foreach($aTranscoders as $sTranscoder => $sTitle) {
  181. $oTranscoder = BxDolImageTranscoder::getObjectInstance($sTranscoder);
  182. $sImageUrl = $oTranscoder->getImageUrl($iId);
  183. if($sImageUrl === false) {
  184. $this->oDb->setParam('sys_site_icon', 0);
  185. break;
  186. }
  187. $aTmplVars['bx_repeat:images'][] = array(
  188. 'caption' => _t($sTitle),
  189. 'url' => $sImageUrl
  190. );
  191. }
  192. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  193. }
  194. $aForm = array(
  195. 'form_attrs' => array(
  196. 'id' => $this->sIconFormId,
  197. 'name' => $this->sIconFormId,
  198. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  199. 'method' => 'post',
  200. 'enctype' => 'multipart/form-data',
  201. 'target' => $this->sIconIframeId
  202. ),
  203. 'params' => array(
  204. 'db' => array(
  205. 'table' => '',
  206. 'key' => '',
  207. 'uri' => '',
  208. 'uri_title' => '',
  209. 'submit_name' => 'save'
  210. ),
  211. ),
  212. 'inputs' => array(
  213. 'page' => array(
  214. 'type' => 'hidden',
  215. 'name' => 'page',
  216. 'value' => $this->sPage
  217. ),
  218. 'preview' => array(
  219. 'type' => 'custom',
  220. 'name' => 'preview',
  221. 'content' => $sPreview
  222. ),
  223. 'image' => array(
  224. 'type' => 'file',
  225. 'name' => 'image',
  226. 'caption' => _t('_adm_dsg_txt_upload_icon')
  227. ),
  228. 'save' => array(
  229. 'type' => 'submit',
  230. 'name' => 'save',
  231. 'value' => _t('_adm_btn_designer_submit'),
  232. )
  233. )
  234. );
  235. $oForm = new BxTemplStudioFormView($aForm);
  236. $oForm->initChecker();
  237. if($oForm->isSubmittedAndValid()) {
  238. echo $this->submitIcon($oForm);
  239. exit;
  240. }
  241. $aTmplVars = array(
  242. 'js_object' => $this->getPageJsObject(),
  243. 'bx_repeat:blocks' => array(
  244. array(
  245. 'caption' => '',
  246. 'panel_top' => '',
  247. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  248. 'panel_bottom' => ''
  249. )
  250. )
  251. );
  252. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  253. }
  254. protected function getSettings() {
  255. $oTemplate = BxDolStudioTemplate::getInstance();
  256. bx_import('BxTemplStudioSettings');
  257. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  258. $aTmplVars = array(
  259. 'js_object' => $this->getPageJsObject(),
  260. 'bx_repeat:blocks' => $oPage->getPageCode(),
  261. );
  262. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  263. }
  264. }
  265. /** @} */