BxBaseStudioPolyglot.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. protected function getEtemplatesHtml()
  85. {
  86. return $this->{'_getEtemplatesHtml' . ($this->isEtEditor() ? 'Editor' : 'Form')}();
  87. }
  88. protected function _getEtemplatesHtmlForm()
  89. {
  90. $oTemplate = BxDolStudioTemplate::getInstance();
  91. $sFormId = 'adm-dsg-et-hf-form';
  92. $sIFrameId = 'adm-dsg-et-hf-iframe';
  93. $aForm = [
  94. 'form_attrs' => [
  95. 'id' => $sFormId,
  96. 'name' => $sFormId,
  97. 'action' => BX_DOL_URL_STUDIO . 'polyglot.php',
  98. 'method' => 'post',
  99. 'enctype' => 'multipart/form-data',
  100. 'target' => $sIFrameId
  101. ],
  102. 'params' => [
  103. 'db' => [
  104. 'table' => '',
  105. 'key' => '',
  106. 'uri' => '',
  107. 'uri_title' => '',
  108. 'submit_name' => 'save'
  109. ],
  110. ],
  111. 'inputs' => [
  112. 'page' => [
  113. 'type' => 'hidden',
  114. 'name' => 'page',
  115. 'value' => $this->sPage
  116. ],
  117. 'editor' => [
  118. 'type' => 'switcher',
  119. 'name' => 'editor',
  120. 'caption' => _t('_adm_pgt_btn_et_hf_editor'),
  121. 'info' => '',
  122. 'value' => 'on',
  123. 'checked' => $this->isEtEditor(),
  124. 'attrs' => [
  125. 'onchange' => $this->getPageJsObject() . '.enableEditor(this)'
  126. ]
  127. ],
  128. 'et_hf_header' => [
  129. 'type' => 'textarea',
  130. 'code' => true,
  131. 'name' => 'et_hf_header',
  132. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_header'),
  133. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  134. 'value' => getParam('site_email_html_template_header'),
  135. 'db' => [
  136. 'pass' => 'Xss',
  137. ],
  138. ],
  139. 'et_hf_footer' => [
  140. 'type' => 'textarea',
  141. 'code' => true,
  142. 'name' => 'et_hf_footer',
  143. 'caption' => _t('_adm_stg_cpt_option_site_email_html_template_footer'),
  144. 'info' => _t('_adm_pgt_txt_et_hf_inf'),
  145. 'value' => getParam('site_email_html_template_footer'),
  146. 'db' => [
  147. 'pass' => 'Xss',
  148. ],
  149. ],
  150. 'save' => [
  151. 'type' => 'submit',
  152. 'name' => 'save',
  153. 'value' => _t('_adm_pgt_btn_et_hf_submit'),
  154. ]
  155. ]
  156. ];
  157. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  158. $oForm->initChecker();
  159. if($oForm->isSubmittedAndValid()) {
  160. echo $this->submitEtemplatesHtmlOld($oForm);
  161. exit;
  162. }
  163. /*
  164. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  165. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  166. */
  167. return $oTemplate->parseHtmlByName('polyglot.html', array(
  168. 'content' => $oTemplate->parseHtmlByName('pgt_etemplates_hf.html', array(
  169. 'warning' => '',
  170. 'iframe_id' => $sIFrameId,
  171. 'form' => $oForm->getCode()
  172. )),
  173. 'js_content' => $this->getPageJsCode(array(
  174. 'sCodeMirror' => 'textarea[name=et_hf_header],textarea[name=et_hf_footer]'
  175. ))
  176. ));
  177. }
  178. protected function _getEtemplatesHtmlEditor()
  179. {
  180. $oTemplate = BxDolStudioTemplate::getInstance();
  181. $sFormId = 'adm-dsg-et-creative-form';
  182. $sIFrameId = 'adm-dsg-et-creative-iframe';
  183. $sContent = '';
  184. $sContent .= getParam('site_email_html_template_header');
  185. $sContent .= $this->sEtcContent;
  186. $sContent .= getParam('site_email_html_template_footer');
  187. $aForm = [
  188. 'form_attrs' => [
  189. 'id' => $sFormId,
  190. 'name' => $sFormId,
  191. 'action' => BX_DOL_URL_STUDIO . 'polyglot.php',
  192. 'method' => 'post',
  193. 'enctype' => 'multipart/form-data',
  194. 'target' => $sIFrameId
  195. ],
  196. 'params' => [
  197. 'db' => [
  198. 'table' => '',
  199. 'key' => '',
  200. 'uri' => '',
  201. 'uri_title' => '',
  202. 'submit_name' => 'save'
  203. ],
  204. ],
  205. 'inputs' => [
  206. 'page' => [
  207. 'type' => 'hidden',
  208. 'name' => 'page',
  209. 'value' => $this->sPage
  210. ],
  211. 'editor' => [
  212. 'type' => 'switcher',
  213. 'name' => 'editor',
  214. 'caption' => _t('_adm_pgt_btn_et_hf_editor'),
  215. 'info' => '',
  216. 'value' => 'on',
  217. 'checked' => $this->isEtEditor(),
  218. 'attrs' => [
  219. 'onchange' => $this->getPageJsObject() . '.enableEditor(this)'
  220. ]
  221. ],
  222. 'content' => [
  223. 'type' => 'custom',
  224. 'name' => 'content',
  225. 'caption' => '',
  226. 'content' => $oTemplate->parseHtmlByName('pgt_etemplates_creative_fld.html', [
  227. 'html_id' => $this->aHtmlIds['etc_builder_id'],
  228. 'content_html' => $sContent,
  229. 'content_data' => json_encode([
  230. 'pages' => [
  231. ['component' => $sContent]
  232. ]
  233. ])
  234. ]),
  235. 'required' => '0',
  236. 'db' => [
  237. 'pass' => 'XssHtml',
  238. ],
  239. ],
  240. 'save' => [
  241. 'type' => 'submit',
  242. 'name' => 'save',
  243. 'value' => _t('_adm_pgt_btn_et_hf_submit'),
  244. ]
  245. ]
  246. ];
  247. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  248. $oForm->initChecker();
  249. if($oForm->isSubmittedAndValid()) {
  250. echo $this->submitEtemplatesHtml($oForm);
  251. exit;
  252. }
  253. $oTemplate->addJs([
  254. 'grapesjs/grapes.min.js',
  255. 'grapesjs/grapesjs-preset-newsletter.min.js'
  256. ]);
  257. $oTemplate->addCss([
  258. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css'
  259. ]);
  260. return $oTemplate->parseHtmlByName('polyglot.html', [
  261. 'content' => $oTemplate->parseHtmlByName('pgt_etemplates_creative_frm.html', [
  262. 'warning' => '',
  263. 'iframe_id' => $sIFrameId,
  264. 'form' => $oForm->getCode()
  265. ]),
  266. 'js_content' => $this->getPageJsCode()
  267. ]);
  268. }
  269. protected function getGrid($sObjectName)
  270. {
  271. $oGrid = BxDolGrid::getObjectInstance($sObjectName);
  272. if(!$oGrid)
  273. return '';
  274. return BxDolStudioTemplate::getInstance()->parseHtmlByName('polyglot.html', array(
  275. 'content' => $oGrid->getCode(),
  276. 'js_content' => ''
  277. ));
  278. }
  279. protected function isEtEditor()
  280. {
  281. return getParam($this->sEtSettingEditor) == 'on';
  282. }
  283. }
  284. /** @} */