| @@ -256,11 +256,11 @@ | ||
| 256 | 256 | */ | 
| 257 | 257 | private function printHTML(array $searchresults, bool $showMedia = true): void | 
| 258 | 258 |      { | 
| 259 | - $pages = (array)($searchresults ['pages']); | |
| 260 | - $media = (array)$searchresults ['media']; | |
| 261 | - $lat = (float)$searchresults ['lat']; | |
| 262 | - $lon = (float)$searchresults ['lon']; | |
| 263 | - $geohash = (string)$searchresults ['geohash']; | |
| 259 | + $pages = ( array ) ($searchresults ['pages']); | |
| 260 | + $media = ( array ) $searchresults ['media']; | |
| 261 | + $lat = ( float ) $searchresults ['lat']; | |
| 262 | + $lon = ( float ) $searchresults ['lon']; | |
| 263 | + $geohash = ( string ) $searchresults ['geohash']; | |
| 264 | 264 | |
| 265 | 265 |          if (isset($searchresults ['error'])) { | 
| 266 | 266 | echo '<div class="level1"><p>' . hsc($searchresults ['error']) . '</p></div>'; | 
| @@ -30,369 +30,369 @@ | ||
| 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'] . ' 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'] . ' 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'] . ' 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'] . ' 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 | } | 
| @@ -24,41 +24,41 @@ | ||
| 24 | 24 | class general_plugin_spatialhelper_test extends DokuWikiTest | 
| 25 | 25 |  { | 
| 26 | 26 | |
| 27 | -    protected $pluginsEnabled = array('spatialhelper'); | |
| 27 | +	protected $pluginsEnabled = array('spatialhelper'); | |
| 28 | 28 | |
| 29 | - /** | |
| 30 | - * Simple test to make sure the plugin.info.txt is in correct format. | |
| 31 | - */ | |
| 32 | - final public function test_plugininfo(): void | |
| 33 | -    { | |
| 34 | - $file = __DIR__ . '/../plugin.info.txt'; | |
| 35 | - self::assertFileExists($file); | |
| 29 | + /** | |
| 30 | + * Simple test to make sure the plugin.info.txt is in correct format. | |
| 31 | + */ | |
| 32 | + final public function test_plugininfo(): void | |
| 33 | +	{ | |
| 34 | + $file = __DIR__ . '/../plugin.info.txt'; | |
| 35 | + self::assertFileExists($file); | |
| 36 | 36 | |
| 37 | - $info = confToHash($file); | |
| 37 | + $info = confToHash($file); | |
| 38 | 38 | |
| 39 | -        self::assertArrayHasKey('base', $info); | |
| 40 | -        self::assertArrayHasKey('author', $info); | |
| 41 | -        self::assertArrayHasKey('email', $info); | |
| 42 | -        self::assertArrayHasKey('date', $info); | |
| 43 | -        self::assertArrayHasKey('name', $info); | |
| 44 | -        self::assertArrayHasKey('desc', $info); | |
| 45 | -        self::assertArrayHasKey('url', $info); | |
| 39 | +		self::assertArrayHasKey('base', $info); | |
| 40 | +		self::assertArrayHasKey('author', $info); | |
| 41 | +		self::assertArrayHasKey('email', $info); | |
| 42 | +		self::assertArrayHasKey('date', $info); | |
| 43 | +		self::assertArrayHasKey('name', $info); | |
| 44 | +		self::assertArrayHasKey('desc', $info); | |
| 45 | +		self::assertArrayHasKey('url', $info); | |
| 46 | 46 | |
| 47 | -        self::assertEquals('spatialhelper', $info['base']); | |
| 48 | -        self::assertRegExp('/^https?:\/\//', $info['url']); | |
| 49 | - self::assertTrue(mail_isvalid($info['email'])); | |
| 50 | -        self::assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); | |
| 51 | - self::assertNotFalse(strtotime($info['date'])); | |
| 52 | - } | |
| 47 | +		self::assertEquals('spatialhelper', $info['base']); | |
| 48 | +		self::assertRegExp('/^https?:\/\//', $info['url']); | |
| 49 | + self::assertTrue(mail_isvalid($info['email'])); | |
| 50 | +		self::assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); | |
| 51 | + self::assertNotFalse(strtotime($info['date'])); | |
| 52 | + } | |
| 53 | 53 | |
| 54 | - /** | |
| 55 | - * test if plugin is loaded. | |
| 56 | - */ | |
| 57 | - final public function test_plugin_spatialhelper_isloaded(): void | |
| 58 | -    { | |
| 59 | - global $plugin_controller; | |
| 60 | - self::assertContains( | |
| 61 | - 'spatialhelper', $plugin_controller->getList(), "spatialhelper plugin is loaded" | |
| 62 | - ); | |
| 63 | - } | |
| 54 | + /** | |
| 55 | + * test if plugin is loaded. | |
| 56 | + */ | |
| 57 | + final public function test_plugin_spatialhelper_isloaded(): void | |
| 58 | +	{ | |
| 59 | + global $plugin_controller; | |
| 60 | + self::assertContains( | |
| 61 | + 'spatialhelper', $plugin_controller->getList(), "spatialhelper plugin is loaded" | |
| 62 | + ); | |
| 63 | + } | |
| 64 | 64 | } | 
| @@ -27,63 +27,63 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | class admin_plugin_spatialhelper_purge extends AdminPlugin | 
| 29 | 29 |  { | 
| 30 | - /** | |
| 31 | - * | |
| 32 | - * @see DokuWiki_Admin_Plugin::getMenuSort() | |
| 33 | - */ | |
| 34 | - final public function getMenuSort(): int | |
| 35 | -    { | |
| 36 | - return 801; | |
| 37 | - } | |
| 30 | + /** | |
| 31 | + * | |
| 32 | + * @see DokuWiki_Admin_Plugin::getMenuSort() | |
| 33 | + */ | |
| 34 | + final public function getMenuSort(): int | |
| 35 | +	{ | |
| 36 | + return 801; | |
| 37 | + } | |
| 38 | 38 | |
| 39 | - final public function getMenuIcon(): string | |
| 40 | -    { | |
| 41 | - $plugin = $this->getPluginName(); | |
| 42 | - return DOKU_PLUGIN . $plugin . '/admin/purge.svg'; | |
| 43 | - } | |
| 39 | + final public function getMenuIcon(): string | |
| 40 | +	{ | |
| 41 | + $plugin = $this->getPluginName(); | |
| 42 | + return DOKU_PLUGIN . $plugin . '/admin/purge.svg'; | |
| 43 | + } | |
| 44 | 44 | |
| 45 | - /** | |
| 46 | - * purge and regenerate the index and sitemaps. | |
| 47 | - * | |
| 48 | - * @see DokuWiki_Admin_Plugin::handle() | |
| 49 | - */ | |
| 50 | - final public function handle(): void | |
| 51 | -    { | |
| 52 | -        if (isset($_REQUEST ['purgeindex'])) { | |
| 53 | - global $conf; | |
| 54 | - $path = $conf ['indexdir'] . '/spatial.idx'; | |
| 55 | -            if (file_exists($path) && unlink($path)) { | |
| 56 | -                msg($this->getLang('admin_purged_tiles'), 0); | |
| 57 | - } | |
| 58 | - } | |
| 45 | + /** | |
| 46 | + * purge and regenerate the index and sitemaps. | |
| 47 | + * | |
| 48 | + * @see DokuWiki_Admin_Plugin::handle() | |
| 49 | + */ | |
| 50 | + final public function handle(): void | |
| 51 | +	{ | |
| 52 | +		if (isset($_REQUEST ['purgeindex'])) { | |
| 53 | + global $conf; | |
| 54 | + $path = $conf ['indexdir'] . '/spatial.idx'; | |
| 55 | +			if (file_exists($path) && unlink($path)) { | |
| 56 | +				msg($this->getLang('admin_purged_tiles'), 0); | |
| 57 | + } | |
| 58 | + } | |
| 59 | 59 | |
| 60 | -        $indexer = plugin_load('helper', 'spatialhelper_index'); | |
| 61 | -        if (isset($indexer)) { | |
| 62 | - $indexer->generateSpatialIndex(); | |
| 63 | - } | |
| 60 | +		$indexer = plugin_load('helper', 'spatialhelper_index'); | |
| 61 | +		if (isset($indexer)) { | |
| 62 | + $indexer->generateSpatialIndex(); | |
| 63 | + } | |
| 64 | 64 | |
| 65 | -        $sitemapper = plugin_load('helper', 'spatialhelper_sitemap'); | |
| 66 | -        if (isset($sitemapper)) { | |
| 67 | -            $sitemapper->createKMLSitemap($this->getConf('media_kml')); | |
| 68 | -            $sitemapper->createGeoRSSSitemap($this->getConf('media_georss')); | |
| 69 | - } | |
| 70 | - } | |
| 65 | +		$sitemapper = plugin_load('helper', 'spatialhelper_sitemap'); | |
| 66 | +		if (isset($sitemapper)) { | |
| 67 | +			$sitemapper->createKMLSitemap($this->getConf('media_kml')); | |
| 68 | +			$sitemapper->createGeoRSSSitemap($this->getConf('media_georss')); | |
| 69 | + } | |
| 70 | + } | |
| 71 | 71 | |
| 72 | - /** | |
| 73 | - * render the form for this plugin. | |
| 74 | - * | |
| 75 | - * @see DokuWiki_Admin_Plugin::html() | |
| 76 | - */ | |
| 77 | - final public function html(): void | |
| 78 | -    { | |
| 79 | -        echo $this->locale_xhtml('admin_purge_intro'); | |
| 72 | + /** | |
| 73 | + * render the form for this plugin. | |
| 74 | + * | |
| 75 | + * @see DokuWiki_Admin_Plugin::html() | |
| 76 | + */ | |
| 77 | + final public function html(): void | |
| 78 | +	{ | |
| 79 | +		echo $this->locale_xhtml('admin_purge_intro'); | |
| 80 | 80 | |
| 81 | - $form = new Form( | |
| 82 | - ['id' => 'spatialhelper__purgeform', 'method' => 'post'] | |
| 83 | - ); | |
| 84 | -        $form->setHiddenField('purgeindex', 'true'); | |
| 85 | -        $form->addButton('submit', $this->getLang('admin_submit')) | |
| 86 | -            ->attr('title', $this->getLang('admin_submit')); | |
| 87 | - echo $form->toHTML(); | |
| 88 | - } | |
| 81 | + $form = new Form( | |
| 82 | + ['id' => 'spatialhelper__purgeform', 'method' => 'post'] | |
| 83 | + ); | |
| 84 | +		$form->setHiddenField('purgeindex', 'true'); | |
| 85 | +		$form->addButton('submit', $this->getLang('admin_submit')) | |
| 86 | +			->attr('title', $this->getLang('admin_submit')); | |
| 87 | + echo $form->toHTML(); | |
| 88 | + } | |
| 89 | 89 | } | 
| @@ -27,218 +27,218 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | class helper_plugin_spatialhelper_sitemap extends Plugin | 
| 29 | 29 |  { | 
| 30 | - /** | |
| 31 | - * spatial index. | |
| 32 | - */ | |
| 33 | - private $spatial_idx; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * constructor, load spatial index. | |
| 37 | - */ | |
| 38 | - public function __construct() | |
| 39 | -    { | |
| 40 | - global $conf; | |
| 41 | - $idx_dir = $conf['indexdir']; | |
| 42 | -        if (!@file_exists($idx_dir . '/spatial.idx')) { | |
| 43 | -            $indexer = plugin_load('helper', 'spatialhelper_index'); | |
| 44 | -            if ($indexer !== null) { | |
| 45 | - $indexer->generateSpatialIndex(); | |
| 46 | - } | |
| 47 | - } | |
| 48 | - $this->spatial_idx = unserialize( | |
| 49 | - io_readFile($idx_dir . '/spatial.idx', false), | |
| 50 | - ['allowed_classes' => false] | |
| 51 | - ); | |
| 52 | - } | |
| 53 | - | |
| 54 | - final public function getMethods(): array | |
| 55 | -    { | |
| 56 | - $result[] = [ | |
| 57 | - 'name' => 'createGeoRSSSitemap', | |
| 58 | - 'desc' => 'create a spatial sitemap in GeoRSS format.', | |
| 59 | - 'params' => ['path' => 'string'], 'return' => ['success' => 'boolean'] | |
| 60 | - ]; | |
| 61 | - $result[] = [ | |
| 62 | - 'name' => 'createKMLSitemap', | |
| 63 | - 'desc' => 'create a spatial sitemap in KML format.', | |
| 64 | - 'params' => ['path' => 'string'], 'return' => ['success' => 'boolean'] | |
| 65 | - ]; | |
| 66 | - return $result; | |
| 67 | - } | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * Create a GeoRSS Simple sitemap (Atom). | |
| 71 | - * | |
| 72 | - * @param string $mediaID id | |
| 73 | - * for the GeoRSS file | |
| 74 | - */ | |
| 75 | - final public function createGeoRSSSitemap(string $mediaID): bool | |
| 76 | -    { | |
| 77 | - global $conf; | |
| 78 | - $namespace = getNS($mediaID); | |
| 79 | - | |
| 80 | - $idTag = 'tag:' . parse_url(DOKU_URL, PHP_URL_HOST) . ','; | |
| 81 | - | |
| 82 | - $RSSstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; | |
| 83 | - $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '; | |
| 84 | - $RSSstart .= 'xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF; | |
| 85 | - $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF; | |
| 86 | -        if (!empty($conf['tagline'])) { | |
| 87 | - $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF; | |
| 88 | - } | |
| 89 | - $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF; | |
| 90 | - $RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF; | |
| 91 | - $RSSstart .= '<link href="' . ml($mediaID, '', true, '&', true) . '" rel="self" />' . DOKU_LF; | |
| 92 | - $RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF; | |
| 93 | -        $RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) | |
| 94 | - . '</id>' . DOKU_LF; | |
| 95 | - $RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF; | |
| 96 | - | |
| 97 | - $RSSend = '</feed>' . DOKU_LF; | |
| 98 | - | |
| 99 | - io_createNamespace($mediaID, 'media'); | |
| 100 | - @touch(mediaFN($mediaID)); | |
| 101 | - @chmod(mediaFN($mediaID), $conf['fmode']); | |
| 102 | - $fh = fopen(mediaFN($mediaID), 'wb'); | |
| 103 | - fwrite($fh, $RSSstart); | |
| 104 | - | |
| 105 | -        foreach ($this->spatial_idx as $idxEntry) { | |
| 106 | - // get list of id's | |
| 107 | -            foreach ($idxEntry as $id) { | |
| 108 | - // for document item in the index | |
| 109 | -                if (strpos($id, 'media__') !== 0) { | |
| 110 | -                    if ($this->skipPage($id, $namespace)) { | |
| 111 | - continue; | |
| 112 | - } | |
| 113 | - | |
| 114 | - $meta = p_get_metadata($id); | |
| 115 | - | |
| 116 | -                    // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); | |
| 117 | - $desc = strip_tags($meta['description']['abstract']); | |
| 118 | - | |
| 119 | - $entry = '<entry>' . DOKU_LF; | |
| 120 | - $entry .= ' <title>' . $meta['title'] . '</title>' . DOKU_LF; | |
| 121 | - $entry .= ' <summary>' . $desc . '</summary>' . DOKU_LF; | |
| 122 | - $entry .= ' <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] | |
| 123 | - . '</georss:point>' . DOKU_LF; | |
| 124 | -                    if (!empty($meta['geo']['alt'])) { | |
| 125 | - $entry .= ' <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF; | |
| 126 | - } | |
| 127 | - $entry .= ' <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF; | |
| 128 | -                    if (empty($meta['creator'])) { | |
| 129 | - $meta['creator'] = $conf['title']; | |
| 130 | - } | |
| 131 | - $entry .= ' <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF; | |
| 132 | - $entry .= ' <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF; | |
| 133 | - $entry .= ' <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF; | |
| 134 | -                    $entry .= '  <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':' | |
| 135 | - . parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF; | |
| 136 | - $entry .= '</entry>' . DOKU_LF; | |
| 137 | - fwrite($fh, $entry); | |
| 138 | - } | |
| 139 | - } | |
| 140 | - } | |
| 141 | - | |
| 142 | - fwrite($fh, $RSSend); | |
| 143 | - return fclose($fh); | |
| 144 | - } | |
| 145 | - | |
| 146 | - /** | |
| 147 | - * will return true for non-public or hidden pages or pages that are not below or in the namespace. | |
| 148 | - */ | |
| 149 | - private function skipPage(string $id, string $namespace): bool | |
| 150 | -    { | |
| 151 | -        Logger::debug("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace"); | |
| 152 | -        if (isHiddenPage($id)) { | |
| 153 | - return true; | |
| 154 | - } | |
| 155 | -        if (auth_aclcheck($id, '', null) < AUTH_READ) { | |
| 156 | - return true; | |
| 157 | - } | |
| 158 | - | |
| 159 | -        if (!empty($namespace)) { | |
| 160 | - // only if id is in or below namespace | |
| 161 | -            if (0 !== strpos(getNS($id), $namespace)) { | |
| 162 | - return true; | |
| 163 | - } | |
| 164 | - } | |
| 165 | - return false; | |
| 166 | - } | |
| 167 | - | |
| 168 | - /** | |
| 169 | - * Create a KML sitemap. | |
| 170 | - * | |
| 171 | - * @param string $mediaID id for the KML file | |
| 172 | - */ | |
| 173 | - final public function createKMLSitemap(string $mediaID): bool | |
| 174 | -    { | |
| 175 | - global $conf; | |
| 176 | - $namespace = getNS($mediaID); | |
| 177 | - | |
| 178 | - $KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; | |
| 179 | - $KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" '; | |
| 180 | - $KMLstart .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '; | |
| 181 | - $KMLstart .= 'xmlns:atom="http://www.w3.org/2005/Atom"'; | |
| 182 | - $KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 '; | |
| 183 | - $KMLstart .= 'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF; | |
| 184 | - $KMLstart .= '<Document id="root_doc">' . DOKU_LF; | |
| 185 | - $KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF; | |
| 186 | - $KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF; | |
| 187 | - $KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF; | |
| 188 | - $KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>'; | |
| 189 | - $KMLstart .= '<Icon><href>' | |
| 190 | - . DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF; | |
| 191 | - | |
| 192 | - $KMLend = '</Document>' . DOKU_LF . '</kml>'; | |
| 193 | - | |
| 194 | - io_createNamespace($mediaID, 'media'); | |
| 195 | - @touch(mediaFN($mediaID)); | |
| 196 | - @chmod(mediaFN($mediaID), $conf['fmode']); | |
| 197 | - | |
| 198 | - $fh = fopen(mediaFN($mediaID), 'wb'); | |
| 199 | - fwrite($fh, $KMLstart); | |
| 200 | - | |
| 201 | -        foreach ($this->spatial_idx as $idxEntry) { | |
| 202 | - // get list of id's | |
| 203 | -            foreach ($idxEntry as $id) { | |
| 204 | - // for document item in the index | |
| 205 | -                if (strpos($id, 'media__') !== 0) { | |
| 206 | -                    if ($this->skipPage($id, $namespace)) { | |
| 207 | - continue; | |
| 208 | - } | |
| 209 | - | |
| 210 | - $meta = p_get_metadata($id); | |
| 211 | - | |
| 212 | -                    // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); | |
| 213 | - $desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>'; | |
| 214 | - $desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>'; | |
| 215 | - | |
| 216 | - // create an entry and store it | |
| 217 | -                    $plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF; | |
| 218 | - $plcm .= ' <name>' . $meta['title'] . '</name>' . DOKU_LF; | |
| 219 | - // TODO escape quotes in: title="' . $meta['title'] . '" | |
| 220 | - $plcm .= ' <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' | |
| 221 | - . DOKU_LF; | |
| 222 | -                    if (!empty($meta['creator'])) { | |
| 223 | - $plcm .= ' <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' | |
| 224 | - . DOKU_LF; | |
| 225 | - } | |
| 226 | - | |
| 227 | - $plcm .= ' <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF; | |
| 228 | - $plcm .= ' <styleUrl>#icon</styleUrl>' . DOKU_LF; | |
| 229 | - | |
| 230 | - $plcm .= ' <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat']; | |
| 231 | -                    if (!empty($meta['geo']['alt'])) { | |
| 232 | - $plcm .= ',' . $meta['geo']['alt']; | |
| 233 | - } | |
| 234 | - $plcm .= '</coordinates></Point>' . DOKU_LF; | |
| 235 | - $plcm .= '</Placemark>' . DOKU_LF; | |
| 236 | - | |
| 237 | - fwrite($fh, $plcm); | |
| 238 | - } | |
| 239 | - } | |
| 240 | - } | |
| 241 | - fwrite($fh, $KMLend); | |
| 242 | - return fclose($fh); | |
| 243 | - } | |
| 30 | + /** | |
| 31 | + * spatial index. | |
| 32 | + */ | |
| 33 | + private $spatial_idx; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * constructor, load spatial index. | |
| 37 | + */ | |
| 38 | + public function __construct() | |
| 39 | +	{ | |
| 40 | + global $conf; | |
| 41 | + $idx_dir = $conf['indexdir']; | |
| 42 | +		if (!@file_exists($idx_dir . '/spatial.idx')) { | |
| 43 | +			$indexer = plugin_load('helper', 'spatialhelper_index'); | |
| 44 | +			if ($indexer !== null) { | |
| 45 | + $indexer->generateSpatialIndex(); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + $this->spatial_idx = unserialize( | |
| 49 | + io_readFile($idx_dir . '/spatial.idx', false), | |
| 50 | + ['allowed_classes' => false] | |
| 51 | + ); | |
| 52 | + } | |
| 53 | + | |
| 54 | + final public function getMethods(): array | |
| 55 | +	{ | |
| 56 | + $result[] = [ | |
| 57 | + 'name' => 'createGeoRSSSitemap', | |
| 58 | + 'desc' => 'create a spatial sitemap in GeoRSS format.', | |
| 59 | + 'params' => ['path' => 'string'], 'return' => ['success' => 'boolean'] | |
| 60 | + ]; | |
| 61 | + $result[] = [ | |
| 62 | + 'name' => 'createKMLSitemap', | |
| 63 | + 'desc' => 'create a spatial sitemap in KML format.', | |
| 64 | + 'params' => ['path' => 'string'], 'return' => ['success' => 'boolean'] | |
| 65 | + ]; | |
| 66 | + return $result; | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Create a GeoRSS Simple sitemap (Atom). | |
| 71 | + * | |
| 72 | + * @param string $mediaID id | |
| 73 | + * for the GeoRSS file | |
| 74 | + */ | |
| 75 | + final public function createGeoRSSSitemap(string $mediaID): bool | |
| 76 | +	{ | |
| 77 | + global $conf; | |
| 78 | + $namespace = getNS($mediaID); | |
| 79 | + | |
| 80 | + $idTag = 'tag:' . parse_url(DOKU_URL, PHP_URL_HOST) . ','; | |
| 81 | + | |
| 82 | + $RSSstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; | |
| 83 | + $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '; | |
| 84 | + $RSSstart .= 'xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF; | |
| 85 | + $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF; | |
| 86 | +		if (!empty($conf['tagline'])) { | |
| 87 | + $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF; | |
| 88 | + } | |
| 89 | + $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF; | |
| 90 | + $RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF; | |
| 91 | + $RSSstart .= '<link href="' . ml($mediaID, '', true, '&', true) . '" rel="self" />' . DOKU_LF; | |
| 92 | + $RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF; | |
| 93 | +		$RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) | |
| 94 | + . '</id>' . DOKU_LF; | |
| 95 | + $RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF; | |
| 96 | + | |
| 97 | + $RSSend = '</feed>' . DOKU_LF; | |
| 98 | + | |
| 99 | + io_createNamespace($mediaID, 'media'); | |
| 100 | + @touch(mediaFN($mediaID)); | |
| 101 | + @chmod(mediaFN($mediaID), $conf['fmode']); | |
| 102 | + $fh = fopen(mediaFN($mediaID), 'wb'); | |
| 103 | + fwrite($fh, $RSSstart); | |
| 104 | + | |
| 105 | +		foreach ($this->spatial_idx as $idxEntry) { | |
| 106 | + // get list of id's | |
| 107 | +			foreach ($idxEntry as $id) { | |
| 108 | + // for document item in the index | |
| 109 | +				if (strpos($id, 'media__') !== 0) { | |
| 110 | +					if ($this->skipPage($id, $namespace)) { | |
| 111 | + continue; | |
| 112 | + } | |
| 113 | + | |
| 114 | + $meta = p_get_metadata($id); | |
| 115 | + | |
| 116 | +					// $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); | |
| 117 | + $desc = strip_tags($meta['description']['abstract']); | |
| 118 | + | |
| 119 | + $entry = '<entry>' . DOKU_LF; | |
| 120 | + $entry .= ' <title>' . $meta['title'] . '</title>' . DOKU_LF; | |
| 121 | + $entry .= ' <summary>' . $desc . '</summary>' . DOKU_LF; | |
| 122 | + $entry .= ' <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] | |
| 123 | + . '</georss:point>' . DOKU_LF; | |
| 124 | +					if (!empty($meta['geo']['alt'])) { | |
| 125 | + $entry .= ' <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF; | |
| 126 | + } | |
| 127 | + $entry .= ' <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF; | |
| 128 | +					if (empty($meta['creator'])) { | |
| 129 | + $meta['creator'] = $conf['title']; | |
| 130 | + } | |
| 131 | + $entry .= ' <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF; | |
| 132 | + $entry .= ' <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF; | |
| 133 | + $entry .= ' <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF; | |
| 134 | +					$entry .= '  <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':' | |
| 135 | + . parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF; | |
| 136 | + $entry .= '</entry>' . DOKU_LF; | |
| 137 | + fwrite($fh, $entry); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + } | |
| 141 | + | |
| 142 | + fwrite($fh, $RSSend); | |
| 143 | + return fclose($fh); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * will return true for non-public or hidden pages or pages that are not below or in the namespace. | |
| 148 | + */ | |
| 149 | + private function skipPage(string $id, string $namespace): bool | |
| 150 | +	{ | |
| 151 | +		Logger::debug("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace"); | |
| 152 | +		if (isHiddenPage($id)) { | |
| 153 | + return true; | |
| 154 | + } | |
| 155 | +		if (auth_aclcheck($id, '', null) < AUTH_READ) { | |
| 156 | + return true; | |
| 157 | + } | |
| 158 | + | |
| 159 | +		if (!empty($namespace)) { | |
| 160 | + // only if id is in or below namespace | |
| 161 | +			if (0 !== strpos(getNS($id), $namespace)) { | |
| 162 | + return true; | |
| 163 | + } | |
| 164 | + } | |
| 165 | + return false; | |
| 166 | + } | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Create a KML sitemap. | |
| 170 | + * | |
| 171 | + * @param string $mediaID id for the KML file | |
| 172 | + */ | |
| 173 | + final public function createKMLSitemap(string $mediaID): bool | |
| 174 | +	{ | |
| 175 | + global $conf; | |
| 176 | + $namespace = getNS($mediaID); | |
| 177 | + | |
| 178 | + $KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; | |
| 179 | + $KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" '; | |
| 180 | + $KMLstart .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '; | |
| 181 | + $KMLstart .= 'xmlns:atom="http://www.w3.org/2005/Atom"'; | |
| 182 | + $KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 '; | |
| 183 | + $KMLstart .= 'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF; | |
| 184 | + $KMLstart .= '<Document id="root_doc">' . DOKU_LF; | |
| 185 | + $KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF; | |
| 186 | + $KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF; | |
| 187 | + $KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF; | |
| 188 | + $KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>'; | |
| 189 | + $KMLstart .= '<Icon><href>' | |
| 190 | + . DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF; | |
| 191 | + | |
| 192 | + $KMLend = '</Document>' . DOKU_LF . '</kml>'; | |
| 193 | + | |
| 194 | + io_createNamespace($mediaID, 'media'); | |
| 195 | + @touch(mediaFN($mediaID)); | |
| 196 | + @chmod(mediaFN($mediaID), $conf['fmode']); | |
| 197 | + | |
| 198 | + $fh = fopen(mediaFN($mediaID), 'wb'); | |
| 199 | + fwrite($fh, $KMLstart); | |
| 200 | + | |
| 201 | +		foreach ($this->spatial_idx as $idxEntry) { | |
| 202 | + // get list of id's | |
| 203 | +			foreach ($idxEntry as $id) { | |
| 204 | + // for document item in the index | |
| 205 | +				if (strpos($id, 'media__') !== 0) { | |
| 206 | +					if ($this->skipPage($id, $namespace)) { | |
| 207 | + continue; | |
| 208 | + } | |
| 209 | + | |
| 210 | + $meta = p_get_metadata($id); | |
| 211 | + | |
| 212 | +					// $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); | |
| 213 | + $desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>'; | |
| 214 | + $desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>'; | |
| 215 | + | |
| 216 | + // create an entry and store it | |
| 217 | +					$plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF; | |
| 218 | + $plcm .= ' <name>' . $meta['title'] . '</name>' . DOKU_LF; | |
| 219 | + // TODO escape quotes in: title="' . $meta['title'] . '" | |
| 220 | + $plcm .= ' <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' | |
| 221 | + . DOKU_LF; | |
| 222 | +					if (!empty($meta['creator'])) { | |
| 223 | + $plcm .= ' <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' | |
| 224 | + . DOKU_LF; | |
| 225 | + } | |
| 226 | + | |
| 227 | + $plcm .= ' <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF; | |
| 228 | + $plcm .= ' <styleUrl>#icon</styleUrl>' . DOKU_LF; | |
| 229 | + | |
| 230 | + $plcm .= ' <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat']; | |
| 231 | +					if (!empty($meta['geo']['alt'])) { | |
| 232 | + $plcm .= ',' . $meta['geo']['alt']; | |
| 233 | + } | |
| 234 | + $plcm .= '</coordinates></Point>' . DOKU_LF; | |
| 235 | + $plcm .= '</Placemark>' . DOKU_LF; | |
| 236 | + | |
| 237 | + fwrite($fh, $plcm); | |
| 238 | + } | |
| 239 | + } | |
| 240 | + } | |
| 241 | + fwrite($fh, $KMLend); | |
| 242 | + return fclose($fh); | |
| 243 | + } | |
| 244 | 244 | } | 
| @@ -30,155 +30,155 @@ | ||
| 30 | 30 | */ | 
| 31 | 31 | class helper_plugin_spatialhelper_search extends Plugin | 
| 32 | 32 |  { | 
| 33 | - /** | |
| 34 | - * spatial index. | |
| 35 | - * | |
| 36 | - * @var array | |
| 37 | - */ | |
| 38 | - protected $spatial_idx = []; | |
| 39 | - /** | |
| 40 | - * Precision, Distance of Adjacent Cell in Meters. | |
| 41 | - * | |
| 42 | - * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance | |
| 43 | - * | |
| 44 | - * @var float | |
| 45 | - */ | |
| 46 | - private $precision = [5_003_530, 625441, 123264, 19545, 3803, 610, 118, 19, 3.7, 0.6]; | |
| 33 | + /** | |
| 34 | + * spatial index. | |
| 35 | + * | |
| 36 | + * @var array | |
| 37 | + */ | |
| 38 | + protected $spatial_idx = []; | |
| 39 | + /** | |
| 40 | + * Precision, Distance of Adjacent Cell in Meters. | |
| 41 | + * | |
| 42 | + * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance | |
| 43 | + * | |
| 44 | + * @var float | |
| 45 | + */ | |
| 46 | + private $precision = [5_003_530, 625441, 123264, 19545, 3803, 610, 118, 19, 3.7, 0.6]; | |
| 47 | 47 | |
| 48 | - /** | |
| 49 | - * constructor; initialize/load spatial index. | |
| 50 | - */ | |
| 51 | - public function __construct() | |
| 52 | -    { | |
| 53 | - global $conf; | |
| 48 | + /** | |
| 49 | + * constructor; initialize/load spatial index. | |
| 50 | + */ | |
| 51 | + public function __construct() | |
| 52 | +	{ | |
| 53 | + global $conf; | |
| 54 | 54 | |
| 55 | -        if (plugin_load('helper', 'geophp', false, true) === null) { | |
| 56 | - $message = | |
| 57 | - 'helper_plugin_spatialhelper_search::spatialhelper_search: required geophp plugin is not available.'; | |
| 58 | - msg($message, -1); | |
| 59 | - } | |
| 55 | +		if (plugin_load('helper', 'geophp', false, true) === null) { | |
| 56 | + $message = | |
| 57 | + 'helper_plugin_spatialhelper_search::spatialhelper_search: required geophp plugin is not available.'; | |
| 58 | + msg($message, -1); | |
| 59 | + } | |
| 60 | 60 | |
| 61 | - $idx_dir = $conf ['indexdir']; | |
| 62 | -        if (!@file_exists($idx_dir . '/spatial.idx')) { | |
| 63 | -            plugin_load('helper', 'spatialhelper_index'); | |
| 64 | - } | |
| 61 | + $idx_dir = $conf ['indexdir']; | |
| 62 | +		if (!@file_exists($idx_dir . '/spatial.idx')) { | |
| 63 | +			plugin_load('helper', 'spatialhelper_index'); | |
| 64 | + } | |
| 65 | 65 | |
| 66 | - $this->spatial_idx = unserialize(io_readFile($idx_dir . '/spatial.idx', false), ['allowed_classes' => false]); | |
| 67 | - } | |
| 66 | + $this->spatial_idx = unserialize(io_readFile($idx_dir . '/spatial.idx', false), ['allowed_classes' => false]); | |
| 67 | + } | |
| 68 | 68 | |
| 69 | - /** | |
| 70 | - * Find locations based on the coordinate pair. | |
| 71 | - * | |
| 72 | - * @param float $lat | |
| 73 | - * The y coordinate (or latitude) | |
| 74 | - * @param float $lon | |
| 75 | - * The x coordinate (or longitude) | |
| 76 | - * @throws Exception | |
| 77 | - */ | |
| 78 | - final public function findNearbyLatLon(float $lat, float $lon): array | |
| 79 | -    { | |
| 80 | - $geometry = new Point($lon, $lat); | |
| 81 | -        return $this->findNearby($geometry->out('geohash'), $geometry); | |
| 82 | - } | |
| 69 | + /** | |
| 70 | + * Find locations based on the coordinate pair. | |
| 71 | + * | |
| 72 | + * @param float $lat | |
| 73 | + * The y coordinate (or latitude) | |
| 74 | + * @param float $lon | |
| 75 | + * The x coordinate (or longitude) | |
| 76 | + * @throws Exception | |
| 77 | + */ | |
| 78 | + final public function findNearbyLatLon(float $lat, float $lon): array | |
| 79 | +	{ | |
| 80 | + $geometry = new Point($lon, $lat); | |
| 81 | +		return $this->findNearby($geometry->out('geohash'), $geometry); | |
| 82 | + } | |
| 83 | 83 | |
| 84 | - /** | |
| 85 | - * finds nearby elements in the index based on the geohash. | |
| 86 | - * returns a list of documents and the bunding box. | |
| 87 | - * | |
| 88 | - * @param string $geohash | |
| 89 | - * @param Point|null $p | |
| 90 | - * optional point | |
| 91 | - * @return array of ... | |
| 92 | - * @throws Exception | |
| 93 | - */ | |
| 94 | - final public function findNearby(string $geohash, Point $p = null): array | |
| 95 | -    { | |
| 96 | - $_geohashClass = new Geohash(); | |
| 97 | -        if (!$p instanceof Point) { | |
| 98 | - $decodedPoint = $_geohashClass->read($geohash); | |
| 99 | -        } else { | |
| 100 | - $decodedPoint = $p; | |
| 101 | - } | |
| 84 | + /** | |
| 85 | + * finds nearby elements in the index based on the geohash. | |
| 86 | + * returns a list of documents and the bunding box. | |
| 87 | + * | |
| 88 | + * @param string $geohash | |
| 89 | + * @param Point|null $p | |
| 90 | + * optional point | |
| 91 | + * @return array of ... | |
| 92 | + * @throws Exception | |
| 93 | + */ | |
| 94 | + final public function findNearby(string $geohash, Point $p = null): array | |
| 95 | +	{ | |
| 96 | + $_geohashClass = new Geohash(); | |
| 97 | +		if (!$p instanceof Point) { | |
| 98 | + $decodedPoint = $_geohashClass->read($geohash); | |
| 99 | +		} else { | |
| 100 | + $decodedPoint = $p; | |
| 101 | + } | |
| 102 | 102 | |
| 103 | - // find adjacent blocks | |
| 104 | - $adjacent = []; | |
| 105 | - $adjacent ['center'] = $geohash; | |
| 106 | - $adjacent ['top'] = Geohash::adjacent($adjacent ['center'], 'top'); | |
| 107 | - $adjacent ['bottom'] = Geohash::adjacent($adjacent ['center'], 'bottom'); | |
| 108 | - $adjacent ['right'] = Geohash::adjacent($adjacent ['center'], 'right'); | |
| 109 | - $adjacent ['left'] = Geohash::adjacent($adjacent ['center'], 'left'); | |
| 110 | - $adjacent ['topleft'] = Geohash::adjacent($adjacent ['left'], 'top'); | |
| 111 | - $adjacent ['topright'] = Geohash::adjacent($adjacent ['right'], 'top'); | |
| 112 | - $adjacent ['bottomright'] = Geohash::adjacent($adjacent ['right'], 'bottom'); | |
| 113 | - $adjacent ['bottomleft'] = Geohash::adjacent($adjacent ['left'], 'bottom'); | |
| 114 | -        Logger::debug("adjacent geo hashes", $adjacent); | |
| 103 | + // find adjacent blocks | |
| 104 | + $adjacent = []; | |
| 105 | + $adjacent ['center'] = $geohash; | |
| 106 | + $adjacent ['top'] = Geohash::adjacent($adjacent ['center'], 'top'); | |
| 107 | + $adjacent ['bottom'] = Geohash::adjacent($adjacent ['center'], 'bottom'); | |
| 108 | + $adjacent ['right'] = Geohash::adjacent($adjacent ['center'], 'right'); | |
| 109 | + $adjacent ['left'] = Geohash::adjacent($adjacent ['center'], 'left'); | |
| 110 | + $adjacent ['topleft'] = Geohash::adjacent($adjacent ['left'], 'top'); | |
| 111 | + $adjacent ['topright'] = Geohash::adjacent($adjacent ['right'], 'top'); | |
| 112 | + $adjacent ['bottomright'] = Geohash::adjacent($adjacent ['right'], 'bottom'); | |
| 113 | + $adjacent ['bottomleft'] = Geohash::adjacent($adjacent ['left'], 'bottom'); | |
| 114 | +		Logger::debug("adjacent geo hashes", $adjacent); | |
| 115 | 115 | |
| 116 | - // find all the pages in the index that overlap with the adjacent hashes | |
| 117 | - $docIds = []; | |
| 118 | -        foreach ($adjacent as $adjHash) { | |
| 119 | -            if (is_array($this->spatial_idx)) { | |
| 120 | -                foreach ($this->spatial_idx as $_geohash => $_docIds) { | |
| 121 | -                    if (strpos($_geohash, (string)$adjHash) !== false) { | |
| 122 | - // if $adjHash similar to geohash | |
| 123 | - $docIds = array_merge($docIds, $_docIds); | |
| 124 | - } | |
| 125 | - } | |
| 126 | - } | |
| 127 | - } | |
| 128 | - $docIds = array_unique($docIds); | |
| 129 | -        Logger::debug("found docIDs", $docIds); | |
| 116 | + // find all the pages in the index that overlap with the adjacent hashes | |
| 117 | + $docIds = []; | |
| 118 | +		foreach ($adjacent as $adjHash) { | |
| 119 | +			if (is_array($this->spatial_idx)) { | |
| 120 | +				foreach ($this->spatial_idx as $_geohash => $_docIds) { | |
| 121 | +					if (strpos($_geohash, (string)$adjHash) !== false) { | |
| 122 | + // if $adjHash similar to geohash | |
| 123 | + $docIds = array_merge($docIds, $_docIds); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + } | |
| 127 | + } | |
| 128 | + $docIds = array_unique($docIds); | |
| 129 | +		Logger::debug("found docIDs", $docIds); | |
| 130 | 130 | |
| 131 | - // create associative array of pages + calculate distance | |
| 132 | - $pages = []; | |
| 133 | - $media = []; | |
| 134 | -        $indexer = plugin_load('helper', 'spatialhelper_index'); | |
| 131 | + // create associative array of pages + calculate distance | |
| 132 | + $pages = []; | |
| 133 | + $media = []; | |
| 134 | +		$indexer = plugin_load('helper', 'spatialhelper_index'); | |
| 135 | 135 | |
| 136 | -        foreach ($docIds as $id) { | |
| 137 | -            if (strpos($id, 'media__') === 0) { | |
| 138 | -                $id = substr($id, strlen('media__')); | |
| 139 | -                if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { | |
| 140 | - $point = $indexer->getCoordsFromExif($id); | |
| 141 | - $line = new LineString( | |
| 142 | - [ | |
| 143 | - $decodedPoint, | |
| 144 | - $point | |
| 145 | - ] | |
| 146 | - ); | |
| 147 | - $media [] = ['id' => $id, 'distance' => (int)($line->greatCircleLength()), | |
| 148 | - 'lat' => $point->y(), 'lon' => $point->x()]; | |
| 149 | - } | |
| 150 | -            } elseif (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { | |
| 151 | - $geotags = p_get_metadata($id, 'geo'); | |
| 152 | - $point = new Point($geotags ['lon'], $geotags ['lat']); | |
| 153 | - $line = new LineString( | |
| 154 | - [ | |
| 155 | - $decodedPoint, | |
| 156 | - $point | |
| 157 | - ] | |
| 158 | - ); | |
| 159 | - $pages [] = ['id' => $id, 'distance' => (int)($line->greatCircleLength()), | |
| 160 | - 'description' => p_get_metadata($id, 'description')['abstract'], | |
| 161 | - 'lat' => $geotags ['lat'], 'lon' => $geotags ['lon']]; | |
| 162 | - } | |
| 163 | - } | |
| 136 | +		foreach ($docIds as $id) { | |
| 137 | +			if (strpos($id, 'media__') === 0) { | |
| 138 | +				$id = substr($id, strlen('media__')); | |
| 139 | +				if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { | |
| 140 | + $point = $indexer->getCoordsFromExif($id); | |
| 141 | + $line = new LineString( | |
| 142 | + [ | |
| 143 | + $decodedPoint, | |
| 144 | + $point | |
| 145 | + ] | |
| 146 | + ); | |
| 147 | + $media [] = ['id' => $id, 'distance' => (int)($line->greatCircleLength()), | |
| 148 | + 'lat' => $point->y(), 'lon' => $point->x()]; | |
| 149 | + } | |
| 150 | +			} elseif (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { | |
| 151 | + $geotags = p_get_metadata($id, 'geo'); | |
| 152 | + $point = new Point($geotags ['lon'], $geotags ['lat']); | |
| 153 | + $line = new LineString( | |
| 154 | + [ | |
| 155 | + $decodedPoint, | |
| 156 | + $point | |
| 157 | + ] | |
| 158 | + ); | |
| 159 | + $pages [] = ['id' => $id, 'distance' => (int)($line->greatCircleLength()), | |
| 160 | + 'description' => p_get_metadata($id, 'description')['abstract'], | |
| 161 | + 'lat' => $geotags ['lat'], 'lon' => $geotags ['lon']]; | |
| 162 | + } | |
| 163 | + } | |
| 164 | 164 | |
| 165 | - // sort all the pages/media using distance | |
| 166 | - usort( | |
| 167 | - $pages, | |
| 168 | - static fn($a, $b) => strnatcmp($a ['distance'], $b ['distance']) | |
| 169 | - ); | |
| 170 | - usort( | |
| 171 | - $media, | |
| 172 | - static fn($a, $b) => strnatcmp($a ['distance'], $b ['distance']) | |
| 173 | - ); | |
| 165 | + // sort all the pages/media using distance | |
| 166 | + usort( | |
| 167 | + $pages, | |
| 168 | + static fn($a, $b) => strnatcmp($a ['distance'], $b ['distance']) | |
| 169 | + ); | |
| 170 | + usort( | |
| 171 | + $media, | |
| 172 | + static fn($a, $b) => strnatcmp($a ['distance'], $b ['distance']) | |
| 173 | + ); | |
| 174 | 174 | |
| 175 | - return [ | |
| 176 | - 'pages' => $pages, | |
| 177 | - 'media' => $media, | |
| 178 | - 'lat' => $decodedPoint->y(), | |
| 179 | - 'lon' => $decodedPoint->x(), | |
| 180 | - 'geohash' => $geohash, | |
| 181 | - 'precision' => $this->precision [strlen($geohash)] | |
| 182 | - ]; | |
| 183 | - } | |
| 175 | + return [ | |
| 176 | + 'pages' => $pages, | |
| 177 | + 'media' => $media, | |
| 178 | + 'lat' => $decodedPoint->y(), | |
| 179 | + 'lon' => $decodedPoint->x(), | |
| 180 | + 'geohash' => $geohash, | |
| 181 | + 'precision' => $this->precision [strlen($geohash)] | |
| 182 | + ]; | |
| 183 | + } | |
| 184 | 184 | } | 
| @@ -118,7 +118,7 @@ discard block | ||
| 118 | 118 |          foreach ($adjacent as $adjHash) { | 
| 119 | 119 |              if (is_array($this->spatial_idx)) { | 
| 120 | 120 |                  foreach ($this->spatial_idx as $_geohash => $_docIds) { | 
| 121 | -                    if (strpos($_geohash, (string)$adjHash) !== false) { | |
| 121 | +                    if (strpos($_geohash, ( string ) $adjHash) !== false) { | |
| 122 | 122 | // if $adjHash similar to geohash | 
| 123 | 123 | $docIds = array_merge($docIds, $_docIds); | 
| 124 | 124 | } | 
| @@ -144,7 +144,7 @@ discard block | ||
| 144 | 144 | $point | 
| 145 | 145 | ] | 
| 146 | 146 | ); | 
| 147 | - $media [] = ['id' => $id, 'distance' => (int)($line->greatCircleLength()), | |
| 147 | + $media [] = ['id' => $id, 'distance' => ( int ) ($line->greatCircleLength()), | |
| 148 | 148 | 'lat' => $point->y(), 'lon' => $point->x()]; | 
| 149 | 149 | } | 
| 150 | 150 |              } elseif (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { | 
| @@ -156,7 +156,7 @@ discard block | ||
| 156 | 156 | $point | 
| 157 | 157 | ] | 
| 158 | 158 | ); | 
| 159 | - $pages [] = ['id' => $id, 'distance' => (int)($line->greatCircleLength()), | |
| 159 | + $pages [] = ['id' => $id, 'distance' => ( int ) ($line->greatCircleLength()), | |
| 160 | 160 | 'description' => p_get_metadata($id, 'description')['abstract'], | 
| 161 | 161 | 'lat' => $geotags ['lat'], 'lon' => $geotags ['lon']]; | 
| 162 | 162 | } | 
| @@ -26,94 +26,94 @@ | ||
| 26 | 26 | */ | 
| 27 | 27 | class syntax_plugin_spatialhelper_findnearby extends SyntaxPlugin | 
| 28 | 28 |  { | 
| 29 | - /** | |
| 30 | - * | |
| 31 | - * @see DokuWiki_Syntax_Plugin::getType() | |
| 32 | - */ | |
| 33 | - final public function getType(): string | |
| 34 | -    { | |
| 35 | - return 'substition'; | |
| 36 | - } | |
| 29 | + /** | |
| 30 | + * | |
| 31 | + * @see DokuWiki_Syntax_Plugin::getType() | |
| 32 | + */ | |
| 33 | + final public function getType(): string | |
| 34 | +	{ | |
| 35 | + return 'substition'; | |
| 36 | + } | |
| 37 | 37 | |
| 38 | - /** | |
| 39 | - * Return 'normal' so this syntax can be rendered inline. | |
| 40 | - * | |
| 41 | - * @see DokuWiki_Syntax_Plugin::getPType() | |
| 42 | - */ | |
| 43 | - final public function getPType(): string | |
| 44 | -    { | |
| 45 | - return 'normal'; | |
| 46 | - } | |
| 38 | + /** | |
| 39 | + * Return 'normal' so this syntax can be rendered inline. | |
| 40 | + * | |
| 41 | + * @see DokuWiki_Syntax_Plugin::getPType() | |
| 42 | + */ | |
| 43 | + final public function getPType(): string | |
| 44 | +	{ | |
| 45 | + return 'normal'; | |
| 46 | + } | |
| 47 | 47 | |
| 48 | - /** | |
| 49 | - * | |
| 50 | - * @see Doku_Parser_Mode::getSort() | |
| 51 | - */ | |
| 52 | - final public function getSort(): int | |
| 53 | -    { | |
| 54 | - return 307; | |
| 55 | - } | |
| 48 | + /** | |
| 49 | + * | |
| 50 | + * @see Doku_Parser_Mode::getSort() | |
| 51 | + */ | |
| 52 | + final public function getSort(): int | |
| 53 | +	{ | |
| 54 | + return 307; | |
| 55 | + } | |
| 56 | 56 | |
| 57 | - /** | |
| 58 | -     * define our special pattern: {{findnearby>Some linkt text or nothing}}. | |
| 59 | - * | |
| 60 | - * @see Doku_Parser_Mode::connectTo() | |
| 61 | - */ | |
| 62 | - final public function connectTo($mode): void | |
| 63 | -    { | |
| 64 | -        $this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby'); | |
| 65 | - } | |
| 57 | + /** | |
| 58 | +	 * define our special pattern: {{findnearby>Some linkt text or nothing}}. | |
| 59 | + * | |
| 60 | + * @see Doku_Parser_Mode::connectTo() | |
| 61 | + */ | |
| 62 | + final public function connectTo($mode): void | |
| 63 | +	{ | |
| 64 | +		$this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby'); | |
| 65 | + } | |
| 66 | 66 | |
| 67 | - /** | |
| 68 | - * look up the page's geo metadata and pass that on to render. | |
| 69 | - * | |
| 70 | - * @param string $match The text matched by the patterns | |
| 71 | - * @param int $state The lexer state for the match | |
| 72 | - * @param int $pos The character position of the matched text | |
| 73 | - * @param Doku_Handler $handler The Doku_Handler object | |
| 74 | - * @return bool|array Return an array with all data you want to use in render, false don't add an instruction | |
| 75 | - * | |
| 76 | - * @see DokuWiki_Syntax_Plugin::handle() | |
| 77 | - */ | |
| 78 | - final public function handle($match, $state, $pos, Doku_Handler $handler): bool|array | |
| 79 | -    { | |
| 80 | - $data = []; | |
| 81 | -        $data [0] = trim(substr($match, strlen('{{findnearby>'), -2)); | |
| 82 | -        if ($data [0] === '') { | |
| 83 | -            $data [0] = $this->getLang('search_findnearby'); | |
| 84 | - } | |
| 85 | - $meta = p_get_metadata(getID(), 'geo'); | |
| 86 | -        if ($meta) { | |
| 87 | -            if ($meta ['lat'] && $meta ['lon']) { | |
| 88 | - $data [1] = ['do' => 'findnearby', 'lat' => $meta ['lat'], 'lon' => $meta ['lon']]; | |
| 89 | -            } elseif ($meta ['geohash']) { | |
| 90 | - $data [1] = ['do' => 'findnearby', 'geohash' => $meta ['geohash']]; | |
| 91 | - } | |
| 92 | - return $data; | |
| 93 | - } | |
| 94 | - return false; | |
| 95 | - } | |
| 67 | + /** | |
| 68 | + * look up the page's geo metadata and pass that on to render. | |
| 69 | + * | |
| 70 | + * @param string $match The text matched by the patterns | |
| 71 | + * @param int $state The lexer state for the match | |
| 72 | + * @param int $pos The character position of the matched text | |
| 73 | + * @param Doku_Handler $handler The Doku_Handler object | |
| 74 | + * @return bool|array Return an array with all data you want to use in render, false don't add an instruction | |
| 75 | + * | |
| 76 | + * @see DokuWiki_Syntax_Plugin::handle() | |
| 77 | + */ | |
| 78 | + final public function handle($match, $state, $pos, Doku_Handler $handler): bool|array | |
| 79 | +	{ | |
| 80 | + $data = []; | |
| 81 | +		$data [0] = trim(substr($match, strlen('{{findnearby>'), -2)); | |
| 82 | +		if ($data [0] === '') { | |
| 83 | +			$data [0] = $this->getLang('search_findnearby'); | |
| 84 | + } | |
| 85 | + $meta = p_get_metadata(getID(), 'geo'); | |
| 86 | +		if ($meta) { | |
| 87 | +			if ($meta ['lat'] && $meta ['lon']) { | |
| 88 | + $data [1] = ['do' => 'findnearby', 'lat' => $meta ['lat'], 'lon' => $meta ['lon']]; | |
| 89 | +			} elseif ($meta ['geohash']) { | |
| 90 | + $data [1] = ['do' => 'findnearby', 'geohash' => $meta ['geohash']]; | |
| 91 | + } | |
| 92 | + return $data; | |
| 93 | + } | |
| 94 | + return false; | |
| 95 | + } | |
| 96 | 96 | |
| 97 | - /** | |
| 98 | - * Render a link to a search page. | |
| 99 | - * | |
| 100 | - * @see DokuWiki_Syntax_Plugin::render() | |
| 101 | - */ | |
| 102 | - final public function render($format, Doku_Renderer $renderer, $data): bool | |
| 103 | -    { | |
| 104 | -        if ($data === false) { | |
| 105 | - return false; | |
| 106 | - } | |
| 97 | + /** | |
| 98 | + * Render a link to a search page. | |
| 99 | + * | |
| 100 | + * @see DokuWiki_Syntax_Plugin::render() | |
| 101 | + */ | |
| 102 | + final public function render($format, Doku_Renderer $renderer, $data): bool | |
| 103 | +	{ | |
| 104 | +		if ($data === false) { | |
| 105 | + return false; | |
| 106 | + } | |
| 107 | 107 | |
| 108 | -        if ($format === 'xhtml') { | |
| 109 | - $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>'; | |
| 110 | - return true; | |
| 111 | -        } elseif ($format === 'metadata') { | |
| 112 | - return false; | |
| 113 | -        } elseif ($format === 'odt') { | |
| 114 | - // don't render anything in ODT | |
| 115 | - return false; | |
| 116 | - } | |
| 117 | - return false; | |
| 118 | - } | |
| 108 | +		if ($format === 'xhtml') { | |
| 109 | + $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>'; | |
| 110 | + return true; | |
| 111 | +		} elseif ($format === 'metadata') { | |
| 112 | + return false; | |
| 113 | +		} elseif ($format === 'odt') { | |
| 114 | + // don't render anything in ODT | |
| 115 | + return false; | |
| 116 | + } | |
| 117 | + return false; | |
| 118 | + } | |
| 119 | 119 | } | 
| @@ -75,7 +75,7 @@ | ||
| 75 | 75 | * | 
| 76 | 76 | * @see DokuWiki_Syntax_Plugin::handle() | 
| 77 | 77 | */ | 
| 78 | - final public function handle($match, $state, $pos, Doku_Handler $handler): bool|array | |
| 78 | + final public function handle($match, $state, $pos, Doku_Handler $handler): bool | array | |
| 79 | 79 |      { | 
| 80 | 80 | $data = []; | 
| 81 | 81 |          $data [0] = trim(substr($match, strlen('{{findnearby>'), -2)); | 
| @@ -28,296 +28,296 @@ | ||
| 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 (!$exif || 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 (!$exif || 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'] ?? 'N' | |
| 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'] ?? 'N' | |
| 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'] ?? 'E' | |
| 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'] ?? 'E' | |
| 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 | } | 
| @@ -237,7 +237,7 @@ discard block | ||
| 237 | 237 | * @return Point|false | 
| 238 | 238 | * @throws Exception | 
| 239 | 239 | */ | 
| 240 | - final public function getCoordsFromExif(string $id): Point|false | |
| 240 | + final public function getCoordsFromExif(string $id): Point | false | |
| 241 | 241 |      { | 
| 242 | 242 | $exif = exif_read_data(mediaFN($id), 0, true); | 
| 243 | 243 |          if (!$exif || empty($exif ['GPS'])) { | 
| @@ -288,11 +288,11 @@ discard block | ||
| 288 | 288 |      { | 
| 289 | 289 | // rational64u | 
| 290 | 290 |          $nums = explode('/', $param); | 
| 291 | -        if ((int)$nums[1] > 0) { | |
| 292 | - return (float)$nums[0] / (int)$nums[1]; | |
| 291 | +        if (( int ) $nums[1] > 0) { | |
| 292 | + return ( float ) $nums[0] / ( int ) $nums[1]; | |
| 293 | 293 | } | 
| 294 | 294 | |
| 295 | - return (float)$nums[0]; | |
| 295 | + return ( float ) $nums[0]; | |
| 296 | 296 | } | 
| 297 | 297 | |
| 298 | 298 | /** | 
| @@ -15,93 +15,93 @@ | ||
| 15 | 15 | class index_test extends DokuWikiTest | 
| 16 | 16 |  { | 
| 17 | 17 | |
| 18 | -    protected $pluginsEnabled = array('spatialhelper'); | |
| 18 | +	protected $pluginsEnabled = array('spatialhelper'); | |
| 19 | 19 | |
| 20 | - /** | |
| 21 | - * copy data and add pages to the index. | |
| 22 | - */ | |
| 23 | - public static function setUpBeforeClass(): void | |
| 24 | -    { | |
| 25 | - parent::setUpBeforeClass(); | |
| 26 | - global $conf; | |
| 27 | - $conf['allowdebug'] = 1; | |
| 20 | + /** | |
| 21 | + * copy data and add pages to the index. | |
| 22 | + */ | |
| 23 | + public static function setUpBeforeClass(): void | |
| 24 | +	{ | |
| 25 | + parent::setUpBeforeClass(); | |
| 26 | + global $conf; | |
| 27 | + $conf['allowdebug'] = 1; | |
| 28 | 28 | |
| 29 | - TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/'); | |
| 30 | - } | |
| 29 | + TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/'); | |
| 30 | + } | |
| 31 | 31 | |
| 32 | - final public function setUp(): void | |
| 33 | -    { | |
| 34 | - parent::setUp(); | |
| 32 | + final public function setUp(): void | |
| 33 | +	{ | |
| 34 | + parent::setUp(); | |
| 35 | 35 | |
| 36 | - global $conf; | |
| 37 | - $conf['allowdebug'] = 1; | |
| 38 | - $conf['cachetime'] = -1; | |
| 36 | + global $conf; | |
| 37 | + $conf['allowdebug'] = 1; | |
| 38 | + $conf['cachetime'] = -1; | |
| 39 | 39 | |
| 40 | - $data = array(); | |
| 41 | -        search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); | |
| 42 | - } | |
| 40 | + $data = array(); | |
| 41 | +		search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); | |
| 42 | + } | |
| 43 | 43 | |
| 44 | - /** | |
| 45 | - * Testdata for @return array | |
| 46 | - * @see index_test::test_convertDMStoD | |
| 47 | - * | |
| 48 | - */ | |
| 49 | - final public static function convertDMStoDTestdata(): array | |
| 50 | -    { | |
| 51 | - return array( | |
| 52 | - array( | |
| 53 | - array(0 => '52/1', 1 => '31/1', 2 => '2/1', 3 => 'N',), | |
| 54 | - 52.5172, | |
| 55 | - 'Latitude in Europe' | |
| 56 | - ), | |
| 57 | - array( | |
| 58 | - array(0 => '13/1', 1 => '30/1', 2 => '38/1', 3 => 'E',), | |
| 59 | - 13.5105, | |
| 60 | - 'Longitude in Europe' | |
| 61 | - ), | |
| 62 | - array( | |
| 63 | - array(0 => '50/1', 1 => '34251480/1000000', 2 => '0/1', 3 => 'N',), | |
| 64 | - 50.5708, | |
| 65 | - 'Latitude in North America' | |
| 66 | - ), | |
| 67 | - array( | |
| 68 | - array(0 => '109/1', 1 => '28041300/1000000', 2 => '0/1', 3 => 'W',), | |
| 69 | - -109.4673, | |
| 70 | - 'Longitude in North America' | |
| 71 | - ), | |
| 72 | - ); | |
| 73 | - } | |
| 44 | + /** | |
| 45 | + * Testdata for @return array | |
| 46 | + * @see index_test::test_convertDMStoD | |
| 47 | + * | |
| 48 | + */ | |
| 49 | + final public static function convertDMStoDTestdata(): array | |
| 50 | +	{ | |
| 51 | + return array( | |
| 52 | + array( | |
| 53 | + array(0 => '52/1', 1 => '31/1', 2 => '2/1', 3 => 'N',), | |
| 54 | + 52.5172, | |
| 55 | + 'Latitude in Europe' | |
| 56 | + ), | |
| 57 | + array( | |
| 58 | + array(0 => '13/1', 1 => '30/1', 2 => '38/1', 3 => 'E',), | |
| 59 | + 13.5105, | |
| 60 | + 'Longitude in Europe' | |
| 61 | + ), | |
| 62 | + array( | |
| 63 | + array(0 => '50/1', 1 => '34251480/1000000', 2 => '0/1', 3 => 'N',), | |
| 64 | + 50.5708, | |
| 65 | + 'Latitude in North America' | |
| 66 | + ), | |
| 67 | + array( | |
| 68 | + array(0 => '109/1', 1 => '28041300/1000000', 2 => '0/1', 3 => 'W',), | |
| 69 | + -109.4673, | |
| 70 | + 'Longitude in North America' | |
| 71 | + ), | |
| 72 | + ); | |
| 73 | + } | |
| 74 | 74 | |
| 75 | - /** | |
| 76 | - * @dataProvider convertDMStoDTestdata | |
| 77 | - */ | |
| 78 | - final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void | |
| 79 | -    { | |
| 80 | -        $index = plugin_load('helper', 'spatialhelper_index'); | |
| 81 | - assert($index instanceof helper_plugin_spatialhelper_index); | |
| 75 | + /** | |
| 76 | + * @dataProvider convertDMStoDTestdata | |
| 77 | + */ | |
| 78 | + final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void | |
| 79 | +	{ | |
| 80 | +		$index = plugin_load('helper', 'spatialhelper_index'); | |
| 81 | + assert($index instanceof helper_plugin_spatialhelper_index); | |
| 82 | 82 | |
| 83 | - $actual_output = $index->convertDMStoD($input); | |
| 83 | + $actual_output = $index->convertDMStoD($input); | |
| 84 | 84 | |
| 85 | - self::assertEqualsWithDelta($expected_output, $actual_output, 0.0001, $msg); | |
| 86 | - } | |
| 85 | + self::assertEqualsWithDelta($expected_output, $actual_output, 0.0001, $msg); | |
| 86 | + } | |
| 87 | 87 | |
| 88 | - final public function test_ImageWithoutGeotag(): void | |
| 89 | -    { | |
| 90 | -        $index = plugin_load('helper', 'spatialhelper_index'); | |
| 91 | - assert($index instanceof helper_plugin_spatialhelper_index); | |
| 92 | -        $actual_output = $index->getCoordsFromExif(':vesder_eupen_no_gps.jpg'); | |
| 93 | - self::assertFalse($actual_output, 'Expected no geotag to be found'); | |
| 94 | - } | |
| 88 | + final public function test_ImageWithoutGeotag(): void | |
| 89 | +	{ | |
| 90 | +		$index = plugin_load('helper', 'spatialhelper_index'); | |
| 91 | + assert($index instanceof helper_plugin_spatialhelper_index); | |
| 92 | +		$actual_output = $index->getCoordsFromExif(':vesder_eupen_no_gps.jpg'); | |
| 93 | + self::assertFalse($actual_output, 'Expected no geotag to be found'); | |
| 94 | + } | |
| 95 | 95 | |
| 96 | - final public function test_ImageWithGeotag(): void | |
| 97 | -    { | |
| 98 | -        $index = plugin_load('helper', 'spatialhelper_index'); | |
| 99 | - assert($index instanceof helper_plugin_spatialhelper_index); | |
| 100 | - // 37° 4' 36.12",31° 39' 21.96" or 31.656100,37.076700 | |
| 101 | -        $actual_output = $index->getCoordsFromExif(':manavgat_restaurant_handost_with_gps.jpg'); | |
| 102 | - self::assertNotNull($actual_output, 'Expected a geotag to be found'); | |
| 103 | - self::assertNotFalse($actual_output, 'Expected a geotag to be found'); | |
| 104 | - self::assertEqualsWithDelta(31.6561, $actual_output->x(), 0.0001); | |
| 105 | - self::assertEqualsWithDelta(37.0767, $actual_output->y(), 0.0001); | |
| 106 | - } | |
| 96 | + final public function test_ImageWithGeotag(): void | |
| 97 | +	{ | |
| 98 | +		$index = plugin_load('helper', 'spatialhelper_index'); | |
| 99 | + assert($index instanceof helper_plugin_spatialhelper_index); | |
| 100 | + // 37° 4' 36.12",31° 39' 21.96" or 31.656100,37.076700 | |
| 101 | +		$actual_output = $index->getCoordsFromExif(':manavgat_restaurant_handost_with_gps.jpg'); | |
| 102 | + self::assertNotNull($actual_output, 'Expected a geotag to be found'); | |
| 103 | + self::assertNotFalse($actual_output, 'Expected a geotag to be found'); | |
| 104 | + self::assertEqualsWithDelta(31.6561, $actual_output->x(), 0.0001); | |
| 105 | + self::assertEqualsWithDelta(37.0767, $actual_output->y(), 0.0001); | |
| 106 | + } | |
| 107 | 107 | } |