BxBaseStudioOptions.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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' . ($bWrap ? '-categorized' : ''),
  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($sType)
  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. $sErrorWf = _t('_adm_stg_err_import_wrong_format');
  253. $aFile = $_FILES['file'];
  254. if(empty($aFile['tmp_name']))
  255. return ['code' => '1', 'message' => $sError];
  256. $sFile = $aFile['tmp_name'];
  257. $rHandle = @fopen($sFile, "r");
  258. if(!$rHandle)
  259. return ['code' => '2', 'message' => $sError];
  260. $sContents = fread($rHandle, filesize($sFile));
  261. fclose($rHandle);
  262. $aContent = json_decode($sContents, true);
  263. if(!is_array($aContent) || empty($aContent['meta']) || empty($aContent['data']))
  264. return ['code' => '3', 'message' => $sErrorWf];
  265. if(empty($aContent['meta']['type']) || strcmp($aContent['meta']['type'], $sType) != 0)
  266. return ['code' => '4', 'message' => $sErrorWf];
  267. $iData = 0;
  268. foreach($aContent['data']['types'] as $aType) {
  269. if(empty($aType['categories']) || !is_array($aType['categories']))
  270. continue;
  271. foreach($aType['categories'] as $aCategory) {
  272. if(empty($aCategory['options']) || !is_array($aCategory['options']))
  273. continue;
  274. foreach($aCategory['options'] as $sOptName => $sOptValue) {
  275. setParam($sOptName, $sOptValue);
  276. $iData += 1;
  277. }
  278. }
  279. }
  280. $this->clearCache();
  281. return [
  282. 'message' => _t('_adm_stg_msg_imported', $iData),
  283. 'eval' => $sJsObject . '.onImport(oData);'
  284. ];
  285. }
  286. return [
  287. 'popup' => BxTemplStudioFunctions::getInstance()->popupBox('adm-stg-import-popup', _t('_adm_stg_txt_import_popup'), $oTemplate->parseHtmlByName('options_manage_popup.html', [
  288. 'js_object' => $sJsObject,
  289. 'form_id' => $sForm,
  290. 'form' => $oForm->getCode(true),
  291. ]))
  292. ];
  293. }
  294. public function getPopupCodeCreateMix()
  295. {
  296. $oTemplate = BxDolStudioTemplate::getInstance();
  297. $sJsObject = $this->getJsObject();
  298. $sForm = 'adm-settings-create-mix-form';
  299. $aForm = [
  300. 'form_attrs' => [
  301. 'id' => $sForm,
  302. 'name' => $sForm,
  303. 'action' => bx_append_url_params($this->sBaseUrl, [$this->sParamPrefix . '_action' => 'create-mix']),
  304. 'method' => 'post',
  305. 'enctype' => 'multipart/form-data'
  306. ],
  307. 'params' => [
  308. 'db' => [
  309. 'table' => 'sys_options_mixes',
  310. 'key' => 'id',
  311. 'uri' => 'name',
  312. 'uri_title' => 'title',
  313. 'submit_name' => 'save'
  314. ],
  315. ],
  316. 'inputs' => [
  317. 'type' => [
  318. 'type' => 'hidden',
  319. 'name' => 'type',
  320. 'value' => $this->sType
  321. ],
  322. 'category' => [
  323. 'type' => 'hidden',
  324. 'name' => 'category',
  325. 'value' => is_array($this->sCategory) ? json_encode($this->sCategory) : $this->sCategory,
  326. ],
  327. 'title' => [
  328. 'type' => 'text',
  329. 'name' => 'title',
  330. 'caption' => _t('_adm_stg_txt_mix_title'),
  331. 'info' => _t('_adm_stg_txt_mix_title_inf'),
  332. 'value' => '',
  333. 'required' => true,
  334. 'checker' => [
  335. 'func' => 'avail',
  336. 'params' => [],
  337. 'error' => _t('_adm_stg_txt_mix_title_err')
  338. ],
  339. 'db' => ['pass' => 'Xss']
  340. ],
  341. 'dark' => [
  342. 'type' => 'switcher',
  343. 'name' => 'dark',
  344. 'caption' => _t('_adm_stg_txt_mix_dark'),
  345. 'info' => '',
  346. 'value' => '1',
  347. 'db' => ['pass' => 'Int']
  348. ],
  349. 'duplicate' => [
  350. 'type' => 'select',
  351. 'name' => 'duplicate',
  352. 'caption' => _t('_adm_stg_txt_mix_duplicate'),
  353. 'info' => _t('_adm_stg_txt_mix_duplicate_inf'),
  354. 'values' => [
  355. ['key' => '', 'value' => _t('_None')]
  356. ],
  357. 'value' => '',
  358. ],
  359. 'controls' => [
  360. 'type' => 'input_set', [
  361. 'type' => 'submit',
  362. 'name' => 'save',
  363. 'value' => _t('_adm_btn_settings_save'),
  364. ], [
  365. 'type' => 'button',
  366. 'name' => 'cancel',
  367. 'value' => _t('_adm_txt_confirm_cancel'),
  368. 'attrs' => [
  369. 'class' => 'bx-def-margin-sec-left-auto',
  370. 'onclick' => '$(".bx-popup-applied:visible").dolPopupHide()'
  371. ]
  372. ]
  373. ]
  374. ]
  375. ];
  376. if(is_string($this->sCategory))
  377. $aMixesBrowse = ['type' => 'by_type_category', 'mix_type' => $this->sType, 'mix_category' => $this->sCategory];
  378. else
  379. $aMixesBrowse = ['type' => 'by_type', 'value' => $this->sType];
  380. $aMixes = [];
  381. $this->oDb->getMixes($aMixesBrowse, $aMixes, false);
  382. foreach($aMixes as $aMix)
  383. $aForm['inputs']['duplicate']['values'][] = ['key' => $aMix['name'], 'value' => $aMix['title']];
  384. $oForm = new BxTemplStudioFormView($aForm);
  385. $oForm->initChecker();
  386. if($oForm->isSubmittedAndValid()) {
  387. $iId = $oForm->insert([
  388. 'type' => $this->sType,
  389. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  390. 'name' => $oForm->generateUri()
  391. ]);
  392. if($iId === false)
  393. return ['code' => '1', 'message' => _t('_adm_stg_err_cannot_perform')];
  394. $this->oDb->updateMixes(['active' => 0], [
  395. 'type' => $this->sType,
  396. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  397. 'active' => 1
  398. ]);
  399. $this->oDb->updateMixes(['active' => 1], ['id' => $iId]);
  400. $aDuplicate = [];
  401. $this->oDb->getMixes(['type' => 'by_name', 'value' => $oForm->getCleanValue('duplicate')], $aDuplicate, false);
  402. if(!empty($aDuplicate) && is_array($aDuplicate))
  403. $this->oDb->duplicateMixesOptions($aDuplicate['id'], $iId);
  404. $this->clearCache();
  405. return ['eval' => $sJsObject . '.onMixCreate(oData);'];
  406. }
  407. return [
  408. 'popup' => BxTemplStudioFunctions::getInstance()->popupBox('adm-stg-create-mix-popup', _t('_adm_stg_txt_create_mix_popup'), $oTemplate->parseHtmlByName('options_create_mix.html', [
  409. 'js_object' => $sJsObject,
  410. 'form_id' => $sForm,
  411. 'form' => $oForm->getCode(true),
  412. ]))
  413. ];
  414. }
  415. public function getPopupCodeImportMix()
  416. {
  417. $oTemplate = BxDolStudioTemplate::getInstance();
  418. $sJsObject = $this->getJsObject();
  419. $sForm = 'adm-settings-import-mix-form';
  420. $aForm = [
  421. 'form_attrs' => [
  422. 'id' => $sForm,
  423. 'name' => $sForm,
  424. 'action' => bx_append_url_params($this->sBaseUrl, [$this->sParamPrefix . '_action' => 'import-mix']),
  425. 'method' => 'post',
  426. 'enctype' => 'multipart/form-data'
  427. ],
  428. 'params' => [
  429. 'db' => [
  430. 'table' => 'sys_options_mixes',
  431. 'key' => 'id',
  432. 'uri' => 'name',
  433. 'uri_title' => 'title',
  434. 'submit_name' => 'save'
  435. ],
  436. ],
  437. 'inputs' => [
  438. 'type' => [
  439. 'type' => 'hidden',
  440. 'name' => 'type',
  441. 'value' => $this->sType
  442. ],
  443. 'category' => [
  444. 'type' => 'hidden',
  445. 'name' => 'category',
  446. 'value' => is_array($this->sCategory) ? json_encode($this->sCategory) : $this->sCategory,
  447. ],
  448. 'file' => [
  449. 'type' => 'file',
  450. 'name' => 'file',
  451. 'caption' => '',
  452. 'value' => '',
  453. ],
  454. 'controls' => [
  455. 'type' => 'input_set', [
  456. 'type' => 'submit',
  457. 'name' => 'save',
  458. 'value' => _t('_adm_btn_settings_import'),
  459. ], [
  460. 'type' => 'button',
  461. 'name' => 'cancel',
  462. 'value' => _t('_adm_txt_confirm_cancel'),
  463. 'attrs' => [
  464. 'class' => 'bx-def-margin-sec-left-auto',
  465. 'onclick' => '$(".bx-popup-applied:visible").dolPopupHide()'
  466. ]
  467. ]
  468. ]
  469. ]
  470. ];
  471. $oForm = new BxTemplStudioFormView($aForm);
  472. $oForm->initChecker();
  473. if($oForm->isSubmittedAndValid()) {
  474. $sError = _t('_adm_stg_err_cannot_perform');
  475. $aFile = $_FILES['file'];
  476. if(empty($aFile['tmp_name']))
  477. return ['code' => '1', 'message' => $sError];
  478. $sFile = $aFile['tmp_name'];
  479. $rHandle = @fopen($sFile, "r");
  480. if(!$rHandle)
  481. return ['code' => '2', 'message' => $sError];
  482. $sContents = fread($rHandle, filesize($sFile));
  483. fclose($rHandle);
  484. $aContent = json_decode($sContents, true);
  485. if(!is_array($aContent) || empty($aContent['mix']) || empty($aContent['options']))
  486. return ['code' => '3', 'message' => $sError];
  487. $aMix = [];
  488. $this->oDb->getMixes(['type' => 'by_name', 'value' => $aContent['mix']['name']], $aMix, false);
  489. if(!empty($aMix) && is_array($aMix))
  490. return ['code' => '4', 'message' => _t('_adm_stg_err_mix_already_exists')];
  491. $iId = $oForm->insert([
  492. 'type' => $aContent['mix']['type'],
  493. 'category' => $aContent['mix']['category'],
  494. 'name' => $aContent['mix']['name'],
  495. 'title' => $aContent['mix']['title']
  496. ]);
  497. if($iId === false)
  498. return ['code' => '5', 'message' => $sError];
  499. foreach($aContent['options'] as $sKey => $sValue)
  500. $this->oDb->insertMixesOptions([
  501. 'option' => $sKey,
  502. 'mix_id' => $iId,
  503. 'value' => $sValue
  504. ]);
  505. $this->oDb->updateMixes(['active' => 0], [
  506. 'type' => $this->sType,
  507. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  508. 'active' => 1
  509. ]);
  510. $this->oDb->updateMixes(['active' => 1], ['id' => $iId]);
  511. $this->clearCache();
  512. return ['eval' => $sJsObject . '.onMixImport(oData);'];
  513. }
  514. return [
  515. 'popup' => BxTemplStudioFunctions::getInstance()->popupBox('adm-stg-import-mix-popup', _t('_adm_stg_txt_import_mix_popup'), $oTemplate->parseHtmlByName('options_import_mix.html', [
  516. 'js_object' => $sJsObject,
  517. 'form_id' => $sForm,
  518. 'form' => $oForm->getCode(true),
  519. ]))
  520. ];
  521. }
  522. protected function header($aCategory, $aFields)
  523. {
  524. return array_merge([
  525. 'category_' . $aCategory['id'] . '_beg' => [
  526. 'type' => 'block_header',
  527. 'name' => 'category_' . $aCategory['id'] . '_beg',
  528. 'caption' => _t($aCategory['caption']),
  529. 'collapsable' => true,
  530. 'collapsed' => !$aCategory['selected']
  531. ]
  532. ],
  533. $aFields
  534. );
  535. }
  536. protected function field($aItem, $aItems2Mixes)
  537. {
  538. $mixedValue = isset($aItems2Mixes[$aItem['name']]) ? $aItems2Mixes[$aItem['name']] : $aItem['value'];
  539. $sMethod = 'getCustomValue' . bx_gen_method_name(trim(str_replace($this->sType, '', $aItem['name']), '_'));
  540. if(method_exists($this, $sMethod))
  541. $mixedValue = $this->$sMethod($aItem, $mixedValue);
  542. $aAttributes = array();
  543. if($this->isReadOnly())
  544. $aAttributes = array_merge($aAttributes, [
  545. 'disabled' => 'disabled'
  546. ]);
  547. $aField = [];
  548. switch($aItem['type']) {
  549. case 'value':
  550. $aField = [
  551. 'type' => 'text',
  552. 'name' => $aItem['name'],
  553. 'caption' => _t($aItem['caption']),
  554. 'value' => $mixedValue,
  555. 'attrs' => array_merge($aAttributes, ['readonly' => 'readonly']),
  556. 'db' => ['pass' => 'Xss'],
  557. ];
  558. break;
  559. case 'digit':
  560. $aField = [
  561. 'type' => 'text',
  562. 'name' => $aItem['name'],
  563. 'caption' => _t($aItem['caption']),
  564. 'value' => $mixedValue,
  565. 'attrs' => $aAttributes,
  566. 'db' => ['pass' => 'Xss'],
  567. ];
  568. break;
  569. case 'text':
  570. $aField = [
  571. 'type' => 'textarea',
  572. 'name' => $aItem['name'],
  573. 'caption' => _t($aItem['caption']),
  574. 'value' => $mixedValue,
  575. 'attrs' => $aAttributes,
  576. 'db' => ['pass' => 'XssHtml'],
  577. ];
  578. break;
  579. case 'code':
  580. $aField = [
  581. 'type' => 'textarea',
  582. 'code' => true,
  583. 'name' => $aItem['name'],
  584. 'caption' => _t($aItem['caption']),
  585. 'value' => $mixedValue,
  586. 'attrs' => $aAttributes,
  587. 'db' => ['pass' => 'XssHtml'],
  588. ];
  589. break;
  590. case 'checkbox':
  591. $aField = [
  592. 'type' => 'checkbox',
  593. 'name' => $aItem['name'],
  594. 'caption' => _t($aItem['caption']),
  595. 'value' => 'on',
  596. 'checked' => $mixedValue == 'on',
  597. 'attrs' => $aAttributes,
  598. 'db' => ['pass' => 'Xss'],
  599. ];
  600. break;
  601. case 'list':
  602. case 'rlist':
  603. $aField = [
  604. 'type' => 'checkbox_set',
  605. 'name' => $aItem['name'],
  606. 'caption' => _t($aItem['caption']),
  607. 'value' => !empty($mixedValue) ? explode(',', $mixedValue) : [],
  608. 'reverse' => $aItem['type'] == 'rlist',
  609. 'attrs' => $aAttributes,
  610. 'db' => ['pass' => 'Xss'],
  611. ];
  612. if (BxDolService::isSerializedService($aItem['extra']))
  613. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  614. else
  615. foreach(explode(',', $aItem['extra']) as $sValue)
  616. $aField['values'][$sValue] = $sValue;
  617. break;
  618. case 'select':
  619. $aField = [
  620. 'type' => 'select',
  621. 'name' => $aItem['name'],
  622. 'caption' => _t($aItem['caption']),
  623. 'value' => $mixedValue,
  624. 'values' => [],
  625. 'attrs' => $aAttributes,
  626. 'db' => ['pass' => 'Xss'],
  627. ];
  628. if (BxDolService::isSerializedService($aItem['extra']))
  629. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  630. else
  631. foreach(explode(',', $aItem['extra']) as $sValue)
  632. $aField['values'][] = ['key' => $sValue, 'value' => $sValue];
  633. break;
  634. case 'file':
  635. $aField = [
  636. 'type' => 'file',
  637. 'name' => $aItem['name'],
  638. 'caption' => _t($aItem['caption']),
  639. 'value' => $mixedValue,
  640. 'attrs' => $aAttributes,
  641. 'db' => ['pass' => 'Xss']
  642. ];
  643. break;
  644. case 'image':
  645. //--- Concatenation integer values as strings is required to get unique content id
  646. $iContentId = (int)($aItem['id'] . ($this->bMixes && isset($this->aMix['id']) ? $this->aMix['id'] : 0));
  647. $aField = [
  648. 'type' => 'files',
  649. 'name' => $aItem['name'],
  650. 'storage_object' => $this->sStorage,
  651. 'storage_private' => 0,
  652. 'images_transcoder' => $this->sTranscoder,
  653. 'uploaders' => ['sys_settings_html5'],
  654. 'upload_buttons_titles' => ['HTML5' => _t('_sys_uploader_button_name_single')],
  655. 'multiple' => false,
  656. 'content_id' => $iContentId,
  657. 'ghost_template' => BxTemplStudioFunctions::getInstance()->getDefaultGhostTemplate($aItem['name']),
  658. 'caption' => _t($aItem['caption']),
  659. 'value' => $mixedValue,
  660. 'attrs' => $aAttributes,
  661. 'db' => ['pass' => 'Xss']
  662. ];
  663. break;
  664. case 'rgb':
  665. case 'rgba':
  666. $aField = [
  667. 'type' => $aItem['type'],
  668. 'name' => $aItem['name'],
  669. 'caption' => _t($aItem['caption']),
  670. 'value' => $mixedValue,
  671. 'attrs' => $aAttributes,
  672. 'db' => ['pass' => 'Xss'],
  673. ];
  674. break;
  675. case 'datetime':
  676. $aField = [
  677. 'type' => 'datetime',
  678. 'name' => $aItem['name'],
  679. 'caption' => _t($aItem['caption']),
  680. 'value' => $mixedValue,
  681. 'attrs' => $aAttributes,
  682. 'db' => ['pass' => 'DateTimeUtc'],
  683. ];
  684. break;
  685. }
  686. return $aField;
  687. }
  688. }
  689. /** @} */