1<?php
2/**
3 * Script to put indexed documents into the sitemap Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     i-net software <tools@inetsoftware.de>
7 * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8 */
9
10if(!defined('DOKU_INC')) die();
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12if(!defined('DOKU_DATA')) define('DOKU_DATA',DOKU_INC.'data/');
13
14require_once(DOKU_PLUGIN.'action.php');
15require_once(DOKU_INC . 'inc/fulltext.php');
16
17class action_plugin_docsearchsitemap extends DokuWiki_Action_Plugin {
18
19    private $data = array();
20
21    /**
22     * Register to the content display event to place the results under it.
23     */
24    function register(Doku_Event_Handler $controller) {
25        $controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'runSitemapper', array());
26    }
27
28    /**
29     * Builds a Google Sitemap of all public documents known to the indexer
30     *
31     * The map is placed in the root directory named sitemap.xml.gz - This
32     * file needs to be writable!
33     *
34     * @autohr Gerry Weissbach
35     * @link   https://www.google.com/webmasters/sitemaps/docs/en/about.html
36     */
37    function runSitemapper(&$event, $param){
38        global $conf;
39
40        // backup the config array
41        $cp = $conf;
42
43        // change index/pages folder for DocSearch
44        $conf['indexdir'] = init_path($conf['savedir'] . '/docsearch/index');
45        $conf['datadir'] = init_path($conf['savedir'] . '/docsearch/pages');
46
47        $pages = idx_get_indexer()->getPages();
48
49        // build the sitemap
50        foreach($pages as $id){
51
52            //skip hidden, non existing and restricted files
53            if(isHiddenPage($id)) continue;
54            if(auth_aclcheck($id,'','') < AUTH_READ) continue;
55
56
57            // $item = SitemapItem::createFromID($id);
58            $id = trim($id);
59            $date = @filemtime(mediaFN($id));
60            if(!$date) continue;
61            $item = new SitemapItem(ml($id, '', true, '', true), $date, $changefreq, $priority);
62
63            if ($item !== null) {
64                $event->data['items'][] = $item;
65            }
66        }
67
68        $conf = $cp;
69        return true;
70    }
71}
72
73?>
74