BxBaseStudioDesigner.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. $aInputs = [];
  164. foreach($this->aLogos as $sLogo => $aLogo) {
  165. if(empty($this->{$aLogo['param']}))
  166. continue;
  167. if(isset($aLogo['storage'], $aLogo['transcoder']))
  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. else
  181. $aInputs[$sLogo] = [
  182. 'type' => 'textarea',
  183. 'name' => $sLogo,
  184. 'caption' => _t('_adm_dsg_txt_upload_' . $sLogo),
  185. 'value' => getParam($this->{$aLogo['param']}),
  186. 'code' => 1,
  187. 'db' => [
  188. 'pass' => 'Xss',
  189. ],
  190. ];
  191. }
  192. $aForm['inputs'] = bx_array_insert_after($aInputs, $aForm['inputs'], 'page');
  193. $oForm = new BxTemplStudioFormView($aForm);
  194. $oForm->initChecker();
  195. if($oForm->isSubmittedAndValid()) {
  196. echo $this->submitLogo($oForm);
  197. exit;
  198. }
  199. return MsgBox(_t('_adm_dsg_txt_logo_redefinition')) . $oTemplate->parseHtmlByName('designer.html', array(
  200. 'content' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  201. 'js_content' => $this->getPageJsCode()
  202. ));
  203. }
  204. protected function getIcon()
  205. {
  206. $oTemplate = BxDolStudioTemplate::getInstance();
  207. $oFunctions = BxTemplStudioFunctions::getInstance();
  208. $aTmplVarsPreview = ['bx_repeat:images' => []];
  209. foreach($this->aIcons as $sIcon => $aIcon) {
  210. $sSetting = 'sys_site_' . $sIcon;
  211. $iIconValue = (int)getParam($sSetting);
  212. if(($iOptionId = $this->getOptionId($sSetting)) != 0)
  213. $this->aIcons[$sIcon]['id'] = $iOptionId;
  214. if(empty($iIconValue))
  215. continue;
  216. $sIconUrl = '';
  217. $aIconParams = [];
  218. if(!empty($aIcon['transcoder'])) {
  219. $oTranscoder = BxDolTranscoderImage::getObjectInstance($aIcon['transcoder']);
  220. $sIconUrl = $oTranscoder->getFileUrl($iIconValue);
  221. $aIconParams = $oTranscoder->getFilterParams('Resize');
  222. }
  223. else {
  224. $oStorage = BxDolStorage::getObjectInstance($aIcon['storage']);
  225. $sIconUrl = $oStorage->getFileUrlById($iIconValue);
  226. }
  227. if($sIconUrl === false) {
  228. setParam($sSetting, 0);
  229. continue;
  230. }
  231. $bIconWidth = !empty($aIconParams['w']);
  232. $bIconHeight = !empty($aIconParams['h']);
  233. $aTmplVarsPreview['bx_repeat:images'][] = array(
  234. 'js_object' => $this->getPageJsObject(),
  235. 'id' => $iIconValue,
  236. 'name' => $sIcon,
  237. 'caption' => _t('_adm_dsg_txt_' . $sIcon),
  238. 'url' => $sIconUrl,
  239. 'bx_if:show_width' => array(
  240. 'condition' => $bIconWidth,
  241. 'content' => array(
  242. 'width' => $bIconWidth ? (int)$aIconParams['w'] : 0
  243. )
  244. ),
  245. 'bx_if:show_height' => array(
  246. 'condition' => $bIconHeight,
  247. 'content' => array(
  248. 'height' => $bIconHeight ? (int)$aIconParams['h'] : 0
  249. )
  250. ),
  251. );
  252. }
  253. $aForm = array(
  254. 'form_attrs' => array(
  255. 'id' => $this->sIconFormId,
  256. 'name' => $this->sIconFormId,
  257. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  258. 'method' => 'post',
  259. 'enctype' => 'multipart/form-data',
  260. 'target' => $this->sIconIframeId
  261. ),
  262. 'params' => array(
  263. 'db' => array(
  264. 'table' => '',
  265. 'key' => '',
  266. 'uri' => '',
  267. 'uri_title' => '',
  268. 'submit_name' => 'save'
  269. ),
  270. ),
  271. 'inputs' => array(
  272. 'page' => array(
  273. 'type' => 'hidden',
  274. 'name' => 'page',
  275. 'value' => $this->sPage
  276. ),
  277. 'icon' => array(
  278. 'type' => 'file',
  279. 'name' => 'icon',
  280. 'caption' => _t('_adm_dsg_txt_upload_icon'),
  281. 'info' => _t('_adm_dsg_txt_upload_icon_inf'),
  282. 'attrs' => ['accept' => '.ico']
  283. ),
  284. 'icon_svg' => array(
  285. 'type' => 'file',
  286. 'name' => 'icon_svg',
  287. 'caption' => _t('_adm_dsg_txt_upload_icon_svg'),
  288. 'info' => _t('_adm_dsg_txt_upload_icon_svg_inf'),
  289. 'attrs' => ['accept' => '.svg']
  290. ),
  291. 'icon_apple' => array(
  292. 'type' => 'files',
  293. 'name' => 'icon_apple',
  294. 'storage_object' => $this->aIcons['icon_apple']['storage'],
  295. 'images_transcoder' => $this->aIcons['icon_apple']['transcoder'],
  296. 'uploaders' => ['sys_html5'],
  297. 'multiple' => false,
  298. 'content_id' => $this->aIcons['icon_apple']['id'],
  299. 'ghost_template' => $oFunctions->getDefaultGhostTemplate('icon_apple'),
  300. 'caption' => _t('_adm_dsg_txt_upload_icon_apple'),
  301. 'info' => _t('_adm_dsg_txt_upload_icon_apple_inf'),
  302. ),
  303. 'icon_android' => array(
  304. 'type' => 'files',
  305. 'name' => 'icon_android',
  306. 'storage_object' => $this->aIcons['icon_android']['storage'],
  307. 'images_transcoder' => $this->aIcons['icon_android']['transcoder'],
  308. 'uploaders' => ['sys_html5'],
  309. 'multiple' => false,
  310. 'content_id' => $this->aIcons['icon_android']['id'],
  311. 'ghost_template' => $oFunctions->getDefaultGhostTemplate('icon_android'),
  312. 'caption' => _t('_adm_dsg_txt_upload_icon_android'),
  313. 'info' => _t('_adm_dsg_txt_upload_icon_android_inf'),
  314. ),
  315. 'icon_android_splash' => array(
  316. 'type' => 'files',
  317. 'name' => 'icon_android_splash',
  318. 'storage_object' => $this->aIcons['icon_android_splash']['storage'],
  319. 'images_transcoder' => $this->aIcons['icon_android_splash']['transcoder'],
  320. 'uploaders' => ['sys_html5'],
  321. 'multiple' => false,
  322. 'content_id' => $this->aIcons['icon_android_splash']['id'],
  323. 'ghost_template' => $oFunctions->getDefaultGhostTemplate('icon_android_splash'),
  324. 'caption' => _t('_adm_dsg_txt_upload_icon_android_splash'),
  325. 'info' => _t('_adm_dsg_txt_upload_icon_android_splash_inf'),
  326. ),
  327. 'save' => array(
  328. 'type' => 'submit',
  329. 'name' => 'save',
  330. 'value' => _t('_adm_btn_designer_submit'),
  331. )
  332. )
  333. );
  334. $oForm = new BxTemplStudioFormView($aForm);
  335. $oForm->initChecker();
  336. if($oForm->isSubmittedAndValid()) {
  337. echo $this->submitIcon($oForm);
  338. exit;
  339. }
  340. return $oTemplate->parseHtmlByName('designer.html', [
  341. 'content' => $oTemplate->parseHtmlByName('dsr_icon.html', [
  342. 'preview' => $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVarsPreview),
  343. 'icon_iframe_id' => $this->sIconIframeId,
  344. 'form' => $oForm->getCode()
  345. ]),
  346. 'js_content' => $this->getPageJsCode()
  347. ]);
  348. }
  349. protected function getCover()
  350. {
  351. $sJsObject = $this->getPageJsObject();
  352. $oTemplate = BxDolStudioTemplate::getInstance();
  353. $oDbSettings = new BxDolStudioSettingsQuery();
  354. $aFormInputs = array();
  355. $aTmplVarsCovers = array();
  356. foreach($this->aCovers as $sCover => $aCover) {
  357. $aSetting = array();
  358. $oDbSettings->getOptions(array('type' => 'by_name', 'value' => $aCover['setting']), $aSetting, false);
  359. if(empty($aSetting) || !is_array($aSetting))
  360. continue;
  361. $aFormInputs[$sCover] = array(
  362. 'type' => 'files',
  363. 'name' => $sCover,
  364. 'storage_object' => $this->sCoverStorage,
  365. 'images_transcoder' => $this->sCoverTranscoder,
  366. 'uploaders' => array('sys_std_crop_cover'),
  367. 'multiple' => false,
  368. 'content_id' => $aSetting['id'],
  369. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate($sCover),
  370. 'caption' => _t('_adm_dsg_txt_upload_' . $sCover),
  371. 'db' => array (
  372. 'pass' => 'Int',
  373. )
  374. );
  375. if(($iImageId = (int)getParam($aCover['setting'])) == 0)
  376. continue;
  377. $sImageUrl = BxDolTranscoderImage::getObjectInstance($aCover['transcoder'])->getFileUrl($iImageId);
  378. if($sImageUrl === false) {
  379. setParam($aCover['setting'], 0);
  380. continue;
  381. }
  382. $aTmplVarsCovers[] = array(
  383. 'image_id' => $iImageId,
  384. 'content' => $oTemplate->parseHtmlByName($aCover['template'], array(
  385. 'js_object' => $sJsObject,
  386. 'type' => $sCover,
  387. 'caption' => _t($aCover['title']),
  388. 'image_id' => $iImageId,
  389. 'bx_if:show_bg' => array(
  390. 'condition' => !empty($sImageUrl),
  391. 'content' => array(
  392. 'image_url' => $sImageUrl
  393. )
  394. ),
  395. ))
  396. );
  397. }
  398. $aForm = array(
  399. 'form_attrs' => array(
  400. 'id' => $this->sCoverFormId,
  401. 'name' => $this->sCoverFormId,
  402. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  403. 'method' => 'post',
  404. 'enctype' => 'multipart/form-data',
  405. 'target' => $this->sCoverIframeId
  406. ),
  407. 'params' => array(
  408. 'db' => array(
  409. 'table' => '',
  410. 'key' => '',
  411. 'uri' => '',
  412. 'uri_title' => '',
  413. 'submit_name' => 'save'
  414. ),
  415. ),
  416. 'inputs' => array(
  417. 'page' => array(
  418. 'type' => 'hidden',
  419. 'name' => 'page',
  420. 'value' => $this->sPage
  421. ),
  422. 'disabled' => array(
  423. 'type' => 'checkbox',
  424. 'name' => 'enabled',
  425. 'caption' => _t('_adm_dsg_txt_cover_disabled'),
  426. 'value' => 'on',
  427. 'checked' => getParam('sys_site_cover_disabled') == 'on',
  428. 'db' => array (
  429. 'pass' => 'Xss',
  430. ),
  431. ),
  432. 'preview' => array(
  433. 'type' => 'custom',
  434. 'name' => 'preview',
  435. 'content' => $oTemplate->parseHtmlByName('dsr_cover_preview.html', array(
  436. 'bx_repeat:covers' => $aTmplVarsCovers
  437. ))
  438. ),
  439. 'save' => array(
  440. 'type' => 'submit',
  441. 'name' => 'save',
  442. 'value' => _t('_adm_btn_designer_submit'),
  443. )
  444. )
  445. );
  446. $aForm['inputs'] = bx_array_insert_after($aFormInputs, $aForm['inputs'], 'preview');
  447. $oForm = new BxTemplStudioFormView($aForm);
  448. $oForm->initChecker();
  449. if($oForm->isSubmittedAndValid()) {
  450. echo $this->submitCover($oForm);
  451. exit;
  452. }
  453. $this->aPageCss[] = 'cover.css';
  454. return $oTemplate->parseHtmlByName('designer.html', array(
  455. 'content' => $oTemplate->parseHtmlByName('dsr_cover.html', array('iframe_id' => $this->sCoverIframeId, 'form' => $oForm->getCode())),
  456. 'js_content' => $this->getPageJsCode()
  457. ));
  458. }
  459. protected function getSplash()
  460. {
  461. $oTemplate = BxDolStudioTemplate::getInstance();
  462. $aForm = array(
  463. 'form_attrs' => array(
  464. 'id' => $this->sSplashFormId,
  465. 'name' => $this->sSplashFormId,
  466. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  467. 'method' => 'post',
  468. 'enctype' => 'multipart/form-data',
  469. 'target' => $this->sSplashIframeId
  470. ),
  471. 'params' => array(
  472. 'db' => array(
  473. 'table' => '',
  474. 'key' => '',
  475. 'uri' => '',
  476. 'uri_title' => '',
  477. 'submit_name' => 'save'
  478. ),
  479. ),
  480. 'inputs' => array(
  481. 'page' => array(
  482. 'type' => 'hidden',
  483. 'name' => 'page',
  484. 'value' => $this->sPage
  485. ),
  486. 'enabled' => array(
  487. 'type' => 'checkbox',
  488. 'name' => 'enabled',
  489. 'caption' => _t('_adm_dsg_txt_splash_enabled'),
  490. 'value' => 'on',
  491. 'checked' => getParam('sys_site_splash_enabled') == 'on',
  492. 'db' => array (
  493. 'pass' => 'Xss',
  494. ),
  495. ),
  496. 'code' => array(
  497. 'type' => 'textarea',
  498. 'code' => true,
  499. 'name' => 'code',
  500. 'caption' => '',
  501. 'value' => getParam('sys_site_splash_code'),
  502. ),
  503. 'save' => array(
  504. 'type' => 'submit',
  505. 'name' => 'save',
  506. 'value' => _t('_adm_btn_designer_submit'),
  507. )
  508. )
  509. );
  510. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  511. $oForm->initChecker();
  512. if($oForm->isSubmittedAndValid()) {
  513. echo $this->submitSplash($oForm);
  514. exit;
  515. }
  516. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  517. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  518. return $oTemplate->parseHtmlByName('designer.html', array(
  519. 'content' => $oTemplate->parseHtmlByName('dsr_splash.html', array(
  520. 'warning' => MsgBox(_t('_adm_dsg_dsc_splash_warning')),
  521. 'splash_iframe_id' => $this->sSplashIframeId,
  522. 'form' => $oForm->getCode()
  523. )),
  524. 'js_content' => $this->getPageJsCode(array(
  525. 'sCodeMirror' => 'textarea[name=code]'
  526. )),
  527. ));
  528. }
  529. protected function getInjections()
  530. {
  531. $oTemplate = BxDolStudioTemplate::getInstance();
  532. $aForm = array(
  533. 'form_attrs' => array(
  534. 'id' => $this->sInjectionsFormId,
  535. 'name' => $this->sInjectionsFormId,
  536. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  537. 'method' => 'post',
  538. 'enctype' => 'multipart/form-data',
  539. 'target' => $this->sInjectionsIframeId
  540. ),
  541. 'params' => array(
  542. 'db' => array(
  543. 'table' => '',
  544. 'key' => '',
  545. 'uri' => '',
  546. 'uri_title' => '',
  547. 'submit_name' => 'save'
  548. ),
  549. ),
  550. 'inputs' => array(
  551. 'page' => array(
  552. 'type' => 'hidden',
  553. 'name' => 'page',
  554. 'value' => $this->sPage
  555. ),
  556. 'sys_head' => array(
  557. 'type' => 'textarea',
  558. 'code' => true,
  559. 'name' => 'sys_head',
  560. 'caption' => _t('_adm_dsg_txt_inj_head'),
  561. 'info' => _t('_adm_dsg_txt_inj_head_inf'),
  562. 'value' => $this->oDb->getOne("SELECT `data` FROM `sys_injections` WHERE `name`='sys_head'"),
  563. ),
  564. 'sys_body' => array(
  565. 'type' => 'textarea',
  566. 'code' => true,
  567. 'name' => 'sys_body',
  568. 'caption' => _t('_adm_dsg_txt_inj_body'),
  569. 'info' => _t('_adm_dsg_txt_inj_body_inf'),
  570. 'value' => $this->oDb->getOne("SELECT `data` FROM `sys_injections` WHERE `name`='sys_body'"),
  571. ),
  572. 'save' => array(
  573. 'type' => 'submit',
  574. 'name' => 'save',
  575. 'value' => _t('_adm_btn_designer_submit'),
  576. )
  577. )
  578. );
  579. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  580. $oForm->initChecker();
  581. if($oForm->isSubmittedAndValid()) {
  582. echo $this->submitInjections($oForm);
  583. exit;
  584. }
  585. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  586. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  587. return $oTemplate->parseHtmlByName('designer.html', array(
  588. 'content' => $oTemplate->parseHtmlByName('dsr_injections.html', array(
  589. 'warning' => '',
  590. 'splash_iframe_id' => $this->sInjectionsIframeId,
  591. 'form' => $oForm->getCode()
  592. )),
  593. 'js_content' => $this->getPageJsCode(array(
  594. 'sCodeMirror' => 'textarea[name=sys_head],textarea[name=sys_body]'
  595. ))
  596. ));
  597. }
  598. protected function getPwa()
  599. {
  600. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_SYSTEM, ['pwa_manifest', 'pwa_sw']);
  601. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  602. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  603. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', array(
  604. 'content' => $oOptions->getCode(),
  605. 'js_content' => $this->getPageJsCode()
  606. ));
  607. }
  608. protected function getSettings()
  609. {
  610. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  611. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  612. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  613. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', array(
  614. 'content' => $oOptions->getCode(),
  615. 'js_content' => $this->getPageJsCode()
  616. ));
  617. }
  618. protected function getOptionId($sName)
  619. {
  620. $aSetting = [];
  621. $this->oDbSettings->getOptions(['type' => 'by_name', 'value' => $sName], $aSetting, false);
  622. if(empty($aSetting) || !is_array($aSetting))
  623. return 0;
  624. return (int)$aSetting['id'];
  625. }
  626. }
  627. /** @} */