1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-26 07:44:49 +02:00

Experimental: Dynamically generated news sitemap.

This commit is contained in:
Cameron
2022-03-03 18:12:48 -08:00
parent fde53794ca
commit 7254c87a04
3 changed files with 181 additions and 43 deletions

View File

@@ -42,6 +42,23 @@ class gsitemap_url // plugin-folder + '_url'
);
$addons = e107::getAddonConfig('e_gsitemap', 'gsitemap');
foreach($addons as $plug => $item)
{
foreach($item as $data )
{
$key = $plug.'-'.$data['function']; // eg. news-latest
$config[$key] = array(
'alias' => $key,
'regex' => '^'.$key.'-sitemap\.xml$', // matched against url, and if true, redirected to 'redirect' below.
'sef' => $key.'-sitemap.xml', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_BASE}gsitemap.php?plug='.$plug.'&func='.$data['function'], // file-path of what to load when the regex returns true.
);
}
}
return $config;

View File

@@ -20,6 +20,40 @@ e107::coreLan('news');
class news_gsitemap
{
// Dynamically Generated Sitemap;
function config()
{
$config = array();
// Viewable from my-website.com/news-latest-sitemap.xml ie. plugin-folder + function + 'sitemap.xml'
$config[] = array(
'name' => "Latest News Posts",
'function' => "latest",
);
return $config;
}
private function getNewsPosts()
{
/* public, guests */
$userclass_list = "0,252";
$_t = time(); /* public, quests */
$query = "SELECT n.*, nc.category_name, nc.category_sef FROM #news AS n
LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
WHERE n.news_class IN (". $userclass_list.") AND n.news_start < ".$_t." AND (n.news_end=0 || n.news_end>".time().") ORDER BY n.news_datestamp ASC ";
// $data = $sql->retrieve("news", "*", "news_class IN (" . $userclass_list . ") AND news_start < " . $_t . " ORDER BY news_datestamp ASC", true);
return e107::getDb()->retrieve($query,true);
}
function import()
{
$import = array();
@@ -41,16 +75,9 @@ class news_gsitemap
);
}
$data = $this->getNewsPosts();
$query = "SELECT n.*, nc.category_name, nc.category_sef FROM #news AS n
LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
WHERE n.news_class IN (". $userclass_list.") AND n.news_start < ".$_t." AND (n.news_end=0 || n.news_end>".time().") ORDER BY n.news_datestamp ASC ";
// $data = $sql->retrieve("news", "*", "news_class IN (" . $userclass_list . ") AND news_start < " . $_t . " ORDER BY news_datestamp ASC", true);
$data = $sql->retrieve($query,true);
foreach($data as $row)
{
$import[] = array(
@@ -66,6 +93,31 @@ class news_gsitemap
return $import;
}
/* Custom Function for dynamic sitemap of news posts */
function latest()
{
$data = $this->getNewsPosts();
$ret = [];
foreach($data as $row)
{
$ret[] = [
'url' => $this->url('news', $row),
'lastmod' => (int) $row['news_datestamp'],
'freq' => 'always',
'priority' => 0.7
];
}
return $ret;
}
/**
* Used above and by gsitemap/e_event.php to update the URL when changed in news, pages etc.
*