Page 1 of 4
Google Sitemaps generator
Posted: Sat Dec 03, 2005 12:10 am
by Stefan Noll
hi,
i created a sitemap generator for cms made simple which produces a sitemap in the google xml format.
just copy the following code to a new php file in the root directory and give google the url of that file.
Code: Select all
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id: preview.php 2148 2005-11-09 20:44:15Z wishy $
require_once(dirname(__FILE__)."/include.php");
header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
echo '<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">
'. "\n";
$allcontent = ContentManager::GetAllContent();
$maxdepth = 1;
foreach ($allcontent as $onecontent)
{
$depth = count(split('\.', $onecontent->Hierarchy()));
if($maxdepth < $depth)
$maxdepth = $depth;
}
foreach ($allcontent as $onecontent)
{
$depth = count(split('\.', $onecontent->Hierarchy()));
//$rel = 1 - ($depth-1) / ($maxdepth);
$rel = 0.7 / $depth;
$rel = number_format($rel, 1, '.', '');
if($oneconetn->default_content)
$rel = 1;
if (!$onecontent->Active())
{
continue;
}
if ($onecontent->Type() == 'separator')
{
continue;
}
if ($onecontent->Type() == 'sectionheader')
{
continue;
}
echo ' <url> ' . "\n";
echo ' <loc>' . $onecontent->GetURL() . '</loc>'. "\n";
echo ' <lastmod>' . $onecontent->mModifiedDate . '</lastmod>'. "\n";
echo ' <priority>' . $rel . '</priority>'. "\n";
// Perhaps: generate a changefreq param of $onconent->Cachable()
echo ' </url> '. "\n";
}
echo ' </urlset>'. "\n";
?>
sincerely,
stefan noll
Re: Google Sitemaps generator
Posted: Sat Dec 03, 2005 5:55 pm
by owl666
Hi,
thx. Great work, but there's still a bug in the date at least. Google expects this:
https://www.google.com/webmasters/sitem ... fying_time
Greets,
owl
Re: Google Sitemaps generator
Posted: Sat Dec 03, 2005 6:01 pm
by stefan noll
hi,
thanks,
here i have a small patch, it just splits the date up and only uses date without time.
sincerely,
stefan noll
Code: Select all
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id: preview.php 2148 2005-11-09 20:44:15Z wishy $
require_once(dirname(__FILE__)."/include.php");
header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
echo '<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">
'. "\n";
$allcontent = ContentManager::GetAllContent();
$maxdepth = 1;
foreach ($allcontent as $onecontent)
{
$depth = count(split('\.', $onecontent->Hierarchy()));
if($maxdepth < $depth)
$maxdepth = $depth;
}
foreach ($allcontent as $onecontent)
{
$depth = count(split('\.', $onecontent->Hierarchy()));
//$rel = 1 - ($depth-1) / ($maxdepth);
$rel = 0.7 / $depth;
$rel = number_format($rel, 1, '.', '');
if($oneconetn->default_content)
$rel = 1;
if (!$onecontent->Active())
{
continue;
}
if ($onecontent->Type() == 'separator')
{
continue;
}
if ($onecontent->Type() == 'sectionheader')
{
continue;
}
$date = $onecontent->mModifiedDate;
$datepart = explode(" ", $date);
$date = $datepart[0];
echo ' <url> ' . "\n";
echo ' <loc>' . $onecontent->GetURL() . '</loc>'. "\n";
echo ' <lastmod>' . $date . '</lastmod>'. "\n";
echo ' <priority>' . $rel . '</priority>'. "\n";
// Perhaps: generate a changefreq param of $onconent->Cachable()
echo ' </url> '. "\n";
}
echo ' </urlset>'. "\n";
?>
Re: Google Sitemaps generator
Posted: Sat Dec 03, 2005 6:20 pm
by owl666
Hi,
thx for the fix - you were faster than me *g* :
DateTime - modified (and seeing hopefully soon, if it works):
add below $date = $datepart[0];
Code: Select all
$time = $datepart[1];
//setting time-zone statically
$TZD = "+01:00";
$datetime = implode("T",$datepart);
$googledatetime = $datetime.$TZD;
change: echo ' ' . $date . ''. "\n";
to:
Code: Select all
echo ' <lastmod>' . $googledatetime . '</lastmod>'. "\n";
Well - somehow it isn't willed to work... Google tells me, that it's a wrong DateTime-Entry....I've the same entry format like mentioned in the Google-help... (YYYY-MM-DDTHH:MM:SS+TDZ)
MediaWiki-people seem to get it working:
http://www.thinklemon.com/wiki/sitemap.xml.php
Mine looks like: 2005-07-04T12:04:52+01:00
Well, where exactly could be the problem right now?
Greets,
owl
Re: Google Sitemaps generator
Posted: Sat Dec 03, 2005 9:47 pm
by owl666
Another Hi

Well, it works right now - with timestamp:
Code: Select all
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id: preview.php 2148 2005-11-09 20:44:15Z wishy $
require_once(dirname(__FILE__)."/include.php");
header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n";
/*echo '<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">
'. "\n";
*/
echo '<urlset>' . "\n";
$allcontent = ContentManager::GetAllContent();
$maxdepth = 3;
foreach ($allcontent as $onecontent)
{
$depth = count(split('\.', $onecontent->Hierarchy()));
if($maxdepth < $depth)
$maxdepth = $depth;
}
foreach ($allcontent as $onecontent)
{
$depth = count(split('\.', $onecontent->Hierarchy()));
//$rel = 1 - ($depth-1) / ($maxdepth);
$rel = 0.7 / $depth;
$rel = number_format($rel, 1, '.', '');
if($oneconetn->default_content)
$rel = 1;
if (!$onecontent->Active())
{
continue;
}
if ($onecontent->Type() == 'separator')
{
continue;
}
if ($onecontent->Type() == 'sectionheader')
{
continue;
}
$date = $onecontent->mModifiedDate;
$datepart = explode(" ", $date);
$date = $datepart[0];
$time = $datepart[1];
//setting time-zone statically
$TZD = "+01:00";
$datetime = implode("T",$datepart);
$googledatetime = $datetime.$TZD;
echo ' <url> ' . "\n";
echo ' <loc>' . $onecontent->GetURL() . '</loc>'. "\n";
echo ' <lastmod>' . $googledatetime . '</lastmod>'. "\n";
echo ' <priority>' . $rel . '</priority>'. "\n";
// Perhaps: generate a changefreq param of $onconent->Cachable()
echo ' </url> '. "\n";
}
echo ' </urlset>'. "\n";
?>
Greets,
owl
Re: Google Sitemaps generator
Posted: Sun Feb 12, 2006 8:51 pm
by zyxyla
This generator is really great! Exactly what I was looking for except one thing... and this is a big request to you programmers out there...
I have a website splitted in two languages with each language it's own cms - so ....
Could someone modify it for me so I can access two databases?
That would be sooo great!!!
Thanks in advance!
Re: Google Sitemaps generator
Posted: Tue Feb 21, 2006 10:08 pm
by iNSiPiD
Sorry to sound obtuse but could someone provide exact steps on how to implement this? Seems it could easily be employed as a user-defined tag or plugin.
So...
1. Paste contents to a new file and save as whatever.php? Or sitemap.php?
2. Tell Google about it. How, where?
3. And then what? How is it used within the CMS?
If anyone's got a URL for a working sampe, I'd like to see it.
Re: Google Sitemaps generator
Posted: Wed Feb 22, 2006 10:24 pm
by -
How about making a module out of it.
Re: Google Sitemaps generator
Posted: Wed Feb 22, 2006 10:31 pm
by -
I guess you're right.
Unless it made installation easier.
Re: Google Sitemaps generator
Posted: Sun Feb 26, 2006 11:30 am
by Stefan Noll
Hi,
a module would be fine, but Google Sitemaps wants the sitemap in the root directory and i don't know the possibilities to put modul files in the root directory.
sincerely,
stefan noll
Re: Google Sitemaps generator
Posted: Fri Mar 10, 2006 7:25 pm
by ssi
Is there any need to include news articles in the sitemap? I don't know that it's important since you can create a page that lists the news articles... also, does it hurt anything to include external links that are in the menu (i.e. menu with links to external AP source)?
I can modify the script without a lot of trouble, however, I am just looking for some other opinions...is it worth it?
Re: Google Sitemaps generator
Posted: Fri Mar 17, 2006 12:12 pm
by wipeout
I can't get this to work. Google always gives me an Unsupported file format error. I've even tried to use mod_rewrite to make the script work as sitemap.xml, but with no success.
Re: Google Sitemaps generator
Posted: Tue Mar 21, 2006 1:58 am
by tamlyn
I installed this a few days ago and it worked fine but now google is telling me it's an unsupported format - have they changed the spec?
Re: Google Sitemaps generator
Posted: Tue Mar 21, 2006 2:28 pm
by tamlyn
The problem was the missing xml namspace. For some reason owl666 commented it out in his/her version. So I commented it back in and it validates now.
Re: Google Sitemaps generator
Posted: Fri Mar 24, 2006 2:36 pm
by fredt
I love this soft and people using it... Never been deceived !
Can one of you nice gals & guys enhance this code with this:
- remove "hidden" pages (they're active, but not displayed in the menu) - so Goooogle won't see my test pages ?
- browse and sitemap News pages? We use this feature quite a lot...
Thanks !
Fred