1
0

BxBaseStudioOptions.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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 BxBaseStudioOptions extends BxDolStudioOptions
  11. {
  12. public function __construct($sType = '', $mixedCategory = '', $sMix = '')
  13. {
  14. parent::__construct($sType, $mixedCategory);
  15. }
  16. public function getCss()
  17. {
  18. return ['forms.css', 'options.css'];
  19. }
  20. public function getJs()
  21. {
  22. return ['jquery.form.min.js', 'jquery.webForms.js', 'options.js'];
  23. }
  24. public function getJsObject()
  25. {
  26. return 'oBxDolStudioOptions';
  27. }
  28. public function getCode($sCategorySelected = '')
  29. {
  30. $oTemplate = BxDolStudioTemplate::getInstance();
  31. $sJsObject = $this->getJsObject();
  32. $aCategories = [];
  33. $iCategories = $this->oDb->getCategories(['type' => 'by_type_name_key_name', 'type_name' => $this->sType, 'category_name' => $this->sCategory, 'hidden' => 0], $aCategories);
  34. if($iCategories > 0)
  35. $aCategories = array_keys($aCategories);
  36. $bMix = false;
  37. $aOptions2Mixes = [];
  38. if($this->bMixes) {
  39. if(!empty($this->sMix))
  40. $aMixesBrowse = ['type' => 'by_name', 'value' => $this->sMix];
  41. else if(is_string($this->sCategory))
  42. $aMixesBrowse = ['type' => 'by_type_category', 'mix_type' => $this->sType, 'mix_category' => $this->sCategory, 'active' => 1];
  43. else
  44. $aMixesBrowse = ['type' => 'by_type', 'value' => $this->sType, 'active' => 1];
  45. $aMix = array();
  46. $this->oDb->getMixes($aMixesBrowse, $aMix, false);
  47. if(!empty($aMix) && is_array($aMix)) {
  48. $this->aMix = $aMix;
  49. $this->sMix = $aMix['name'];
  50. $bMix = true;
  51. $this->oDb->getMixesOptions(['type' => 'by_mix_id_pair_option_value', 'value' => $this->aMix['id']], $aOptions2Mixes, false);
  52. }
  53. else
  54. $this->sMix = BX_DOL_STUDIO_STG_MIX_DEFAULT;
  55. }
  56. $bWrap = count($aCategories) > 1;
  57. $aForm = [
  58. 'form_attrs' => [
  59. 'id' => 'adm-settings-form',
  60. 'name' => 'adm-settings-form',
  61. 'action' => bx_append_url_params($this->sBaseUrl, ['type' => $this->sType]),
  62. 'method' => 'post',
  63. 'enctype' => 'multipart/form-data',
  64. 'target' => 'adm-settings-iframe',
  65. 'onsubmit' => 'return ' . $sJsObject . '.onSubmit(this)'
  66. ],
  67. 'params' => [
  68. 'db' => [
  69. 'table' => 'sys_options',
  70. 'key' => 'id',
  71. 'uri' => '',
  72. 'uri_title' => '',
  73. 'submit_name' => 'save'
  74. ],
  75. ],
  76. 'inputs' => []
  77. ];
  78. if($bMix)
  79. $aForm['inputs']['mix_id'] = [
  80. 'type' => 'hidden',
  81. 'name' => 'mix_id',
  82. 'value' => $this->aMix['id'],
  83. 'db' => [
  84. 'pass' => 'Int',
  85. ],
  86. ];
  87. foreach($aCategories as $sCategory) {
  88. $aFields = [];
  89. if(empty($sCategory))
  90. continue;
  91. $aCategory = array();
  92. $iCategory = $this->oDb->getCategories(['type' => 'by_name', 'value' => $sCategory], $aCategory);
  93. if($iCategory != 1)
  94. continue;
  95. $aOptions = array();
  96. $iOptions = $this->oDb->getOptions(['type' => 'by_category_id', 'value' => $aCategory['id']], $aOptions);
  97. foreach($aOptions as $aOption)
  98. $aFields[$aOption['name']] = $this->field($aOption, $aOptions2Mixes);
  99. if($bWrap) {
  100. $aCategory['selected'] = $aCategory['name'] == $sCategorySelected;
  101. $aFields = $this->header($aCategory, $aFields);
  102. }
  103. $aForm['inputs'] = array_merge($aForm['inputs'], $aFields);
  104. }
  105. $aForm['inputs'] = array_merge(
  106. $aForm['inputs'], (!$bWrap ? [] : [
  107. 'header_save' => [
  108. 'type' => 'block_header',
  109. ],
  110. ]), [
  111. 'categories' => [
  112. 'type' => 'hidden',
  113. 'name' => 'categories',
  114. 'value' => implode(',', $aCategories),
  115. 'db' => [
  116. 'pass' => 'Xss',
  117. ],
  118. ]
  119. ], ($this->isReadOnly() ? [] : [
  120. 'save' => [
  121. 'type' => 'submit',
  122. 'name' => 'save',
  123. 'value' => _t("_adm_btn_settings_save")
  124. ],
  125. ])
  126. );
  127. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  128. $oForm->initChecker();
  129. if($oForm->isSubmittedAndValid()) {
  130. echo $this->saveChanges($oForm);
  131. exit;
  132. }
  133. $bTmplVarsMixes = false;
  134. $aTmplVarsMixes = [];
  135. if($this->bMixes) {
  136. if(is_string($this->sCategory))
  137. $aMixesBrowse = ['type' => 'by_type_category', 'mix_type' => $this->sType, 'mix_category' => $this->sCategory];
  138. else
  139. $aMixesBrowse = ['type' => 'by_type', 'value' => $this->sType];
  140. $aMixes = [];
  141. $this->oDb->getMixes($aMixesBrowse, $aMixes, false);
  142. $aMixes = array_merge([['name' => BX_DOL_STUDIO_STG_MIX_DEFAULT, 'title' => _t('_adm_stg_txt_mix_' . BX_DOL_STUDIO_STG_MIX_DEFAULT)]], $aMixes);
  143. foreach($aMixes as $aMix)
  144. $aTmplVarsMixes[] = [
  145. 'value' => $aMix['name'],
  146. 'title' => $aMix['title'],
  147. 'bx_if:show_checked_mix' => [
  148. 'condition' => !empty($this->sMix) && $aMix['name'] == $this->sMix,
  149. 'content' => []
  150. ]
  151. ];
  152. $bTmplVarsMixes = !empty($aTmplVarsMixes);
  153. }
  154. $bMixSelected = !empty($this->sMix) && !empty($this->aMix);
  155. $aTmplVarsButton = [];
  156. if($bMixSelected)
  157. $aTmplVarsButton = [
  158. 'js_object' => $sJsObject,
  159. 'id' => $this->aMix['id']
  160. ];
  161. return $oTemplate->parseHtmlByName('options.html', [
  162. 'base_url' => $this->sBaseUrl,
  163. 'param_prefix' => $this->sParamPrefix,
  164. 'js_object' => $sJsObject,
  165. 'type' => $this->sType,
  166. 'category' => is_array($this->sCategory) ? json_encode($this->sCategory) : $this->sCategory,
  167. 'mix' => $this->sMix,
  168. 'bx_if:show_manage' => [
  169. 'condition' => $this->bManage,
  170. 'content' => [
  171. 'js_object' => $sJsObject,
  172. ]
  173. ],
  174. 'bx_if:show_mixes' => [
  175. 'condition' => $this->bMixes,
  176. 'content' => [
  177. 'js_object' => $sJsObject,
  178. 'bx_if:show_select_mix' => [
  179. 'condition' => $bTmplVarsMixes,
  180. 'content' => [
  181. 'js_object' => $sJsObject,
  182. 'bx_repeat:mixes' => $aTmplVarsMixes,
  183. ]
  184. ],
  185. 'bx_if:show_publish_mix' => [
  186. 'condition' => $bMixSelected && (int)$this->aMix['published'] == 0,
  187. 'content' => $aTmplVarsButton
  188. ],
  189. 'bx_if:show_hide_mix' => [
  190. 'condition' => $bMixSelected && (int)$this->aMix['published'] != 0,
  191. 'content' => $aTmplVarsButton
  192. ],
  193. 'bx_if:show_export_mix' => [
  194. 'condition' => $bMixSelected,
  195. 'content' => $aTmplVarsButton
  196. ],
  197. 'bx_if:show_delete_mix' => [
  198. 'condition' => $bMixSelected,
  199. 'content' => $aTmplVarsButton
  200. ],
  201. ]
  202. ],
  203. 'form' => $oForm->getCode()
  204. ]);
  205. }
  206. public function getPopupCodeImport()
  207. {
  208. $oTemplate = BxDolStudioTemplate::getInstance();
  209. $sJsObject = $this->getJsObject();
  210. $sForm = 'adm-settings-import-form';
  211. $aForm = [
  212. 'form_attrs' => [
  213. 'id' => $sForm,
  214. 'name' => $sForm,
  215. 'action' => bx_append_url_params($this->sBaseUrl, [$this->sParamPrefix . '_action' => 'import']),
  216. 'method' => 'post',
  217. 'enctype' => 'multipart/form-data'
  218. ],
  219. 'params' => [
  220. 'db' => [
  221. 'submit_name' => 'save'
  222. ],
  223. ],
  224. 'inputs' => [
  225. 'file' => [
  226. 'type' => 'file',
  227. 'name' => 'file',
  228. 'caption' => '',
  229. 'value' => '',
  230. ],
  231. 'controls' => [
  232. 'type' => 'input_set', [
  233. 'type' => 'submit',
  234. 'name' => 'save',
  235. 'value' => _t('_adm_btn_settings_import'),
  236. ], [
  237. 'type' => 'button',
  238. 'name' => 'cancel',
  239. 'value' => _t('_adm_txt_confirm_cancel'),
  240. 'attrs' => [
  241. 'class' => 'bx-def-margin-sec-left-auto',
  242. 'onclick' => '$(".bx-popup-applied:visible").dolPopupHide()'
  243. ]
  244. ]
  245. ]
  246. ]
  247. ];
  248. $oForm = new BxTemplStudioFormView($aForm);
  249. $oForm->initChecker();
  250. if($oForm->isSubmittedAndValid()) {
  251. $sError = _t('_adm_stg_err_cannot_perform');
  252. $aFile = $_FILES['file'];
  253. if(empty($aFile['tmp_name']))
  254. return ['code' => '1', 'message' => $sError];
  255. $sFile = $aFile['tmp_name'];
  256. $rHandle = @fopen($sFile, "r");
  257. if(!$rHandle)
  258. return ['code' => '2', 'message' => $sError];
  259. $sContents = fread($rHandle, filesize($sFile));
  260. fclose($rHandle);
  261. $aContent = json_decode($sContents, true);
  262. if(!is_array($aContent) || empty($aContent['meta']) || empty($aContent['types']))
  263. return ['code' => '3', 'message' => $sError];
  264. foreach($aContent['types'] as $aType) {
  265. if(empty($aType['categories']) || !is_array($aType['categories']))
  266. continue;
  267. foreach($aType['categories'] as $aCategory) {
  268. if(empty($aCategory['options']) || !is_array($aCategory['options']))
  269. continue;
  270. foreach($aCategory['options'] as $sOptName => $sOptValue)
  271. setParam($sOptName, $sOptValue);
  272. }
  273. }
  274. $this->clearCache();
  275. return ['eval' => $sJsObject . '.onImport(oData);'];
  276. }
  277. return [
  278. 'popup' => BxTemplStudioFunctions::getInstance()->popupBox('adm-stg-import-popup', _t('_adm_stg_txt_import_popup'), $oTemplate->parseHtmlByName('options_manage_popup.html', [
  279. 'js_object' => $sJsObject,
  280. 'form_id' => $sForm,
  281. 'form' => $oForm->getCode(true),
  282. ]))
  283. ];
  284. }
  285. public function getPopupCodeCreateMix()
  286. {
  287. $oTemplate = BxDolStudioTemplate::getInstance();
  288. $sJsObject = $this->getJsObject();
  289. $sForm = 'adm-settings-create-mix-form';
  290. $aForm = [
  291. 'form_attrs' => [
  292. 'id' => $sForm,
  293. 'name' => $sForm,
  294. 'action' => bx_append_url_params($this->sBaseUrl, [$this->sParamPrefix . '_action' => 'create-mix']),
  295. 'method' => 'post',
  296. 'enctype' => 'multipart/form-data'
  297. ],
  298. 'params' => [
  299. 'db' => [
  300. 'table' => 'sys_options_mixes',
  301. 'key' => 'id',
  302. 'uri' => 'name',
  303. 'uri_title' => 'title',
  304. 'submit_name' => 'save'
  305. ],
  306. ],
  307. 'inputs' => [
  308. 'type' => [
  309. 'type' => 'hidden',
  310. 'name' => 'type',
  311. 'value' => $this->sType
  312. ],
  313. 'category' => [
  314. 'type' => 'hidden',
  315. 'name' => 'category',
  316. 'value' => is_array($this->sCategory) ? json_encode($this->sCategory) : $this->sCategory,
  317. ],
  318. 'title' => [
  319. 'type' => 'text',
  320. 'name' => 'title',
  321. 'caption' => _t('_adm_stg_txt_mix_title'),
  322. 'info' => _t('_adm_stg_txt_mix_title_inf'),
  323. 'value' => '',
  324. 'required' => true,
  325. 'checker' => [
  326. 'func' => 'avail',
  327. 'params' => [],
  328. 'error' => _t('_adm_stg_txt_mix_title_err')
  329. ],
  330. 'db' => ['pass' => 'Xss']
  331. ],
  332. 'dark' => [
  333. 'type' => 'switcher',
  334. 'name' => 'dark',
  335. 'caption' => _t('_adm_stg_txt_mix_dark'),
  336. 'info' => '',
  337. 'value' => '1',
  338. 'db' => ['pass' => 'Int']
  339. ],
  340. 'duplicate' => [
  341. 'type' => 'select',
  342. 'name' => 'duplicate',
  343. 'caption' => _t('_adm_stg_txt_mix_duplicate'),
  344. 'info' => _t('_adm_stg_txt_mix_duplicate_inf'),
  345. 'values' => [
  346. ['key' => '', 'value' => _t('_None')]
  347. ],
  348. 'value' => '',
  349. ],
  350. 'controls' => [
  351. 'type' => 'input_set', [
  352. 'type' => 'submit',
  353. 'name' => 'save',
  354. 'value' => _t('_adm_btn_settings_save'),
  355. ], [
  356. 'type' => 'button',
  357. 'name' => 'cancel',
  358. 'value' => _t('_adm_txt_confirm_cancel'),
  359. 'attrs' => [
  360. 'class' => 'bx-def-margin-sec-left-auto',
  361. 'onclick' => '$(".bx-popup-applied:visible").dolPopupHide()'
  362. ]
  363. ]
  364. ]
  365. ]
  366. ];
  367. if(is_string($this->sCategory))
  368. $aMixesBrowse = ['type' => 'by_type_category', 'mix_type' => $this->sType, 'mix_category' => $this->sCategory];
  369. else
  370. $aMixesBrowse = ['type' => 'by_type', 'value' => $this->sType];
  371. $aMixes = [];
  372. $this->oDb->getMixes($aMixesBrowse, $aMixes, false);
  373. foreach($aMixes as $aMix)
  374. $aForm['inputs']['duplicate']['values'][] = ['key' => $aMix['name'], 'value' => $aMix['title']];
  375. $oForm = new BxTemplStudioFormView($aForm);
  376. $oForm->initChecker();
  377. if($oForm->isSubmittedAndValid()) {
  378. $iId = $oForm->insert([
  379. 'type' => $this->sType,
  380. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  381. 'name' => $oForm->generateUri()
  382. ]);
  383. if($iId === false)
  384. return ['code' => '1', 'message' => _t('_adm_stg_err_cannot_perform')];
  385. $this->oDb->updateMixes(['active' => 0], [
  386. 'type' => $this->sType,
  387. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  388. 'active' => 1
  389. ]);
  390. $this->oDb->updateMixes(['active' => 1], ['id' => $iId]);
  391. $aDuplicate = [];
  392. $this->oDb->getMixes(['type' => 'by_name', 'value' => $oForm->getCleanValue('duplicate')], $aDuplicate, false);
  393. if(!empty($aDuplicate) && is_array($aDuplicate))
  394. $this->oDb->duplicateMixesOptions($aDuplicate['id'], $iId);
  395. $this->clearCache();
  396. return ['eval' => $sJsObject . '.onMixCreate(oData);'];
  397. }
  398. return [
  399. 'popup' => BxTemplStudioFunctions::getInstance()->popupBox('adm-stg-create-mix-popup', _t('_adm_stg_txt_create_mix_popup'), $oTemplate->parseHtmlByName('options_create_mix.html', [
  400. 'js_object' => $sJsObject,
  401. 'form_id' => $sForm,
  402. 'form' => $oForm->getCode(true),
  403. ]))
  404. ];
  405. }
  406. public function getPopupCodeImportMix()
  407. {
  408. $oTemplate = BxDolStudioTemplate::getInstance();
  409. $sJsObject = $this->getJsObject();
  410. $sForm = 'adm-settings-import-mix-form';
  411. $aForm = [
  412. 'form_attrs' => [
  413. 'id' => $sForm,
  414. 'name' => $sForm,
  415. 'action' => bx_append_url_params($this->sBaseUrl, [$this->sParamPrefix . '_action' => 'import-mix']),
  416. 'method' => 'post',
  417. 'enctype' => 'multipart/form-data'
  418. ],
  419. 'params' => [
  420. 'db' => [
  421. 'table' => 'sys_options_mixes',
  422. 'key' => 'id',
  423. 'uri' => 'name',
  424. 'uri_title' => 'title',
  425. 'submit_name' => 'save'
  426. ],
  427. ],
  428. 'inputs' => [
  429. 'type' => [
  430. 'type' => 'hidden',
  431. 'name' => 'type',
  432. 'value' => $this->sType
  433. ],
  434. 'category' => [
  435. 'type' => 'hidden',
  436. 'name' => 'category',
  437. 'value' => is_array($this->sCategory) ? json_encode($this->sCategory) : $this->sCategory,
  438. ],
  439. 'file' => [
  440. 'type' => 'file',
  441. 'name' => 'file',
  442. 'caption' => '',
  443. 'value' => '',
  444. ],
  445. 'controls' => [
  446. 'type' => 'input_set', [
  447. 'type' => 'submit',
  448. 'name' => 'save',
  449. 'value' => _t('_adm_btn_settings_import'),
  450. ], [
  451. 'type' => 'button',
  452. 'name' => 'cancel',
  453. 'value' => _t('_adm_txt_confirm_cancel'),
  454. 'attrs' => [
  455. 'class' => 'bx-def-margin-sec-left-auto',
  456. 'onclick' => '$(".bx-popup-applied:visible").dolPopupHide()'
  457. ]
  458. ]
  459. ]
  460. ]
  461. ];
  462. $oForm = new BxTemplStudioFormView($aForm);
  463. $oForm->initChecker();
  464. if($oForm->isSubmittedAndValid()) {
  465. $sError = _t('_adm_stg_err_cannot_perform');
  466. $aFile = $_FILES['file'];
  467. if(empty($aFile['tmp_name']))
  468. return ['code' => '1', 'message' => $sError];
  469. $sFile = $aFile['tmp_name'];
  470. $rHandle = @fopen($sFile, "r");
  471. if(!$rHandle)
  472. return ['code' => '2', 'message' => $sError];
  473. $sContents = fread($rHandle, filesize($sFile));
  474. fclose($rHandle);
  475. $aContent = json_decode($sContents, true);
  476. if(!is_array($aContent) || empty($aContent['mix']) || empty($aContent['options']))
  477. return ['code' => '3', 'message' => $sError];
  478. $aMix = [];
  479. $this->oDb->getMixes(['type' => 'by_name', 'value' => $aContent['mix']['name']], $aMix, false);
  480. if(!empty($aMix) && is_array($aMix))
  481. return ['code' => '4', 'message' => _t('_adm_stg_err_mix_already_exists')];
  482. $iId = $oForm->insert([
  483. 'type' => $aContent['mix']['type'],
  484. 'category' => $aContent['mix']['category'],
  485. 'name' => $aContent['mix']['name'],
  486. 'title' => $aContent['mix']['title']
  487. ]);
  488. if($iId === false)
  489. return ['code' => '5', 'message' => $sError];
  490. foreach($aContent['options'] as $sKey => $sValue)
  491. $this->oDb->insertMixesOptions([
  492. 'option' => $sKey,
  493. 'mix_id' => $iId,
  494. 'value' => $sValue
  495. ]);
  496. $this->oDb->updateMixes(['active' => 0], [
  497. 'type' => $this->sType,
  498. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  499. 'active' => 1
  500. ]);
  501. $this->oDb->updateMixes(['active' => 1], ['id' => $iId]);
  502. $this->clearCache();
  503. return ['eval' => $sJsObject . '.onMixImport(oData);'];
  504. }
  505. return [
  506. 'popup' => BxTemplStudioFunctions::getInstance()->popupBox('adm-stg-import-mix-popup', _t('_adm_stg_txt_import_mix_popup'), $oTemplate->parseHtmlByName('options_import_mix.html', [
  507. 'js_object' => $sJsObject,
  508. 'form_id' => $sForm,
  509. 'form' => $oForm->getCode(true),
  510. ]))
  511. ];
  512. }
  513. protected function header($aCategory, $aFields)
  514. {
  515. return array_merge([
  516. 'category_' . $aCategory['id'] . '_beg' => [
  517. 'type' => 'block_header',
  518. 'name' => 'category_' . $aCategory['id'] . '_beg',
  519. 'caption' => _t($aCategory['caption']),
  520. 'collapsable' => true,
  521. 'collapsed' => !$aCategory['selected']
  522. ]
  523. ],
  524. $aFields
  525. );
  526. }
  527. protected function field($aItem, $aItems2Mixes)
  528. {
  529. $mixedValue = isset($aItems2Mixes[$aItem['name']]) ? $aItems2Mixes[$aItem['name']] : $aItem['value'];
  530. $sMethod = 'getCustomValue' . bx_gen_method_name(trim(str_replace($this->sType, '', $aItem['name']), '_'));
  531. if(method_exists($this, $sMethod))
  532. $mixedValue = $this->$sMethod($aItem, $mixedValue);
  533. $aAttributes = array();
  534. if($this->isReadOnly())
  535. $aAttributes = array_merge($aAttributes, [
  536. 'disabled' => 'disabled'
  537. ]);
  538. $aField = [];
  539. switch($aItem['type']) {
  540. case 'value':
  541. $aField = [
  542. 'type' => 'text',
  543. 'name' => $aItem['name'],
  544. 'caption' => _t($aItem['caption']),
  545. 'value' => $mixedValue,
  546. 'attrs' => array_merge($aAttributes, ['readonly' => 'readonly']),
  547. 'db' => ['pass' => 'Xss'],
  548. ];
  549. break;
  550. case 'digit':
  551. $aField = [
  552. 'type' => 'text',
  553. 'name' => $aItem['name'],
  554. 'caption' => _t($aItem['caption']),
  555. 'value' => $mixedValue,
  556. 'attrs' => $aAttributes,
  557. 'db' => ['pass' => 'Xss'],
  558. ];
  559. break;
  560. case 'text':
  561. $aField = [
  562. 'type' => 'textarea',
  563. 'name' => $aItem['name'],
  564. 'caption' => _t($aItem['caption']),
  565. 'value' => $mixedValue,
  566. 'attrs' => $aAttributes,
  567. 'db' => ['pass' => 'XssHtml'],
  568. ];
  569. break;
  570. case 'code':
  571. $aField = [
  572. 'type' => 'textarea',
  573. 'code' => true,
  574. 'name' => $aItem['name'],
  575. 'caption' => _t($aItem['caption']),
  576. 'value' => $mixedValue,
  577. 'attrs' => $aAttributes,
  578. 'db' => ['pass' => 'XssHtml'],
  579. ];
  580. break;
  581. case 'checkbox':
  582. $aField = [
  583. 'type' => 'checkbox',
  584. 'name' => $aItem['name'],
  585. 'caption' => _t($aItem['caption']),
  586. 'value' => 'on',
  587. 'checked' => $mixedValue == 'on',
  588. 'attrs' => $aAttributes,
  589. 'db' => ['pass' => 'Xss'],
  590. ];
  591. break;
  592. case 'list':
  593. case 'rlist':
  594. $aField = [
  595. 'type' => 'checkbox_set',
  596. 'name' => $aItem['name'],
  597. 'caption' => _t($aItem['caption']),
  598. 'value' => !empty($mixedValue) ? explode(',', $mixedValue) : [],
  599. 'reverse' => $aItem['type'] == 'rlist',
  600. 'attrs' => $aAttributes,
  601. 'db' => ['pass' => 'Xss'],
  602. ];
  603. if (BxDolService::isSerializedService($aItem['extra']))
  604. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  605. else
  606. foreach(explode(',', $aItem['extra']) as $sValue)
  607. $aField['values'][$sValue] = $sValue;
  608. break;
  609. case 'select':
  610. $aField = [
  611. 'type' => 'select',
  612. 'name' => $aItem['name'],
  613. 'caption' => _t($aItem['caption']),
  614. 'value' => $mixedValue,
  615. 'values' => [],
  616. 'attrs' => $aAttributes,
  617. 'db' => ['pass' => 'Xss'],
  618. ];
  619. if (BxDolService::isSerializedService($aItem['extra']))
  620. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  621. else
  622. foreach(explode(',', $aItem['extra']) as $sValue)
  623. $aField['values'][] = ['key' => $sValue, 'value' => $sValue];
  624. break;
  625. case 'file':
  626. $aField = [
  627. 'type' => 'file',
  628. 'name' => $aItem['name'],
  629. 'caption' => _t($aItem['caption']),
  630. 'value' => $mixedValue,
  631. 'attrs' => $aAttributes,
  632. 'db' => ['pass' => 'Xss']
  633. ];
  634. break;
  635. case 'image':
  636. //--- Concatenation integer values as strings is required to get unique content id
  637. $iContentId = (int)($aItem['id'] . ($this->bMixes && isset($this->aMix['id']) ? $this->aMix['id'] : 0));
  638. $aField = [
  639. 'type' => 'files',
  640. 'name' => $aItem['name'],
  641. 'storage_object' => $this->sStorage,
  642. 'storage_private' => 0,
  643. 'images_transcoder' => $this->sTranscoder,
  644. 'uploaders' => ['sys_settings_html5'],
  645. 'upload_buttons_titles' => ['HTML5' => _t('_sys_uploader_button_name_single')],
  646. 'multiple' => false,
  647. 'content_id' => $iContentId,
  648. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate($aItem['name']),
  649. 'caption' => _t($aItem['caption']),
  650. 'value' => $mixedValue,
  651. 'attrs' => $aAttributes,
  652. 'db' => ['pass' => 'Xss']
  653. ];
  654. break;
  655. case 'rgb':
  656. case 'rgba':
  657. $aField = [
  658. 'type' => $aItem['type'],
  659. 'name' => $aItem['name'],
  660. 'caption' => _t($aItem['caption']),
  661. 'value' => $mixedValue,
  662. 'attrs' => $aAttributes,
  663. 'db' => ['pass' => 'Xss'],
  664. ];
  665. break;
  666. case 'datetime':
  667. $aField = [
  668. 'type' => 'datetime',
  669. 'name' => $aItem['name'],
  670. 'caption' => _t($aItem['caption']),
  671. 'value' => $mixedValue,
  672. 'attrs' => $aAttributes,
  673. 'db' => ['pass' => 'DateTimeUtc'],
  674. ];
  675. break;
  676. }
  677. return $aField;
  678. }
  679. }
  680. /** @} */