renderXML($items);
}
}
else // From Gsitemap Database Table.
{
$this->renderXML();
}
}
/**
* @param $items
* @return void
*/
function renderXML($items=array())
{
header('Content-type: application/xml', TRUE);
$xml = "
";
if(empty($items))
{
$smArray = e107::getDb()->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true);
$xml .= $this->renderXMLItems($smArray, 'gsitemap_');
}
else
{
$xml .= $this->renderXMLItems($items);
}
$xml .= "
";
echo $xml;
}
function renderXMLItems($data, $prefix = '')
{
$tp = e107::getParser();
$xml = '';
foreach($data as $sm)
{
$url = $sm[$prefix.'url'];
if($url[0] === '/')
{
$url = ltrim($url, '/');
}
$loc = (strpos($url, 'http') === 0) ? $url : SITEURL.$tp->replaceConstants($url,true);
$xml .= "
".$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']."
";
}
return $xml;
}
}
// HTML below.
if(e_QUERY == "show" || !empty($_GET['show']))
{
e107::canonical('gsitemap');
e107::route('gsitemap/index');
require_once(HEADERF);
$nfArray = e107::getDb()->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true);
$tp = e107::getParser();
if(deftrue('BOOTSTRAP'))
{
$bread = array(
0 => array('text' => $tp->toHTML(GSLAN_Name), 'url'=> null ) // e107::url('gsitemap','index')
);
$text = e107::getForm()->breadcrumb($bread);
e107::breadcrumb($bread);
}
else
{
$text = '';
}
$text .= "
";
foreach($nfArray as $nfa)
{
$url = (substr($nfa['gsitemap_url'],0,4)== "http")? $nfa['gsitemap_url'] : SITEURL.$tp->replaceConstants($nfa['gsitemap_url'],TRUE);
$text .= "- ".$tp->toHTML($nfa['gsitemap_cat'],"","defs").": ".$tp->toHTML($nfa['gsitemap_name'],"","defs")."
\n";
}
$text .= "
";
e107::getRender() -> tablerender(GSLAN_Name, $text);
require_once(FOOTERF);
exit;
}
new gsitemap_xml;