1
0

BxBaseStudioPolyglot.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. protected $aHtmlIds;
  16. public function __construct($sPage = '')
  17. {
  18. parent::__construct($sPage);
  19. $this->aPageCss = array_merge($this->aPageCss, ['forms.css', 'paginate.css', 'polyglot.css']);
  20. $this->aPageJs = array_merge($this->aPageJs, ['polyglot.js']);
  21. $this->sPageJsClass = 'BxDolStudioPolyglot';
  22. $this->sPageJsObject = 'oBxDolStudioPolyglot';
  23. $this->sSubpageUrl = BX_DOL_URL_STUDIO . 'polyglot.php?page=';
  24. $this->aMenuItems = [
  25. BX_DOL_STUDIO_PGT_TYPE_SETTINGS => ['icon' => 'mi-pgt-settings.svg'],
  26. BX_DOL_STUDIO_PGT_TYPE_KEYS => ['icon' => 'mi-pgt-keys.svg'],
  27. BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_TEXT => ['icon' => 'mi-pgt-etemplates-text.svg'],
  28. BX_DOL_STUDIO_PGT_TYPE_ETEMPLATES_HTML => ['icon' => 'mi-pgt-etemplates-html.svg']
  29. ];
  30. $this->aGridObjects = [
  31. 'keys' => 'sys_studio_lang_keys',
  32. 'etemplates' => 'sys_studio_lang_etemplates',
  33. ];
  34. $this->aHtmlIds = [
  35. 'etc_builder_id' => 'adm-pgt-etc-builder',
  36. ];
  37. }
  38. public function getPageJsCode($aOptions = array(), $bWrap = true)
  39. {
  40. $aOptions = array_merge($aOptions, array(
  41. 'sActionUrl' => BX_DOL_URL_STUDIO . 'polyglot.php'
  42. ));
  43. return parent::getPageJsCode($aOptions, $bWrap);
  44. }
  45. public function getPageCaption()
  46. {
  47. return parent::getPageCaption() . $this->getPageJsCode();
  48. }
  49. public function getPageMenu($aMenu = [], $aMarkers = [])
  50. {
  51. if($this->aMenuItems === false)
  52. return '';
  53. $sJsObject = $this->getPageJsObject();
  54. $aMenu = [];
  55. foreach($this->aMenuItems as $sMenuItem => $aItem)
  56. $aMenu[] = [
  57. 'name' => $sMenuItem,
  58. 'icon' => $aItem['icon'],
  59. 'icon_bg' => true,
  60. 'link' => $this->sSubpageUrl . $sMenuItem,
  61. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  62. 'selected' => $sMenuItem == $this->sPage
  63. ];
  64. return parent::getPageMenu($aMenu);
  65. }
  66. protected function getPgtSettings()
  67. {
  68. $oOptions = new BxTemplStudioOptions(BX_DOL_STUDIO_STG_TYPE_DEFAULT, BX_DOL_STUDIO_STG_CATEGORY_LANGUAGES);
  69. $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss());
  70. $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs());
  71. return BxDolStudioTemplate::getInstance()->parseHtmlByName('polyglot.html', array(
  72. 'content' => $oOptions->getCode(),
  73. 'js_content' => ''
  74. ));
  75. }
  76. protected function getPgtKeys()
  77. {
  78. return $this->getGrid($this->aGridObjects['keys']);
  79. }
  80. protected function getEtemplatesText()
  81. {
  82. return $this->getGrid($this->aGridObjects['etemplates']);
  83. }
  84. /**
  85. * TODO: Remove (after UNA 14) if new version is working fine.
  86. */
  87. protected function getEtemplatesHtmlOld()
  88. {
  89. $oTemplate = BxDolStudioTemplate::getInstance();
  90. $sFormId = 'adm-dsg-et-hf-form';
  91. $sIFrameId = 'adm-dsg-et-hf-iframe';
  92. $aForm = array(
  93. 'form_attrs' => array(
  94. 'id' => $sFormId,
  95. 'name' => $sFormId,
  96. 'action' => BX_DOL_URL_STUDIO . 'polyglot.php',
  97. 'method' => 'post',
  98. 'enctype' => 'multipart/form-data',
  99. 'target' => $sIFrameId
  100. ),
  101. 'params' => array(
  102. 'db' => array(
  103. 'table' => '',
  104. 'key' => '',
  105. 'uri' => '',
  106. 'uri_title' => '',
  107. 'submit_name' => 'save'
  108. ),
  109. ),
  110. 'inputs' => array(
  111. 'page' => array(
  112. 'type' => 'hidden',
  113. 'name' => 'page',
  114. 'value' => $this->sPage
  115. ),
  116. 'et_hf_header' => array(
  117. 'type' => 'textarea',
  118. 'code' => true,
  119. 'name' => 'et_hf_header',
  120. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_header'),
  121. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  122. 'value' => getParam('site_email_html_template_header'),
  123. 'db' => array (
  124. 'pass' => 'Xss',
  125. ),
  126. ),
  127. 'et_hf_footer' => array(
  128. 'type' => 'textarea',
  129. 'code' => true,
  130. 'name' => 'et_hf_footer',
  131. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_footer'),
  132. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  133. 'value' => getParam('site_email_html_template_footer'),
  134. 'db' => array (
  135. 'pass' => 'Xss',
  136. ),
  137. ),
  138. 'save' => array(
  139. 'type' => 'submit',
  140. 'name' => 'save',
  141. 'value' => _t('_adm_pgt_btn_et_hf_submit'),
  142. )
  143. )
  144. );
  145. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  146. $oForm->initChecker();
  147. if($oForm->isSubmittedAndValid()) {
  148. echo $this->submitEtemplatesHtmlOld($oForm);
  149. exit;
  150. }
  151. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  152. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  153. return $oTemplate->parseHtmlByName('polyglot.html', array(
  154. 'content' => $oTemplate->parseHtmlByName('pgt_etemplates_hf.html', array(
  155. 'warning' => '',
  156. 'iframe_id' => $sIFrameId,
  157. 'form' => $oForm->getCode()
  158. )),
  159. 'js_content' => $this->getPageJsCode(array(
  160. 'sCodeMirror' => 'textarea[name=et_hf_header],textarea[name=et_hf_footer]'
  161. ))
  162. ));
  163. }
  164. protected function getEtemplatesHtml()
  165. {
  166. $oTemplate = BxDolStudioTemplate::getInstance();
  167. $sFormId = 'adm-dsg-et-creative-form';
  168. $sIFrameId = 'adm-dsg-et-creative-iframe';
  169. $sContent = '';
  170. $sContent .= getParam('site_email_html_template_header');
  171. $sContent .= $this->sEtcContent;
  172. $sContent .= getParam('site_email_html_template_footer');
  173. $aForm = [
  174. 'form_attrs' => [
  175. 'id' => $sFormId,
  176. 'name' => $sFormId,
  177. 'action' => BX_DOL_URL_STUDIO . 'polyglot.php',
  178. 'method' => 'post',
  179. 'enctype' => 'multipart/form-data',
  180. 'target' => $sIFrameId
  181. ],
  182. 'params' => [
  183. 'db' => [
  184. 'table' => '',
  185. 'key' => '',
  186. 'uri' => '',
  187. 'uri_title' => '',
  188. 'submit_name' => 'save'
  189. ],
  190. ],
  191. 'inputs' => [
  192. 'page' => [
  193. 'type' => 'hidden',
  194. 'name' => 'page',
  195. 'value' => $this->sPage
  196. ],
  197. 'content' => [
  198. 'type' => 'custom',
  199. 'name' => 'content',
  200. 'caption' => '',
  201. 'content' => $oTemplate->parseHtmlByName('pgt_etemplates_creative_fld.html', [
  202. 'html_id' => $this->aHtmlIds['etc_builder_id'],
  203. 'content_html' => $sContent,
  204. 'content_data' => json_encode([
  205. 'pages' => [
  206. ['component' => $sContent]
  207. ]
  208. ])
  209. ]),
  210. 'required' => '0',
  211. 'db' => [
  212. 'pass' => 'XssHtml',
  213. ],
  214. ],
  215. 'save' => [
  216. 'type' => 'submit',
  217. 'name' => 'save',
  218. 'value' => _t('_adm_pgt_btn_et_hf_submit'),
  219. ]
  220. ]
  221. ];
  222. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  223. $oForm->initChecker();
  224. if($oForm->isSubmittedAndValid()) {
  225. echo $this->submitEtemplatesHtml($oForm);
  226. exit;
  227. }
  228. $oTemplate->addJs([
  229. 'grapesjs/grapes.min.js',
  230. 'grapesjs/grapesjs-preset-newsletter.min.js'
  231. ]);
  232. $oTemplate->addCss([
  233. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css'
  234. ]);
  235. return $oTemplate->parseHtmlByName('polyglot.html', [
  236. 'content' => $oTemplate->parseHtmlByName('pgt_etemplates_creative_frm.html', [
  237. 'warning' => '',
  238. 'iframe_id' => $sIFrameId,
  239. 'form' => $oForm->getCode()
  240. ]),
  241. 'js_content' => $this->getPageJsCode()
  242. ]);
  243. }
  244. protected function getGrid($sObjectName)
  245. {
  246. $oGrid = BxDolGrid::getObjectInstance($sObjectName);
  247. if(!$oGrid)
  248. return '';
  249. return BxDolStudioTemplate::getInstance()->parseHtmlByName('polyglot.html', array(
  250. 'content' => $oGrid->getCode(),
  251. 'js_content' => ''
  252. ));
  253. }
  254. }
  255. /** @} */