BxBaseStudioDesigner.php 26 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 $sLogoFormId = 'adm-dsg-logo-form';
  13. protected $sLogoIframeId = 'adm-dsg-logo-iframe';
  14. protected $sIconFormId = 'adm-dsg-icon-form';
  15. protected $sIconIframeId = 'adm-dsg-icon-iframe';
  16. protected $sCoverFormId = 'adm-dsg-cover-form';
  17. protected $sCoverIframeId = 'adm-dsg-cover-iframe';
  18. protected $sCoverStorage = BX_DOL_STORAGE_OBJ_IMAGES;
  19. protected $sCoverTranscoder = 'sys_cover_preview';
  20. protected $sSplashFormId = 'adm-dsg-splash-form';
  21. protected $sSplashIframeId = 'adm-dsg-splash-iframe';
  22. protected $sSplashEditorId = 'adm-dsg-splash-editor';
  23. protected $sInjectionsFormId = 'adm-dsg-injections-form';
  24. protected $sInjectionsIframeId = 'adm-dsg-injections-iframe';
  25. protected $sInjectionsEditorId = 'adm-dsg-injections-editor';
  26. public function __construct($sPage = '')
  27. {
  28. parent::__construct($sPage);
  29. $this->aPageCss = array_merge($this->aPageCss, ['forms.css', 'designer.css']);
  30. $this->aPageJs = array_merge($this->aPageJs, ['designer.js']);
  31. $this->sPageJsClass = 'BxDolStudioDesigner';
  32. $this->sPageJsObject = 'oBxDolStudioDesigner';
  33. }
  34. public function getPageJsCode($aOptions = array(), $bWrap = true)
  35. {
  36. $aOptions = array_merge([
  37. 'sActionUrl' => $this->sManageUrl,
  38. 'sParamPrefix' => $this->sParamPrefix
  39. ], $aOptions);
  40. return parent::getPageJsCode($aOptions, $bWrap);
  41. }
  42. public function getPageMenu($aMenu = array(), $aMarkers = array())
  43. {
  44. $sJsObject = $this->getPageJsObject();
  45. $aMenu = array();
  46. $aMenuItems = array(
  47. BX_DOL_STUDIO_DSG_TYPE_GENERAL => array('icon' => 'globe'),
  48. BX_DOL_STUDIO_DSG_TYPE_LOGO => array('icon' => 'pencil-alt'),
  49. BX_DOL_STUDIO_DSG_TYPE_ICON => array('icon' => 'far image'),
  50. BX_DOL_STUDIO_DSG_TYPE_COVER => array('icon' => 'far file-image'),
  51. BX_DOL_STUDIO_DSG_TYPE_SPLASH => array('icon' => 'far file-image'),
  52. BX_DOL_STUDIO_DSG_TYPE_INJECTIONS => array('icon' => 'object-group'),
  53. BX_DOL_STUDIO_DSG_TYPE_SETTINGS => array('icon' => 'cogs'),
  54. );
  55. foreach($aMenuItems as $sMenuItem => $aItem)
  56. $aMenu[] = array(
  57. 'name' => $sMenuItem,
  58. 'icon' => $aItem['icon'],
  59. 'link' => BX_DOL_URL_STUDIO . 'designer.php?page=' . $sMenuItem,
  60. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  61. 'selected' => $sMenuItem == $this->sPage
  62. );
  63. return parent::getPageMenu($aMenu);
  64. }
  65. protected function getGeneral()
  66. {
  67. $sJsObject = $this->getPageJsObject();
  68. $oTemplate = BxDolStudioTemplate::getInstance();
  69. $sResult = '';
  70. $sTemplate = getParam('template');
  71. $aTemplates = get_templates_array(true, false);
  72. $aTmplVarsTemplates = array ();
  73. foreach($aTemplates as $sUri => $aTemplate) {
  74. $sIcon = $this->getModuleIcon($aTemplate, 'store');
  75. $bIcon = strpos($sIcon, '.') === false && strcmp(substr($sIcon, 0, 10), 'data:image') != 0;
  76. $aTmplVarsTemplates[] = array(
  77. 'uri' => $sUri,
  78. 'title' => htmlspecialchars_adv($aTemplate['title']),
  79. 'version' => htmlspecialchars_adv($aTemplate['version']),
  80. 'vendor' => htmlspecialchars_adv($aTemplate['vendor']),
  81. 'bx_if:icon' => array (
  82. 'condition' => $bIcon,
  83. 'content' => array('icon' => $sIcon),
  84. ),
  85. 'bx_if:image' => array (
  86. 'condition' => !$bIcon,
  87. 'content' => array('icon_url' => $sIcon),
  88. ),
  89. 'bx_if:default' => array (
  90. 'condition' => $sUri == $sTemplate,
  91. 'content' => array (),
  92. ),
  93. 'bx_if:make_default' => array (
  94. 'condition' => $sUri != $sTemplate,
  95. 'content' => array(
  96. 'js_object' => $sJsObject,
  97. 'uri' => $sUri
  98. ),
  99. )
  100. );
  101. }
  102. $sContent = $sResult ? MsgBox($sResult, 10) : '';
  103. $sContent .= $oTemplate->parseHtmlByName('templates.html', array(
  104. 'bx_repeat:templates' => $aTmplVarsTemplates,
  105. ));
  106. return $oTemplate->parseHtmlByName('designer.html', array(
  107. 'content' => $sContent,
  108. 'js_content' => $this->getPageJsCode()
  109. ));
  110. }
  111. protected function getLogo()
  112. {
  113. $sJsObject = $this->getPageJsObject();
  114. $oTemplate = BxDolStudioTemplate::getInstance();
  115. $aForm = array(
  116. 'form_attrs' => array(
  117. 'id' => $this->sLogoFormId,
  118. 'name' => $this->sLogoFormId,
  119. 'action' => $this->sManageUrl,
  120. 'method' => 'post',
  121. 'enctype' => 'multipart/form-data',
  122. 'target' => $this->sLogoIframeId
  123. ),
  124. 'params' => array(
  125. 'db' => array(
  126. 'table' => '',
  127. 'key' => '',
  128. 'uri' => '',
  129. 'uri_title' => '',
  130. 'submit_name' => 'save'
  131. ),
  132. ),
  133. 'inputs' => array(
  134. 'page' => array(
  135. 'type' => 'hidden',
  136. 'name' => 'page',
  137. 'value' => $this->sPage
  138. ),
  139. 'image' => array(
  140. 'type' => 'image_uploader',
  141. 'name' => 'image',
  142. 'caption' => _t('_adm_dsg_txt_upload_image'),
  143. 'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
  144. 'ajax_action_delete' => $sJsObject . '.deleteLogo()',
  145. 'storage_object' => 'sys_images_custom',
  146. 'value' => (int)getParam($this->sParamLogo),
  147. ),
  148. 'mark' => array(
  149. 'type' => 'image_uploader',
  150. 'name' => 'mark',
  151. 'caption' => _t('_adm_dsg_txt_upload_mark'),
  152. 'caption_preview' => _t('_adm_dsg_txt_upload_mark_preview'),
  153. 'ajax_action_delete' => $sJsObject . '.deleteMark()',
  154. 'storage_object' => 'sys_images_custom',
  155. 'value' => '',
  156. ),
  157. 'alt' => array(
  158. 'type' => 'text',
  159. 'name' => 'alt',
  160. 'caption' => _t('_adm_dsg_txt_alt_text'),
  161. 'info' => _t('_adm_dsg_dsc_alt_text'),
  162. 'value' => getParam($this->sParamLogoAlt),
  163. 'checker' => array(
  164. 'func' => '',
  165. 'params' => array(),
  166. 'error' => ''
  167. ),
  168. 'db' => array (
  169. 'pass' => 'Xss',
  170. ),
  171. ),
  172. 'save' => array(
  173. 'type' => 'submit',
  174. 'name' => 'save',
  175. 'value' => _t('_adm_btn_designer_submit'),
  176. )
  177. )
  178. );
  179. if(!empty($this->sParamMark))
  180. $aForm['inputs']['mark']['value'] = (int)getParam($this->sParamMark);
  181. else
  182. unset($aForm['inputs']['mark']);
  183. $oForm = new BxTemplStudioFormView($aForm);
  184. $oForm->initChecker();
  185. if($oForm->isSubmittedAndValid()) {
  186. echo $this->submitLogo($oForm);
  187. exit;
  188. }
  189. return MsgBox(_t('_adm_dsg_txt_logo_redefinition')) . $oTemplate->parseHtmlByName('designer.html', array(
  190. 'content' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  191. 'js_content' => $this->getPageJsCode()
  192. ));
  193. }
  194. protected function getIcon()
  195. {
  196. $oTemplate = BxDolStudioTemplate::getInstance();
  197. $oDbSettings = new BxDolStudioSettingsQuery();
  198. $aTmplVarsPreview = ['bx_repeat:images' => []];
  199. foreach($this->aIcons as $sIcon => $aIcon) {
  200. $sSetting = 'sys_site_' . $sIcon;
  201. $iIconValue = (int)getParam($sSetting);
  202. $aSetting = [];
  203. $oDbSettings->getOptions(['type' => 'by_name', 'value' => $sSetting], $aSetting, false);
  204. if(!empty($aSetting) && is_array($aSetting))
  205. $this->aIcons[$sIcon]['id'] = (int)$aSetting['id'];
  206. if(empty($iIconValue))
  207. continue;
  208. $sIconUrl = '';
  209. $aIconParams = [];
  210. if(!empty($aIcon['transcoder'])) {
  211. $oTranscoder = BxDolTranscoderImage::getObjectInstance($aIcon['transcoder']);
  212. $sIconUrl = $oTranscoder->getFileUrl($iIconValue);
  213. $aIconParams = $oTranscoder->getFilterParams('Resize');
  214. }
  215. else {
  216. $oStorage = BxDolStorage::getObjectInstance($aIcon['storage']);
  217. $sIconUrl = $oStorage->getFileUrlById($iIconValue);
  218. }
  219. if($sIconUrl === false) {
  220. setParam($sSetting, 0);
  221. continue;
  222. }
  223. $bIconWidth = !empty($aIconParams['w']);
  224. $bIconHeight = !empty($aIconParams['h']);
  225. $aTmplVarsPreview['bx_repeat:images'][] = array(
  226. 'js_object' => $this->getPageJsObject(),
  227. 'id' => $iIconValue,
  228. 'name' => $sIcon,
  229. 'caption' => _t('_adm_dsg_txt_' . $sIcon),
  230. 'url' => $sIconUrl,
  231. 'bx_if:show_width' => array(
  232. 'condition' => $bIconWidth,
  233. 'content' => array(
  234. 'width' => $bIconWidth ? (int)$aIconParams['w'] : 0
  235. )
  236. ),
  237. 'bx_if:show_height' => array(
  238. 'condition' => $bIconHeight,
  239. 'content' => array(
  240. 'height' => $bIconHeight ? (int)$aIconParams['h'] : 0
  241. )
  242. ),
  243. );
  244. }
  245. $aForm = array(
  246. 'form_attrs' => array(
  247. 'id' => $this->sIconFormId,
  248. 'name' => $this->sIconFormId,
  249. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  250. 'method' => 'post',
  251. 'enctype' => 'multipart/form-data',
  252. 'target' => $this->sIconIframeId
  253. ),
  254. 'params' => array(
  255. 'db' => array(
  256. 'table' => '',
  257. 'key' => '',
  258. 'uri' => '',
  259. 'uri_title' => '',
  260. 'submit_name' => 'save'
  261. ),
  262. ),
  263. 'inputs' => array(
  264. 'page' => array(
  265. 'type' => 'hidden',
  266. 'name' => 'page',
  267. 'value' => $this->sPage
  268. ),
  269. 'icon' => array(
  270. 'type' => 'file',
  271. 'name' => 'icon',
  272. 'caption' => _t('_adm_dsg_txt_upload_icon'),
  273. 'info' => _t('_adm_dsg_txt_upload_icon_inf'),
  274. 'attrs' => ['accept' => '.ico']
  275. ),
  276. 'icon_svg' => array(
  277. 'type' => 'file',
  278. 'name' => 'icon_svg',
  279. 'caption' => _t('_adm_dsg_txt_upload_icon_svg'),
  280. 'info' => _t('_adm_dsg_txt_upload_icon_svg_inf'),
  281. 'attrs' => ['accept' => '.svg']
  282. ),
  283. 'icon_apple' => array(
  284. 'type' => 'files',
  285. 'name' => 'icon_apple',
  286. 'storage_object' => $this->aIcons['icon_apple']['storage'],
  287. 'images_transcoder' => $this->aIcons['icon_apple']['transcoder'],
  288. 'uploaders' => ['sys_html5'],
  289. 'multiple' => false,
  290. 'content_id' => $this->aIcons['icon_apple']['id'],
  291. 'ghost_template' => $oTemplate->parseHtmlByName('uploader_fgt_icon.html', array(
  292. 'name' => 'icon_apple',
  293. )),
  294. 'caption' => _t('_adm_dsg_txt_upload_icon_apple'),
  295. 'info' => _t('_adm_dsg_txt_upload_icon_apple_inf'),
  296. ),
  297. 'icon_android' => array(
  298. 'type' => 'files',
  299. 'name' => 'icon_android',
  300. 'storage_object' => $this->aIcons['icon_android']['storage'],
  301. 'images_transcoder' => $this->aIcons['icon_android']['transcoder'],
  302. 'uploaders' => ['sys_html5'],
  303. 'multiple' => false,
  304. 'content_id' => $this->aIcons['icon_android']['id'],
  305. 'ghost_template' => $oTemplate->parseHtmlByName('uploader_fgt_icon.html', array(
  306. 'name' => 'icon_android',
  307. )),
  308. 'caption' => _t('_adm_dsg_txt_upload_icon_android'),
  309. 'info' => _t('_adm_dsg_txt_upload_icon_android_inf'),
  310. ),
  311. 'icon_android_splash' => array(
  312. 'type' => 'files',
  313. 'name' => 'icon_android_splash',
  314. 'storage_object' => $this->aIcons['icon_android_splash']['storage'],
  315. 'images_transcoder' => $this->aIcons['icon_android_splash']['transcoder'],
  316. 'uploaders' => ['sys_html5'],
  317. 'multiple' => false,
  318. 'content_id' => $this->aIcons['icon_android_splash']['id'],
  319. 'ghost_template' => $oTemplate->parseHtmlByName('uploader_fgt_icon.html', array(
  320. 'name' => 'icon_android_splash',
  321. )),
  322. 'caption' => _t('_adm_dsg_txt_upload_icon_android_splash'),
  323. 'info' => _t('_adm_dsg_txt_upload_icon_android_splash_inf'),
  324. ),
  325. 'save' => array(
  326. 'type' => 'submit',
  327. 'name' => 'save',
  328. 'value' => _t('_adm_btn_designer_submit'),
  329. )
  330. )
  331. );
  332. $oForm = new BxTemplStudioFormView($aForm);
  333. $oForm->initChecker();
  334. if($oForm->isSubmittedAndValid()) {
  335. echo $this->submitIcon($oForm);
  336. exit;
  337. }
  338. return $oTemplate->parseHtmlByName('designer.html', [
  339. 'content' => $oTemplate->parseHtmlByName('dsr_icon.html', [
  340. 'preview' => $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVarsPreview),
  341. 'icon_iframe_id' => $this->sIconIframeId,
  342. 'form' => $oForm->getCode()
  343. ]),
  344. 'js_content' => $this->getPageJsCode()
  345. ]);
  346. }
  347. protected function getCover()
  348. {
  349. $sJsObject = $this->getPageJsObject();
  350. $oTemplate = BxDolStudioTemplate::getInstance();
  351. $oDbSettings = new BxDolStudioSettingsQuery();
  352. $aFormInputs = array();
  353. $aTmplVarsCovers = array();
  354. foreach($this->aCovers as $sCover => $aCover) {
  355. $aSetting = array();
  356. $oDbSettings->getOptions(array('type' => 'by_name', 'value' => $aCover['setting']), $aSetting, false);
  357. if(empty($aSetting) || !is_array($aSetting))
  358. continue;
  359. $aFormInputs[$sCover] = array(
  360. 'type' => 'files',
  361. 'name' => $sCover,
  362. 'storage_object' => $this->sCoverStorage,
  363. 'images_transcoder' => $this->sCoverTranscoder,
  364. 'uploaders' => array('sys_std_crop_cover'),
  365. 'multiple' => false,
  366. 'content_id' => $aSetting['id'],
  367. 'ghost_template' => BxDolStudioTemplate::getInstance()->parseHtmlByName('uploader_fgt_cover.html', array(
  368. 'name' => $sCover,
  369. )),
  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 getSettings()
  599. {
  600. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  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. }
  609. /** @} */