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