BxDolStudioDesigner.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_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_SPLASH', 'splash');
  13. define('BX_DOL_STUDIO_DSG_TYPE_SETTINGS', 'settings');
  14. define('BX_DOL_STUDIO_DSG_TYPE_DEFAULT', 'general');
  15. class BxDolStudioDesigner extends BxTemplStudioPage
  16. {
  17. protected $sPage;
  18. protected $sManageUrl;
  19. protected $sParamLogo;
  20. protected $sParamLogoAlt;
  21. protected $sParamLogoWidth;
  22. protected $sParamLogoHeight;
  23. function __construct($sPage = "")
  24. {
  25. parent::__construct('designer');
  26. $this->oDb = new BxDolStudioDesignerQuery();
  27. $this->sPage = BX_DOL_STUDIO_DSG_TYPE_DEFAULT;
  28. if(is_string($sPage) && !empty($sPage))
  29. $this->sPage = $sPage;
  30. $this->sManageUrl = BX_DOL_URL_STUDIO . 'designer.php';
  31. $this->sParamLogo = 'sys_site_logo';
  32. $this->sParamLogoAlt = 'sys_site_logo_alt';
  33. $this->sParamLogoWidth = 'sys_site_logo_width';
  34. $this->sParamLogoHeight = 'sys_site_logo_height';
  35. }
  36. function checkAction()
  37. {
  38. $sAction = bx_get('dsg_action');
  39. if($sAction === false)
  40. return;
  41. $sAction = bx_process_input($sAction);
  42. $aResult = array('code' => 1, 'message' => _t('_adm_dsg_err_cannot_process_action'));
  43. switch($sAction) {
  44. case 'delete_logo':
  45. $aResult = array('code' => 0, 'message' => '');
  46. if(!$this->deleteLogo())
  47. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_remove_old_logo'));
  48. break;
  49. case 'make_default':
  50. $aResult = array('code' => 0, 'message' => '');
  51. if(!$this->makeDefault())
  52. $aResult = array('code' => 2, 'message' => _t('_adm_dsg_err_make_default'));
  53. break;
  54. case 'get-page-by-type':
  55. $sValue = bx_process_input(bx_get('dsg_value'));
  56. if(empty($sValue))
  57. break;
  58. $this->sPage = $sValue;
  59. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  60. break;
  61. }
  62. echo json_encode($aResult);
  63. exit;
  64. }
  65. function setManageUrl($sUrl)
  66. {
  67. $this->sManageUrl = $sUrl;
  68. }
  69. function setLogoParams($aParams)
  70. {
  71. list($this->sParamLogo, $this->sParamLogoAlt, $this->sParamLogoWidth, $this->sParamLogoHeight) = $aParams;
  72. }
  73. function makeDefault()
  74. {
  75. $sValue = bx_get('dsg_value');
  76. if($sValue === false)
  77. return false;
  78. $sValue = bx_process_input($sValue);
  79. return $this->oDb->setParam('template', $sValue);
  80. }
  81. function submitLogo(&$oForm)
  82. {
  83. $iProfileId = getLoggedId();
  84. if(!empty($_FILES['image']['tmp_name'])) {
  85. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  86. if(!$this->deleteLogo())
  87. return $this->getJsResult('_adm_dsg_err_remove_old_logo');
  88. $iId = $oStorage->storeFileFromForm($_FILES['image'], false, $iProfileId);
  89. if($iId === false) {
  90. $this->oDb->setParam($this->sParamLogo, 0);
  91. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  92. }
  93. $this->oDb->setParam($this->sParamLogo, $iId);
  94. $oStorage->afterUploadCleanup($iId, $iProfileId);
  95. }
  96. $this->oDb->setParam($this->sParamLogoAlt, $oForm->getCleanValue('alt'));
  97. $this->oDb->setParam($this->sParamLogoWidth, $oForm->getCleanValue('width'));
  98. $this->oDb->setParam($this->sParamLogoHeight, $oForm->getCleanValue('height'));
  99. return $this->getJsResult('_adm_dsg_scs_save', true, true, bx_append_url_params($this->sManageUrl, array('page' => BX_DOL_STUDIO_DSG_TYPE_LOGO)));
  100. }
  101. function deleteLogo()
  102. {
  103. $iProfileId = getLoggedId();
  104. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  105. $iId = (int)getParam($this->sParamLogo);
  106. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  107. return false;
  108. $this->oDb->setParam($this->sParamLogo, 0);
  109. return true;
  110. }
  111. function submitIcon(&$oForm)
  112. {
  113. $iProfileId = getLoggedId();
  114. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  115. $iId = (int)getParam('sys_site_icon');
  116. if($iId != 0 && !$oStorage->deleteFile($iId, $iProfileId))
  117. return $this->getJsResult('_adm_dsg_err_remove_old_icon');
  118. $iId = $oStorage->storeFileFromForm($_FILES['image'], true, $iProfileId);
  119. if($iId === false) {
  120. $this->oDb->setParam('sys_site_icon', 0);
  121. return $this->getJsResult(_t('_adm_dsg_err_save') . $oStorage->getErrorString(), false);
  122. }
  123. $this->oDb->setParam('sys_site_icon', $iId);
  124. $oStorage->afterUploadCleanup($iId, $iProfileId);
  125. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_ICON);
  126. }
  127. function submitSplash(&$oForm)
  128. {
  129. $this->oDb->setParam('sys_site_splash_code', $oForm->getCleanValue('code'));
  130. $this->oDb->setParam('sys_site_splash_enabled', $oForm->getCleanValue('enabled') == 'on' ? 'on' : '');
  131. return $this->getJsResult('_adm_dsg_scs_save', true, true, BX_DOL_URL_STUDIO . 'designer.php?page=' . BX_DOL_STUDIO_DSG_TYPE_SPLASH);
  132. }
  133. }
  134. /** @} */