BxDolStudioDesigner.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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(
  40. 'setting' => 'sys_site_cover_common',
  41. 'transcoder' => BX_DOL_TRANSCODER_OBJ_COVER,
  42. 'title' => '_adm_dsg_txt_cover_common',
  43. 'template' => 'dsr_cover_preview_page.html'
  44. ),
  45. 'cover_unit_profile' => array(
  46. 'setting' => 'sys_unit_cover_profile',
  47. 'transcoder' => BX_DOL_TRANSCODER_OBJ_COVER_UNIT_PROFILE,
  48. 'title' => '_adm_dsg_txt_cover_unit_profile',
  49. 'template' => 'dsr_cover_preview_unit_profile.html'
  50. )
  51. );
  52. }
  53. function checkAction()
  54. {
  55. $sAction = bx_get('dsg_action');
  56. if($sAction === false)
  57. return;
  58. $sAction = bx_process_input($sAction);
  59. $aResult = array('code' => 1, 'message' => _t('_adm_dsg_err_cannot_process_action'));
  60. switch($sAction) {
  61. case 'delete_logo':
  62. $aResult = array('code' => 0, 'message' => '');
  63. if(!$this->deleteLogo())
  64. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_remove_old_logo'));
  65. break;
  66. case 'delete_cover':
  67. $sValue = bx_process_input(bx_get('dsg_value'));
  68. $aResult = array('code' => 0, 'message' => '');
  69. if(empty($sValue) || !$this->deleteCover($sValue))
  70. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_remove_old_cover'));
  71. break;
  72. case 'make_default':
  73. $aResult = array('code' => 0, 'message' => '');
  74. if(!$this->makeDefault())
  75. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_make_default'));
  76. break;
  77. case 'get-page-by-type':
  78. $sValue = bx_process_input(bx_get('dsg_value'));
  79. if(empty($sValue))
  80. break;
  81. $this->sPage = $sValue;
  82. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  83. break;
  84. }
  85. echo json_encode($aResult);
  86. exit;
  87. }
  88. function setManageUrl($sUrl)
  89. {
  90. $this->sManageUrl = $sUrl;
  91. }
  92. function setLogoParams($aParams)
  93. {
  94. list($this->sParamLogo, $this->sParamLogoAlt, $this->sParamLogoWidth, $this->sParamLogoHeight) = $aParams;
  95. }
  96. function makeDefault()
  97. {
  98. $sValue = bx_get('dsg_value');
  99. if($sValue === false)
  100. return false;
  101. $sValue = bx_process_input($sValue);
  102. return $this->oDb->setParam('template', $sValue);
  103. }
  104. function submitLogo(&$oForm)
  105. {
  106. $iProfileId = getLoggedId();
  107. if(!empty($_FILES['image']['tmp_name'])) {
  108. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  109. if(!$this->deleteLogo())
  110. return $this->getJsResult('_adm_dsg_err_remove_old_logo');
  111. $iId = $oStorage->storeFileFromForm($_FILES['image'], false, $iProfileId);
  112. if($iId === false) {
  113. $this->oDb->setParam($this->sParamLogo, 0);
  114. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  115. }
  116. $this->oDb->setParam($this->sParamLogo, $iId);
  117. $oStorage->afterUploadCleanup($iId, $iProfileId);
  118. }
  119. $this->oDb->setParam($this->sParamLogoAlt, $oForm->getCleanValue('alt'));
  120. $this->oDb->setParam($this->sParamLogoWidth, $oForm->getCleanValue('width'));
  121. $this->oDb->setParam($this->sParamLogoHeight, $oForm->getCleanValue('height'));
  122. return $this->getJsResult('_adm_dsg_scs_save', true, true, bx_append_url_params($this->sManageUrl, array('page' => BX_DOL_STUDIO_DSG_TYPE_LOGO)));
  123. }
  124. function deleteLogo()
  125. {
  126. $iProfileId = getLoggedId();
  127. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  128. $iId = (int)getParam($this->sParamLogo);
  129. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  130. return false;
  131. $this->oDb->setParam($this->sParamLogo, 0);
  132. return true;
  133. }
  134. function submitIcon(&$oForm)
  135. {
  136. $iProfileId = getLoggedId();
  137. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  138. $iId = (int)getParam('sys_site_icon');
  139. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  140. return $this->getJsResult('_adm_dsg_err_remove_old_icon');
  141. $iId = $oStorage->storeFileFromForm($_FILES['image'], true, $iProfileId);
  142. if($iId === false) {
  143. $this->oDb->setParam('sys_site_icon', 0);
  144. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  145. }
  146. $this->oDb->setParam('sys_site_icon', $iId);
  147. $oStorage->afterUploadCleanup($iId, $iProfileId);
  148. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_ICON);
  149. }
  150. function submitCover(&$oForm)
  151. {
  152. $iProfile = bx_get_logged_profile_id();
  153. $oStorage = BxDolStorage::getObjectInstance($this->sCoverStorage);
  154. foreach($this->aCovers as $sCover => $aCover) {
  155. $iIdNew = $oForm->getCleanValue($sCover);
  156. if(empty($iIdNew))
  157. continue;
  158. $iIdOld = (int)getParam($aCover['setting']);
  159. if(!$this->deleteCover($sCover))
  160. return $this->getJsResult('_adm_dsg_err_remove_old_cover');
  161. $this->oDb->setParam($aCover['setting'], $iIdNew);
  162. $oStorage->afterUploadCleanup($iIdNew, $iProfile);
  163. }
  164. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_COVER);
  165. }
  166. function deleteCover($sCover)
  167. {
  168. $iProfile = bx_get_logged_profile_id();
  169. $oStorage = BxDolStorage::getObjectInstance($this->sCoverStorage);
  170. $iId = (int)getParam($this->aCovers[$sCover]['setting']);
  171. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfile) && $oStorage->getErrorCode() != BX_DOL_STORAGE_ERR_FILE_NOT_FOUND)
  172. return false;
  173. $this->oDb->setParam($this->aCovers[$sCover]['setting'], 0);
  174. return true;
  175. }
  176. function submitSplash(&$oForm)
  177. {
  178. $this->oDb->setParam('sys_site_splash_code', $oForm->getCleanValue('code'));
  179. $this->oDb->setParam('sys_site_splash_enabled', $oForm->getCleanValue('enabled') == 'on' ? 'on' : '');
  180. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_SPLASH);
  181. }
  182. function submitInjections(&$oForm)
  183. {
  184. $bResult = $this->oDb->updateInjection('sys_head', $oForm->getCleanValue('sys_head'));
  185. $bResult |= $this->oDb->updateInjection('sys_body', $oForm->getCleanValue('sys_body'));
  186. if($bResult) {
  187. if(getParam('sys_db_cache_enable'))
  188. $this->oDb->cleanCache('sys_injections.inc');
  189. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_INJECTIONS);
  190. }
  191. return $this->getJsResult('_adm_dsg_err_save_changes');
  192. }
  193. }
  194. /** @} */