1 <?php
if (!defined('PmWiki')) exit();
3 $Id: sitemap.php,v 1.7 2005/12/29 10:26:50 pts00065 Exp $
4 This file is NOT part of PmWiki; still you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
10 This script generated a google sitemap, either automaticly or as action=sitemap or both.
12 The automtic version creates a .gz file and is more efficient compared to the action version.
14 google requires that the generated file is located in the root of your pmwiki installation, typically the same place as your pmwiki.php or equivalent file. Thus:
16 http://www.brambring.nl/pmwiki.php -> sitemap must be in: http://www.brambring.nl/sitemap.xml.gz
18 place the file in the cookbook or local directory
19 and include the file from your farmconfig.php or config.php
20 include_once("$FarmD/cookbook/sitemap.php");
23 Then add the URL to your sitemap in the google webform or ping google
25 automatic google ping is not implemented yet.
31 http://www.brambring.nl
34 Revision 1.7 2005/12/29 10:26:50 pts00065
35 * support EnablePageListProtect
36 * Added Site to exclude pattern
41 SDV($LastModFile, "$WorkDir/.lastmod"); # same as in caching
42 SDV($SitemapFile, "sitemap.xml.gz"); #will need write access must be in root dir. Ensure dir is writable or create (symbolic) link
44 SDV($HandleActions['sitemap'], 'HandleSitemap'); # it is not usefull to have both an action
45 // and automatic creation ( SitemapDelay >= 0
46 SDV($SitemapDelay, 3600); # Seconds to wait after last edit set to -1 to disable automatic generation
47 SDV($SitemapSquelch, 12*3600); # Squelch between generations of sitemap
50 SDVA($SitemapSearchPatterns, array());
51 $SitemapSearchPatterns[] = '!\.(All)?Recent(Changes|Uploads|Pages)$!';
52 $SitemapSearchPatterns[] = '!\.Group(Print)?(Header|Footer|Attributes)$!';
53 $SitemapSearchPatterns[] = '!^PmWiki\.!';
54 $SitemapSearchPatterns[] = '!^Site\.!';
55 $SitemapSearchPatterns[] = '!\.SideBar!';
57 SDV($SitemapMaxItems, 50000); # maximum items to display defined by google
58 SDV($SitemapMaxSize, 10); # maximum size is 10 Mbytes TODO
59 SDV($SitemapPing, "http://www.google.com/"); # Use ping with long SitemapDelay (like 24*60*60 ) TODO
61 // SDV($SitemapTimeFmt,'%Y-%m-%dT%H:%M:%sZ'); # seems to break in current version of google
62 SDV($SitemapTimeFmt, '%Y-%m-%d');
64 SDV($SiteMapItems, array());
65 SDV($SitemapChannelFmt, '<?xml version="1.0" encoding="UTF-8"?>
66 <urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
68 SDV($SitemapItemFmt, '
71 <lastmod>$SitemapItemPubDate</lastmod>
72 <changefreq>$SitemapChangeFreq</changefreq>
73 <priority>$SitemapPriority</priority>
75 SDV($HandleSitemapFmt, array(&$SitemapChannelFmt, &$SitemapItems, '</urlset>'));
77 if ( $action == 'browse' ) {
78 if ($SitemapDelay >= 0) {
79 $l = @filemtime
($LastModFile);
80 $s = @filemtime
($SitemapFile);
81 if ((($Now - $l) > $SitemapDelay) && ($l > $s) && (($Now - $s) > $SitemapSquelch)) {
82 $fp = @fopen
($SitemapFile, "w");
86 $x = gzencode (ob_get_clean(), 9);
96 function HandleSitemap()
98 header("Content-type: text/xml");
103 function MakeSitemap()
105 global $SitemapMaxItems, $SitemapChannelFmt, $SitemapTimeFmt,
106 $SitemapItems, $SitemapItemFmt, $SearchPatterns,$FarmD,
107 $EnablePageListProtect,
108 $HandleSitemapFmt, $FmtV, $SitemapSearchPatterns, $Now;
109 global $EntitiesTable;
110 if (IsEnabled($EnablePageListProtect, 1)) $readf = 1000;
113 $t = @ListPages
($SitemapSearchPatterns);
114 $daily_weekly = 60 * 60 * 24 * 6; #TODO
115 foreach ($t as $i => $pn) {
116 $page= ($readf >= 1000)
117 ?
RetrieveAuthPage($pn, 'read', false
, READPAGE_CURRENT
)
118 : ReadPage($pn, READPAGE_CURRENT
);
119 if (!$page) continue;
121 // foreach ( $page as $k => $l ) { print "$k == $l <br />\n"; }
122 if ( (count($SitemapItems) > $SitemapMaxItems)) continue;
123 $FmtV['$SitemapChangeFreq'] = ($Now - $page['time'] < $daily_weekly)?
'daily':'weekly'; #TODO
124 $FmtV['$SitemapPriority'] = '0.5'; #TODO
125 $FmtV['$SitemapItemPubDate'] = gmstrftime($SitemapTimeFmt, $page['time']);
126 $SitemapItems[] = FmtPageName($SitemapItemFmt, $page['name']);
129 #PrintFmt('', str_replace(array_keys($EntitiesTable), array_values($EntitiesTable), $HandleSitemapFmt));
130 PrintFmt('', $HandleSitemapFmt);