@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | public function handle($match, $state, $pos, Doku_Handler $handler) { |
71 | 71 | $data = array(); |
72 | 72 | $data [0] = trim(substr($match, strlen('{{findnearby>'), -2)); |
73 | - if(strlen($data [0]) < 1) { |
|
73 | + if (strlen($data [0]) < 1) { |
|
74 | 74 | $data [0] = $this->getLang('search_findnearby'); |
75 | 75 | } |
76 | 76 | $meta = p_get_metadata(getID(), 'geo'); |
77 | - if($meta) { |
|
78 | - if($meta ['lat'] && $meta ['lon']) { |
|
77 | + if ($meta) { |
|
78 | + if ($meta ['lat'] && $meta ['lon']) { |
|
79 | 79 | $data [1] = array( |
80 | 80 | 'do' => 'findnearby', |
81 | 81 | 'lat' => $meta ['lat'], |
82 | 82 | 'lon' => $meta ['lon'] |
83 | 83 | ); |
84 | - } elseif($meta ['geohash']) { |
|
84 | + } elseif ($meta ['geohash']) { |
|
85 | 85 | $data [1] = array( |
86 | 86 | 'do' => 'findnearby', |
87 | 87 | 'geohash' => $meta ['geohash'] |
@@ -98,16 +98,16 @@ discard block |
||
98 | 98 | * @see DokuWiki_Syntax_Plugin::render() |
99 | 99 | */ |
100 | 100 | public function render($format, Doku_Renderer $renderer, $data): bool { |
101 | - if($data === false) { |
|
101 | + if ($data === false) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | |
105 | - if($format === 'xhtml') { |
|
105 | + if ($format === 'xhtml') { |
|
106 | 106 | $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>'; |
107 | 107 | return true; |
108 | - } elseif($format === 'metadata') { |
|
108 | + } elseif ($format === 'metadata') { |
|
109 | 109 | return false; |
110 | - } elseif($format === 'odt') { |
|
110 | + } elseif ($format === 'odt') { |
|
111 | 111 | // don't render anything in ODT |
112 | 112 | return false; |
113 | 113 | } |
@@ -42,10 +42,10 @@ |
||
42 | 42 | * @see DokuWiki_Admin_Plugin::handle() |
43 | 43 | */ |
44 | 44 | public function handle(): void { |
45 | - if(isset ($_REQUEST ['purgeindex'])) { |
|
45 | + if (isset ($_REQUEST ['purgeindex'])) { |
|
46 | 46 | global $conf; |
47 | 47 | $path = $conf ['indexdir'] . '/spatial.idx'; |
48 | - if(file_exists($path) && unlink($path)) { |
|
48 | + if (file_exists($path) && unlink($path)) { |
|
49 | 49 | msg($this->getLang('admin_purged_tiles'), 0); |
50 | 50 | } |
51 | 51 | } |
@@ -101,18 +101,18 @@ discard block |
||
101 | 101 | // $data[3] – rev: The page revision, false for current wiki pages. |
102 | 102 | |
103 | 103 | dbglog($event->data, "Event data in removeFromIndex."); |
104 | - if(@file_exists($event->data [0] [0])) { |
|
104 | + if (@file_exists($event->data [0] [0])) { |
|
105 | 105 | // file not new |
106 | - if(!$event->data [0] [1]) { |
|
106 | + if (!$event->data [0] [1]) { |
|
107 | 107 | // file is empty, page is being deleted |
108 | - if(empty ($event->data [1])) { |
|
108 | + if (empty ($event->data [1])) { |
|
109 | 109 | // root namespace |
110 | 110 | $id = $event->data [2]; |
111 | 111 | } else { |
112 | 112 | $id = $event->data [1] . ":" . $event->data [2]; |
113 | 113 | } |
114 | 114 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
115 | - if($indexer) { |
|
115 | + if ($indexer) { |
|
116 | 116 | $indexer->deleteFromIndex($id); |
117 | 117 | } |
118 | 118 | } |
@@ -145,15 +145,15 @@ discard block |
||
145 | 145 | // $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already |
146 | 146 | // contains all public pages of the wiki |
147 | 147 | // $event→data['sitemap']: The path of the file the sitemap will be saved to. |
148 | - if($helper = plugin_load('helper', 'spatialhelper_sitemap')) { |
|
148 | + if ($helper = plugin_load('helper', 'spatialhelper_sitemap')) { |
|
149 | 149 | // dbglog($helper, "createSpatialSitemap loaded helper."); |
150 | 150 | |
151 | 151 | $kml = $helper->createKMLSitemap($this->getConf('media_kml')); |
152 | 152 | $rss = $helper->createGeoRSSSitemap($this->getConf('media_georss')); |
153 | 153 | |
154 | - if(!empty ($this->getConf('sitemap_namespaces'))) { |
|
154 | + if (!empty ($this->getConf('sitemap_namespaces'))) { |
|
155 | 155 | $namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces'))); |
156 | - foreach($namespaces as $namespace) { |
|
156 | + foreach ($namespaces as $namespace) { |
|
157 | 157 | $kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml')); |
158 | 158 | $rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss')); |
159 | 159 | dbglog( |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * not used |
179 | 179 | */ |
180 | 180 | public function handleActionActPreprocess(Doku_Event $event, $param): void { |
181 | - if($event->data !== 'findnearby') { |
|
181 | + if ($event->data !== 'findnearby') { |
|
182 | 182 | return; |
183 | 183 | } |
184 | 184 | $event->preventDefault(); |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | * 'format'=> HTML | JSON |
195 | 195 | */ |
196 | 196 | public function findnearby(Doku_Event $event, $param): void { |
197 | - if($event->data !== 'findnearby') { |
|
197 | + if ($event->data !== 'findnearby') { |
|
198 | 198 | return; |
199 | 199 | } |
200 | 200 | $event->preventDefault(); |
201 | 201 | $results = array(); |
202 | 202 | global $INPUT; |
203 | - if($helper = plugin_load('helper', 'spatialhelper_search')) { |
|
204 | - if($INPUT->has('lat') && $INPUT->has('lon')) { |
|
203 | + if ($helper = plugin_load('helper', 'spatialhelper_search')) { |
|
204 | + if ($INPUT->has('lat') && $INPUT->has('lon')) { |
|
205 | 205 | $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon')); |
206 | - } elseif($INPUT->has('geohash')) { |
|
206 | + } elseif ($INPUT->has('geohash')) { |
|
207 | 207 | $results = $helper->findNearby($INPUT->str('geohash')); |
208 | 208 | } else { |
209 | 209 | $results = array( |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | |
215 | 215 | $showMedia = $INPUT->bool('showMedia', true); |
216 | 216 | |
217 | - switch($param['format']) { |
|
217 | + switch ($param['format']) { |
|
218 | 218 | case 'JSON' : |
219 | 219 | $this->printJSON($results); |
220 | 220 | break; |
@@ -245,13 +245,13 @@ discard block |
||
245 | 245 | * @param bool $showMedia |
246 | 246 | */ |
247 | 247 | private function printHTML(array $searchresults, bool $showMedia = true): void { |
248 | - $pages = (array) ($searchresults ['pages']); |
|
249 | - $media = (array) $searchresults ['media']; |
|
250 | - $lat = (float) $searchresults ['lat']; |
|
251 | - $lon = (float) $searchresults ['lon']; |
|
252 | - $geohash = (string) $searchresults ['geohash']; |
|
248 | + $pages = ( array ) ($searchresults ['pages']); |
|
249 | + $media = ( array ) $searchresults ['media']; |
|
250 | + $lat = ( float ) $searchresults ['lat']; |
|
251 | + $lon = ( float ) $searchresults ['lon']; |
|
252 | + $geohash = ( string ) $searchresults ['geohash']; |
|
253 | 253 | |
254 | - if(isset ($searchresults ['error'])) { |
|
254 | + if (isset ($searchresults ['error'])) { |
|
255 | 255 | print '<div class="level1"><p>' . hsc($searchresults ['error']) . '</p></div>'; |
256 | 256 | return; |
257 | 257 | } |
@@ -259,9 +259,9 @@ discard block |
||
259 | 259 | // print a HTML list |
260 | 260 | print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF; |
261 | 261 | print '<div class="level1">' . DOKU_LF; |
262 | - if(!empty ($pages)) { |
|
262 | + if (!empty ($pages)) { |
|
263 | 263 | $pagelist = '<ol>' . DOKU_LF; |
264 | - foreach($pages as $page) { |
|
264 | + foreach ($pages as $page) { |
|
265 | 265 | $pagelist .= '<li>' . html_wikilink( |
266 | 266 | ':' . $page ['id'], useHeading('navigation') ? null : |
267 | 267 | noNS($page ['id']) |
@@ -281,14 +281,14 @@ discard block |
||
281 | 281 | print '<p>' . hsc($this->getLang('nothingfound')) . '</p>'; |
282 | 282 | } |
283 | 283 | |
284 | - if(!empty ($media) && $showMedia) { |
|
284 | + if (!empty ($media) && $showMedia) { |
|
285 | 285 | $pagelist = '<ol>' . DOKU_LF; |
286 | - foreach($media as $m) { |
|
286 | + foreach ($media as $m) { |
|
287 | 287 | $opts = array(); |
288 | 288 | $link = ml($m ['id'], $opts, false, '&', false); |
289 | 289 | $opts ['w'] = '100'; |
290 | 290 | $src = ml($m ['id'], $opts); |
291 | - $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' |
|
291 | + $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' |
|
292 | 292 | . $this->getLang('results_distance_prefix') . $page ['distance'] . ' m) ' . hsc($desc) |
293 | 293 | . '</li>' . DOKU_LF; |
294 | 294 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | print '</div>' . DOKU_LF; |
304 | 304 | } |
305 | 305 | print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. '; |
306 | - if(strlen($geohash) > 1) { |
|
306 | + if (strlen($geohash) > 1) { |
|
307 | 307 | $url = wl( |
308 | 308 | getID(), array( |
309 | 309 | 'do' => 'findnearby', |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | |
335 | 335 | // check the list of mimetypes |
336 | 336 | // if it's a supported type call appropriate index function |
337 | - if(substr_compare($event->data [3], 'image/jpeg', 0)) { |
|
337 | + if (substr_compare($event->data [3], 'image/jpeg', 0)) { |
|
338 | 338 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
339 | - if($indexer) { |
|
339 | + if ($indexer) { |
|
340 | 340 | $indexer->indexImage($event->data [2], $event->data [1]); |
341 | 341 | } |
342 | 342 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | // remove the media id from the index |
359 | 359 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
360 | - if($indexer) { |
|
360 | + if ($indexer) { |
|
361 | 361 | $indexer->deleteFromIndex('media__' . $event->data ['id']); |
362 | 362 | } |
363 | 363 | } |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | public function __construct() { |
34 | 34 | global $conf; |
35 | 35 | $idx_dir = $conf['indexdir']; |
36 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
36 | + if (!@file_exists($idx_dir . '/spatial.idx')) { |
|
37 | 37 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
38 | - if($indexer !== null) { |
|
38 | + if ($indexer !== null) { |
|
39 | 39 | $indexer->generateSpatialIndex(); |
40 | 40 | } |
41 | 41 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '; |
83 | 83 | $RSSstart .= 'xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF; |
84 | 84 | $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF; |
85 | - if(!empty($conf['tagline'])) { |
|
85 | + if (!empty($conf['tagline'])) { |
|
86 | 86 | $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF; |
87 | 87 | } |
88 | 88 | $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF; |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | $fh = fopen(mediaFN($mediaID), 'wb'); |
102 | 102 | fwrite($fh, $RSSstart); |
103 | 103 | |
104 | - foreach($this->spatial_idx as $idxEntry) { |
|
104 | + foreach ($this->spatial_idx as $idxEntry) { |
|
105 | 105 | // get list of id's |
106 | - foreach($idxEntry as $id) { |
|
106 | + foreach ($idxEntry as $id) { |
|
107 | 107 | // for document item in the index |
108 | - if(strpos($id, 'media__', 0) !== 0) { |
|
109 | - if($this->skipPage($id, $namespace)) { |
|
108 | + if (strpos($id, 'media__', 0) !== 0) { |
|
109 | + if ($this->skipPage($id, $namespace)) { |
|
110 | 110 | continue; |
111 | 111 | } |
112 | 112 | |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | $entry .= ' <summary>' . $desc . '</summary>' . DOKU_LF; |
121 | 121 | $entry .= ' <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] |
122 | 122 | . '</georss:point>' . DOKU_LF; |
123 | - if(isset($meta['geo']['alt'])) { |
|
123 | + if (isset($meta['geo']['alt'])) { |
|
124 | 124 | $entry .= ' <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF; |
125 | 125 | } |
126 | 126 | $entry .= ' <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF; |
127 | - if(empty($meta['creator'])) { |
|
127 | + if (empty($meta['creator'])) { |
|
128 | 128 | $meta['creator'] = $conf['title']; |
129 | 129 | } |
130 | 130 | $entry .= ' <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF; |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | */ |
148 | 148 | private function skipPage(string $id, string $namespace): bool { |
149 | 149 | dbglog("helper_plugin_spatialhelper_sitemap::skipPage, check for $id in $namespace"); |
150 | - if(isHiddenPage($id)) { |
|
150 | + if (isHiddenPage($id)) { |
|
151 | 151 | return true; |
152 | 152 | } |
153 | - if(auth_aclcheck($id, '', null) < AUTH_READ) { |
|
153 | + if (auth_aclcheck($id, '', null) < AUTH_READ) { |
|
154 | 154 | return true; |
155 | 155 | } |
156 | 156 | |
157 | - if(!empty($namespace)) { |
|
157 | + if (!empty($namespace)) { |
|
158 | 158 | // only if id is in or below namespace |
159 | - if(0 !== strpos(getNS($id), $namespace)) { |
|
159 | + if (0 !== strpos(getNS($id), $namespace)) { |
|
160 | 160 | // dbglog("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace"); |
161 | 161 | return true; |
162 | 162 | } |
@@ -196,12 +196,12 @@ discard block |
||
196 | 196 | $fh = fopen(mediaFN($mediaID), 'wb'); |
197 | 197 | fwrite($fh, $KMLstart); |
198 | 198 | |
199 | - foreach($this->spatial_idx as $idxEntry) { |
|
199 | + foreach ($this->spatial_idx as $idxEntry) { |
|
200 | 200 | // get list of id's |
201 | - foreach($idxEntry as $id) { |
|
201 | + foreach ($idxEntry as $id) { |
|
202 | 202 | // for document item in the index |
203 | - if(strpos($id, 'media__', 0) !== 0) { |
|
204 | - if($this->skipPage($id, $namespace)) { |
|
203 | + if (strpos($id, 'media__', 0) !== 0) { |
|
204 | + if ($this->skipPage($id, $namespace)) { |
|
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | // TODO escape quotes in: title="' . $meta['title'] . '" |
218 | 218 | $plcm .= ' <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' |
219 | 219 | . DOKU_LF; |
220 | - if(!empty($meta['creator'])) { |
|
220 | + if (!empty($meta['creator'])) { |
|
221 | 221 | $plcm .= ' <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' |
222 | 222 | . DOKU_LF; |
223 | 223 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $plcm .= ' <styleUrl>#icon</styleUrl>' . DOKU_LF; |
227 | 227 | |
228 | 228 | $plcm .= ' <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat']; |
229 | - if(isset($meta['geo']['alt'])) { |
|
229 | + if (isset($meta['geo']['alt'])) { |
|
230 | 230 | $plcm .= ',' . $meta['geo']['alt']; |
231 | 231 | } |
232 | 232 | $plcm .= '</coordinates></Point>' . DOKU_LF; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * Constructor, initialises the spatial index. |
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | - if(!plugin_load('helper', 'geophp')) { |
|
46 | + if (!plugin_load('helper', 'geophp')) { |
|
47 | 47 | $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: required geophp plugin is not available.'; |
48 | 48 | msg($message, -1); |
49 | 49 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | global $conf; |
52 | 52 | $this->idx_dir = $conf ['indexdir']; |
53 | 53 | // test if there is a spatialindex, if not build one for the wiki |
54 | - if(!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
54 | + if (!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
55 | 55 | // creates and stores the index |
56 | 56 | $this->generateSpatialIndex(); |
57 | 57 | } else { |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | require_once(DOKU_INC . 'inc/search.php'); |
74 | 74 | $pages = array(); |
75 | 75 | search($pages, $conf ['datadir'], 'search_allpages', array()); |
76 | - foreach($pages as $page) { |
|
76 | + foreach ($pages as $page) { |
|
77 | 77 | $this->updateSpatialIndex($page ['id']); |
78 | 78 | } |
79 | 79 | // media |
80 | 80 | $media = array(); |
81 | 81 | search($media, $conf ['mediadir'], 'search_media', array()); |
82 | - foreach($media as $medium) { |
|
83 | - if($medium ['isimg']) { |
|
82 | + foreach ($media as $medium) { |
|
83 | + if ($medium ['isimg']) { |
|
84 | 84 | $this->indexImage($medium); |
85 | 85 | } |
86 | 86 | } |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function updateSpatialIndex(string $id): bool { |
98 | 98 | $geotags = p_get_metadata($id, 'geo'); |
99 | - if(empty ($geotags)) { |
|
99 | + if (empty ($geotags)) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | - if(empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
102 | + if (empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | dbglog($geotags, "Geo metadata found for page $id"); |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | private function addToIndex(string $geohash, string $id): bool { |
121 | 121 | $pageIds = array(); |
122 | 122 | // check index for key/geohash |
123 | - if(!array_key_exists($geohash, $this->spatial_idx)) { |
|
123 | + if (!array_key_exists($geohash, $this->spatial_idx)) { |
|
124 | 124 | dbglog("Geohash $geohash not in index, just add $id."); |
125 | 125 | $pageIds [] = $id; |
126 | 126 | } else { |
127 | 127 | dbglog('Geohash for document is in index, find it.'); |
128 | 128 | // check the index for document |
129 | 129 | $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
130 | - if(empty ($knownHashes)) { |
|
130 | + if (empty ($knownHashes)) { |
|
131 | 131 | dbglog("No index record found for document $id, just add"); |
132 | 132 | $pageIds = $this->spatial_idx [$geohash]; |
133 | 133 | $pageIds [] = $id; |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
136 | 136 | $knownHash = $knownHashes [0]; |
137 | 137 | |
138 | - if($knownHash === $geohash) { |
|
138 | + if ($knownHash === $geohash) { |
|
139 | 139 | dbglog("Document $id was found in index and has the same geohash, nothing to do."); |
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | |
143 | - if(!empty ($knownHash)) { |
|
143 | + if (!empty ($knownHash)) { |
|
144 | 144 | dbglog("Document/media $id was found in index but has different geohash (it moved)."); |
145 | 145 | $knownIds = $this->spatial_idx [$knownHash]; |
146 | 146 | dbglog($knownIds, "Known id's for this hash:"); |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function findHashesForId(string $id, array $index): array { |
171 | 171 | $hashes = array(); |
172 | - foreach($index as $hash => $docIds) { |
|
173 | - if(in_array($id, $docIds, false)) { |
|
172 | + foreach ($index as $hash => $docIds) { |
|
173 | + if (in_array($id, $docIds, false)) { |
|
174 | 174 | $hashes [] = $hash; |
175 | 175 | } |
176 | 176 | } |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function indexImage($img): bool { |
200 | 200 | // test for supported files (jpeg only) |
201 | - if( |
|
201 | + if ( |
|
202 | 202 | (substr($img ['file'], -strlen('.jpg')) !== '.jpg') && |
203 | 203 | (substr($img ['file'], -strlen('.jpeg')) !== '.jpeg')) { |
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $geometry = $this->getCoordsFromExif($img ['id']); |
208 | - if(!$geometry) { |
|
208 | + if (!$geometry) { |
|
209 | 209 | return false; |
210 | 210 | } |
211 | 211 | $geohash = $geometry->out('geohash'); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function getCoordsFromExif(string $id) { |
226 | 226 | $exif = exif_read_data(mediaFN($id), 0, true); |
227 | - if(empty ($exif ['GPS'])) { |
|
227 | + if (empty ($exif ['GPS'])) { |
|
228 | 228 | return false; |
229 | 229 | } |
230 | 230 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @return float |
257 | 257 | */ |
258 | 258 | public function convertDMStoD(array $param): float { |
259 | - if(!is_array($param)) { |
|
259 | + if (!is_array($param)) { |
|
260 | 260 | $param = array($param); |
261 | 261 | } |
262 | 262 | $deg = $this->convertRationaltoFloat($param [0]); |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | public function convertRationaltoFloat($param): float { |
271 | 271 | // rational64u |
272 | 272 | $nums = explode('/', $param); |
273 | - if((int) $nums[1] > 0) { |
|
274 | - return (float) $nums[0] / (int) $nums[1]; |
|
273 | + if (( int ) $nums[1] > 0) { |
|
274 | + return ( float ) $nums[0] / ( int ) $nums[1]; |
|
275 | 275 | } else { |
276 | - return (float) $nums[0]; |
|
276 | + return ( float ) $nums[0]; |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | public function deleteFromIndex(string $id): void { |
286 | 286 | // check the index for document |
287 | 287 | $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
288 | - if(empty ($knownHashes)) { |
|
288 | + if (empty ($knownHashes)) { |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | dbglog("removing: $knownIds[$i] from the index."); |
297 | 297 | unset ($knownIds [$i]); |
298 | 298 | $this->spatial_idx [$knownHash] = $knownIds; |
299 | - if(empty ($this->spatial_idx [$knownHash])) { |
|
299 | + if (empty ($this->spatial_idx [$knownHash])) { |
|
300 | 300 | // dbglog ( "removing key: $knownHash from the index." ); |
301 | 301 | unset ($this->spatial_idx [$knownHash]); |
302 | 302 | } |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | // parent::__construct (); |
60 | 60 | global $conf; |
61 | 61 | |
62 | - if(!plugin_load('helper', 'geophp', false, true)) { |
|
62 | + if (!plugin_load('helper', 'geophp', false, true)) { |
|
63 | 63 | $message = |
64 | 64 | 'helper_plugin_spatialhelper_search::spatialhelper_search: required geophp plugin is not available.'; |
65 | 65 | msg($message, -1); |
66 | 66 | } |
67 | 67 | |
68 | 68 | $idx_dir = $conf ['indexdir']; |
69 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
69 | + if (!@file_exists($idx_dir . '/spatial.idx')) { |
|
70 | 70 | plugin_load('helper', 'spatialhelper_index'); |
71 | 71 | } |
72 | 72 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function findNearby(string $geohash, Point $p = null): array { |
100 | 100 | $_geohashClass = new Geohash(); |
101 | - if(!$p) { |
|
101 | + if (!$p) { |
|
102 | 102 | $decodedPoint = $_geohashClass->read($geohash); |
103 | 103 | } else { |
104 | 104 | $decodedPoint = $p; |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | |
120 | 120 | // find all the pages in the index that overlap with the adjacent hashes |
121 | 121 | $docIds = array(); |
122 | - foreach($adjacent as $adjHash) { |
|
123 | - if(is_array($this->spatial_idx)) { |
|
124 | - foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
125 | - if(strpos($_geohash, $adjHash) !== false) { |
|
122 | + foreach ($adjacent as $adjHash) { |
|
123 | + if (is_array($this->spatial_idx)) { |
|
124 | + foreach ($this->spatial_idx as $_geohash => $_docIds) { |
|
125 | + if (strpos($_geohash, $adjHash) !== false) { |
|
126 | 126 | // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
127 | 127 | // if $adjHash similar to geohash |
128 | 128 | $docIds = array_merge($docIds, $_docIds); |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | $media = array(); |
139 | 139 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
140 | 140 | |
141 | - foreach($docIds as $id) { |
|
142 | - if(strpos($id, 'media__', 0) === 0) { |
|
141 | + foreach ($docIds as $id) { |
|
142 | + if (strpos($id, 'media__', 0) === 0) { |
|
143 | 143 | $id = substr($id, strlen('media__')); |
144 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
144 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
145 | 145 | $point = $indexer->getCoordsFromExif($id); |
146 | 146 | $line = new LineString( |
147 | 147 | [ |
@@ -151,14 +151,14 @@ discard block |
||
151 | 151 | ); |
152 | 152 | $media [] = array( |
153 | 153 | 'id' => $id, |
154 | - 'distance' => (int) ($line->greatCircleLength()), |
|
154 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
155 | 155 | 'lat' => $point->y(), |
156 | 156 | 'lon' => $point->x() |
157 | 157 | // optionally add other meta such as tag, description... |
158 | 158 | ); |
159 | 159 | } |
160 | 160 | } else { |
161 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
161 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
162 | 162 | $geotags = p_get_metadata($id, 'geo'); |
163 | 163 | $point = new Point($geotags ['lon'], $geotags ['lat']); |
164 | 164 | $line = new LineString( |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ); |
170 | 170 | $pages [] = array( |
171 | 171 | 'id' => $id, |
172 | - 'distance' => (int) ($line->greatCircleLength()), |
|
172 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
173 | 173 | 'description' => p_get_metadata($id, 'description')['abstract'], |
174 | 174 | 'lat' => $geotags ['lat'], |
175 | 175 | 'lon' => $geotags ['lon'] |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | |
182 | 182 | // sort all the pages/media using distance |
183 | 183 | usort( |
184 | - $pages, static function ($a, $b) { |
|
184 | + $pages, static function($a, $b) { |
|
185 | 185 | return strnatcmp($a ['distance'], $b ['distance']); |
186 | 186 | } |
187 | 187 | ); |
188 | 188 | usort( |
189 | - $media, static function ($a, $b) { |
|
189 | + $media, static function($a, $b) { |
|
190 | 190 | return strnatcmp($a ['distance'], $b ['distance']); |
191 | 191 | } |
192 | 192 | ); |