BxDolStudioPolyglot.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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', 'pgt_settings');
  10. define('BX_DOL_STUDIO_PGT_TYPE_KEYS', 'pgt_keys');
  11. define('BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_TEXT', 'etemplates_text');
  12. define('BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_HTML', 'etemplates_html');
  13. define('BX_DOL_STUDIO_PGT_TYPE_DEFAULT', BX_DOL_STUDIO_PGT_TYPE_SETTINGS);
  14. class BxDolStudioPolyglot extends BxTemplStudioWidget
  15. {
  16. protected $sPage;
  17. protected $sEtcContent;
  18. function __construct($sPage = "")
  19. {
  20. parent::__construct('polyglot');
  21. $this->oDb = new BxDolStudioPolyglotQuery();
  22. $this->sPage = BX_DOL_STUDIO_PGT_TYPE_DEFAULT;
  23. if(is_string($sPage) && !empty($sPage))
  24. $this->sPage = $sPage;
  25. $this->sEtcContent = '<pre id="etc_content">' . _t('_adm_pgt_txt_et_c_content') . '</pre>';
  26. }
  27. public function checkAction()
  28. {
  29. $sAction = bx_get('pgt_action');
  30. if($sAction === false)
  31. return false;
  32. $sAction = bx_process_input($sAction);
  33. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  34. $aResult = array('code' => 1, 'message' => _t('_adm_pgt_err_cannot_process_action'));
  35. switch($sAction) {
  36. case 'get-page-by-type':
  37. $sValue = bx_process_input(bx_get('pgt_value'));
  38. if(empty($sValue))
  39. break;
  40. $this->sPage = $sValue;
  41. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  42. break;
  43. /*
  44. * Available URL params:
  45. * pgt_action = recompile - action name
  46. * pgt_language - ID or name(en, ru, etc) of language.
  47. */
  48. case 'recompile':
  49. $sLanguage = bx_process_input(bx_get('pgt_language'));
  50. if($oLanguages->compileLanguage($sLanguage))
  51. $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_recompiled'));
  52. else
  53. $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_recompile_lang'));
  54. break;
  55. /*
  56. * Available URL params:
  57. * pgt_action = restore - action name
  58. * pgt_language - ID or name(en, ru, etc) of language.
  59. * pgt_module - ID or Module Uri (@see sys_modules table). Leave empty for 'System' language file.
  60. */
  61. case 'restore':
  62. $sLanguage = bx_process_input(bx_get('pgt_language'));
  63. $sModule = bx_process_input(bx_get('pgt_module'));
  64. if($oLanguages->restoreLanguage($sLanguage, $sModule))
  65. $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_restored'));
  66. else
  67. $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_restore_lang'));
  68. break;
  69. }
  70. return $aResult;
  71. }
  72. /**
  73. * TODO: Remove (after UNA 14) if new version is working fine.
  74. */
  75. public function submitEtemplatesHtmlOld(&$oForm)
  76. {
  77. $sUnsubscribe = "{unsubscribe}";
  78. $sHeader = $oForm->getCleanValue('et_hf_header');
  79. $sFooter = $oForm->getCleanValue('et_hf_footer');
  80. if(strpos($sHeader, $sUnsubscribe) === false && strpos($sFooter, $sUnsubscribe) === false)
  81. return $this->getJsResult('_adm_pgt_err_et_hf_save_unsubscribe');
  82. $bResult = false;
  83. $bResult |= $this->oDb->setParam('site_email_html_template_header', $sHeader);
  84. $bResult |= $this->oDb->setParam('site_email_html_template_footer', $sFooter);
  85. if(!$bResult)
  86. return $this->getJsResult('_adm_pgt_err_et_hf_save');
  87. return $this->getJsResult('_adm_pgt_scs_et_hf_save', true, true, BX_DOL_URL_STUDIO . 'polyglot.php?page=' . BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_HTML);
  88. }
  89. public function submitEtemplatesHtml(&$oForm)
  90. {
  91. $sUnsubscribe = "{unsubscribe}";
  92. $sContent = $oForm->getCleanValue('content');
  93. if(strpos($sContent, $sUnsubscribe) === false)
  94. return $this->getJsResult('_adm_pgt_err_et_hf_save_unsubscribe');
  95. list($sHeader, $sFooter) = explode($this->sEtcContent, $sContent);
  96. $bResult = false;
  97. $bResult |= $this->oDb->setParam('site_email_html_template_header', $sHeader);
  98. $bResult |= $this->oDb->setParam('site_email_html_template_footer', $sFooter);
  99. if(!$bResult)
  100. return $this->getJsResult('_adm_pgt_err_et_hf_save');
  101. return $this->getJsResult('_adm_pgt_scs_et_hf_save', true, true, BX_DOL_URL_STUDIO . 'polyglot.php?page=' . BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_HTML);
  102. }
  103. }
  104. /** @} */