diff --git a/core/core.php b/core/core.php index 060fdc70..61c925d3 100644 --- a/core/core.php +++ b/core/core.php @@ -601,6 +601,27 @@ class common { } } + /** + * Récupérer une copie d'écran du site Web pour le tag image si le fichier n'existe pas. + * En local, copie du site décran de ZwiiCMS + */ + public function makeImageTag () { + if (!file_exists('site/file/source/screenshot.png')) + { + 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&key=AIzaSyBqIP3mGvATby3mU_Xn-UoZjbVoem6MfBI'); + $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( 'site/file/source/screenshot.png',$data); + } + } + /** * Accède aux données * @param array $keys Clé(s) des données @@ -1998,6 +2019,7 @@ class layout extends common { } + /** * Affiche la notification */ diff --git a/core/module/config/config.php b/core/module/config/config.php index b122e486..bc7ced0b 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -142,6 +142,7 @@ class config extends common { 20 => '20 articles' ]; + /** * Sauvegarde des données */ @@ -171,27 +172,30 @@ class config extends common { * Réalise une copie d'écran * https://www.codexworld.com/capture-screenshot-website-url-php-google-api/ */ - public function metaimage() { - // fonction désactivée pour un site local - if ( strpos(helper::baseUrl(false),'localhost') === 0 OR 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&key=AIzaSyA_JOJidlWFgEiyxTlSGi2_fORgYsCZFtA'); - $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( helper::baseUrl(false) . '/site/file/source/screenshot.png',$data); + public function configmetaimage() { + // fonction désactivée pour un site local + 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); } - // Valeurs en sortie - $this->addOutput([ - 'notification' => 'Image tag réinitialisée', - 'redirect' => helper::baseUrl() . 'config', - 'state' => true - ]); - } + $googlePagespeedData = file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='. $site .'&screenshot=true&key=AIzaSyA_JOJidlWFgEiyxTlSGi2_fORgYsCZFtA'); + $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( 'site/file/source/screenshot.png',$data); + + // Valeurs en sortie + $this->addOutput([ + 'notification' => 'Image tag réinitialisée', + 'redirect' => helper::baseUrl() . 'config', + 'state' => true + ]); } + + /** * Configuration */ diff --git a/core/module/config/view/index/index.php b/core/module/config/view/index/index.php index a292993b..704eb23b 100755 --- a/core/module/config/view/index/index.php +++ b/core/module/config/view/index/index.php @@ -1,3 +1,4 @@ +makeImageTag(); ?>
' /> -
' /> +
Cette copie d'écran est nécessaire aux partages sur les réseaux sociaux. Elle est régénérée lorsque le fichier screenshot.png est effacé du gestionnaire de fichiers.
+