BxBaseStudioSettings.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioSettings extends BxDolStudioSettings
  11. {
  12. public function __construct($sType = '', $mixedCategory = '')
  13. {
  14. parent::__construct($sType, $mixedCategory);
  15. }
  16. public function getPageCss()
  17. {
  18. return array_merge(parent::getPageCss(), array('forms.css', 'settings.css'));
  19. }
  20. public function getPageJs()
  21. {
  22. return array_merge(parent::getPageJs(), array('jquery.form.min.js', 'jquery.webForms.js', 'settings.js'));
  23. }
  24. public function getPageJsObject()
  25. {
  26. return 'oBxDolStudioSettings';
  27. }
  28. public function getPageMenu($aMenu = array(), $aMarkers = array())
  29. {
  30. $aTypes = $aMenu = array();
  31. if($this->oDb->getTypes(array('type' => 'all'), $aTypes) > 0 ) {
  32. $aTypesGrouped = array();
  33. foreach($aTypes as $aType)
  34. $aTypesGrouped[$aType['group']][] = $aType;
  35. foreach($aTypesGrouped as $sGroup => $aTypes)
  36. foreach($aTypes as $aType)
  37. $aMenu[] = array(
  38. 'name' => $aType['name'],
  39. 'icon' => $this->getMenuIcon($sGroup, $aType),
  40. 'link' => BX_DOL_URL_STUDIO . 'settings.php?page=' . $aType['name'],
  41. 'title' => $aType['caption'],
  42. 'selected' => $aType['name'] == $this->sType
  43. );
  44. }
  45. return parent::getPageMenu($aMenu);
  46. }
  47. public function getPageCode($sCategorySelected = '')
  48. {
  49. $oTemplate = BxDolStudioTemplate::getInstance();
  50. $sJsObject = $this->getPageJsObject();
  51. $aCategories = array();
  52. $iCategories = $this->oDb->getCategories(array('type' => 'by_type_name_key_name', 'type_name' => $this->sType, 'category_name' => $this->sCategory, 'hidden' => 0), $aCategories);
  53. if($iCategories > 0)
  54. $aCategories = array_keys($aCategories);
  55. $bMix = false;
  56. $aOptions2Mixes = array();
  57. if($this->bMixes) {
  58. if(is_string($this->sCategory))
  59. $aMixesBrowse = array('type' => 'by_type_category', 'type' => $this->sType, 'category' => $this->sCategory, 'active' => 1);
  60. else
  61. $aMixesBrowse = array('type' => 'by_type', 'value' => $this->sType, 'active' => 1);
  62. $aMix = array();
  63. $this->oDb->getMixes($aMixesBrowse, $aMix, false);
  64. $this->sMix = BX_DOL_STUDIO_STG_MIX_DEFAULT;
  65. if(!empty($aMix) && is_array($aMix)) {
  66. $this->aMix = $aMix;
  67. $this->sMix = $aMix['name'];
  68. $bMix = true;
  69. $this->oDb->getMixesOptions(array('type' => 'by_mix_id_pair_option_value', 'value' => $this->aMix['id']), $aOptions2Mixes, false);
  70. }
  71. }
  72. $bWrap = count($aCategories) > 1;
  73. $aForm = array(
  74. 'form_attrs' => array(
  75. 'id' => 'adm-settings-form',
  76. 'name' => 'adm-settings-form',
  77. 'action' => BX_DOL_URL_STUDIO . 'settings.php?page=' . $this->sType,
  78. 'method' => 'post',
  79. 'enctype' => 'multipart/form-data',
  80. 'target' => 'adm-settings-iframe'
  81. ),
  82. 'params' => array(
  83. 'db' => array(
  84. 'table' => 'sys_options',
  85. 'key' => 'id',
  86. 'uri' => '',
  87. 'uri_title' => '',
  88. 'submit_name' => 'save'
  89. ),
  90. ),
  91. 'inputs' => array()
  92. );
  93. if($bMix)
  94. $aForm['inputs']['mix_id'] = array(
  95. 'type' => 'hidden',
  96. 'name' => 'mix_id',
  97. 'value' => $this->aMix['id'],
  98. 'db' => array (
  99. 'pass' => 'Int',
  100. ),
  101. );
  102. foreach($aCategories as $sCategory) {
  103. $aFields = array();
  104. if(empty($sCategory))
  105. continue;
  106. $aCategory = array();
  107. $iCategory = $this->oDb->getCategories(array('type' => 'by_name', 'value' => $sCategory), $aCategory);
  108. if($iCategory != 1)
  109. continue;
  110. $aOptions = array();
  111. $iOptions = $this->oDb->getOptions(array('type' => 'by_category_id', 'value' => $aCategory['id']), $aOptions);
  112. foreach($aOptions as $aOption)
  113. $aFields[$aOption['name']] = $this->field($aOption, $aOptions2Mixes);
  114. if($bWrap) {
  115. $aCategory['selected'] = $aCategory['name'] == $sCategorySelected;
  116. $aFields = $this->header($aCategory, $aFields);
  117. }
  118. $aForm['inputs'] = array_merge($aForm['inputs'], $aFields);
  119. }
  120. $aForm['inputs'] = array_merge(
  121. $aForm['inputs'],
  122. (!$bWrap ? array() : array(
  123. 'header_save' => array(
  124. 'type' => 'block_header',
  125. ),
  126. )),
  127. array(
  128. 'categories' => array(
  129. 'type' => 'hidden',
  130. 'name' => 'categories',
  131. 'value' => implode(',', $aCategories),
  132. 'db' => array (
  133. 'pass' => 'Xss',
  134. ),
  135. ),
  136. 'save' => array(
  137. 'type' => 'submit',
  138. 'name' => 'save',
  139. 'value' => _t("_adm_btn_settings_save"),
  140. )
  141. )
  142. );
  143. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  144. $oForm->initChecker();
  145. if($oForm->isSubmittedAndValid()) {
  146. echo $this->saveChanges($oForm);
  147. exit;
  148. }
  149. $bTmplVarsMixes = false;
  150. $aTmplVarsMixes = array();
  151. if($this->bMixes) {
  152. if(is_string($this->sCategory))
  153. $aMixesBrowse = array('type' => 'by_type_category', 'type' => $this->sType, 'category' => $this->sCategory);
  154. else
  155. $aMixesBrowse = array('type' => 'by_type', 'value' => $this->sType);
  156. $aMixes = array();
  157. $this->oDb->getMixes($aMixesBrowse, $aMixes, false);
  158. $aMixes = array_merge(array(array('name' => BX_DOL_STUDIO_STG_MIX_DEFAULT, 'title' => _t('_adm_stg_txt_mix_' . BX_DOL_STUDIO_STG_MIX_DEFAULT))), $aMixes);
  159. foreach($aMixes as $aMix)
  160. $aTmplVarsMixes[] = array(
  161. 'value' => $aMix['name'],
  162. 'title' => $aMix['title'],
  163. 'bx_if:show_checked_mix' => array(
  164. 'condition' => !empty($this->sMix) && $aMix['name'] == $this->sMix,
  165. 'content' => array()
  166. )
  167. );
  168. $bTmplVarsMixes = !empty($aTmplVarsMixes);
  169. }
  170. $bTmplVarsDeleteMix = !empty($this->sMix) && !empty($this->aMix);
  171. $aTmplVarsDeleteMix = array();
  172. if($bTmplVarsDeleteMix)
  173. $aTmplVarsDeleteMix = array(
  174. 'js_object' => $sJsObject,
  175. 'id' => $this->aMix['id']
  176. );
  177. return $oTemplate->parseHtmlByName('settings.html', array(
  178. 'js_object' => $sJsObject,
  179. 'type' => $this->sType,
  180. 'category' => is_array($this->sCategory) ? json_encode($this->sCategory) : $this->sCategory,
  181. 'mix' => $this->sMix,
  182. 'bx_if:show_mixes' => array(
  183. 'condition' => $this->bMixes,
  184. 'content' => array(
  185. 'js_object' => $sJsObject,
  186. 'bx_if:show_select_mix' => array(
  187. 'condition' => $bTmplVarsMixes,
  188. 'content' => array(
  189. 'js_object' => $sJsObject,
  190. 'bx_repeat:mixes' => $aTmplVarsMixes,
  191. )
  192. ),
  193. 'bx_if:show_delete_mix' => array(
  194. 'condition' => !empty($this->sMix) && !empty($this->aMix),
  195. 'content' => $aTmplVarsDeleteMix
  196. ),
  197. )
  198. ),
  199. 'form' => $oForm->getCode()
  200. ));
  201. }
  202. public function getPopupCodeCreateMix()
  203. {
  204. $oTemplate = BxDolStudioTemplate::getInstance();
  205. $sJsObject = $this->getPageJsObject();
  206. $sForm = 'adm-settings-create-mix-form';
  207. $aForm = array(
  208. 'form_attrs' => array(
  209. 'id' => $sForm,
  210. 'name' => $sForm,
  211. 'action' => bx_append_url_params(BX_DOL_URL_STUDIO . 'settings.php', array('stg_action' => 'create-mix')),
  212. 'method' => 'post',
  213. 'enctype' => 'multipart/form-data'
  214. ),
  215. 'params' => array(
  216. 'db' => array(
  217. 'table' => 'sys_options_mixes',
  218. 'key' => 'id',
  219. 'uri' => 'name',
  220. 'uri_title' => 'title',
  221. 'submit_name' => 'save'
  222. ),
  223. ),
  224. 'inputs' => array(
  225. 'page' => array(
  226. 'type' => 'hidden',
  227. 'name' => 'page',
  228. 'value' => $this->sType
  229. ),
  230. 'category' => array(
  231. 'type' => 'hidden',
  232. 'name' => 'category',
  233. 'value' => is_array($this->sCategory) ? json_encode($this->sCategory) : $this->sCategory,
  234. ),
  235. 'title' => array(
  236. 'type' => 'text',
  237. 'name' => 'title',
  238. 'caption' => _t('_adm_stg_txt_mix_title'),
  239. 'value' => '',
  240. 'db' => array (
  241. 'pass' => 'Xss',
  242. )
  243. ),
  244. 'controls' => array(
  245. 'type' => 'input_set',
  246. array(
  247. 'type' => 'submit',
  248. 'name' => 'save',
  249. 'value' => _t('_adm_btn_settings_save'),
  250. ),
  251. array(
  252. 'type' => 'button',
  253. 'name' => 'cancel',
  254. 'value' => _t('_adm_txt_confirm_cancel'),
  255. 'attrs' => array(
  256. 'class' => 'bx-def-margin-sec-left-auto',
  257. 'onclick' => '$(".bx-popup-applied:visible").dolPopupHide()'
  258. )
  259. )
  260. )
  261. )
  262. );
  263. $oForm = new BxTemplStudioFormView($aForm);
  264. $oForm->initChecker();
  265. if($oForm->isSubmittedAndValid()) {
  266. $iId = $oForm->insert(array(
  267. 'type' => $this->sType,
  268. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  269. 'name' => $oForm->generateUri()
  270. ));
  271. if($iId !== false) {
  272. $this->oDb->updateMixes(array('active' => 0), array(
  273. 'type' => $this->sType,
  274. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  275. 'active' => 1
  276. ));
  277. $this->oDb->updateMixes(array('active' => 1), array('id' => $iId));
  278. return array(
  279. 'eval' => $sJsObject . '.onMixCreate(oData);'
  280. );
  281. }
  282. }
  283. return array(
  284. 'popup' => BxTemplStudioFunctions::getInstance()->popupBox('adm-stg-create-mix-popup', _t('_adm_stg_txt_create_mix_popup'), $oTemplate->parseHtmlByName('stg_create_mix.html', array(
  285. 'js_object' => $sJsObject,
  286. 'form_id' => $sForm,
  287. 'form' => $oForm->getCode(true),
  288. )))
  289. );
  290. }
  291. protected function header($aCategory, $aFields)
  292. {
  293. return array_merge(
  294. array(
  295. 'category_' . $aCategory['id'] . '_beg' => array(
  296. 'type' => 'block_header',
  297. 'name' => 'category_' . $aCategory['id'] . '_beg',
  298. 'caption' => _t($aCategory['caption']),
  299. 'collapsable' => true,
  300. 'collapsed' => !$aCategory['selected']
  301. )
  302. ),
  303. $aFields);
  304. }
  305. protected function field($aItem, $aItems2Mixes)
  306. {
  307. $oTemplate = BxDolStudioTemplate::getInstance();
  308. $mixedValue = isset($aItems2Mixes[$aItem['name']]) ? $aItems2Mixes[$aItem['name']] : $aItem['value'];
  309. $aField = array();
  310. switch($aItem['type']) {
  311. case 'digit':
  312. $aField = array(
  313. 'type' => 'text',
  314. 'name' => $aItem['name'],
  315. 'caption' => _t($aItem['caption']),
  316. 'value' => $mixedValue,
  317. 'db' => array (
  318. 'pass' => 'Xss',
  319. ),
  320. );
  321. break;
  322. case 'text':
  323. $aField = array(
  324. 'type' => 'textarea',
  325. 'name' => $aItem['name'],
  326. 'caption' => _t($aItem['caption']),
  327. 'value' => $mixedValue,
  328. 'db' => array (
  329. 'pass' => 'XssHtml',
  330. ),
  331. );
  332. break;
  333. case 'checkbox':
  334. $aField = array(
  335. 'type' => 'checkbox',
  336. 'name' => $aItem['name'],
  337. 'caption' => _t($aItem['caption']),
  338. 'value' => 'on',
  339. 'checked' => $mixedValue == 'on',
  340. 'db' => array (
  341. 'pass' => 'Xss',
  342. ),
  343. );
  344. break;
  345. case 'list':
  346. case 'rlist':
  347. $aField = array(
  348. 'type' => 'checkbox_set',
  349. 'name' => $aItem['name'],
  350. 'caption' => _t($aItem['caption']),
  351. 'value' => !empty($mixedValue) ? explode(',', $mixedValue) : array(),
  352. 'reverse' => $aItem['type'] == 'rlist',
  353. 'db' => array (
  354. 'pass' => 'Xss',
  355. ),
  356. );
  357. if (BxDolService::isSerializedService($aItem['extra']))
  358. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  359. else
  360. foreach(explode(',', $aItem['extra']) as $sValue)
  361. $aField['values'][$sValue] = $sValue;
  362. break;
  363. case 'select':
  364. $aField = array(
  365. 'type' => 'select',
  366. 'name' => $aItem['name'],
  367. 'caption' => _t($aItem['caption']),
  368. 'value' => $mixedValue,
  369. 'values' => array(),
  370. 'db' => array (
  371. 'pass' => 'Xss',
  372. ),
  373. );
  374. if (BxDolService::isSerializedService($aItem['extra']))
  375. $aField['values'] = BxDolService::callSerialized($aItem['extra']);
  376. else
  377. foreach(explode(',', $aItem['extra']) as $sValue)
  378. $aField['values'][] = array('key' => $sValue, 'value' => $sValue);
  379. break;
  380. case 'file':
  381. $aField = array(
  382. 'type' => 'file',
  383. 'name' => $aItem['name'],
  384. 'caption' => _t($aItem['caption']),
  385. 'value' => $mixedValue,
  386. 'db' => array (
  387. 'pass' => 'Xss'
  388. )
  389. );
  390. break;
  391. case 'image':
  392. //--- Concatenation integer values as strings is required to get unique content id
  393. $iContentId = (int)($aItem['id'] . ($this->bMixes && isset($this->aMix['id']) ? $this->aMix['id'] : 0));
  394. $aField = array(
  395. 'type' => 'files',
  396. 'name' => $aItem['name'],
  397. 'storage_object' => $this->sStorage,
  398. 'images_transcoder' => $this->sTranscoder,
  399. 'uploaders' => array('sys_settings_html5'),
  400. 'upload_buttons_titles' => array('HTML5' => _t('_sys_uploader_button_name_single')),
  401. 'multiple' => false,
  402. 'content_id' => $iContentId,
  403. 'ghost_template' => array(
  404. 'inputs' => array(),
  405. ),
  406. 'caption' => _t($aItem['caption']),
  407. 'value' => $mixedValue,
  408. 'db' => array (
  409. 'pass' => 'Xss'
  410. )
  411. );
  412. break;
  413. case 'rgb':
  414. case 'rgba':
  415. $aField = array(
  416. 'type' => $aItem['type'],
  417. 'name' => $aItem['name'],
  418. 'caption' => _t($aItem['caption']),
  419. 'value' => $mixedValue,
  420. 'db' => array (
  421. 'pass' => 'Xss',
  422. ),
  423. );
  424. break;
  425. }
  426. return $aField;
  427. }
  428. protected function getMenuIcon($sGroup, &$aType)
  429. {
  430. if(empty($aType['icon']) || ($sUrl = BxDolStudioTemplate::getInstance()->getIconUrl($aType['icon'])) == "")
  431. switch($sGroup) {
  432. case BX_DOL_STUDIO_STG_GROUP_MODULES:
  433. $aType['icon'] = BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_MODULE);
  434. break;
  435. case BX_DOL_STUDIO_STG_GROUP_LANGUAGES:
  436. $aType['icon'] = BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_LANGUAGE);
  437. break;
  438. case BX_DOL_STUDIO_STG_GROUP_TEMPLATES:
  439. $aType['icon'] = BxDolStudioUtils::getIconDefault(BX_DOL_MODULE_TYPE_TEMPLATE);
  440. break;
  441. }
  442. return $aType['icon'];
  443. }
  444. }
  445. /** @} */