BxDolStudioDesigner.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 UnaStudio UNA Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_DSG_TYPE_GENERAL', 'general');
  10. define('BX_DOL_STUDIO_DSG_TYPE_LOGO', 'logo');
  11. define('BX_DOL_STUDIO_DSG_TYPE_ICON', 'icon');
  12. define('BX_DOL_STUDIO_DSG_TYPE_COVER', 'cover');
  13. define('BX_DOL_STUDIO_DSG_TYPE_SPLASH', 'splash');
  14. define('BX_DOL_STUDIO_DSG_TYPE_INJECTIONS', 'injections');
  15. define('BX_DOL_STUDIO_DSG_TYPE_SETTINGS', 'settings');
  16. define('BX_DOL_STUDIO_DSG_TYPE_DEFAULT', 'general');
  17. class BxDolStudioDesigner extends BxTemplStudioPage
  18. {
  19. protected $sPage;
  20. protected $sManageUrl;
  21. protected $sParamLogo;
  22. protected $sParamLogoAlt;
  23. protected $sParamLogoWidth;
  24. protected $sParamLogoHeight;
  25. protected $aCovers;
  26. function __construct($sPage = "")
  27. {
  28. parent::__construct('designer');
  29. $this->oDb = new BxDolStudioDesignerQuery();
  30. $this->sPage = BX_DOL_STUDIO_DSG_TYPE_DEFAULT;
  31. if(is_string($sPage) && !empty($sPage))
  32. $this->sPage = $sPage;
  33. $this->sManageUrl = BX_DOL_URL_STUDIO . 'designer.php';
  34. $this->sParamLogo = 'sys_site_logo';
  35. $this->sParamLogoAlt = 'sys_site_logo_alt';
  36. $this->sParamLogoWidth = 'sys_site_logo_width';
  37. $this->sParamLogoHeight = 'sys_site_logo_height';
  38. $this->aCovers = array(
  39. 'cover_common' => array('setting' => 'sys_site_cover_common', 'title' => '_adm_dsg_txt_cover_common'),
  40. );
  41. }
  42. function checkAction()
  43. {
  44. $sAction = bx_get('dsg_action');
  45. if($sAction === false)
  46. return;
  47. $sAction = bx_process_input($sAction);
  48. $aResult = array('code' => 1, 'message' => _t('_adm_dsg_err_cannot_process_action'));
  49. switch($sAction) {
  50. case 'delete_logo':
  51. $aResult = array('code' => 0, 'message' => '');
  52. if(!$this->deleteLogo())
  53. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_remove_old_logo'));
  54. break;
  55. case 'delete_cover':
  56. $sValue = bx_process_input(bx_get('dsg_value'));
  57. $aResult = array('code' => 0, 'message' => '');
  58. if(empty($sValue) || !$this->deleteCover($sValue))
  59. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_remove_old_cover'));
  60. break;
  61. case 'make_default':
  62. $aResult = array('code' => 0, 'message' => '');
  63. if(!$this->makeDefault())
  64. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_make_default'));
  65. break;
  66. case 'get-page-by-type':
  67. $sValue = bx_process_input(bx_get('dsg_value'));
  68. if(empty($sValue))
  69. break;
  70. $this->sPage = $sValue;
  71. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  72. break;
  73. }
  74. echo json_encode($aResult);
  75. exit;
  76. }
  77. function setManageUrl($sUrl)
  78. {
  79. $this->sManageUrl = $sUrl;
  80. }
  81. function setLogoParams($aParams)
  82. {
  83. list($this->sParamLogo, $this->sParamLogoAlt, $this->sParamLogoWidth, $this->sParamLogoHeight) = $aParams;
  84. }
  85. function makeDefault()
  86. {
  87. $sValue = bx_get('dsg_value');
  88. if($sValue === false)
  89. return false;
  90. $sValue = bx_process_input($sValue);
  91. return $this->oDb->setParam('template', $sValue);
  92. }
  93. function submitLogo(&$oForm)
  94. {
  95. $iProfileId = getLoggedId();
  96. if(!empty($_FILES['image']['tmp_name'])) {
  97. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  98. if(!$this->deleteLogo())
  99. return $this->getJsResult('_adm_dsg_err_remove_old_logo');
  100. $iId = $oStorage->storeFileFromForm($_FILES['image'], false, $iProfileId);
  101. if($iId === false) {
  102. $this->oDb->setParam($this->sParamLogo, 0);
  103. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  104. }
  105. $this->oDb->setParam($this->sParamLogo, $iId);
  106. $oStorage->afterUploadCleanup($iId, $iProfileId);
  107. }
  108. $this->oDb->setParam($this->sParamLogoAlt, $oForm->getCleanValue('alt'));
  109. $this->oDb->setParam($this->sParamLogoWidth, $oForm->getCleanValue('width'));
  110. $this->oDb->setParam($this->sParamLogoHeight, $oForm->getCleanValue('height'));
  111. return $this->getJsResult('_adm_dsg_scs_save', true, true, bx_append_url_params($this->sManageUrl, array('page' => BX_DOL_STUDIO_DSG_TYPE_LOGO)));
  112. }
  113. function deleteLogo()
  114. {
  115. $iProfileId = getLoggedId();
  116. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  117. $iId = (int)getParam($this->sParamLogo);
  118. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  119. return false;
  120. $this->oDb->setParam($this->sParamLogo, 0);
  121. return true;
  122. }
  123. function submitIcon(&$oForm)
  124. {
  125. $iProfileId = getLoggedId();
  126. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  127. $iId = (int)getParam('sys_site_icon');
  128. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  129. return $this->getJsResult('_adm_dsg_err_remove_old_icon');
  130. $iId = $oStorage->storeFileFromForm($_FILES['image'], true, $iProfileId);
  131. if($iId === false) {
  132. $this->oDb->setParam('sys_site_icon', 0);
  133. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  134. }
  135. $this->oDb->setParam('sys_site_icon', $iId);
  136. $oStorage->afterUploadCleanup($iId, $iProfileId);
  137. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_ICON);
  138. }
  139. function submitCover(&$oForm)
  140. {
  141. $iProfile = bx_get_logged_profile_id();
  142. $oStorage = BxDolStorage::getObjectInstance($this->sCoverStorage);
  143. foreach($this->aCovers as $sCover => $aCover) {
  144. $iIdNew = $oForm->getCleanValue($sCover);
  145. if(empty($iIdNew))
  146. continue;
  147. $iIdOld = (int)getParam($aCover['setting']);
  148. if($iIdOld != 0 && !$oStorage->deleteFile($iIdOld, $iProfile))
  149. return $this->getJsResult('_adm_dsg_err_remove_old_cover');
  150. $this->oDb->setParam($aCover['setting'], $iIdNew);
  151. $oStorage->afterUploadCleanup($iIdNew, $iProfile);
  152. }
  153. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_COVER);
  154. }
  155. function deleteCover($sCover)
  156. {
  157. $iProfile = bx_get_logged_profile_id();
  158. $oStorage = BxDolStorage::getObjectInstance($this->sCoverStorage);
  159. $iId = (int)getParam($this->aCovers[$sCover]['setting']);
  160. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfile))
  161. return false;
  162. $this->oDb->setParam($this->aCovers[$sCover]['setting'], 0);
  163. return true;
  164. }
  165. function submitSplash(&$oForm)
  166. {
  167. $this->oDb->setParam('sys_site_splash_code', $oForm->getCleanValue('code'));
  168. $this->oDb->setParam('sys_site_splash_enabled', $oForm->getCleanValue('enabled') == 'on' ? 'on' : '');
  169. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_SPLASH);
  170. }
  171. function submitInjections(&$oForm)
  172. {
  173. $bResult = $this->oDb->updateInjection('sys_head', $oForm->getCleanValue('sys_head'));
  174. $bResult |= $this->oDb->updateInjection('sys_body', $oForm->getCleanValue('sys_body'));
  175. if($bResult) {
  176. if(getParam('sys_db_cache_enable'))
  177. $this->oDb->cleanCache('sys_injections.inc');
  178. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_INJECTIONS);
  179. }
  180. return $this->getJsResult('_adm_dsg_err_save_changes');
  181. }
  182. }
  183. /** @} */