@@ -108,11 +108,15 @@  | 
                                                    ||
| 108 | 108 |      { | 
                                                        
| 109 | 109 | $geotags = p_get_metadata($id, 'geo');  | 
                                                        
| 110 | 110 |          if (empty($geotags)) { | 
                                                        
| 111 | - if ($verbose) echo "No geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 111 | +            if ($verbose) { | 
                                                        |
| 112 | + echo "No geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 113 | + }  | 
                                                        |
| 112 | 114 | return false;  | 
                                                        
| 113 | 115 | }  | 
                                                        
| 114 | 116 |          if (empty($geotags ['lon']) || empty($geotags ['lat'])) { | 
                                                        
| 115 | - if ($verbose) echo "No valid geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 117 | +            if ($verbose) { | 
                                                        |
| 118 | + echo "No valid geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 119 | + }  | 
                                                        |
| 116 | 120 | return false;  | 
                                                        
| 117 | 121 | }  | 
                                                        
| 118 | 122 |          Logger::debug("Geo metadata found for page $id", $geotags); | 
                                                        
@@ -28,300 +28,300 @@  | 
                                                    ||
| 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 | - * @param bool $verbose  | 
                                                        |
| 104 | - * if true, echo debug info  | 
                                                        |
| 105 | - * @throws Exception  | 
                                                        |
| 106 | - */  | 
                                                        |
| 107 | - final public function updateSpatialIndex(string $id, bool $verbose = false): bool  | 
                                                        |
| 108 | -    { | 
                                                        |
| 109 | - $geotags = p_get_metadata($id, 'geo');  | 
                                                        |
| 110 | -        if (empty($geotags)) { | 
                                                        |
| 111 | - if ($verbose) echo "No geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 112 | - return false;  | 
                                                        |
| 113 | - }  | 
                                                        |
| 114 | -        if (empty($geotags ['lon']) || empty($geotags ['lat'])) { | 
                                                        |
| 115 | - if ($verbose) echo "No valid geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 116 | - return false;  | 
                                                        |
| 117 | - }  | 
                                                        |
| 118 | -        Logger::debug("Geo metadata found for page $id", $geotags); | 
                                                        |
| 119 | - $geometry = new Point($geotags ['lon'], $geotags ['lat']);  | 
                                                        |
| 120 | -        $geohash = $geometry->out('geohash'); | 
                                                        |
| 121 | -        Logger::debug('Update index for geohash: ' . $geohash); | 
                                                        |
| 122 | - return $this->addToIndex($geohash, $id);  | 
                                                        |
| 123 | - }  | 
                                                        |
| 98 | + /**  | 
                                                        |
| 99 | + * Update the spatial index for the page.  | 
                                                        |
| 100 | + *  | 
                                                        |
| 101 | + * @param string $id  | 
                                                        |
| 102 | + * the document ID  | 
                                                        |
| 103 | + * @param bool $verbose  | 
                                                        |
| 104 | + * if true, echo debug info  | 
                                                        |
| 105 | + * @throws Exception  | 
                                                        |
| 106 | + */  | 
                                                        |
| 107 | + final public function updateSpatialIndex(string $id, bool $verbose = false): bool  | 
                                                        |
| 108 | +	{ | 
                                                        |
| 109 | + $geotags = p_get_metadata($id, 'geo');  | 
                                                        |
| 110 | +		if (empty($geotags)) { | 
                                                        |
| 111 | + if ($verbose) echo "No geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 112 | + return false;  | 
                                                        |
| 113 | + }  | 
                                                        |
| 114 | +		if (empty($geotags ['lon']) || empty($geotags ['lat'])) { | 
                                                        |
| 115 | + if ($verbose) echo "No valid geo metadata found for page $id" . DOKU_LF;  | 
                                                        |
| 116 | + return false;  | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | +		Logger::debug("Geo metadata found for page $id", $geotags); | 
                                                        |
| 119 | + $geometry = new Point($geotags ['lon'], $geotags ['lat']);  | 
                                                        |
| 120 | +		$geohash = $geometry->out('geohash'); | 
                                                        |
| 121 | +		Logger::debug('Update index for geohash: ' . $geohash); | 
                                                        |
| 122 | + return $this->addToIndex($geohash, $id);  | 
                                                        |
| 123 | + }  | 
                                                        |
| 124 | 124 | |
| 125 | - /**  | 
                                                        |
| 126 | - * Store the hash/id entry in the index.  | 
                                                        |
| 127 | - *  | 
                                                        |
| 128 | - * @param string $geohash  | 
                                                        |
| 129 | - * @param string $id  | 
                                                        |
| 130 | - * page or media id  | 
                                                        |
| 131 | - * @return bool true when succesful  | 
                                                        |
| 132 | - */  | 
                                                        |
| 133 | - private function addToIndex(string $geohash, string $id): bool  | 
                                                        |
| 134 | -    { | 
                                                        |
| 135 | - $pageIds = [];  | 
                                                        |
| 136 | - // check index for key/geohash  | 
                                                        |
| 137 | -        if (!array_key_exists($geohash, $this->spatial_idx)) { | 
                                                        |
| 138 | -            Logger::debug("Geohash $geohash not in index, just add $id."); | 
                                                        |
| 139 | - $pageIds [] = $id;  | 
                                                        |
| 140 | -        } else { | 
                                                        |
| 141 | -            Logger::debug('Geohash for document is in index, find it.'); | 
                                                        |
| 142 | - // check the index for document  | 
                                                        |
| 143 | - $knownHashes = $this->findHashesForId($id, $this->spatial_idx);  | 
                                                        |
| 144 | -            if ($knownHashes === []) { | 
                                                        |
| 145 | -                Logger::debug("No index record found for document $id, adding it to the index."); | 
                                                        |
| 146 | - $pageIds = $this->spatial_idx [$geohash];  | 
                                                        |
| 147 | - $pageIds [] = $id;  | 
                                                        |
| 148 | - }  | 
                                                        |
| 149 | - // TODO shortcut, need to make sure there is only one element, if not the index is corrupt  | 
                                                        |
| 150 | - $knownHash = $knownHashes [0] ?? '';  | 
                                                        |
| 125 | + /**  | 
                                                        |
| 126 | + * Store the hash/id entry in the index.  | 
                                                        |
| 127 | + *  | 
                                                        |
| 128 | + * @param string $geohash  | 
                                                        |
| 129 | + * @param string $id  | 
                                                        |
| 130 | + * page or media id  | 
                                                        |
| 131 | + * @return bool true when succesful  | 
                                                        |
| 132 | + */  | 
                                                        |
| 133 | + private function addToIndex(string $geohash, string $id): bool  | 
                                                        |
| 134 | +	{ | 
                                                        |
| 135 | + $pageIds = [];  | 
                                                        |
| 136 | + // check index for key/geohash  | 
                                                        |
| 137 | +		if (!array_key_exists($geohash, $this->spatial_idx)) { | 
                                                        |
| 138 | +			Logger::debug("Geohash $geohash not in index, just add $id."); | 
                                                        |
| 139 | + $pageIds [] = $id;  | 
                                                        |
| 140 | +		} else { | 
                                                        |
| 141 | +			Logger::debug('Geohash for document is in index, find it.'); | 
                                                        |
| 142 | + // check the index for document  | 
                                                        |
| 143 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx);  | 
                                                        |
| 144 | +			if ($knownHashes === []) { | 
                                                        |
| 145 | +				Logger::debug("No index record found for document $id, adding it to the index."); | 
                                                        |
| 146 | + $pageIds = $this->spatial_idx [$geohash];  | 
                                                        |
| 147 | + $pageIds [] = $id;  | 
                                                        |
| 148 | + }  | 
                                                        |
| 149 | + // TODO shortcut, need to make sure there is only one element, if not the index is corrupt  | 
                                                        |
| 150 | + $knownHash = $knownHashes [0] ?? '';  | 
                                                        |
| 151 | 151 | |
| 152 | -            if ($knownHash === $geohash) { | 
                                                        |
| 153 | -                Logger::debug("Document $id was found in index and has the same geohash, nothing to do."); | 
                                                        |
| 154 | - return true;  | 
                                                        |
| 155 | - }  | 
                                                        |
| 152 | +			if ($knownHash === $geohash) { | 
                                                        |
| 153 | +				Logger::debug("Document $id was found in index and has the same geohash, nothing to do."); | 
                                                        |
| 154 | + return true;  | 
                                                        |
| 155 | + }  | 
                                                        |
| 156 | 156 | |
| 157 | -            if (!empty($knownHash)) { | 
                                                        |
| 158 | -                Logger::debug("Document/media $id was found in index but has different geohash (it moved)."); | 
                                                        |
| 159 | - $knownIds = $this->spatial_idx [$knownHash];  | 
                                                        |
| 160 | -                Logger::debug("Known id's for this hash:", $knownIds); | 
                                                        |
| 161 | - // remove it from the old geohash element  | 
                                                        |
| 162 | - $i = array_search($id, $knownIds);  | 
                                                        |
| 163 | -                Logger::debug('Unsetting:' . $knownIds [$i]); | 
                                                        |
| 164 | - unset($knownIds [$i]);  | 
                                                        |
| 165 | - $this->spatial_idx [$knownHash] = $knownIds;  | 
                                                        |
| 166 | - // set on new geohash element  | 
                                                        |
| 167 | - $pageIds = $this->spatial_idx[$geohash];  | 
                                                        |
| 168 | - $pageIds [] = $id;  | 
                                                        |
| 169 | - }  | 
                                                        |
| 170 | - }  | 
                                                        |
| 171 | - // store and save  | 
                                                        |
| 172 | - $this->spatial_idx [$geohash] = $pageIds;  | 
                                                        |
| 173 | - return $this->saveIndex();  | 
                                                        |
| 174 | - }  | 
                                                        |
| 157 | +			if (!empty($knownHash)) { | 
                                                        |
| 158 | +				Logger::debug("Document/media $id was found in index but has different geohash (it moved)."); | 
                                                        |
| 159 | + $knownIds = $this->spatial_idx [$knownHash];  | 
                                                        |
| 160 | +				Logger::debug("Known id's for this hash:", $knownIds); | 
                                                        |
| 161 | + // remove it from the old geohash element  | 
                                                        |
| 162 | + $i = array_search($id, $knownIds);  | 
                                                        |
| 163 | +				Logger::debug('Unsetting:' . $knownIds [$i]); | 
                                                        |
| 164 | + unset($knownIds [$i]);  | 
                                                        |
| 165 | + $this->spatial_idx [$knownHash] = $knownIds;  | 
                                                        |
| 166 | + // set on new geohash element  | 
                                                        |
| 167 | + $pageIds = $this->spatial_idx[$geohash];  | 
                                                        |
| 168 | + $pageIds [] = $id;  | 
                                                        |
| 169 | + }  | 
                                                        |
| 170 | + }  | 
                                                        |
| 171 | + // store and save  | 
                                                        |
| 172 | + $this->spatial_idx [$geohash] = $pageIds;  | 
                                                        |
| 173 | + return $this->saveIndex();  | 
                                                        |
| 174 | + }  | 
                                                        |
| 175 | 175 | |
| 176 | - /**  | 
                                                        |
| 177 | - * Looks up the geohash(es) for the document in the index.  | 
                                                        |
| 178 | - *  | 
                                                        |
| 179 | - * @param String $id  | 
                                                        |
| 180 | - * document ID  | 
                                                        |
| 181 | - * @param array $index  | 
                                                        |
| 182 | - * spatial index  | 
                                                        |
| 183 | - */  | 
                                                        |
| 184 | - final public function findHashesForId(string $id, array $index): array  | 
                                                        |
| 185 | -    { | 
                                                        |
| 186 | - $hashes = [];  | 
                                                        |
| 187 | -        foreach ($index as $hash => $docIds) { | 
                                                        |
| 188 | -            if (in_array($id, $docIds)) { | 
                                                        |
| 189 | - $hashes [] = $hash;  | 
                                                        |
| 190 | - }  | 
                                                        |
| 191 | - }  | 
                                                        |
| 192 | -        Logger::debug("Found the following hashes for $id (should only be 1)", $hashes); | 
                                                        |
| 193 | - return $hashes;  | 
                                                        |
| 194 | - }  | 
                                                        |
| 176 | + /**  | 
                                                        |
| 177 | + * Looks up the geohash(es) for the document in the index.  | 
                                                        |
| 178 | + *  | 
                                                        |
| 179 | + * @param String $id  | 
                                                        |
| 180 | + * document ID  | 
                                                        |
| 181 | + * @param array $index  | 
                                                        |
| 182 | + * spatial index  | 
                                                        |
| 183 | + */  | 
                                                        |
| 184 | + final public function findHashesForId(string $id, array $index): array  | 
                                                        |
| 185 | +	{ | 
                                                        |
| 186 | + $hashes = [];  | 
                                                        |
| 187 | +		foreach ($index as $hash => $docIds) { | 
                                                        |
| 188 | +			if (in_array($id, $docIds)) { | 
                                                        |
| 189 | + $hashes [] = $hash;  | 
                                                        |
| 190 | + }  | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | +		Logger::debug("Found the following hashes for $id (should only be 1)", $hashes); | 
                                                        |
| 193 | + return $hashes;  | 
                                                        |
| 194 | + }  | 
                                                        |
| 195 | 195 | |
| 196 | - /**  | 
                                                        |
| 197 | - * Save spatial index.  | 
                                                        |
| 198 | - */  | 
                                                        |
| 199 | - private function saveIndex(): bool  | 
                                                        |
| 200 | -    { | 
                                                        |
| 201 | - return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx));  | 
                                                        |
| 202 | - }  | 
                                                        |
| 196 | + /**  | 
                                                        |
| 197 | + * Save spatial index.  | 
                                                        |
| 198 | + */  | 
                                                        |
| 199 | + private function saveIndex(): bool  | 
                                                        |
| 200 | +	{ | 
                                                        |
| 201 | + return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx));  | 
                                                        |
| 202 | + }  | 
                                                        |
| 203 | 203 | |
| 204 | - /**  | 
                                                        |
| 205 | - * Add an index entry for this file having EXIF / IPTC data.  | 
                                                        |
| 206 | - *  | 
                                                        |
| 207 | - * @param $imgId  | 
                                                        |
| 208 | - * a Dokuwiki image id  | 
                                                        |
| 209 | - * @return bool true when image was successfully added to the index.  | 
                                                        |
| 210 | - * @throws Exception  | 
                                                        |
| 211 | - * @see http://www.php.net/manual/en/function.iptcparse.php  | 
                                                        |
| 212 | - * @see http://php.net/manual/en/function.exif-read-data.php  | 
                                                        |
| 213 | - *  | 
                                                        |
| 214 | - */  | 
                                                        |
| 215 | - final public function indexImage(string $imgId): bool  | 
                                                        |
| 216 | -    { | 
                                                        |
| 217 | - // test for supported files (jpeg only)  | 
                                                        |
| 218 | - if (  | 
                                                        |
| 219 | - (!str_ends_with(strtolower($imgId), '.jpg')) &&  | 
                                                        |
| 220 | - (!str_ends_with(strtolower($imgId), '.jpeg'))  | 
                                                        |
| 221 | -        ) { | 
                                                        |
| 222 | -            Logger::debug("indexImage:: " . $imgId . " is not a supported image file."); | 
                                                        |
| 223 | - return false;  | 
                                                        |
| 224 | - }  | 
                                                        |
| 204 | + /**  | 
                                                        |
| 205 | + * Add an index entry for this file having EXIF / IPTC data.  | 
                                                        |
| 206 | + *  | 
                                                        |
| 207 | + * @param $imgId  | 
                                                        |
| 208 | + * a Dokuwiki image id  | 
                                                        |
| 209 | + * @return bool true when image was successfully added to the index.  | 
                                                        |
| 210 | + * @throws Exception  | 
                                                        |
| 211 | + * @see http://www.php.net/manual/en/function.iptcparse.php  | 
                                                        |
| 212 | + * @see http://php.net/manual/en/function.exif-read-data.php  | 
                                                        |
| 213 | + *  | 
                                                        |
| 214 | + */  | 
                                                        |
| 215 | + final public function indexImage(string $imgId): bool  | 
                                                        |
| 216 | +	{ | 
                                                        |
| 217 | + // test for supported files (jpeg only)  | 
                                                        |
| 218 | + if (  | 
                                                        |
| 219 | + (!str_ends_with(strtolower($imgId), '.jpg')) &&  | 
                                                        |
| 220 | + (!str_ends_with(strtolower($imgId), '.jpeg'))  | 
                                                        |
| 221 | +		) { | 
                                                        |
| 222 | +			Logger::debug("indexImage:: " . $imgId . " is not a supported image file."); | 
                                                        |
| 223 | + return false;  | 
                                                        |
| 224 | + }  | 
                                                        |
| 225 | 225 | |
| 226 | - $geometry = $this->getCoordsFromExif($imgId);  | 
                                                        |
| 227 | -        if (!$geometry) { | 
                                                        |
| 228 | - return false;  | 
                                                        |
| 229 | - }  | 
                                                        |
| 230 | -        $geohash = $geometry->out('geohash'); | 
                                                        |
| 231 | - // TODO truncate the geohash to something reasonable, otherwise they are  | 
                                                        |
| 232 | - // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too  | 
                                                        |
| 233 | - // precise, limit at ~9 as most GPS are not submeter accurate  | 
                                                        |
| 234 | - return $this->addToIndex($geohash, 'media__' . $imgId);  | 
                                                        |
| 235 | - }  | 
                                                        |
| 226 | + $geometry = $this->getCoordsFromExif($imgId);  | 
                                                        |
| 227 | +		if (!$geometry) { | 
                                                        |
| 228 | + return false;  | 
                                                        |
| 229 | + }  | 
                                                        |
| 230 | +		$geohash = $geometry->out('geohash'); | 
                                                        |
| 231 | + // TODO truncate the geohash to something reasonable, otherwise they are  | 
                                                        |
| 232 | + // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too  | 
                                                        |
| 233 | + // precise, limit at ~9 as most GPS are not submeter accurate  | 
                                                        |
| 234 | + return $this->addToIndex($geohash, 'media__' . $imgId);  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | 236 | |
| 237 | - /**  | 
                                                        |
| 238 | - * retrieve GPS decimal coordinates from exif.  | 
                                                        |
| 239 | - *  | 
                                                        |
| 240 | - * @param string $id  | 
                                                        |
| 241 | - * @return Point|false  | 
                                                        |
| 242 | - * @throws Exception  | 
                                                        |
| 243 | - */  | 
                                                        |
| 244 | - final public function getCoordsFromExif(string $id): Point|false  | 
                                                        |
| 245 | -    { | 
                                                        |
| 246 | - $exif = exif_read_data(mediaFN($id), 0, true);  | 
                                                        |
| 247 | -        if (!$exif || empty($exif ['GPS'])) { | 
                                                        |
| 248 | - return false;  | 
                                                        |
| 249 | - }  | 
                                                        |
| 237 | + /**  | 
                                                        |
| 238 | + * retrieve GPS decimal coordinates from exif.  | 
                                                        |
| 239 | + *  | 
                                                        |
| 240 | + * @param string $id  | 
                                                        |
| 241 | + * @return Point|false  | 
                                                        |
| 242 | + * @throws Exception  | 
                                                        |
| 243 | + */  | 
                                                        |
| 244 | + final public function getCoordsFromExif(string $id): Point|false  | 
                                                        |
| 245 | +	{ | 
                                                        |
| 246 | + $exif = exif_read_data(mediaFN($id), 0, true);  | 
                                                        |
| 247 | +		if (!$exif || empty($exif ['GPS'])) { | 
                                                        |
| 248 | + return false;  | 
                                                        |
| 249 | + }  | 
                                                        |
| 250 | 250 | |
| 251 | - $lat = $this->convertDMStoD(  | 
                                                        |
| 252 | - [  | 
                                                        |
| 253 | - $exif ['GPS'] ['GPSLatitude'] [0],  | 
                                                        |
| 254 | - $exif ['GPS'] ['GPSLatitude'] [1],  | 
                                                        |
| 255 | - $exif ['GPS'] ['GPSLatitude'] [2],  | 
                                                        |
| 256 | - $exif ['GPS'] ['GPSLatitudeRef'] ?? 'N'  | 
                                                        |
| 257 | - ]  | 
                                                        |
| 258 | - );  | 
                                                        |
| 251 | + $lat = $this->convertDMStoD(  | 
                                                        |
| 252 | + [  | 
                                                        |
| 253 | + $exif ['GPS'] ['GPSLatitude'] [0],  | 
                                                        |
| 254 | + $exif ['GPS'] ['GPSLatitude'] [1],  | 
                                                        |
| 255 | + $exif ['GPS'] ['GPSLatitude'] [2],  | 
                                                        |
| 256 | + $exif ['GPS'] ['GPSLatitudeRef'] ?? 'N'  | 
                                                        |
| 257 | + ]  | 
                                                        |
| 258 | + );  | 
                                                        |
| 259 | 259 | |
| 260 | - $lon = $this->convertDMStoD(  | 
                                                        |
| 261 | - [  | 
                                                        |
| 262 | - $exif ['GPS'] ['GPSLongitude'] [0],  | 
                                                        |
| 263 | - $exif ['GPS'] ['GPSLongitude'] [1],  | 
                                                        |
| 264 | - $exif ['GPS'] ['GPSLongitude'] [2],  | 
                                                        |
| 265 | - $exif ['GPS'] ['GPSLongitudeRef'] ?? 'E'  | 
                                                        |
| 266 | - ]  | 
                                                        |
| 267 | - );  | 
                                                        |
| 260 | + $lon = $this->convertDMStoD(  | 
                                                        |
| 261 | + [  | 
                                                        |
| 262 | + $exif ['GPS'] ['GPSLongitude'] [0],  | 
                                                        |
| 263 | + $exif ['GPS'] ['GPSLongitude'] [1],  | 
                                                        |
| 264 | + $exif ['GPS'] ['GPSLongitude'] [2],  | 
                                                        |
| 265 | + $exif ['GPS'] ['GPSLongitudeRef'] ?? 'E'  | 
                                                        |
| 266 | + ]  | 
                                                        |
| 267 | + );  | 
                                                        |
| 268 | 268 | |
| 269 | - return new Point($lon, $lat);  | 
                                                        |
| 270 | - }  | 
                                                        |
| 269 | + return new Point($lon, $lat);  | 
                                                        |
| 270 | + }  | 
                                                        |
| 271 | 271 | |
| 272 | - /**  | 
                                                        |
| 273 | - * convert DegreesMinutesSeconds to Decimal degrees.  | 
                                                        |
| 274 | - *  | 
                                                        |
| 275 | - * @param array $param array of rational DMS  | 
                                                        |
| 276 | - */  | 
                                                        |
| 277 | - final public function convertDMStoD(array $param): float  | 
                                                        |
| 278 | -    { | 
                                                        |
| 279 | -        //        if (!(is_array($param))) { | 
                                                        |
| 280 | - // $param = [$param];  | 
                                                        |
| 281 | - // }  | 
                                                        |
| 282 | - $deg = $this->convertRationaltoFloat($param [0]);  | 
                                                        |
| 283 | - $min = $this->convertRationaltoFloat($param [1]) / 60;  | 
                                                        |
| 284 | - $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;  | 
                                                        |
| 285 | - // Hemisphere (N, S, W or E)  | 
                                                        |
| 286 | - $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;  | 
                                                        |
| 272 | + /**  | 
                                                        |
| 273 | + * convert DegreesMinutesSeconds to Decimal degrees.  | 
                                                        |
| 274 | + *  | 
                                                        |
| 275 | + * @param array $param array of rational DMS  | 
                                                        |
| 276 | + */  | 
                                                        |
| 277 | + final public function convertDMStoD(array $param): float  | 
                                                        |
| 278 | +	{ | 
                                                        |
| 279 | +		//        if (!(is_array($param))) { | 
                                                        |
| 280 | + // $param = [$param];  | 
                                                        |
| 281 | + // }  | 
                                                        |
| 282 | + $deg = $this->convertRationaltoFloat($param [0]);  | 
                                                        |
| 283 | + $min = $this->convertRationaltoFloat($param [1]) / 60;  | 
                                                        |
| 284 | + $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60;  | 
                                                        |
| 285 | + // Hemisphere (N, S, W or E)  | 
                                                        |
| 286 | + $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1;  | 
                                                        |
| 287 | 287 | |
| 288 | - return $hem * ($deg + $min + $sec);  | 
                                                        |
| 289 | - }  | 
                                                        |
| 288 | + return $hem * ($deg + $min + $sec);  | 
                                                        |
| 289 | + }  | 
                                                        |
| 290 | 290 | |
| 291 | - final public function convertRationaltoFloat(string $param): float  | 
                                                        |
| 292 | -    { | 
                                                        |
| 293 | - // rational64u  | 
                                                        |
| 294 | -        $nums = explode('/', $param); | 
                                                        |
| 295 | -        if ((int)$nums[1] > 0) { | 
                                                        |
| 296 | - return (float)$nums[0] / (int)$nums[1];  | 
                                                        |
| 297 | - }  | 
                                                        |
| 291 | + final public function convertRationaltoFloat(string $param): float  | 
                                                        |
| 292 | +	{ | 
                                                        |
| 293 | + // rational64u  | 
                                                        |
| 294 | +		$nums = explode('/', $param); | 
                                                        |
| 295 | +		if ((int)$nums[1] > 0) { | 
                                                        |
| 296 | + return (float)$nums[0] / (int)$nums[1];  | 
                                                        |
| 297 | + }  | 
                                                        |
| 298 | 298 | |
| 299 | - return (float)$nums[0];  | 
                                                        |
| 300 | - }  | 
                                                        |
| 299 | + return (float)$nums[0];  | 
                                                        |
| 300 | + }  | 
                                                        |
| 301 | 301 | |
| 302 | - /**  | 
                                                        |
| 303 | - * Deletes the page from the index.  | 
                                                        |
| 304 | - *  | 
                                                        |
| 305 | - * @param string $id document ID  | 
                                                        |
| 306 | - */  | 
                                                        |
| 307 | - final public function deleteFromIndex(string $id): void  | 
                                                        |
| 308 | -    { | 
                                                        |
| 309 | - // check the index for document  | 
                                                        |
| 310 | - $knownHashes = $this->findHashesForId($id, $this->spatial_idx);  | 
                                                        |
| 311 | -        if ($knownHashes === []) { | 
                                                        |
| 312 | - return;  | 
                                                        |
| 313 | - }  | 
                                                        |
| 302 | + /**  | 
                                                        |
| 303 | + * Deletes the page from the index.  | 
                                                        |
| 304 | + *  | 
                                                        |
| 305 | + * @param string $id document ID  | 
                                                        |
| 306 | + */  | 
                                                        |
| 307 | + final public function deleteFromIndex(string $id): void  | 
                                                        |
| 308 | +	{ | 
                                                        |
| 309 | + // check the index for document  | 
                                                        |
| 310 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx);  | 
                                                        |
| 311 | +		if ($knownHashes === []) { | 
                                                        |
| 312 | + return;  | 
                                                        |
| 313 | + }  | 
                                                        |
| 314 | 314 | |
| 315 | - // TODO shortcut, need to make sure there is only one element, if not the index is corrupt  | 
                                                        |
| 316 | - $knownHash = $knownHashes [0];  | 
                                                        |
| 317 | - $knownIds = $this->spatial_idx [$knownHash];  | 
                                                        |
| 318 | - $i = array_search($id, $knownIds);  | 
                                                        |
| 319 | -        Logger::debug("removing: $knownIds[$i] from the index."); | 
                                                        |
| 320 | - unset($knownIds [$i]);  | 
                                                        |
| 321 | - $this->spatial_idx [$knownHash] = $knownIds;  | 
                                                        |
| 322 | -        if (empty($this->spatial_idx [$knownHash])) { | 
                                                        |
| 323 | - unset($this->spatial_idx [$knownHash]);  | 
                                                        |
| 324 | - }  | 
                                                        |
| 325 | - $this->saveIndex();  | 
                                                        |
| 326 | - }  | 
                                                        |
| 315 | + // TODO shortcut, need to make sure there is only one element, if not the index is corrupt  | 
                                                        |
| 316 | + $knownHash = $knownHashes [0];  | 
                                                        |
| 317 | + $knownIds = $this->spatial_idx [$knownHash];  | 
                                                        |
| 318 | + $i = array_search($id, $knownIds);  | 
                                                        |
| 319 | +		Logger::debug("removing: $knownIds[$i] from the index."); | 
                                                        |
| 320 | + unset($knownIds [$i]);  | 
                                                        |
| 321 | + $this->spatial_idx [$knownHash] = $knownIds;  | 
                                                        |
| 322 | +		if (empty($this->spatial_idx [$knownHash])) { | 
                                                        |
| 323 | + unset($this->spatial_idx [$knownHash]);  | 
                                                        |
| 324 | + }  | 
                                                        |
| 325 | + $this->saveIndex();  | 
                                                        |
| 326 | + }  | 
                                                        |
| 327 | 327 | }  | 
                                                        
@@ -14,95 +14,95 @@  | 
                                                    ||
| 14 | 14 | class index_test extends DokuWikiTest  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | 16 | |
| 17 | -    protected $pluginsEnabled = array('spatialhelper'); | 
                                                        |
| 18 | -  | 
                                                        |
| 19 | - /**  | 
                                                        |
| 20 | - * copy data and add pages to the index.  | 
                                                        |
| 21 | - */  | 
                                                        |
| 22 | - public static function setUpBeforeClass(): void  | 
                                                        |
| 23 | -    { | 
                                                        |
| 24 | - parent::setUpBeforeClass();  | 
                                                        |
| 25 | - global $conf;  | 
                                                        |
| 26 | - $conf['allowdebug'] = 1;  | 
                                                        |
| 27 | -  | 
                                                        |
| 28 | - TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');  | 
                                                        |
| 29 | - }  | 
                                                        |
| 30 | -  | 
                                                        |
| 31 | - /**  | 
                                                        |
| 32 | - * Test data provider.  | 
                                                        |
| 33 | - * @return array  | 
                                                        |
| 34 | - * @see index_test::test_convertDMStoD  | 
                                                        |
| 35 | - *  | 
                                                        |
| 36 | - * @see index_test::test_convertDMStoD  | 
                                                        |
| 37 | - */  | 
                                                        |
| 38 | - final public static function convertDMStoDTestdata(): array  | 
                                                        |
| 39 | -    { | 
                                                        |
| 40 | - return array(  | 
                                                        |
| 41 | - array(  | 
                                                        |
| 42 | - array(0 => '52/1', 1 => '31/1', 2 => '2/1', 3 => 'N',),  | 
                                                        |
| 43 | - 52.5172,  | 
                                                        |
| 44 | - 'Latitude in Europe'  | 
                                                        |
| 45 | - ),  | 
                                                        |
| 46 | - array(  | 
                                                        |
| 47 | - array(0 => '13/1', 1 => '30/1', 2 => '38/1', 3 => 'E',),  | 
                                                        |
| 48 | - 13.5105,  | 
                                                        |
| 49 | - 'Longitude in Europe'  | 
                                                        |
| 50 | - ),  | 
                                                        |
| 51 | - array(  | 
                                                        |
| 52 | - array(0 => '50/1', 1 => '34251480/1000000', 2 => '0/1', 3 => 'N',),  | 
                                                        |
| 53 | - 50.5708,  | 
                                                        |
| 54 | - 'Latitude in North America'  | 
                                                        |
| 55 | - ),  | 
                                                        |
| 56 | - array(  | 
                                                        |
| 57 | - array(0 => '109/1', 1 => '28041300/1000000', 2 => '0/1', 3 => 'W',),  | 
                                                        |
| 58 | - -109.4673,  | 
                                                        |
| 59 | - 'Longitude in North America'  | 
                                                        |
| 60 | - ),  | 
                                                        |
| 61 | - );  | 
                                                        |
| 62 | - }  | 
                                                        |
| 63 | -  | 
                                                        |
| 64 | - final public function setUp(): void  | 
                                                        |
| 65 | -    { | 
                                                        |
| 66 | - parent::setUp();  | 
                                                        |
| 67 | -  | 
                                                        |
| 68 | - global $conf;  | 
                                                        |
| 69 | - $conf['allowdebug'] = 1;  | 
                                                        |
| 70 | - $conf['cachetime'] = -1;  | 
                                                        |
| 71 | - }  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | - /**  | 
                                                        |
| 74 | - * @dataProvider convertDMStoDTestdata  | 
                                                        |
| 75 | - */  | 
                                                        |
| 76 | - final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void  | 
                                                        |
| 77 | -    { | 
                                                        |
| 78 | -        $index = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 79 | -        self::assertInstanceOf('helper_plugin_spatialhelper_index', $index); | 
                                                        |
| 80 | -  | 
                                                        |
| 81 | - $actual_output = $index->convertDMStoD($input);  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - self::assertEqualsWithDelta($expected_output, $actual_output, 0.0001, $msg);  | 
                                                        |
| 84 | - }  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | - final public function test_ImageWithoutGeotag(): void  | 
                                                        |
| 87 | -    { | 
                                                        |
| 88 | -        $index = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 89 | -        self::assertInstanceOf('helper_plugin_spatialhelper_index', $index); | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | -        $actual_output = $index->getCoordsFromExif(':vesder_eupen_no_gps.jpg'); | 
                                                        |
| 92 | - self::assertFalse($actual_output, 'Expected no geotag to be found');  | 
                                                        |
| 93 | - }  | 
                                                        |
| 94 | -  | 
                                                        |
| 95 | - final public function test_ImageWithGeotag(): void  | 
                                                        |
| 96 | -    { | 
                                                        |
| 97 | -        $index = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 98 | -        self::assertInstanceOf('helper_plugin_spatialhelper_index', $index); | 
                                                        |
| 99 | -  | 
                                                        |
| 100 | - // lat/lon: 37°4'36.12",31°39'21.96" or x/y: 31.6561,37.0767  | 
                                                        |
| 101 | -        $actual_output = $index->getCoordsFromExif(':manavgat_restaurant_handost_with_gps.jpg'); | 
                                                        |
| 102 | -  | 
                                                        |
| 103 | - self::assertNotNull($actual_output, 'Expected a geotag to be found');  | 
                                                        |
| 104 | - self::assertNotFalse($actual_output, 'Expected a geotag to be found');  | 
                                                        |
| 105 | - self::assertEqualsWithDelta(31.6561, $actual_output->x(), 0.0001);  | 
                                                        |
| 106 | - self::assertEqualsWithDelta(37.0767, $actual_output->y(), 0.0001);  | 
                                                        |
| 107 | - }  | 
                                                        |
| 17 | +	protected $pluginsEnabled = array('spatialhelper'); | 
                                                        |
| 18 | +  | 
                                                        |
| 19 | + /**  | 
                                                        |
| 20 | + * copy data and add pages to the index.  | 
                                                        |
| 21 | + */  | 
                                                        |
| 22 | + public static function setUpBeforeClass(): void  | 
                                                        |
| 23 | +	{ | 
                                                        |
| 24 | + parent::setUpBeforeClass();  | 
                                                        |
| 25 | + global $conf;  | 
                                                        |
| 26 | + $conf['allowdebug'] = 1;  | 
                                                        |
| 27 | +  | 
                                                        |
| 28 | + TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');  | 
                                                        |
| 29 | + }  | 
                                                        |
| 30 | +  | 
                                                        |
| 31 | + /**  | 
                                                        |
| 32 | + * Test data provider.  | 
                                                        |
| 33 | + * @return array  | 
                                                        |
| 34 | + * @see index_test::test_convertDMStoD  | 
                                                        |
| 35 | + *  | 
                                                        |
| 36 | + * @see index_test::test_convertDMStoD  | 
                                                        |
| 37 | + */  | 
                                                        |
| 38 | + final public static function convertDMStoDTestdata(): array  | 
                                                        |
| 39 | +	{ | 
                                                        |
| 40 | + return array(  | 
                                                        |
| 41 | + array(  | 
                                                        |
| 42 | + array(0 => '52/1', 1 => '31/1', 2 => '2/1', 3 => 'N',),  | 
                                                        |
| 43 | + 52.5172,  | 
                                                        |
| 44 | + 'Latitude in Europe'  | 
                                                        |
| 45 | + ),  | 
                                                        |
| 46 | + array(  | 
                                                        |
| 47 | + array(0 => '13/1', 1 => '30/1', 2 => '38/1', 3 => 'E',),  | 
                                                        |
| 48 | + 13.5105,  | 
                                                        |
| 49 | + 'Longitude in Europe'  | 
                                                        |
| 50 | + ),  | 
                                                        |
| 51 | + array(  | 
                                                        |
| 52 | + array(0 => '50/1', 1 => '34251480/1000000', 2 => '0/1', 3 => 'N',),  | 
                                                        |
| 53 | + 50.5708,  | 
                                                        |
| 54 | + 'Latitude in North America'  | 
                                                        |
| 55 | + ),  | 
                                                        |
| 56 | + array(  | 
                                                        |
| 57 | + array(0 => '109/1', 1 => '28041300/1000000', 2 => '0/1', 3 => 'W',),  | 
                                                        |
| 58 | + -109.4673,  | 
                                                        |
| 59 | + 'Longitude in North America'  | 
                                                        |
| 60 | + ),  | 
                                                        |
| 61 | + );  | 
                                                        |
| 62 | + }  | 
                                                        |
| 63 | +  | 
                                                        |
| 64 | + final public function setUp(): void  | 
                                                        |
| 65 | +	{ | 
                                                        |
| 66 | + parent::setUp();  | 
                                                        |
| 67 | +  | 
                                                        |
| 68 | + global $conf;  | 
                                                        |
| 69 | + $conf['allowdebug'] = 1;  | 
                                                        |
| 70 | + $conf['cachetime'] = -1;  | 
                                                        |
| 71 | + }  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | + /**  | 
                                                        |
| 74 | + * @dataProvider convertDMStoDTestdata  | 
                                                        |
| 75 | + */  | 
                                                        |
| 76 | + final public function test_convertDMStoD(array $input, float $expected_output, string $msg): void  | 
                                                        |
| 77 | +	{ | 
                                                        |
| 78 | +		$index = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 79 | +		self::assertInstanceOf('helper_plugin_spatialhelper_index', $index); | 
                                                        |
| 80 | +  | 
                                                        |
| 81 | + $actual_output = $index->convertDMStoD($input);  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + self::assertEqualsWithDelta($expected_output, $actual_output, 0.0001, $msg);  | 
                                                        |
| 84 | + }  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | + final public function test_ImageWithoutGeotag(): void  | 
                                                        |
| 87 | +	{ | 
                                                        |
| 88 | +		$index = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 89 | +		self::assertInstanceOf('helper_plugin_spatialhelper_index', $index); | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | +		$actual_output = $index->getCoordsFromExif(':vesder_eupen_no_gps.jpg'); | 
                                                        |
| 92 | + self::assertFalse($actual_output, 'Expected no geotag to be found');  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | +  | 
                                                        |
| 95 | + final public function test_ImageWithGeotag(): void  | 
                                                        |
| 96 | +	{ | 
                                                        |
| 97 | +		$index = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 98 | +		self::assertInstanceOf('helper_plugin_spatialhelper_index', $index); | 
                                                        |
| 99 | +  | 
                                                        |
| 100 | + // lat/lon: 37°4'36.12",31°39'21.96" or x/y: 31.6561,37.0767  | 
                                                        |
| 101 | +		$actual_output = $index->getCoordsFromExif(':manavgat_restaurant_handost_with_gps.jpg'); | 
                                                        |
| 102 | +  | 
                                                        |
| 103 | + self::assertNotNull($actual_output, 'Expected a geotag to be found');  | 
                                                        |
| 104 | + self::assertNotFalse($actual_output, 'Expected a geotag to be found');  | 
                                                        |
| 105 | + self::assertEqualsWithDelta(31.6561, $actual_output->x(), 0.0001);  | 
                                                        |
| 106 | + self::assertEqualsWithDelta(37.0767, $actual_output->y(), 0.0001);  | 
                                                        |
| 107 | + }  | 
                                                        |
| 108 | 108 | }  | 
                                                        
@@ -30,160 +30,160 @@  | 
                                                    ||
| 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 bounding 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 bounding 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 | -        if (strlen($geohash) < 10) { | 
                                                        |
| 176 | - $precision = $this->precision[strlen($geohash)];  | 
                                                        |
| 177 | -        } else { | 
                                                        |
| 178 | - $precision = $this->precision[9];  | 
                                                        |
| 179 | - }  | 
                                                        |
| 180 | - return [  | 
                                                        |
| 181 | - 'pages' => $pages,  | 
                                                        |
| 182 | - 'media' => $media,  | 
                                                        |
| 183 | - 'lat' => $decodedPoint->y(),  | 
                                                        |
| 184 | - 'lon' => $decodedPoint->x(),  | 
                                                        |
| 185 | - 'geohash' => $geohash,  | 
                                                        |
| 186 | - 'precision' => $precision  | 
                                                        |
| 187 | - ];  | 
                                                        |
| 188 | - }  | 
                                                        |
| 175 | +		if (strlen($geohash) < 10) { | 
                                                        |
| 176 | + $precision = $this->precision[strlen($geohash)];  | 
                                                        |
| 177 | +		} else { | 
                                                        |
| 178 | + $precision = $this->precision[9];  | 
                                                        |
| 179 | + }  | 
                                                        |
| 180 | + return [  | 
                                                        |
| 181 | + 'pages' => $pages,  | 
                                                        |
| 182 | + 'media' => $media,  | 
                                                        |
| 183 | + 'lat' => $decodedPoint->y(),  | 
                                                        |
| 184 | + 'lon' => $decodedPoint->x(),  | 
                                                        |
| 185 | + 'geohash' => $geohash,  | 
                                                        |
| 186 | + 'precision' => $precision  | 
                                                        |
| 187 | + ];  | 
                                                        |
| 188 | + }  | 
                                                        |
| 189 | 189 | }  | 
                                                        
@@ -26,92 +26,92 @@  | 
                                                    ||
| 26 | 26 | */  | 
                                                        
| 27 | 27 | class indexing_test extends DokuWikiTest  | 
                                                        
| 28 | 28 |  { | 
                                                        
| 29 | - /**  | 
                                                        |
| 30 | - * copy data and add pages to the index.  | 
                                                        |
| 31 | - */  | 
                                                        |
| 32 | - public static function setUpBeforeClass(): void  | 
                                                        |
| 33 | -    { | 
                                                        |
| 34 | - parent::setUpBeforeClass();  | 
                                                        |
| 35 | - TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');  | 
                                                        |
| 36 | - }  | 
                                                        |
| 29 | + /**  | 
                                                        |
| 30 | + * copy data and add pages to the index.  | 
                                                        |
| 31 | + */  | 
                                                        |
| 32 | + public static function setUpBeforeClass(): void  | 
                                                        |
| 33 | +	{ | 
                                                        |
| 34 | + parent::setUpBeforeClass();  | 
                                                        |
| 35 | + TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');  | 
                                                        |
| 36 | + }  | 
                                                        |
| 37 | 37 | |
| 38 | - final public function setUp(): void  | 
                                                        |
| 39 | -    { | 
                                                        |
| 40 | - $this->pluginsEnabled = array(  | 
                                                        |
| 41 | - 'geophp',  | 
                                                        |
| 42 | - 'geotag',  | 
                                                        |
| 43 | - 'spatialhelper'  | 
                                                        |
| 44 | - );  | 
                                                        |
| 38 | + final public function setUp(): void  | 
                                                        |
| 39 | +	{ | 
                                                        |
| 40 | + $this->pluginsEnabled = array(  | 
                                                        |
| 41 | + 'geophp',  | 
                                                        |
| 42 | + 'geotag',  | 
                                                        |
| 43 | + 'spatialhelper'  | 
                                                        |
| 44 | + );  | 
                                                        |
| 45 | 45 | |
| 46 | - global $conf;  | 
                                                        |
| 47 | - $conf['allowdebug'] = 1;  | 
                                                        |
| 48 | - $conf['dontlog'] = [];  | 
                                                        |
| 49 | - $conf['cachetime'] = -1;  | 
                                                        |
| 46 | + global $conf;  | 
                                                        |
| 47 | + $conf['allowdebug'] = 1;  | 
                                                        |
| 48 | + $conf['dontlog'] = [];  | 
                                                        |
| 49 | + $conf['cachetime'] = -1;  | 
                                                        |
| 50 | 50 | |
| 51 | - parent::setUp();  | 
                                                        |
| 51 | + parent::setUp();  | 
                                                        |
| 52 | 52 | |
| 53 | -        $indexer = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 54 | -        self::assertInstanceOf('helper_plugin_spatialhelper_index', $indexer); | 
                                                        |
| 53 | +		$indexer = plugin_load('helper', 'spatialhelper_index'); | 
                                                        |
| 54 | +		self::assertInstanceOf('helper_plugin_spatialhelper_index', $indexer); | 
                                                        |
| 55 | 55 | |
| 56 | - $data = [];  | 
                                                        |
| 57 | -        search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); | 
                                                        |
| 56 | + $data = [];  | 
                                                        |
| 57 | +		search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); | 
                                                        |
| 58 | 58 | |
| 59 | -        foreach ($data as $val) { | 
                                                        |
| 60 | - idx_addPage($val['id']);  | 
                                                        |
| 61 | - $indexer->updateSpatialIndex($val['id']);  | 
                                                        |
| 62 | - }  | 
                                                        |
| 63 | - }  | 
                                                        |
| 59 | +		foreach ($data as $val) { | 
                                                        |
| 60 | + idx_addPage($val['id']);  | 
                                                        |
| 61 | + $indexer->updateSpatialIndex($val['id']);  | 
                                                        |
| 62 | + }  | 
                                                        |
| 63 | + }  | 
                                                        |
| 64 | 64 | |
| 65 | - /**  | 
                                                        |
| 66 | - * @throws Exception if anything goes wrong  | 
                                                        |
| 67 | - */  | 
                                                        |
| 68 | - final public function testIndexed(): void  | 
                                                        |
| 69 | -    { | 
                                                        |
| 70 | - // render the page  | 
                                                        |
| 71 | - $request = new TestRequest();  | 
                                                        |
| 72 | -        $response = $request->get(array('id' => 'geotag')); | 
                                                        |
| 65 | + /**  | 
                                                        |
| 66 | + * @throws Exception if anything goes wrong  | 
                                                        |
| 67 | + */  | 
                                                        |
| 68 | + final public function testIndexed(): void  | 
                                                        |
| 69 | +	{ | 
                                                        |
| 70 | + // render the page  | 
                                                        |
| 71 | + $request = new TestRequest();  | 
                                                        |
| 72 | +		$response = $request->get(array('id' => 'geotag')); | 
                                                        |
| 73 | 73 | |
| 74 | - // test metadata  | 
                                                        |
| 75 | - self::assertEquals(  | 
                                                        |
| 76 | - '52.132633;5.291266;9',  | 
                                                        |
| 77 | -            $response->queryHTML('meta[name="geo.position"]')->attr('content') | 
                                                        |
| 78 | - );  | 
                                                        |
| 79 | - self::assertEquals(  | 
                                                        |
| 80 | - '52.132633, 5.291266',  | 
                                                        |
| 81 | -            $response->queryHTML('meta[name="ICBM"]')->attr('content') | 
                                                        |
| 82 | - );  | 
                                                        |
| 74 | + // test metadata  | 
                                                        |
| 75 | + self::assertEquals(  | 
                                                        |
| 76 | + '52.132633;5.291266;9',  | 
                                                        |
| 77 | +			$response->queryHTML('meta[name="geo.position"]')->attr('content') | 
                                                        |
| 78 | + );  | 
                                                        |
| 79 | + self::assertEquals(  | 
                                                        |
| 80 | + '52.132633, 5.291266',  | 
                                                        |
| 81 | +			$response->queryHTML('meta[name="ICBM"]')->attr('content') | 
                                                        |
| 82 | + );  | 
                                                        |
| 83 | 83 | |
| 84 | - // test the geohash and index values  | 
                                                        |
| 85 | - self::assertStringStartsWith(  | 
                                                        |
| 86 | - 'u17b86kyx7jv',  | 
                                                        |
| 87 | -            $response->queryHTML('meta[name="geo.geohash"]')->attr('content') | 
                                                        |
| 88 | - );  | 
                                                        |
| 89 | - }  | 
                                                        |
| 84 | + // test the geohash and index values  | 
                                                        |
| 85 | + self::assertStringStartsWith(  | 
                                                        |
| 86 | + 'u17b86kyx7jv',  | 
                                                        |
| 87 | +			$response->queryHTML('meta[name="geo.geohash"]')->attr('content') | 
                                                        |
| 88 | + );  | 
                                                        |
| 89 | + }  | 
                                                        |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - final public function testIndexFileExists(): void  | 
                                                        |
| 93 | -    { | 
                                                        |
| 94 | - self::assertFileExists(TMP_DIR . '/data/index/spatial.idx');  | 
                                                        |
| 95 | - }  | 
                                                        |
| 92 | + final public function testIndexFileExists(): void  | 
                                                        |
| 93 | +	{ | 
                                                        |
| 94 | + self::assertFileExists(TMP_DIR . '/data/index/spatial.idx');  | 
                                                        |
| 95 | + }  | 
                                                        |
| 96 | 96 | |
| 97 | - final public function testIndexFileNotEmpty(): void  | 
                                                        |
| 98 | -    { | 
                                                        |
| 99 | - self::assertGreaterThan(0, filesize(TMP_DIR . '/data/index/spatial.idx'));  | 
                                                        |
| 100 | - }  | 
                                                        |
| 97 | + final public function testIndexFileNotEmpty(): void  | 
                                                        |
| 98 | +	{ | 
                                                        |
| 99 | + self::assertGreaterThan(0, filesize(TMP_DIR . '/data/index/spatial.idx'));  | 
                                                        |
| 100 | + }  | 
                                                        |
| 101 | 101 | |
| 102 | - final public function testSearchNearby(): void  | 
                                                        |
| 103 | -    { | 
                                                        |
| 104 | -        $search = plugin_load('helper', 'spatialhelper_search'); | 
                                                        |
| 105 | -        self::assertInstanceOf('helper_plugin_spatialhelper_search', $search); | 
                                                        |
| 102 | + final public function testSearchNearby(): void  | 
                                                        |
| 103 | +	{ | 
                                                        |
| 104 | +		$search = plugin_load('helper', 'spatialhelper_search'); | 
                                                        |
| 105 | +		self::assertInstanceOf('helper_plugin_spatialhelper_search', $search); | 
                                                        |
| 106 | 106 | |
| 107 | -        $result = $search->findNearby('u17b86kyx7'); | 
                                                        |
| 108 | - self::assertIsArray($result);  | 
                                                        |
| 109 | - self::assertNotEmpty($result);  | 
                                                        |
| 110 | - self::assertEmpty($result['media']);  | 
                                                        |
| 111 | -        self::assertEquals('geotag', $result['pages'][0]['id']); | 
                                                        |
| 112 | -        self::assertEquals('u17b86kyx7', $result['geohash']); | 
                                                        |
| 113 | - self::assertEquals(0.6, $result['precision']);  | 
                                                        |
| 114 | - self::assertEqualsWithDelta(52.1326, $result['lat'], 0.001);  | 
                                                        |
| 115 | - self::assertEqualsWithDelta(5.2912, $result['lon'], 0.001);  | 
                                                        |
| 116 | - }  | 
                                                        |
| 107 | +		$result = $search->findNearby('u17b86kyx7'); | 
                                                        |
| 108 | + self::assertIsArray($result);  | 
                                                        |
| 109 | + self::assertNotEmpty($result);  | 
                                                        |
| 110 | + self::assertEmpty($result['media']);  | 
                                                        |
| 111 | +		self::assertEquals('geotag', $result['pages'][0]['id']); | 
                                                        |
| 112 | +		self::assertEquals('u17b86kyx7', $result['geohash']); | 
                                                        |
| 113 | + self::assertEquals(0.6, $result['precision']);  | 
                                                        |
| 114 | + self::assertEqualsWithDelta(52.1326, $result['lat'], 0.001);  | 
                                                        |
| 115 | + self::assertEqualsWithDelta(5.2912, $result['lon'], 0.001);  | 
                                                        |
| 116 | + }  | 
                                                        |
| 117 | 117 | }  |