BxBaseStudioPolyglot.php 6.2 KB

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