11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2013 Adobe
4+ * All Rights Reserved .
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Newsletter \Block \Adminhtml \Template ;
79
10+ use Magento \Backend \Block \Template \Context ;
11+ use Magento \Backend \Block \Widget ;
12+ use Magento \Framework \App \ObjectManager ;
13+ use Magento \Framework \Filter \Input \MaliciousCode ;
14+ use Magento \Framework \Profiler ;
15+ use Magento \Newsletter \Model \TemplateFactory ;
16+ use Magento \Newsletter \Model \Template ;
17+ use Magento \Newsletter \Model \SubscriberFactory ;
18+
819/**
920 * Newsletter template preview block
1021 *
1122 * @api
1223 * @since 100.0.2
1324 */
14- class Preview extends \ Magento \ Backend \ Block \ Widget
25+ class Preview extends Widget
1526{
1627 /**
1728 * Name for profiler
@@ -21,30 +32,39 @@ class Preview extends \Magento\Backend\Block\Widget
2132 protected $ profilerName = "newsletter_template_proccessing " ;
2233
2334 /**
24- * @var \Magento\Newsletter\Model\ TemplateFactory
35+ * @var TemplateFactory
2536 */
2637 protected $ _templateFactory ;
2738
2839 /**
29- * @var \Magento\Newsletter\Model\ SubscriberFactory
40+ * @var SubscriberFactory
3041 */
3142 protected $ _subscriberFactory ;
3243
3344 /**
34- * @param \Magento\Backend\Block\Template\Context $context
35- * @param \Magento\Newsletter\Model\TemplateFactory $templateFactory
36- * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
45+ * @var MaliciousCode
46+ */
47+ protected $ maliciousCode ;
48+
49+ /**
50+ * @param Context $context
51+ * @param TemplateFactory $templateFactory
52+ * @param SubscriberFactory $subscriberFactory
3753 * @param array $data
54+ * @param ?MaliciousCode $maliciousCode
3855 */
3956 public function __construct (
40- \Magento \Backend \Block \Template \Context $ context ,
41- \Magento \Newsletter \Model \TemplateFactory $ templateFactory ,
42- \Magento \Newsletter \Model \SubscriberFactory $ subscriberFactory ,
43- array $ data = []
57+ Context $ context ,
58+ TemplateFactory $ templateFactory ,
59+ SubscriberFactory $ subscriberFactory ,
60+ array $ data = [],
61+ ?MaliciousCode $ maliciousCode = null
4462 ) {
4563 $ this ->_templateFactory = $ templateFactory ;
4664 $ this ->_subscriberFactory = $ subscriberFactory ;
4765 parent ::__construct ($ context , $ data );
66+ $ this ->maliciousCode = $ maliciousCode ?:
67+ ObjectManager::getInstance ()->get (MaliciousCode::class);
4868 }
4969
5070 /**
@@ -61,13 +81,12 @@ protected function _toHtml()
6181 $ this ->loadTemplate ($ template , $ id );
6282 } else {
6383 $ previewData = $ this ->getPreviewData ();
64-
6584 $ template ->setTemplateType ($ previewData ['type ' ]);
6685 $ template ->setTemplateText ($ previewData ['text ' ]);
6786 $ template ->setTemplateStyles ($ previewData ['styles ' ]);
6887 }
6988
70- \ Magento \ Framework \ Profiler::start ($ this ->profilerName );
89+ Profiler::start ($ this ->profilerName );
7190 $ vars = [];
7291
7392 $ vars ['subscriber ' ] = $ this ->_subscriberFactory ->create ();
@@ -77,20 +96,19 @@ protected function _toHtml()
7796 $ vars ['subscriber_data ' ]['unsubscription_link ' ] = $ vars ['subscriber ' ] ?
7897 $ vars ['subscriber ' ]->getUnsubscriptionLink () :
7998 null ;
80-
8199 $ template ->emulateDesign ($ this ->getStoreId ());
82100 $ templateProcessed = $ this ->_appState ->emulateAreaCode (
83- \ Magento \ Newsletter \ Model \ Template::DEFAULT_DESIGN_AREA ,
101+ Template::DEFAULT_DESIGN_AREA ,
84102 [$ template , 'getProcessedTemplate ' ],
85103 [$ vars ]
86104 );
87105 $ template ->revertDesign ();
88-
106+ $ templateProcessed = $ this -> maliciousCode -> filter ( $ templateProcessed );
89107 if ($ template ->isPlain ()) {
90108 $ templateProcessed = "<pre> " . $ this ->escapeHtml ($ templateProcessed ) . "</pre> " ;
91109 }
92110
93- \ Magento \ Framework \ Profiler::stop ($ this ->profilerName );
111+ Profiler::stop ($ this ->profilerName );
94112
95113 return $ templateProcessed ;
96114 }
@@ -147,11 +165,11 @@ protected function getStoreId()
147165 /**
148166 * Return template
149167 *
150- * @param \Magento\Newsletter\Model\ Template $template
168+ * @param Template $template
151169 * @param string $id
152170 * @return $this
153171 */
154- protected function loadTemplate (\ Magento \ Newsletter \ Model \ Template $ template , $ id )
172+ protected function loadTemplate (Template $ template , $ id )
155173 {
156174 $ template ->load ($ id );
157175 return $ this ;
0 commit comments