BxDolStudioPolyglot.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_PGT_TYPE_SETTINGS', 'settings');
  10. define('BX_DOL_STUDIO_PGT_TYPE_KEYS', 'keys');
  11. define('BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES', 'etemplates');
  12. define('BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_HF', 'etemplates_hf');
  13. define('BX_DOL_STUDIO_PGT_TYPE_DEFAULT', BX_DOL_STUDIO_PGT_TYPE_SETTINGS);
  14. class BxDolStudioPolyglot extends BxTemplStudioWidget
  15. {
  16. protected $sPage;
  17. function __construct($sPage = "")
  18. {
  19. parent::__construct('polyglot');
  20. $this->oDb = new BxDolStudioPolyglotQuery();
  21. $this->sPage = BX_DOL_STUDIO_PGT_TYPE_DEFAULT;
  22. if(is_string($sPage) && !empty($sPage))
  23. $this->sPage = $sPage;
  24. }
  25. public function checkAction()
  26. {
  27. $sAction = bx_get('pgt_action');
  28. if($sAction === false)
  29. return false;
  30. $sAction = bx_process_input($sAction);
  31. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  32. $aResult = array('code' => 1, 'message' => _t('_adm_pgt_err_cannot_process_action'));
  33. switch($sAction) {
  34. case 'get-page-by-type':
  35. $sValue = bx_process_input(bx_get('pgt_value'));
  36. if(empty($sValue))
  37. break;
  38. $this->sPage = $sValue;
  39. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  40. break;
  41. /*
  42. * Available URL params:
  43. * pgt_action = recompile - action name
  44. * pgt_language - ID or name(en, ru, etc) of language.
  45. */
  46. case 'recompile':
  47. $sLanguage = bx_process_input(bx_get('pgt_language'));
  48. if($oLanguages->compileLanguage($sLanguage))
  49. $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_recompiled'));
  50. else
  51. $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_recompile_lang'));
  52. break;
  53. /*
  54. * Available URL params:
  55. * pgt_action = restore - action name
  56. * pgt_language - ID or name(en, ru, etc) of language.
  57. * pgt_module - ID or Module Uri (@see sys_modules table). Leave empty for 'System' language file.
  58. */
  59. case 'restore':
  60. $sLanguage = bx_process_input(bx_get('pgt_language'));
  61. $sModule = bx_process_input(bx_get('pgt_module'));
  62. if($oLanguages->restoreLanguage($sLanguage, $sModule))
  63. $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_restored'));
  64. else
  65. $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_restore_lang'));
  66. break;
  67. }
  68. return $aResult;
  69. }
  70. public function submitEtemplatesHf(&$oForm)
  71. {
  72. $sUnsubscribe = "{unsubscribe}";
  73. $sHeader = $oForm->getCleanValue('et_hf_header');
  74. $sFooter = $oForm->getCleanValue('et_hf_footer');
  75. if(strpos($sHeader, $sUnsubscribe) === false && strpos($sFooter, $sUnsubscribe) === false)
  76. return $this->getJsResult('_adm_pgt_err_et_hf_save_unsubscribe');
  77. $bResult = false;
  78. $bResult |= $this->oDb->setParam('site_email_html_template_header', $sHeader);
  79. $bResult |= $this->oDb->setParam('site_email_html_template_footer', $sFooter);
  80. if(!$bResult)
  81. return $this->getJsResult('_adm_pgt_err_et_hf_save');
  82. return $this->getJsResult('_adm_pgt_scs_et_hf_save', true, true, BX_DOL_URL_STUDIO . 'polyglot.php?page=' . BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_HF);
  83. }
  84. }
  85. /** @} */