BxBaseStudioDesigner.php 25 KB

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