1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00
php-e107/gsitemap.php

168 lines
3.1 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
2008-12-21 09:00:02 +00:00
* e107 website system
*
2009-11-18 01:06:08 +00:00
* Copyright (C) 2008-2009 e107 Inc (e107.org)
2008-12-21 09:00:02 +00:00
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Plugin supporting file - gsitemap
*
* $Source: /cvs_backup/e107_0.8/gsitemap.php,v $
2010-02-10 18:18:01 +00:00
* $Revision$
* $Date$
* $Author$
2008-12-21 09:00:02 +00:00
*
2006-12-02 04:36:16 +00:00
*/
require_once("class2.php");
if(!e107::isInstalled('gsitemap'))
2008-12-21 09:00:02 +00:00
{
e107::redirect();
2008-12-21 09:00:02 +00:00
exit();
}
e107::lan('gsitemap');
2006-12-02 04:36:16 +00:00
class gsitemap_xml
{
function __construct()
{
$items = [];
// Gsitemap Addon.
if(!empty($_GET['plug']) && !empty($_GET['func']))
{
if(!e107::isInstalled($_GET['plug']))
{
exit;
}
$obj = e107::getAddon($_GET['plug'], 'e_gsitemap');
if($items = e107::callMethod($obj, $_GET['func']))
{
$this->renderXML($items);
}
}
else // From Gsitemap Database Table.
{
$this->renderXML([], 'gsitemap_');
}
}
/**
* @param $items
* @return void
*/
function renderXML($items=array())
{
header('Content-type: application/xml', TRUE);
$xml = "<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>";
if(empty($items))
{
$smArray = e107::getDb()->retrieve("gsitemap", "*", "gsitemap_active IN (".USERCLASS_LIST.") ORDER BY gsitemap_order ",true);
$xml .= $this->renderXMLItems($smArray);
}
else
{
$xml .= $this->renderXMLItems($items);
}
$xml .= "
</urlset>";
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 .= "
<url>
<loc>".$loc."</loc>
<lastmod>".date('c', (int) $sm[$prefix.'lastmod'])."</lastmod>
<changefreq>".$sm[$prefix.'freq']."</changefreq>
<priority>".$sm[$prefix.'priority']."</priority>
</url>";
}
return $xml;
}
}
// HTML below.
if(e_QUERY == "show" || !empty($_GET['show']))
2006-12-02 04:36:16 +00:00
{
e107::canonical('gsitemap');
e107::route('gsitemap/index');
2006-12-02 04:36:16 +00:00
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 .= "<div style='text-align:left' class='gsitemap'><ul>";
2006-12-02 04:36:16 +00:00
foreach($nfArray as $nfa)
{
$url = (substr($nfa['gsitemap_url'],0,4)== "http")? $nfa['gsitemap_url'] : SITEURL.$tp->replaceConstants($nfa['gsitemap_url'],TRUE);
2007-12-24 16:21:16 +00:00
$text .= "<li>".$tp->toHTML($nfa['gsitemap_cat'],"","defs").": <a href='".$url."'>".$tp->toHTML($nfa['gsitemap_name'],"","defs")."</a></li>\n";
2006-12-02 04:36:16 +00:00
}
$text .= "</ul></div>";
e107::getRender() -> tablerender(GSLAN_Name, $text);
2006-12-02 04:36:16 +00:00
require_once(FOOTERF);
exit;
}
new gsitemap_xml;
2006-12-02 04:36:16 +00:00