BxBaseStudioDesigner.php 26 KB

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