BxBaseStudioPolyglot.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioPolyglot extends BxDolStudioPolyglot
  11. {
  12. protected $sSubpageUrl;
  13. protected $aMenuItems;
  14. protected $aGridObjects;
  15. function __construct($sPage = '')
  16. {
  17. parent::__construct($sPage);
  18. $this->sSubpageUrl = BX_DOL_URL_STUDIO . 'polyglot.php?page=';
  19. $this->aMenuItems = array(
  20. BX_DOL_STUDIO_PGT_TYPE_SETTINGS => array('icon' => 'cogs'),
  21. BX_DOL_STUDIO_PGT_TYPE_KEYS => array('icon' => 'key'),
  22. BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES => array('icon' => 'far envelope'),
  23. BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_HF => array('icon' => 'far sticky-note')
  24. );
  25. $this->aGridObjects = array(
  26. 'keys' => 'sys_studio_lang_keys',
  27. 'etemplates' => 'sys_studio_lang_etemplates',
  28. );
  29. }
  30. function getPageCss()
  31. {
  32. return array_merge(parent::getPageCss(), array('forms.css', 'paginate.css', 'polyglot.css'));
  33. }
  34. function getPageJs()
  35. {
  36. return array_merge(parent::getPageJs(), array('settings.js', 'polyglot.js'));
  37. }
  38. function getPageJsClass()
  39. {
  40. return 'BxDolStudioPolyglot';
  41. }
  42. function getPageJsObject()
  43. {
  44. return 'oBxDolStudioPolyglot';
  45. }
  46. function getPageJsCode($aOptions = array(), $bWrap = true)
  47. {
  48. $aOptions = array_merge($aOptions, array(
  49. 'sActionUrl' => BX_DOL_URL_STUDIO . 'polyglot.php'
  50. ));
  51. return parent::getPageJsCode($aOptions, $bWrap);
  52. }
  53. function getPageMenu($aMenu = array(), $aMarkers = array())
  54. {
  55. $sJsObject = $this->getPageJsObject();
  56. $aMenu = array();
  57. foreach($this->aMenuItems as $sMenuItem => $aItem)
  58. $aMenu[] = array(
  59. 'name' => $sMenuItem,
  60. 'icon' => $aItem['icon'],
  61. 'link' => $this->sSubpageUrl . $sMenuItem,
  62. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  63. 'selected' => $sMenuItem == $this->sPage
  64. );
  65. return parent::getPageMenu($aMenu);
  66. }
  67. protected function getSettings()
  68. {
  69. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_DEFAULT, BX_DOL_STUDIO_STG_CATEGORY_LANGUAGES);
  70. return BxDolStudioTemplate::getInstance()->parseHtmlByName('polyglot.html', array(
  71. 'content' => $oPage->getFormCode(),
  72. 'js_content' => ''
  73. ));
  74. }
  75. protected function getKeys()
  76. {
  77. return $this->getGrid($this->aGridObjects['keys']);
  78. }
  79. protected function getEtemplates()
  80. {
  81. return $this->getGrid($this->aGridObjects['etemplates']);
  82. }
  83. protected function getEtemplatesHf()
  84. {
  85. $oTemplate = BxDolStudioTemplate::getInstance();
  86. $sFormId = 'adm-dsg-et-hf-form';
  87. $sIFrameId = 'adm-dsg-et-hf-iframe';
  88. $aForm = array(
  89. 'form_attrs' => array(
  90. 'id' => $sFormId,
  91. 'name' => $sFormId,
  92. 'action' => BX_DOL_URL_STUDIO . 'polyglot.php',
  93. 'method' => 'post',
  94. 'enctype' => 'multipart/form-data',
  95. 'target' => $sIFrameId
  96. ),
  97. 'params' => array(
  98. 'db' => array(
  99. 'table' => '',
  100. 'key' => '',
  101. 'uri' => '',
  102. 'uri_title' => '',
  103. 'submit_name' => 'save'
  104. ),
  105. ),
  106. 'inputs' => array(
  107. 'page' => array(
  108. 'type' => 'hidden',
  109. 'name' => 'page',
  110. 'value' => $this->sPage
  111. ),
  112. 'et_hf_header' => array(
  113. 'type' => 'textarea',
  114. 'code' => true,
  115. 'name' => 'et_hf_header',
  116. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_header'),
  117. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  118. 'value' => getParam('site_email_html_template_header'),
  119. 'db' => array (
  120. 'pass' => 'Xss',
  121. ),
  122. ),
  123. 'et_hf_footer' => array(
  124. 'type' => 'textarea',
  125. 'code' => true,
  126. 'name' => 'et_hf_footer',
  127. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_footer'),
  128. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  129. 'value' => getParam('site_email_html_template_footer'),
  130. 'db' => array (
  131. 'pass' => 'Xss',
  132. ),
  133. ),
  134. 'save' => array(
  135. 'type' => 'submit',
  136. 'name' => 'save',
  137. 'value' => _t('_adm_pgt_btn_et_hf_submit'),
  138. )
  139. )
  140. );
  141. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  142. $oForm->initChecker();
  143. if($oForm->isSubmittedAndValid()) {
  144. echo $this->submitEtemplatesHf($oForm);
  145. exit;
  146. }
  147. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  148. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  149. return $oTemplate->parseHtmlByName('polyglot.html', array(
  150. 'content' => $oTemplate->parseHtmlByName('pgt_etemplates_hf.html', array(
  151. 'warning' => '',
  152. 'iframe_id' => $sIFrameId,
  153. 'form' => $oForm->getCode()
  154. )),
  155. 'js_content' => $this->getPageJsCode(array(
  156. 'sCodeMirror' => 'textarea[name=et_hf_header],textarea[name=et_hf_footer]'
  157. ))
  158. ));
  159. }
  160. protected function getGrid($sObjectName)
  161. {
  162. $oGrid = BxDolGrid::getObjectInstance($sObjectName);
  163. if(!$oGrid)
  164. return '';
  165. return BxDolStudioTemplate::getInstance()->parseHtmlByName('polyglot.html', array(
  166. 'content' => $oGrid->getCode(),
  167. 'js_content' => ''
  168. ));
  169. }
  170. }
  171. /** @} */