BxBaseStudioDesigner.php 25 KB

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