/**
* Script zur automatischen Erstellung einer XML-Sitemap für Google
*
* created: 12.08.2009 II
*
* last modified: 12.08.2009 II - Alte sitemap.php in sitemap_old.php umbennant
*/
require 'include/includer.inc.php';
function sitemapFormaterByJJ($text) {
$search_replace = array(
'Ä' => 'Ae',
'ä' => 'ae',
'Ö' => 'Oe',
'ö' => 'oe',
'Ü' => 'Ue',
'ü' => 'ue',
'ß' => 'ss',
'Ä' => 'Ae',
'ä' => 'ae',
'Ö' => 'Oe',
'ö' => 'oe',
'Ü' => 'Ue',
'ü' => 'ue',
'ß' => 'ss',
' ' => '_',
'
' => '_',
'
' => '_',
'
' => '_',
'
' => '_',
'
' => '_',
'
' => '_'
);
$text = strip_tags($text);
foreach($search_replace as $search => $replace) {
$text = str_replace($search, $replace, $text);
}
$text = preg_replace('/[^A-Za-z0-9]/', ' ', $text);
$text = str_replace(' ', '_', trim($text));
while(strpos($text, '__') !== false) {
$text = str_replace('__', '_', $text);
}
return $text;
}
function sitemapCreatorByJJ($menuelang, $parent, $protokoll, $servername, $lastmodified, $path = '/') {
$result = MySQLQuery('SELECT id, ' . $menuelang . ' AS menulang, parent, directlink FROM tbl_struktur WHERE disabled=0 AND parent=' . $parent . ' ORDER BY parent, rank ASC');
$total = mysql_numrows($result);
if($total > 0) {
while($row = mysql_fetch_assoc($result)) {
$row['menulang'] = sitemapFormaterByJJ($row['menulang']);
if($row['menulang'] !== '') {
$htaccessLink = $row['id'];
// if($row['directlink'] > 0) {
// $htaccessLink = $row['directlink'];
// } else {
// $htaccessLink = $row['id'];
// }
$ausgabe .= '' . "\n";
$ausgabe .= ' ' . $protokoll . $servername . $path . $row['menulang'] . '.html' . "\n";
$ausgabe .= ' ' . $lastmodified . '' . "\n";
$ausgabe .= ' always' . "\n";
$ausgabe .= ' 0.97' . "\n";
$ausgabe .= '' . "\n";
//$ausgabe_htaccess .= 'RewriteRule ' . substr($path, 1) . $row['menulang'] . '.html ' . $protokoll . $servername . '/showpage.php?SiteID=';
$ausgabe_htaccess .= 'RewriteRule ' . substr($path, 1) . $row['menulang'] . '.html /showpage.php?' . substr($path, 1) . $row['menulang'] . '&SiteID=' . $htaccessLink;
$ausgabe_htaccess .= ' [R=301,L]' . "\n";
$ausgabe_htaccess .= 'RewriteCond %{QUERY_STRING} ^SiteID=' . $htaccessLink . '$' . "\n";
$ausgabe_htaccess .= 'RewriteRule ^([A-Za-z0-9_]+\.[A-Za-z]+)?$ /showpage.php?' . substr($path, 1) . $row['menulang'] . '&SiteID=' . $htaccessLink . ' [R=301,L]' . "\n";
$ausgabe_htaccess .= 'RewriteCond %{QUERY_STRING} ^SiteID=' . $htaccessLink . '&lang=1$' . "\n";
$ausgabe_htaccess .= 'RewriteRule ^([A-Za-z0-9_]+\.[A-Za-z]+)?$ /showpage.php?' . substr($path, 1) . $row['menulang'] . '&SiteID=' . $htaccessLink . ' [R=301,L]' . "\n";
$ausgaben = sitemapCreatorByJJ($menuelang, $row['id'], $protokoll, $servername, $lastmodified, $path . $row['menulang'] . '/');
if($ausgaben !== false) {
$ausgabe .= $ausgaben['ausgabe'];
$ausgabe_htaccess .= $ausgaben['htaccess'];
}
}
}
$ausgaben = array(
'ausgabe' => $ausgabe,
'htaccess' => $ausgabe_htaccess
);
return $ausgaben;
} else {
return false;
}
}
$ausgabe = '' . "\n";
$ausgabe .= '' . "\n";
for($x = 1; $x <= count($cms_lang); $x++) {
unset($ausgaben);
$menuelang = 'menulang' . $x;
$lastmodified = gmdate("Y-m-d\TH:i+00:00", time());
if(strlen($_SERVER['HTTPS']) > 0) {
$protokoll = 'https://';
} else {
$protokoll = 'http://';
}
//
// Navigation
//
$ausgaben = sitemapCreatorByJJ($menuelang, 0, $protokoll, $_SERVER['SERVER_NAME'], $lastmodified);
$ausgabe .= $ausgaben['ausgabe'];
$ausgabe_htaccess .= $ausgaben['htaccess'];
//
// Artikelgruppen
//
$result = MySQLQuery('SELECT category FROM tbl_article WHERE layout=8882 AND disabled=0 LIMIT 1');
$total = mysql_numrows($result);
if($total == 1) {
$row = mysql_fetch_assoc($result);
$resultCategorie = MySQLQuery('SELECT cid FROM tbl_category WHERE cdisabled=0 AND csaveflag=0 ORDER BY crang ASC');
while($rowCategorie = mysql_fetch_assoc($resultCategorie)) {
$ausgabe .= '' . "\n";
$ausgabe .= ' ' . $protokoll . $_SERVER['SERVER_NAME'] . '/showpage.php?SiteID=' . $row['category'] . '&act=sat&gruppe=' . $rowCategorie['cid'] . '' . "\n";
$ausgabe .= ' ' . $lastmodified . '' . "\n";
$ausgabe .= ' allways' . "\n";
$ausgabe .= ' 0.97' . "\n";
$ausgabe .= '' . "\n";
//
// Artikel
//
$resultProduct = MySQLQuery('SELECT pid FROM tbl_product WHERE pcategoryID=' . $rowCategorie['cid'] . ' AND pdisabled=0 ORDER BY prang ASC');
while($rowProduct = mysql_fetch_assoc($resultProduct)) {
$ausgabe .= '' . "\n";
$ausgabe .= ' ' . $protokoll . $_SERVER['SERVER_NAME'] . '/showpage.php?SiteID=' . $row['category'] . '&act=satdet&ItemID=' . $rowProduct['pid'].'' . "\n";
$ausgabe .= ' ' . $lastmodified . '' . "\n";
$ausgabe .= ' allways' . "\n";
$ausgabe .= ' 0.97' . "\n";
$ausgabe .= '' . "\n";
}
}
}
}
$ausgabe .= '';
$htaccessFilename = '.htaccess';
$rewriteStart = '#BoBB REDIRECT START';
$rewriteEngine = 'RewriteEngine on' . "\n". 'RewriteBase /' . "\n";
$rewriteEnd = '#BoBB REDIRECT END';
if(is_readable($htaccessFilename) === true) {
$htaccessContent = file_get_contents($htaccessFilename);
if(is_writeable($htaccessFilename) === true) {
$rewriteStartPosition = strpos($htaccessContent, $rewriteStart);
if($rewriteStartPosition !== false) {
$rewriteEndPosition = strpos($htaccessContent, $rewriteEnd) + strlen($rewriteEnd);
$before = substr($htaccessContent, 0, $rewriteStartPosition);
$middle = substr($htaccessContent, $rewriteStartPosition, $rewriteEndPosition);
$after = substr($htaccessContent, $rewriteEndPosition);
$startWrite = '#START WRITE ' . $_SERVER['SERVER_NAME'];
$domainStartPosition = strpos($htaccessContent, $startWrite);
if($domainStartPosition !== false) {
// Aktualisiert den Inhalt der zwischen "#START WRITE {Domainname}" und "#END WRITE {Domainname}" gesetzt ist
$endWrite = '#END WRITE ' . $_SERVER['SERVER_NAME'];
$domainEndPosition = strpos($htaccessContent, $endWrite) + strlen('#END WRITE ' . $_SERVER['SERVER_NAME']);
$before = substr($htaccessContent, 0, $domainStartPosition);
$middle = substr($htaccessContent, $domainStartPosition + strlen($startWrite), ($domainEndPosition - ($domainStartPosition + strlen($startWrite))) - strlen($endWrite));
$after = substr($htaccessContent, $domainEndPosition);
$htaccessNewContent = $before . $startWrite . "\n" . $ausgabe_htaccess . $endWrite . $after;
} else {
// Erstellt inhalt des htaccess rewrite falls die aktuelle Domain noch keinen eigenen Inhalt innerhalb von "#BoBB REDIRECT START" hat
$htaccessParts = explode($rewriteEngine, $htaccessContent);
$htaccessNewContent = $htaccessParts[0] . $rewriteEngine . '#START WRITE ' . $_SERVER['SERVER_NAME'] . "\n" . $ausgabe_htaccess . '#END WRITE ' . $_SERVER['SERVER_NAME'] . "\n" . $htaccessParts[1];
}
} else {
// Erstellt inhalt des htaccess rewrite falls "#BoBB REDIRECT START" noch nicht in der htaccess existiert
$htaccessNewContent = $htaccessContent . "\n\n" . $rewriteStart . "\n" . $rewriteEngine . '#START WRITE ' . $_SERVER['SERVER_NAME'] . "\n" . $ausgabe_htaccess . '#END WRITE ' . $_SERVER['SERVER_NAME'] . "\n" . $rewriteEnd . "\n";
}
unset($tmp, $htaccessContent, $ausgabe_htaccess);
/*
// PHP 5 Version
file_put_contents($htaccessFilename, $htaccessNewContent);
*/
// PHP 4 Version
$handle = fopen($htaccessFilename, 'w');
fwrite($handle, $htaccessNewContent);
fclose($handle);
unset($htaccessNewContent, $htaccessFilename);
}
}
header('Content-type: application/xml');
print $ausgabe;
?>