Completed
Pull Request — master (#21)
by Mark
01:23
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.
helper/sitemap.php 1 patch
Indentation   +206 added lines, -206 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,209 +26,209 @@  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
-    var $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" xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF;
85
-        $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF;
86
-        if (!empty($conf['tagline'])) {
87
-            $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF;
88
-        }
89
-        $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF;
90
-        $RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF;
91
-        $RSSstart .= '<link href="' . ml($mediaID, '', true, '&amp;', true) . '" rel="self" />' . DOKU_LF;
92
-        $RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF;
93
-        $RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) . '</id>' . DOKU_LF;
94
-        $RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF;
95
-
96
-        $RSSend = '</feed>' . DOKU_LF;
97
-
98
-        io_createNamespace($mediaID, 'media');
99
-        @touch(mediaFN($mediaID));
100
-        @chmod(mediaFN($mediaID), $conf['fmode']);
101
-        $fh = fopen(mediaFN($mediaID), 'w');
102
-        fwrite($fh, $RSSstart);
103
-
104
-        foreach ($this->spatial_idx as $idxEntry) {
105
-            // get list of id's
106
-            foreach ($idxEntry as $id) {
107
-                // for document item in the index
108
-                if (strpos($id, 'media__', 0) !== 0) {
109
-                    if ($this->_skipPage($id, $namespace)) {
110
-                        continue;
111
-                    }
112
-
113
-                    $meta = p_get_metadata($id);
114
-
115
-                    // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
116
-                    $desc = strip_tags($meta['description']['abstract']);
117
-
118
-                    $entry = '<entry>' . DOKU_LF;
119
-                    $entry .= '  <title>' . $meta['title'] . '</title>' . DOKU_LF;
120
-                    $entry .= '  <summary>' . $desc . '</summary>' . DOKU_LF;
121
-                    $entry .= '  <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] . '</georss:point>' . DOKU_LF;
122
-                    if ($meta['geo']['alt']) {
123
-                        $entry .= '  <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF;
124
-                    }
125
-                    $entry .= '  <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF;
126
-                    if (empty($meta['creator'])) {
127
-                        $meta['creator'] = $conf['title'];
128
-                    }
129
-                    $entry .= '  <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF;
130
-                    $entry .= '  <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF;
131
-                    $entry .= '  <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF;
132
-                    $entry .= '  <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':' . parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF;
133
-                    $entry .= '</entry>' . DOKU_LF;
134
-                    fwrite($fh, $entry);
135
-                }
136
-            }
137
-        }
138
-
139
-        fwrite($fh, $RSSend);
140
-        return fclose($fh);
141
-    }
142
-
143
-    /**
144
-     * Create a KML sitemap.
145
-     *
146
-     * @param $mediaID id
147
-     *          for the KML file
148
-     */
149
-    public function createKMLSitemap($mediaID) {
150
-        global $conf;
151
-        $namespace = getNS($mediaID);
152
-
153
-        $KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF;
154
-        $KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:atom="http://www.w3.org/2005/Atom"';
155
-        $KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF;
156
-        $KMLstart .= '<Document id="root_doc">' . DOKU_LF;
157
-        $KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF;
158
-        $KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF;
159
-        $KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF;
160
-        $KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>';
161
-        $KMLstart .= '<Icon><href>' . DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF;
162
-
163
-        $KMLend = '</Document>' . DOKU_LF . '</kml>';
164
-
165
-        io_createNamespace($mediaID, 'media');
166
-        @touch(mediaFN($mediaID));
167
-        @chmod(mediaFN($mediaID), $conf['fmode']);
168
-
169
-        $fh = fopen(mediaFN($mediaID), 'w');
170
-        fwrite($fh, $KMLstart);
171
-
172
-        foreach ($this->spatial_idx as $idxEntry) {
173
-            // get list of id's
174
-            foreach ($idxEntry as $id) {
175
-                // for document item in the index
176
-                if (strpos($id, 'media__', 0) !== 0) {
177
-                    if ($this->_skipPage($id, $namespace)) {
178
-                        continue;
179
-                    }
180
-
181
-                    $meta = p_get_metadata($id);
182
-
183
-                    // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
184
-                    $desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>';
185
-                    $desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>';
186
-
187
-                    // create an entry and store it
188
-                    $plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF;
189
-                    $plcm .= '  <name>' . $meta['title'] . '</name>' . DOKU_LF;
190
-                    // TODO escape quotes in: title="' . $meta['title'] . '"
191
-                    $plcm .= '  <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' . DOKU_LF;
192
-                    if (!empty($meta['creator'])) {
193
-                        $entry .= '  <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' . DOKU_LF;
194
-                    }
195
-
196
-                    $plcm .= '  <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF;
197
-                    $plcm .= '  <styleUrl>#icon</styleUrl>' . DOKU_LF;
198
-
199
-                    $plcm .= '  <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat'];
200
-                    if ($meta['geo']['alt']) {
201
-                        $plcm .= ',' . $meta['geo']['alt'];
202
-                    }
203
-                    $plcm .= '</coordinates></Point>' . DOKU_LF;
204
-                    $plcm .= '</Placemark>' . DOKU_LF;
205
-
206
-                    fwrite($fh, $plcm);
207
-                }
208
-            }
209
-        }
210
-        fwrite($fh, $KMLend);
211
-        return fclose($fh);
212
-    }
213
-    /**
214
-     * will return true for non-public or hidden pages or pages that are not below or in the namespace.
215
-     */
216
-    private function _skipPage($id, $namespace) {
217
-        dbglog("helper_plugin_spatialhelper_sitemap::_skipPage, check for $id in $namespace");
218
-        if (isHiddenPage($id)) {
219
-            return true;
220
-        }
221
-        if (auth_aclcheck($id, '', '') < AUTH_READ) {
222
-            return true;
223
-        }
224
-
225
-        if (!empty($namespace)) {
226
-            // only if id is in or below namespace
227
-            if (0 !== strpos(getNS($id), $namespace)) {
228
-                // dbglog("helper_plugin_spatialhelper_sitemap::_skipPage, skipping $id, not in $namespace");
229
-                return true;
230
-            }
231
-        }
232
-        return false;
233
-    }
29
+	/**
30
+	 * spatial index.
31
+	 */
32
+	var $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" xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF;
85
+		$RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF;
86
+		if (!empty($conf['tagline'])) {
87
+			$RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF;
88
+		}
89
+		$RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF;
90
+		$RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF;
91
+		$RSSstart .= '<link href="' . ml($mediaID, '', true, '&amp;', true) . '" rel="self" />' . DOKU_LF;
92
+		$RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF;
93
+		$RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) . '</id>' . DOKU_LF;
94
+		$RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF;
95
+
96
+		$RSSend = '</feed>' . DOKU_LF;
97
+
98
+		io_createNamespace($mediaID, 'media');
99
+		@touch(mediaFN($mediaID));
100
+		@chmod(mediaFN($mediaID), $conf['fmode']);
101
+		$fh = fopen(mediaFN($mediaID), 'w');
102
+		fwrite($fh, $RSSstart);
103
+
104
+		foreach ($this->spatial_idx as $idxEntry) {
105
+			// get list of id's
106
+			foreach ($idxEntry as $id) {
107
+				// for document item in the index
108
+				if (strpos($id, 'media__', 0) !== 0) {
109
+					if ($this->_skipPage($id, $namespace)) {
110
+						continue;
111
+					}
112
+
113
+					$meta = p_get_metadata($id);
114
+
115
+					// $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
116
+					$desc = strip_tags($meta['description']['abstract']);
117
+
118
+					$entry = '<entry>' . DOKU_LF;
119
+					$entry .= '  <title>' . $meta['title'] . '</title>' . DOKU_LF;
120
+					$entry .= '  <summary>' . $desc . '</summary>' . DOKU_LF;
121
+					$entry .= '  <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] . '</georss:point>' . DOKU_LF;
122
+					if ($meta['geo']['alt']) {
123
+						$entry .= '  <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF;
124
+					}
125
+					$entry .= '  <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF;
126
+					if (empty($meta['creator'])) {
127
+						$meta['creator'] = $conf['title'];
128
+					}
129
+					$entry .= '  <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF;
130
+					$entry .= '  <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF;
131
+					$entry .= '  <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF;
132
+					$entry .= '  <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':' . parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF;
133
+					$entry .= '</entry>' . DOKU_LF;
134
+					fwrite($fh, $entry);
135
+				}
136
+			}
137
+		}
138
+
139
+		fwrite($fh, $RSSend);
140
+		return fclose($fh);
141
+	}
142
+
143
+	/**
144
+	 * Create a KML sitemap.
145
+	 *
146
+	 * @param $mediaID id
147
+	 *          for the KML file
148
+	 */
149
+	public function createKMLSitemap($mediaID) {
150
+		global $conf;
151
+		$namespace = getNS($mediaID);
152
+
153
+		$KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF;
154
+		$KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:atom="http://www.w3.org/2005/Atom"';
155
+		$KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF;
156
+		$KMLstart .= '<Document id="root_doc">' . DOKU_LF;
157
+		$KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF;
158
+		$KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF;
159
+		$KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF;
160
+		$KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>';
161
+		$KMLstart .= '<Icon><href>' . DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF;
162
+
163
+		$KMLend = '</Document>' . DOKU_LF . '</kml>';
164
+
165
+		io_createNamespace($mediaID, 'media');
166
+		@touch(mediaFN($mediaID));
167
+		@chmod(mediaFN($mediaID), $conf['fmode']);
168
+
169
+		$fh = fopen(mediaFN($mediaID), 'w');
170
+		fwrite($fh, $KMLstart);
171
+
172
+		foreach ($this->spatial_idx as $idxEntry) {
173
+			// get list of id's
174
+			foreach ($idxEntry as $id) {
175
+				// for document item in the index
176
+				if (strpos($id, 'media__', 0) !== 0) {
177
+					if ($this->_skipPage($id, $namespace)) {
178
+						continue;
179
+					}
180
+
181
+					$meta = p_get_metadata($id);
182
+
183
+					// $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info);
184
+					$desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>';
185
+					$desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>';
186
+
187
+					// create an entry and store it
188
+					$plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF;
189
+					$plcm .= '  <name>' . $meta['title'] . '</name>' . DOKU_LF;
190
+					// TODO escape quotes in: title="' . $meta['title'] . '"
191
+					$plcm .= '  <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' . DOKU_LF;
192
+					if (!empty($meta['creator'])) {
193
+						$entry .= '  <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' . DOKU_LF;
194
+					}
195
+
196
+					$plcm .= '  <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF;
197
+					$plcm .= '  <styleUrl>#icon</styleUrl>' . DOKU_LF;
198
+
199
+					$plcm .= '  <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat'];
200
+					if ($meta['geo']['alt']) {
201
+						$plcm .= ',' . $meta['geo']['alt'];
202
+					}
203
+					$plcm .= '</coordinates></Point>' . DOKU_LF;
204
+					$plcm .= '</Placemark>' . DOKU_LF;
205
+
206
+					fwrite($fh, $plcm);
207
+				}
208
+			}
209
+		}
210
+		fwrite($fh, $KMLend);
211
+		return fclose($fh);
212
+	}
213
+	/**
214
+	 * will return true for non-public or hidden pages or pages that are not below or in the namespace.
215
+	 */
216
+	private function _skipPage($id, $namespace) {
217
+		dbglog("helper_plugin_spatialhelper_sitemap::_skipPage, check for $id in $namespace");
218
+		if (isHiddenPage($id)) {
219
+			return true;
220
+		}
221
+		if (auth_aclcheck($id, '', '') < AUTH_READ) {
222
+			return true;
223
+		}
224
+
225
+		if (!empty($namespace)) {
226
+			// only if id is in or below namespace
227
+			if (0 !== strpos(getNS($id), $namespace)) {
228
+				// dbglog("helper_plugin_spatialhelper_sitemap::_skipPage, skipping $id, not in $namespace");
229
+				return true;
230
+			}
231
+		}
232
+		return false;
233
+	}
234 234
 }
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.
helper/index.php 1 patch
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -22,277 +22,277 @@
 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 ((substr($img ['file'], - strlen('.jpg')) !== '.jpg') and (substr($img ['file'], - strlen('.jpeg')) !== '.jpeg')) {
177
-            return false;
178
-        }
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 ((substr($img ['file'], - strlen('.jpg')) !== '.jpg') and (substr($img ['file'], - strlen('.jpeg')) !== '.jpeg')) {
177
+			return false;
178
+		}
179 179
 
180
-        $geometry = $this->getCoordsFromExif($img ['id']);
181
-        if (!$geometry) {
182
-            return false;
183
-        }
184
-        $geohash = $geometry->out('geohash');
185
-        // TODO truncate the geohash to something reasonable, otherwise they are
186
-        // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
187
-        // precise, limit at ~9 as most GPS are not submeter accurate
188
-        return $this->_addToIndex($geohash, 'media__' . $img ['id']);
189
-    }
180
+		$geometry = $this->getCoordsFromExif($img ['id']);
181
+		if (!$geometry) {
182
+			return false;
183
+		}
184
+		$geohash = $geometry->out('geohash');
185
+		// TODO truncate the geohash to something reasonable, otherwise they are
186
+		// useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
187
+		// precise, limit at ~9 as most GPS are not submeter accurate
188
+		return $this->_addToIndex($geohash, 'media__' . $img ['id']);
189
+	}
190 190
 
191
-    /**
192
-     * retrieve GPS decimal coordinates from exif.
193
-     *
194
-     * @param
195
-     *          $id
196
-     * @return Point or false
197
-     */
198
-    public function getCoordsFromExif($id) {
199
-        $exif = exif_read_data(mediaFN($id), 0, true);
200
-        if (empty ($exif ['GPS'])) {
201
-            return false;
202
-        }
191
+	/**
192
+	 * retrieve GPS decimal coordinates from exif.
193
+	 *
194
+	 * @param
195
+	 *          $id
196
+	 * @return Point or false
197
+	 */
198
+	public function getCoordsFromExif($id) {
199
+		$exif = exif_read_data(mediaFN($id), 0, true);
200
+		if (empty ($exif ['GPS'])) {
201
+			return false;
202
+		}
203 203
 
204
-        $lat = $this->convertDMStoD(array(
205
-                $exif ['GPS'] ['GPSLatitude'] [0],
206
-                $exif ['GPS'] ['GPSLatitude'] [1],
207
-                $exif ['GPS'] ['GPSLatitude'] [2],
208
-                $exif ['GPS'] ['GPSLatitudeRef']
209
-        ));
204
+		$lat = $this->convertDMStoD(array(
205
+				$exif ['GPS'] ['GPSLatitude'] [0],
206
+				$exif ['GPS'] ['GPSLatitude'] [1],
207
+				$exif ['GPS'] ['GPSLatitude'] [2],
208
+				$exif ['GPS'] ['GPSLatitudeRef']
209
+		));
210 210
 
211
-        $lon = $this->convertDMStoD(array(
212
-                $exif ['GPS'] ['GPSLongitude'] [0],
213
-                $exif ['GPS'] ['GPSLongitude'] [1],
214
-                $exif ['GPS'] ['GPSLongitude'] [2],
215
-                $exif ['GPS'] ['GPSLongitudeRef']
216
-        ));
211
+		$lon = $this->convertDMStoD(array(
212
+				$exif ['GPS'] ['GPSLongitude'] [0],
213
+				$exif ['GPS'] ['GPSLongitude'] [1],
214
+				$exif ['GPS'] ['GPSLongitude'] [2],
215
+				$exif ['GPS'] ['GPSLongitudeRef']
216
+		));
217 217
 
218
-        return new Point($lon, $lat);
219
-    }
218
+		return new Point($lon, $lat);
219
+	}
220 220
 
221
-    /**
222
-     * Store the hash/id entry in the index.
223
-     *
224
-     * @param string $geohash
225
-     * @param string $id
226
-     *          page or media id
227
-     * @return boolean true when succesful
228
-     */
229
-    private function _addToIndex($geohash, $id) {
230
-        $pageIds = array();
231
-        // check index for key/geohash
232
-        if (!array_key_exists($geohash, $this->spatial_idx)) {
233
-            dbglog("Geohash $geohash not in index, just add $id.");
234
-            $pageIds [] = $id;
235
-        } else {
236
-            dbglog('Geohash for document is in index, find it.');
237
-            // check the index for document
238
-            $knownHashes = $this->findHashesForId($id, $this->spatial_idx);
239
-            if (empty ($knownHashes)) {
240
-                dbglog("No index record found for document $id, just add");
241
-                $pageIds = $this->spatial_idx [$geohash];
242
-                $pageIds [] = $id;
243
-            }
244
-            // TODO shortcut, need to make sure there is only one element, if not the index is corrupt
245
-            $knownHash = $knownHashes [0];
221
+	/**
222
+	 * Store the hash/id entry in the index.
223
+	 *
224
+	 * @param string $geohash
225
+	 * @param string $id
226
+	 *          page or media id
227
+	 * @return boolean true when succesful
228
+	 */
229
+	private function _addToIndex($geohash, $id) {
230
+		$pageIds = array();
231
+		// check index for key/geohash
232
+		if (!array_key_exists($geohash, $this->spatial_idx)) {
233
+			dbglog("Geohash $geohash not in index, just add $id.");
234
+			$pageIds [] = $id;
235
+		} else {
236
+			dbglog('Geohash for document is in index, find it.');
237
+			// check the index for document
238
+			$knownHashes = $this->findHashesForId($id, $this->spatial_idx);
239
+			if (empty ($knownHashes)) {
240
+				dbglog("No index record found for document $id, just add");
241
+				$pageIds = $this->spatial_idx [$geohash];
242
+				$pageIds [] = $id;
243
+			}
244
+			// TODO shortcut, need to make sure there is only one element, if not the index is corrupt
245
+			$knownHash = $knownHashes [0];
246 246
 
247
-            if ($knownHash == $geohash) {
248
-                dbglog("Document $id was found in index and has the same geohash, nothing to do.");
249
-                return true;
250
-            }
247
+			if ($knownHash == $geohash) {
248
+				dbglog("Document $id was found in index and has the same geohash, nothing to do.");
249
+				return true;
250
+			}
251 251
 
252
-            if (!empty ($knownHash)) {
253
-                dbglog("Document/media $id was found in index but has different geohash (it moved).");
254
-                $knownIds = $this->spatial_idx [$knownHash];
255
-                dbglog($knownIds, "Known id's for this hash:");
256
-                // remove it from the old geohash element
257
-                $i = array_search($id, $knownIds);
258
-                dbglog('Unsetting:' . $knownIds [$i]);
259
-                unset ($knownIds [$i]);
260
-                $this->spatial_idx [$knownHash] = $knownIds;
261
-                // set on new geohash element
262
-                $pageIds = $this->spatial_idx [$geohash];
263
-                $pageIds [] = $id;
264
-            }
265
-        }
266
-        // store and save
267
-        $this->spatial_idx [$geohash] = $pageIds;
268
-        return $this->saveIndex();
269
-    }
252
+			if (!empty ($knownHash)) {
253
+				dbglog("Document/media $id was found in index but has different geohash (it moved).");
254
+				$knownIds = $this->spatial_idx [$knownHash];
255
+				dbglog($knownIds, "Known id's for this hash:");
256
+				// remove it from the old geohash element
257
+				$i = array_search($id, $knownIds);
258
+				dbglog('Unsetting:' . $knownIds [$i]);
259
+				unset ($knownIds [$i]);
260
+				$this->spatial_idx [$knownHash] = $knownIds;
261
+				// set on new geohash element
262
+				$pageIds = $this->spatial_idx [$geohash];
263
+				$pageIds [] = $id;
264
+			}
265
+		}
266
+		// store and save
267
+		$this->spatial_idx [$geohash] = $pageIds;
268
+		return $this->saveIndex();
269
+	}
270 270
 
271
-    /**
272
-     * convert DegreesMinutesSeconds to Decimal degrees.
273
-     *
274
-     * @param array $param array of rational DMS
275
-     * @return number
276
-     */
277
-    public function convertDMStoD($param) {
278
-        if (!is_array($param)) {
279
-            $param = array($param);
280
-        }
281
-        $deg = $this->convertRationaltoFloat($param [0]);
282
-        $min = $this->convertRationaltoFloat($param [1]) / 60;
283
-        $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;
284
-        // Hemisphere (N, S, W or E)
285
-        $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;
286
-        return $hem * ($deg + $min + $sec);
287
-    }
271
+	/**
272
+	 * convert DegreesMinutesSeconds to Decimal degrees.
273
+	 *
274
+	 * @param array $param array of rational DMS
275
+	 * @return number
276
+	 */
277
+	public function convertDMStoD($param) {
278
+		if (!is_array($param)) {
279
+			$param = array($param);
280
+		}
281
+		$deg = $this->convertRationaltoFloat($param [0]);
282
+		$min = $this->convertRationaltoFloat($param [1]) / 60;
283
+		$sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;
284
+		// Hemisphere (N, S, W or E)
285
+		$hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;
286
+		return $hem * ($deg + $min + $sec);
287
+	}
288 288
 
289
-    public function convertRationaltoFloat($param) {
290
-        // rational64u
291
-        $nums = explode('/', $param);
292
-        if (intval($nums[1]) > 0) {
293
-            return intval($nums[0]) / intval($nums[1]);
294
-        } else {
295
-            return intval($nums[0]);
296
-        }
297
-    }
289
+	public function convertRationaltoFloat($param) {
290
+		// rational64u
291
+		$nums = explode('/', $param);
292
+		if (intval($nums[1]) > 0) {
293
+			return intval($nums[0]) / intval($nums[1]);
294
+		} else {
295
+			return intval($nums[0]);
296
+		}
297
+	}
298 298
 }
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   +2 added lines, -2 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']
Please login to merge, or discard this patch.
action.php 2 patches
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -25,374 +25,374 @@
 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, 'handle_indexer_page_add');
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, 'handle_sitemap_generate_before');
42
-        // using after will only trigger us if a sitemap was actually created
43
-        $controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handle_sitemap_generate_after');
44
-
45
-        // handle actions we know of
46
-        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action_act_preprocess', 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, '_handle_media_uploaded', array());
58
-        $controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, '_handle_media_deleted', array());
59
-
60
-        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_metaheader_output');
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 handle_indexer_page_add(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 metadata indexes and the value a string or an array of strings with the values. title and relation_references will already be set.
75
-        $id = $event->data ['page'];
76
-        $indexer = & plugin_load('helper', 'spatialhelper_index');
77
-        $entries = $indexer->updateSpatialIndex($id);
78
-    }
79
-
80
-    /**
81
-     * Update the spatial index, removing the page.
82
-     *
83
-     * @param Doku_Event $event
84
-     *          event object by reference
85
-     * @param object $param
86
-     *          the parameters passed to register_hook when this handler was registered
87
-     */
88
-    public function _removeFromIndex(Doku_Event & $event, $param) {
89
-        // event data:
90
-        // $data[0] – The raw arguments for io_saveFile as an array. Do not change file path.
91
-        // $data[0][0] – the file path.
92
-        // $data[0][1] – the content to be saved, and may be modified.
93
-        // $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns)
94
-        // $data[2] – page_name: The wiki page name.
95
-        // $data[3] – rev: The page revision, false for current wiki pages.
96
-
97
-        dbglog($event->data, "Event data in _removeFromIndex.");
98
-        if (@file_exists($event->data [0] [0])) {
99
-            // file not new
100
-            if (!$event->data [0] [1]) {
101
-                // file is empty, page is being deleted
102
-                if (empty ($event->data [1])) {
103
-                    // root namespace
104
-                    $id = $event->data [2];
105
-                } else {
106
-                    $id = $event->data [1] . ":" . $event->data [2];
107
-                }
108
-                $indexer = & plugin_load('helper', 'spatialhelper_index');
109
-                if ($indexer) {
110
-                    $indexer->deleteFromIndex($id);
111
-                }
112
-            }
113
-        }
114
-    }
115
-
116
-    /**
117
-     * Add a new SitemapItem object that points to the KML of public geocoded pages.
118
-     *
119
-     * @param Doku_Event $event
120
-     * @param unknown $param
121
-     */
122
-    public function handle_sitemap_generate_before(Doku_Event $event, $param) {
123
-        $path = mediaFN($this->getConf('media_kml'));
124
-        $lastmod = @filemtime($path);
125
-        $event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&amp;', true), $lastmod);
126
-        //dbglog($event->data ['items'], "Added a new SitemapItem object that points to the KML of public geocoded pages.");
127
-    }
128
-
129
-    /**
130
-     * Create a spatial sitemap or attach the geo/kml map to the sitemap.
131
-     *
132
-     * @param Doku_Event $event
133
-     *          event object by reference, not used
134
-     * @param mixed $param
135
-     *          parameter array, not used
136
-     */
137
-    public function handle_sitemap_generate_after(Doku_Event $event, $param) {
138
-        // $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already contains all public pages of the wiki
139
-        // $event→data['sitemap']: The path of the file the sitemap will be saved to.
140
-        if ($helper = & plugin_load('helper', 'spatialhelper_sitemap')) {
141
-            // dbglog($helper, "createSpatialSitemap loaded helper.");
142
-
143
-            $kml = $helper->createKMLSitemap($this->getConf('media_kml'));
144
-            $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, 'handle_indexer_page_add');
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, 'handle_sitemap_generate_before');
42
+		// using after will only trigger us if a sitemap was actually created
43
+		$controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handle_sitemap_generate_after');
44
+
45
+		// handle actions we know of
46
+		$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action_act_preprocess', 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, '_handle_media_uploaded', array());
58
+		$controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, '_handle_media_deleted', array());
59
+
60
+		$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_metaheader_output');
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 handle_indexer_page_add(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 metadata indexes and the value a string or an array of strings with the values. title and relation_references will already be set.
75
+		$id = $event->data ['page'];
76
+		$indexer = & plugin_load('helper', 'spatialhelper_index');
77
+		$entries = $indexer->updateSpatialIndex($id);
78
+	}
79
+
80
+	/**
81
+	 * Update the spatial index, removing the page.
82
+	 *
83
+	 * @param Doku_Event $event
84
+	 *          event object by reference
85
+	 * @param object $param
86
+	 *          the parameters passed to register_hook when this handler was registered
87
+	 */
88
+	public function _removeFromIndex(Doku_Event & $event, $param) {
89
+		// event data:
90
+		// $data[0] – The raw arguments for io_saveFile as an array. Do not change file path.
91
+		// $data[0][0] – the file path.
92
+		// $data[0][1] – the content to be saved, and may be modified.
93
+		// $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns)
94
+		// $data[2] – page_name: The wiki page name.
95
+		// $data[3] – rev: The page revision, false for current wiki pages.
96
+
97
+		dbglog($event->data, "Event data in _removeFromIndex.");
98
+		if (@file_exists($event->data [0] [0])) {
99
+			// file not new
100
+			if (!$event->data [0] [1]) {
101
+				// file is empty, page is being deleted
102
+				if (empty ($event->data [1])) {
103
+					// root namespace
104
+					$id = $event->data [2];
105
+				} else {
106
+					$id = $event->data [1] . ":" . $event->data [2];
107
+				}
108
+				$indexer = & plugin_load('helper', 'spatialhelper_index');
109
+				if ($indexer) {
110
+					$indexer->deleteFromIndex($id);
111
+				}
112
+			}
113
+		}
114
+	}
115
+
116
+	/**
117
+	 * Add a new SitemapItem object that points to the KML of public geocoded pages.
118
+	 *
119
+	 * @param Doku_Event $event
120
+	 * @param unknown $param
121
+	 */
122
+	public function handle_sitemap_generate_before(Doku_Event $event, $param) {
123
+		$path = mediaFN($this->getConf('media_kml'));
124
+		$lastmod = @filemtime($path);
125
+		$event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&amp;', true), $lastmod);
126
+		//dbglog($event->data ['items'], "Added a new SitemapItem object that points to the KML of public geocoded pages.");
127
+	}
128
+
129
+	/**
130
+	 * Create a spatial sitemap or attach the geo/kml map to the sitemap.
131
+	 *
132
+	 * @param Doku_Event $event
133
+	 *          event object by reference, not used
134
+	 * @param mixed $param
135
+	 *          parameter array, not used
136
+	 */
137
+	public function handle_sitemap_generate_after(Doku_Event $event, $param) {
138
+		// $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already contains all public pages of the wiki
139
+		// $event→data['sitemap']: The path of the file the sitemap will be saved to.
140
+		if ($helper = & plugin_load('helper', 'spatialhelper_sitemap')) {
141
+			// dbglog($helper, "createSpatialSitemap loaded helper.");
142
+
143
+			$kml = $helper->createKMLSitemap($this->getConf('media_kml'));
144
+			$rss = $helper->createGeoRSSSitemap($this->getConf('media_georss'));
145 145
             
146
-            if (!empty ($this->getConf('sitemap_namespaces'))) {
147
-                $namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces')));
148
-                foreach ($namespaces as $namespace) {
149
-                    $kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml'));
150
-                    $rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss'));
151
-                    dbglog($kmlN && $rssN, "handle_sitemap_generate_after, created KML / GeoRSS sitemap in $namespace, succes: ");
152
-                }  
153
-            }
154
-            return $kml && $rss;
155
-        } else {
156
-            dbglog($helper, "createSpatialSitemap NOT loaded helper.");
157
-        }
158
-    }
159
-
160
-    /**
161
-     * trap findnearby action.
162
-     * This addional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown
163
-     *
164
-     * @param Doku_Event $event
165
-     *          event object by reference
166
-     * @param mixed $param
167
-     *          not used
168
-     */
169
-    public function handle_action_act_preprocess(Doku_Event $event, $param) {
170
-        if ($event->data != 'findnearby') {
171
-                    return;
172
-        }
173
-        $event->preventDefault();
174
-    }
175
-
176
-    /**
177
-     * handle findnearby action.
178
-     *
179
-     * @param Doku_Event $event
180
-     *          event object by reference
181
-     * @param mixed $param
182
-     *          associative array with keys
183
-     *          'format'=> HTML | JSON
184
-     */
185
-    public function _findnearby(Doku_Event & $event, $param) {
186
-        if ($event->data != 'findnearby') {
187
-                    return;
188
-        }
189
-        $event->preventDefault();
190
-
191
-        global $INPUT;
192
-        if ($helper = & plugin_load('helper', 'spatialhelper_search')) {
193
-            if ($INPUT->has('lat') && $INPUT->has('lon')) {
194
-                $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon'));
195
-            } elseif ($INPUT->has('geohash')) {
196
-                $results = $helper->findNearby($INPUT->str('geohash'));
197
-            } else {
198
-                $results = array(
199
-                        'error' => hsc($this->getLang('invalidinput'))
200
-                );
201
-            }
202
-        }
203
-
204
-        $showMedia = $INPUT->bool('showMedia', true);
205
-
206
-        switch ($param['format']) {
207
-            case 'JSON' :
208
-                $this->printJSON($results);
209
-                break;
210
-            case 'HTML' :
211
-            // fall through to default
212
-            default :
213
-                $this->printHTML($results, $showMedia);
214
-                break;
215
-        }
216
-    }
217
-
218
-    /**
219
-     * Print seachresults as HTML lists.
220
-     *
221
-     * @param array $searchresults
222
-     */
223
-    private function printJSON($searchresults) {
224
-        require_once DOKU_INC . 'inc/JSON.php';
225
-        $json = new JSON();
226
-        header('Content-Type: application/json');
227
-        print $json->encode($searchresults);
228
-    }
229
-
230
-    /**
231
-     * Print seachresults as HTML lists.
232
-     *
233
-     * @param array $searchresults
234
-     * @param boolean $showMedia
235
-     */
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'];
242
-
243
-        if (isset ($searchresults ['error'])) {
244
-            print '<div class="level1"><p>' . hsc($results ['error']) . '</p></div>';
245
-            return;
246
-        }
247
-
248
-        // print a HTML list
249
-        print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF;
250
-        print '<div class="level1">' . DOKU_LF;
251
-        if (!empty ($pages)) {
252
-            $pagelist = '<ol>' . DOKU_LF;
253
-            foreach ($pages as $page) {
254
-                $pagelist .= '<li>' . html_wikilink(':' . $page ['id'], useHeading('navigation') ? null : noNS($page ['id'])) . ' (' . $this->getLang('results_distance_prefix') . $page ['distance'] . '&nbsp;m) ' . $page ['description'] . '</li>' . DOKU_LF;
255
-            }
256
-            $pagelist .= '</ol>' . DOKU_LF;
257
-
258
-            print '<h2>' . $this->getLang('results_pages') . hsc(' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')') . '</h2>';
259
-            print '<div class="level2">' . DOKU_LF;
260
-            print $pagelist;
261
-            print '</div>' . DOKU_LF;
262
-        } else {
263
-            print '<p>' . hsc($this->getLang('nothingfound')) . '</p>';
264
-        }
265
-
266
-        if (!empty ($media) && $showMedia) {
267
-            $pagelist = '<ol>' . DOKU_LF;
268
-            foreach ($media as $m) {
269
-                $opts = array();
270
-                $link = ml($m ['id'], $opts, false, '&amp;', false);
271
-                $opts ['w'] = '100';
272
-                $src = ml($m ['id'], $opts);
273
-                $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' . $this->getLang('results_distance_prefix') . $page ['distance'] . '&nbsp;m) ' . hsc($desc) . '</li>' . DOKU_LF;
274
-            }
275
-            $pagelist .= '</ol>' . DOKU_LF;
276
-
277
-            print '<h2>' . $this->getLang('results_media') . hsc(' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')') . '</h2>' . DOKU_LF;
278
-            print '<div class="level2">' . DOKU_LF;
279
-            print $pagelist;
280
-            print '</div>' . DOKU_LF;
281
-        }
282
-        print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. ';
283
-        if (strlen($geohash) > 1) {
284
-            $url = wl(getID(), array(
285
-                    'do' => 'findnearby',
286
-                    'geohash' => substr($geohash, 0, - 1)
287
-            ));
288
-            print '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>' . DOKU_LF;
289
-        }
290
-        print '</div>' . DOKU_LF;
291
-    }
292
-
293
-    /**
294
-     * add media to spatial index.
295
-     *
296
-     * @param Doku_Event $event
297
-     *          event object by reference
298
-     * @param unknown $param
299
-     */
300
-    public function _handle_media_uploaded(Doku_Event & $event, $param) {
301
-        // data[0] temporary file name (read from $_FILES)
302
-        // data[1] file name of the file being uploaded
303
-        // data[2] future directory id of the file being uploaded
304
-        // data[3] the mime type of the file being uploaded
305
-        // data[4] true if the uploaded file exists already
306
-        // data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
307
-
308
-        dbglog($event->data, "_handle_media_uploaded::event data");
309
-
310
-        // check the list of mimetypes
311
-        // if it's a supported type call appropriate index function
312
-        if (substr_compare($event->data [3], 'image/jpeg', 0)) {
313
-            $indexer = plugin_load('helper', 'spatialhelper_index');
314
-            if ($indexer) {
315
-                $indexer->indexImage($event->data [2], $event->data [1]);
316
-            }
317
-        }
318
-        // TODO add image/tiff
319
-        // TODO kml, gpx, geojson...
320
-    }
321
-
322
-    /**
323
-     * removes the media from the index.
324
-     */
325
-    public function _handle_media_deleted(Doku_Event & $event, $param) {
326
-        // data['id'] ID data['unl'] unlink return code
327
-        // data['del'] Namespace directory unlink return code
328
-        // data['name'] file name data['path'] full path to the file
329
-        // data['size'] file size
330
-
331
-        dbglog($event->data, "_handle_media_deleted::event data");
332
-
333
-        // remove the media id from the index
334
-        $indexer = & plugin_load('helper', 'spatialhelper_index');
335
-        if ($indexer) {
336
-            $indexer->deleteFromIndex('media__' . $event->data ['id']);
337
-        }
338
-    }
339
-
340
-    /**
341
-     * add a link to the spatial sitemap files in the header.
342
-     *
343
-     * @param Doku_Event $event
344
-     *          the DokuWiki event. $event->data is a two-dimensional
345
-     *          array of all meta headers. The keys are meta, link and script.
346
-     * @param unknown_type $param
347
-     *
348
-     * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
349
-     */
350
-    public function handle_metaheader_output(Doku_Event $event, $param) {
351
-        // TODO maybe test for exist
352
-        $event->data ["link"] [] = array(
353
-                "type" => "application/atom+xml",
354
-                "rel" => "alternate",
355
-                "href" => ml($this->getConf('media_georss')),
356
-                "title" => "Spatial ATOM Feed"
357
-        );
358
-        $event->data ["link"] [] = array(
359
-                "type" => "application/vnd.google-earth.kml+xml",
360
-                "rel" => "alternate",
361
-                "href" => ml($this->getConf('media_kml')),
362
-                "title" => "KML Sitemap"
363
-        );
364
-    }
365
-
366
-    /**
367
-     * Calculate a new coordinate based on start, distance and bearing
368
-     *
369
-     * @param $start array
370
-     *          - start coordinate as decimal lat/lon pair
371
-     * @param $dist float
372
-     *          - distance in kilometers
373
-     * @param $brng float
374
-     *          - bearing in degrees (compass direction)
375
-     */
376
-    private function _geo_destination($start, $dist, $brng) {
377
-        $lat1 = toRad($start [0]);
378
-        $lon1 = toRad($start [1]);
379
-        // http://en.wikipedia.org/wiki/Earth_radius
380
-        // average earth radius in km
381
-        $dist = $dist / 6371.01;
382
-        $brng = toRad($brng);
383
-
384
-        $lon2 = $lon1 + atan2(sin($brng) * sin($dist) * cos($lat1), cos($dist) - sin($lat1) * sin($lat2));
385
-        $lon2 = fmod(($lon2 + 3 * pi()), (2 * pi())) - pi();
386
-
387
-        return array(
388
-                toDeg($lat2),
389
-                toDeg($lon2)
390
-        );
391
-    }
392
-    private function toRad($deg) {
393
-        return $deg * pi() / 180;
394
-    }
395
-    private function toDeg($rad) {
396
-        return $rad * 180 / pi();
397
-    }
146
+			if (!empty ($this->getConf('sitemap_namespaces'))) {
147
+				$namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces')));
148
+				foreach ($namespaces as $namespace) {
149
+					$kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml'));
150
+					$rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss'));
151
+					dbglog($kmlN && $rssN, "handle_sitemap_generate_after, created KML / GeoRSS sitemap in $namespace, succes: ");
152
+				}  
153
+			}
154
+			return $kml && $rss;
155
+		} else {
156
+			dbglog($helper, "createSpatialSitemap NOT loaded helper.");
157
+		}
158
+	}
159
+
160
+	/**
161
+	 * trap findnearby action.
162
+	 * This addional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown
163
+	 *
164
+	 * @param Doku_Event $event
165
+	 *          event object by reference
166
+	 * @param mixed $param
167
+	 *          not used
168
+	 */
169
+	public function handle_action_act_preprocess(Doku_Event $event, $param) {
170
+		if ($event->data != 'findnearby') {
171
+					return;
172
+		}
173
+		$event->preventDefault();
174
+	}
175
+
176
+	/**
177
+	 * handle findnearby action.
178
+	 *
179
+	 * @param Doku_Event $event
180
+	 *          event object by reference
181
+	 * @param mixed $param
182
+	 *          associative array with keys
183
+	 *          'format'=> HTML | JSON
184
+	 */
185
+	public function _findnearby(Doku_Event & $event, $param) {
186
+		if ($event->data != 'findnearby') {
187
+					return;
188
+		}
189
+		$event->preventDefault();
190
+
191
+		global $INPUT;
192
+		if ($helper = & plugin_load('helper', 'spatialhelper_search')) {
193
+			if ($INPUT->has('lat') && $INPUT->has('lon')) {
194
+				$results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon'));
195
+			} elseif ($INPUT->has('geohash')) {
196
+				$results = $helper->findNearby($INPUT->str('geohash'));
197
+			} else {
198
+				$results = array(
199
+						'error' => hsc($this->getLang('invalidinput'))
200
+				);
201
+			}
202
+		}
203
+
204
+		$showMedia = $INPUT->bool('showMedia', true);
205
+
206
+		switch ($param['format']) {
207
+			case 'JSON' :
208
+				$this->printJSON($results);
209
+				break;
210
+			case 'HTML' :
211
+			// fall through to default
212
+			default :
213
+				$this->printHTML($results, $showMedia);
214
+				break;
215
+		}
216
+	}
217
+
218
+	/**
219
+	 * Print seachresults as HTML lists.
220
+	 *
221
+	 * @param array $searchresults
222
+	 */
223
+	private function printJSON($searchresults) {
224
+		require_once DOKU_INC . 'inc/JSON.php';
225
+		$json = new JSON();
226
+		header('Content-Type: application/json');
227
+		print $json->encode($searchresults);
228
+	}
229
+
230
+	/**
231
+	 * Print seachresults as HTML lists.
232
+	 *
233
+	 * @param array $searchresults
234
+	 * @param boolean $showMedia
235
+	 */
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'];
242
+
243
+		if (isset ($searchresults ['error'])) {
244
+			print '<div class="level1"><p>' . hsc($results ['error']) . '</p></div>';
245
+			return;
246
+		}
247
+
248
+		// print a HTML list
249
+		print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF;
250
+		print '<div class="level1">' . DOKU_LF;
251
+		if (!empty ($pages)) {
252
+			$pagelist = '<ol>' . DOKU_LF;
253
+			foreach ($pages as $page) {
254
+				$pagelist .= '<li>' . html_wikilink(':' . $page ['id'], useHeading('navigation') ? null : noNS($page ['id'])) . ' (' . $this->getLang('results_distance_prefix') . $page ['distance'] . '&nbsp;m) ' . $page ['description'] . '</li>' . DOKU_LF;
255
+			}
256
+			$pagelist .= '</ol>' . DOKU_LF;
257
+
258
+			print '<h2>' . $this->getLang('results_pages') . hsc(' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')') . '</h2>';
259
+			print '<div class="level2">' . DOKU_LF;
260
+			print $pagelist;
261
+			print '</div>' . DOKU_LF;
262
+		} else {
263
+			print '<p>' . hsc($this->getLang('nothingfound')) . '</p>';
264
+		}
265
+
266
+		if (!empty ($media) && $showMedia) {
267
+			$pagelist = '<ol>' . DOKU_LF;
268
+			foreach ($media as $m) {
269
+				$opts = array();
270
+				$link = ml($m ['id'], $opts, false, '&amp;', false);
271
+				$opts ['w'] = '100';
272
+				$src = ml($m ['id'], $opts);
273
+				$pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' . $this->getLang('results_distance_prefix') . $page ['distance'] . '&nbsp;m) ' . hsc($desc) . '</li>' . DOKU_LF;
274
+			}
275
+			$pagelist .= '</ol>' . DOKU_LF;
276
+
277
+			print '<h2>' . $this->getLang('results_media') . hsc(' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')') . '</h2>' . DOKU_LF;
278
+			print '<div class="level2">' . DOKU_LF;
279
+			print $pagelist;
280
+			print '</div>' . DOKU_LF;
281
+		}
282
+		print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. ';
283
+		if (strlen($geohash) > 1) {
284
+			$url = wl(getID(), array(
285
+					'do' => 'findnearby',
286
+					'geohash' => substr($geohash, 0, - 1)
287
+			));
288
+			print '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>' . DOKU_LF;
289
+		}
290
+		print '</div>' . DOKU_LF;
291
+	}
292
+
293
+	/**
294
+	 * add media to spatial index.
295
+	 *
296
+	 * @param Doku_Event $event
297
+	 *          event object by reference
298
+	 * @param unknown $param
299
+	 */
300
+	public function _handle_media_uploaded(Doku_Event & $event, $param) {
301
+		// data[0] temporary file name (read from $_FILES)
302
+		// data[1] file name of the file being uploaded
303
+		// data[2] future directory id of the file being uploaded
304
+		// data[3] the mime type of the file being uploaded
305
+		// data[4] true if the uploaded file exists already
306
+		// data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
307
+
308
+		dbglog($event->data, "_handle_media_uploaded::event data");
309
+
310
+		// check the list of mimetypes
311
+		// if it's a supported type call appropriate index function
312
+		if (substr_compare($event->data [3], 'image/jpeg', 0)) {
313
+			$indexer = plugin_load('helper', 'spatialhelper_index');
314
+			if ($indexer) {
315
+				$indexer->indexImage($event->data [2], $event->data [1]);
316
+			}
317
+		}
318
+		// TODO add image/tiff
319
+		// TODO kml, gpx, geojson...
320
+	}
321
+
322
+	/**
323
+	 * removes the media from the index.
324
+	 */
325
+	public function _handle_media_deleted(Doku_Event & $event, $param) {
326
+		// data['id'] ID data['unl'] unlink return code
327
+		// data['del'] Namespace directory unlink return code
328
+		// data['name'] file name data['path'] full path to the file
329
+		// data['size'] file size
330
+
331
+		dbglog($event->data, "_handle_media_deleted::event data");
332
+
333
+		// remove the media id from the index
334
+		$indexer = & plugin_load('helper', 'spatialhelper_index');
335
+		if ($indexer) {
336
+			$indexer->deleteFromIndex('media__' . $event->data ['id']);
337
+		}
338
+	}
339
+
340
+	/**
341
+	 * add a link to the spatial sitemap files in the header.
342
+	 *
343
+	 * @param Doku_Event $event
344
+	 *          the DokuWiki event. $event->data is a two-dimensional
345
+	 *          array of all meta headers. The keys are meta, link and script.
346
+	 * @param unknown_type $param
347
+	 *
348
+	 * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
349
+	 */
350
+	public function handle_metaheader_output(Doku_Event $event, $param) {
351
+		// TODO maybe test for exist
352
+		$event->data ["link"] [] = array(
353
+				"type" => "application/atom+xml",
354
+				"rel" => "alternate",
355
+				"href" => ml($this->getConf('media_georss')),
356
+				"title" => "Spatial ATOM Feed"
357
+		);
358
+		$event->data ["link"] [] = array(
359
+				"type" => "application/vnd.google-earth.kml+xml",
360
+				"rel" => "alternate",
361
+				"href" => ml($this->getConf('media_kml')),
362
+				"title" => "KML Sitemap"
363
+		);
364
+	}
365
+
366
+	/**
367
+	 * Calculate a new coordinate based on start, distance and bearing
368
+	 *
369
+	 * @param $start array
370
+	 *          - start coordinate as decimal lat/lon pair
371
+	 * @param $dist float
372
+	 *          - distance in kilometers
373
+	 * @param $brng float
374
+	 *          - bearing in degrees (compass direction)
375
+	 */
376
+	private function _geo_destination($start, $dist, $brng) {
377
+		$lat1 = toRad($start [0]);
378
+		$lon1 = toRad($start [1]);
379
+		// http://en.wikipedia.org/wiki/Earth_radius
380
+		// average earth radius in km
381
+		$dist = $dist / 6371.01;
382
+		$brng = toRad($brng);
383
+
384
+		$lon2 = $lon1 + atan2(sin($brng) * sin($dist) * cos($lat1), cos($dist) - sin($lat1) * sin($lat2));
385
+		$lon2 = fmod(($lon2 + 3 * pi()), (2 * pi())) - pi();
386
+
387
+		return array(
388
+				toDeg($lat2),
389
+				toDeg($lon2)
390
+		);
391
+	}
392
+	private function toRad($deg) {
393
+		return $deg * pi() / 180;
394
+	}
395
+	private function toDeg($rad) {
396
+		return $rad * 180 / pi();
397
+	}
398 398
 }
Please login to merge, or discard this patch.
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.