@@ -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 { |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | require_once(DOKU_INC . 'inc/search.php'); |
71 | 71 | $pages = array(); |
72 | 72 | search($pages, $conf ['datadir'], 'search_allpages', array()); |
73 | - foreach($pages as $page) { |
|
73 | + foreach ($pages as $page) { |
|
74 | 74 | $this->updateSpatialIndex($page ['id']); |
75 | 75 | } |
76 | 76 | // media |
77 | 77 | $media = array(); |
78 | 78 | search($media, $conf ['mediadir'], 'search_media', array()); |
79 | - foreach($media as $medium) { |
|
80 | - if($medium ['isimg']) { |
|
79 | + foreach ($media as $medium) { |
|
80 | + if ($medium ['isimg']) { |
|
81 | 81 | $this->indexImage($medium); |
82 | 82 | } |
83 | 83 | } |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function updateSpatialIndex(string $id): bool { |
95 | 95 | $geotags = p_get_metadata($id, 'geo'); |
96 | - if(empty ($geotags)) { |
|
96 | + if (empty ($geotags)) { |
|
97 | 97 | return false; |
98 | 98 | } |
99 | - if(empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
99 | + if (empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | dbglog($geotags, "Geo metadata found for page $id"); |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | private function addToIndex(string $geohash, string $id): bool { |
118 | 118 | $pageIds = array(); |
119 | 119 | // check index for key/geohash |
120 | - if(!array_key_exists($geohash, $this->spatial_idx)) { |
|
120 | + if (!array_key_exists($geohash, $this->spatial_idx)) { |
|
121 | 121 | dbglog("Geohash $geohash not in index, just add $id."); |
122 | 122 | $pageIds [] = $id; |
123 | 123 | } else { |
124 | 124 | dbglog('Geohash for document is in index, find it.'); |
125 | 125 | // check the index for document |
126 | 126 | $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
127 | - if(empty ($knownHashes)) { |
|
127 | + if (empty ($knownHashes)) { |
|
128 | 128 | dbglog("No index record found for document $id, just add"); |
129 | 129 | $pageIds = $this->spatial_idx [$geohash]; |
130 | 130 | $pageIds [] = $id; |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
133 | 133 | $knownHash = $knownHashes [0]; |
134 | 134 | |
135 | - if($knownHash === $geohash) { |
|
135 | + if ($knownHash === $geohash) { |
|
136 | 136 | dbglog("Document $id was found in index and has the same geohash, nothing to do."); |
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - if(!empty ($knownHash)) { |
|
140 | + if (!empty ($knownHash)) { |
|
141 | 141 | dbglog("Document/media $id was found in index but has different geohash (it moved)."); |
142 | 142 | $knownIds = $this->spatial_idx [$knownHash]; |
143 | 143 | dbglog($knownIds, "Known id's for this hash:"); |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function findHashesForId(string $id, array $index): array { |
168 | 168 | $hashes = array(); |
169 | - foreach($index as $hash => $docIds) { |
|
170 | - if(in_array($id, $docIds, false)) { |
|
169 | + foreach ($index as $hash => $docIds) { |
|
170 | + if (in_array($id, $docIds, false)) { |
|
171 | 171 | $hashes [] = $hash; |
172 | 172 | } |
173 | 173 | } |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function indexImage($img): bool { |
197 | 197 | // test for supported files (jpeg only) |
198 | - if( |
|
198 | + if ( |
|
199 | 199 | (substr($img ['file'], -strlen('.jpg')) !== '.jpg') && |
200 | 200 | (substr($img ['file'], -strlen('.jpeg')) !== '.jpeg')) { |
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | 204 | $geometry = $this->getCoordsFromExif($img ['id']); |
205 | - if(!$geometry) { |
|
205 | + if (!$geometry) { |
|
206 | 206 | return false; |
207 | 207 | } |
208 | 208 | $geohash = $geometry->out('geohash'); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public function getCoordsFromExif(string $id) { |
223 | 223 | $exif = exif_read_data(mediaFN($id), 0, true); |
224 | - if(empty ($exif ['GPS'])) { |
|
224 | + if (empty ($exif ['GPS'])) { |
|
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return float |
254 | 254 | */ |
255 | 255 | public function convertDMStoD(array $param): float { |
256 | - if(!is_array($param)) { |
|
256 | + if (!is_array($param)) { |
|
257 | 257 | $param = array($param); |
258 | 258 | } |
259 | 259 | $deg = $this->convertRationaltoFloat($param [0]); |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | public function convertRationaltoFloat($param): float { |
268 | 268 | // rational64u |
269 | 269 | $nums = explode('/', $param); |
270 | - if((int) $nums[1] > 0) { |
|
271 | - return (float) $nums[0] / (int) $nums[1]; |
|
270 | + if (( int ) $nums[1] > 0) { |
|
271 | + return ( float ) $nums[0] / ( int ) $nums[1]; |
|
272 | 272 | } else { |
273 | - return (float) $nums[0]; |
|
273 | + return ( float ) $nums[0]; |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | public function deleteFromIndex(string $id): void { |
283 | 283 | // check the index for document |
284 | 284 | $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
285 | - if(empty ($knownHashes)) { |
|
285 | + if (empty ($knownHashes)) { |
|
286 | 286 | return; |
287 | 287 | } |
288 | 288 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | dbglog("removing: $knownIds[$i] from the index."); |
294 | 294 | unset ($knownIds [$i]); |
295 | 295 | $this->spatial_idx [$knownHash] = $knownIds; |
296 | - if(empty ($this->spatial_idx [$knownHash])) { |
|
296 | + if (empty ($this->spatial_idx [$knownHash])) { |
|
297 | 297 | // dbglog ( "removing key: $knownHash from the index." ); |
298 | 298 | unset ($this->spatial_idx [$knownHash]); |
299 | 299 | } |