mirror of
https://github.com/e107inc/e107.git
synced 2025-08-08 07:36:32 +02:00
Closes #5454 - sitemapindex support.
This commit is contained in:
@@ -42,6 +42,14 @@ class gsitemap_url // plugin-folder + '_url'
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$config['sitemaps'] = array(
|
||||||
|
'alias' => 'sitemaps',
|
||||||
|
'regex' => '^{alias}\.xml$', // matched against url, and if true, redirected to 'redirect' below.
|
||||||
|
'sef' => '{alias}.xml', // used by e107::url(); to create a url from the db table.
|
||||||
|
'redirect' => '{e_BASE}gsitemap.php?index=1', // file-path of what to load when the regex returns true.
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
$addons = e107::getAddonConfig('e_gsitemap', 'gsitemap');
|
$addons = e107::getAddonConfig('e_gsitemap', 'gsitemap');
|
||||||
|
|
||||||
foreach($addons as $plug => $item)
|
foreach($addons as $plug => $item)
|
||||||
|
60
gsitemap.php
60
gsitemap.php
@@ -47,6 +47,10 @@ class gsitemap_xml
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
elseif(!empty($_GET['index'])) // Sitemap index.
|
||||||
|
{
|
||||||
|
$this->renderSitemapIndex();
|
||||||
|
}
|
||||||
else // From Gsitemap Database Table.
|
else // From Gsitemap Database Table.
|
||||||
{
|
{
|
||||||
$this->renderXML();
|
$this->renderXML();
|
||||||
@@ -135,6 +139,62 @@ class gsitemap_xml
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a Sitemap Index containing references to multiple sitemaps.
|
||||||
|
*
|
||||||
|
* @param array $sitemaps An array of sitemaps, where each item is an associative array with keys:
|
||||||
|
* - 'loc' (string): The full URL of the sitemap.
|
||||||
|
* - 'lastmod' (int|null): A timestamp representing the last modification date of the sitemap (optional).
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function renderSitemapIndex()
|
||||||
|
{
|
||||||
|
header('Content-type: application/xml', true);
|
||||||
|
|
||||||
|
// Begin the sitemap index
|
||||||
|
$xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
|
$xml .= "<sitemapindex xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n";
|
||||||
|
|
||||||
|
$obj = e107::getAddon('gsitemap', 'e_url');
|
||||||
|
|
||||||
|
$sitemaps = [];
|
||||||
|
|
||||||
|
if($items = e107::callMethod($obj, 'config'))
|
||||||
|
{
|
||||||
|
foreach($items as $key => $val)
|
||||||
|
{
|
||||||
|
if($key == 'sitemaps' || $key == 'index')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sitemaps[] = ['loc' => e107::url('gsitemap',$key, null, ['mode'=>'full']), 'lastmod' => (time() - 86400)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
foreach($sitemaps as $sitemap)
|
||||||
|
{
|
||||||
|
$xml .= "<sitemap>\n";
|
||||||
|
$xml .= "\t<loc>{$sitemap['loc']}</loc>\n";
|
||||||
|
|
||||||
|
|
||||||
|
if(!empty($sitemap['lastmod'])) // Optional: Include the last modified date, if available
|
||||||
|
{
|
||||||
|
$xml .= "\t<lastmod>" . date('c', (int) $sitemap['lastmod']) . "</lastmod>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$xml .= "</sitemap>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$xml .= "</sitemapindex>";
|
||||||
|
|
||||||
|
// Output the XML
|
||||||
|
echo $xml;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user