BxDolStudioPolyglot.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 $sEtSettingEditor;
  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->sEtSettingEditor = 'sys_std_pgt_etemplates_editor';
  27. $this->sEtcContent = '<pre id="etc_content">' . _t('_adm_pgt_txt_et_c_content') . '</pre>';
  28. }
  29. public function checkAction()
  30. {
  31. $sAction = bx_get('pgt_action');
  32. if($sAction === false)
  33. return false;
  34. $sAction = bx_process_input($sAction);
  35. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  36. $aResult = array('code' => 1, 'message' => _t('_adm_pgt_err_cannot_process_action'));
  37. switch($sAction) {
  38. case 'get-page-by-type':
  39. $sValue = bx_process_input(bx_get('pgt_value'));
  40. if(empty($sValue))
  41. break;
  42. $this->sPage = $sValue;
  43. $aResult = array('code' => 0, 'content' => $this->getPageCode());
  44. break;
  45. case 'enable-editor':
  46. $iValue = false;
  47. if(($iValue = bx_get('pgt_value')) !== false)
  48. $iValue = bx_process_input($iValue, BX_DATA_INT);
  49. else
  50. break;
  51. if(setParam($this->sEtSettingEditor, $iValue ? 'on' : ''))
  52. $aResult = ['code' => 0, 'reload' => 1];
  53. break;
  54. /*
  55. * Available URL params:
  56. * pgt_action = recompile - action name
  57. * pgt_language - ID or name(en, ru, etc) of language.
  58. */
  59. case 'recompile':
  60. $sLanguage = bx_process_input(bx_get('pgt_language'));
  61. if($oLanguages->compileLanguage($sLanguage))
  62. $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_recompiled'));
  63. else
  64. $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_recompile_lang'));
  65. break;
  66. /*
  67. * Available URL params:
  68. * pgt_action = restore - action name
  69. * pgt_language - ID or name(en, ru, etc) of language.
  70. * pgt_module - ID or Module Uri (@see sys_modules table). Leave empty for 'System' language file.
  71. */
  72. case 'restore':
  73. $sLanguage = bx_process_input(bx_get('pgt_language'));
  74. $sModule = bx_process_input(bx_get('pgt_module'));
  75. if($oLanguages->restoreLanguage($sLanguage, $sModule))
  76. $aResult = array('code' => 0, 'content' => _t('_adm_pgt_scs_restored'));
  77. else
  78. $aResult = array('code' => 2, 'content' => _t('_adm_pgt_err_cannot_restore_lang'));
  79. break;
  80. }
  81. return $aResult;
  82. }
  83. /**
  84. * TODO: Remove (after UNA 14) if new version is working fine.
  85. */
  86. public function submitEtemplatesHtmlOld(&$oForm)
  87. {
  88. $sUnsubscribe = "{unsubscribe}";
  89. $sHeader = $oForm->getCleanValue('et_hf_header');
  90. $sFooter = $oForm->getCleanValue('et_hf_footer');
  91. if(strpos($sHeader, $sUnsubscribe) === false && strpos($sFooter, $sUnsubscribe) === false)
  92. return $this->getJsResult('_adm_pgt_err_et_hf_save_unsubscribe');
  93. $bResult = false;
  94. $bResult |= $this->oDb->setParam('site_email_html_template_header', $sHeader);
  95. $bResult |= $this->oDb->setParam('site_email_html_template_footer', $sFooter);
  96. if(!$bResult)
  97. return $this->getJsResult('_adm_pgt_err_et_hf_save');
  98. 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);
  99. }
  100. public function submitEtemplatesHtml(&$oForm)
  101. {
  102. $sUnsubscribe = "{unsubscribe}";
  103. $sContent = $oForm->getCleanValue('content');
  104. if(strpos($sContent, $sUnsubscribe) === false)
  105. return $this->getJsResult('_adm_pgt_err_et_hf_save_unsubscribe');
  106. list($sHeader, $sFooter) = explode($this->sEtcContent, $sContent);
  107. $bResult = false;
  108. $bResult |= $this->oDb->setParam('site_email_html_template_header', $sHeader);
  109. $bResult |= $this->oDb->setParam('site_email_html_template_footer', $sFooter);
  110. if(!$bResult)
  111. return $this->getJsResult('_adm_pgt_err_et_hf_save');
  112. 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);
  113. }
  114. }
  115. /** @} */