summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/Sitemapper.php103
-rw-r--r--inc/actions.php3
-rw-r--r--inc/load.php1
-rw-r--r--inc/sitemap.php101
-rw-r--r--lib/exe/indexer.php3
5 files changed, 106 insertions, 105 deletions
diff --git a/inc/Sitemapper.php b/inc/Sitemapper.php
new file mode 100644
index 000000000..68f4beddb
--- /dev/null
+++ b/inc/Sitemapper.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * Sitemap handling functions
+ *
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Michael Hamann <michael@content-space.de>
+ */
+
+if(!defined('DOKU_INC')) die('meh.');
+
+class Sitemapper {
+ /**
+ * Builds a Google Sitemap of all public pages known to the indexer
+ *
+ * The map is placed in the cache directory named sitemap.xml.gz - This
+ * file needs to be writable!
+ *
+ * @author Andreas Gohr
+ * @link https://www.google.com/webmasters/sitemaps/docs/en/about.html
+ */
+ public function generate(){
+ global $conf;
+ dbglog('sitemapGenerate(): started');
+ if(!$conf['sitemap']) return false;
+
+ $sitemap = Sitemapper::getFilePath();
+ dbglog("runSitemapper(): using $sitemap");
+
+ if(@file_exists($sitemap)){
+ if(!is_writable($sitemap)) return false;
+ }else{
+ if(!is_writable(dirname($sitemap))) return false;
+ }
+
+ if(@filesize($sitemap) &&
+ @filemtime($sitemap) > (time()-($conf['sitemap']*60*60*24))){
+ dbglog('runSitemapper(): Sitemap up to date');
+ return false;
+ }
+
+ $pages = idx_getIndex('page', '');
+ dbglog('runSitemapper(): creating sitemap using '.count($pages).' pages');
+
+ // build the sitemap
+ ob_start();
+ print '<?xml version="1.0" encoding="UTF-8"?>'.NL;
+ print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'.NL;
+ foreach($pages as $id){
+ $id = trim($id);
+ $file = wikiFN($id);
+
+ //skip hidden, non existing and restricted files
+ if(isHiddenPage($id)) continue;
+ $date = @filemtime($file);
+ if(!$date) continue;
+ if(auth_aclcheck($id,'','') < AUTH_READ) continue;
+
+ print ' <url>'.NL;
+ print ' <loc>'.wl($id,'',true).'</loc>'.NL;
+ print ' <lastmod>'.date_iso8601($date).'</lastmod>'.NL;
+ print ' </url>'.NL;
+ }
+ print '</urlset>'.NL;
+ $data = ob_get_contents();
+ ob_end_clean();
+
+ //save the new sitemap
+ return io_saveFile($sitemap,$data);
+ }
+
+ public function getFilePath() {
+ global $conf;
+
+ $sitemap = $conf['cachedir'].'/sitemap.xml';
+ if($conf['compression'] == 'bz2' || $conf['compression'] == 'gz'){
+ $sitemap .= '.gz';
+ }
+
+ return $sitemap;
+ }
+
+ public function pingSearchEngines() {
+ //ping search engines...
+ $http = new DokuHTTPClient();
+ $http->timeout = 8;
+
+ $encoded_sitemap_url = urlencode(wl('', array('do' => 'sitemap'), true, '&'));
+ $ping_urls = array(
+ 'google' => 'http://www.google.com/webmasters/sitemaps/ping?sitemap='.$encoded_sitemap_url,
+ 'yahoo' => 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=dokuwiki&url='.$encoded_sitemap_url,
+ 'microsoft' => 'http://www.bing.com/webmaster/ping.aspx?siteMap='.$encoded_sitemap_url,
+ );
+
+ foreach ($ping_urls as $name => $url) {
+ dbglog("sitemapPingSearchEngines(): pinging $name");
+ $resp = $http->get($url);
+ if($http->error) dbglog("runSitemapper(): $http->error");
+ dbglog('runSitemapper(): '.preg_replace('/[\n\r]/',' ',strip_tags($resp)));
+ }
+
+ return true;
+ }
+}
diff --git a/inc/actions.php b/inc/actions.php
index 2d70ac8ed..12c4c595f 100644
--- a/inc/actions.php
+++ b/inc/actions.php
@@ -615,8 +615,7 @@ function act_sitemap($act) {
// Check if sitemap file exists, otherwise create it
if (!is_readable($sitemap)) {
- require_once DOKU_INC.'inc/sitemap.php';
- sitemapGenerate();
+ Sitemapper::generate();
}
if (is_readable($sitemap)) {
diff --git a/inc/load.php b/inc/load.php
index 2f5be6d63..478ee7c76 100644
--- a/inc/load.php
+++ b/inc/load.php
@@ -74,6 +74,7 @@ function load_autoload($name){
'DokuWikiFeedCreator' => DOKU_INC.'inc/feedcreator.class.php',
'Doku_Parser_Mode' => DOKU_INC.'inc/parser/parser.php',
'SafeFN' => DOKU_INC.'inc/SafeFN.class.php',
+ 'Sitemapper' => DOKU_INC.'inc/Sitemapper.php',
'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php',
diff --git a/inc/sitemap.php b/inc/sitemap.php
deleted file mode 100644
index bbed7d269..000000000
--- a/inc/sitemap.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-/**
- * Sitemap handling functions
- *
- * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
- * @author Michael Hamann <michael@content-space.de>
- */
-
-if(!defined('DOKU_INC')) die('meh.');
-
-/**
- * Builds a Google Sitemap of all public pages known to the indexer
- *
- * The map is placed in the cache directory named sitemap.xml.gz - This
- * file needs to be writable!
- *
- * @author Andreas Gohr
- * @link https://www.google.com/webmasters/sitemaps/docs/en/about.html
- */
-function sitemapGenerate(){
- global $conf;
- dbglog('sitemapGenerate(): started');
- if(!$conf['sitemap']) return false;
-
- $sitemap = sitemapGetFilePath();
- dbglog("runSitemapper(): using $sitemap");
-
- if(@file_exists($sitemap)){
- if(!is_writable($sitemap)) return false;
- }else{
- if(!is_writable(dirname($sitemap))) return false;
- }
-
- if(@filesize($sitemap) &&
- @filemtime($sitemap) > (time()-($conf['sitemap']*60*60*24))){
- dbglog('runSitemapper(): Sitemap up to date');
- return false;
- }
-
- $pages = idx_getIndex('page', '');
- dbglog('runSitemapper(): creating sitemap using '.count($pages).' pages');
-
- // build the sitemap
- ob_start();
- print '<?xml version="1.0" encoding="UTF-8"?>'.NL;
- print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'.NL;
- foreach($pages as $id){
- $id = trim($id);
- $file = wikiFN($id);
-
- //skip hidden, non existing and restricted files
- if(isHiddenPage($id)) continue;
- $date = @filemtime($file);
- if(!$date) continue;
- if(auth_aclcheck($id,'','') < AUTH_READ) continue;
-
- print ' <url>'.NL;
- print ' <loc>'.wl($id,'',true).'</loc>'.NL;
- print ' <lastmod>'.date_iso8601($date).'</lastmod>'.NL;
- print ' </url>'.NL;
- }
- print '</urlset>'.NL;
- $data = ob_get_contents();
- ob_end_clean();
-
- //save the new sitemap
- return io_saveFile($sitemap,$data);
-}
-
-function sitemapGetFilePath() {
- global $conf;
-
- $sitemap = $conf['cachedir'].'/sitemap.xml';
- if($conf['compression'] == 'bz2' || $conf['compression'] == 'gz'){
- $sitemap .= '.gz';
- }
-
- return $sitemap;
-}
-
-function sitemapPingSearchEngines() {
- //ping search engines...
- $http = new DokuHTTPClient();
- $http->timeout = 8;
-
- $encoded_sitemap_url = urlencode(wl('', array('do' => 'sitemap'), true, '&'));
- $ping_urls = array(
- 'google' => 'http://www.google.com/webmasters/sitemaps/ping?sitemap='.$encoded_sitemap_url,
- 'yahoo' => 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=dokuwiki&url='.$encoded_sitemap_url,
- 'microsoft' => 'http://www.bing.com/webmaster/ping.aspx?siteMap='.$encoded_sitemap_url,
- );
-
- foreach ($ping_urls as $name => $url) {
- dbglog("sitemapPingSearchEngines(): pinging $name");
- $resp = $http->get($url);
- if($http->error) dbglog("runSitemapper(): $http->error");
- dbglog('runSitemapper(): '.preg_replace('/[\n\r]/',' ',strip_tags($resp)));
- }
-
- return true;
-}
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php
index 63ad5931f..61cf83acc 100644
--- a/lib/exe/indexer.php
+++ b/lib/exe/indexer.php
@@ -233,8 +233,7 @@ function metaUpdate(){
*/
function runSitemapper(){
print "runSitemapper(): started".NL;
- require_once DOKU_INC.'inc/sitemap.php';
- $result = sitemapGenerate() && sitemapPingSearchEngines();
+ $result = Sitemapper::generate() && Sitemapper::pingSearchEngines();
print 'runSitemapper(): finished'.NL;
return $result;
}