BxBaseStudioDesigner.php 26 KB

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