BxDolStudioPolyglot.php 4.8 KB

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