mirror of
https://github.com/e107inc/e107.git
synced 2025-01-16 20:28:28 +01:00
Closes #4760 - Added image support to generated Google sitemaps.
This commit is contained in:
parent
c2fc8fce0a
commit
fe8d27c51c
@ -101,15 +101,25 @@ class news_gsitemap
|
|||||||
{
|
{
|
||||||
$data = $this->getNewsPosts();
|
$data = $this->getNewsPosts();
|
||||||
|
|
||||||
|
/** @var news_shortcodes $sc */
|
||||||
|
$sc = e107::getScBatch('news');
|
||||||
|
|
||||||
|
e107::getParser()->thumbWidth(1000);
|
||||||
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
|
||||||
foreach($data as $row)
|
foreach($data as $row)
|
||||||
{
|
{
|
||||||
|
$sc->setScVar('news_item', $row);
|
||||||
|
|
||||||
|
$imgUrl = $sc->sc_news_image(['item'=>1, 'type'=>'src']);
|
||||||
|
|
||||||
$ret[] = [
|
$ret[] = [
|
||||||
'url' => $this->url('news', $row),
|
'url' => $this->url('news', $row),
|
||||||
'lastmod' => !empty($row['news_modified']) ? $row['news_modified'] : (int) $row['news_datestamp'],
|
'lastmod' => !empty($row['news_modified']) ? $row['news_modified'] : (int) $row['news_datestamp'],
|
||||||
'freq' => 'hourly',
|
'freq' => 'hourly',
|
||||||
'priority' => 0.5
|
'priority' => 0.5,
|
||||||
|
'image' => (strpos($imgUrl, 'http') === 0) ? $imgUrl : SITEURLBASE.$sc->sc_news_image(['item'=>1, 'type'=>'src']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
gsitemap.php
27
gsitemap.php
@ -63,7 +63,7 @@ class gsitemap_xml
|
|||||||
{
|
{
|
||||||
header('Content-type: application/xml', TRUE);
|
header('Content-type: application/xml', TRUE);
|
||||||
$xml = "<?xml version='1.0' encoding='UTF-8'?>
|
$xml = "<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>";
|
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9' xmlns:image='https://www.google.com/schemas/sitemap-image/1.1'>";
|
||||||
|
|
||||||
if(empty($items))
|
if(empty($items))
|
||||||
{
|
{
|
||||||
@ -105,10 +105,29 @@ class gsitemap_xml
|
|||||||
$loc = (strpos($url, 'http') === 0) ? $url : SITEURL.$tp->replaceConstants($url,true);
|
$loc = (strpos($url, 'http') === 0) ? $url : SITEURL.$tp->replaceConstants($url,true);
|
||||||
$xml .= "
|
$xml .= "
|
||||||
<url>
|
<url>
|
||||||
<loc>".$loc."</loc>
|
<loc>".$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 .= "
|
||||||
|
<image:image>
|
||||||
|
<image:loc>".$imgUrl."</image:loc>
|
||||||
|
</image:image>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$xml .= "
|
||||||
<lastmod>".date('c', (int) $sm[$prefix.'lastmod'])."</lastmod>
|
<lastmod>".date('c', (int) $sm[$prefix.'lastmod'])."</lastmod>
|
||||||
<changefreq>".$sm[$prefix.'freq']."</changefreq>
|
<changefreq>".$sm[$prefix.'freq']."</changefreq>
|
||||||
<priority>".$sm[$prefix.'priority']."</priority>
|
<priority>".$sm[$prefix.'priority']."</priority>
|
||||||
</url>";
|
</url>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user