diff --git a/e107_plugins/news/e_gsitemap.php b/e107_plugins/news/e_gsitemap.php index 578f92f58..6d4ebd601 100644 --- a/e107_plugins/news/e_gsitemap.php +++ b/e107_plugins/news/e_gsitemap.php @@ -101,15 +101,25 @@ class news_gsitemap { $data = $this->getNewsPosts(); + /** @var news_shortcodes $sc */ + $sc = e107::getScBatch('news'); + + e107::getParser()->thumbWidth(1000); + $ret = []; foreach($data as $row) { + $sc->setScVar('news_item', $row); + + $imgUrl = $sc->sc_news_image(['item'=>1, 'type'=>'src']); + $ret[] = [ 'url' => $this->url('news', $row), 'lastmod' => !empty($row['news_modified']) ? $row['news_modified'] : (int) $row['news_datestamp'], 'freq' => 'hourly', - 'priority' => 0.5 + 'priority' => 0.5, + 'image' => (strpos($imgUrl, 'http') === 0) ? $imgUrl : SITEURLBASE.$sc->sc_news_image(['item'=>1, 'type'=>'src']), ]; } diff --git a/gsitemap.php b/gsitemap.php index 33eb848ed..cd194f788 100644 --- a/gsitemap.php +++ b/gsitemap.php @@ -63,7 +63,7 @@ class gsitemap_xml { header('Content-type: application/xml', TRUE); $xml = " - "; + "; if(empty($items)) { @@ -105,10 +105,29 @@ class gsitemap_xml $loc = (strpos($url, 'http') === 0) ? $url : SITEURL.$tp->replaceConstants($url,true); $xml .= " - ".$loc." + ".$loc.""; + + if(!empty($sm[$prefix.'image'])) + { + $imgUrl = $sm[$prefix.'image']; + + if($imgUrl[0] === '/') + { + $imgUrl = ltrim($imgUrl, '/'); + } + + $imgUrl = (strpos($imgUrl, 'http') === 0) ? $imgUrl : SITEURL.$tp->replaceConstants($imgUrl,true); + + $xml .= " + + ".$imgUrl." + "; + } + + $xml .= " ".date('c', (int) $sm[$prefix.'lastmod'])." - ".$sm[$prefix.'freq']." - ".$sm[$prefix.'priority']." + ".$sm[$prefix.'freq']." + ".$sm[$prefix.'priority']." "; }