@@ -162,11 +162,10 @@ |
||
| 162 | 162 | /** |
| 163 | 163 | * Add an index entry for this file having EXIF / IPTC data. |
| 164 | 164 | * |
| 165 | - * @param unknown_type $param |
|
| 166 | 165 | * @see http://www.php.net/manual/en/function.iptcparse.php |
| 167 | 166 | * @see http://php.net/manual/en/function.exif-read-data.php |
| 168 | 167 | * |
| 169 | - * @return true when image was succesfully added to the index. |
|
| 168 | + * @return boolean when image was succesfully added to the index. |
|
| 170 | 169 | */ |
| 171 | 170 | function indexImage($img) { |
| 172 | 171 | // test for supported files (jpeg only) |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | 16 | */ |
| 17 | -if (! defined ( 'DOKU_INC' )) |
|
| 17 | +if (!defined('DOKU_INC')) |
|
| 18 | 18 | die (); |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @var array |
| 39 | 39 | */ |
| 40 | - protected $spatial_idx = array (); |
|
| 40 | + protected $spatial_idx = array(); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * handle to the geoPHP plugin. |
@@ -49,20 +49,20 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | function __construct() { |
| 51 | 51 | // parent::__construct (); |
| 52 | - if (! $geophp = &plugin_load ( 'helper', 'geophp' )) { |
|
| 52 | + if (!$geophp = &plugin_load('helper', 'geophp')) { |
|
| 53 | 53 | $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: geophp plugin is not available.'; |
| 54 | - msg ( $message, - 1 ); |
|
| 54 | + msg($message, - 1); |
|
| 55 | 55 | return ""; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | global $conf; |
| 59 | 59 | $this->idx_dir = $conf ['indexdir']; |
| 60 | 60 | // test if there is a spatialindex, if not build one for the wiki |
| 61 | - if (! @file_exists ( $this->idx_dir . '/spatial.idx' )) { |
|
| 61 | + if (!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
| 62 | 62 | // creates and stores the index |
| 63 | - $this->generateSpatialIndex (); |
|
| 63 | + $this->generateSpatialIndex(); |
|
| 64 | 64 | } else { |
| 65 | - $this->spatial_idx = unserialize ( io_readFile ( $this->idx_dir . '/spatial.idx', false ) ); |
|
| 65 | + $this->spatial_idx = unserialize(io_readFile($this->idx_dir . '/spatial.idx', false)); |
|
| 66 | 66 | // dbglog ( $this->spatial_idx, 'done loading spatial index' ); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * the document ID |
| 75 | 75 | */ |
| 76 | 76 | function updateSpatialIndex($id) { |
| 77 | - $geotags = p_get_metadata ( $id, 'geo' ); |
|
| 78 | - if (empty ( $geotags )) return false; |
|
| 77 | + $geotags = p_get_metadata($id, 'geo'); |
|
| 78 | + if (empty ($geotags)) return false; |
|
| 79 | 79 | if (empty ($geotags ['lon']) || empty ($geotags ['lat'])) return false; |
| 80 | 80 | // dbglog ( $geotags, "Geo metadata found for page $id" ); |
| 81 | - $geometry = new Point ( $geotags ['lon'], $geotags ['lat'] ); |
|
| 82 | - $geohash = $geometry->out ( 'geohash' ); |
|
| 81 | + $geometry = new Point($geotags ['lon'], $geotags ['lat']); |
|
| 82 | + $geohash = $geometry->out('geohash'); |
|
| 83 | 83 | // dbglog ( 'Update index for geohash: ' . $geohash ); |
| 84 | - $succes = $this->_addToIndex ( $geohash, $id ); |
|
| 84 | + $succes = $this->_addToIndex($geohash, $id); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * spatial index |
| 94 | 94 | */ |
| 95 | 95 | function findHashesForId($id, $index) { |
| 96 | - $hashes = array (); |
|
| 97 | - foreach ( $index as $hash => $docIds ) { |
|
| 98 | - if (in_array ( $id, $docIds, false )) { |
|
| 96 | + $hashes = array(); |
|
| 97 | + foreach ($index as $hash => $docIds) { |
|
| 98 | + if (in_array($id, $docIds, false)) { |
|
| 99 | 99 | $hashes [] = $hash; |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -111,29 +111,29 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function deleteFromIndex($id) { |
| 113 | 113 | // check the index for document |
| 114 | - $knownHashes = $this->findHashesForId ( $id, $this->spatial_idx ); |
|
| 115 | - if (empty ( $knownHashes )) |
|
| 114 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
| 115 | + if (empty ($knownHashes)) |
|
| 116 | 116 | return; |
| 117 | 117 | |
| 118 | 118 | // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
| 119 | 119 | $knownHash = $knownHashes [0]; |
| 120 | 120 | $knownIds = $this->spatial_idx [$knownHash]; |
| 121 | - $i = array_search ( $id, $knownIds ); |
|
| 121 | + $i = array_search($id, $knownIds); |
|
| 122 | 122 | // dbglog ( "removing: $knownIds[$i] from the index." ); |
| 123 | - unset ( $knownIds [$i] ); |
|
| 123 | + unset ($knownIds [$i]); |
|
| 124 | 124 | $this->spatial_idx [$knownHash] = $knownIds; |
| 125 | - if (empty ( $this->spatial_idx [$knownHash] )) { |
|
| 125 | + if (empty ($this->spatial_idx [$knownHash])) { |
|
| 126 | 126 | // dbglog ( "removing key: $knownHash from the index." ); |
| 127 | - unset ( $this->spatial_idx [$knownHash] ); |
|
| 127 | + unset ($this->spatial_idx [$knownHash]); |
|
| 128 | 128 | } |
| 129 | - $succes = $this->_saveIndex (); |
|
| 129 | + $succes = $this->_saveIndex(); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * Save spatial index. |
| 134 | 134 | */ |
| 135 | 135 | private function _saveIndex() { |
| 136 | - return io_saveFile ( $this->idx_dir . '/spatial.idx', serialize ( $this->spatial_idx ) ); |
|
| 136 | + return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx)); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -144,17 +144,17 @@ discard block |
||
| 144 | 144 | function generateSpatialIndex() { |
| 145 | 145 | global $conf; |
| 146 | 146 | require_once (DOKU_INC . 'inc/search.php'); |
| 147 | - $pages = array (); |
|
| 148 | - search ( $pages, $conf ['datadir'], 'search_allpages', array () ); |
|
| 149 | - foreach ( $pages as $page ) { |
|
| 150 | - $this->updateSpatialIndex ( $page ['id'] ); |
|
| 147 | + $pages = array(); |
|
| 148 | + search($pages, $conf ['datadir'], 'search_allpages', array()); |
|
| 149 | + foreach ($pages as $page) { |
|
| 150 | + $this->updateSpatialIndex($page ['id']); |
|
| 151 | 151 | } |
| 152 | 152 | // media |
| 153 | - $media = array (); |
|
| 154 | - search ( $media, $conf ['mediadir'], 'search_media', array () ); |
|
| 155 | - foreach ( $media as $medium ) { |
|
| 153 | + $media = array(); |
|
| 154 | + search($media, $conf ['mediadir'], 'search_media', array()); |
|
| 155 | + foreach ($media as $medium) { |
|
| 156 | 156 | if ($medium ['isimg']) |
| 157 | - $this->indexImage ( $medium ); |
|
| 157 | + $this->indexImage($medium); |
|
| 158 | 158 | } |
| 159 | 159 | return true; |
| 160 | 160 | } |
@@ -170,19 +170,19 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function indexImage($img) { |
| 172 | 172 | // test for supported files (jpeg only) |
| 173 | - if ((substr ( $img ['file'], - strlen ( '.jpg' ) ) !== '.jpg') and (substr ( $img ['file'], - strlen ( '.jpeg' ) ) !== '.jpeg')) { |
|
| 173 | + if ((substr($img ['file'], - strlen('.jpg')) !== '.jpg') and (substr($img ['file'], - strlen('.jpeg')) !== '.jpeg')) { |
|
| 174 | 174 | return false; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - $geometry = $this->getCoordsFromExif ( $img ['id'] ); |
|
| 177 | + $geometry = $this->getCoordsFromExif($img ['id']); |
|
| 178 | 178 | if (!$geometry) { |
| 179 | 179 | return false; |
| 180 | 180 | } |
| 181 | - $geohash = $geometry->out ( 'geohash' ); |
|
| 181 | + $geohash = $geometry->out('geohash'); |
|
| 182 | 182 | // TODO truncate the geohash to something reasonable, otherwise they are |
| 183 | 183 | // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too |
| 184 | 184 | // precise, limit at ~9 as most GPS are not submeter accurate |
| 185 | - return $this->_addToIndex ( $geohash, 'media__' . $img ['id'] ); |
|
| 185 | + return $this->_addToIndex($geohash, 'media__' . $img ['id']); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -193,26 +193,26 @@ discard block |
||
| 193 | 193 | * @return Point or false |
| 194 | 194 | */ |
| 195 | 195 | public function getCoordsFromExif($id) { |
| 196 | - $exif = exif_read_data ( mediaFN ( $id ), 0, true ); |
|
| 197 | - if (empty ( $exif ['GPS'] )) { |
|
| 196 | + $exif = exif_read_data(mediaFN($id), 0, true); |
|
| 197 | + if (empty ($exif ['GPS'])) { |
|
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - $lat = $this->_convertDMStoD ( array ( |
|
| 201 | + $lat = $this->_convertDMStoD(array( |
|
| 202 | 202 | $exif ['GPS'] ['GPSLatitude'] [0], |
| 203 | 203 | $exif ['GPS'] ['GPSLatitude'] [1], |
| 204 | 204 | $exif ['GPS'] ['GPSLatitude'] [2], |
| 205 | 205 | $exif ['GPS'] ['GPSLatitudeRef'] |
| 206 | - ) ); |
|
| 206 | + )); |
|
| 207 | 207 | |
| 208 | - $lon = $this->_convertDMStoD ( array ( |
|
| 208 | + $lon = $this->_convertDMStoD(array( |
|
| 209 | 209 | $exif ['GPS'] ['GPSLongitude'] [0], |
| 210 | 210 | $exif ['GPS'] ['GPSLongitude'] [1], |
| 211 | 211 | $exif ['GPS'] ['GPSLongitude'] [2], |
| 212 | 212 | $exif ['GPS'] ['GPSLongitudeRef'] |
| 213 | - ) ); |
|
| 213 | + )); |
|
| 214 | 214 | |
| 215 | - return new Point ( $lon, $lat ); |
|
| 215 | + return new Point($lon, $lat); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -224,17 +224,17 @@ discard block |
||
| 224 | 224 | * @return boolean true when succesful |
| 225 | 225 | */ |
| 226 | 226 | private function _addToIndex($geohash, $id) { |
| 227 | - $pageIds = array (); |
|
| 227 | + $pageIds = array(); |
|
| 228 | 228 | // check index for key/geohash |
| 229 | - if (! array_key_exists ( $geohash, $this->spatial_idx )) { |
|
| 229 | + if (!array_key_exists($geohash, $this->spatial_idx)) { |
|
| 230 | 230 | // dbglog ( "Geohash $geohash not in index, just add $id." ); |
| 231 | 231 | $pageIds [] = $id; |
| 232 | 232 | } else { |
| 233 | 233 | // dbglog ( 'Geohash for document is in index, find it.' ); |
| 234 | 234 | // check the index for document |
| 235 | - $knownHashes = $this->findHashesForId ( $id, $this->spatial_idx ); |
|
| 236 | - if (empty ( $knownHashes )) { |
|
| 237 | - dbglog ( "No index record found for document $id, just add" ); |
|
| 235 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
| 236 | + if (empty ($knownHashes)) { |
|
| 237 | + dbglog("No index record found for document $id, just add"); |
|
| 238 | 238 | $pageIds = $this->spatial_idx [$geohash]; |
| 239 | 239 | $pageIds [] = $id; |
| 240 | 240 | } |
@@ -246,14 +246,14 @@ discard block |
||
| 246 | 246 | return true; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if (! empty ( $knownHash )) { |
|
| 249 | + if (!empty ($knownHash)) { |
|
| 250 | 250 | // dbglog ( "Document/media $id was found in index but has different geohash (it moved)." ); |
| 251 | 251 | $knownIds = $this->spatial_idx [$knownHash]; |
| 252 | 252 | // dbglog ( $knownIds, "Known id's for this hash:" ); |
| 253 | 253 | // remove it from the old geohash element |
| 254 | - $i = array_search ( $id, $knownIds ); |
|
| 254 | + $i = array_search($id, $knownIds); |
|
| 255 | 255 | // dbglog ( 'Unsetting:' . $knownIds [$i] ); |
| 256 | - unset ( $knownIds [$i] ); |
|
| 256 | + unset ($knownIds [$i]); |
|
| 257 | 257 | $this->spatial_idx [$knownHash] = $knownIds; |
| 258 | 258 | // set on new geohash element |
| 259 | 259 | $pageIds = $this->spatial_idx [$geohash]; |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | // store and save |
| 264 | 264 | $this->spatial_idx [$geohash] = $pageIds; |
| 265 | - return $this->_saveIndex (); |
|
| 265 | + return $this->_saveIndex(); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -273,12 +273,12 @@ discard block |
||
| 273 | 273 | * @return number |
| 274 | 274 | */ |
| 275 | 275 | private function _convertDMStoD($param) { |
| 276 | - if (!is_array($param)){ |
|
| 277 | - $param = array ($param); |
|
| 276 | + if (!is_array($param)) { |
|
| 277 | + $param = array($param); |
|
| 278 | 278 | } |
| 279 | - $deg = $this->_convertRationaltoFloat ( $param [0] ); |
|
| 280 | - $min = $this->_convertRationaltoFloat ( $param [1] ) / 60; |
|
| 281 | - $sec = $this->_convertRationaltoFloat ( $param [2] ) / 60 / 60; |
|
| 279 | + $deg = $this->_convertRationaltoFloat($param [0]); |
|
| 280 | + $min = $this->_convertRationaltoFloat($param [1]) / 60; |
|
| 281 | + $sec = $this->_convertRationaltoFloat($param [2]) / 60 / 60; |
|
| 282 | 282 | // Hemisphere (N, S, W or E) |
| 283 | 283 | $hem = $param [4] == ('N' | 'E') ? - 1 : 1; |
| 284 | 284 | return $hem * $deg + $min + $sec; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | private function _convertRationaltoFloat($param) { |
| 288 | 288 | // rational64u |
| 289 | 289 | $nums = explode('/', $param); |
| 290 | - if (intval ($nums[1]) > 0 ){ |
|
| 290 | + if (intval($nums[1]) > 0) { |
|
| 291 | 291 | return intval($nums[0]) / intval($nums[1]); |
| 292 | 292 | } else { |
| 293 | 293 | return intval($nums[0]); |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | 16 | */ |
| 17 | -if (! defined ( 'DOKU_INC' )) |
|
| 17 | +if (!defined('DOKU_INC')) |
|
| 18 | 18 | die (); |
| 19 | -if (! defined ( 'DOKU_PLUGIN' )) |
|
| 20 | - define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' ); |
|
| 19 | +if (!defined('DOKU_PLUGIN')) |
|
| 20 | + define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); |
|
| 21 | 21 | require_once DOKU_PLUGIN . 'admin.php'; |
| 22 | 22 | /** |
| 23 | 23 | * DokuWiki Plugin spatialhelper (Admin Component). |
@@ -52,22 +52,22 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function handle() { |
| 54 | 54 | global $conf; |
| 55 | - if (isset ( $_REQUEST ['purgeindex'] )) { |
|
| 55 | + if (isset ($_REQUEST ['purgeindex'])) { |
|
| 56 | 56 | global $conf; |
| 57 | 57 | $path = $conf ['indexdir'] . '/spatial.idx'; |
| 58 | - if (file_exists ( $path )) { |
|
| 59 | - if (unlink ( $path )) { |
|
| 60 | - msg ( $this->getLang ( 'admin_purged_tiles' ), 0 ); |
|
| 58 | + if (file_exists($path)) { |
|
| 59 | + if (unlink($path)) { |
|
| 60 | + msg($this->getLang('admin_purged_tiles'), 0); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $indexer = plugin_load ( 'helper', 'spatialhelper_index' ); |
|
| 66 | - $indexer->generateSpatialIndex (); |
|
| 65 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
| 66 | + $indexer->generateSpatialIndex(); |
|
| 67 | 67 | |
| 68 | - $sitemapper = plugin_load ( 'helper', 'spatialhelper_sitemap' ); |
|
| 69 | - $sitemapper->createKMLSitemap ( $this->getConf('media_kml') ); |
|
| 70 | - $sitemapper->createGeoRSSSitemap ( $this->getConf('media_georss') ); |
|
| 68 | + $sitemapper = plugin_load('helper', 'spatialhelper_sitemap'); |
|
| 69 | + $sitemapper->createKMLSitemap($this->getConf('media_kml')); |
|
| 70 | + $sitemapper->createGeoRSSSitemap($this->getConf('media_georss')); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,17 +76,17 @@ discard block |
||
| 76 | 76 | * @see DokuWiki_Admin_Plugin::html() |
| 77 | 77 | */ |
| 78 | 78 | public function html() { |
| 79 | - echo $this->locale_xhtml ( 'admin_purge_intro' ); |
|
| 79 | + echo $this->locale_xhtml('admin_purge_intro'); |
|
| 80 | 80 | |
| 81 | - $form = new Doku_Form ( array ( |
|
| 81 | + $form = new Doku_Form(array( |
|
| 82 | 82 | 'id' => 'spatialhelper__purgeform', |
| 83 | 83 | 'method' => 'post' |
| 84 | - ) ); |
|
| 85 | - $form->addHidden ( 'purgeindex', 'true' ); |
|
| 84 | + )); |
|
| 85 | + $form->addHidden('purgeindex', 'true'); |
|
| 86 | 86 | |
| 87 | - $form->addElement ( form_makeButton ( 'submit', 'admin', $this->getLang ( 'admin_submit' ), array ( |
|
| 88 | - 'title' => $this->getLang ( 'admin_submit' ) |
|
| 89 | - ) ) ); |
|
| 90 | - $form->printForm (); |
|
| 87 | + $form->addElement(form_makeButton('submit', 'admin', $this->getLang('admin_submit'), array( |
|
| 88 | + 'title' => $this->getLang('admin_submit') |
|
| 89 | + ))); |
|
| 90 | + $form->printForm(); |
|
| 91 | 91 | } |
| 92 | 92 | } |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | 16 | */ |
| 17 | -if (! defined ( 'DOKU_INC' )) |
|
| 17 | +if (!defined('DOKU_INC')) |
|
| 18 | 18 | die (); |
| 19 | -if (! defined ( 'DOKU_PLUGIN' )) |
|
| 20 | - define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' ); |
|
| 19 | +if (!defined('DOKU_PLUGIN')) |
|
| 20 | + define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * DokuWiki Plugin spatialhelper (Search component). |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @var array |
| 33 | 33 | */ |
| 34 | - protected $spatial_idx = array (); |
|
| 34 | + protected $spatial_idx = array(); |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Precision, Distance of Adjacent Cell in Meters. |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @var float |
| 42 | 42 | */ |
| 43 | - private $precision = array ( |
|
| 43 | + private $precision = array( |
|
| 44 | 44 | 5003530, |
| 45 | 45 | 625441, |
| 46 | 46 | 123264, |
@@ -65,18 +65,18 @@ discard block |
||
| 65 | 65 | // parent::__construct (); |
| 66 | 66 | global $conf; |
| 67 | 67 | |
| 68 | - if (! $geophp = &plugin_load ( 'helper', 'geophp' )) { |
|
| 68 | + if (!$geophp = &plugin_load('helper', 'geophp')) { |
|
| 69 | 69 | $message = 'helper_plugin_spatialhelper_search::spatialhelper_search: geophp plugin is not available.'; |
| 70 | - msg ( $message, - 1 ); |
|
| 70 | + msg($message, - 1); |
|
| 71 | 71 | return ""; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $idx_dir = $conf ['indexdir']; |
| 75 | - if (! @file_exists ( $idx_dir . '/spatial.idx' )) { |
|
| 76 | - $indexer = plugin_load ( 'helper', 'spatialhelper_index' ); |
|
| 75 | + if (!@file_exists($idx_dir . '/spatial.idx')) { |
|
| 76 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $this->spatial_idx = unserialize ( io_readFile ( $fn = $idx_dir . '/spatial.idx', false ) ); |
|
| 79 | + $this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false)); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | * The x coordinate (or longitude) |
| 89 | 89 | */ |
| 90 | 90 | function findNearbyLatLon($lat, $lon) { |
| 91 | - $geometry = new Point ( $lon, $lat ); |
|
| 92 | - return $this->findNearby ( $geometry->out ( 'geohash' ), $geometry ); |
|
| 91 | + $geometry = new Point($lon, $lat); |
|
| 92 | + return $this->findNearby($geometry->out('geohash'), $geometry); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -102,76 +102,76 @@ discard block |
||
| 102 | 102 | * @return array of ... |
| 103 | 103 | */ |
| 104 | 104 | function findNearby($geohash, Point $p = null) { |
| 105 | - $_geohashClass = new Geohash (); |
|
| 106 | - if (! $p) { |
|
| 107 | - $decodedPoint = $_geohashClass->read ( $geohash ); |
|
| 105 | + $_geohashClass = new Geohash(); |
|
| 106 | + if (!$p) { |
|
| 107 | + $decodedPoint = $_geohashClass->read($geohash); |
|
| 108 | 108 | } else { |
| 109 | 109 | $decodedPoint = $p; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // find adjacent blocks |
| 113 | - $adjacent = array (); |
|
| 113 | + $adjacent = array(); |
|
| 114 | 114 | $adjacent ['center'] = $geohash; |
| 115 | - $adjacent ['top'] = $_geohashClass->adjacent ( $adjacent ['center'], 'top' ); |
|
| 116 | - $adjacent ['bottom'] = $_geohashClass->adjacent ( $adjacent ['center'], 'bottom' ); |
|
| 117 | - $adjacent ['right'] = $_geohashClass->adjacent ( $adjacent ['center'], 'right' ); |
|
| 118 | - $adjacent ['left'] = $_geohashClass->adjacent ( $adjacent ['center'], 'left' ); |
|
| 119 | - $adjacent ['topleft'] = $_geohashClass->adjacent ( $adjacent ['left'], 'top' ); |
|
| 120 | - $adjacent ['topright'] = $_geohashClass->adjacent ( $adjacent ['right'], 'top' ); |
|
| 121 | - $adjacent ['bottomright'] = $_geohashClass->adjacent ( $adjacent ['right'], 'bottom' ); |
|
| 122 | - $adjacent ['bottomleft'] = $_geohashClass->adjacent ( $adjacent ['left'], 'bottom' ); |
|
| 115 | + $adjacent ['top'] = $_geohashClass->adjacent($adjacent ['center'], 'top'); |
|
| 116 | + $adjacent ['bottom'] = $_geohashClass->adjacent($adjacent ['center'], 'bottom'); |
|
| 117 | + $adjacent ['right'] = $_geohashClass->adjacent($adjacent ['center'], 'right'); |
|
| 118 | + $adjacent ['left'] = $_geohashClass->adjacent($adjacent ['center'], 'left'); |
|
| 119 | + $adjacent ['topleft'] = $_geohashClass->adjacent($adjacent ['left'], 'top'); |
|
| 120 | + $adjacent ['topright'] = $_geohashClass->adjacent($adjacent ['right'], 'top'); |
|
| 121 | + $adjacent ['bottomright'] = $_geohashClass->adjacent($adjacent ['right'], 'bottom'); |
|
| 122 | + $adjacent ['bottomleft'] = $_geohashClass->adjacent($adjacent ['left'], 'bottom'); |
|
| 123 | 123 | // dbglog ( $adjacent, "adjacent geo hashes:" ); |
| 124 | 124 | |
| 125 | 125 | // find all the pages in the index that overlap with the adjacent hashes |
| 126 | - $docIds = array (); |
|
| 127 | - foreach ( $adjacent as $adjHash ) { |
|
| 128 | - if (is_array ( $this->spatial_idx )) { |
|
| 129 | - foreach ( $this->spatial_idx as $_geohash => $_docIds ) { |
|
| 130 | - if (strstr ( $_geohash, $adjHash )) { |
|
| 126 | + $docIds = array(); |
|
| 127 | + foreach ($adjacent as $adjHash) { |
|
| 128 | + if (is_array($this->spatial_idx)) { |
|
| 129 | + foreach ($this->spatial_idx as $_geohash => $_docIds) { |
|
| 130 | + if (strstr($_geohash, $adjHash)) { |
|
| 131 | 131 | // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
| 132 | 132 | // if $adjHash similar to geohash |
| 133 | - $docIds = array_merge ( $docIds, $_docIds ); |
|
| 133 | + $docIds = array_merge($docIds, $_docIds); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | - $docIds = array_unique ( $docIds ); |
|
| 138 | + $docIds = array_unique($docIds); |
|
| 139 | 139 | // dbglog ( $docIds, "found docIDs" ); |
| 140 | 140 | |
| 141 | 141 | // create associative array of pages + calculate distance |
| 142 | - $pages = array (); |
|
| 143 | - $media = array (); |
|
| 144 | - $indexer = plugin_load ( 'helper', 'spatialhelper_index' ); |
|
| 142 | + $pages = array(); |
|
| 143 | + $media = array(); |
|
| 144 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
| 145 | 145 | |
| 146 | - foreach ( $docIds as $id ) { |
|
| 147 | - if (strpos ( $id, 'media__', 0 ) === 0) { |
|
| 148 | - $id = substr ( $id, strlen ( 'media__' ) ); |
|
| 149 | - if (auth_quickaclcheck ( $id ) >= /*AUTH_READ*/1) { |
|
| 150 | - $point = $indexer->getCoordsFromExif ( $id ); |
|
| 151 | - $line = new LineString ( [ |
|
| 146 | + foreach ($docIds as $id) { |
|
| 147 | + if (strpos($id, 'media__', 0) === 0) { |
|
| 148 | + $id = substr($id, strlen('media__')); |
|
| 149 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/1) { |
|
| 150 | + $point = $indexer->getCoordsFromExif($id); |
|
| 151 | + $line = new LineString([ |
|
| 152 | 152 | $decodedPoint, |
| 153 | 153 | $point |
| 154 | - ] ); |
|
| 155 | - $media [] = array ( |
|
| 154 | + ]); |
|
| 155 | + $media [] = array( |
|
| 156 | 156 | 'id' => $id, |
| 157 | - 'distance' => ( int ) ($line->greatCircleLength ()), |
|
| 158 | - 'lat' => $point->y (), |
|
| 159 | - 'lon' => $point->x () |
|
| 157 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
| 158 | + 'lat' => $point->y(), |
|
| 159 | + 'lon' => $point->x() |
|
| 160 | 160 | // optionally add other meta such as tag, description... |
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | 163 | } else { |
| 164 | - if (auth_quickaclcheck ( $id ) >= /*AUTH_READ*/1) { |
|
| 165 | - $geotags = p_get_metadata ( $id, 'geo' ); |
|
| 166 | - $point = new Point ( $geotags ['lon'], $geotags ['lat'] ); |
|
| 167 | - $line = new LineString ( [ |
|
| 164 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/1) { |
|
| 165 | + $geotags = p_get_metadata($id, 'geo'); |
|
| 166 | + $point = new Point($geotags ['lon'], $geotags ['lat']); |
|
| 167 | + $line = new LineString([ |
|
| 168 | 168 | $decodedPoint, |
| 169 | 169 | $point |
| 170 | - ] ); |
|
| 171 | - $pages [] = array ( |
|
| 170 | + ]); |
|
| 171 | + $pages [] = array( |
|
| 172 | 172 | 'id' => $id, |
| 173 | - 'distance' => ( int ) ($line->greatCircleLength ()), |
|
| 174 | - 'description' => p_get_metadata ( $id, 'description' )['abstract'], |
|
| 173 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
| 174 | + 'description' => p_get_metadata($id, 'description')['abstract'], |
|
| 175 | 175 | 'lat' => $geotags ['lat'], |
| 176 | 176 | 'lon' => $geotags ['lon'] |
| 177 | 177 | // optionally add other meta such as tag... |
@@ -181,20 +181,20 @@ discard block |
||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // sort all the pages/media using distance |
| 184 | - usort ( $pages, function ($a, $b) { |
|
| 185 | - return strnatcmp ( $a ['distance'], $b ['distance'] ); |
|
| 184 | + usort($pages, function($a, $b) { |
|
| 185 | + return strnatcmp($a ['distance'], $b ['distance']); |
|
| 186 | 186 | } ); |
| 187 | - usort ( $media, function ($a, $b) { |
|
| 188 | - return strnatcmp ( $a ['distance'], $b ['distance'] ); |
|
| 187 | + usort($media, function($a, $b) { |
|
| 188 | + return strnatcmp($a ['distance'], $b ['distance']); |
|
| 189 | 189 | } ); |
| 190 | 190 | |
| 191 | - return array ( |
|
| 191 | + return array( |
|
| 192 | 192 | 'pages' => $pages, |
| 193 | 193 | 'media' => $media, |
| 194 | - 'lat' => $decodedPoint->y (), |
|
| 195 | - 'lon' => $decodedPoint->x (), |
|
| 194 | + 'lat' => $decodedPoint->y(), |
|
| 195 | + 'lon' => $decodedPoint->x(), |
|
| 196 | 196 | 'geohash' => $geohash, |
| 197 | - 'precision' => $this->precision [strlen ( $geohash )] |
|
| 197 | + 'precision' => $this->precision [strlen($geohash)] |
|
| 198 | 198 | ); |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | \ No newline at end of file |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | 16 | */ |
| 17 | -if (! defined('DOKU_INC')) |
|
| 17 | +if (!defined('DOKU_INC')) |
|
| 18 | 18 | die (); |
| 19 | -if (! defined('DOKU_PLUGIN')) |
|
| 19 | +if (!defined('DOKU_PLUGIN')) |
|
| 20 | 20 | define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); |
| 21 | -if (! defined('DOKU_LF')) |
|
| 21 | +if (!defined('DOKU_LF')) |
|
| 22 | 22 | define('DOKU_LF', "\n"); |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * spatial index. |
| 33 | 33 | */ |
| 34 | - var $spatial_idx = array (); |
|
| 34 | + var $spatial_idx = array(); |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * constructor, load spatial index. |
@@ -42,29 +42,29 @@ discard block |
||
| 42 | 42 | $idx_dir = $conf['indexdir']; |
| 43 | 43 | if (!@file_exists($idx_dir . '/spatial.idx')) { |
| 44 | 44 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
| 45 | - $indexer->generateSpatialIndex (); |
|
| 45 | + $indexer->generateSpatialIndex(); |
|
| 46 | 46 | } |
| 47 | 47 | $this->spatial_idx = unserialize(io_readFile($fn = $idx_dir . '/spatial.idx', false)); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function getMethods() { |
| 51 | - $result[] = array ( |
|
| 51 | + $result[] = array( |
|
| 52 | 52 | 'name' => 'createGeoRSSSitemap', |
| 53 | 53 | 'desc' => 'create a spatial sitemap in GeoRSS format.', |
| 54 | - 'params' => array ( |
|
| 54 | + 'params' => array( |
|
| 55 | 55 | 'path' => 'string' |
| 56 | 56 | ), |
| 57 | - 'return' => array ( |
|
| 57 | + 'return' => array( |
|
| 58 | 58 | 'success' => 'boolean' |
| 59 | 59 | ) |
| 60 | 60 | ); |
| 61 | - $result[] = array ( |
|
| 61 | + $result[] = array( |
|
| 62 | 62 | 'name' => 'createKMLSitemap', |
| 63 | 63 | 'desc' => 'create a spatial sitemap in KML format.', |
| 64 | - 'params' => array ( |
|
| 64 | + 'params' => array( |
|
| 65 | 65 | 'path' => 'string' |
| 66 | 66 | ), |
| 67 | - 'return' => array ( |
|
| 67 | + 'return' => array( |
|
| 68 | 68 | 'success' => 'boolean' |
| 69 | 69 | ) |
| 70 | 70 | ); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $RSSstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; |
| 86 | 86 | $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF; |
| 87 | 87 | $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF; |
| 88 | - if (! empty($conf['tagline'])) { |
|
| 88 | + if (!empty($conf['tagline'])) { |
|
| 89 | 89 | $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF; |
| 90 | 90 | } |
| 91 | 91 | $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF; |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | $fh = fopen(mediaFN($mediaID), 'w'); |
| 104 | 104 | fwrite($fh, $RSSstart); |
| 105 | 105 | |
| 106 | - foreach($this->spatial_idx as $idxEntry) { |
|
| 106 | + foreach ($this->spatial_idx as $idxEntry) { |
|
| 107 | 107 | // get list of id's |
| 108 | - foreach($idxEntry as $id) { |
|
| 108 | + foreach ($idxEntry as $id) { |
|
| 109 | 109 | // for document item in the index |
| 110 | 110 | if (strpos($id, 'media__', 0) !== 0) { |
| 111 | 111 | // public and non-hidden pages only |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | $fh = fopen(mediaFN($mediaID), 'w'); |
| 173 | 173 | fwrite($fh, $KMLstart); |
| 174 | 174 | |
| 175 | - foreach($this->spatial_idx as $idxEntry) { |
|
| 175 | + foreach ($this->spatial_idx as $idxEntry) { |
|
| 176 | 176 | // get list of id's |
| 177 | - foreach($idxEntry as $id) { |
|
| 177 | + foreach ($idxEntry as $id) { |
|
| 178 | 178 | // for document item in the index |
| 179 | 179 | if (strpos($id, 'media__', 0) !== 0) { |
| 180 | 180 | // public and non-hidden pages only |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $plcm .= ' <name>' . $meta['title'] . '</name>' . DOKU_LF; |
| 195 | 195 | // TODO escape quotes in: title="' . $meta['title'] . '" |
| 196 | 196 | $plcm .= ' <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' . DOKU_LF; |
| 197 | - if (! empty($meta['creator'])) { |
|
| 197 | + if (!empty($meta['creator'])) { |
|
| 198 | 198 | $entry .= ' <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' . DOKU_LF; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | 16 | */ |
| 17 | -if (! defined ( 'DOKU_INC' )) |
|
| 17 | +if (!defined('DOKU_INC'))
|
|
| 18 | 18 | die (); |
| 19 | -if (! defined ( 'DOKU_PLUGIN' )) |
|
| 20 | - define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' ); |
|
| 19 | +if (!defined('DOKU_PLUGIN'))
|
|
| 20 | + define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
|
|
| 21 | 21 | require_once (DOKU_PLUGIN . 'syntax.php'); |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @see Doku_Parser_Mode::connectTo() |
| 59 | 59 | */ |
| 60 | 60 | public function connectTo($mode) {
|
| 61 | - $this->Lexer->addSpecialPattern ( '\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby' );
|
|
| 61 | + $this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby');
|
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,21 +67,21 @@ discard block |
||
| 67 | 67 | * @see DokuWiki_Syntax_Plugin::handle() |
| 68 | 68 | */ |
| 69 | 69 | public function handle($match, $state, $pos, Doku_Handler $handler) {
|
| 70 | - $data = array (); |
|
| 71 | - $data [0] = trim ( substr ( $match, strlen ( '{{findnearby>' ), - 2 ) );
|
|
| 72 | - if (strlen ( $data [0]) < 1 ) {
|
|
| 73 | - $data [0] = $this->getLang ( 'search_findnearby' ); |
|
| 70 | + $data = array(); |
|
| 71 | + $data [0] = trim(substr($match, strlen('{{findnearby>'), - 2));
|
|
| 72 | + if (strlen($data [0]) < 1) {
|
|
| 73 | + $data [0] = $this->getLang('search_findnearby');
|
|
| 74 | 74 | } |
| 75 | - $meta = p_get_metadata ( getID (), 'geo' ); |
|
| 75 | + $meta = p_get_metadata(getID(), 'geo'); |
|
| 76 | 76 | if ($meta) {
|
| 77 | 77 | if ($meta ['lat'] && $meta ['lon']) {
|
| 78 | - $data [1] = array ( |
|
| 78 | + $data [1] = array( |
|
| 79 | 79 | 'do' => 'findnearby', |
| 80 | 80 | 'lat' => $meta ['lat'], |
| 81 | 81 | 'lon' => $meta ['lon'] |
| 82 | 82 | ); |
| 83 | 83 | } elseif ($meta ['geohash']) {
|
| 84 | - $data [1] = array ( |
|
| 84 | + $data [1] = array( |
|
| 85 | 85 | 'do' => 'findnearby', |
| 86 | 86 | 'geohash' => $meta ['geohash'] |
| 87 | 87 | ); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | return false; |
| 102 | 102 | |
| 103 | 103 | if ($mode == 'xhtml') {
|
| 104 | - $renderer->doc .= '<a href="' . wl ( getID (), $data [1] ) . '" class="findnearby">' . hsc( $data [0] ) . '</a>'; |
|
| 104 | + $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>'; |
|
| 105 | 105 | return true; |
| 106 | 106 | // } elseif ($mode == 'metadata') {
|
| 107 | 107 | } elseif ($mode == 'odt') {
|
@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | 16 | */ |
| 17 | -if (! defined ( 'DOKU_INC' )) |
|
| 17 | +if (!defined('DOKU_INC'))
|
|
| 18 | 18 | die (); |
| 19 | -if (! defined ( 'DOKU_PLUGIN' )) |
|
| 20 | - define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' ); |
|
| 21 | -if (! defined ( 'DOKU_LF' )) |
|
| 22 | - define ( 'DOKU_LF', "\n" ); |
|
| 19 | +if (!defined('DOKU_PLUGIN'))
|
|
| 20 | + define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
|
|
| 21 | +if (!defined('DOKU_LF'))
|
|
| 22 | + define('DOKU_LF', "\n");
|
|
| 23 | 23 | require_once (DOKU_PLUGIN . 'action.php'); |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -39,30 +39,30 @@ discard block |
||
| 39 | 39 | public function register(Doku_Event_Handler $controller) {
|
| 40 | 40 | // listen for page add / delete events |
| 41 | 41 | // http://www.dokuwiki.org/devel:event:indexer_page_add |
| 42 | - $controller->register_hook ( 'INDEXER_PAGE_ADD', 'BEFORE', $this, 'handle_indexer_page_add' ); |
|
| 43 | - $controller->register_hook ( 'IO_WIKIPAGE_WRITE', 'BEFORE', $this, '_removeFromIndex' ); |
|
| 42 | + $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handle_indexer_page_add');
|
|
| 43 | + $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, '_removeFromIndex');
|
|
| 44 | 44 | |
| 45 | 45 | // http://www.dokuwiki.org/devel:event:sitemap_generate |
| 46 | - $controller->register_hook ( 'SITEMAP_GENERATE', 'BEFORE', $this, 'handle_sitemap_generate_before' ); |
|
| 46 | + $controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'handle_sitemap_generate_before');
|
|
| 47 | 47 | // using after will only trigger us if a sitemap was actually created |
| 48 | - $controller->register_hook ( 'SITEMAP_GENERATE', 'AFTER', $this, 'handle_sitemap_generate_after' ); |
|
| 48 | + $controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handle_sitemap_generate_after');
|
|
| 49 | 49 | |
| 50 | 50 | // handle actions we know of |
| 51 | - $controller->register_hook ( 'ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action_act_preprocess', array () ); |
|
| 51 | + $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action_act_preprocess', array());
|
|
| 52 | 52 | // handle HTML eg. /dokuwiki/doku.php?id=start&do=findnearby&geohash=u15vk4 |
| 53 | - $controller->register_hook ( 'TPL_ACT_UNKNOWN', 'BEFORE', $this, '_findnearby', array ( |
|
| 53 | + $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, '_findnearby', array(
|
|
| 54 | 54 | 'format' => 'HTML' |
| 55 | - ) ); |
|
| 55 | + )); |
|
| 56 | 56 | // handles AJAX/json eg: jQuery.post("/dokuwiki/lib/exe/ajax.php?id=start&call=findnearby&geohash=u15vk4");
|
| 57 | - $controller->register_hook ( 'AJAX_CALL_UNKNOWN', 'BEFORE', $this, '_findnearby', array ( |
|
| 57 | + $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, '_findnearby', array(
|
|
| 58 | 58 | 'format' => 'JSON' |
| 59 | - ) ); |
|
| 59 | + )); |
|
| 60 | 60 | |
| 61 | 61 | // listen for media uploads and deletes |
| 62 | - $controller->register_hook ( 'MEDIA_UPLOAD_FINISH', 'BEFORE', $this, '_handle_media_uploaded', array () ); |
|
| 63 | - $controller->register_hook ( 'MEDIA_DELETE_FILE', 'BEFORE', $this, '_handle_media_deleted', array () ); |
|
| 62 | + $controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, '_handle_media_uploaded', array());
|
|
| 63 | + $controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, '_handle_media_deleted', array());
|
|
| 64 | 64 | |
| 65 | - $controller->register_hook ( 'TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_metaheader_output' ); |
|
| 65 | + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_metaheader_output');
|
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | // $event→data['body'] – empty, can be filled by additional content to index by your plugin |
| 79 | 79 | // $event→data['metadata'] – the metadata that shall be indexed. This is an array where the keys are the metadata indexes and the value a string or an array of strings with the values. title and relation_references will already be set. |
| 80 | 80 | $id = $event->data ['page']; |
| 81 | - $indexer = & plugin_load ( 'helper', 'spatialhelper_index' ); |
|
| 82 | - $entries = $indexer->updateSpatialIndex ( $id ); |
|
| 81 | + $indexer = & plugin_load('helper', 'spatialhelper_index');
|
|
| 82 | + $entries = $indexer->updateSpatialIndex($id); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param object $param |
| 91 | 91 | * the parameters passed to register_hook when this handler was registered |
| 92 | 92 | */ |
| 93 | - function _removeFromIndex(Doku_Event &$event, $param) {
|
|
| 93 | + function _removeFromIndex(Doku_Event & $event, $param) {
|
|
| 94 | 94 | // event data: |
| 95 | 95 | // $data[0] – The raw arguments for io_saveFile as an array. Do not change file path. |
| 96 | 96 | // $data[0][0] – the file path. |
@@ -100,19 +100,19 @@ discard block |
||
| 100 | 100 | // $data[3] – rev: The page revision, false for current wiki pages. |
| 101 | 101 | |
| 102 | 102 | // dbglog ( $event->data, "Event data in _removeFromIndex." ); |
| 103 | - if (@file_exists ( $event->data [0] [0] )) {
|
|
| 103 | + if (@file_exists($event->data [0] [0])) {
|
|
| 104 | 104 | // file not new |
| 105 | - if (! $event->data [0] [1]) {
|
|
| 105 | + if (!$event->data [0] [1]) {
|
|
| 106 | 106 | // file is empty, page is being deleted |
| 107 | - if (empty ( $event->data [1] )) {
|
|
| 107 | + if (empty ($event->data [1])) {
|
|
| 108 | 108 | // root namespace |
| 109 | 109 | $id = $event->data [2]; |
| 110 | 110 | } else {
|
| 111 | 111 | $id = $event->data [1] . ":" . $event->data [2]; |
| 112 | 112 | } |
| 113 | - $indexer = & plugin_load ( 'helper', 'spatialhelper_index' ); |
|
| 113 | + $indexer = & plugin_load('helper', 'spatialhelper_index');
|
|
| 114 | 114 | if ($indexer) {
|
| 115 | - $indexer->deleteFromIndex ( $id ); |
|
| 115 | + $indexer->deleteFromIndex($id); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | * @param unknown $param |
| 126 | 126 | */ |
| 127 | 127 | function handle_sitemap_generate_before(Doku_Event $event, $param) {
|
| 128 | - $path = mediaFN ( $this->getConf ( 'media_kml' ) ); |
|
| 129 | - $lastmod = @filemtime ( $path ); |
|
| 130 | - $event->data ['items'] [] = new SitemapItem ( ml ( $this->getConf ( 'media_kml' ), '', true, '&', true ), $lastmod ); |
|
| 128 | + $path = mediaFN($this->getConf('media_kml'));
|
|
| 129 | + $lastmod = @filemtime($path); |
|
| 130 | + $event->data ['items'] [] = new SitemapItem(ml($this->getConf('media_kml'), '', true, '&', true), $lastmod);
|
|
| 131 | 131 | // dbglog ( $event->data ['items'], "Added a new SitemapItem object that points to the KML of public geocoded pages." ); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | // $event→data['sitemap']: The path of the file the sitemap will be saved to. |
| 145 | 145 | |
| 146 | 146 | // dbglog ($event->data['items'], "createSpatialSitemap loading helper" ); |
| 147 | - if ($helper = & plugin_load ( 'helper', 'spatialhelper_sitemap' )) {
|
|
| 147 | + if ($helper = & plugin_load('helper', 'spatialhelper_sitemap')) {
|
|
| 148 | 148 | // dbglog ( $helper, "createSpatialSitemap loaded helper." ); |
| 149 | 149 | |
| 150 | - $kml = $helper->createKMLSitemap ( $this->getConf ( 'media_kml' ) ); |
|
| 151 | - $rss = $helper->createGeoRSSSitemap ( $this->getConf ( 'media_georss' ) ); |
|
| 150 | + $kml = $helper->createKMLSitemap($this->getConf('media_kml'));
|
|
| 151 | + $rss = $helper->createGeoRSSSitemap($this->getConf('media_georss'));
|
|
| 152 | 152 | |
| 153 | 153 | return $kml && $rss; |
| 154 | 154 | } else {
|
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | function handle_action_act_preprocess(Doku_Event $event, $param) {
|
| 169 | 169 | if ($event->data != 'findnearby') |
| 170 | 170 | return; |
| 171 | - $event->preventDefault (); |
|
| 171 | + $event->preventDefault(); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -180,34 +180,34 @@ discard block |
||
| 180 | 180 | * associative array with keys |
| 181 | 181 | * 'format'=> HTML | JSON |
| 182 | 182 | */ |
| 183 | - function _findnearby(Doku_Event &$event, $param) {
|
|
| 183 | + function _findnearby(Doku_Event & $event, $param) {
|
|
| 184 | 184 | if ($event->data != 'findnearby') |
| 185 | 185 | return; |
| 186 | - $event->preventDefault (); |
|
| 186 | + $event->preventDefault(); |
|
| 187 | 187 | |
| 188 | 188 | global $INPUT; |
| 189 | - if ($helper = & plugin_load ( 'helper', 'spatialhelper_search' )) {
|
|
| 190 | - if ($INPUT->has ( 'lat' ) && $INPUT->has ( 'lon' )) {
|
|
| 191 | - $results = $helper->findNearbyLatLon ( $INPUT->param ( 'lat' ), $INPUT->param ( 'lon' ) ); |
|
| 192 | - } elseif ($INPUT->has ( 'geohash' )) {
|
|
| 193 | - $results = $helper->findNearby ( $INPUT->str ( 'geohash' ) ); |
|
| 189 | + if ($helper = & plugin_load('helper', 'spatialhelper_search')) {
|
|
| 190 | + if ($INPUT->has('lat') && $INPUT->has('lon')) {
|
|
| 191 | + $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon'));
|
|
| 192 | + } elseif ($INPUT->has('geohash')) {
|
|
| 193 | + $results = $helper->findNearby($INPUT->str('geohash'));
|
|
| 194 | 194 | } else {
|
| 195 | - $results = array ( |
|
| 196 | - 'error' => hsc ( $this->getLang ( 'invalidinput' ) ) |
|
| 195 | + $results = array( |
|
| 196 | + 'error' => hsc($this->getLang('invalidinput'))
|
|
| 197 | 197 | ); |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - $showMedia = $INPUT->bool ( 'showMedia', true ); |
|
| 201 | + $showMedia = $INPUT->bool('showMedia', true);
|
|
| 202 | 202 | |
| 203 | - switch ( $param[ 'format' ] ) {
|
|
| 203 | + switch ($param['format']) {
|
|
| 204 | 204 | case 'JSON' : |
| 205 | - $this->printJSON ( $results ); |
|
| 205 | + $this->printJSON($results); |
|
| 206 | 206 | break; |
| 207 | 207 | case 'HTML' : |
| 208 | 208 | // fall through to default |
| 209 | 209 | default : |
| 210 | - $this->printHTML ( $results, $showMedia ); |
|
| 210 | + $this->printHTML($results, $showMedia); |
|
| 211 | 211 | break; |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -219,9 +219,9 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | private function printJSON($searchresults) {
|
| 221 | 221 | require_once DOKU_INC . 'inc/JSON.php'; |
| 222 | - $json = new JSON (); |
|
| 223 | - header ( 'Content-Type: application/json' ); |
|
| 224 | - print $json->encode ( $searchresults ); |
|
| 222 | + $json = new JSON(); |
|
| 223 | + header('Content-Type: application/json');
|
|
| 224 | + print $json->encode($searchresults); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -237,52 +237,52 @@ discard block |
||
| 237 | 237 | $lon = ( float ) $searchresults ['lon']; |
| 238 | 238 | $geohash = ( string ) $searchresults ['geohash']; |
| 239 | 239 | |
| 240 | - if (isset ( $searchresults ['error'] )) {
|
|
| 241 | - print '<div class="level1"><p>' . hsc ( $results ['error'] ) . '</p></div>'; |
|
| 240 | + if (isset ($searchresults ['error'])) {
|
|
| 241 | + print '<div class="level1"><p>' . hsc($results ['error']) . '</p></div>'; |
|
| 242 | 242 | return; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // print a HTML list |
| 246 | - print '<h1>' . $this->getLang ( 'results_header' ) . '</h1>' . DOKU_LF; |
|
| 246 | + print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF;
|
|
| 247 | 247 | print '<div class="level1">' . DOKU_LF; |
| 248 | - if (! empty ( $pages )) {
|
|
| 248 | + if (!empty ($pages)) {
|
|
| 249 | 249 | $pagelist = '<ol>' . DOKU_LF; |
| 250 | - foreach ( $pages as $page ) {
|
|
| 251 | - $pagelist .= '<li>' . html_wikilink ( ':' . $page ['id'], useHeading ( 'navigation' ) ? null : noNS ( $page ['id'] ) ) . ' (' . $this->getLang ( 'results_distance_prefix' ) . $page ['distance'] . ' m) ' . $page ['description'] . '</li>' . DOKU_LF;
|
|
| 250 | + foreach ($pages as $page) {
|
|
| 251 | + $pagelist .= '<li>' . html_wikilink(':' . $page ['id'], useHeading('navigation') ? null : noNS($page ['id'])) . ' (' . $this->getLang('results_distance_prefix') . $page ['distance'] . ' m) ' . $page ['description'] . '</li>' . DOKU_LF;
|
|
| 252 | 252 | } |
| 253 | 253 | $pagelist .= '</ol>' . DOKU_LF; |
| 254 | 254 | |
| 255 | - print '<h2>' . $this->getLang ( 'results_pages' ) . hsc ( ' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')' ) . '</h2>'; |
|
| 255 | + print '<h2>' . $this->getLang('results_pages') . hsc(' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')') . '</h2>';
|
|
| 256 | 256 | print '<div class="level2">' . DOKU_LF; |
| 257 | 257 | print $pagelist; |
| 258 | 258 | print '</div>' . DOKU_LF; |
| 259 | 259 | } else {
|
| 260 | - print '<p>' . hsc ( $this->getLang ( 'nothingfound' ) ) . '</p>'; |
|
| 260 | + print '<p>' . hsc($this->getLang('nothingfound')) . '</p>';
|
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if (! empty ( $media ) && $showMedia) {
|
|
| 263 | + if (!empty ($media) && $showMedia) {
|
|
| 264 | 264 | $pagelist = '<ol>' . DOKU_LF; |
| 265 | - foreach ( $media as $m ) {
|
|
| 266 | - $opts = array (); |
|
| 267 | - $link = ml ( $m ['id'], $opts, false, '&', false ); |
|
| 265 | + foreach ($media as $m) {
|
|
| 266 | + $opts = array(); |
|
| 267 | + $link = ml($m ['id'], $opts, false, '&', false); |
|
| 268 | 268 | $opts ['w'] = '100'; |
| 269 | - $src = ml ( $m ['id'], $opts ); |
|
| 270 | - $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' . $this->getLang ( 'results_distance_prefix' ) . $page ['distance'] . ' m) ' . hsc ( $desc ) . '</li>' . DOKU_LF;
|
|
| 269 | + $src = ml($m ['id'], $opts); |
|
| 270 | + $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' . $this->getLang('results_distance_prefix') . $page ['distance'] . ' m) ' . hsc($desc) . '</li>' . DOKU_LF;
|
|
| 271 | 271 | } |
| 272 | 272 | $pagelist .= '</ol>' . DOKU_LF; |
| 273 | 273 | |
| 274 | - print '<h2>' . $this->getLang ( 'results_media' ) . hsc ( ' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')' ) . '</h2>' . DOKU_LF; |
|
| 274 | + print '<h2>' . $this->getLang('results_media') . hsc(' lat;lon: ' . $lat . ';' . $lon . ' (geohash: ' . $geohash . ')') . '</h2>' . DOKU_LF;
|
|
| 275 | 275 | print '<div class="level2">' . DOKU_LF; |
| 276 | 276 | print $pagelist; |
| 277 | 277 | print '</div>' . DOKU_LF; |
| 278 | 278 | } |
| 279 | - print '<p>' . $this->getLang ( 'results_precision' ) . $searchresults ['precision'] . ' m. '; |
|
| 280 | - if (strlen ( $geohash ) > 1) {
|
|
| 281 | - $url = wl ( getID (), array ( |
|
| 279 | + print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. ';
|
|
| 280 | + if (strlen($geohash) > 1) {
|
|
| 281 | + $url = wl(getID(), array( |
|
| 282 | 282 | 'do' => 'findnearby', |
| 283 | - 'geohash' => substr ( $geohash, 0, - 1 ) |
|
| 284 | - ) ); |
|
| 285 | - print '<a href="' . $url . '" class="findnearby">' . $this->getLang ( 'search_largerarea' ) . '</a>.</p>' . DOKU_LF; |
|
| 283 | + 'geohash' => substr($geohash, 0, - 1) |
|
| 284 | + )); |
|
| 285 | + print '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>' . DOKU_LF;
|
|
| 286 | 286 | } |
| 287 | 287 | print '</div>' . DOKU_LF; |
| 288 | 288 | } |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * event object by reference |
| 295 | 295 | * @param unknown $param |
| 296 | 296 | */ |
| 297 | - function _handle_media_uploaded(Doku_Event &$event, $param) {
|
|
| 297 | + function _handle_media_uploaded(Doku_Event & $event, $param) {
|
|
| 298 | 298 | // data[0] temporary file name (read from $_FILES) |
| 299 | 299 | // data[1] file name of the file being uploaded |
| 300 | 300 | // data[2] future directory id of the file being uploaded |
@@ -306,10 +306,10 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | // check the list of mimetypes |
| 308 | 308 | // if it's a supported type call appropriate index function |
| 309 | - if (substr_compare ( $event->data [3], 'image/jpeg', 0 )) {
|
|
| 310 | - $indexer = plugin_load ( 'helper', 'spatialhelper_index' ); |
|
| 309 | + if (substr_compare($event->data [3], 'image/jpeg', 0)) {
|
|
| 310 | + $indexer = plugin_load('helper', 'spatialhelper_index');
|
|
| 311 | 311 | if ($indexer) {
|
| 312 | - $indexer->indexImage ( $event->data [2], $event->data [1] ); |
|
| 312 | + $indexer->indexImage($event->data [2], $event->data [1]); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | // TODO add image/tiff |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | /** |
| 320 | 320 | * removes the media from the index. |
| 321 | 321 | */ |
| 322 | - function _handle_media_deleted(Doku_Event &$event, $param) {
|
|
| 322 | + function _handle_media_deleted(Doku_Event & $event, $param) {
|
|
| 323 | 323 | // data['id'] ID data['unl'] unlink return code |
| 324 | 324 | // data['del'] Namespace directory unlink return code |
| 325 | 325 | // data['name'] file name data['path'] full path to the file |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | // dbglog ( $event->data, "_handle_media_deleted::event data" ); |
| 329 | 329 | |
| 330 | 330 | // remove the media id from the index |
| 331 | - $indexer = & plugin_load ( 'helper', 'spatialhelper_index' ); |
|
| 331 | + $indexer = & plugin_load('helper', 'spatialhelper_index');
|
|
| 332 | 332 | if ($indexer) {
|
| 333 | - $indexer->deleteFromIndex ( 'media__' . $event->data ['id'] ); |
|
| 333 | + $indexer->deleteFromIndex('media__' . $event->data ['id']);
|
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
@@ -346,16 +346,16 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | public function handle_metaheader_output(Doku_Event $event, $param) {
|
| 348 | 348 | // TODO maybe test for exist |
| 349 | - $event->data ["link"] [] = array ( |
|
| 349 | + $event->data ["link"] [] = array( |
|
| 350 | 350 | "type" => "application/atom+xml", |
| 351 | 351 | "rel" => "alternate", |
| 352 | - "href" => ml ( $this->getConf ( 'media_georss' ) ), |
|
| 352 | + "href" => ml($this->getConf('media_georss')),
|
|
| 353 | 353 | "title" => "Spatial ATOM Feed" |
| 354 | 354 | ); |
| 355 | - $event->data ["link"] [] = array ( |
|
| 355 | + $event->data ["link"] [] = array( |
|
| 356 | 356 | "type" => "application/vnd.google-earth.kml+xml", |
| 357 | 357 | "rel" => "alternate", |
| 358 | - "href" => ml ( $this->getConf ( 'media_kml' ) ), |
|
| 358 | + "href" => ml($this->getConf('media_kml')),
|
|
| 359 | 359 | "title" => "KML Sitemap" |
| 360 | 360 | ); |
| 361 | 361 | } |
@@ -371,25 +371,25 @@ discard block |
||
| 371 | 371 | * - bearing in degrees (compass direction) |
| 372 | 372 | */ |
| 373 | 373 | private function _geo_destination($start, $dist, $brng) {
|
| 374 | - $lat1 = _toRad ( $start [0] ); |
|
| 375 | - $lon1 = _toRad ( $start [1] ); |
|
| 374 | + $lat1 = _toRad($start [0]); |
|
| 375 | + $lon1 = _toRad($start [1]); |
|
| 376 | 376 | // http://en.wikipedia.org/wiki/Earth_radius |
| 377 | 377 | // average earth radius in km |
| 378 | 378 | $dist = $dist / 6371.01; |
| 379 | - $brng = _toRad ( $brng ); |
|
| 379 | + $brng = _toRad($brng); |
|
| 380 | 380 | |
| 381 | - $lon2 = $lon1 + atan2 ( sin ( $brng ) * sin ( $dist ) * cos ( $lat1 ), cos ( $dist ) - sin ( $lat1 ) * sin ( $lat2 ) ); |
|
| 382 | - $lon2 = fmod ( ($lon2 + 3 * pi ()), (2 * pi ()) ) - pi (); |
|
| 381 | + $lon2 = $lon1 + atan2(sin($brng) * sin($dist) * cos($lat1), cos($dist) - sin($lat1) * sin($lat2)); |
|
| 382 | + $lon2 = fmod(($lon2 + 3 * pi()), (2 * pi())) - pi(); |
|
| 383 | 383 | |
| 384 | - return array ( |
|
| 385 | - _toDeg ( $lat2 ), |
|
| 386 | - _toDeg ( $lon2 ) |
|
| 384 | + return array( |
|
| 385 | + _toDeg($lat2), |
|
| 386 | + _toDeg($lon2) |
|
| 387 | 387 | ); |
| 388 | 388 | } |
| 389 | 389 | private function _toRad($deg) {
|
| 390 | - return $deg * pi () / 180; |
|
| 390 | + return $deg * pi() / 180; |
|
| 391 | 391 | } |
| 392 | 392 | private function _toDeg($rad) {
|
| 393 | - return $rad * 180 / pi (); |
|
| 393 | + return $rad * 180 / pi(); |
|
| 394 | 394 | } |
| 395 | 395 | } |