BxBaseStudioDesigner.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('icon_apple'),
  292. 'caption' => _t('_adm_dsg_txt_upload_icon_apple'),
  293. 'info' => _t('_adm_dsg_txt_upload_icon_apple_inf'),
  294. ),
  295. 'icon_android' => array(
  296. 'type' => 'files',
  297. 'name' => 'icon_android',
  298. 'storage_object' => $this->aIcons['icon_android']['storage'],
  299. 'images_transcoder' => $this->aIcons['icon_android']['transcoder'],
  300. 'uploaders' => ['sys_html5'],
  301. 'multiple' => false,
  302. 'content_id' => $this->aIcons['icon_android']['id'],
  303. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('icon_android'),
  304. 'caption' => _t('_adm_dsg_txt_upload_icon_android'),
  305. 'info' => _t('_adm_dsg_txt_upload_icon_android_inf'),
  306. ),
  307. 'icon_android_splash' => array(
  308. 'type' => 'files',
  309. 'name' => 'icon_android_splash',
  310. 'storage_object' => $this->aIcons['icon_android_splash']['storage'],
  311. 'images_transcoder' => $this->aIcons['icon_android_splash']['transcoder'],
  312. 'uploaders' => ['sys_html5'],
  313. 'multiple' => false,
  314. 'content_id' => $this->aIcons['icon_android_splash']['id'],
  315. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate('icon_android_splash'),
  316. 'caption' => _t('_adm_dsg_txt_upload_icon_android_splash'),
  317. 'info' => _t('_adm_dsg_txt_upload_icon_android_splash_inf'),
  318. ),
  319. 'save' => array(
  320. 'type' => 'submit',
  321. 'name' => 'save',
  322. 'value' => _t('_adm_btn_designer_submit'),
  323. )
  324. )
  325. );
  326. $oForm = new BxTemplStudioFormView($aForm);
  327. $oForm->initChecker();
  328. if($oForm->isSubmittedAndValid()) {
  329. echo $this->submitIcon($oForm);
  330. exit;
  331. }
  332. return $oTemplate->parseHtmlByName('designer.html', [
  333. 'content' => $oTemplate->parseHtmlByName('dsr_icon.html', [
  334. 'preview' => $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVarsPreview),
  335. 'icon_iframe_id' => $this->sIconIframeId,
  336. 'form' => $oForm->getCode()
  337. ]),
  338. 'js_content' => $this->getPageJsCode()
  339. ]);
  340. }
  341. protected function getCover()
  342. {
  343. $sJsObject = $this->getPageJsObject();
  344. $oTemplate = BxDolStudioTemplate::getInstance();
  345. $oDbSettings = new BxDolStudioSettingsQuery();
  346. $aFormInputs = array();
  347. $aTmplVarsCovers = array();
  348. foreach($this->aCovers as $sCover => $aCover) {
  349. $aSetting = array();
  350. $oDbSettings->getOptions(array('type' => 'by_name', 'value' => $aCover['setting']), $aSetting, false);
  351. if(empty($aSetting) || !is_array($aSetting))
  352. continue;
  353. $aFormInputs[$sCover] = array(
  354. 'type' => 'files',
  355. 'name' => $sCover,
  356. 'storage_object' => $this->sCoverStorage,
  357. 'images_transcoder' => $this->sCoverTranscoder,
  358. 'uploaders' => array('sys_std_crop_cover'),
  359. 'multiple' => false,
  360. 'content_id' => $aSetting['id'],
  361. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate($sCover),
  362. 'caption' => _t('_adm_dsg_txt_upload_' . $sCover),
  363. 'db' => array (
  364. 'pass' => 'Int',
  365. )
  366. );
  367. if(($iImageId = (int)getParam($aCover['setting'])) == 0)
  368. continue;
  369. $sImageUrl = BxDolTranscoderImage::getObjectInstance($aCover['transcoder'])->getFileUrl($iImageId);
  370. if($sImageUrl === false) {
  371. setParam($aCover['setting'], 0);
  372. continue;
  373. }
  374. $aTmplVarsCovers[] = array(
  375. 'image_id' => $iImageId,
  376. 'content' => $oTemplate->parseHtmlByName($aCover['template'], array(
  377. 'js_object' => $sJsObject,
  378. 'type' => $sCover,
  379. 'caption' => _t($aCover['title']),
  380. 'image_id' => $iImageId,
  381. 'bx_if:show_bg' => array(
  382. 'condition' => !empty($sImageUrl),
  383. 'content' => array(
  384. 'image_url' => $sImageUrl
  385. )
  386. ),
  387. ))
  388. );
  389. }
  390. $aForm = array(
  391. 'form_attrs' => array(
  392. 'id' => $this->sCoverFormId,
  393. 'name' => $this->sCoverFormId,
  394. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  395. 'method' => 'post',
  396. 'enctype' => 'multipart/form-data',
  397. 'target' => $this->sCoverIframeId
  398. ),
  399. 'params' => array(
  400. 'db' => array(
  401. 'table' => '',
  402. 'key' => '',
  403. 'uri' => '',
  404. 'uri_title' => '',
  405. 'submit_name' => 'save'
  406. ),
  407. ),
  408. 'inputs' => array(
  409. 'page' => array(
  410. 'type' => 'hidden',
  411. 'name' => 'page',
  412. 'value' => $this->sPage
  413. ),
  414. 'disabled' => array(
  415. 'type' => 'checkbox',
  416. 'name' => 'enabled',
  417. 'caption' => _t('_adm_dsg_txt_cover_disabled'),
  418. 'value' => 'on',
  419. 'checked' => getParam('sys_site_cover_disabled') == 'on',
  420. 'db' => array (
  421. 'pass' => 'Xss',
  422. ),
  423. ),
  424. 'preview' => array(
  425. 'type' => 'custom',
  426. 'name' => 'preview',
  427. 'content' => $oTemplate->parseHtmlByName('dsr_cover_preview.html', array(
  428. 'bx_repeat:covers' => $aTmplVarsCovers
  429. ))
  430. ),
  431. 'save' => array(
  432. 'type' => 'submit',
  433. 'name' => 'save',
  434. 'value' => _t('_adm_btn_designer_submit'),
  435. )
  436. )
  437. );
  438. $aForm['inputs'] = bx_array_insert_after($aFormInputs, $aForm['inputs'], 'preview');
  439. $oForm = new BxTemplStudioFormView($aForm);
  440. $oForm->initChecker();
  441. if($oForm->isSubmittedAndValid()) {
  442. echo $this->submitCover($oForm);
  443. exit;
  444. }
  445. $this->aPageCss[] = 'cover.css';
  446. return $oTemplate->parseHtmlByName('designer.html', array(
  447. 'content' => $oTemplate->parseHtmlByName('dsr_cover.html', array('iframe_id' => $this->sCoverIframeId, 'form' => $oForm->getCode())),
  448. 'js_content' => $this->getPageJsCode()
  449. ));
  450. }
  451. protected function getSplash()
  452. {
  453. $oTemplate = BxDolStudioTemplate::getInstance();
  454. $aForm = array(
  455. 'form_attrs' => array(
  456. 'id' => $this->sSplashFormId,
  457. 'name' => $this->sSplashFormId,
  458. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  459. 'method' => 'post',
  460. 'enctype' => 'multipart/form-data',
  461. 'target' => $this->sSplashIframeId
  462. ),
  463. 'params' => array(
  464. 'db' => array(
  465. 'table' => '',
  466. 'key' => '',
  467. 'uri' => '',
  468. 'uri_title' => '',
  469. 'submit_name' => 'save'
  470. ),
  471. ),
  472. 'inputs' => array(
  473. 'page' => array(
  474. 'type' => 'hidden',
  475. 'name' => 'page',
  476. 'value' => $this->sPage
  477. ),
  478. 'enabled' => array(
  479. 'type' => 'checkbox',
  480. 'name' => 'enabled',
  481. 'caption' => _t('_adm_dsg_txt_splash_enabled'),
  482. 'value' => 'on',
  483. 'checked' => getParam('sys_site_splash_enabled') == 'on',
  484. 'db' => array (
  485. 'pass' => 'Xss',
  486. ),
  487. ),
  488. 'code' => array(
  489. 'type' => 'textarea',
  490. 'code' => true,
  491. 'name' => 'code',
  492. 'caption' => '',
  493. 'value' => getParam('sys_site_splash_code'),
  494. ),
  495. 'save' => array(
  496. 'type' => 'submit',
  497. 'name' => 'save',
  498. 'value' => _t('_adm_btn_designer_submit'),
  499. )
  500. )
  501. );
  502. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  503. $oForm->initChecker();
  504. if($oForm->isSubmittedAndValid()) {
  505. echo $this->submitSplash($oForm);
  506. exit;
  507. }
  508. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  509. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  510. return $oTemplate->parseHtmlByName('designer.html', array(
  511. 'content' => $oTemplate->parseHtmlByName('dsr_splash.html', array(
  512. 'warning' => MsgBox(_t('_adm_dsg_dsc_splash_warning')),
  513. 'splash_iframe_id' => $this->sSplashIframeId,
  514. 'form' => $oForm->getCode()
  515. )),
  516. 'js_content' => $this->getPageJsCode(array(
  517. 'sCodeMirror' => 'textarea[name=code]'
  518. )),
  519. ));
  520. }
  521. protected function getInjections()
  522. {
  523. $oTemplate = BxDolStudioTemplate::getInstance();
  524. $aForm = array(
  525. 'form_attrs' => array(
  526. 'id' => $this->sInjectionsFormId,
  527. 'name' => $this->sInjectionsFormId,
  528. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  529. 'method' => 'post',
  530. 'enctype' => 'multipart/form-data',
  531. 'target' => $this->sInjectionsIframeId
  532. ),
  533. 'params' => array(
  534. 'db' => array(
  535. 'table' => '',
  536. 'key' => '',
  537. 'uri' => '',
  538. 'uri_title' => '',
  539. 'submit_name' => 'save'
  540. ),
  541. ),
  542. 'inputs' => array(
  543. 'page' => array(
  544. 'type' => 'hidden',
  545. 'name' => 'page',
  546. 'value' => $this->sPage
  547. ),
  548. 'sys_head' => array(
  549. 'type' => 'textarea',
  550. 'code' => true,
  551. 'name' => 'sys_head',
  552. 'caption' => _t('_adm_dsg_txt_inj_head'),
  553. 'info' => _t('_adm_dsg_txt_inj_head_inf'),
  554. 'value' => $this->oDb->getOne("SELECT `data` FROM `sys_injections` WHERE `name`='sys_head'"),
  555. ),
  556. 'sys_body' => array(
  557. 'type' => 'textarea',
  558. 'code' => true,
  559. 'name' => 'sys_body',
  560. 'caption' => _t('_adm_dsg_txt_inj_body'),
  561. 'info' => _t('_adm_dsg_txt_inj_body_inf'),
  562. 'value' => $this->oDb->getOne("SELECT `data` FROM `sys_injections` WHERE `name`='sys_body'"),
  563. ),
  564. 'save' => array(
  565. 'type' => 'submit',
  566. 'name' => 'save',
  567. 'value' => _t('_adm_btn_designer_submit'),
  568. )
  569. )
  570. );
  571. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  572. $oForm->initChecker();
  573. if($oForm->isSubmittedAndValid()) {
  574. echo $this->submitInjections($oForm);
  575. exit;
  576. }
  577. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  578. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  579. return $oTemplate->parseHtmlByName('designer.html', array(
  580. 'content' => $oTemplate->parseHtmlByName('dsr_injections.html', array(
  581. 'warning' => '',
  582. 'splash_iframe_id' => $this->sInjectionsIframeId,
  583. 'form' => $oForm->getCode()
  584. )),
  585. 'js_content' => $this->getPageJsCode(array(
  586. 'sCodeMirror' => 'textarea[name=sys_head],textarea[name=sys_body]'
  587. ))
  588. ));
  589. }
  590. protected function getSettings()
  591. {
  592. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  593. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  594. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  595. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', array(
  596. 'content' => $oOptions->getCode(),
  597. 'js_content' => $this->getPageJsCode()
  598. ));
  599. }
  600. }
  601. /** @} */