BxBaseStudioDesigner.php 10 KB

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