- Als Time wird nun die Update-Zeit des Artikels an Google Sitemaps übergeben. So wie es sein sollte
- Die Priority wird gerundet
- Die Change Frequence wird automatisch aus der Update Zeit berechnet und switcht zwischen monthly und weekly automatisch
Hier die Anleitung:
1. öffnet redaxo/include/classes/class.ooarticle.inc.php
2. Sucht nach folgendem Code
Code: Alles auswählen
function isSiteStartArticle()
{
global $REX;
return $this->_id == $REX['STARTARTIKEL_ID'];
}
Code: Alles auswählen
/**
* Accessor Method:
* returns the Updatetime of this article in Google Time
**/
function getUpdatedate() {
$articleUpdateTime = $this->_updatedate;
$last_time_post = date("Y-m-d\TH:i:s",$articleUpdateTime);
$last_time_post = $last_time_post ."+00:00";
return $last_time_post;
}
/**
* Accessor Method:
* returns the ChangeFrequence of the Article
**/
function getChangeFreq() {
$articleUpdatedTime = $this->_updatedate;
$actualtime = time();
$timepastsinceupdate = $actualtime - $articleUpdatedTime;
if ($timepastsinceupdate < 604800) { $changefreq = 'weekly'; } else { $changefreq = 'monthly'; }
return $changefreq;
}
/**
* Accessor Method:
* returns the priority of this article
**/
function getPriority() {
return $this->_prior;
}
So, nun braucht ihr noch das Template. Ich basier wiederum auf der Doku, habs aber ein wenig verändert:
Code: Alles auswählen
<?
// Execution Code
$rsb = new RexSitemapBuilder();
$rsb->setUrlPrefix("http://" . $_SERVER["HTTP_HOST"]."/");
// dump to requestor (the start category level as param)
echo $rsb->buildXML( OOCategory::getRootCategories() );
// Object Definitions
/**
* Class RexSitemapBuilder is a Component that does faciliate
* the URLSet and URL classes to build the SiteMap for Redaxo.
**/
class RexSitemapBuilder {
var $xml="";
var $urlprefix="";
var $document="";
function RexSitemapBuilder() {
$this->xml = "";
$this->document = new URLSet();
}
function setUrlPrefix( $urlprefix ) {
$this->urlprefix=$urlprefix;
}
function buildXML( $categories ) {
foreach ($categories as $category) {
$articles = $category->getArticles();
foreach ($articles as $article) {
if( $article->isOnline() ) {
$this->document->addURL(new URL( $this->urlprefix . $article->getUrl(), $article->getChangeFreq(), $article->getUpdatedate(), round((1 / $article->getPriority()), 1 ), $article->getName() ));
}
}
//recurse
if( sizeof( $category->getChildren() ) > 0) {
$this->buildXML( $category->getChildren() );
}
}
return $this->document->getAsXML();
}
}
/**
* Class URLSet does implement the Parent object
* that can host as many URL objects as required
**/
class URLSet {
var $urls = "";
var $opentag = "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">";
var $closetag = "</urlset>";
var $xmlheader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
/**
* construct me please
**/
function URLSet () {
$this->urls = array();
}
/**
* allows to add URL Objects. And just those.
* okay. I could explicitly type-safe it, but
* i use it internally anyway.
**/
function addURL($url) {
$this->urls[$url->loc] = $url;
}
/**
* returns this Artifact of the XML document
* which is in fact the entire one.
**/
function getAsXML() {
$xml = "";
$xml .= $this->xmlheader . " ";
$xml .= $this->opentag . " ";
foreach($this->urls as $url) {
$xml .= $url->getAsXML();
}
$xml .= $this->closetag . " ";
return $xml;
}
}
/**
* The URL Class does represent a URL SubElement
* that handles an entire url Element in itself
**/
/*public*/ class URL {
var $loc = "";
var $changefreq = "";
var $lastmod = "";
var $priority = "";
var $name = "";
/**
* Constructor Method for a new URL Artifact
**/
/*public*/ function URL($u, $c, $l, $p, $n) {
$this->loc = $u;
$this->changefreq = $c;
$this->lastmod = $l;
$this->priority = $p;
$this->name = $n;
}
/**
* returns this object as XML Artifact
**/
/*protected*/ function getAsXML() {
$xml = "";
//$xml .= " <!-- " . htmlentities( $this->name ) . " --> ";
$xml .= " <url> ";
$xml .= " <loc>" . $this->loc . "</loc> ";
$xml .= " <changefreq>" . $this->changefreq . "</changefreq> ";
$xml .= " <lastmod>" . $this->lastmod . "</lastmod> ";
$xml .= " <priority>" . $this->priority . "</priority> ";
$xml .= " </url> ";
return $xml;
}
}
?>
DEMO: http://www.parkrocker.net/58-0-sitemap.html
Wer nun will, kann google das ganze auch noch als xml übergeben. Dazu einfach das ganze in die .htaccess eintragen.