@@ -30,16 +30,33 @@ class ResultPlugin
30
30
*/
31
31
protected $ scopeConfig ;
32
32
33
+ /**
34
+ * @var bool
35
+ */
36
+ protected $ allowedOnPage ;
37
+
38
+ /**
39
+ * @var \Magento\Store\Model\StoreManagerInterface
40
+ */
41
+ protected $ storeManager ;
42
+
33
43
/**
34
44
* @param \Magento\Framework\App\RequestInterface $request
35
45
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
46
+ * @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
36
47
*/
37
48
public function __construct (
38
49
\Magento \Framework \App \RequestInterface $ request ,
39
- \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig
50
+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
51
+ \Magento \Store \Model \StoreManagerInterface $ storeManager = null
40
52
) {
41
53
$ this ->request = $ request ;
42
54
$ this ->scopeConfig = $ scopeConfig ;
55
+
56
+ $ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
57
+ $ this ->storeManager = $ storeManager ?: $ objectManager ->get (
58
+ \Magento \Store \Model \StoreManagerInterface::class
59
+ );
43
60
}
44
61
45
62
/**
@@ -59,6 +76,10 @@ public function aroundRenderResult(
59
76
return $ result ;
60
77
}
61
78
79
+ if (!$ this ->isAllowedOnPage ()) {
80
+ return $ result ;
81
+ }
82
+
62
83
$ html = $ response ->getBody ();
63
84
$ scripts = [];
64
85
@@ -134,4 +155,76 @@ private function isEnabled()
134
155
135
156
return $ enabled ;
136
157
}
158
+
159
+ /**
160
+ * @return bool
161
+ */
162
+ private function isAllowedOnPage ()
163
+ {
164
+ if (null !== $ this ->allowedOnPage ) {
165
+ return $ this ->allowedOnPage ;
166
+ }
167
+ $ this ->allowedOnPage = false ;
168
+
169
+ $ spPages = $ this ->scopeConfig ->getValue (
170
+ 'mfrocketjavascript/general/disallowed_pages_for_deferred_js ' ,
171
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE
172
+ );
173
+ $ spPages = explode ("\n" , str_replace ("\r" , "\n" , $ spPages ));
174
+
175
+ foreach ($ spPages as $ key => $ path ) {
176
+ $ spPages [$ key ] = trim ($ spPages [$ key ]);
177
+ if (empty ($ spPages [$ key ])) {
178
+ unset($ spPages [$ key ]);
179
+ }
180
+ }
181
+ $ baseUrl = trim ($ this ->storeManager ->getStore ()->getBaseUrl (), '/ ' );
182
+ $ baseUrl = str_replace ('/index.php ' , '' , $ baseUrl );
183
+
184
+ $ currentUrl = $ this ->storeManager ->getStore ()->getCurrentUrl ();
185
+ $ currentUrl = explode ('? ' , $ currentUrl );
186
+ $ currentUrl = trim ($ currentUrl [0 ], '/ ' );
187
+ foreach (['index.php ' , '.php ' , '.html ' ] as $ end ) {
188
+ $ el = mb_strlen ($ end );
189
+ $ cl = mb_strlen ($ currentUrl );
190
+ if (mb_strrpos ($ currentUrl , $ end ) == $ cl - $ el ) {
191
+ $ currentUrl = mb_substr ($ currentUrl , 0 , $ cl - $ el );
192
+ }
193
+ }
194
+ $ currentUrl = str_replace ('/index.php ' , '' , $ currentUrl );
195
+ $ currentUrl = trim ($ currentUrl , '/ ' );
196
+ foreach ($ spPages as $ key => $ path ) {
197
+ $ path = trim ($ path , '/ ' );
198
+
199
+ if (mb_strlen ($ path )) {
200
+ if ('* ' == $ path {0 }) {
201
+ $ subPath = trim ($ path , '*/ ' );
202
+ if (mb_strlen ($ currentUrl ) - mb_strlen ($ subPath ) === mb_strrpos ($ currentUrl , $ subPath )) {
203
+ $ this ->allowedOnPage = true ;
204
+ break ;
205
+ }
206
+ }
207
+
208
+ if ('* ' == $ path {mb_strlen ($ path ) - 1 }) {
209
+ if (0 === mb_strpos ($ currentUrl , $ baseUrl . '/ ' . trim ($ path , '*/ ' ))) {
210
+ $ this ->allowedOnPage = true ;
211
+ break ;
212
+ }
213
+ }
214
+ if ($ currentUrl == $ baseUrl . '/ ' . trim ($ path , '/ ' )) {
215
+ $ this ->allowedOnPage = true ;
216
+ break ;
217
+ }
218
+ } else {
219
+ //homepage
220
+
221
+ if ($ currentUrl == $ baseUrl ) {
222
+ $ this ->allowedOnPage = true ;
223
+ break ;
224
+ }
225
+ }
226
+ }
227
+
228
+ return $ this ->allowedOnPage = !$ this ->allowedOnPage ;
229
+ }
137
230
}
0 commit comments