BxDolStudioSettings.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 TridentStudio Trident Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_STG_TYPE_SYSTEM', 'system');
  10. define('BX_DOL_STUDIO_STG_TYPE_DEFAULT', BX_DOL_STUDIO_STG_TYPE_SYSTEM);
  11. define('BX_DOL_STUDIO_STG_GROUP_SYSTEM', 'system');
  12. define('BX_DOL_STUDIO_STG_GROUP_MODULES', 'modules');
  13. define('BX_DOL_STUDIO_STG_GROUP_LANGUAGES', 'languages');
  14. define('BX_DOL_STUDIO_STG_GROUP_TEMPLATES', 'templates');
  15. define('BX_DOL_STUDIO_STG_CATEGORY_SYSTEM', 'system');
  16. define('BX_DOL_STUDIO_STG_CATEGORY_LANGUAGES', 'languages');
  17. define('BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES', 'templates');
  18. define('BX_DOL_STUDIO_STG_MIX_SYSTEM', 'system');
  19. define('BX_DOL_STUDIO_STG_MIX_DEFAULT', BX_DOL_STUDIO_STG_MIX_SYSTEM);
  20. class BxDolStudioSettings extends BxTemplStudioPage
  21. {
  22. protected $sType;
  23. protected $sCategory;
  24. protected $aCategories;
  25. protected $aCustomCategories;
  26. protected $bMixes;
  27. protected $sMix;
  28. protected $aMix;
  29. protected $sStorage;
  30. protected $sTranscoder;
  31. protected $sErrorMessage;
  32. function __construct($sType = '', $mixedCategory = '')
  33. {
  34. parent::__construct('settings');
  35. $this->oDb = new BxDolStudioSettingsQuery();
  36. $this->sType = BX_DOL_STUDIO_STG_TYPE_DEFAULT;
  37. if(!empty($sType) && is_string($sType))
  38. $this->sType = $sType;
  39. $this->sCategory = '';
  40. if(!empty($mixedCategory)) {
  41. if(is_array($mixedCategory))
  42. $this->sCategory = $mixedCategory;
  43. else if(is_string($mixedCategory)) {
  44. $this->sCategory = json_decode($mixedCategory);
  45. if(empty($this->sCategory))
  46. $this->sCategory = $mixedCategory;
  47. }
  48. }
  49. $this->bMixes = false;
  50. $this->sMix = '';
  51. $this->aMix = array();
  52. $this->sStorage = 'sys_images_custom';
  53. $this->sTranscoder = 'sys_images_custom';
  54. $this->sErrorMessage = '';
  55. //--- Check actions ---//
  56. if(($sAction = bx_get('stg_action')) !== false) {
  57. $sAction = bx_process_input($sAction);
  58. $sValue = '';
  59. if(bx_get('stg_value') !== false)
  60. $sValue = bx_process_input(bx_get('stg_value'));
  61. $aResult = array('code' => 0, 'message' => '');
  62. if(!empty($sAction)) {
  63. switch($sAction) {
  64. case 'select-mix':
  65. $aResult = array_merge($aResult, $this->selectMix($sValue));
  66. break;
  67. case 'create-mix':
  68. $aResult = array_merge($aResult, $this->getPopupCodeCreateMix());
  69. break;
  70. case 'delete-mix':
  71. $aResult = array_merge($aResult, $this->deleteMix((int)$sValue));
  72. break;
  73. case 'get-page-by-type':
  74. $this->sType = $sValue;
  75. $aResult['content'] = $this->getPageCode();
  76. break;
  77. }
  78. echo json_encode($aResult);
  79. }
  80. exit;
  81. }
  82. }
  83. public function enableMixes($bMixes = true)
  84. {
  85. $this->bMixes = $bMixes;
  86. }
  87. public function selectMix($sName)
  88. {
  89. $this->oDb->updateMixes(array('active' => 0), array(
  90. 'type' => $this->sType,
  91. 'category' => is_string($this->sCategory) ? $this->sCategory : '',
  92. 'active' => 1
  93. ));
  94. $aResult = array();
  95. if($sName == BX_DOL_STUDIO_STG_MIX_SYSTEM || $this->oDb->updateMixes(array('active' => 1), array('name' => $sName)))
  96. $aResult = array('eval' => $this->getPageJsObject() . '.onMixSelect(oData);');
  97. else
  98. $aResult = array('message' => _t('_adm_stg_err_cannot_perform'));
  99. return $aResult;
  100. }
  101. public function deleteMix($iId)
  102. {
  103. $aResult = array();
  104. if($this->oDb->deleteMixesOptions(array('mix_id' => $iId)) && $this->oDb->deleteMixes(array('id' => $iId)))
  105. $aResult = array('eval' => $this->getPageJsObject() . '.onMixDelete(oData);');
  106. else
  107. $aResult = array('message' => _t('_adm_stg_err_cannot_perform'));
  108. return $aResult;
  109. }
  110. function saveChanges(&$oForm)
  111. {
  112. $iMixId = $oForm->getCleanValue('mix_id');
  113. $aCategories = explode(',', $oForm->getCleanValue('categories'));
  114. foreach ($aCategories as $sCategory) {
  115. $aOptions = array();
  116. $iOptions = $this->oDb->getOptions(array('type' => 'by_category_name_full', 'value' => $sCategory), $aOptions);
  117. $aData = array();
  118. foreach($aOptions as $aOption) {
  119. $aData[$aOption['name']] = $this->getSubmittedValue($aOption, $oForm);
  120. if($aData[$aOption['name']] === false && !empty($this->sErrorMessage)) {
  121. $this->sCategory = $sCategory;
  122. return $this->getJsResult(_t('_adm_stg_err_save_error_message', _t($aOption['caption']), _t($this->sErrorMessage)), false);
  123. }
  124. if(!empty($aOption['check'])) {
  125. $sCheckerHelper = '';
  126. if(!empty($aOption['type_name']) && BxDolRequest::serviceExists($aOption['type_name'], 'get_settings_checker_helper'))
  127. $sCheckerHelper = BxDolService::call($aOption['type_name'], 'get_settings_checker_helper');
  128. if($sCheckerHelper == '') {
  129. bx_import('BxDolStudioForm');
  130. $sCheckerHelper = 'BxDolStudioFormCheckerHelper';
  131. }
  132. $oChecker = new $sCheckerHelper();
  133. $aCheckFunction = array($oChecker, 'check' . bx_gen_method_name($aOption['check']));
  134. $aCheckFunctionParams = array($aData[$aOption['name']]);
  135. if(!empty($aOption['check_params']))
  136. $aCheckFunctionParams = array_merge($aCheckFunctionParams, unserialize($aOption['check_params']));
  137. if(is_callable($aCheckFunction) && !call_user_func_array($aCheckFunction, $aCheckFunctionParams)) {
  138. $this->sCategory = $sCategory;
  139. return $this->getJsResult(_t('_adm_stg_err_save_error_message', _t($aOption['caption']), _t($aOption['check_error'])), false);
  140. }
  141. }
  142. if(isset($aData[$aOption['name']]))
  143. $aData[$aOption['name']] = $this->getProcessedValue($aOption, $aData[$aOption['name']]);
  144. else
  145. $aData[$aOption['name']] = $this->getEmptyValue($aOption);
  146. if($this->oDb->setParam($aOption['name'], $aData[$aOption['name']], $iMixId)) {
  147. $aCategoryInfo = array();
  148. $this->oDb->getCategories(array('type' => 'by_name', 'value' => $sCategory), $aCategoryInfo, false);
  149. bx_alert('system', 'save_setting', 0, 0, array('category' => $aCategoryInfo, 'option' => $aOption['name'], 'value' => $aData[$aOption['name']]));
  150. }
  151. }
  152. }
  153. return $this->getJsResult('_adm_stg_scs_save');
  154. }
  155. protected function getSubmittedValue($aOption, &$oForm)
  156. {
  157. $mixedValue = '';
  158. switch($aOption['type']) {
  159. case 'image':
  160. $mixedValue = (int)getParam($aOption['name']);
  161. $aIds = $oForm->getCleanValue($aOption['name']);
  162. if(empty($aIds))
  163. break;
  164. $oStorage = BxDolStorage::getObjectInstance($this->sStorage);
  165. if(!$oStorage)
  166. break;
  167. //--- Concatenation integer values as strings is required to get unique content id
  168. $iContentId = (int)($aOption['id'] . (int)$oForm->getCleanValue('mix_id'));
  169. foreach($aIds as $iId) {
  170. $oStorage->updateGhostsContentId($iId, false, $iContentId);
  171. $mixedValue = $iId;
  172. }
  173. break;
  174. default:
  175. $mixedValue = $oForm->getCleanValue($aOption['name']);
  176. }
  177. return $mixedValue;
  178. }
  179. protected function getProcessedValue($aOption, $mixedValue)
  180. {
  181. if(is_array($mixedValue))
  182. $mixedValue = implode(',', $mixedValue);
  183. return $mixedValue;
  184. }
  185. protected function getEmptyValue($aOption)
  186. {
  187. $mixedValue = '';
  188. switch($aOption['type']) {
  189. case 'digit':
  190. $mixedValue = 0;
  191. break;
  192. case 'select':
  193. if (BxDolService::isSerializedService($aOption['extra']))
  194. $aValues = BxDolService::callSerialized($aOption['extra']);
  195. else
  196. $aValues = explode(',', $aOption['extra']);
  197. $mixedValue = $aValues[0];
  198. break;
  199. case 'text':
  200. case 'checkbox':
  201. case 'file':
  202. $mixedValue = "";
  203. break;
  204. }
  205. return $mixedValue;
  206. }
  207. }
  208. /** @} */