Skip to content

Commit 44b5a1f

Browse files
committed
Compatible PHP8.x
1 parent 6a8626b commit 44b5a1f

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getConfigModule($cfg='', $value=null)
4040
{
4141
$values = $this->configModule;
4242
if( !$cfg ) return $values;
43-
$config = explode('/', $cfg);
43+
$config = explode('/', (string) $cfg);
4444
$end = count($config) - 1;
4545
foreach ($config as $key => $vl) {
4646
if( isset($values[$vl]) ){

Plugin/SpeedOptimizer.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public function beforeSendResponse(Http $response)
104104
$exclude = $this->helper->getConfigModule('general/exclude_img');
105105
// $exclude = 'product-image-photo';
106106
if($exclude){
107-
$exclude = str_replace(' ', '', $exclude);
108-
$this->exclude = explode(',', $exclude);
107+
$exclude = str_replace(' ', '', (string) $exclude);
108+
$this->exclude = explode(',', (string) $exclude);
109109
}
110110
$placeholder = $this->helper->getConfigModule('general/placeholder');
111111
// $placeholder = false;
@@ -146,9 +146,9 @@ public function addBodyClass( $content, $class )
146146
'/<body([\s\S]*?)(?:class="(.*?)")([\s\S]*?)?([^>]*)>/',
147147
function($match) use ($class) {
148148
if($match[2]){
149-
return $lazy = str_replace('class="', 'class="' . $class . ' ', $match[0]);
149+
return $lazy = str_replace('class="', 'class="' . $class . ' ', (string) $match[0]);
150150
}else {
151-
return str_replace('<body ', '<body class="' . $class . '" ', $match[0]);
151+
return str_replace('<body ', '<body class="' . $class . '" ', (string) $match[0]);
152152
}
153153
},
154154
$content
@@ -188,11 +188,11 @@ public function addLazyloadPlaceholder( $content, $addJs=false )
188188
$content = preg_replace_callback_array(
189189
[
190190
'/<img([^>]+?)width=[\'"]?([^\'"\s>]+)[\'"]([^>]+?)height=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>/' => function ($match) use ($placeholder) {
191-
$holder = str_replace(['$width', '$height'], [$match[2], $match[4]], $placeholder);
191+
$holder = str_replace(['$width', '$height'], [$match[2], $match[4]], (string) $placeholder);
192192
return $this->addLazyloadImage($match[0], $holder);
193193
},
194194
'/<img([^>]+?)height=[\'"]?([^\'"\s>]+)[\'"]([^>]+?)width=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>/' => function ($match) use ($placeholder) {
195-
$holder = str_replace(['$width', '$height'], [$match[4], $match[2]], $placeholder);
195+
$holder = str_replace(['$width', '$height'], [$match[4], $match[2]], (string) $placeholder);
196196
return $this->addLazyloadImage($match[0], $holder);
197197
}
198198
],
@@ -206,7 +206,7 @@ public function addLazyloadPlaceholder( $content, $addJs=false )
206206

207207
public function isExclude($class)
208208
{
209-
if(is_string($class)) $class = explode(' ', $class);
209+
if(is_string($class)) $class = explode(' ', (string) $class);
210210
$excludeExist = array_intersect($this->exclude, $class);
211211
return !empty($excludeExist);
212212
}
@@ -221,12 +221,12 @@ function($match) use ($placeholder) {
221221
if(stripos($match[0], ' data-src="') !== false) return $match[0];
222222
if(stripos($match[0], ' class="') !== false){
223223
if( $this->isExclude($match[1]) ) return $match[0];
224-
$lazy = str_replace(' class="', ' class="lazyload ', $match[0]);
224+
$lazy = str_replace(' class="', ' class="lazyload ', (string) $match[0]);
225225
if(stripos($match[1], 'background-image') !== false){
226226
$lazy = str_replace('<img ', '<source ', $lazy);
227227
}
228228
}else {
229-
$lazy = str_replace('<img ', '<img class="lazyload" ', $match[0]);
229+
$lazy = str_replace('<img ', '<img class="lazyload" ', (string) $match[0]);
230230
if(stripos($match[1], 'background-image') !== false){
231231
$lazy = str_replace('<img ', '<source ', $lazy);
232232
}
@@ -235,7 +235,7 @@ function($match) use ($placeholder) {
235235
/* break if exist data-src */
236236
// if(strpos($lazy, ' data-src="')) return $lazy;
237237

238-
return str_replace(' src="', ' src="' .$placeholder. '" data-src="', $lazy);
238+
return str_replace(' src="', ' src="' .$placeholder. '" data-src="', (string) $lazy);
239239
},
240240
$content
241241
);
@@ -251,15 +251,15 @@ function($match) use ($placeholder) {
251251
if(stripos($match[0], ' data-src=\"') !== false) return $match[0];
252252
if(stripos($match[0], ' class="') !== false){
253253
if( $this->isExclude($match[1]) ) return $match[0];
254-
$lazy = str_replace(' class=\"', ' class=\"lazyload ', $match[0]);
254+
$lazy = str_replace(' class=\"', ' class=\"lazyload ', (string) $match[0]);
255255
}else {
256-
$lazy = str_replace('<img ', '<img class=\"lazyload\" ', $match[0]);
256+
$lazy = str_replace('<img ', '<img class=\"lazyload\" ', (string) $match[0]);
257257
}
258258

259259
/* break if exist data-src */
260260
// if(strpos($lazy, ' data-src=\"')) return $lazy;
261261

262-
return str_replace(' src=\"', ' src=\"' . $placeholder . '\" data-src=\"', $lazy);
262+
return str_replace(' src=\"', ' src=\"' . $placeholder . '\" data-src=\"', (string) $lazy);
263263
},
264264
$content
265265
);
@@ -268,7 +268,7 @@ function($match) use ($placeholder) {
268268
/* Not Placeholder so can't keep layout original while loading */
269269
public function addLazyloadAll( $content, $addJs=false )
270270
{
271-
$placeholder = str_replace(['$width', '$height'], [1, 1], $this->placeholder);
271+
$placeholder = str_replace(['$width', '$height'], [1, 1], (string) $this->placeholder);
272272

273273
$content = $this->addLazyloadImage($content, $placeholder);
274274

@@ -347,8 +347,8 @@ public function minifyHtml($content)
347347
$minHtml = $content;
348348

349349
// Searching textarea and pre
350-
preg_match_all('#\<textarea.*\>.*\<\/textarea\>#Uis', $minHtml, $foundTxt);
351-
preg_match_all('#\<pre.*\>.*\<\/pre\>#Uis', $minHtml, $foundPre);
350+
preg_match_all('#\<textarea.*\>.*\<\/textarea\>#Uis', (string) $minHtml, $foundTxt);
351+
preg_match_all('#\<pre.*\>.*\<\/pre\>#Uis', (string) $minHtml, $foundPre);
352352

353353
// replacing both with <textarea>$index</textarea> / <pre>$index</pre>
354354
$minHtml = str_replace($foundTxt[0], array_map(function($el){ return '<textarea>'.$el.'</textarea>'; }, array_keys($foundTxt[0])), $minHtml);
@@ -434,7 +434,7 @@ public function getTheme()
434434
public function getHtmlClean($html)
435435
{
436436
/* break process if html have many tag body */
437-
if( preg_match_all("/<body.*\/body>/s", $html, $matches) > 1) return $html;
437+
if( preg_match_all("/<body.*\/body>/s", (string) $html, $matches) > 1) return $html;
438438

439439
/* break process if html have many tag body */
440440

@@ -447,8 +447,8 @@ public function getHtmlClean($html)
447447
}
448448
if(!$excludeHtml) return $html;
449449

450-
$excludeHtml = str_replace(' ', '', $excludeHtml);
451-
$this->excludeHtml = explode(',', $excludeHtml);
450+
$excludeHtml = str_replace(' ', '', (string) $excludeHtml);
451+
$this->excludeHtml = explode(',', (string) $excludeHtml);
452452
$html = $this->cleanHtml($html, "~<\s*\bheader\b[^>]*>(.*?)<\s*\/\s*header\s*>~is");
453453
$html = $this->cleanHtml($html, "~<\s*\bmain\b[^>]*>(.*?)<\s*\/\s*main\s*>~is");
454454

@@ -488,13 +488,13 @@ public function cleanHtml($html, $regex)
488488
public function isTablet()
489489
{
490490
$userAgent = $this->httpHeader->getHttpUserAgent();
491-
return preg_match('/iPad|iPad.*Mobile/i', $userAgent);
491+
return preg_match('/iPad|iPad.*Mobile/i', (string) $userAgent);
492492
}
493493

494494
public function isNoJs()
495495
{
496496
$userAgent = $this->httpHeader->getHttpUserAgent();
497-
return preg_match('/Chrome-Lighthouse|PingdomPageSpeed|PingdomPageSpeed/i', $userAgent);
497+
return preg_match('/Chrome-Lighthouse|PingdomPageSpeed|PingdomPageSpeed/i', (string) $userAgent);
498498
}
499499

500500
public function isMobile()

0 commit comments

Comments
 (0)