BxBaseStudioPolyglot.php 9.5 KB

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