From ec2c2cf4e0b784a886f1deff7841aaf3809478b1 Mon Sep 17 00:00:00 2001 From: horst-n Date: Sat, 27 Apr 2019 10:27:07 +0200 Subject: [PATCH] cleaning minor things and whitespaces and added "Options Hierarchy" to the getDebugInfo method --- wire/core/Pageimage.php | 48 +++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/wire/core/Pageimage.php b/wire/core/Pageimage.php index b89b3e3c..50b4d619 100644 --- a/wire/core/Pageimage.php +++ b/wire/core/Pageimage.php @@ -186,13 +186,13 @@ class Pageimage extends Pagefile { * @return string * */ - public function urlWebp() { - if(!$this->hasWebp()) { - return '#'; // @Ryan: what should be returned for none existing webp variations here? - } - $path_parts = pathinfo($this->url); - $webpUrl = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp'; - return $webpUrl; + public function webpUrl() { + if(!$this->hasWebp()) { + return '#'; // @Ryan: what should be returned for none existing webp variations here? + } + $path_parts = pathinfo($this->url); + $webpUrl = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp'; + return $webpUrl; } /** @@ -202,9 +202,9 @@ class Pageimage extends Pagefile { * */ public function hasWebp() { - $path_parts = pathinfo($this->filename()); - $webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp'; - return is_readable($webpFilename); + $path_parts = pathinfo($this->filename()); + $webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp'; + return is_readable($webpFilename); } /** @@ -426,11 +426,11 @@ class Pageimage extends Pagefile { case 'hasWebp': $value = $this->hasWebp(); break; - case 'urlWebp': - case 'srcWebp': case 'webpUrl': case 'webpSrc': - $value = $this->urlWebp(); + case 'urlWebp': + case 'srcWebp': + $value = $this->webpUrl(); break; default: $value = parent::get($key); @@ -790,8 +790,8 @@ class Pageimage extends Pagefile { // filenameUnvalidated is temporary filename used for resize $tempDir = $this->pagefiles->page->filesManager()->getTempPath(); $filenameUnvalidated = $tempDir . $basename; - $path_parts = pathinfo($filenameUnvalidated); - $filenameUnvalidatedWebp = $tempDir . $path_parts['filename'] . '.webp'; + $path_parts = pathinfo($filenameUnvalidated); + $filenameUnvalidatedWebp = $tempDir . $path_parts['filename'] . '.webp'; if($exists && $options['forceNew']) $this->wire('files')->unlink($filenameFinal, true); if(file_exists($filenameFinalWebp) && $options['forceNew']) $this->wire('files')->unlink($filenameFinalWebp, true); @@ -1642,8 +1642,9 @@ class Pageimage extends Pagefile { if($success) $deletedFiles[] = $filename; // Also remove WebP variation, if there exist one - $webp = dirname($filename) . '/' . str_replace(array('.jpg', '.jpeg', '.png', '.gif'), '.webp', basename($filename)); - if(!is_file($webp)) continue; + $path_parts = pathinfo($filenameFinal); + $webp = dirname($filename) . '/' . $path_parts['filename'] . '.webp'; + if(!is_file($webp)) continue; if($options['dryRun']) { $success = true; } else { @@ -1928,10 +1929,16 @@ class Pageimage extends Pagefile { $info['neededEngineSupport'] = $is->getImageInfo(); $info['installedEngines'] = array_merge($is->getEngines(), array('ImageSizerEngineGD')); $info['selectedEngine'] = $is->getEngine(); - $info['individualOptions'] = $options; + $info['Options Hierarchy'] = array(); + $info['Options Hierarchy']['imageSizerOptions'] = $this->wire('config')->imageSizerOptions; + $info['Options Hierarchy']['individualOptions'] = $options; + $info['Options Hierarchy']['finalOptions'] = $is->getOptions(); + if(!$returnAsString) { return $info; } + + // make a beautyfied var_dump ob_start(); var_dump($info); $content = ob_get_contents(); @@ -1951,10 +1958,13 @@ class Pageimage extends Pagefile { $content = preg_replace('#^((\s*).*){$#m', "\\1\n\\2{", $content); $content = str_replace(array('
', '
'), '', $content); if(isset($_SERVER['HTTP_HOST'])) { - $return = "
{$content}
"; + // build output for HTML + $return = "
{$content}
"; } else { + // output for Console $return = $content; } + return $return; }