BxBaseStudioDesigner.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioDesigner extends BxDolStudioDesigner
  11. {
  12. protected $sLogoFormId = 'adm-dsg-logo-form';
  13. protected $sLogoIframeId = 'adm-dsg-logo-iframe';
  14. protected $sIconFormId = 'adm-dsg-icon-form';
  15. protected $sIconIframeId = 'adm-dsg-icon-iframe';
  16. protected $sCoverFormId = 'adm-dsg-cover-form';
  17. protected $sCoverIframeId = 'adm-dsg-cover-iframe';
  18. protected $sCoverStorage = BX_DOL_STORAGE_OBJ_IMAGES;
  19. protected $sCoverTranscoder = 'sys_cover_preview';
  20. protected $sSplashFormId = 'adm-dsg-splash-form';
  21. protected $sSplashIframeId = 'adm-dsg-splash-iframe';
  22. protected $sSplashEditorId = 'adm-dsg-splash-editor';
  23. protected $sInjectionsFormId = 'adm-dsg-injections-form';
  24. protected $sInjectionsIframeId = 'adm-dsg-injections-iframe';
  25. protected $sInjectionsEditorId = 'adm-dsg-injections-editor';
  26. public function __construct($sPage = '')
  27. {
  28. parent::__construct($sPage);
  29. $this->aPageCss = array_merge($this->aPageCss, ['forms.css', 'designer.css']);
  30. $this->aPageJs = array_merge($this->aPageJs, ['designer.js']);
  31. $this->sPageJsClass = 'BxDolStudioDesigner';
  32. $this->sPageJsObject = 'oBxDolStudioDesigner';
  33. }
  34. public function getPageJsCode($aOptions = array(), $bWrap = true)
  35. {
  36. $aOptions = array_merge([
  37. 'sActionUrl' => $this->sManageUrl,
  38. 'sParamPrefix' => $this->sParamPrefix
  39. ], $aOptions);
  40. return parent::getPageJsCode($aOptions, $bWrap);
  41. }
  42. public function getPageMenu($aMenu = array(), $aMarkers = array())
  43. {
  44. $sJsObject = $this->getPageJsObject();
  45. $aMenu = array();
  46. $aMenuItems = array(
  47. BX_DOL_STUDIO_DSG_TYPE_GENERAL => array('icon' => 'globe'),
  48. BX_DOL_STUDIO_DSG_TYPE_LOGO => array('icon' => 'pencil-alt'),
  49. BX_DOL_STUDIO_DSG_TYPE_ICON => array('icon' => 'far image'),
  50. BX_DOL_STUDIO_DSG_TYPE_COVER => array('icon' => 'far file-image'),
  51. BX_DOL_STUDIO_DSG_TYPE_SPLASH => array('icon' => 'far file-image'),
  52. BX_DOL_STUDIO_DSG_TYPE_INJECTIONS => array('icon' => 'object-group'),
  53. BX_DOL_STUDIO_DSG_TYPE_SETTINGS => array('icon' => 'cogs'),
  54. );
  55. foreach($aMenuItems as $sMenuItem => $aItem)
  56. $aMenu[] = array(
  57. 'name' => $sMenuItem,
  58. 'icon' => $aItem['icon'],
  59. 'link' => BX_DOL_URL_STUDIO . 'designer.php?page=' . $sMenuItem,
  60. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  61. 'selected' => $sMenuItem == $this->sPage
  62. );
  63. return parent::getPageMenu($aMenu);
  64. }
  65. protected function getGeneral()
  66. {
  67. $sJsObject = $this->getPageJsObject();
  68. $oTemplate = BxDolStudioTemplate::getInstance();
  69. $sResult = '';
  70. $sTemplate = getParam('template');
  71. $aTemplates = get_templates_array(true, false);
  72. $aTmplVarsTemplates = array ();
  73. foreach($aTemplates as $sUri => $aTemplate) {
  74. $sIcon = $this->getModuleIcon($aTemplate, 'store');
  75. $bIcon = strpos($sIcon, '.') === false && strcmp(substr($sIcon, 0, 10), 'data:image') != 0;
  76. $aTmplVarsTemplates[] = array(
  77. 'uri' => $sUri,
  78. 'title' => htmlspecialchars_adv($aTemplate['title']),
  79. 'version' => htmlspecialchars_adv($aTemplate['version']),
  80. 'vendor' => htmlspecialchars_adv($aTemplate['vendor']),
  81. 'bx_if:icon' => array (
  82. 'condition' => $bIcon,
  83. 'content' => array('icon' => $sIcon),
  84. ),
  85. 'bx_if:image' => array (
  86. 'condition' => !$bIcon,
  87. 'content' => array('icon_url' => $sIcon),
  88. ),
  89. 'bx_if:default' => array (
  90. 'condition' => $sUri == $sTemplate,
  91. 'content' => array (),
  92. ),
  93. 'bx_if:make_default' => array (
  94. 'condition' => $sUri != $sTemplate,
  95. 'content' => array(
  96. 'js_object' => $sJsObject,
  97. 'uri' => $sUri
  98. ),
  99. )
  100. );
  101. }
  102. $sContent = $sResult ? MsgBox($sResult, 10) : '';
  103. $sContent .= $oTemplate->parseHtmlByName('templates.html', array(
  104. 'bx_repeat:templates' => $aTmplVarsTemplates,
  105. ));
  106. return $oTemplate->parseHtmlByName('designer.html', array(
  107. 'content' => $sContent,
  108. 'js_content' => $this->getPageJsCode()
  109. ));
  110. }
  111. protected function getLogo()
  112. {
  113. $oTemplate = BxDolStudioTemplate::getInstance();
  114. $aForm = array(
  115. 'form_attrs' => array(
  116. 'id' => $this->sLogoFormId,
  117. 'name' => $this->sLogoFormId,
  118. 'action' => $this->sManageUrl,
  119. 'method' => 'post',
  120. 'enctype' => 'multipart/form-data',
  121. 'target' => $this->sLogoIframeId
  122. ),
  123. 'params' => array(
  124. 'db' => array(
  125. 'table' => '',
  126. 'key' => '',
  127. 'uri' => '',
  128. 'uri_title' => '',
  129. 'submit_name' => 'save'
  130. ),
  131. ),
  132. 'inputs' => array(
  133. 'page' => array(
  134. 'type' => 'hidden',
  135. 'name' => 'page',
  136. 'value' => $this->sPage
  137. ),
  138. 'image' => array(
  139. 'type' => 'image_uploader',
  140. 'name' => 'image',
  141. 'caption' => _t('_adm_dsg_txt_upload_image'),
  142. 'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
  143. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
  144. 'storage_object' => 'sys_images_custom',
  145. 'value' => (int)getParam($this->sParamLogo),
  146. ),
  147. 'alt' => array(
  148. 'type' => 'text',
  149. 'name' => 'alt',
  150. 'caption' => _t('_adm_dsg_txt_alt_text'),
  151. 'info' => _t('_adm_dsg_dsc_alt_text'),
  152. 'value' => getParam($this->sParamLogoAlt),
  153. 'checker' => array(
  154. 'func' => '',
  155. 'params' => array(),
  156. 'error' => ''
  157. ),
  158. 'db' => array (
  159. 'pass' => 'Xss',
  160. ),
  161. ),
  162. 'save' => array(
  163. 'type' => 'submit',
  164. 'name' => 'save',
  165. 'value' => _t('_adm_btn_designer_submit'),
  166. )
  167. )
  168. );
  169. $oForm = new BxTemplStudioFormView($aForm);
  170. $oForm->initChecker();
  171. if($oForm->isSubmittedAndValid()) {
  172. echo $this->submitLogo($oForm);
  173. exit;
  174. }
  175. return MsgBox(_t('_adm_dsg_txt_logo_redefinition')) . $oTemplate->parseHtmlByName('designer.html', array(
  176. 'content' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  177. 'js_content' => $this->getPageJsCode()
  178. ));
  179. }
  180. protected function getIcon()
  181. {
  182. $oTemplate = BxDolStudioTemplate::getInstance();
  183. $sPreview = "";
  184. $aTmplVars = array('bx_repeat:images' => array());
  185. if(($iId = (int)getParam('sys_site_icon')) != 0) {
  186. $aTranscoders = array(
  187. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  188. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  189. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  190. );
  191. foreach($aTranscoders as $sTranscoder => $sTitle) {
  192. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  193. $sImageUrl = $oTranscoder->getFileUrl($iId);
  194. if($sImageUrl === false) {
  195. setParam('sys_site_icon', 0);
  196. break;
  197. }
  198. $aFilterParams = $oTranscoder->getFilterParams('Resize');
  199. $bFilterWidth = !empty($aFilterParams['w']);
  200. $bFilterHeight = !empty($aFilterParams['h']);
  201. $aTmplVars['bx_repeat:images'][] = array(
  202. 'caption' => _t($sTitle),
  203. 'url' => $sImageUrl,
  204. 'bx_if:show_width' => array(
  205. 'condition' => $bFilterWidth,
  206. 'content' => array(
  207. 'width' => $bFilterWidth ? (int)$aFilterParams['w'] : 0
  208. )
  209. ),
  210. 'bx_if:show_height' => array(
  211. 'condition' => $bFilterHeight,
  212. 'content' => array(
  213. 'height' => $bFilterHeight ? (int)$aFilterParams['h'] : 0
  214. )
  215. ),
  216. );
  217. }
  218. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  219. }
  220. $aForm = array(
  221. 'form_attrs' => array(
  222. 'id' => $this->sIconFormId,
  223. 'name' => $this->sIconFormId,
  224. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  225. 'method' => 'post',
  226. 'enctype' => 'multipart/form-data',
  227. 'target' => $this->sIconIframeId
  228. ),
  229. 'params' => array(
  230. 'db' => array(
  231. 'table' => '',
  232. 'key' => '',
  233. 'uri' => '',
  234. 'uri_title' => '',
  235. 'submit_name' => 'save'
  236. ),
  237. ),
  238. 'inputs' => array(
  239. 'page' => array(
  240. 'type' => 'hidden',
  241. 'name' => 'page',
  242. 'value' => $this->sPage
  243. ),
  244. 'preview' => array(
  245. 'type' => 'custom',
  246. 'name' => 'preview',
  247. 'content' => $sPreview
  248. ),
  249. 'image' => array(
  250. 'type' => 'file',
  251. 'name' => 'image',
  252. 'caption' => _t('_adm_dsg_txt_upload_icon')
  253. ),
  254. 'save' => array(
  255. 'type' => 'submit',
  256. 'name' => 'save',
  257. 'value' => _t('_adm_btn_designer_submit'),
  258. )
  259. )
  260. );
  261. $oForm = new BxTemplStudioFormView($aForm);
  262. $oForm->initChecker();
  263. if($oForm->isSubmittedAndValid()) {
  264. echo $this->submitIcon($oForm);
  265. exit;
  266. }
  267. return $oTemplate->parseHtmlByName('designer.html', array(
  268. 'content' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  269. 'js_content' => $this->getPageJsCode()
  270. ));
  271. }
  272. protected function getCover()
  273. {
  274. $sJsObject = $this->getPageJsObject();
  275. $oTemplate = BxDolStudioTemplate::getInstance();
  276. $oDbSettings = new BxDolStudioSettingsQuery();
  277. $aFormInputs = array();
  278. $aTmplVarsCovers = array();
  279. foreach($this->aCovers as $sCover => $aCover) {
  280. $aSetting = array();
  281. $oDbSettings->getOptions(array('type' => 'by_name', 'value' => $aCover['setting']), $aSetting, false);
  282. if(empty($aSetting) || !is_array($aSetting))
  283. continue;
  284. $aFormInputs[$sCover] = array(
  285. 'type' => 'files',
  286. 'name' => $sCover,
  287. 'storage_object' => $this->sCoverStorage,
  288. 'images_transcoder' => $this->sCoverTranscoder,
  289. 'uploaders' => array('sys_std_crop_cover'),
  290. 'multiple' => false,
  291. 'content_id' => $aSetting['id'],
  292. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('uploader_fgt_cover.html', array(
  293. 'name' => $sCover,
  294. )),
  295. 'caption' => _t('_adm_dsg_txt_upload_' . $sCover),
  296. 'db' => array (
  297. 'pass' => 'Int',
  298. )
  299. );
  300. if(($iImageId = (int)getParam($aCover['setting'])) == 0)
  301. continue;
  302. $sImageUrl = BxDolTranscoderImage::getObjectInstance($aCover['transcoder'])->getFileUrl($iImageId);
  303. if($sImageUrl === false) {
  304. setParam($aCover['setting'], 0);
  305. continue;
  306. }
  307. $aTmplVarsCovers[] = array(
  308. 'image_id' => $iImageId,
  309. 'content' => $oTemplate->parseHtmlByName($aCover['template'], array(
  310. 'js_object' => $sJsObject,
  311. 'type' => $sCover,
  312. 'caption' => _t($aCover['title']),
  313. 'image_id' => $iImageId,
  314. 'bx_if:show_bg' => array(
  315. 'condition' => !empty($sImageUrl),
  316. 'content' => array(
  317. 'image_url' => $sImageUrl
  318. )
  319. ),
  320. ))
  321. );
  322. }
  323. $aForm = array(
  324. 'form_attrs' => array(
  325. 'id' => $this->sCoverFormId,
  326. 'name' => $this->sCoverFormId,
  327. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  328. 'method' => 'post',
  329. 'enctype' => 'multipart/form-data',
  330. 'target' => $this->sCoverIframeId
  331. ),
  332. 'params' => array(
  333. 'db' => array(
  334. 'table' => '',
  335. 'key' => '',
  336. 'uri' => '',
  337. 'uri_title' => '',
  338. 'submit_name' => 'save'
  339. ),
  340. ),
  341. 'inputs' => array(
  342. 'page' => array(
  343. 'type' => 'hidden',
  344. 'name' => 'page',
  345. 'value' => $this->sPage
  346. ),
  347. 'disabled' => array(
  348. 'type' => 'checkbox',
  349. 'name' => 'enabled',
  350. 'caption' => _t('_adm_dsg_txt_cover_disabled'),
  351. 'value' => 'on',
  352. 'checked' => getParam('sys_site_cover_disabled') == 'on',
  353. 'db' => array (
  354. 'pass' => 'Xss',
  355. ),
  356. ),
  357. 'preview' => array(
  358. 'type' => 'custom',
  359. 'name' => 'preview',
  360. 'content' => $oTemplate->parseHtmlByName('dsr_cover_preview.html', array(
  361. 'bx_repeat:covers' => $aTmplVarsCovers
  362. ))
  363. ),
  364. 'save' => array(
  365. 'type' => 'submit',
  366. 'name' => 'save',
  367. 'value' => _t('_adm_btn_designer_submit'),
  368. )
  369. )
  370. );
  371. $aForm['inputs'] = bx_array_insert_after($aFormInputs, $aForm['inputs'], 'preview');
  372. $oForm = new BxTemplStudioFormView($aForm);
  373. $oForm->initChecker();
  374. if($oForm->isSubmittedAndValid()) {
  375. echo $this->submitCover($oForm);
  376. exit;
  377. }
  378. $this->aPageCss[] = 'cover.css';
  379. return $oTemplate->parseHtmlByName('designer.html', array(
  380. 'content' => $oTemplate->parseHtmlByName('dsr_cover.html', array('iframe_id' => $this->sCoverIframeId, 'form' => $oForm->getCode())),
  381. 'js_content' => $this->getPageJsCode()
  382. ));
  383. }
  384. protected function getSplash()
  385. {
  386. $oTemplate = BxDolStudioTemplate::getInstance();
  387. $aForm = array(
  388. 'form_attrs' => array(
  389. 'id' => $this->sSplashFormId,
  390. 'name' => $this->sSplashFormId,
  391. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  392. 'method' => 'post',
  393. 'enctype' => 'multipart/form-data',
  394. 'target' => $this->sSplashIframeId
  395. ),
  396. 'params' => array(
  397. 'db' => array(
  398. 'table' => '',
  399. 'key' => '',
  400. 'uri' => '',
  401. 'uri_title' => '',
  402. 'submit_name' => 'save'
  403. ),
  404. ),
  405. 'inputs' => array(
  406. 'page' => array(
  407. 'type' => 'hidden',
  408. 'name' => 'page',
  409. 'value' => $this->sPage
  410. ),
  411. 'enabled' => array(
  412. 'type' => 'checkbox',
  413. 'name' => 'enabled',
  414. 'caption' => _t('_adm_dsg_txt_splash_enabled'),
  415. 'value' => 'on',
  416. 'checked' => getParam('sys_site_splash_enabled') == 'on',
  417. 'db' => array (
  418. 'pass' => 'Xss',
  419. ),
  420. ),
  421. 'code' => array(
  422. 'type' => 'textarea',
  423. 'code' => true,
  424. 'name' => 'code',
  425. 'caption' => '',
  426. 'value' => getParam('sys_site_splash_code'),
  427. ),
  428. 'save' => array(
  429. 'type' => 'submit',
  430. 'name' => 'save',
  431. 'value' => _t('_adm_btn_designer_submit'),
  432. )
  433. )
  434. );
  435. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  436. $oForm->initChecker();
  437. if($oForm->isSubmittedAndValid()) {
  438. echo $this->submitSplash($oForm);
  439. exit;
  440. }
  441. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  442. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  443. return $oTemplate->parseHtmlByName('designer.html', array(
  444. 'content' => $oTemplate->parseHtmlByName('dsr_splash.html', array(
  445. 'warning' => MsgBox(_t('_adm_dsg_dsc_splash_warning')),
  446. 'splash_iframe_id' => $this->sSplashIframeId,
  447. 'form' => $oForm->getCode()
  448. )),
  449. 'js_content' => $this->getPageJsCode(array(
  450. 'sCodeMirror' => 'textarea[name=code]'
  451. )),
  452. ));
  453. }
  454. protected function getInjections()
  455. {
  456. $oTemplate = BxDolStudioTemplate::getInstance();
  457. $aForm = array(
  458. 'form_attrs' => array(
  459. 'id' => $this->sInjectionsFormId,
  460. 'name' => $this->sInjectionsFormId,
  461. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  462. 'method' => 'post',
  463. 'enctype' => 'multipart/form-data',
  464. 'target' => $this->sInjectionsIframeId
  465. ),
  466. 'params' => array(
  467. 'db' => array(
  468. 'table' => '',
  469. 'key' => '',
  470. 'uri' => '',
  471. 'uri_title' => '',
  472. 'submit_name' => 'save'
  473. ),
  474. ),
  475. 'inputs' => array(
  476. 'page' => array(
  477. 'type' => 'hidden',
  478. 'name' => 'page',
  479. 'value' => $this->sPage
  480. ),
  481. 'sys_head' => array(
  482. 'type' => 'textarea',
  483. 'code' => true,
  484. 'name' => 'sys_head',
  485. 'caption' => _t('_adm_dsg_txt_inj_head'),
  486. 'info' => _t('_adm_dsg_txt_inj_head_inf'),
  487. 'value' => $this->oDb->getOne("SELECT `data` FROM `sys_injections` WHERE `name`='sys_head'"),
  488. ),
  489. 'sys_body' => array(
  490. 'type' => 'textarea',
  491. 'code' => true,
  492. 'name' => 'sys_body',
  493. 'caption' => _t('_adm_dsg_txt_inj_body'),
  494. 'info' => _t('_adm_dsg_txt_inj_body_inf'),
  495. 'value' => $this->oDb->getOne("SELECT `data` FROM `sys_injections` WHERE `name`='sys_body'"),
  496. ),
  497. 'save' => array(
  498. 'type' => 'submit',
  499. 'name' => 'save',
  500. 'value' => _t('_adm_btn_designer_submit'),
  501. )
  502. )
  503. );
  504. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  505. $oForm->initChecker();
  506. if($oForm->isSubmittedAndValid()) {
  507. echo $this->submitInjections($oForm);
  508. exit;
  509. }
  510. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  511. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  512. return $oTemplate->parseHtmlByName('designer.html', array(
  513. 'content' => $oTemplate->parseHtmlByName('dsr_injections.html', array(
  514. 'warning' => '',
  515. 'splash_iframe_id' => $this->sInjectionsIframeId,
  516. 'form' => $oForm->getCode()
  517. )),
  518. 'js_content' => $this->getPageJsCode(array(
  519. 'sCodeMirror' => 'textarea[name=sys_head],textarea[name=sys_body]'
  520. ))
  521. ));
  522. }
  523. protected function getSettings()
  524. {
  525. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  526. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  527. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  528. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', array(
  529. 'content' => $oOptions->getCode(),
  530. 'js_content' => $this->getPageJsCode()
  531. ));
  532. }
  533. }
  534. /** @} */