Completed
Push — master ( 038f4f...639d6e )
by Mark
01:43 queued 01:30
created
_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.
action.php 1 patch
Indentation   +337 added lines, -337 removed lines patch added patch discarded remove patch
@@ -30,369 +30,369 @@
 block discarded – undo
30 30
  */
31 31
 class action_plugin_spatialhelper extends ActionPlugin
32 32
 {
33
-    /**
34
-     * Register for events.
35
-     *
36
-     * @param EventHandler $controller
37
-     *          DokuWiki's event controller object.
38
-     */
39
-    final public function register(EventHandler $controller): void
40
-    {
41
-        // listen for page add / delete events
42
-        // http://www.dokuwiki.org/devel:event:indexer_page_add
43
-        $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexerPageAdd');
44
-        $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'removeFromIndex');
33
+	/**
34
+	 * Register for events.
35
+	 *
36
+	 * @param EventHandler $controller
37
+	 *          DokuWiki's event controller object.
38
+	 */
39
+	final public function register(EventHandler $controller): void
40
+	{
41
+		// listen for page add / delete events
42
+		// http://www.dokuwiki.org/devel:event:indexer_page_add
43
+		$controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexerPageAdd');
44
+		$controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'removeFromIndex');
45 45
 
46
-        // http://www.dokuwiki.org/devel:event:sitemap_generate
47
-        $controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'handleSitemapGenerateBefore');
48
-        // using after will only trigger us if a sitemap was actually created
49
-        $controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handleSitemapGenerateAfter');
46
+		// http://www.dokuwiki.org/devel:event:sitemap_generate
47
+		$controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'handleSitemapGenerateBefore');
48
+		// using after will only trigger us if a sitemap was actually created
49
+		$controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handleSitemapGenerateAfter');
50 50
 
51
-        // handle actions we know of
52
-        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActionActPreprocess', []);
53
-        // handle HTML eg. /dokuwiki/doku.php?id=start&do=findnearby&geohash=u15vk4
54
-        $controller->register_hook(
55
-            'TPL_ACT_UNKNOWN',
56
-            'BEFORE',
57
-            $this,
58
-            'findnearby',
59
-            ['format' => 'HTML']
60
-        );
61
-        // handles AJAX/json eg: jQuery.post("/dokuwiki/lib/exe/ajax.php?id=start&call=findnearby&geohash=u15vk4");
62
-        $controller->register_hook(
63
-            'AJAX_CALL_UNKNOWN',
64
-            'BEFORE',
65
-            $this,
66
-            'findnearby',
67
-            ['format' => 'JSON']
68
-        );
51
+		// handle actions we know of
52
+		$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActionActPreprocess', []);
53
+		// handle HTML eg. /dokuwiki/doku.php?id=start&do=findnearby&geohash=u15vk4
54
+		$controller->register_hook(
55
+			'TPL_ACT_UNKNOWN',
56
+			'BEFORE',
57
+			$this,
58
+			'findnearby',
59
+			['format' => 'HTML']
60
+		);
61
+		// handles AJAX/json eg: jQuery.post("/dokuwiki/lib/exe/ajax.php?id=start&call=findnearby&geohash=u15vk4");
62
+		$controller->register_hook(
63
+			'AJAX_CALL_UNKNOWN',
64
+			'BEFORE',
65
+			$this,
66
+			'findnearby',
67
+			['format' => 'JSON']
68
+		);
69 69
 
70
-        // listen for media uploads and deletes
71
-        $controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, 'handleMediaUploaded', []);
72
-        $controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, 'handleMediaDeleted', []);
70
+		// listen for media uploads and deletes
71
+		$controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, 'handleMediaUploaded', []);
72
+		$controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, 'handleMediaDeleted', []);
73 73
 
74
-        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
75
-        $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity');
76
-    }
74
+		$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
75
+		$controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity');
76
+	}
77 77
 
78
-    /**
79
-     * Update the spatial index for the page.
80
-     *
81
-     * @param Event $event
82
-     *          event object
83
-     */
84
-    final  public function handleIndexerPageAdd(Event $event): 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
-    }
78
+	/**
79
+	 * Update the spatial index for the page.
80
+	 *
81
+	 * @param Event $event
82
+	 *          event object
83
+	 */
84
+	final  public function handleIndexerPageAdd(Event $event): 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 Event $event
100
-     *          event object
101
-     */
102
-    final    public function removeFromIndex(Event $event): void
103
-    {
104
-        // event data:
105
-        // $data[0] – The raw arguments for io_saveFile as an array. Do not change file path.
106
-        // $data[0][0] – the file path.
107
-        // $data[0][1] – the content to be saved, and may be modified.
108
-        // $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns)
109
-        // $data[2] – page_name: The wiki page name.
110
-        // $data[3] – rev: The page revision, false for current wiki pages.
96
+	/**
97
+	 * Update the spatial index, removing the page.
98
+	 *
99
+	 * @param Event $event
100
+	 *          event object
101
+	 */
102
+	final    public function removeFromIndex(Event $event): void
103
+	{
104
+		// event data:
105
+		// $data[0] – The raw arguments for io_saveFile as an array. Do not change file path.
106
+		// $data[0][0] – the file path.
107
+		// $data[0][1] – the content to be saved, and may be modified.
108
+		// $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns)
109
+		// $data[2] – page_name: The wiki page name.
110
+		// $data[3] – rev: The page revision, false for current wiki pages.
111 111
 
112
-        Logger::debug("Event data in removeFromIndex.", $event->data);
113
-        if (@file_exists($event->data [0] [0])) {
114
-            // file not new
115
-            if (!$event->data [0] [1]) {
116
-                // file is empty, page is being deleted
117
-                if (empty($event->data [1])) {
118
-                    // root namespace
119
-                    $id = $event->data [2];
120
-                } else {
121
-                    $id = $event->data [1] . ":" . $event->data [2];
122
-                }
123
-                $indexer = plugin_load('helper', 'spatialhelper_index');
124
-                if ($indexer !== null) {
125
-                    $indexer->deleteFromIndex($id);
126
-                }
127
-            }
128
-        }
129
-    }
112
+		Logger::debug("Event data in removeFromIndex.", $event->data);
113
+		if (@file_exists($event->data [0] [0])) {
114
+			// file not new
115
+			if (!$event->data [0] [1]) {
116
+				// file is empty, page is being deleted
117
+				if (empty($event->data [1])) {
118
+					// root namespace
119
+					$id = $event->data [2];
120
+				} else {
121
+					$id = $event->data [1] . ":" . $event->data [2];
122
+				}
123
+				$indexer = plugin_load('helper', 'spatialhelper_index');
124
+				if ($indexer !== null) {
125
+					$indexer->deleteFromIndex($id);
126
+				}
127
+			}
128
+		}
129
+	}
130 130
 
131
-    /**
132
-     * Add a new SitemapItem object that points to the KML of public geocoded pages.
133
-     *
134
-     * @param Event $event
135
-     */
136
-    final   public function handleSitemapGenerateBefore(Event $event): void
137
-    {
138
-        $path = mediaFN($this->getConf('media_kml'));
139
-        $lastmod = @filemtime($path);
140
-        $event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&', true), $lastmod);
141
-    }
131
+	/**
132
+	 * Add a new SitemapItem object that points to the KML of public geocoded pages.
133
+	 *
134
+	 * @param Event $event
135
+	 */
136
+	final   public function handleSitemapGenerateBefore(Event $event): void
137
+	{
138
+		$path = mediaFN($this->getConf('media_kml'));
139
+		$lastmod = @filemtime($path);
140
+		$event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&', true), $lastmod);
141
+	}
142 142
 
143
-    /**
144
-     * Create a spatial sitemap or attach the geo/kml map to the sitemap.
145
-     *
146
-     * @param Event $event
147
-     *          event object, not used
148
-     */
149
-    final   public function handleSitemapGenerateAfter(Event $event): bool
150
-    {
151
-        // $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already
152
-        //      contains all public pages of the wiki
153
-        // $event→data['sitemap']: The path of the file the sitemap will be saved to.
154
-        if (($helper = plugin_load('helper', 'spatialhelper_sitemap')) !== null) {
155
-            $kml = $helper->createKMLSitemap($this->getConf('media_kml'));
156
-            $rss = $helper->createGeoRSSSitemap($this->getConf('media_georss'));
143
+	/**
144
+	 * Create a spatial sitemap or attach the geo/kml map to the sitemap.
145
+	 *
146
+	 * @param Event $event
147
+	 *          event object, not used
148
+	 */
149
+	final   public function handleSitemapGenerateAfter(Event $event): bool
150
+	{
151
+		// $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already
152
+		//      contains all public pages of the wiki
153
+		// $event→data['sitemap']: The path of the file the sitemap will be saved to.
154
+		if (($helper = plugin_load('helper', 'spatialhelper_sitemap')) !== null) {
155
+			$kml = $helper->createKMLSitemap($this->getConf('media_kml'));
156
+			$rss = $helper->createGeoRSSSitemap($this->getConf('media_georss'));
157 157
 
158
-            if (!empty($this->getConf('sitemap_namespaces'))) {
159
-                $namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces')));
160
-                foreach ($namespaces as $namespace) {
161
-                    $kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml'));
162
-                    $rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss'));
163
-                    Logger::debug(
164
-                        "handleSitemapGenerateAfter, created KML / GeoRSS sitemap in $namespace, succes: ",
165
-                        $kmlN && $rssN
166
-                    );
167
-                }
168
-            }
169
-            return $kml && $rss;
170
-        }
171
-        return false;
172
-    }
158
+			if (!empty($this->getConf('sitemap_namespaces'))) {
159
+				$namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces')));
160
+				foreach ($namespaces as $namespace) {
161
+					$kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml'));
162
+					$rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss'));
163
+					Logger::debug(
164
+						"handleSitemapGenerateAfter, created KML / GeoRSS sitemap in $namespace, succes: ",
165
+						$kmlN && $rssN
166
+					);
167
+				}
168
+			}
169
+			return $kml && $rss;
170
+		}
171
+		return false;
172
+	}
173 173
 
174
-    /**
175
-     * trap findnearby action.
176
-     * This additional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown
177
-     *
178
-     * @param Event $event
179
-     *          event object
180
-     */
181
-    final  public function handleActionActPreprocess(Event $event): void
182
-    {
183
-        if ($event->data !== 'findnearby') {
184
-            return;
185
-        }
186
-        $event->preventDefault();
187
-    }
174
+	/**
175
+	 * trap findnearby action.
176
+	 * This additional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown
177
+	 *
178
+	 * @param Event $event
179
+	 *          event object
180
+	 */
181
+	final  public function handleActionActPreprocess(Event $event): void
182
+	{
183
+		if ($event->data !== 'findnearby') {
184
+			return;
185
+		}
186
+		$event->preventDefault();
187
+	}
188 188
 
189
-    /**
190
-     * handle findnearby action.
191
-     *
192
-     * @param Event $event
193
-     *          event object
194
-     * @param array $param
195
-     *          associative array with keys
196
-     *          'format'=> HTML | JSON
197
-     * @throws JsonException if anything goes wrong with JSON encoding
198
-     */
199
-    final  public function findnearby(Event $event, array $param): void
200
-    {
201
-        if ($event->data !== 'findnearby') {
202
-            return;
203
-        }
204
-        $event->preventDefault();
205
-        $results = [];
206
-        global $INPUT;
207
-        if (($helper = plugin_load('helper', 'spatialhelper_search')) !== null) {
208
-            if ($INPUT->has('lat') && $INPUT->has('lon')) {
209
-                $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon'));
210
-            } elseif ($INPUT->has('geohash')) {
211
-                $results = $helper->findNearby($INPUT->str('geohash'));
212
-            } else {
213
-                $results = ['error' => hsc($this->getLang('invalidinput'))];
214
-            }
215
-        }
189
+	/**
190
+	 * handle findnearby action.
191
+	 *
192
+	 * @param Event $event
193
+	 *          event object
194
+	 * @param array $param
195
+	 *          associative array with keys
196
+	 *          'format'=> HTML | JSON
197
+	 * @throws JsonException if anything goes wrong with JSON encoding
198
+	 */
199
+	final  public function findnearby(Event $event, array $param): void
200
+	{
201
+		if ($event->data !== 'findnearby') {
202
+			return;
203
+		}
204
+		$event->preventDefault();
205
+		$results = [];
206
+		global $INPUT;
207
+		if (($helper = plugin_load('helper', 'spatialhelper_search')) !== null) {
208
+			if ($INPUT->has('lat') && $INPUT->has('lon')) {
209
+				$results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon'));
210
+			} elseif ($INPUT->has('geohash')) {
211
+				$results = $helper->findNearby($INPUT->str('geohash'));
212
+			} else {
213
+				$results = ['error' => hsc($this->getLang('invalidinput'))];
214
+			}
215
+		}
216 216
 
217
-        $showMedia = $INPUT->bool('showMedia', true);
217
+		$showMedia = $INPUT->bool('showMedia', true);
218 218
 
219
-        switch ($param['format']) {
220
-            case 'JSON':
221
-                $this->printJSON($results);
222
-                break;
223
-            case 'HTML':
224
-                // fall through to default
225
-            default:
226
-                $this->printHTML($results, $showMedia);
227
-                break;
228
-        }
229
-    }
219
+		switch ($param['format']) {
220
+			case 'JSON':
221
+				$this->printJSON($results);
222
+				break;
223
+			case 'HTML':
224
+				// fall through to default
225
+			default:
226
+				$this->printHTML($results, $showMedia);
227
+				break;
228
+		}
229
+	}
230 230
 
231
-    /**
232
-     * Print seachresults as HTML lists.
233
-     *
234
-     * @param array $searchresults
235
-     * @throws JsonException if anything goes wrong with JSON encoding
236
-     */
237
-    private function printJSON(array $searchresults): void
238
-    {
239
-        header('Content-Type: application/json');
240
-        echo json_encode($searchresults, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
241
-    }
231
+	/**
232
+	 * Print seachresults as HTML lists.
233
+	 *
234
+	 * @param array $searchresults
235
+	 * @throws JsonException if anything goes wrong with JSON encoding
236
+	 */
237
+	private function printJSON(array $searchresults): void
238
+	{
239
+		header('Content-Type: application/json');
240
+		echo json_encode($searchresults, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
241
+	}
242 242
 
243
-    /**
244
-     * Print seachresults as HTML lists.
245
-     *
246
-     * @param array $searchresults
247
-     * @param bool $showMedia
248
-     */
249
-    private function printHTML(array $searchresults, bool $showMedia = true): void
250
-    {
251
-        $pages = (array)($searchresults ['pages']);
252
-        $media = (array)$searchresults ['media'];
253
-        $lat = (float)$searchresults ['lat'];
254
-        $lon = (float)$searchresults ['lon'];
255
-        $geohash = (string)$searchresults ['geohash'];
243
+	/**
244
+	 * Print seachresults as HTML lists.
245
+	 *
246
+	 * @param array $searchresults
247
+	 * @param bool $showMedia
248
+	 */
249
+	private function printHTML(array $searchresults, bool $showMedia = true): void
250
+	{
251
+		$pages = (array)($searchresults ['pages']);
252
+		$media = (array)$searchresults ['media'];
253
+		$lat = (float)$searchresults ['lat'];
254
+		$lon = (float)$searchresults ['lon'];
255
+		$geohash = (string)$searchresults ['geohash'];
256 256
 
257
-        if (isset($searchresults ['error'])) {
258
-            echo '<div class="level1"><p>' . hsc($searchresults ['error']) . '</p></div>';
259
-            return;
260
-        }
257
+		if (isset($searchresults ['error'])) {
258
+			echo '<div class="level1"><p>' . hsc($searchresults ['error']) . '</p></div>';
259
+			return;
260
+		}
261 261
 
262
-        // print a HTML list
263
-        echo '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF;
264
-        echo '<div class="level1">' . DOKU_LF;
265
-        if ($pages !== []) {
266
-            $pagelist = '<ol>' . DOKU_LF;
267
-            foreach ($pages as $page) {
268
-                $pagelist .= '<li>' . html_wikilink(
269
-                    ':' . $page ['id'],
270
-                    useHeading('navigation') ? null :
271
-                            noNS($page ['id'])
272
-                ) . ' (' . $this->getLang('results_distance_prefix')
273
-                    . $page ['distance'] . '&nbsp;m) ' . $page ['description'] . '</li>' . DOKU_LF;
274
-            }
275
-            $pagelist .= '</ol>' . DOKU_LF;
262
+		// print a HTML list
263
+		echo '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF;
264
+		echo '<div class="level1">' . DOKU_LF;
265
+		if ($pages !== []) {
266
+			$pagelist = '<ol>' . DOKU_LF;
267
+			foreach ($pages as $page) {
268
+				$pagelist .= '<li>' . html_wikilink(
269
+					':' . $page ['id'],
270
+					useHeading('navigation') ? null :
271
+							noNS($page ['id'])
272
+				) . ' (' . $this->getLang('results_distance_prefix')
273
+					. $page ['distance'] . '&nbsp;m) ' . $page ['description'] . '</li>' . DOKU_LF;
274
+			}
275
+			$pagelist .= '</ol>' . DOKU_LF;
276 276
 
277
-            echo '<h2>' . $this->getLang('results_pages') . hsc(
278
-                ' lat;lon: ' . $lat . ';' . $lon
279
-                    . ' (geohash: ' . $geohash . ')'
280
-            ) . '</h2>';
281
-            echo '<div class="level2">' . DOKU_LF;
282
-            echo $pagelist;
283
-            echo '</div>' . DOKU_LF;
284
-        } else {
285
-            echo '<p>' . hsc($this->getLang('nothingfound')) . '</p>';
286
-        }
277
+			echo '<h2>' . $this->getLang('results_pages') . hsc(
278
+				' lat;lon: ' . $lat . ';' . $lon
279
+					. ' (geohash: ' . $geohash . ')'
280
+			) . '</h2>';
281
+			echo '<div class="level2">' . DOKU_LF;
282
+			echo $pagelist;
283
+			echo '</div>' . DOKU_LF;
284
+		} else {
285
+			echo '<p>' . hsc($this->getLang('nothingfound')) . '</p>';
286
+		}
287 287
 
288
-        if ($media !== [] && $showMedia) {
289
-            $pagelist = '<ol>' . DOKU_LF;
290
-            foreach ($media as $m) {
291
-                $opts = [];
292
-                $link = ml($m ['id'], $opts, false);
293
-                $opts ['w'] = '100';
294
-                $src = ml($m ['id'], $opts);
295
-                $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '" alt=""></a> ('
296
-                    . $this->getLang('results_distance_prefix') . $m ['distance'] . '&nbsp;m) '
297
-                    . '</li>' . DOKU_LF;
298
-            }
299
-            $pagelist .= '</ol>' . DOKU_LF;
288
+		if ($media !== [] && $showMedia) {
289
+			$pagelist = '<ol>' . DOKU_LF;
290
+			foreach ($media as $m) {
291
+				$opts = [];
292
+				$link = ml($m ['id'], $opts, false);
293
+				$opts ['w'] = '100';
294
+				$src = ml($m ['id'], $opts);
295
+				$pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '" alt=""></a> ('
296
+					. $this->getLang('results_distance_prefix') . $m ['distance'] . '&nbsp;m) '
297
+					. '</li>' . DOKU_LF;
298
+			}
299
+			$pagelist .= '</ol>' . DOKU_LF;
300 300
 
301
-            echo '<h2>' . $this->getLang('results_media') . hsc(
302
-                ' lat;lon: ' . $lat . ';' . $lon
303
-                    . ' (geohash: ' . $geohash . ')'
304
-            ) . '</h2>' . DOKU_LF;
305
-            echo '<div class="level2">' . DOKU_LF;
306
-            echo $pagelist;
307
-            echo '</div>' . DOKU_LF;
308
-        }
309
-        echo '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. ';
310
-        if (strlen($geohash) > 1) {
311
-            $url = wl(
312
-                getID(),
313
-                ['do' => 'findnearby', 'geohash' => substr($geohash, 0, -1)]
314
-            );
315
-            echo '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>'
316
-                . DOKU_LF;
317
-        }
318
-        echo '</div>' . DOKU_LF;
319
-    }
301
+			echo '<h2>' . $this->getLang('results_media') . hsc(
302
+				' lat;lon: ' . $lat . ';' . $lon
303
+					. ' (geohash: ' . $geohash . ')'
304
+			) . '</h2>' . DOKU_LF;
305
+			echo '<div class="level2">' . DOKU_LF;
306
+			echo $pagelist;
307
+			echo '</div>' . DOKU_LF;
308
+		}
309
+		echo '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. ';
310
+		if (strlen($geohash) > 1) {
311
+			$url = wl(
312
+				getID(),
313
+				['do' => 'findnearby', 'geohash' => substr($geohash, 0, -1)]
314
+			);
315
+			echo '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>'
316
+				. DOKU_LF;
317
+		}
318
+		echo '</div>' . DOKU_LF;
319
+	}
320 320
 
321
-    /**
322
-     * add media to spatial index.
323
-     *
324
-     * @param Event $event
325
-     */
326
-    final  public function handleMediaUploaded(Event $event): void
327
-    {
328
-        //data[0] path/to/new/media.file (normally read from $_FILES, potentially could come from elsewhere)
329
-        //data[1] file name of the file being uploaded
330
-        //data[2] future directory id of the file being uploaded
331
-        //data[3] the mime type of the file being uploaded
332
-        //data[4] true if the uploaded file exists already
333
-        //data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
321
+	/**
322
+	 * add media to spatial index.
323
+	 *
324
+	 * @param Event $event
325
+	 */
326
+	final  public function handleMediaUploaded(Event $event): void
327
+	{
328
+		//data[0] path/to/new/media.file (normally read from $_FILES, potentially could come from elsewhere)
329
+		//data[1] file name of the file being uploaded
330
+		//data[2] future directory id of the file being uploaded
331
+		//data[3] the mime type of the file being uploaded
332
+		//data[4] true if the uploaded file exists already
333
+		//data[5] (since 2011-02-06) the PHP function used to move the file to the correct location
334 334
 
335
-        Logger::debug("handleMediaUploaded::event data", $event->data);
335
+		Logger::debug("handleMediaUploaded::event data", $event->data);
336 336
 
337
-        // check the list of mimetypes
338
-        // if it's a supported type call appropriate index function
339
-        if (str_contains($event->data [3], 'image/jpeg')) {
340
-            $indexer = plugin_load('helper', 'spatialhelper_index');
341
-            if ($indexer !== null) {
342
-                $indexer->indexImage($event->data [2]);
343
-            }
344
-        }
345
-        // TODO add image/tiff
346
-        // TODO kml, gpx, geojson...
347
-    }
337
+		// check the list of mimetypes
338
+		// if it's a supported type call appropriate index function
339
+		if (str_contains($event->data [3], 'image/jpeg')) {
340
+			$indexer = plugin_load('helper', 'spatialhelper_index');
341
+			if ($indexer !== null) {
342
+				$indexer->indexImage($event->data [2]);
343
+			}
344
+		}
345
+		// TODO add image/tiff
346
+		// TODO kml, gpx, geojson...
347
+	}
348 348
 
349
-    /**
350
-     * removes the media from the index.
351
-     * @param Event $event event object with data
352
-     */
353
-    final   public function handleMediaDeleted(Event $event): void
354
-    {
355
-        // data['id'] ID data['unl'] unlink return code
356
-        // data['del'] Namespace directory unlink return code
357
-        // data['name'] file name data['path'] full path to the file
358
-        // data['size'] file size
349
+	/**
350
+	 * removes the media from the index.
351
+	 * @param Event $event event object with data
352
+	 */
353
+	final   public function handleMediaDeleted(Event $event): void
354
+	{
355
+		// data['id'] ID data['unl'] unlink return code
356
+		// data['del'] Namespace directory unlink return code
357
+		// data['name'] file name data['path'] full path to the file
358
+		// data['size'] file size
359 359
 
360
-        // remove the media id from the index
361
-        $indexer = plugin_load('helper', 'spatialhelper_index');
362
-        if ($indexer !== null) {
363
-            $indexer->deleteFromIndex('media__' . $event->data ['id']);
364
-        }
365
-    }
360
+		// remove the media id from the index
361
+		$indexer = plugin_load('helper', 'spatialhelper_index');
362
+		if ($indexer !== null) {
363
+			$indexer->deleteFromIndex('media__' . $event->data ['id']);
364
+		}
365
+	}
366 366
 
367
-    /**
368
-     * add a link to the spatial sitemap files in the header.
369
-     *
370
-     * @param Event $event the DokuWiki event. $event->data is a two-dimensional array of all meta headers.
371
-     * The keys are meta, link and script.
372
-     *
373
-     * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
374
-     */
375
-    final  public function handleMetaheaderOutput(Event $event): void
376
-    {
377
-        // TODO maybe test for exist
378
-        $event->data ["link"] [] = ["type" => "application/atom+xml", "rel" => "alternate",
379
-            "href" => ml($this->getConf('media_georss')), "title" => "Spatial ATOM Feed"];
380
-        $event->data ["link"] [] = ["type" => "application/vnd.google-earth.kml+xml", "rel" => "alternate",
381
-            "href" => ml($this->getConf('media_kml')), "title" => "KML Sitemap"];
382
-    }
367
+	/**
368
+	 * add a link to the spatial sitemap files in the header.
369
+	 *
370
+	 * @param Event $event the DokuWiki event. $event->data is a two-dimensional array of all meta headers.
371
+	 * The keys are meta, link and script.
372
+	 *
373
+	 * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
374
+	 */
375
+	final  public function handleMetaheaderOutput(Event $event): void
376
+	{
377
+		// TODO maybe test for exist
378
+		$event->data ["link"] [] = ["type" => "application/atom+xml", "rel" => "alternate",
379
+			"href" => ml($this->getConf('media_georss')), "title" => "Spatial ATOM Feed"];
380
+		$event->data ["link"] [] = ["type" => "application/vnd.google-earth.kml+xml", "rel" => "alternate",
381
+			"href" => ml($this->getConf('media_kml')), "title" => "KML Sitemap"];
382
+	}
383 383
 
384
-    /**
385
-     * Add spatialhelper popularity data.
386
-     *
387
-     * @param Event $event
388
-     *          the DokuWiki event
389
-     */
390
-    final public function popularity(Event $event): void
391
-    {
392
-        $versionInfo = getVersionData();
393
-        $plugin_info = $this->getInfo();
394
-        $event->data['spatialhelper']['version'] = $plugin_info['date'];
395
-        $event->data['spatialhelper']['dwversion'] = $versionInfo['date'];
396
-        $event->data['spatialhelper']['combinedversion'] = $versionInfo['date'] . '_' . $plugin_info['date'];
397
-    }
384
+	/**
385
+	 * Add spatialhelper popularity data.
386
+	 *
387
+	 * @param Event $event
388
+	 *          the DokuWiki event
389
+	 */
390
+	final public function popularity(Event $event): void
391
+	{
392
+		$versionInfo = getVersionData();
393
+		$plugin_info = $this->getInfo();
394
+		$event->data['spatialhelper']['version'] = $plugin_info['date'];
395
+		$event->data['spatialhelper']['dwversion'] = $versionInfo['date'];
396
+		$event->data['spatialhelper']['combinedversion'] = $versionInfo['date'] . '_' . $plugin_info['date'];
397
+	}
398 398
 }
Please login to merge, or discard this patch.
helper/index.php 1 patch
Indentation   +270 added lines, -270 removed lines patch added patch discarded remove patch
@@ -28,296 +28,296 @@
 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 = '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 = '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['id']);
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['id']);
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 $imgId
204
-     *          a Dokuwiki image id
205
-     * @return bool true when image was successfully 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(string $imgId): bool
212
-    {
213
-        // test for supported files (jpeg only)
214
-        if (
215
-            (!str_ends_with(strtolower($imgId), '.jpg')) &&
216
-            (!str_ends_with(strtolower($imgId), '.jpeg'))
217
-        ) {
218
-            Logger::debug("indexImage:: " . $imgId . " is not a supported image file.");
219
-            return false;
220
-        }
200
+	/**
201
+	 * Add an index entry for this file having EXIF / IPTC data.
202
+	 *
203
+	 * @param $imgId
204
+	 *          a Dokuwiki image id
205
+	 * @return bool true when image was successfully 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(string $imgId): bool
212
+	{
213
+		// test for supported files (jpeg only)
214
+		if (
215
+			(!str_ends_with(strtolower($imgId), '.jpg')) &&
216
+			(!str_ends_with(strtolower($imgId), '.jpeg'))
217
+		) {
218
+			Logger::debug("indexImage:: " . $imgId . " is not a supported image file.");
219
+			return false;
220
+		}
221 221
 
222
-        $geometry = $this->getCoordsFromExif($imgId);
223
-        if (!$geometry) {
224
-            return false;
225
-        }
226
-        $geohash = $geometry->out('geohash');
227
-        // TODO truncate the geohash to something reasonable, otherwise they are
228
-        //   useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
229
-        //   precise, limit at ~9 as most GPS are not submeter accurate
230
-        return $this->addToIndex($geohash, 'media__' . $imgId);
231
-    }
222
+		$geometry = $this->getCoordsFromExif($imgId);
223
+		if (!$geometry) {
224
+			return false;
225
+		}
226
+		$geohash = $geometry->out('geohash');
227
+		// TODO truncate the geohash to something reasonable, otherwise they are
228
+		//   useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too
229
+		//   precise, limit at ~9 as most GPS are not submeter accurate
230
+		return $this->addToIndex($geohash, 'media__' . $imgId);
231
+	}
232 232
 
233
-    /**
234
-     * retrieve GPS decimal coordinates from exif.
235
-     *
236
-     * @param string $id
237
-     * @return Point|false
238
-     * @throws Exception
239
-     */
240
-    final public function getCoordsFromExif(string $id): Point|false
241
-    {
242
-        $exif = exif_read_data(mediaFN($id), 0, true);
243
-        if (empty($exif ['GPS'])) {
244
-            return false;
245
-        }
233
+	/**
234
+	 * retrieve GPS decimal coordinates from exif.
235
+	 *
236
+	 * @param string $id
237
+	 * @return Point|false
238
+	 * @throws Exception
239
+	 */
240
+	final public function getCoordsFromExif(string $id): Point|false
241
+	{
242
+		$exif = exif_read_data(mediaFN($id), 0, true);
243
+		if (empty($exif ['GPS'])) {
244
+			return false;
245
+		}
246 246
 
247
-        $lat = $this->convertDMStoD(
248
-            [
249
-                $exif ['GPS'] ['GPSLatitude'] [0],
250
-                $exif ['GPS'] ['GPSLatitude'] [1],
251
-                $exif ['GPS'] ['GPSLatitude'] [2],
252
-                $exif ['GPS'] ['GPSLatitudeRef']
253
-            ]
254
-        );
247
+		$lat = $this->convertDMStoD(
248
+			[
249
+				$exif ['GPS'] ['GPSLatitude'] [0],
250
+				$exif ['GPS'] ['GPSLatitude'] [1],
251
+				$exif ['GPS'] ['GPSLatitude'] [2],
252
+				$exif ['GPS'] ['GPSLatitudeRef']
253
+			]
254
+		);
255 255
 
256
-        $lon = $this->convertDMStoD(
257
-            [
258
-                $exif ['GPS'] ['GPSLongitude'] [0],
259
-                $exif ['GPS'] ['GPSLongitude'] [1],
260
-                $exif ['GPS'] ['GPSLongitude'] [2],
261
-                $exif ['GPS'] ['GPSLongitudeRef']
262
-            ]
263
-        );
256
+		$lon = $this->convertDMStoD(
257
+			[
258
+				$exif ['GPS'] ['GPSLongitude'] [0],
259
+				$exif ['GPS'] ['GPSLongitude'] [1],
260
+				$exif ['GPS'] ['GPSLongitude'] [2],
261
+				$exif ['GPS'] ['GPSLongitudeRef']
262
+			]
263
+		);
264 264
 
265
-        return new Point($lon, $lat);
266
-    }
265
+		return new Point($lon, $lat);
266
+	}
267 267
 
268
-    /**
269
-     * convert DegreesMinutesSeconds to Decimal degrees.
270
-     *
271
-     * @param array $param array of rational DMS
272
-     */
273
-    final  public function convertDMStoD(array $param): float
274
-    {
275
-        //        if (!(is_array($param))) {
276
-        //            $param = [$param];
277
-        //        }
278
-        $deg = $this->convertRationaltoFloat($param [0]);
279
-        $min = $this->convertRationaltoFloat($param [1]) / 60;
280
-        $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;
281
-        // Hemisphere (N, S, W or E)
282
-        $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;
268
+	/**
269
+	 * convert DegreesMinutesSeconds to Decimal degrees.
270
+	 *
271
+	 * @param array $param array of rational DMS
272
+	 */
273
+	final  public function convertDMStoD(array $param): float
274
+	{
275
+		//        if (!(is_array($param))) {
276
+		//            $param = [$param];
277
+		//        }
278
+		$deg = $this->convertRationaltoFloat($param [0]);
279
+		$min = $this->convertRationaltoFloat($param [1]) / 60;
280
+		$sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;
281
+		// Hemisphere (N, S, W or E)
282
+		$hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;
283 283
 
284
-        return $hem * ($deg + $min + $sec);
285
-    }
284
+		return $hem * ($deg + $min + $sec);
285
+	}
286 286
 
287
-    final public function convertRationaltoFloat(string $param): float
288
-    {
289
-        // rational64u
290
-        $nums = explode('/', $param);
291
-        if ((int)$nums[1] > 0) {
292
-            return (float)$nums[0] / (int)$nums[1];
293
-        }
287
+	final public function convertRationaltoFloat(string $param): float
288
+	{
289
+		// rational64u
290
+		$nums = explode('/', $param);
291
+		if ((int)$nums[1] > 0) {
292
+			return (float)$nums[0] / (int)$nums[1];
293
+		}
294 294
 
295
-        return (float)$nums[0];
296
-    }
295
+		return (float)$nums[0];
296
+	}
297 297
 
298
-    /**
299
-     * Deletes the page from the index.
300
-     *
301
-     * @param string $id document ID
302
-     */
303
-    final public function deleteFromIndex(string $id): void
304
-    {
305
-        // check the index for document
306
-        $knownHashes = $this->findHashesForId($id, $this->spatial_idx);
307
-        if ($knownHashes === []) {
308
-            return;
309
-        }
298
+	/**
299
+	 * Deletes the page from the index.
300
+	 *
301
+	 * @param string $id document ID
302
+	 */
303
+	final public function deleteFromIndex(string $id): void
304
+	{
305
+		// check the index for document
306
+		$knownHashes = $this->findHashesForId($id, $this->spatial_idx);
307
+		if ($knownHashes === []) {
308
+			return;
309
+		}
310 310
 
311
-        // TODO shortcut, need to make sure there is only one element, if not the index is corrupt
312
-        $knownHash = $knownHashes [0];
313
-        $knownIds = $this->spatial_idx [$knownHash];
314
-        $i = array_search($id, $knownIds);
315
-        Logger::debug("removing: $knownIds[$i] from the index.");
316
-        unset($knownIds [$i]);
317
-        $this->spatial_idx [$knownHash] = $knownIds;
318
-        if (empty($this->spatial_idx [$knownHash])) {
319
-            unset($this->spatial_idx [$knownHash]);
320
-        }
321
-        $this->saveIndex();
322
-    }
311
+		// TODO shortcut, need to make sure there is only one element, if not the index is corrupt
312
+		$knownHash = $knownHashes [0];
313
+		$knownIds = $this->spatial_idx [$knownHash];
314
+		$i = array_search($id, $knownIds);
315
+		Logger::debug("removing: $knownIds[$i] from the index.");
316
+		unset($knownIds [$i]);
317
+		$this->spatial_idx [$knownHash] = $knownIds;
318
+		if (empty($this->spatial_idx [$knownHash])) {
319
+			unset($this->spatial_idx [$knownHash]);
320
+		}
321
+		$this->saveIndex();
322
+	}
323 323
 }
Please login to merge, or discard this patch.