BxBaseStudioPolyglot.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. function getPageCode()
  68. {
  69. $sResult = parent::getPageCode();
  70. if($sResult === false)
  71. return false;
  72. $sMethod = 'get' . bx_gen_method_name($this->sPage);
  73. if(!method_exists($this, $sMethod))
  74. return '';
  75. return $sResult . $this->$sMethod();
  76. }
  77. protected function getSettings()
  78. {
  79. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_DEFAULT, BX_DOL_STUDIO_STG_CATEGORY_LANGUAGES);
  80. return BxDolStudioTemplate::getInstance()->parseHtmlByName('polyglot.html', array(
  81. 'content' => $oPage->getFormCode(),
  82. 'js_content' => ''
  83. ));
  84. }
  85. protected function getKeys()
  86. {
  87. return $this->getGrid($this->aGridObjects['keys']);
  88. }
  89. protected function getEtemplates()
  90. {
  91. return $this->getGrid($this->aGridObjects['etemplates']);
  92. }
  93. protected function getEtemplatesHf()
  94. {
  95. $oTemplate = BxDolStudioTemplate::getInstance();
  96. $sFormId = 'adm-dsg-et-hf-form';
  97. $sIFrameId = 'adm-dsg-et-hf-iframe';
  98. $aForm = array(
  99. 'form_attrs' => array(
  100. 'id' => $sFormId,
  101. 'name' => $sFormId,
  102. 'action' => BX_DOL_URL_STUDIO . 'polyglot.php',
  103. 'method' => 'post',
  104. 'enctype' => 'multipart/form-data',
  105. 'target' => $sIFrameId
  106. ),
  107. 'params' => array(
  108. 'db' => array(
  109. 'table' => '',
  110. 'key' => '',
  111. 'uri' => '',
  112. 'uri_title' => '',
  113. 'submit_name' => 'save'
  114. ),
  115. ),
  116. 'inputs' => array(
  117. 'page' => array(
  118. 'type' => 'hidden',
  119. 'name' => 'page',
  120. 'value' => $this->sPage
  121. ),
  122. 'et_hf_header' => array(
  123. 'type' => 'textarea',
  124. 'code' => true,
  125. 'name' => 'et_hf_header',
  126. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_header'),
  127. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  128. 'value' => getParam('site_email_html_template_header'),
  129. 'db' => array (
  130. 'pass' => 'Xss',
  131. ),
  132. ),
  133. 'et_hf_footer' => array(
  134. 'type' => 'textarea',
  135. 'code' => true,
  136. 'name' => 'et_hf_footer',
  137. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_footer'),
  138. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  139. 'value' => getParam('site_email_html_template_footer'),
  140. 'db' => array (
  141. 'pass' => 'Xss',
  142. ),
  143. ),
  144. 'save' => array(
  145. 'type' => 'submit',
  146. 'name' => 'save',
  147. 'value' => _t('_adm_pgt_btn_et_hf_submit'),
  148. )
  149. )
  150. );
  151. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  152. $oForm->initChecker();
  153. if($oForm->isSubmittedAndValid()) {
  154. echo $this->submitEtemplatesHf($oForm);
  155. exit;
  156. }
  157. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  158. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  159. return $oTemplate->parseHtmlByName('polyglot.html', array(
  160. 'content' => $this->getBlockCode(array(
  161. 'items' => $oTemplate->parseHtmlByName('pgt_etemplates_hf.html', array(
  162. 'warning' => '',
  163. 'iframe_id' => $sIFrameId,
  164. 'form' => $oForm->getCode()
  165. )),
  166. )),
  167. 'js_content' => $this->getPageJsCode(array(
  168. 'sCodeMirror' => 'textarea[name=et_hf_header],textarea[name=et_hf_footer]'
  169. ))
  170. ));
  171. }
  172. protected function getGrid($sObjectName)
  173. {
  174. $oGrid = BxDolGrid::getObjectInstance($sObjectName);
  175. if(!$oGrid)
  176. return '';
  177. return BxDolStudioTemplate::getInstance()->parseHtmlByName('polyglot.html', array(
  178. 'content' => $this->getBlockCode(array(
  179. 'items' => $oGrid->getCode()
  180. )),
  181. 'js_content' => ''
  182. ));
  183. }
  184. }
  185. /** @} */