@@ -59,13 +59,13 @@ 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 = 'helper_plugin_spatialhelper_search::spatialhelper_search: required geophp plugin is not available.'; |
64 | 64 | msg($message, -1); |
65 | 65 | } |
66 | 66 | |
67 | 67 | $idx_dir = $conf ['indexdir']; |
68 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
68 | + if (!@file_exists($idx_dir . '/spatial.idx')) { |
|
69 | 69 | plugin_load('helper', 'spatialhelper_index'); |
70 | 70 | } |
71 | 71 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function findNearby(string $geohash, Point $p = null): array { |
99 | 99 | $_geohashClass = new Geohash(); |
100 | - if(!$p) { |
|
100 | + if (!$p) { |
|
101 | 101 | $decodedPoint = $_geohashClass->read($geohash); |
102 | 102 | } else { |
103 | 103 | $decodedPoint = $p; |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | |
119 | 119 | // find all the pages in the index that overlap with the adjacent hashes |
120 | 120 | $docIds = array(); |
121 | - foreach($adjacent as $adjHash) { |
|
122 | - if(is_array($this->spatial_idx)) { |
|
123 | - foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
124 | - if(strpos($_geohash, $adjHash) !== false) { |
|
121 | + foreach ($adjacent as $adjHash) { |
|
122 | + if (is_array($this->spatial_idx)) { |
|
123 | + foreach ($this->spatial_idx as $_geohash => $_docIds) { |
|
124 | + if (strpos($_geohash, $adjHash) !== false) { |
|
125 | 125 | // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
126 | 126 | // if $adjHash similar to geohash |
127 | 127 | $docIds = array_merge($docIds, $_docIds); |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | $media = array(); |
138 | 138 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
139 | 139 | |
140 | - foreach($docIds as $id) { |
|
141 | - if(strpos($id, 'media__', 0) === 0) { |
|
140 | + foreach ($docIds as $id) { |
|
141 | + if (strpos($id, 'media__', 0) === 0) { |
|
142 | 142 | $id = substr($id, strlen('media__')); |
143 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
143 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
144 | 144 | $point = $indexer->getCoordsFromExif($id); |
145 | 145 | $line = new LineString( |
146 | 146 | [ |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | ); |
151 | 151 | $media [] = array( |
152 | 152 | 'id' => $id, |
153 | - 'distance' => (int) ($line->greatCircleLength()), |
|
153 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
154 | 154 | 'lat' => $point->y(), |
155 | 155 | 'lon' => $point->x() |
156 | 156 | // optionally add other meta such as tag, description... |
157 | 157 | ); |
158 | 158 | } |
159 | 159 | } else { |
160 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
160 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
161 | 161 | $geotags = p_get_metadata($id, 'geo'); |
162 | 162 | $point = new Point($geotags ['lon'], $geotags ['lat']); |
163 | 163 | $line = new LineString( |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | ); |
169 | 169 | $pages [] = array( |
170 | 170 | 'id' => $id, |
171 | - 'distance' => (int) ($line->greatCircleLength()), |
|
171 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
172 | 172 | 'description' => p_get_metadata($id, 'description')['abstract'], |
173 | 173 | 'lat' => $geotags ['lat'], |
174 | 174 | 'lon' => $geotags ['lon'] |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | |
181 | 181 | // sort all the pages/media using distance |
182 | 182 | usort( |
183 | - $pages, static function ($a, $b) { |
|
183 | + $pages, static function($a, $b) { |
|
184 | 184 | return strnatcmp($a ['distance'], $b ['distance']); |
185 | 185 | } |
186 | 186 | ); |
187 | 187 | usort( |
188 | - $media, static function ($a, $b) { |
|
188 | + $media, static function($a, $b) { |
|
189 | 189 | return strnatcmp($a ['distance'], $b ['distance']); |
190 | 190 | } |
191 | 191 | ); |
@@ -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 | } |