BxBaseStudioPolyglot.php 5.8 KB

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