Hallo Jungs,
es gibt bestimmt viele unter euch die Ihren Shop bei Google anmelden wollen,
um diesen für Suchmaschinen zu optimieren.
Daher ist aber eine so genannt Google Sitemap Xml von nöten, die leider
bie Oxid nicht dabei ist und auch nur in überteuerten Modulen angeboten wird.
Da wir selber eine schnell Lösung brauchten,
habe ich ein kleines Script aufgesetzt was diese selbst erstellt.
In der Sitemap werden mit SEO URLs alle
Kategorien, Produkte und Kundencmsseiten gespeichert.
[B]google_sitemap_xml.php[/B]
<?php
/*
Google Sitemap Xml v.0.1
--------------------------------
oxid ESales - SEO
--------------------------------
by DIATOM Internet & Medien GmbH
--------------------------------
c: 27.07.2009 | u: 27.07.2009
*/
/* BEGIN - Config ----------------------------------------------------------- */
// Default
$xmlList = array();
$xmlInsert = array();
// Config
$mod_cnf = array();
$mod_cnf['filepath'] = './';
$mod_cnf['filename'] = 'sitemap.xml';
$mod_cnf['siteurl'] = 'http://www.domain.de/';
$mod_cnf['sql_server'] = "localhost";
$mod_cnf['sql_dbname'] = "";
$mod_cnf['sql_dbuser'] = "";
$mod_cnf['sql_dbpw'] = "";
// Error
$error = array();
$error['connect'] = "keine Mysql Verbindung gefunden!";
$error['select'] = "kein Mysql Datensatz gefunden!";
/* END - Config ------------------------------------------------------------- */
/* BEGIN - Function --------------------------------------------------------- */
// Function - Create Xml File
function createXmlFile($xmlInsert) {
global $mod_cnf;
// File Create
$fp = fopen($mod_cnf['filepath'].$mod_cnf['filename'], "w+");
fwrite($fp, implode("
", $xmlInsert));
fclose($fp);
}
// Function - get Categorys
function getCategorys() {
global $mod_cnf;
// Default
$list = array();
// Sql - Select
$sql_sel = "SELECT
oxid,
oxtitle,
oxdesc,
oxlongdesc
FROM oxcategories
WHERE
oxactive = 1 AND
oxhidden = 0
ORDER by oxtitle ASC
";
$sql_query = mysql_query($sql_sel);
while( $sql_row = mysql_fetch_array($sql_query) ) {
// Vars
$loc = $sql_row['oxid'];
// List
$list[] = array(
'loc' => getSeoUrl($loc),
'priority' => '1.0',
'lastmod' => date('Y').'-'.date('m').'-'.date('d').'T'.date('h').':'.date('i').':'.date('s').'+00:00',
'changefreq' => 'weekly',
);
}
return $list;
}
// Function - get Products
function getProducts() {
global $mod_cnf;
// Default
$list = array();
// Sql - Select
$sql_sel = "SELECT
oxart.oxid as oxid,
oxart.oxartnum as oxartnum,
oxart.oxtitle as oxtitle,
oxart.oxshortdesc as oxshortdesc,
oxart.oxtimestamp as oxtimestamp
FROM oxarticles as oxart
LEFT JOIN oxobject2category as oxobj2cat ON ( oxobj2cat.oxobjectid = oxart.oxid )
LEFT JOIN oxcategories as oxcat ON ( oxcat.oxid = oxobj2cat.oxcatnid )
WHERE
oxart.oxactive = 1 AND
oxcat.oxactive = 1 AND
oxcat.oxhidden = 0
ORDER by oxart.oxartnum ASC
";
$sql_query = mysql_query($sql_sel);
while( $sql_row = mysql_fetch_array($sql_query) ) {
// Vars
$loc = getSeoUrl($sql_row['oxid']);
$oxtimestamp = explode(" ", $sql_row['oxtimestamp']);
// List
$list[] = array(
'loc' => $loc,
'priority' => '0.5',
'lastmod' => $oxtimestamp[0].'T'.$oxtimestamp[1].'+00:00',
'changefreq' => 'daily',
);
}
return $list;
}
// Function - get CMS Sites
function getCmsSite() {
global $mod_cnf;
// Default
$list = array();
// Sql - Select
$sql_sel = "SELECT
oxid,
oxtitle
FROM oxcontents
WHERE
oxactive = 1 AND
oxfolder = 'CMSFOLDER_USERINFO'
ORDER by oxtitle ASC
";
$sql_query = mysql_query($sql_sel);
while( $sql_row = mysql_fetch_array($sql_query) ) {
// Vars
$loc = getSeoUrl($sql_row['oxid']);
// List
$list[] = array(
'loc' => $loc,
'priority' => '1.0',
'lastmod' => date('Y').'-'.date('m').'-'.date('d').'T'.date('h').':'.date('i').':'.date('s').'+00:00',
'changefreq' => 'weekly',
);
}
return $list;
}
// Function - Get SEO URL
function getSeoUrl($oxid) {
global $mod_cnf;
// Default
$url = '';
// Sql - Select
$sql_sel = "SELECT
oxstdurl,
oxseourl
FROM oxseo
WHERE
oxobjectid = '". $oxid ."' AND
oxlang = '0'
LIMIT 1
";
$sql_query = mysql_query($sql_sel);
if( $sql_row = mysql_fetch_array($sql_query) ) {
// Var
$url = $sql_row['oxseourl'];
if( empty($url) ) $url = $sql_row['oxstdurl'];
return $url;
}
return $url;
}
/* END - Function ----------------------------------------------------------- */
/* BEGIN - Action ----------------------------------------------------------- */
// SQL Connect
$sqlConnect = mysql_connect($mod_cnf['sql_server'], $mod_cnf['sql_dbuser'], $mod_cnf['sql_dbpw']) OR die($error['connect']);
mysql_select_db($mod_cnf['sql_dbname'], $sqlConnect) OR die($error['select']);
// Get - Categorys
$xmlList_cat = getCategorys();
// Get - Products
$xmlList_prod = getProducts();
// Get - Cms Site
$xmlList_cms = getCmsSite();
// Output - Xml
$xmlList = array_merge($xmlList_cat, $xmlList_prod, $xmlList_cms);
/* END - Action ------------------------------------------------------------- */
/* BEGIN - Output ----------------------------------------------------------- */
// Vars
$xmlInsert[] = '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">';
foreach($xmlList as $key => $val) {
// Vars
$xmlInsert[] = '<url>
<loc>'. $mod_cnf['siteurl'].$val['loc'] .'</loc>
<priority>'. $val['priority'] .'</priority>
<lastmod>'. $val['lastmod'] .'</lastmod>
<changefreq>'. $val['changefreq'] .'</changefreq>
</url>';
}
// Vars
$xmlInsert[] = '</urlset>';
// Create Xml File
createXmlFile($xmlInsert);
// Output - User Info
echo '<a href="'. $mod_cnf['filepath'].$mod_cnf['filename'] .'" target="_blank">XML Datei betrachten</a>';
/* END - Output ------------------------------------------------------------- */
?>
Später soll sich das ganze noch automatisch aktualisieren und
auch mehrere Sprachen unterstützen.
mfg, Sebastian
P.s. more Modules 4 Free