From 5c773b6963179bca08e7eee5421a005492eb96d5 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Sat, 1 Nov 2008 13:35:10 +0100 Subject: [PATCH] add sitemap support. generates with ?action=sitemap --- install/cookbook/sitemap.php | 133 +++++++++++++++++++++++++++++++++++++++++++ install/local/farmconfig.php | 1 + 2 files changed, 134 insertions(+) create mode 100644 install/cookbook/sitemap.php diff --git a/install/cookbook/sitemap.php b/install/cookbook/sitemap.php new file mode 100644 index 0000000..c58c4c6 --- /dev/null +++ b/install/cookbook/sitemap.php @@ -0,0 +1,133 @@ + sitemap must be in: http://www.brambring.nl/sitemap.xml.gz + +place the file in the cookbook or local directory +and include the file from your farmconfig.php or config.php +include_once("$FarmD/cookbook/sitemap.php"); + + +Then add the URL to your sitemap in the google webform or ping google + +automatic google ping is not implemented yet. + +regards + +bram + +http://www.brambring.nl + + $Log: sitemap.php,v $ + Revision 1.7 2005/12/29 10:26:50 pts00065 + * support EnablePageListProtect + * Added Site to exclude pattern + + + +*/ +SDV($LastModFile, "$WorkDir/.lastmod"); # same as in caching +SDV($SitemapFile, "sitemap.xml.gz"); #will need write access must be in root dir. Ensure dir is writable or create (symbolic) link + +SDV($HandleActions['sitemap'], 'HandleSitemap'); # it is not usefull to have both an action +// and automatic creation ( SitemapDelay >= 0 +SDV($SitemapDelay, 3600); # Seconds to wait after last edit set to -1 to disable automatic generation +SDV($SitemapSquelch, 12*3600); # Squelch between generations of sitemap + + +SDVA($SitemapSearchPatterns, array()); +$SitemapSearchPatterns[] = '!\.(All)?Recent(Changes|Uploads|Pages)$!'; +$SitemapSearchPatterns[] = '!\.Group(Print)?(Header|Footer|Attributes)$!'; +$SitemapSearchPatterns[] = '!^PmWiki\.!'; +$SitemapSearchPatterns[] = '!^Site\.!'; +$SitemapSearchPatterns[] = '!\.SideBar!'; + +SDV($SitemapMaxItems, 50000); # maximum items to display defined by google +SDV($SitemapMaxSize, 10); # maximum size is 10 Mbytes TODO +SDV($SitemapPing, "http://www.google.com/"); # Use ping with long SitemapDelay (like 24*60*60 ) TODO + +// SDV($SitemapTimeFmt,'%Y-%m-%dT%H:%M:%sZ'); # seems to break in current version of google +SDV($SitemapTimeFmt, '%Y-%m-%d'); + +SDV($SiteMapItems, array()); +SDV($SitemapChannelFmt, ' + + '); +SDV($SitemapItemFmt, ' + + $PageUrl + $SitemapItemPubDate + $SitemapChangeFreq + $SitemapPriority + '); +SDV($HandleSitemapFmt, array(&$SitemapChannelFmt, &$SitemapItems, '')); + +if ( $action == 'browse' ) { + if ($SitemapDelay >= 0) { + $l = @filemtime($LastModFile); + $s = @filemtime($SitemapFile); + if ((($Now - $l) > $SitemapDelay) && ($l > $s) && (($Now - $s) > $SitemapSquelch)) { + $fp = @fopen($SitemapFile, "w"); + if ($fp) { + ob_start(); + MakeSitemap(); + $x = gzencode (ob_get_clean(), 9); + fwrite($fp, $x); + fclose($fp); + } + } + } +} + + + +function HandleSitemap() +{ + header("Content-type: text/xml"); + MakeSitemap(); + exit; +} + +function MakeSitemap() +{ + global $SitemapMaxItems, $SitemapChannelFmt, $SitemapTimeFmt, + $SitemapItems, $SitemapItemFmt, $SearchPatterns,$FarmD, + $EnablePageListProtect, + $HandleSitemapFmt, $FmtV, $SitemapSearchPatterns, $Now; + global $EntitiesTable; + if (IsEnabled($EnablePageListProtect, 1)) $readf = 1000; + + $t = array(); + $t = @ListPages($SitemapSearchPatterns); + $daily_weekly = 60 * 60 * 24 * 6; #TODO + foreach ($t as $i => $pn) { + $page= ($readf >= 1000) + ? RetrieveAuthPage($pn, 'read', false, READPAGE_CURRENT) + : ReadPage($pn, READPAGE_CURRENT); + if (!$page) continue; + + // foreach ( $page as $k => $l ) { print "$k == $l
\n"; } + if ( (count($SitemapItems) > $SitemapMaxItems)) continue; + $FmtV['$SitemapChangeFreq'] = ($Now - $page['time'] < $daily_weekly)?'daily':'weekly'; #TODO + $FmtV['$SitemapPriority'] = '0.5'; #TODO + $FmtV['$SitemapItemPubDate'] = gmstrftime($SitemapTimeFmt, $page['time']); + $SitemapItems[] = FmtPageName($SitemapItemFmt, $page['name']); + } + + #PrintFmt('', str_replace(array_keys($EntitiesTable), array_values($EntitiesTable), $HandleSitemapFmt)); + PrintFmt('', $HandleSitemapFmt); +} + + diff --git a/install/local/farmconfig.php b/install/local/farmconfig.php index 68e5f47..4b34ca5 100644 --- a/install/local/farmconfig.php +++ b/install/local/farmconfig.php @@ -14,6 +14,7 @@ include_once("$FarmD/cookbook/geoloc.php"); include_once("$FarmD/cookbook/chat.php"); include_once("$FarmD/cookbook/faq.php"); include_once("$FarmD/cookbook/fieldadmin.php"); +include_once("$FarmD/cookbook/sitemap.php"); ##---------------Francisation ------------------------------------ -- 2.1.4