diff --git a/core/core.php b/core/core.php index a86cfc87..9d546589 100644 --- a/core/core.php +++ b/core/core.php @@ -32,7 +32,7 @@ class common { const TEMP_DIR = 'site/tmp/'; // Numéro de version - const ZWII_VERSION = '9.1.11'; + const ZWII_VERSION = '9.1.12'; public static $actions = []; public static $coreModuleIds = [ @@ -349,13 +349,15 @@ class common { if (!file_exists(self::FILE_DIR.'source/screenshot.png')) { if ( strpos(helper::baseUrl(false),'localhost') == 0 AND strpos(helper::baseUrl(false),'127.0.0.1') == 0) { - $googlePagespeedData = file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='. helper::baseUrl(false) .'&screenshot=true'); - $googlePagespeedData = json_decode($googlePagespeedData, true); - $screenshot = $googlePagespeedData['screenshot']['data']; - $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); - $data = 'data:image/jpeg;base64,'.$screenshot; - $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data)); - file_put_contents( self::FILE_DIR.'source/screenshot.png',$data); + $googlePagespeedData = @file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='. helper::baseUrl(false) .'&screenshot=true'); + if ($googlePagespeedData !== false) { + $googlePagespeedData = json_decode($googlePagespeedData, true); + $screenshot = $googlePagespeedData['screenshot']['data']; + $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); + $data = 'data:image/jpeg;base64,'.$screenshot; + $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data)); + file_put_contents( self::FILE_DIR.'source/screenshot.png',$data); + } } } } diff --git a/core/module/config/config.php b/core/module/config/config.php index 39e8ee81..63d392d8 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -230,20 +230,26 @@ class config extends common { if ( strpos(helper::baseUrl(false),'localhost') > 0 OR strpos(helper::baseUrl(false),'127.0.0.1') > 0) { $site = 'https://zwiicms.com/'; } else { $site = helper::baseUrl(false); } - - $googlePagespeedData = file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='. $site .'&screenshot=true'); - $googlePagespeedData = json_decode($googlePagespeedData, true); - $screenshot = $googlePagespeedData['screenshot']['data']; - $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); - $data = 'data:image/jpeg;base64,'.$screenshot; - $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data)); - file_put_contents( self::FILE_DIR.'source/screenshot.png',$data); + + $success= false; + $googlePagespeedData = @file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='. $site .'&screenshot=true'); + if ($googlePagespeedData !== false) { + $googlePagespeedData = json_decode($googlePagespeedData, true); + $screenshot = $googlePagespeedData['screenshot']['data']; + $screenshot = str_replace(array('_','-'),array('/','+'),$screenshot); + $data = 'data:image/jpeg;base64,'.$screenshot; + $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data)); + // Effacer la miniature + unlink (self::FILE_DIR.'thumb/screenshot.png'); + file_put_contents( self::FILE_DIR.'source/screenshot.png',$data); + $success =true; + } // Valeurs en sortie $this->addOutput([ - 'notification' => 'Image tag réinitialisée', + 'notification' => $success === true ? 'Image tag réinitialisée' : "Erreur : image tag non créée", 'redirect' => helper::baseUrl() . 'config', - 'state' => true + 'state' => $success ]); }