Skip to content

Commit

Permalink
Compatible PHP8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
magiccart committed Nov 10, 2022
1 parent 6a8626b commit 44b5a1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getConfigModule($cfg='', $value=null)
{
$values = $this->configModule;
if( !$cfg ) return $values;
$config = explode('/', $cfg);
$config = explode('/', (string) $cfg);
$end = count($config) - 1;
foreach ($config as $key => $vl) {
if( isset($values[$vl]) ){
Expand Down
42 changes: 21 additions & 21 deletions Plugin/SpeedOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public function beforeSendResponse(Http $response)
$exclude = $this->helper->getConfigModule('general/exclude_img');
// $exclude = 'product-image-photo';
if($exclude){
$exclude = str_replace(' ', '', $exclude);
$this->exclude = explode(',', $exclude);
$exclude = str_replace(' ', '', (string) $exclude);
$this->exclude = explode(',', (string) $exclude);
}
$placeholder = $this->helper->getConfigModule('general/placeholder');
// $placeholder = false;
Expand Down Expand Up @@ -146,9 +146,9 @@ public function addBodyClass( $content, $class )
'/<body([\s\S]*?)(?:class="(.*?)")([\s\S]*?)?([^>]*)>/',
function($match) use ($class) {
if($match[2]){
return $lazy = str_replace('class="', 'class="' . $class . ' ', $match[0]);
return $lazy = str_replace('class="', 'class="' . $class . ' ', (string) $match[0]);
}else {
return str_replace('<body ', '<body class="' . $class . '" ', $match[0]);
return str_replace('<body ', '<body class="' . $class . '" ', (string) $match[0]);
}
},
$content
Expand Down Expand Up @@ -188,11 +188,11 @@ public function addLazyloadPlaceholder( $content, $addJs=false )
$content = preg_replace_callback_array(
[
'/<img([^>]+?)width=[\'"]?([^\'"\s>]+)[\'"]([^>]+?)height=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>/' => function ($match) use ($placeholder) {
$holder = str_replace(['$width', '$height'], [$match[2], $match[4]], $placeholder);
$holder = str_replace(['$width', '$height'], [$match[2], $match[4]], (string) $placeholder);
return $this->addLazyloadImage($match[0], $holder);
},
'/<img([^>]+?)height=[\'"]?([^\'"\s>]+)[\'"]([^>]+?)width=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>/' => function ($match) use ($placeholder) {
$holder = str_replace(['$width', '$height'], [$match[4], $match[2]], $placeholder);
$holder = str_replace(['$width', '$height'], [$match[4], $match[2]], (string) $placeholder);
return $this->addLazyloadImage($match[0], $holder);
}
],
Expand All @@ -206,7 +206,7 @@ public function addLazyloadPlaceholder( $content, $addJs=false )

public function isExclude($class)
{
if(is_string($class)) $class = explode(' ', $class);
if(is_string($class)) $class = explode(' ', (string) $class);
$excludeExist = array_intersect($this->exclude, $class);
return !empty($excludeExist);
}
Expand All @@ -221,12 +221,12 @@ function($match) use ($placeholder) {
if(stripos($match[0], ' data-src="') !== false) return $match[0];
if(stripos($match[0], ' class="') !== false){
if( $this->isExclude($match[1]) ) return $match[0];
$lazy = str_replace(' class="', ' class="lazyload ', $match[0]);
$lazy = str_replace(' class="', ' class="lazyload ', (string) $match[0]);
if(stripos($match[1], 'background-image') !== false){
$lazy = str_replace('<img ', '<source ', $lazy);
}
}else {
$lazy = str_replace('<img ', '<img class="lazyload" ', $match[0]);
$lazy = str_replace('<img ', '<img class="lazyload" ', (string) $match[0]);
if(stripos($match[1], 'background-image') !== false){
$lazy = str_replace('<img ', '<source ', $lazy);
}
Expand All @@ -235,7 +235,7 @@ function($match) use ($placeholder) {
/* break if exist data-src */
// if(strpos($lazy, ' data-src="')) return $lazy;

return str_replace(' src="', ' src="' .$placeholder. '" data-src="', $lazy);
return str_replace(' src="', ' src="' .$placeholder. '" data-src="', (string) $lazy);
},
$content
);
Expand All @@ -251,15 +251,15 @@ function($match) use ($placeholder) {
if(stripos($match[0], ' data-src=\"') !== false) return $match[0];
if(stripos($match[0], ' class="') !== false){
if( $this->isExclude($match[1]) ) return $match[0];
$lazy = str_replace(' class=\"', ' class=\"lazyload ', $match[0]);
$lazy = str_replace(' class=\"', ' class=\"lazyload ', (string) $match[0]);
}else {
$lazy = str_replace('<img ', '<img class=\"lazyload\" ', $match[0]);
$lazy = str_replace('<img ', '<img class=\"lazyload\" ', (string) $match[0]);
}

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

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

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

Expand Down Expand Up @@ -347,8 +347,8 @@ public function minifyHtml($content)
$minHtml = $content;

// Searching textarea and pre
preg_match_all('#\<textarea.*\>.*\<\/textarea\>#Uis', $minHtml, $foundTxt);
preg_match_all('#\<pre.*\>.*\<\/pre\>#Uis', $minHtml, $foundPre);
preg_match_all('#\<textarea.*\>.*\<\/textarea\>#Uis', (string) $minHtml, $foundTxt);
preg_match_all('#\<pre.*\>.*\<\/pre\>#Uis', (string) $minHtml, $foundPre);

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

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

Expand All @@ -447,8 +447,8 @@ public function getHtmlClean($html)
}
if(!$excludeHtml) return $html;

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

Expand Down Expand Up @@ -488,13 +488,13 @@ public function cleanHtml($html, $regex)
public function isTablet()
{
$userAgent = $this->httpHeader->getHttpUserAgent();
return preg_match('/iPad|iPad.*Mobile/i', $userAgent);
return preg_match('/iPad|iPad.*Mobile/i', (string) $userAgent);
}

public function isNoJs()
{
$userAgent = $this->httpHeader->getHttpUserAgent();
return preg_match('/Chrome-Lighthouse|PingdomPageSpeed|PingdomPageSpeed/i', $userAgent);
return preg_match('/Chrome-Lighthouse|PingdomPageSpeed|PingdomPageSpeed/i', (string) $userAgent);
}

public function isMobile()
Expand Down

0 comments on commit 44b5a1f

Please sign in to comment.