Completed
Pull Request — master (#21)
by Mark
01:24
created
admin/purge.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -23,66 +23,66 @@
 block discarded – undo
23 23
  */
24 24
 class admin_plugin_spatialhelper_purge extends DokuWiki_Admin_Plugin {
25 25
 
26
-    /**
27
-     *
28
-     * @see DokuWiki_Admin_Plugin::getMenuSort()
29
-     */
30
-    public function getMenuSort() {
31
-        return 801;
32
-    }
33
-    /**
34
-     * admin use only.
35
-     *
36
-     * @return true
37
-     *
38
-     * @see DokuWiki_Admin_Plugin::forAdminOnly()
39
-     */
40
-    public function forAdminOnly() {
41
-        return true;
42
-    }
26
+	/**
27
+	 *
28
+	 * @see DokuWiki_Admin_Plugin::getMenuSort()
29
+	 */
30
+	public function getMenuSort() {
31
+		return 801;
32
+	}
33
+	/**
34
+	 * admin use only.
35
+	 *
36
+	 * @return true
37
+	 *
38
+	 * @see DokuWiki_Admin_Plugin::forAdminOnly()
39
+	 */
40
+	public function forAdminOnly() {
41
+		return true;
42
+	}
43 43
 
44
-    /**
45
-     * purge and regenerate the index and sitemaps.
46
-     *
47
-     * @see DokuWiki_Admin_Plugin::handle()
48
-     */
49
-    public function handle() {
50
-        global $conf;
51
-        if (isset ($_REQUEST ['purgeindex'])) {
52
-            global $conf;
53
-            $path = $conf ['indexdir'] . '/spatial.idx';
54
-            if (file_exists($path)) {
55
-                if (unlink($path)) {
56
-                    msg($this->getLang('admin_purged_tiles'), 0);
57
-                }
58
-            }
59
-        }
44
+	/**
45
+	 * purge and regenerate the index and sitemaps.
46
+	 *
47
+	 * @see DokuWiki_Admin_Plugin::handle()
48
+	 */
49
+	public function handle() {
50
+		global $conf;
51
+		if (isset ($_REQUEST ['purgeindex'])) {
52
+			global $conf;
53
+			$path = $conf ['indexdir'] . '/spatial.idx';
54
+			if (file_exists($path)) {
55
+				if (unlink($path)) {
56
+					msg($this->getLang('admin_purged_tiles'), 0);
57
+				}
58
+			}
59
+		}
60 60
 
61
-        $indexer = plugin_load('helper', 'spatialhelper_index');
62
-        $indexer->generateSpatialIndex();
61
+		$indexer = plugin_load('helper', 'spatialhelper_index');
62
+		$indexer->generateSpatialIndex();
63 63
 
64
-        $sitemapper = plugin_load('helper', 'spatialhelper_sitemap');
65
-        $sitemapper->createKMLSitemap($this->getConf('media_kml'));
66
-        $sitemapper->createGeoRSSSitemap($this->getConf('media_georss'));
67
-    }
64
+		$sitemapper = plugin_load('helper', 'spatialhelper_sitemap');
65
+		$sitemapper->createKMLSitemap($this->getConf('media_kml'));
66
+		$sitemapper->createGeoRSSSitemap($this->getConf('media_georss'));
67
+	}
68 68
 
69
-    /**
70
-     * render the form for this plugin.
71
-     *
72
-     * @see DokuWiki_Admin_Plugin::html()
73
-     */
74
-    public function html() {
75
-        echo $this->locale_xhtml('admin_purge_intro');
69
+	/**
70
+	 * render the form for this plugin.
71
+	 *
72
+	 * @see DokuWiki_Admin_Plugin::html()
73
+	 */
74
+	public function html() {
75
+		echo $this->locale_xhtml('admin_purge_intro');
76 76
 
77
-        $form = new Doku_Form(array(
78
-                'id' => 'spatialhelper__purgeform',
79
-                'method' => 'post'
80
-        ));
81
-        $form->addHidden('purgeindex', 'true');
77
+		$form = new Doku_Form(array(
78
+				'id' => 'spatialhelper__purgeform',
79
+				'method' => 'post'
80
+		));
81
+		$form->addHidden('purgeindex', 'true');
82 82
 
83
-        $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin_submit'), array(
84
-                'title' => $this->getLang('admin_submit')
85
-        )));
86
-        $form->printForm();
87
-    }
83
+		$form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin_submit'), array(
84
+				'title' => $this->getLang('admin_submit')
85
+		)));
86
+		$form->printForm();
87
+	}
88 88
 }
Please login to merge, or discard this patch.
_test/general.test.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,40 +23,40 @@
 block discarded – undo
23 23
  */
24 24
 class general_plugin_spatialhelper_test extends DokuWikiTest {
25 25
 
26
-    protected $pluginsEnabled = array('spatialhelper');
26
+	protected $pluginsEnabled = array('spatialhelper');
27 27
 
28
-    /**
29
-     * Simple test to make sure the plugin.info.txt is in correct format.
30
-     */
31
-    public function test_plugininfo() {
32
-        $file = __DIR__ . '/../plugin.info.txt';
33
-        $this->assertFileExists($file);
28
+	/**
29
+	 * Simple test to make sure the plugin.info.txt is in correct format.
30
+	 */
31
+	public function test_plugininfo() {
32
+		$file = __DIR__ . '/../plugin.info.txt';
33
+		$this->assertFileExists($file);
34 34
 
35
-        $info = confToHash($file);
35
+		$info = confToHash($file);
36 36
 
37
-        $this->assertArrayHasKey('base', $info);
38
-        $this->assertArrayHasKey('author', $info);
39
-        $this->assertArrayHasKey('email', $info);
40
-        $this->assertArrayHasKey('date', $info);
41
-        $this->assertArrayHasKey('name', $info);
42
-        $this->assertArrayHasKey('desc', $info);
43
-        $this->assertArrayHasKey('url', $info);
37
+		$this->assertArrayHasKey('base', $info);
38
+		$this->assertArrayHasKey('author', $info);
39
+		$this->assertArrayHasKey('email', $info);
40
+		$this->assertArrayHasKey('date', $info);
41
+		$this->assertArrayHasKey('name', $info);
42
+		$this->assertArrayHasKey('desc', $info);
43
+		$this->assertArrayHasKey('url', $info);
44 44
 
45
-        $this->assertEquals('spatialhelper', $info['base']);
46
-        $this->assertRegExp('/^https?:\/\//', $info['url']);
47
-        $this->assertTrue(mail_isvalid($info['email']));
48
-        $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
49
-        $this->assertTrue(false !== strtotime($info['date']));
50
-    }
45
+		$this->assertEquals('spatialhelper', $info['base']);
46
+		$this->assertRegExp('/^https?:\/\//', $info['url']);
47
+		$this->assertTrue(mail_isvalid($info['email']));
48
+		$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
49
+		$this->assertTrue(false !== strtotime($info['date']));
50
+	}
51 51
 
52
-    /**
53
-     * test if plugin is loaded.
54
-     */
55
-    public function test_plugin_spatialhelper_isloaded() {
56
-        global $plugin_controller;
57
-        $this->assertTrue(
58
-            in_array('spatialhelper', $plugin_controller->getList()),
59
-            "spatialhelper plugin is loaded"
60
-        );
61
-    }
52
+	/**
53
+	 * test if plugin is loaded.
54
+	 */
55
+	public function test_plugin_spatialhelper_isloaded() {
56
+		global $plugin_controller;
57
+		$this->assertTrue(
58
+			in_array('spatialhelper', $plugin_controller->getList()),
59
+			"spatialhelper plugin is loaded"
60
+		);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
syntax/findnearby.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -22,89 +22,89 @@
 block discarded – undo
22 22
  * @author Mark C. Prins <[email protected]>
23 23
  */
24 24
 class syntax_plugin_spatialhelper_findnearby extends DokuWiki_Syntax_Plugin {
25
-    /**
26
-     *
27
-     * @see DokuWiki_Syntax_Plugin::getType()
28
-     */
29
-    public function getType() {
30
-        return 'substition';
31
-    }
25
+	/**
26
+	 *
27
+	 * @see DokuWiki_Syntax_Plugin::getType()
28
+	 */
29
+	public function getType() {
30
+		return 'substition';
31
+	}
32 32
 
33
-    /**
34
-     * Return 'normal' so this syntax can be rendered inline.
35
-     *
36
-     * @see DokuWiki_Syntax_Plugin::getPType()
37
-     */
38
-    public function getPType() {
39
-        return 'normal';
40
-    }
33
+	/**
34
+	 * Return 'normal' so this syntax can be rendered inline.
35
+	 *
36
+	 * @see DokuWiki_Syntax_Plugin::getPType()
37
+	 */
38
+	public function getPType() {
39
+		return 'normal';
40
+	}
41 41
 
42
-    /**
43
-     *
44
-     * @see Doku_Parser_Mode::getSort()
45
-     */
46
-    public function getSort() {
47
-        return 307;
48
-    }
42
+	/**
43
+	 *
44
+	 * @see Doku_Parser_Mode::getSort()
45
+	 */
46
+	public function getSort() {
47
+		return 307;
48
+	}
49 49
 
50
-    /**
51
-     * define our special pattern: {{findnearby>Some linkt text or nothing}}.
52
-     *
53
-     * @see Doku_Parser_Mode::connectTo()
54
-     */
55
-    public function connectTo($mode) {
56
-        $this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby');
57
-    }
50
+	/**
51
+	 * define our special pattern: {{findnearby>Some linkt text or nothing}}.
52
+	 *
53
+	 * @see Doku_Parser_Mode::connectTo()
54
+	 */
55
+	public function connectTo($mode) {
56
+		$this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby');
57
+	}
58 58
 
59
-    /**
60
-     * look up the page's geo metadata and pass that on to render.
61
-     *
62
-     * @see DokuWiki_Syntax_Plugin::handle()
63
-     */
64
-    public function handle($match, $state, $pos, Doku_Handler $handler) {
65
-        $data = array();
66
-        $data [0] = trim(substr($match, strlen('{{findnearby>'), - 2));
67
-        if (strlen($data [0]) < 1) {
68
-            $data [0] = $this->getLang('search_findnearby');
69
-        }
70
-        $meta = p_get_metadata(getID(), 'geo');
71
-        if ($meta) {
72
-            if ($meta ['lat'] && $meta ['lon']) {
73
-                $data [1] = array(
74
-                        'do' => 'findnearby',
75
-                        'lat' => $meta ['lat'],
76
-                        'lon' => $meta ['lon']
77
-                );
78
-            } elseif ($meta ['geohash']) {
79
-                $data [1] = array(
80
-                        'do' => 'findnearby',
81
-                        'geohash' => $meta ['geohash']
82
-                );
83
-            }
84
-            return $data;
85
-        }
86
-        return false;
87
-    }
59
+	/**
60
+	 * look up the page's geo metadata and pass that on to render.
61
+	 *
62
+	 * @see DokuWiki_Syntax_Plugin::handle()
63
+	 */
64
+	public function handle($match, $state, $pos, Doku_Handler $handler) {
65
+		$data = array();
66
+		$data [0] = trim(substr($match, strlen('{{findnearby>'), - 2));
67
+		if (strlen($data [0]) < 1) {
68
+			$data [0] = $this->getLang('search_findnearby');
69
+		}
70
+		$meta = p_get_metadata(getID(), 'geo');
71
+		if ($meta) {
72
+			if ($meta ['lat'] && $meta ['lon']) {
73
+				$data [1] = array(
74
+						'do' => 'findnearby',
75
+						'lat' => $meta ['lat'],
76
+						'lon' => $meta ['lon']
77
+				);
78
+			} elseif ($meta ['geohash']) {
79
+				$data [1] = array(
80
+						'do' => 'findnearby',
81
+						'geohash' => $meta ['geohash']
82
+				);
83
+			}
84
+			return $data;
85
+		}
86
+		return false;
87
+	}
88 88
 
89
-    /**
90
-     * Render a link to a search page.
91
-     *
92
-     * @see DokuWiki_Syntax_Plugin::render()
93
-     */
94
-    public function render($mode, Doku_Renderer $renderer, $data) {
95
-        if ($data === false) {
96
-                    return false;
97
-        }
89
+	/**
90
+	 * Render a link to a search page.
91
+	 *
92
+	 * @see DokuWiki_Syntax_Plugin::render()
93
+	 */
94
+	public function render($mode, Doku_Renderer $renderer, $data) {
95
+		if ($data === false) {
96
+					return false;
97
+		}
98 98
 
99
-        if ($mode == 'xhtml') {
100
-            $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>';
101
-            return true;
102
-        } elseif ($mode == 'metadata') {
103
-            return false;
104
-        } elseif ($mode == 'odt') {
105
-            // don't render anything in ODT
106
-            return false;
107
-        }
108
-        return false;
109
-    }
99
+		if ($mode == 'xhtml') {
100
+			$renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>';
101
+			return true;
102
+		} elseif ($mode == 'metadata') {
103
+			return false;
104
+		} elseif ($mode == 'odt') {
105
+			// don't render anything in ODT
106
+			return false;
107
+		}
108
+		return false;
109
+	}
110 110
 }
Please login to merge, or discard this patch.
action.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -234,11 +234,11 @@
 block discarded – undo
234 234
      * @param boolean $showMedia
235 235
      */
236 236
     private function printHTML($searchresults, $showMedia = true) {
237
-        $pages = (array) ($searchresults ['pages']);
238
-        $media = (array) $searchresults ['media'];
239
-        $lat = (float) $searchresults ['lat'];
240
-        $lon = (float) $searchresults ['lon'];
241
-        $geohash = (string) $searchresults ['geohash'];
237
+        $pages = ( array ) ($searchresults ['pages']);
238
+        $media = ( array ) $searchresults ['media'];
239
+        $lat = ( float ) $searchresults ['lat'];
240
+        $lon = ( float ) $searchresults ['lon'];
241
+        $geohash = ( string ) $searchresults ['geohash'];
242 242
 
243 243
         if (isset ($searchresults ['error'])) {
244 244
             print '<div class="level1"><p>' . hsc($results ['error']) . '</p></div>';
Please login to merge, or discard this patch.
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -25,388 +25,388 @@
 block discarded – undo
25 25
  */
26 26
 class action_plugin_spatialhelper extends DokuWiki_Action_Plugin {
27 27
 
28
-    /**
29
-     * Register for events.
30
-     *
31
-     * @param Doku_Event_Handler $controller
32
-     *          DokuWiki's event controller object. Also available as global $EVENT_HANDLER
33
-     */
34
-    public function register(Doku_Event_Handler $controller) {
35
-        // listen for page add / delete events
36
-        // http://www.dokuwiki.org/devel:event:indexer_page_add
37
-        $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexerPageAdd');
38
-        $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'removeFromIndex');
39
-
40
-        // http://www.dokuwiki.org/devel:event:sitemap_generate
41
-        $controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'handleSitemapGenerateBefore');
42
-        // using after will only trigger us if a sitemap was actually created
43
-        $controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handleSitemapGenerateAfter');
44
-
45
-        // handle actions we know of
46
-        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActionActPreprocess', array());
47
-        // handle HTML eg. /dokuwiki/doku.php?id=start&do=findnearby&geohash=u15vk4
48
-        $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'findnearby', array(
49
-                'format' => 'HTML'
50
-        ));
51
-        // handles AJAX/json eg: jQuery.post("/dokuwiki/lib/exe/ajax.php?id=start&call=findnearby&geohash=u15vk4");
52
-        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'findnearby', array(
53
-                'format' => 'JSON'
54
-        ));
55
-
56
-        // listen for media uploads and deletes
57
-        $controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, 'handleMediaUploaded', array());
58
-        $controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, 'handleMediaDeleted', array());
59
-
60
-        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
61
-    }
62
-
63
-    /**
64
-     * Update the spatial index for the page.
65
-     *
66
-     * @param Doku_Event $event
67
-     *          event object by reference
68
-     * @param object $param
69
-     *          the parameters passed to register_hook when this handler was registered
70
-     */
71
-    public function handleIndexerPageAdd(Doku_Event $event, $param) {
72
-        // $event→data['page'] – the page id
73
-        // $event→data['body'] – empty, can be filled by additional content to index by your plugin
74
-        // $event→data['metadata'] – the metadata that shall be indexed. This is an array where the keys are the
75
-        //    metadata indexes and the value a string or an array of strings with the values.
76
-        //    title and relation_references will already be set.
77
-        $id = $event->data ['page'];
78
-        $indexer = & plugin_load('helper', 'spatialhelper_index');
79
-        $entries = $indexer->updateSpatialIndex($id);
80
-    }
81
-
82
-    /**
83
-     * Update the spatial index, removing the page.
84
-     *
85
-     * @param Doku_Event $event
86
-     *          event object by reference
87
-     * @param object $param
88
-     *          the parameters passed to register_hook when this handler was registered
89
-     */
90
-    public function removeFromIndex(Doku_Event & $event, $param) {
91
-        // event data:
92
-        // $data[0] – The raw arguments for io_saveFile as an array. Do not change file path.
93
-        // $data[0][0] – the file path.
94
-        // $data[0][1] – the content to be saved, and may be modified.
95
-        // $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns)
96
-        // $data[2] – page_name: The wiki page name.
97
-        // $data[3] – rev: The page revision, false for current wiki pages.
98
-
99
-        dbglog($event->data, "Event data in removeFromIndex.");
100
-        if (@file_exists($event->data [0] [0])) {
101
-            // file not new
102
-            if (!$event->data [0] [1]) {
103
-                // file is empty, page is being deleted
104
-                if (empty ($event->data [1])) {
105
-                    // root namespace
106
-                    $id = $event->data [2];
107
-                } else {
108
-                    $id = $event->data [1] . ":" . $event->data [2];
109
-                }
110
-                $indexer = & plugin_load('helper', 'spatialhelper_index');
111
-                if ($indexer) {
112
-                    $indexer->deleteFromIndex($id);
113
-                }
114
-            }
115
-        }
116
-    }
117
-
118
-    /**
119
-     * Add a new SitemapItem object that points to the KML of public geocoded pages.
120
-     *
121
-     * @param Doku_Event $event
122
-     * @param unknown $param
123
-     */
124
-    public function handleSitemapGenerateBefore(Doku_Event $event, $param) {
125
-        $path = mediaFN($this->getConf('media_kml'));
126
-        $lastmod = @filemtime($path);
127
-        $event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&amp;', true), $lastmod);
128
-        //dbglog($event->data ['items'],
129
-        //  "Added a new SitemapItem object that points to the KML of public geocoded pages.");
130
-    }
131
-
132
-    /**
133
-     * Create a spatial sitemap or attach the geo/kml map to the sitemap.
134
-     *
135
-     * @param Doku_Event $event
136
-     *          event object by reference, not used
137
-     * @param mixed $param
138
-     *          parameter array, not used
139
-     */
140
-    public function handleSitemapGenerateAfter(Doku_Event $event, $param) {
141
-        // $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already
142
-        //      contains all public pages of the wiki
143
-        // $event→data['sitemap']: The path of the file the sitemap will be saved to.
144
-        if ($helper = & plugin_load('helper', 'spatialhelper_sitemap')) {
145
-            // dbglog($helper, "createSpatialSitemap loaded helper.");
146
-
147
-            $kml = $helper->createKMLSitemap($this->getConf('media_kml'));
148
-            $rss = $helper->createGeoRSSSitemap($this->getConf('media_georss'));
28
+	/**
29
+	 * Register for events.
30
+	 *
31
+	 * @param Doku_Event_Handler $controller
32
+	 *          DokuWiki's event controller object. Also available as global $EVENT_HANDLER
33
+	 */
34
+	public function register(Doku_Event_Handler $controller) {
35
+		// listen for page add / delete events
36
+		// http://www.dokuwiki.org/devel:event:indexer_page_add
37
+		$controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexerPageAdd');
38
+		$controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'removeFromIndex');
39
+
40
+		// http://www.dokuwiki.org/devel:event:sitemap_generate
41
+		$controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'handleSitemapGenerateBefore');
42
+		// using after will only trigger us if a sitemap was actually created
43
+		$controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handleSitemapGenerateAfter');
44
+
45
+		// handle actions we know of
46
+		$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActionActPreprocess', array());
47
+		// handle HTML eg. /dokuwiki/doku.php?id=start&do=findnearby&geohash=u15vk4
48
+		$controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'findnearby', array(
49
+				'format' => 'HTML'
50
+		));
51
+		// handles AJAX/json eg: jQuery.post("/dokuwiki/lib/exe/ajax.php?id=start&call=findnearby&geohash=u15vk4");
52
+		$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'findnearby', array(
53
+				'format' => 'JSON'
54
+		));
55
+
56
+		// listen for media uploads and deletes
57
+		$controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, 'handleMediaUploaded', array());
58
+		$controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, 'handleMediaDeleted', array());
59
+
60
+		$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
61
+	}
62
+
63
+	/**
64
+	 * Update the spatial index for the page.
65
+	 *
66
+	 * @param Doku_Event $event
67
+	 *          event object by reference
68
+	 * @param object $param
69
+	 *          the parameters passed to register_hook when this handler was registered
70
+	 */
71
+	public function handleIndexerPageAdd(Doku_Event $event, $param) {
72
+		// $event→data['page'] – the page id
73
+		// $event→data['body'] – empty, can be filled by additional content to index by your plugin
74
+		// $event→data['metadata'] – the metadata that shall be indexed. This is an array where the keys are the
75
+		//    metadata indexes and the value a string or an array of strings with the values.
76
+		//    title and relation_references will already be set.
77
+		$id = $event->data ['page'];
78
+		$indexer = & plugin_load('helper', 'spatialhelper_index');
79
+		$entries = $indexer->updateSpatialIndex($id);
80
+	}
81
+
82
+	/**
83
+	 * Update the spatial index, removing the page.
84
+	 *
85
+	 * @param Doku_Event $event
86
+	 *          event object by reference
87
+	 * @param object $param
88
+	 *          the parameters passed to register_hook when this handler was registered
89
+	 */
90
+	public function removeFromIndex(Doku_Event & $event, $param) {
91
+		// event data:
92
+		// $data[0] – The raw arguments for io_saveFile as an array. Do not change file path.
93
+		// $data[0][0] – the file path.
94
+		// $data[0][1] – the content to be saved, and may be modified.
95
+		// $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns)
96
+		// $data[2] – page_name: The wiki page name.
97
+		// $data[3] – rev: The page revision, false for current wiki pages.
98
+
99
+		dbglog($event->data, "Event data in removeFromIndex.");
100
+		if (@file_exists($event->data [0] [0])) {
101
+			// file not new
102
+			if (!$event->data [0] [1]) {
103
+				// file is empty, page is being deleted
104
+				if (empty ($event->data [1])) {
105
+					// root namespace
106
+					$id = $event->data [2];
107
+				} else {
108
+					$id = $event->data [1] . ":" . $event->data [2];
109
+				}
110
+				$indexer = & plugin_load('helper', 'spatialhelper_index');
111
+				if ($indexer) {
112
+					$indexer->deleteFromIndex($id);
113
+				}
114
+			}
115
+		}
116
+	}
117
+
118
+	/**
119
+	 * Add a new SitemapItem object that points to the KML of public geocoded pages.
120
+	 *
121
+	 * @param Doku_Event $event
122
+	 * @param unknown $param
123
+	 */
124
+	public function handleSitemapGenerateBefore(Doku_Event $event, $param) {
125
+		$path = mediaFN($this->getConf('media_kml'));
126
+		$lastmod = @filemtime($path);
127
+		$event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&amp;', true), $lastmod);
128
+		//dbglog($event->data ['items'],
129
+		//  "Added a new SitemapItem object that points to the KML of public geocoded pages.");
130
+	}
131
+
132
+	/**
133
+	 * Create a spatial sitemap or attach the geo/kml map to the sitemap.
134
+	 *
135
+	 * @param Doku_Event $event
136
+	 *          event object by reference, not used
137
+	 * @param mixed $param
138
+	 *          parameter array, not used
139
+	 */
140
+	public function handleSitemapGenerateAfter(Doku_Event $event, $param) {
141
+		// $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already
142
+		//      contains all public pages of the wiki
143
+		// $event→data['sitemap']: The path of the file the sitemap will be saved to.
144
+		if ($helper = & plugin_load('helper', 'spatialhelper_sitemap')) {
145
+			// dbglog($helper, "createSpatialSitemap loaded helper.");
146
+
147
+			$kml = $helper->createKMLSitemap($this->getConf('media_kml'));
148
+			$rss = $helper->createGeoRSSSitemap($this->getConf('media_georss'));
149 149
             
150
-            if (!empty ($this->getConf('sitemap_namespaces'))) {
151
-                $namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces')));
152
-                foreach ($namespaces as $namespace) {
153
-                    $kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml'));
154
-                    $rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss'));
155
-                    dbglog(
156
-                        $kmlN && $rssN,
157
-                        "handleSitemapGenerateAfter, created KML / GeoRSS sitemap in $namespace, succes: "
158
-                    );
159
-                }  
160
-            }
161
-            return $kml && $rss;
162
-        } else {
163
-            dbglog($helper, "createSpatialSitemap NOT loaded helper.");
164
-        }
165
-    }
166
-
167
-    /**
168
-     * trap findnearby action.
169
-     * This addional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown
170
-     *
171
-     * @param Doku_Event $event
172
-     *          event object by reference
173
-     * @param mixed $param
174
-     *          not used
175
-     */
176
-    public function handleActionActPreprocess(Doku_Event $event, $param) {
177
-        if ($event->data != 'findnearby') {
178
-            return;
179
-        }
180
-        $event->preventDefault();
181
-    }
182
-
183
-    /**
184
-     * handle findnearby action.
185
-     *
186
-     * @param Doku_Event $event
187
-     *          event object by reference
188
-     * @param mixed $param
189
-     *          associative array with keys
190
-     *          'format'=> HTML | JSON
191
-     */
192
-    public function findnearby(Doku_Event & $event, $param) {
193
-        if ($event->data != 'findnearby') {
194
-            return;
195
-        }
196
-        $event->preventDefault();
197
-
198
-        global $INPUT;
199
-        if ($helper = & plugin_load('helper', 'spatialhelper_search')) {
200
-            if ($INPUT->has('lat') && $INPUT->has('lon')) {
201
-                $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon'));
202
-            } elseif ($INPUT->has('geohash')) {
203
-                $results = $helper->findNearby($INPUT->str('geohash'));
204
-            } else {
205
-                $results = array(
206
-                        'error' => hsc($this->getLang('invalidinput'))
207
-                );
208
-            }
209
-        }
210
-
211
-        $showMedia = $INPUT->bool('showMedia', true);
212
-
213
-        switch ($param['format']) {
214
-            case 'JSON' :
215
-                $this->printJSON($results);
216
-                break;
217
-            case 'HTML' :
218
-            // fall through to default
219
-            default :
220
-                $this->printHTML($results, $showMedia);
221
-                break;
222
-        }
223
-    }
224
-
225
-    /**
226
-     * Print seachresults as HTML lists.
227
-     *
228
-     * @param array $searchresults
229
-     */
230
-    private function printJSON($searchresults) {
231
-        require_once DOKU_INC . 'inc/JSON.php';
232
-        $json = new JSON();
233
-        header('Content-Type: application/json');
234
-        print $json->encode($searchresults);
235
-    }
236
-
237
-    /**
238
-     * Print seachresults as HTML lists.
239
-     *
240
-     * @param array $searchresults
241
-     * @param boolean $showMedia
242
-     */
243
-    private function printHTML($searchresults, $showMedia = true) {
244
-        $pages = (array) ($searchresults ['pages']);
245
-        $media = (array) $searchresults ['media'];
246
-        $lat = (float) $searchresults ['lat'];
247
-        $lon = (float) $searchresults ['lon'];
248
-        $geohash = (string) $searchresults ['geohash'];
249
-
250
-        if (isset ($searchresults ['error'])) {
251
-            print '<div class="level1"><p>' . hsc($results ['error']) . '</p></div>';
252
-            return;
253
-        }
254
-
255
-        // print a HTML list
256
-        print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF;
257
-        print '<div class="level1">' . DOKU_LF;
258
-        if (!empty ($pages)) {
259
-            $pagelist = '<ol>' . DOKU_LF;
260
-            foreach ($pages as $page) {
261
-                $pagelist .= '<li>' . html_wikilink(':' . $page ['id'], useHeading('navigation') ? null :
262
-                    noNS($page ['id'])) . ' (' . $this->getLang('results_distance_prefix')
263
-                        . $page ['distance'] . '&nbsp;m) ' . $page ['description'] . '</li>' . DOKU_LF;
264
-            }
265
-            $pagelist .= '</ol>' . DOKU_LF;
266
-
267
-            print '<h2>' . $this->getLang('results_pages') . hsc(' lat;lon: ' . $lat . ';' . $lon
268
-                . ' (geohash: ' . $geohash . ')') . '</h2>';
269
-            print '<div class="level2">' . DOKU_LF;
270
-            print $pagelist;
271
-            print '</div>' . DOKU_LF;
272
-        } else {
273
-            print '<p>' . hsc($this->getLang('nothingfound')) . '</p>';
274
-        }
275
-
276
-        if (!empty ($media) && $showMedia) {
277
-            $pagelist = '<ol>' . DOKU_LF;
278
-            foreach ($media as $m) {
279
-                $opts = array();
280
-                $link = ml($m ['id'], $opts, false, '&amp;', false);
281
-                $opts ['w'] = '100';
282
-                $src = ml($m ['id'], $opts);
283
-                $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> ('
284
-                    . $this->getLang('results_distance_prefix') . $page ['distance'] . '&nbsp;m) ' . hsc($desc)
285
-                    . '</li>' . DOKU_LF;
286
-            }
287
-            $pagelist .= '</ol>' . DOKU_LF;
288
-
289
-            print '<h2>' . $this->getLang('results_media') . hsc(' lat;lon: ' . $lat . ';' . $lon
290
-                . ' (geohash: ' . $geohash . ')') . '</h2>' . DOKU_LF;
291
-            print '<div class="level2">' . DOKU_LF;
292
-            print $pagelist;
293
-            print '</div>' . DOKU_LF;
294
-        }
295
-        print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. ';
296
-        if (strlen($geohash) > 1) {
297
-            $url = wl(getID(), array(
298
-                    'do' => 'findnearby',
299
-                    'geohash' => substr($geohash, 0, - 1)
300
-            ));
301
-            print '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>'
302
-                . DOKU_LF;
303
-        }
304
-        print '</div>' . DOKU_LF;
305
-    }
306
-
307
-    /**
308
-     * add media to spatial index.
309
-     *
310
-     * @param Doku_Event $event
311
-     *          event object by reference
312
-     * @param unknown $param
313
-     */
314
-    public function handleMediaUploaded(Doku_Event & $event, $param) {
315
-        // data[0] temporary file name (read from $_FILES)
316
-        // data[1] file name of the file being uploaded
317
-        // data[2] future directory id of the file being uploaded
318
-        // data[3] the mime type of the file being uploaded
319
-        // data[4] true if the uploaded file exists already
320
-        // data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
321
-
322
-        dbglog($event->data, "handleMediaUploaded::event data");
323
-
324
-        // check the list of mimetypes
325
-        // if it's a supported type call appropriate index function
326
-        if (substr_compare($event->data [3], 'image/jpeg', 0)) {
327
-            $indexer = plugin_load('helper', 'spatialhelper_index');
328
-            if ($indexer) {
329
-                $indexer->indexImage($event->data [2], $event->data [1]);
330
-            }
331
-        }
332
-        // TODO add image/tiff
333
-        // TODO kml, gpx, geojson...
334
-    }
335
-
336
-    /**
337
-     * removes the media from the index.
338
-     */
339
-    public function handleMediaDeleted(Doku_Event & $event, $param) {
340
-        // data['id'] ID data['unl'] unlink return code
341
-        // data['del'] Namespace directory unlink return code
342
-        // data['name'] file name data['path'] full path to the file
343
-        // data['size'] file size
344
-
345
-        dbglog($event->data, "handleMediaDeleted::event data");
346
-
347
-        // remove the media id from the index
348
-        $indexer = & plugin_load('helper', 'spatialhelper_index');
349
-        if ($indexer) {
350
-            $indexer->deleteFromIndex('media__' . $event->data ['id']);
351
-        }
352
-    }
353
-
354
-    /**
355
-     * add a link to the spatial sitemap files in the header.
356
-     *
357
-     * @param Doku_Event $event
358
-     *          the DokuWiki event. $event->data is a two-dimensional
359
-     *          array of all meta headers. The keys are meta, link and script.
360
-     * @param unknown_type $param
361
-     *
362
-     * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
363
-     */
364
-    public function handleMetaheaderOutput(Doku_Event $event, $param) {
365
-        // TODO maybe test for exist
366
-        $event->data ["link"] [] = array(
367
-                "type" => "application/atom+xml",
368
-                "rel" => "alternate",
369
-                "href" => ml($this->getConf('media_georss')),
370
-                "title" => "Spatial ATOM Feed"
371
-        );
372
-        $event->data ["link"] [] = array(
373
-                "type" => "application/vnd.google-earth.kml+xml",
374
-                "rel" => "alternate",
375
-                "href" => ml($this->getConf('media_kml')),
376
-                "title" => "KML Sitemap"
377
-        );
378
-    }
379
-
380
-    /**
381
-     * Calculate a new coordinate based on start, distance and bearing
382
-     *
383
-     * @param $start array
384
-     *          - start coordinate as decimal lat/lon pair
385
-     * @param $dist float
386
-     *          - distance in kilometers
387
-     * @param $brng float
388
-     *          - bearing in degrees (compass direction)
389
-     */
390
-    private function geoDestination($start, $dist, $brng) {
391
-        $lat1 = toRad($start [0]);
392
-        $lon1 = toRad($start [1]);
393
-        // http://en.wikipedia.org/wiki/Earth_radius
394
-        // average earth radius in km
395
-        $dist = $dist / 6371.01;
396
-        $brng = toRad($brng);
397
-
398
-        $lon2 = $lon1 + atan2(sin($brng) * sin($dist) * cos($lat1), cos($dist) - sin($lat1) * sin($lat2));
399
-        $lon2 = fmod(($lon2 + 3 * pi()), (2 * pi())) - pi();
400
-
401
-        return array(
402
-                toDeg($lat2),
403
-                toDeg($lon2)
404
-        );
405
-    }
406
-    private function toRad($deg) {
407
-        return $deg * pi() / 180;
408
-    }
409
-    private function toDeg($rad) {
410
-        return $rad * 180 / pi();
411
-    }
150
+			if (!empty ($this->getConf('sitemap_namespaces'))) {
151
+				$namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces')));
152
+				foreach ($namespaces as $namespace) {
153
+					$kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml'));
154
+					$rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss'));
155
+					dbglog(
156
+						$kmlN && $rssN,
157
+						"handleSitemapGenerateAfter, created KML / GeoRSS sitemap in $namespace, succes: "
158
+					);
159
+				}  
160
+			}
161
+			return $kml && $rss;
162
+		} else {
163
+			dbglog($helper, "createSpatialSitemap NOT loaded helper.");
164
+		}
165
+	}
166
+
167
+	/**
168
+	 * trap findnearby action.
169
+	 * This addional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown
170
+	 *
171
+	 * @param Doku_Event $event
172
+	 *          event object by reference
173
+	 * @param mixed $param
174
+	 *          not used
175
+	 */
176
+	public function handleActionActPreprocess(Doku_Event $event, $param) {
177
+		if ($event->data != 'findnearby') {
178
+			return;
179
+		}
180
+		$event->preventDefault();
181
+	}
182
+
183
+	/**
184
+	 * handle findnearby action.
185
+	 *
186
+	 * @param Doku_Event $event
187
+	 *          event object by reference
188
+	 * @param mixed $param
189
+	 *          associative array with keys
190
+	 *          'format'=> HTML | JSON
191
+	 */
192
+	public function findnearby(Doku_Event & $event, $param) {
193
+		if ($event->data != 'findnearby') {
194
+			return;
195
+		}
196
+		$event->preventDefault();
197
+
198
+		global $INPUT;
199
+		if ($helper = & plugin_load('helper', 'spatialhelper_search')) {
200
+			if ($INPUT->has('lat') && $INPUT->has('lon')) {
201
+				$results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon'));
202
+			} elseif ($INPUT->has('geohash')) {
203
+				$results = $helper->findNearby($INPUT->str('geohash'));
204
+			} else {
205
+				$results = array(
206
+						'error' => hsc($this->getLang('invalidinput'))
207
+				);
208
+			}
209
+		}
210
+
211
+		$showMedia = $INPUT->bool('showMedia', true);
212
+
213
+		switch ($param['format']) {
214
+			case 'JSON' :
215
+				$this->printJSON($results);
216
+				break;
217
+			case 'HTML' :
218
+			// fall through to default
219
+			default :
220
+				$this->printHTML($results, $showMedia);
221
+				break;
222
+		}
223
+	}
224
+
225
+	/**
226
+	 * Print seachresults as HTML lists.
227
+	 *
228
+	 * @param array $searchresults
229
+	 */
230
+	private function printJSON($searchresults) {
231
+		require_once DOKU_INC . 'inc/JSON.php';
232
+		$json = new JSON();
233
+		header('Content-Type: application/json');
234
+		print $json->encode($searchresults);
235
+	}
236
+
237
+	/**
238
+	 * Print seachresults as HTML lists.
239
+	 *
240
+	 * @param array $searchresults
241
+	 * @param boolean $showMedia
242
+	 */
243
+	private function printHTML($searchresults, $showMedia = true) {
244
+		$pages = (array) ($searchresults ['pages']);
245
+		$media = (array) $searchresults ['media'];
246
+		$lat = (float) $searchresults ['lat'];
247
+		$lon = (float) $searchresults ['lon'];
248
+		$geohash = (string) $searchresults ['geohash'];
249
+
250
+		if (isset ($searchresults ['error'])) {
251
+			print '<div class="level1"><p>' . hsc($results ['error']) . '</p></div>';
252
+			return;
253
+		}
254
+
255
+		// print a HTML list
256
+		print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF;
257
+		print '<div class="level1">' . DOKU_LF;
258
+		if (!empty ($pages)) {
259
+			$pagelist = '<ol>' . DOKU_LF;
260
+			foreach ($pages as $page) {
261
+				$pagelist .= '<li>' . html_wikilink(':' . $page ['id'], useHeading('navigation') ? null :
262
+					noNS($page ['id'])) . ' (' . $this->getLang('results_distance_prefix')
263
+						. $page ['distance'] . '&nbsp;m) ' . $page ['description'] . '</li>' . DOKU_LF;
264
+			}
265
+			$pagelist .= '</ol>' . DOKU_LF;
266
+
267
+			print '<h2>' . $this->getLang('results_pages') . hsc(' lat;lon: ' . $lat . ';' . $lon
268
+				. ' (geohash: ' . $geohash . ')') . '</h2>';
269
+			print '<div class="level2">' . DOKU_LF;
270
+			print $pagelist;
271
+			print '</div>' . DOKU_LF;
272
+		} else {
273
+			print '<p>' . hsc($this->getLang('nothingfound')) . '</p>';
274
+		}
275
+
276
+		if (!empty ($media) && $showMedia) {
277
+			$pagelist = '<ol>' . DOKU_LF;
278
+			foreach ($media as $m) {
279
+				$opts = array();
280
+				$link = ml($m ['id'], $opts, false, '&amp;', false);
281
+				$opts ['w'] = '100';
282
+				$src = ml($m ['id'], $opts);
283
+				$pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> ('
284
+					. $this->getLang('results_distance_prefix') . $page ['distance'] . '&nbsp;m) ' . hsc($desc)
285
+					. '</li>' . DOKU_LF;
286
+			}
287
+			$pagelist .= '</ol>' . DOKU_LF;
288
+
289
+			print '<h2>' . $this->getLang('results_media') . hsc(' lat;lon: ' . $lat . ';' . $lon
290
+				. ' (geohash: ' . $geohash . ')') . '</h2>' . DOKU_LF;
291
+			print '<div class="level2">' . DOKU_LF;
292
+			print $pagelist;
293
+			print '</div>' . DOKU_LF;
294
+		}
295
+		print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. ';
296
+		if (strlen($geohash) > 1) {
297
+			$url = wl(getID(), array(
298
+					'do' => 'findnearby',
299
+					'geohash' => substr($geohash, 0, - 1)
300
+			));
301
+			print '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>'
302
+				. DOKU_LF;
303
+		}
304
+		print '</div>' . DOKU_LF;
305
+	}
306
+
307
+	/**
308
+	 * add media to spatial index.
309
+	 *
310
+	 * @param Doku_Event $event
311
+	 *          event object by reference
312
+	 * @param unknown $param
313
+	 */
314
+	public function handleMediaUploaded(Doku_Event & $event, $param) {
315
+		// data[0] temporary file name (read from $_FILES)
316
+		// data[1] file name of the file being uploaded
317
+		// data[2] future directory id of the file being uploaded
318
+		// data[3] the mime type of the file being uploaded
319
+		// data[4] true if the uploaded file exists already
320
+		// data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
321
+
322
+		dbglog($event->data, "handleMediaUploaded::event data");
323
+
324
+		// check the list of mimetypes
325
+		// if it's a supported type call appropriate index function
326
+		if (substr_compare($event->data [3], 'image/jpeg', 0)) {
327
+			$indexer = plugin_load('helper', 'spatialhelper_index');
328
+			if ($indexer) {
329
+				$indexer->indexImage($event->data [2], $event->data [1]);
330
+			}
331
+		}
332
+		// TODO add image/tiff
333
+		// TODO kml, gpx, geojson...
334
+	}
335
+
336
+	/**
337
+	 * removes the media from the index.
338
+	 */
339
+	public function handleMediaDeleted(Doku_Event & $event, $param) {
340
+		// data['id'] ID data['unl'] unlink return code
341
+		// data['del'] Namespace directory unlink return code
342
+		// data['name'] file name data['path'] full path to the file
343
+		// data['size'] file size
344
+
345
+		dbglog($event->data, "handleMediaDeleted::event data");
346
+
347
+		// remove the media id from the index
348
+		$indexer = & plugin_load('helper', 'spatialhelper_index');
349
+		if ($indexer) {
350
+			$indexer->deleteFromIndex('media__' . $event->data ['id']);
351
+		}
352
+	}
353
+
354
+	/**
355
+	 * add a link to the spatial sitemap files in the header.
356
+	 *
357
+	 * @param Doku_Event $event
358
+	 *          the DokuWiki event. $event->data is a two-dimensional
359
+	 *          array of all meta headers. The keys are meta, link and script.
360
+	 * @param unknown_type $param
361
+	 *
362
+	 * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
363
+	 */
364
+	public function handleMetaheaderOutput(Doku_Event $event, $param) {
365
+		// TODO maybe test for exist
366
+		$event->data ["link"] [] = array(
367
+				"type" => "application/atom+xml",
368
+				"rel" => "alternate",
369
+				"href" => ml($this->getConf('media_georss')),
370
+				"title" => "Spatial ATOM Feed"
371
+		);
372
+		$event->data ["link"] [] = array(
373
+				"type" => "application/vnd.google-earth.kml+xml",
374
+				"rel" => "alternate",
375
+				"href" => ml($this->getConf('media_kml')),
376
+				"title" => "KML Sitemap"
377
+		);
378
+	}
379
+
380
+	/**
381
+	 * Calculate a new coordinate based on start, distance and bearing
382
+	 *
383
+	 * @param $start array
384
+	 *          - start coordinate as decimal lat/lon pair
385
+	 * @param $dist float
386
+	 *          - distance in kilometers
387
+	 * @param $brng float
388
+	 *          - bearing in degrees (compass direction)
389
+	 */
390
+	private function geoDestination($start, $dist, $brng) {
391
+		$lat1 = toRad($start [0]);
392
+		$lon1 = toRad($start [1]);
393
+		// http://en.wikipedia.org/wiki/Earth_radius
394
+		// average earth radius in km
395
+		$dist = $dist / 6371.01;
396
+		$brng = toRad($brng);
397
+
398
+		$lon2 = $lon1 + atan2(sin($brng) * sin($dist) * cos($lat1), cos($dist) - sin($lat1) * sin($lat2));
399
+		$lon2 = fmod(($lon2 + 3 * pi()), (2 * pi())) - pi();
400
+
401
+		return array(
402
+				toDeg($lat2),
403
+				toDeg($lon2)
404
+		);
405
+	}
406
+	private function toRad($deg) {
407
+		return $deg * pi() / 180;
408
+	}
409
+	private function toDeg($rad) {
410
+		return $rad * 180 / pi();
411
+	}
412 412
 }
Please login to merge, or discard this patch.
helper/search.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -22,175 +22,175 @@
 block discarded – undo
22 22
  * @author Mark Prins
23 23
  */
24 24
 class helper_plugin_spatialhelper_search extends DokuWiki_Plugin {
25
-    /**
26
-     * spatial index.
27
-     *
28
-     * @var array
29
-     */
30
-    protected $spatial_idx = array();
25
+	/**
26
+	 * spatial index.
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected $spatial_idx = array();
31 31
 
32
-    /**
33
-     * Precision, Distance of Adjacent Cell in Meters.
34
-     *
35
-     * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance
36
-     *
37
-     * @var float
38
-     */
39
-    private $precision = array(
40
-            5003530,
41
-            625441,
42
-            123264,
43
-            19545,
44
-            3803,
45
-            610,
46
-            118,
47
-            19,
48
-            3.7,
49
-            0.6
50
-    );
32
+	/**
33
+	 * Precision, Distance of Adjacent Cell in Meters.
34
+	 *
35
+	 * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance
36
+	 *
37
+	 * @var float
38
+	 */
39
+	private $precision = array(
40
+			5003530,
41
+			625441,
42
+			123264,
43
+			19545,
44
+			3803,
45
+			610,
46
+			118,
47
+			19,
48
+			3.7,
49
+			0.6
50
+	);
51 51
 
52
-    /**
53
-     * handle to the geoPHP plugin.
54
-     */
55
-    protected $geophp;
52
+	/**
53
+	 * handle to the geoPHP plugin.
54
+	 */
55
+	protected $geophp;
56 56
 
57
-    /**
58
-     * constructor; initialize/load spatial index.
59
-     */
60
-    public function __construct() {
61
-        // parent::__construct ();
62
-        global $conf;
57
+	/**
58
+	 * constructor; initialize/load spatial index.
59
+	 */
60
+	public function __construct() {
61
+		// parent::__construct ();
62
+		global $conf;
63 63
 
64
-        if (!$geophp = &plugin_load('helper', 'geophp')) {
65
-            $message = 'helper_plugin_spatialhelper_search::spatialhelper_search: geophp plugin is not available.';
66
-            msg($message, - 1);
67
-            return "";
68
-        }
64
+		if (!$geophp = &plugin_load('helper', 'geophp')) {
65
+			$message = 'helper_plugin_spatialhelper_search::spatialhelper_search: geophp plugin is not available.';
66
+			msg($message, - 1);
67
+			return "";
68
+		}
69 69
 
70
-        $idx_dir = $conf ['indexdir'];
71
-        if (!@file_exists($idx_dir . '/spatial.idx')) {
72
-            $indexer = plugin_load('helper', 'spatialhelper_index');
73
-        }
70
+		$idx_dir = $conf ['indexdir'];
71
+		if (!@file_exists($idx_dir . '/spatial.idx')) {
72
+			$indexer = plugin_load('helper', 'spatialhelper_index');
73
+		}
74 74
 
75
-        $this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false));
76
-    }
75
+		$this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false));
76
+	}
77 77
 
78
-    /**
79
-     * Find locations based on the coordinate pair.
80
-     *
81
-     * @param numeric $lat
82
-     *          The y coordinate (or latitude)
83
-     * @param numeric $lon
84
-     *          The x coordinate (or longitude)
85
-     */
86
-    public function findNearbyLatLon($lat, $lon) {
87
-        $geometry = new Point($lon, $lat);
88
-        return $this->findNearby($geometry->out('geohash'), $geometry);
89
-    }
78
+	/**
79
+	 * Find locations based on the coordinate pair.
80
+	 *
81
+	 * @param numeric $lat
82
+	 *          The y coordinate (or latitude)
83
+	 * @param numeric $lon
84
+	 *          The x coordinate (or longitude)
85
+	 */
86
+	public function findNearbyLatLon($lat, $lon) {
87
+		$geometry = new Point($lon, $lat);
88
+		return $this->findNearby($geometry->out('geohash'), $geometry);
89
+	}
90 90
 
91
-    /**
92
-     * finds nearby elements in the index based on the geohash.
93
-     * returns a list of documents and the bunding box.
94
-     *
95
-     * @param string $geohash
96
-     * @param Point $p
97
-     *          optional point
98
-     * @return array of ...
99
-     */
100
-    public function findNearby($geohash, Point $p = null) {
101
-        $_geohashClass = new Geohash();
102
-        if (!$p) {
103
-            $decodedPoint = $_geohashClass->read($geohash);
104
-        } else {
105
-            $decodedPoint = $p;
106
-        }
91
+	/**
92
+	 * finds nearby elements in the index based on the geohash.
93
+	 * returns a list of documents and the bunding box.
94
+	 *
95
+	 * @param string $geohash
96
+	 * @param Point $p
97
+	 *          optional point
98
+	 * @return array of ...
99
+	 */
100
+	public function findNearby($geohash, Point $p = null) {
101
+		$_geohashClass = new Geohash();
102
+		if (!$p) {
103
+			$decodedPoint = $_geohashClass->read($geohash);
104
+		} else {
105
+			$decodedPoint = $p;
106
+		}
107 107
 
108
-        // find adjacent blocks
109
-        $adjacent = array();
110
-        $adjacent ['center'] = $geohash;
111
-        $adjacent ['top'] = $_geohashClass->adjacent($adjacent ['center'], 'top');
112
-        $adjacent ['bottom'] = $_geohashClass->adjacent($adjacent ['center'], 'bottom');
113
-        $adjacent ['right'] = $_geohashClass->adjacent($adjacent ['center'], 'right');
114
-        $adjacent ['left'] = $_geohashClass->adjacent($adjacent ['center'], 'left');
115
-        $adjacent ['topleft'] = $_geohashClass->adjacent($adjacent ['left'], 'top');
116
-        $adjacent ['topright'] = $_geohashClass->adjacent($adjacent ['right'], 'top');
117
-        $adjacent ['bottomright'] = $_geohashClass->adjacent($adjacent ['right'], 'bottom');
118
-        $adjacent ['bottomleft'] = $_geohashClass->adjacent($adjacent ['left'], 'bottom');
119
-        dbglog($adjacent, "adjacent geo hashes:");
108
+		// find adjacent blocks
109
+		$adjacent = array();
110
+		$adjacent ['center'] = $geohash;
111
+		$adjacent ['top'] = $_geohashClass->adjacent($adjacent ['center'], 'top');
112
+		$adjacent ['bottom'] = $_geohashClass->adjacent($adjacent ['center'], 'bottom');
113
+		$adjacent ['right'] = $_geohashClass->adjacent($adjacent ['center'], 'right');
114
+		$adjacent ['left'] = $_geohashClass->adjacent($adjacent ['center'], 'left');
115
+		$adjacent ['topleft'] = $_geohashClass->adjacent($adjacent ['left'], 'top');
116
+		$adjacent ['topright'] = $_geohashClass->adjacent($adjacent ['right'], 'top');
117
+		$adjacent ['bottomright'] = $_geohashClass->adjacent($adjacent ['right'], 'bottom');
118
+		$adjacent ['bottomleft'] = $_geohashClass->adjacent($adjacent ['left'], 'bottom');
119
+		dbglog($adjacent, "adjacent geo hashes:");
120 120
 
121
-        // find all the pages in the index that overlap with the adjacent hashes
122
-        $docIds = array();
123
-        foreach ($adjacent as $adjHash) {
124
-            if (is_array($this->spatial_idx)) {
125
-                foreach ($this->spatial_idx as $_geohash => $_docIds) {
126
-                    if (strstr($_geohash, $adjHash)) {
127
-                        // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" );
128
-                        // if $adjHash similar to geohash
129
-                        $docIds = array_merge($docIds, $_docIds);
130
-                    }
131
-                }
132
-            }
133
-        }
134
-        $docIds = array_unique($docIds);
135
-        dbglog($docIds, "found docIDs");
121
+		// find all the pages in the index that overlap with the adjacent hashes
122
+		$docIds = array();
123
+		foreach ($adjacent as $adjHash) {
124
+			if (is_array($this->spatial_idx)) {
125
+				foreach ($this->spatial_idx as $_geohash => $_docIds) {
126
+					if (strstr($_geohash, $adjHash)) {
127
+						// dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" );
128
+						// if $adjHash similar to geohash
129
+						$docIds = array_merge($docIds, $_docIds);
130
+					}
131
+				}
132
+			}
133
+		}
134
+		$docIds = array_unique($docIds);
135
+		dbglog($docIds, "found docIDs");
136 136
 
137
-        // create associative array of pages + calculate distance
138
-        $pages = array();
139
-        $media = array();
140
-        $indexer = plugin_load('helper', 'spatialhelper_index');
137
+		// create associative array of pages + calculate distance
138
+		$pages = array();
139
+		$media = array();
140
+		$indexer = plugin_load('helper', 'spatialhelper_index');
141 141
 
142
-        foreach ($docIds as $id) {
143
-            if (strpos($id, 'media__', 0) === 0) {
144
-                $id = substr($id, strlen('media__'));
145
-                if (auth_quickaclcheck($id) >= /*AUTH_READ*/1) {
146
-                    $point = $indexer->getCoordsFromExif($id);
147
-                    $line = new LineString([
148
-                            $decodedPoint,
149
-                            $point
150
-                    ]);
151
-                    $media [] = array(
152
-                            'id' => $id,
153
-                            'distance' => (int) ($line->greatCircleLength()),
154
-                            'lat' => $point->y(),
155
-                            'lon' => $point->x()
156
-                    // optionally add other meta such as tag, description...
157
-                                        );
158
-                }
159
-            } else {
160
-                if (auth_quickaclcheck($id) >= /*AUTH_READ*/1) {
161
-                    $geotags = p_get_metadata($id, 'geo');
162
-                    $point = new Point($geotags ['lon'], $geotags ['lat']);
163
-                    $line = new LineString([
164
-                            $decodedPoint,
165
-                            $point
166
-                    ]);
167
-                    $pages [] = array(
168
-                            'id' => $id,
169
-                            'distance' => (int) ($line->greatCircleLength()),
170
-                            'description' => p_get_metadata($id, 'description')['abstract'],
171
-                            'lat' => $geotags ['lat'],
172
-                            'lon' => $geotags ['lon']
173
-                    // optionally add other meta such as tag...
174
-                                        );
175
-                }
176
-            }
177
-        }
142
+		foreach ($docIds as $id) {
143
+			if (strpos($id, 'media__', 0) === 0) {
144
+				$id = substr($id, strlen('media__'));
145
+				if (auth_quickaclcheck($id) >= /*AUTH_READ*/1) {
146
+					$point = $indexer->getCoordsFromExif($id);
147
+					$line = new LineString([
148
+							$decodedPoint,
149
+							$point
150
+					]);
151
+					$media [] = array(
152
+							'id' => $id,
153
+							'distance' => (int) ($line->greatCircleLength()),
154
+							'lat' => $point->y(),
155
+							'lon' => $point->x()
156
+					// optionally add other meta such as tag, description...
157
+										);
158
+				}
159
+			} else {
160
+				if (auth_quickaclcheck($id) >= /*AUTH_READ*/1) {
161
+					$geotags = p_get_metadata($id, 'geo');
162
+					$point = new Point($geotags ['lon'], $geotags ['lat']);
163
+					$line = new LineString([
164
+							$decodedPoint,
165
+							$point
166
+					]);
167
+					$pages [] = array(
168
+							'id' => $id,
169
+							'distance' => (int) ($line->greatCircleLength()),
170
+							'description' => p_get_metadata($id, 'description')['abstract'],
171
+							'lat' => $geotags ['lat'],
172
+							'lon' => $geotags ['lon']
173
+					// optionally add other meta such as tag...
174
+										);
175
+				}
176
+			}
177
+		}
178 178
 
179
-        // sort all the pages/media using distance
180
-        usort($pages, function ($a, $b) {
181
-            return strnatcmp($a ['distance'], $b ['distance']);
182
-        } );
183
-        usort($media, function ($a, $b) {
184
-            return strnatcmp($a ['distance'], $b ['distance']);
185
-        } );
179
+		// sort all the pages/media using distance
180
+		usort($pages, function ($a, $b) {
181
+			return strnatcmp($a ['distance'], $b ['distance']);
182
+		} );
183
+		usort($media, function ($a, $b) {
184
+			return strnatcmp($a ['distance'], $b ['distance']);
185
+		} );
186 186
 
187
-        return array(
188
-                'pages' => $pages,
189
-                'media' => $media,
190
-                'lat' => $decodedPoint->y(),
191
-                'lon' => $decodedPoint->x(),
192
-                'geohash' => $geohash,
193
-                'precision' => $this->precision [strlen($geohash)]
194
-        );
195
-    }
187
+		return array(
188
+				'pages' => $pages,
189
+				'media' => $media,
190
+				'lat' => $decodedPoint->y(),
191
+				'lon' => $decodedPoint->x(),
192
+				'geohash' => $geohash,
193
+				'precision' => $this->precision [strlen($geohash)]
194
+		);
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
                     ]);
151 151
                     $media [] = array(
152 152
                             'id' => $id,
153
-                            'distance' => (int) ($line->greatCircleLength()),
153
+                            'distance' => ( int ) ($line->greatCircleLength()),
154 154
                             'lat' => $point->y(),
155 155
                             'lon' => $point->x()
156 156
                     // optionally add other meta such as tag, description...
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
                     ]);
167 167
                     $pages [] = array(
168 168
                             'id' => $id,
169
-                            'distance' => (int) ($line->greatCircleLength()),
169
+                            'distance' => ( int ) ($line->greatCircleLength()),
170 170
                             'description' => p_get_metadata($id, 'description')['abstract'],
171 171
                             'lat' => $geotags ['lat'],
172 172
                             'lon' => $geotags ['lon']
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
         }
178 178
 
179 179
         // sort all the pages/media using distance
180
-        usort($pages, function ($a, $b) {
180
+        usort($pages, function($a, $b) {
181 181
             return strnatcmp($a ['distance'], $b ['distance']);
182 182
         } );
183
-        usort($media, function ($a, $b) {
183
+        usort($media, function($a, $b) {
184 184
             return strnatcmp($a ['distance'], $b ['distance']);
185 185
         } );
186 186
 
Please login to merge, or discard this patch.
helper/index.php 1 patch
Indentation   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -22,279 +22,279 @@
 block discarded – undo
22 22
  * @author Mark Prins
23 23
  */
24 24
 class helper_plugin_spatialhelper_index extends DokuWiki_Plugin {
25
-    /**
26
-     * directory for index files.
27
-     *
28
-     * @var string
29
-     */
30
-    protected $idx_dir = '';
25
+	/**
26
+	 * directory for index files.
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $idx_dir = '';
31 31
 
32
-    /**
33
-     * spatial index, well lookup list/array so we can do spatial queries.
34
-     * entries should be: array("geohash" => {"id1","id3",})
35
-     *
36
-     * @var array
37
-     */
38
-    protected $spatial_idx = array();
32
+	/**
33
+	 * spatial index, well lookup list/array so we can do spatial queries.
34
+	 * entries should be: array("geohash" => {"id1","id3",})
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $spatial_idx = array();
39 39
 
40
-    /**
41
-     * handle to the geoPHP plugin.
42
-     */
43
-    protected $geophp;
40
+	/**
41
+	 * handle to the geoPHP plugin.
42
+	 */
43
+	protected $geophp;
44 44
 
45
-    /**
46
-     * Constructor, initialises the spatial index.
47
-     */
48
-    public function __construct() {
49
-        if (!$geophp = &plugin_load('helper', 'geophp')) {
50
-            $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: geophp plugin is not available.';
51
-            msg($message, - 1);
52
-            return "";
53
-        }
45
+	/**
46
+	 * Constructor, initialises the spatial index.
47
+	 */
48
+	public function __construct() {
49
+		if (!$geophp = &plugin_load('helper', 'geophp')) {
50
+			$message = 'helper_plugin_spatialhelper_index::spatialhelper_index: geophp plugin is not available.';
51
+			msg($message, - 1);
52
+			return "";
53
+		}
54 54
 
55
-        global $conf;
56
-        $this->idx_dir = $conf ['indexdir'];
57
-        // test if there is a spatialindex, if not build one for the wiki
58
-        if (!@file_exists($this->idx_dir . '/spatial.idx')) {
59
-            // creates and stores the index
60
-            $this->generateSpatialIndex();
61
-        } else {
62
-            $this->spatial_idx = unserialize(io_readFile($this->idx_dir . '/spatial.idx', false));
63
-            dbglog($this->spatial_idx, 'done loading spatial index');
64
-        }
65
-    }
55
+		global $conf;
56
+		$this->idx_dir = $conf ['indexdir'];
57
+		// test if there is a spatialindex, if not build one for the wiki
58
+		if (!@file_exists($this->idx_dir . '/spatial.idx')) {
59
+			// creates and stores the index
60
+			$this->generateSpatialIndex();
61
+		} else {
62
+			$this->spatial_idx = unserialize(io_readFile($this->idx_dir . '/spatial.idx', false));
63
+			dbglog($this->spatial_idx, 'done loading spatial index');
64
+		}
65
+	}
66 66
 
67
-    /**
68
-     * Update the spatial index for the page.
69
-     *
70
-     * @param string $id
71
-     *          the document ID
72
-     */
73
-    public function updateSpatialIndex($id) {
74
-        $geotags = p_get_metadata($id, 'geo');
75
-        if (empty ($geotags)) {
76
-            return false;
77
-        }
78
-        if (empty ($geotags ['lon']) || empty ($geotags ['lat'])) {
79
-            return false;
80
-        }
81
-        dbglog($geotags, "Geo metadata found for page $id");
82
-        $geometry = new Point($geotags ['lon'], $geotags ['lat']);
83
-        $geohash = $geometry->out('geohash');
84
-        dbglog('Update index for geohash: ' . $geohash);
85
-        $succes = $this->addToIndex($geohash, $id);
86
-    }
67
+	/**
68
+	 * Update the spatial index for the page.
69
+	 *
70
+	 * @param string $id
71
+	 *          the document ID
72
+	 */
73
+	public function updateSpatialIndex($id) {
74
+		$geotags = p_get_metadata($id, 'geo');
75
+		if (empty ($geotags)) {
76
+			return false;
77
+		}
78
+		if (empty ($geotags ['lon']) || empty ($geotags ['lat'])) {
79
+			return false;
80
+		}
81
+		dbglog($geotags, "Geo metadata found for page $id");
82
+		$geometry = new Point($geotags ['lon'], $geotags ['lat']);
83
+		$geohash = $geometry->out('geohash');
84
+		dbglog('Update index for geohash: ' . $geohash);
85
+		$succes = $this->addToIndex($geohash, $id);
86
+	}
87 87
 
88
-    /**
89
-     * Looks up the geohash(es) for the document in the index.
90
-     *
91
-     * @param String $id
92
-     *          document ID
93
-     * @param array $index
94
-     *          spatial index
95
-     */
96
-    public function findHashesForId($id, $index) {
97
-        $hashes = array();
98
-        foreach ($index as $hash => $docIds) {
99
-            if (in_array($id, $docIds, false)) {
100
-                $hashes [] = $hash;
101
-            }
102
-        }
103
-        dbglog($hashes, "Found the following hashes for $id (should only be 1)");
104
-        return $hashes;
105
-    }
88
+	/**
89
+	 * Looks up the geohash(es) for the document in the index.
90
+	 *
91
+	 * @param String $id
92
+	 *          document ID
93
+	 * @param array $index
94
+	 *          spatial index
95
+	 */
96
+	public function findHashesForId($id, $index) {
97
+		$hashes = array();
98
+		foreach ($index as $hash => $docIds) {
99
+			if (in_array($id, $docIds, false)) {
100
+				$hashes [] = $hash;
101
+			}
102
+		}
103
+		dbglog($hashes, "Found the following hashes for $id (should only be 1)");
104
+		return $hashes;
105
+	}
106 106
 
107
-    /**
108
-     * Deletes the page from the index.
109
-     *
110
-     * @param String $id
111
-     *          document ID
112
-     */
113
-    public function deleteFromIndex($id) {
114
-        // check the index for document
115
-        $knownHashes = $this->findHashesForId($id, $this->spatial_idx);
116
-        if (empty ($knownHashes)) {
117
-            return;
118
-        }
107
+	/**
108
+	 * Deletes the page from the index.
109
+	 *
110
+	 * @param String $id
111
+	 *          document ID
112
+	 */
113
+	public function deleteFromIndex($id) {
114
+		// check the index for document
115
+		$knownHashes = $this->findHashesForId($id, $this->spatial_idx);
116
+		if (empty ($knownHashes)) {
117
+			return;
118
+		}
119 119
 
120
-        // TODO shortcut, need to make sure there is only one element, if not the index is corrupt
121
-        $knownHash = $knownHashes [0];
122
-        $knownIds = $this->spatial_idx [$knownHash];
123
-        $i = array_search($id, $knownIds);
124
-        dbglog("removing: $knownIds[$i] from the index.");
125
-        unset ($knownIds [$i]);
126
-        $this->spatial_idx [$knownHash] = $knownIds;
127
-        if (empty ($this->spatial_idx [$knownHash])) {
128
-            // dbglog ( "removing key: $knownHash from the index." );
129
-            unset ($this->spatial_idx [$knownHash]);
130
-        }
131
-        $succes = $this->saveIndex();
132
-    }
120
+		// TODO shortcut, need to make sure there is only one element, if not the index is corrupt
121
+		$knownHash = $knownHashes [0];
122
+		$knownIds = $this->spatial_idx [$knownHash];
123
+		$i = array_search($id, $knownIds);
124
+		dbglog("removing: $knownIds[$i] from the index.");
125
+		unset ($knownIds [$i]);
126
+		$this->spatial_idx [$knownHash] = $knownIds;
127
+		if (empty ($this->spatial_idx [$knownHash])) {
128
+			// dbglog ( "removing key: $knownHash from the index." );
129
+			unset ($this->spatial_idx [$knownHash]);
130
+		}
131
+		$succes = $this->saveIndex();
132
+	}
133 133
 
134
-    /**
135
-     * Save spatial index.
136
-     */
137
-    private function saveIndex() {
138
-        return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx));
139
-    }
134
+	/**
135
+	 * Save spatial index.
136
+	 */
137
+	private function saveIndex() {
138
+		return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx));
139
+	}
140 140
 
141
-    /**
142
-     * (re-)Generates the spatial index by running through all the pages in the wiki.
143
-     *
144
-     * @todo add an option to erase the old index
145
-     */
146
-    public function generateSpatialIndex() {
147
-        global $conf;
148
-        require_once (DOKU_INC . 'inc/search.php');
149
-        $pages = array();
150
-        search($pages, $conf ['datadir'], 'search_allpages', array());
151
-        foreach ($pages as $page) {
152
-            $this->updateSpatialIndex($page ['id']);
153
-        }
154
-        // media
155
-        $media = array();
156
-        search($media, $conf ['mediadir'], 'search_media', array());
157
-        foreach ($media as $medium) {
158
-            if ($medium ['isimg']) {
159
-                $this->indexImage($medium);
160
-            }
161
-        }
162
-        return true;
163
-    }
141
+	/**
142
+	 * (re-)Generates the spatial index by running through all the pages in the wiki.
143
+	 *
144
+	 * @todo add an option to erase the old index
145
+	 */
146
+	public function generateSpatialIndex() {
147
+		global $conf;
148
+		require_once (DOKU_INC . 'inc/search.php');
149
+		$pages = array();
150
+		search($pages, $conf ['datadir'], 'search_allpages', array());
151
+		foreach ($pages as $page) {
152
+			$this->updateSpatialIndex($page ['id']);
153
+		}
154
+		// media
155
+		$media = array();
156
+		search($media, $conf ['mediadir'], 'search_media', array());
157
+		foreach ($media as $medium) {
158
+			if ($medium ['isimg']) {
159
+				$this->indexImage($medium);
160
+			}
161
+		}
162
+		return true;
163
+	}
164 164
 
165
-    /**
166
-     * Add an index entry for this file having EXIF / IPTC data.
167
-     *
168
-     * @param unknown_type $img Dokuwiki image
169
-     * @see http://www.php.net/manual/en/function.iptcparse.php
170
-     * @see http://php.net/manual/en/function.exif-read-data.php
171
-     *
172
-     * @return boolean true when image was succesfully added to the index.
173
-     */
174
-    public function indexImage($img) {
175
-        // test for supported files (jpeg only)
176
-        if (
177
-            (substr($img ['file'], - strlen('.jpg')) !== '.jpg') and
178
-            (substr($img ['file'], - strlen('.jpeg')) !== '.jpeg')) {
179
-            return false;
180
-        }
165
+	/**
166
+	 * Add an index entry for this file having EXIF / IPTC data.
167
+	 *
168
+	 * @param unknown_type $img Dokuwiki image
169
+	 * @see http://www.php.net/manual/en/function.iptcparse.php
170
+	 * @see http://php.net/manual/en/function.exif-read-data.php
171
+	 *
172
+	 * @return boolean true when image was succesfully added to the index.
173
+	 */
174
+	public function indexImage($img) {
175
+		// test for supported files (jpeg only)
176
+		if (
177
+			(substr($img ['file'], - strlen('.jpg')) !== '.jpg') and
178
+			(substr($img ['file'], - strlen('.jpeg')) !== '.jpeg')) {
179
+			return false;
180
+		}
181 181
 
182
-        $geometry = $this->getCoordsFromExif($img ['id']);
183
-        if (!$geometry) {
184
-            return false;
185
-        }
186
-        $geohash = $geometry->out('geohash');
187
-        // TODO truncate the geohash to something reasonable, otherwise they are
188
-        // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
189
-        // precise, limit at ~9 as most GPS are not submeter accurate
190
-        return $this->addToIndex($geohash, 'media__' . $img ['id']);
191
-    }
182
+		$geometry = $this->getCoordsFromExif($img ['id']);
183
+		if (!$geometry) {
184
+			return false;
185
+		}
186
+		$geohash = $geometry->out('geohash');
187
+		// TODO truncate the geohash to something reasonable, otherwise they are
188
+		// useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
189
+		// precise, limit at ~9 as most GPS are not submeter accurate
190
+		return $this->addToIndex($geohash, 'media__' . $img ['id']);
191
+	}
192 192
 
193
-    /**
194
-     * retrieve GPS decimal coordinates from exif.
195
-     *
196
-     * @param
197
-     *          $id
198
-     * @return Point or false
199
-     */
200
-    public function getCoordsFromExif($id) {
201
-        $exif = exif_read_data(mediaFN($id), 0, true);
202
-        if (empty ($exif ['GPS'])) {
203
-            return false;
204
-        }
193
+	/**
194
+	 * retrieve GPS decimal coordinates from exif.
195
+	 *
196
+	 * @param
197
+	 *          $id
198
+	 * @return Point or false
199
+	 */
200
+	public function getCoordsFromExif($id) {
201
+		$exif = exif_read_data(mediaFN($id), 0, true);
202
+		if (empty ($exif ['GPS'])) {
203
+			return false;
204
+		}
205 205
 
206
-        $lat = $this->convertDMStoD(array(
207
-                $exif ['GPS'] ['GPSLatitude'] [0],
208
-                $exif ['GPS'] ['GPSLatitude'] [1],
209
-                $exif ['GPS'] ['GPSLatitude'] [2],
210
-                $exif ['GPS'] ['GPSLatitudeRef']
211
-        ));
206
+		$lat = $this->convertDMStoD(array(
207
+				$exif ['GPS'] ['GPSLatitude'] [0],
208
+				$exif ['GPS'] ['GPSLatitude'] [1],
209
+				$exif ['GPS'] ['GPSLatitude'] [2],
210
+				$exif ['GPS'] ['GPSLatitudeRef']
211
+		));
212 212
 
213
-        $lon = $this->convertDMStoD(array(
214
-                $exif ['GPS'] ['GPSLongitude'] [0],
215
-                $exif ['GPS'] ['GPSLongitude'] [1],
216
-                $exif ['GPS'] ['GPSLongitude'] [2],
217
-                $exif ['GPS'] ['GPSLongitudeRef']
218
-        ));
213
+		$lon = $this->convertDMStoD(array(
214
+				$exif ['GPS'] ['GPSLongitude'] [0],
215
+				$exif ['GPS'] ['GPSLongitude'] [1],
216
+				$exif ['GPS'] ['GPSLongitude'] [2],
217
+				$exif ['GPS'] ['GPSLongitudeRef']
218
+		));
219 219
 
220
-        return new Point($lon, $lat);
221
-    }
220
+		return new Point($lon, $lat);
221
+	}
222 222
 
223
-    /**
224
-     * Store the hash/id entry in the index.
225
-     *
226
-     * @param string $geohash
227
-     * @param string $id
228
-     *          page or media id
229
-     * @return boolean true when succesful
230
-     */
231
-    private function addToIndex($geohash, $id) {
232
-        $pageIds = array();
233
-        // check index for key/geohash
234
-        if (!array_key_exists($geohash, $this->spatial_idx)) {
235
-            dbglog("Geohash $geohash not in index, just add $id.");
236
-            $pageIds [] = $id;
237
-        } else {
238
-            dbglog('Geohash for document is in index, find it.');
239
-            // check the index for document
240
-            $knownHashes = $this->findHashesForId($id, $this->spatial_idx);
241
-            if (empty ($knownHashes)) {
242
-                dbglog("No index record found for document $id, just add");
243
-                $pageIds = $this->spatial_idx [$geohash];
244
-                $pageIds [] = $id;
245
-            }
246
-            // TODO shortcut, need to make sure there is only one element, if not the index is corrupt
247
-            $knownHash = $knownHashes [0];
223
+	/**
224
+	 * Store the hash/id entry in the index.
225
+	 *
226
+	 * @param string $geohash
227
+	 * @param string $id
228
+	 *          page or media id
229
+	 * @return boolean true when succesful
230
+	 */
231
+	private function addToIndex($geohash, $id) {
232
+		$pageIds = array();
233
+		// check index for key/geohash
234
+		if (!array_key_exists($geohash, $this->spatial_idx)) {
235
+			dbglog("Geohash $geohash not in index, just add $id.");
236
+			$pageIds [] = $id;
237
+		} else {
238
+			dbglog('Geohash for document is in index, find it.');
239
+			// check the index for document
240
+			$knownHashes = $this->findHashesForId($id, $this->spatial_idx);
241
+			if (empty ($knownHashes)) {
242
+				dbglog("No index record found for document $id, just add");
243
+				$pageIds = $this->spatial_idx [$geohash];
244
+				$pageIds [] = $id;
245
+			}
246
+			// TODO shortcut, need to make sure there is only one element, if not the index is corrupt
247
+			$knownHash = $knownHashes [0];
248 248
 
249
-            if ($knownHash == $geohash) {
250
-                dbglog("Document $id was found in index and has the same geohash, nothing to do.");
251
-                return true;
252
-            }
249
+			if ($knownHash == $geohash) {
250
+				dbglog("Document $id was found in index and has the same geohash, nothing to do.");
251
+				return true;
252
+			}
253 253
 
254
-            if (!empty ($knownHash)) {
255
-                dbglog("Document/media $id was found in index but has different geohash (it moved).");
256
-                $knownIds = $this->spatial_idx [$knownHash];
257
-                dbglog($knownIds, "Known id's for this hash:");
258
-                // remove it from the old geohash element
259
-                $i = array_search($id, $knownIds);
260
-                dbglog('Unsetting:' . $knownIds [$i]);
261
-                unset ($knownIds [$i]);
262
-                $this->spatial_idx [$knownHash] = $knownIds;
263
-                // set on new geohash element
264
-                $pageIds = $this->spatial_idx [$geohash];
265
-                $pageIds [] = $id;
266
-            }
267
-        }
268
-        // store and save
269
-        $this->spatial_idx [$geohash] = $pageIds;
270
-        return $this->saveIndex();
271
-    }
254
+			if (!empty ($knownHash)) {
255
+				dbglog("Document/media $id was found in index but has different geohash (it moved).");
256
+				$knownIds = $this->spatial_idx [$knownHash];
257
+				dbglog($knownIds, "Known id's for this hash:");
258
+				// remove it from the old geohash element
259
+				$i = array_search($id, $knownIds);
260
+				dbglog('Unsetting:' . $knownIds [$i]);
261
+				unset ($knownIds [$i]);
262
+				$this->spatial_idx [$knownHash] = $knownIds;
263
+				// set on new geohash element
264
+				$pageIds = $this->spatial_idx [$geohash];
265
+				$pageIds [] = $id;
266
+			}
267
+		}
268
+		// store and save
269
+		$this->spatial_idx [$geohash] = $pageIds;
270
+		return $this->saveIndex();
271
+	}
272 272
 
273
-    /**
274
-     * convert DegreesMinutesSeconds to Decimal degrees.
275
-     *
276
-     * @param array $param array of rational DMS
277
-     * @return number
278
-     */
279
-    public function convertDMStoD($param) {
280
-        if (!is_array($param)) {
281
-            $param = array($param);
282
-        }
283
-        $deg = $this->convertRationaltoFloat($param [0]);
284
-        $min = $this->convertRationaltoFloat($param [1]) / 60;
285
-        $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;
286
-        // Hemisphere (N, S, W or E)
287
-        $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;
288
-        return $hem * ($deg + $min + $sec);
289
-    }
273
+	/**
274
+	 * convert DegreesMinutesSeconds to Decimal degrees.
275
+	 *
276
+	 * @param array $param array of rational DMS
277
+	 * @return number
278
+	 */
279
+	public function convertDMStoD($param) {
280
+		if (!is_array($param)) {
281
+			$param = array($param);
282
+		}
283
+		$deg = $this->convertRationaltoFloat($param [0]);
284
+		$min = $this->convertRationaltoFloat($param [1]) / 60;
285
+		$sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;
286
+		// Hemisphere (N, S, W or E)
287
+		$hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;
288
+		return $hem * ($deg + $min + $sec);
289
+	}
290 290
 
291
-    public function convertRationaltoFloat($param) {
292
-        // rational64u
293
-        $nums = explode('/', $param);
294
-        if (intval($nums[1]) > 0) {
295
-            return intval($nums[0]) / intval($nums[1]);
296
-        } else {
297
-            return intval($nums[0]);
298
-        }
299
-    }
291
+	public function convertRationaltoFloat($param) {
292
+		// rational64u
293
+		$nums = explode('/', $param);
294
+		if (intval($nums[1]) > 0) {
295
+			return intval($nums[0]) / intval($nums[1]);
296
+		} else {
297
+			return intval($nums[0]);
298
+		}
299
+	}
300 300
 }
Please login to merge, or discard this patch.
helper/sitemap.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('DOKU_LF')) {
19
-    define('DOKU_LF', "\n");
19
+	define('DOKU_LF', "\n");
20 20
 }
21 21
 
22 22
 /**
@@ -26,218 +26,218 @@  discard block
 block discarded – undo
26 26
  * @author Mark Prins
27 27
  */
28 28
 class helper_plugin_spatialhelper_sitemap extends DokuWiki_Plugin {
29
-    /**
30
-     * spatial index.
31
-     */
32
-    private $spatial_idx = array();
33
-
34
-    /**
35
-     * constructor, load spatial index.
36
-     */
37
-    public function __construct() {
38
-        global $conf;
39
-        $idx_dir = $conf['indexdir'];
40
-        if (!@file_exists($idx_dir . '/spatial.idx')) {
41
-            $indexer = plugin_load('helper', 'spatialhelper_index');
42
-            $indexer->generateSpatialIndex();
43
-        }
44
-        $this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false));
45
-    }
46
-
47
-    public function getMethods() {
48
-        $result[] = array(
49
-                'name' => 'createGeoRSSSitemap',
50
-                'desc' => 'create a spatial sitemap in GeoRSS format.',
51
-                'params' => array(
52
-                        'path' => 'string'
53
-                ),
54
-                'return' => array(
55
-                        'success' => 'boolean'
56
-                )
57
-        );
58
-        $result[] = array(
59
-                'name' => 'createKMLSitemap',
60
-                'desc' => 'create a spatial sitemap in KML format.',
61
-                'params' => array(
62
-                        'path' => 'string'
63
-                ),
64
-                'return' => array(
65
-                        'success' => 'boolean'
66
-                )
67
-        );
68
-        return $result;
69
-    }
70
-
71
-    /**
72
-     * Create a GeoRSS Simple sitemap (Atom).
73
-     *
74
-     * @param $mediaID id
75
-     *          for the GeoRSS file
76
-     */
77
-    public function createGeoRSSSitemap($mediaID) {
78
-        global $conf;
79
-        $namespace = getNS($mediaID);
80
-
81
-        $idTag = 'tag:' . parse_url(DOKU_URL, PHP_URL_HOST) . ',';
82
-
83
-        $RSSstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF;
84
-        $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '
85
-        $RSSstart .= 'xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF;
86
-        $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF;
87
-        if (!empty($conf['tagline'])) {
88
-            $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF;
89
-        }
90
-        $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF;
91
-        $RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF;
92
-        $RSSstart .= '<link href="' . ml($mediaID, '', true, '&amp;', true) . '" rel="self" />' . DOKU_LF;
93
-        $RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF;
94
-        $RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) . '</id>' . DOKU_LF;
95
-        $RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF;
96
-
97
-        $RSSend = '</feed>' . DOKU_LF;
98
-
99
-        io_createNamespace($mediaID, 'media');
100
-        @touch(mediaFN($mediaID));
101
-        @chmod(mediaFN($mediaID), $conf['fmode']);
102
-        $fh = fopen(mediaFN($mediaID), 'w');
103
-        fwrite($fh, $RSSstart);
104
-
105
-        foreach ($this->spatial_idx as $idxEntry) {
106
-            // get list of id's
107
-            foreach ($idxEntry as $id) {
108
-                // for document item in the index
109
-                if (strpos($id, 'media__', 0) !== 0) {
110
-                    if ($this->skipPage($id, $namespace)) {
111
-                        continue;
112
-                    }
113
-
114
-                    $meta = p_get_metadata($id);
115
-
116
-                    // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
117
-                    $desc = strip_tags($meta['description']['abstract']);
118
-
119
-                    $entry = '<entry>' . DOKU_LF;
120
-                    $entry .= '  <title>' . $meta['title'] . '</title>' . DOKU_LF;
121
-                    $entry .= '  <summary>' . $desc . '</summary>' . DOKU_LF;
122
-                    $entry .= '  <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon']
123
-                        . '</georss:point>' . DOKU_LF;
124
-                    if ($meta['geo']['alt']) {
125
-                        $entry .= '  <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF;
126
-                    }
127
-                    $entry .= '  <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF;
128
-                    if (empty($meta['creator'])) {
129
-                        $meta['creator'] = $conf['title'];
130
-                    }
131
-                    $entry .= '  <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF;
132
-                    $entry .= '  <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF;
133
-                    $entry .= '  <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF;
134
-                    $entry .= '  <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':'
135
-                        . parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF;
136
-                    $entry .= '</entry>' . DOKU_LF;
137
-                    fwrite($fh, $entry);
138
-                }
139
-            }
140
-        }
141
-
142
-        fwrite($fh, $RSSend);
143
-        return fclose($fh);
144
-    }
145
-
146
-    /**
147
-     * Create a KML sitemap.
148
-     *
149
-     * @param $mediaID id
150
-     *          for the KML file
151
-     */
152
-    public function createKMLSitemap($mediaID) {
153
-        global $conf;
154
-        $namespace = getNS($mediaID);
155
-
156
-        $KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF;
157
-        $KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" ';
158
-        $KMLstart .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
159
-        $KMLstart .= 'xmlns:atom="http://www.w3.org/2005/Atom"';
160
-        $KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 ';
161
-        $KMLstart .= 'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF;
162
-        $KMLstart .= '<Document id="root_doc">' . DOKU_LF;
163
-        $KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF;
164
-        $KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF;
165
-        $KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF;
166
-        $KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>';
167
-        $KMLstart .= '<Icon><href>'
168
-            . DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF;
169
-
170
-        $KMLend = '</Document>' . DOKU_LF . '</kml>';
171
-
172
-        io_createNamespace($mediaID, 'media');
173
-        @touch(mediaFN($mediaID));
174
-        @chmod(mediaFN($mediaID), $conf['fmode']);
175
-
176
-        $fh = fopen(mediaFN($mediaID), 'w');
177
-        fwrite($fh, $KMLstart);
178
-
179
-        foreach ($this->spatial_idx as $idxEntry) {
180
-            // get list of id's
181
-            foreach ($idxEntry as $id) {
182
-                // for document item in the index
183
-                if (strpos($id, 'media__', 0) !== 0) {
184
-                    if ($this->skipPage($id, $namespace)) {
185
-                        continue;
186
-                    }
187
-
188
-                    $meta = p_get_metadata($id);
189
-
190
-                    // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
191
-                    $desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>';
192
-                    $desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>';
193
-
194
-                    // create an entry and store it
195
-                    $plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF;
196
-                    $plcm .= '  <name>' . $meta['title'] . '</name>' . DOKU_LF;
197
-                    // TODO escape quotes in: title="' . $meta['title'] . '"
198
-                    $plcm .= '  <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />'
199
-                        . DOKU_LF;
200
-                    if (!empty($meta['creator'])) {
201
-                        $entry .= '  <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>'
202
-                            . DOKU_LF;
203
-                    }
204
-
205
-                    $plcm .= '  <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF;
206
-                    $plcm .= '  <styleUrl>#icon</styleUrl>' . DOKU_LF;
207
-
208
-                    $plcm .= '  <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat'];
209
-                    if ($meta['geo']['alt']) {
210
-                        $plcm .= ',' . $meta['geo']['alt'];
211
-                    }
212
-                    $plcm .= '</coordinates></Point>' . DOKU_LF;
213
-                    $plcm .= '</Placemark>' . DOKU_LF;
214
-
215
-                    fwrite($fh, $plcm);
216
-                }
217
-            }
218
-        }
219
-        fwrite($fh, $KMLend);
220
-        return fclose($fh);
221
-    }
222
-    /**
223
-     * will return true for non-public or hidden pages or pages that are not below or in the namespace.
224
-     */
225
-    private function skipPage($id, $namespace) {
226
-        dbglog("helper_plugin_spatialhelper_sitemap::skipPage, check for $id in $namespace");
227
-        if (isHiddenPage($id)) {
228
-            return true;
229
-        }
230
-        if (auth_aclcheck($id, '', '') < AUTH_READ) {
231
-            return true;
232
-        }
233
-
234
-        if (!empty($namespace)) {
235
-            // only if id is in or below namespace
236
-            if (0 !== strpos(getNS($id), $namespace)) {
237
-                // dbglog("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace");
238
-                return true;
239
-            }
240
-        }
241
-        return false;
242
-    }
29
+	/**
30
+	 * spatial index.
31
+	 */
32
+	private $spatial_idx = array();
33
+
34
+	/**
35
+	 * constructor, load spatial index.
36
+	 */
37
+	public function __construct() {
38
+		global $conf;
39
+		$idx_dir = $conf['indexdir'];
40
+		if (!@file_exists($idx_dir . '/spatial.idx')) {
41
+			$indexer = plugin_load('helper', 'spatialhelper_index');
42
+			$indexer->generateSpatialIndex();
43
+		}
44
+		$this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false));
45
+	}
46
+
47
+	public function getMethods() {
48
+		$result[] = array(
49
+				'name' => 'createGeoRSSSitemap',
50
+				'desc' => 'create a spatial sitemap in GeoRSS format.',
51
+				'params' => array(
52
+						'path' => 'string'
53
+				),
54
+				'return' => array(
55
+						'success' => 'boolean'
56
+				)
57
+		);
58
+		$result[] = array(
59
+				'name' => 'createKMLSitemap',
60
+				'desc' => 'create a spatial sitemap in KML format.',
61
+				'params' => array(
62
+						'path' => 'string'
63
+				),
64
+				'return' => array(
65
+						'success' => 'boolean'
66
+				)
67
+		);
68
+		return $result;
69
+	}
70
+
71
+	/**
72
+	 * Create a GeoRSS Simple sitemap (Atom).
73
+	 *
74
+	 * @param $mediaID id
75
+	 *          for the GeoRSS file
76
+	 */
77
+	public function createGeoRSSSitemap($mediaID) {
78
+		global $conf;
79
+		$namespace = getNS($mediaID);
80
+
81
+		$idTag = 'tag:' . parse_url(DOKU_URL, PHP_URL_HOST) . ',';
82
+
83
+		$RSSstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF;
84
+		$RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '
85
+		$RSSstart .= 'xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF;
86
+		$RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF;
87
+		if (!empty($conf['tagline'])) {
88
+			$RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF;
89
+		}
90
+		$RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF;
91
+		$RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF;
92
+		$RSSstart .= '<link href="' . ml($mediaID, '', true, '&amp;', true) . '" rel="self" />' . DOKU_LF;
93
+		$RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF;
94
+		$RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) . '</id>' . DOKU_LF;
95
+		$RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF;
96
+
97
+		$RSSend = '</feed>' . DOKU_LF;
98
+
99
+		io_createNamespace($mediaID, 'media');
100
+		@touch(mediaFN($mediaID));
101
+		@chmod(mediaFN($mediaID), $conf['fmode']);
102
+		$fh = fopen(mediaFN($mediaID), 'w');
103
+		fwrite($fh, $RSSstart);
104
+
105
+		foreach ($this->spatial_idx as $idxEntry) {
106
+			// get list of id's
107
+			foreach ($idxEntry as $id) {
108
+				// for document item in the index
109
+				if (strpos($id, 'media__', 0) !== 0) {
110
+					if ($this->skipPage($id, $namespace)) {
111
+						continue;
112
+					}
113
+
114
+					$meta = p_get_metadata($id);
115
+
116
+					// $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
117
+					$desc = strip_tags($meta['description']['abstract']);
118
+
119
+					$entry = '<entry>' . DOKU_LF;
120
+					$entry .= '  <title>' . $meta['title'] . '</title>' . DOKU_LF;
121
+					$entry .= '  <summary>' . $desc . '</summary>' . DOKU_LF;
122
+					$entry .= '  <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon']
123
+						. '</georss:point>' . DOKU_LF;
124
+					if ($meta['geo']['alt']) {
125
+						$entry .= '  <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF;
126
+					}
127
+					$entry .= '  <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF;
128
+					if (empty($meta['creator'])) {
129
+						$meta['creator'] = $conf['title'];
130
+					}
131
+					$entry .= '  <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF;
132
+					$entry .= '  <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF;
133
+					$entry .= '  <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF;
134
+					$entry .= '  <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':'
135
+						. parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF;
136
+					$entry .= '</entry>' . DOKU_LF;
137
+					fwrite($fh, $entry);
138
+				}
139
+			}
140
+		}
141
+
142
+		fwrite($fh, $RSSend);
143
+		return fclose($fh);
144
+	}
145
+
146
+	/**
147
+	 * Create a KML sitemap.
148
+	 *
149
+	 * @param $mediaID id
150
+	 *          for the KML file
151
+	 */
152
+	public function createKMLSitemap($mediaID) {
153
+		global $conf;
154
+		$namespace = getNS($mediaID);
155
+
156
+		$KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF;
157
+		$KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" ';
158
+		$KMLstart .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
159
+		$KMLstart .= 'xmlns:atom="http://www.w3.org/2005/Atom"';
160
+		$KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 ';
161
+		$KMLstart .= 'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF;
162
+		$KMLstart .= '<Document id="root_doc">' . DOKU_LF;
163
+		$KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF;
164
+		$KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF;
165
+		$KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF;
166
+		$KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>';
167
+		$KMLstart .= '<Icon><href>'
168
+			. DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF;
169
+
170
+		$KMLend = '</Document>' . DOKU_LF . '</kml>';
171
+
172
+		io_createNamespace($mediaID, 'media');
173
+		@touch(mediaFN($mediaID));
174
+		@chmod(mediaFN($mediaID), $conf['fmode']);
175
+
176
+		$fh = fopen(mediaFN($mediaID), 'w');
177
+		fwrite($fh, $KMLstart);
178
+
179
+		foreach ($this->spatial_idx as $idxEntry) {
180
+			// get list of id's
181
+			foreach ($idxEntry as $id) {
182
+				// for document item in the index
183
+				if (strpos($id, 'media__', 0) !== 0) {
184
+					if ($this->skipPage($id, $namespace)) {
185
+						continue;
186
+					}
187
+
188
+					$meta = p_get_metadata($id);
189
+
190
+					// $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
191
+					$desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>';
192
+					$desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>';
193
+
194
+					// create an entry and store it
195
+					$plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF;
196
+					$plcm .= '  <name>' . $meta['title'] . '</name>' . DOKU_LF;
197
+					// TODO escape quotes in: title="' . $meta['title'] . '"
198
+					$plcm .= '  <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />'
199
+						. DOKU_LF;
200
+					if (!empty($meta['creator'])) {
201
+						$entry .= '  <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>'
202
+							. DOKU_LF;
203
+					}
204
+
205
+					$plcm .= '  <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF;
206
+					$plcm .= '  <styleUrl>#icon</styleUrl>' . DOKU_LF;
207
+
208
+					$plcm .= '  <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat'];
209
+					if ($meta['geo']['alt']) {
210
+						$plcm .= ',' . $meta['geo']['alt'];
211
+					}
212
+					$plcm .= '</coordinates></Point>' . DOKU_LF;
213
+					$plcm .= '</Placemark>' . DOKU_LF;
214
+
215
+					fwrite($fh, $plcm);
216
+				}
217
+			}
218
+		}
219
+		fwrite($fh, $KMLend);
220
+		return fclose($fh);
221
+	}
222
+	/**
223
+	 * will return true for non-public or hidden pages or pages that are not below or in the namespace.
224
+	 */
225
+	private function skipPage($id, $namespace) {
226
+		dbglog("helper_plugin_spatialhelper_sitemap::skipPage, check for $id in $namespace");
227
+		if (isHiddenPage($id)) {
228
+			return true;
229
+		}
230
+		if (auth_aclcheck($id, '', '') < AUTH_READ) {
231
+			return true;
232
+		}
233
+
234
+		if (!empty($namespace)) {
235
+			// only if id is in or below namespace
236
+			if (0 !== strpos(getNS($id), $namespace)) {
237
+				// dbglog("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace");
238
+				return true;
239
+			}
240
+		}
241
+		return false;
242
+	}
243 243
 }
Please login to merge, or discard this patch.