@@ -22,95 +22,95 @@ |
||
22 | 22 | * @author Mark C. Prins <[email protected]> |
23 | 23 | */ |
24 | 24 | class syntax_plugin_spatialhelper_findnearby extends DokuWiki_Syntax_Plugin { |
25 | - /** |
|
26 | - * |
|
27 | - * @see DokuWiki_Syntax_Plugin::getType() |
|
28 | - */ |
|
29 | - public function getType(): string { |
|
30 | - return 'substition'; |
|
31 | - } |
|
25 | + /** |
|
26 | + * |
|
27 | + * @see DokuWiki_Syntax_Plugin::getType() |
|
28 | + */ |
|
29 | + public function getType(): string { |
|
30 | + return 'substition'; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Return 'normal' so this syntax can be rendered inline. |
|
35 | - * |
|
36 | - * @see DokuWiki_Syntax_Plugin::getPType() |
|
37 | - */ |
|
38 | - public function getPType(): string { |
|
39 | - return 'normal'; |
|
40 | - } |
|
33 | + /** |
|
34 | + * Return 'normal' so this syntax can be rendered inline. |
|
35 | + * |
|
36 | + * @see DokuWiki_Syntax_Plugin::getPType() |
|
37 | + */ |
|
38 | + public function getPType(): string { |
|
39 | + return 'normal'; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * |
|
44 | - * @see Doku_Parser_Mode::getSort() |
|
45 | - */ |
|
46 | - public function getSort(): int { |
|
47 | - return 307; |
|
48 | - } |
|
42 | + /** |
|
43 | + * |
|
44 | + * @see Doku_Parser_Mode::getSort() |
|
45 | + */ |
|
46 | + public function getSort(): int { |
|
47 | + return 307; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * define our special pattern: {{findnearby>Some linkt text or nothing}}. |
|
52 | - * |
|
53 | - * @see Doku_Parser_Mode::connectTo() |
|
54 | - */ |
|
55 | - public function connectTo($mode): void { |
|
56 | - $this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby'); |
|
57 | - } |
|
50 | + /** |
|
51 | + * define our special pattern: {{findnearby>Some linkt text or nothing}}. |
|
52 | + * |
|
53 | + * @see Doku_Parser_Mode::connectTo() |
|
54 | + */ |
|
55 | + public function connectTo($mode): void { |
|
56 | + $this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby'); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * look up the page's geo metadata and pass that on to render. |
|
61 | - * |
|
62 | - * @param string $match The text matched by the patterns |
|
63 | - * @param int $state The lexer state for the match |
|
64 | - * @param int $pos The character position of the matched text |
|
65 | - * @param Doku_Handler $handler The Doku_Handler object |
|
66 | - * @return bool|array Return an array with all data you want to use in render, false don't add an instruction |
|
67 | - * |
|
68 | - * @see DokuWiki_Syntax_Plugin::handle() |
|
69 | - */ |
|
70 | - public function handle($match, $state, $pos, Doku_Handler $handler) { |
|
71 | - $data = array(); |
|
72 | - $data [0] = trim(substr($match, strlen('{{findnearby>'), -2)); |
|
73 | - if(strlen($data [0]) < 1) { |
|
74 | - $data [0] = $this->getLang('search_findnearby'); |
|
75 | - } |
|
76 | - $meta = p_get_metadata(getID(), 'geo'); |
|
77 | - if($meta) { |
|
78 | - if($meta ['lat'] && $meta ['lon']) { |
|
79 | - $data [1] = array( |
|
80 | - 'do' => 'findnearby', |
|
81 | - 'lat' => $meta ['lat'], |
|
82 | - 'lon' => $meta ['lon'] |
|
83 | - ); |
|
84 | - } elseif($meta ['geohash']) { |
|
85 | - $data [1] = array( |
|
86 | - 'do' => 'findnearby', |
|
87 | - 'geohash' => $meta ['geohash'] |
|
88 | - ); |
|
89 | - } |
|
90 | - return $data; |
|
91 | - } |
|
92 | - return false; |
|
93 | - } |
|
59 | + /** |
|
60 | + * look up the page's geo metadata and pass that on to render. |
|
61 | + * |
|
62 | + * @param string $match The text matched by the patterns |
|
63 | + * @param int $state The lexer state for the match |
|
64 | + * @param int $pos The character position of the matched text |
|
65 | + * @param Doku_Handler $handler The Doku_Handler object |
|
66 | + * @return bool|array Return an array with all data you want to use in render, false don't add an instruction |
|
67 | + * |
|
68 | + * @see DokuWiki_Syntax_Plugin::handle() |
|
69 | + */ |
|
70 | + public function handle($match, $state, $pos, Doku_Handler $handler) { |
|
71 | + $data = array(); |
|
72 | + $data [0] = trim(substr($match, strlen('{{findnearby>'), -2)); |
|
73 | + if(strlen($data [0]) < 1) { |
|
74 | + $data [0] = $this->getLang('search_findnearby'); |
|
75 | + } |
|
76 | + $meta = p_get_metadata(getID(), 'geo'); |
|
77 | + if($meta) { |
|
78 | + if($meta ['lat'] && $meta ['lon']) { |
|
79 | + $data [1] = array( |
|
80 | + 'do' => 'findnearby', |
|
81 | + 'lat' => $meta ['lat'], |
|
82 | + 'lon' => $meta ['lon'] |
|
83 | + ); |
|
84 | + } elseif($meta ['geohash']) { |
|
85 | + $data [1] = array( |
|
86 | + 'do' => 'findnearby', |
|
87 | + 'geohash' => $meta ['geohash'] |
|
88 | + ); |
|
89 | + } |
|
90 | + return $data; |
|
91 | + } |
|
92 | + return false; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Render a link to a search page. |
|
97 | - * |
|
98 | - * @see DokuWiki_Syntax_Plugin::render() |
|
99 | - */ |
|
100 | - public function render($format, Doku_Renderer $renderer, $data): bool { |
|
101 | - if($data === false) { |
|
102 | - return false; |
|
103 | - } |
|
95 | + /** |
|
96 | + * Render a link to a search page. |
|
97 | + * |
|
98 | + * @see DokuWiki_Syntax_Plugin::render() |
|
99 | + */ |
|
100 | + public function render($format, Doku_Renderer $renderer, $data): bool { |
|
101 | + if($data === false) { |
|
102 | + return false; |
|
103 | + } |
|
104 | 104 | |
105 | - if($format === 'xhtml') { |
|
106 | - $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>'; |
|
107 | - return true; |
|
108 | - } elseif($format === 'metadata') { |
|
109 | - return false; |
|
110 | - } elseif($format === 'odt') { |
|
111 | - // don't render anything in ODT |
|
112 | - return false; |
|
113 | - } |
|
114 | - return false; |
|
115 | - } |
|
105 | + if($format === 'xhtml') { |
|
106 | + $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>'; |
|
107 | + return true; |
|
108 | + } elseif($format === 'metadata') { |
|
109 | + return false; |
|
110 | + } elseif($format === 'odt') { |
|
111 | + // don't render anything in ODT |
|
112 | + return false; |
|
113 | + } |
|
114 | + return false; |
|
115 | + } |
|
116 | 116 | } |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | public function handle($match, $state, $pos, Doku_Handler $handler) { |
71 | 71 | $data = array(); |
72 | 72 | $data [0] = trim(substr($match, strlen('{{findnearby>'), -2)); |
73 | - if(strlen($data [0]) < 1) { |
|
73 | + if (strlen($data [0]) < 1) { |
|
74 | 74 | $data [0] = $this->getLang('search_findnearby'); |
75 | 75 | } |
76 | 76 | $meta = p_get_metadata(getID(), 'geo'); |
77 | - if($meta) { |
|
78 | - if($meta ['lat'] && $meta ['lon']) { |
|
77 | + if ($meta) { |
|
78 | + if ($meta ['lat'] && $meta ['lon']) { |
|
79 | 79 | $data [1] = array( |
80 | 80 | 'do' => 'findnearby', |
81 | 81 | 'lat' => $meta ['lat'], |
82 | 82 | 'lon' => $meta ['lon'] |
83 | 83 | ); |
84 | - } elseif($meta ['geohash']) { |
|
84 | + } elseif ($meta ['geohash']) { |
|
85 | 85 | $data [1] = array( |
86 | 86 | 'do' => 'findnearby', |
87 | 87 | 'geohash' => $meta ['geohash'] |
@@ -98,16 +98,16 @@ discard block |
||
98 | 98 | * @see DokuWiki_Syntax_Plugin::render() |
99 | 99 | */ |
100 | 100 | public function render($format, Doku_Renderer $renderer, $data): bool { |
101 | - if($data === false) { |
|
101 | + if ($data === false) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | |
105 | - if($format === 'xhtml') { |
|
105 | + if ($format === 'xhtml') { |
|
106 | 106 | $renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>'; |
107 | 107 | return true; |
108 | - } elseif($format === 'metadata') { |
|
108 | + } elseif ($format === 'metadata') { |
|
109 | 109 | return false; |
110 | - } elseif($format === 'odt') { |
|
110 | + } elseif ($format === 'odt') { |
|
111 | 111 | // don't render anything in ODT |
112 | 112 | return false; |
113 | 113 | } |
@@ -13,47 +13,47 @@ |
||
13 | 13 | */ |
14 | 14 | class index_test extends DokuWikiTest { |
15 | 15 | |
16 | - protected $pluginsEnabled = array('spatialhelper'); |
|
17 | - |
|
18 | - /** |
|
19 | - * Testdata for @return array |
|
20 | - * @see index_test::test_convertDMStoD |
|
21 | - * |
|
22 | - */ |
|
23 | - public static function convertDMStoDTestdata(): array { |
|
24 | - return array( |
|
25 | - array( |
|
26 | - array(0 => '52/1', 1 => '31/1', 2 => '2/1', 3 => 'N',), |
|
27 | - 52.5172, |
|
28 | - 'Latitude in Europe' |
|
29 | - ), |
|
30 | - array( |
|
31 | - array(0 => '13/1', 1 => '30/1', 2 => '38/1', 3 => 'E',), |
|
32 | - 13.5105, |
|
33 | - 'Longitude in Europe' |
|
34 | - ), |
|
35 | - array( |
|
36 | - array(0 => '50/1', 1 => '34251480/1000000', 2 => '0/1', 3 => 'N',), |
|
37 | - 50.5708, |
|
38 | - 'Latitude in North America' |
|
39 | - ), |
|
40 | - array( |
|
41 | - array(0 => '109/1', 1 => '28041300/1000000', 2 => '0/1', 3 => 'W',), |
|
42 | - -109.4673, |
|
43 | - 'Longitude in North America' |
|
44 | - ), |
|
45 | - ); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @dataProvider convertDMStoDTestdata |
|
50 | - */ |
|
51 | - public function test_convertDMStoD(array $input, float $expected_output, string $msg): void { |
|
52 | - $index = plugin_load('helper', 'spatialhelper_index'); |
|
53 | - assert($index instanceof helper_plugin_spatialhelper_index); |
|
54 | - |
|
55 | - $actual_output = $index->convertDMStoD($input); |
|
56 | - |
|
57 | - self::assertEqualsWithDelta($expected_output, $actual_output, 0.0001, $msg); |
|
58 | - } |
|
16 | + protected $pluginsEnabled = array('spatialhelper'); |
|
17 | + |
|
18 | + /** |
|
19 | + * Testdata for @return array |
|
20 | + * @see index_test::test_convertDMStoD |
|
21 | + * |
|
22 | + */ |
|
23 | + public static function convertDMStoDTestdata(): array { |
|
24 | + return array( |
|
25 | + array( |
|
26 | + array(0 => '52/1', 1 => '31/1', 2 => '2/1', 3 => 'N',), |
|
27 | + 52.5172, |
|
28 | + 'Latitude in Europe' |
|
29 | + ), |
|
30 | + array( |
|
31 | + array(0 => '13/1', 1 => '30/1', 2 => '38/1', 3 => 'E',), |
|
32 | + 13.5105, |
|
33 | + 'Longitude in Europe' |
|
34 | + ), |
|
35 | + array( |
|
36 | + array(0 => '50/1', 1 => '34251480/1000000', 2 => '0/1', 3 => 'N',), |
|
37 | + 50.5708, |
|
38 | + 'Latitude in North America' |
|
39 | + ), |
|
40 | + array( |
|
41 | + array(0 => '109/1', 1 => '28041300/1000000', 2 => '0/1', 3 => 'W',), |
|
42 | + -109.4673, |
|
43 | + 'Longitude in North America' |
|
44 | + ), |
|
45 | + ); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @dataProvider convertDMStoDTestdata |
|
50 | + */ |
|
51 | + public function test_convertDMStoD(array $input, float $expected_output, string $msg): void { |
|
52 | + $index = plugin_load('helper', 'spatialhelper_index'); |
|
53 | + assert($index instanceof helper_plugin_spatialhelper_index); |
|
54 | + |
|
55 | + $actual_output = $index->convertDMStoD($input); |
|
56 | + |
|
57 | + self::assertEqualsWithDelta($expected_output, $actual_output, 0.0001, $msg); |
|
58 | + } |
|
59 | 59 | } |
@@ -23,39 +23,39 @@ |
||
23 | 23 | */ |
24 | 24 | class general_plugin_spatialhelper_test extends DokuWikiTest { |
25 | 25 | |
26 | - protected $pluginsEnabled = array('spatialhelper'); |
|
26 | + protected $pluginsEnabled = array('spatialhelper'); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Simple test to make sure the plugin.info.txt is in correct format. |
|
30 | - */ |
|
31 | - public function test_plugininfo(): void { |
|
32 | - $file = __DIR__ . '/../plugin.info.txt'; |
|
33 | - self::assertFileExists($file); |
|
28 | + /** |
|
29 | + * Simple test to make sure the plugin.info.txt is in correct format. |
|
30 | + */ |
|
31 | + public function test_plugininfo(): void { |
|
32 | + $file = __DIR__ . '/../plugin.info.txt'; |
|
33 | + self::assertFileExists($file); |
|
34 | 34 | |
35 | - $info = confToHash($file); |
|
35 | + $info = confToHash($file); |
|
36 | 36 | |
37 | - self::assertArrayHasKey('base', $info); |
|
38 | - self::assertArrayHasKey('author', $info); |
|
39 | - self::assertArrayHasKey('email', $info); |
|
40 | - self::assertArrayHasKey('date', $info); |
|
41 | - self::assertArrayHasKey('name', $info); |
|
42 | - self::assertArrayHasKey('desc', $info); |
|
43 | - self::assertArrayHasKey('url', $info); |
|
37 | + self::assertArrayHasKey('base', $info); |
|
38 | + self::assertArrayHasKey('author', $info); |
|
39 | + self::assertArrayHasKey('email', $info); |
|
40 | + self::assertArrayHasKey('date', $info); |
|
41 | + self::assertArrayHasKey('name', $info); |
|
42 | + self::assertArrayHasKey('desc', $info); |
|
43 | + self::assertArrayHasKey('url', $info); |
|
44 | 44 | |
45 | - self::assertEquals('spatialhelper', $info['base']); |
|
46 | - self::assertRegExp('/^https?:\/\//', $info['url']); |
|
47 | - self::assertTrue(mail_isvalid($info['email'])); |
|
48 | - self::assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); |
|
49 | - self::assertTrue(false !== strtotime($info['date'])); |
|
50 | - } |
|
45 | + self::assertEquals('spatialhelper', $info['base']); |
|
46 | + self::assertRegExp('/^https?:\/\//', $info['url']); |
|
47 | + self::assertTrue(mail_isvalid($info['email'])); |
|
48 | + self::assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); |
|
49 | + self::assertTrue(false !== strtotime($info['date'])); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * test if plugin is loaded. |
|
54 | - */ |
|
55 | - public function test_plugin_spatialhelper_isloaded(): void { |
|
56 | - global $plugin_controller; |
|
57 | - self::assertContains( |
|
58 | - 'spatialhelper', $plugin_controller->getList(), "spatialhelper plugin is loaded" |
|
59 | - ); |
|
60 | - } |
|
52 | + /** |
|
53 | + * test if plugin is loaded. |
|
54 | + */ |
|
55 | + public function test_plugin_spatialhelper_isloaded(): void { |
|
56 | + global $plugin_controller; |
|
57 | + self::assertContains( |
|
58 | + 'spatialhelper', $plugin_controller->getList(), "spatialhelper plugin is loaded" |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | } |
@@ -23,64 +23,64 @@ |
||
23 | 23 | */ |
24 | 24 | class admin_plugin_spatialhelper_purge extends DokuWiki_Admin_Plugin { |
25 | 25 | |
26 | - /** |
|
27 | - * |
|
28 | - * @see DokuWiki_Admin_Plugin::getMenuSort() |
|
29 | - */ |
|
30 | - public function getMenuSort(): int { |
|
31 | - return 801; |
|
32 | - } |
|
26 | + /** |
|
27 | + * |
|
28 | + * @see DokuWiki_Admin_Plugin::getMenuSort() |
|
29 | + */ |
|
30 | + public function getMenuSort(): int { |
|
31 | + return 801; |
|
32 | + } |
|
33 | 33 | |
34 | - public function getMenuIcon(): string { |
|
35 | - $plugin = $this->getPluginName(); |
|
36 | - return DOKU_PLUGIN . $plugin . '/admin/purge.svg'; |
|
37 | - } |
|
34 | + public function getMenuIcon(): string { |
|
35 | + $plugin = $this->getPluginName(); |
|
36 | + return DOKU_PLUGIN . $plugin . '/admin/purge.svg'; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * purge and regenerate the index and sitemaps. |
|
41 | - * |
|
42 | - * @see DokuWiki_Admin_Plugin::handle() |
|
43 | - */ |
|
44 | - public function handle(): void { |
|
45 | - if(isset ($_REQUEST ['purgeindex'])) { |
|
46 | - global $conf; |
|
47 | - $path = $conf ['indexdir'] . '/spatial.idx'; |
|
48 | - if(file_exists($path) && unlink($path)) { |
|
49 | - msg($this->getLang('admin_purged_tiles'), 0); |
|
50 | - } |
|
51 | - } |
|
39 | + /** |
|
40 | + * purge and regenerate the index and sitemaps. |
|
41 | + * |
|
42 | + * @see DokuWiki_Admin_Plugin::handle() |
|
43 | + */ |
|
44 | + public function handle(): void { |
|
45 | + if(isset ($_REQUEST ['purgeindex'])) { |
|
46 | + global $conf; |
|
47 | + $path = $conf ['indexdir'] . '/spatial.idx'; |
|
48 | + if(file_exists($path) && unlink($path)) { |
|
49 | + msg($this->getLang('admin_purged_tiles'), 0); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
54 | - $indexer->generateSpatialIndex(); |
|
53 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
54 | + $indexer->generateSpatialIndex(); |
|
55 | 55 | |
56 | - $sitemapper = plugin_load('helper', 'spatialhelper_sitemap'); |
|
57 | - $sitemapper->createKMLSitemap($this->getConf('media_kml')); |
|
58 | - $sitemapper->createGeoRSSSitemap($this->getConf('media_georss')); |
|
59 | - } |
|
56 | + $sitemapper = plugin_load('helper', 'spatialhelper_sitemap'); |
|
57 | + $sitemapper->createKMLSitemap($this->getConf('media_kml')); |
|
58 | + $sitemapper->createGeoRSSSitemap($this->getConf('media_georss')); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * render the form for this plugin. |
|
63 | - * |
|
64 | - * @see DokuWiki_Admin_Plugin::html() |
|
65 | - */ |
|
66 | - public function html(): void { |
|
67 | - echo $this->locale_xhtml('admin_purge_intro'); |
|
61 | + /** |
|
62 | + * render the form for this plugin. |
|
63 | + * |
|
64 | + * @see DokuWiki_Admin_Plugin::html() |
|
65 | + */ |
|
66 | + public function html(): void { |
|
67 | + echo $this->locale_xhtml('admin_purge_intro'); |
|
68 | 68 | |
69 | - $form = new Doku_Form( |
|
70 | - array( |
|
71 | - 'id' => 'spatialhelper__purgeform', |
|
72 | - 'method' => 'post' |
|
73 | - ) |
|
74 | - ); |
|
75 | - $form->addHidden('purgeindex', 'true'); |
|
69 | + $form = new Doku_Form( |
|
70 | + array( |
|
71 | + 'id' => 'spatialhelper__purgeform', |
|
72 | + 'method' => 'post' |
|
73 | + ) |
|
74 | + ); |
|
75 | + $form->addHidden('purgeindex', 'true'); |
|
76 | 76 | |
77 | - $form->addElement( |
|
78 | - form_makeButton( |
|
79 | - 'submit', 'admin', $this->getLang('admin_submit'), array( |
|
80 | - 'title' => $this->getLang('admin_submit') |
|
81 | - ) |
|
82 | - ) |
|
83 | - ); |
|
84 | - $form->printForm(); |
|
85 | - } |
|
77 | + $form->addElement( |
|
78 | + form_makeButton( |
|
79 | + 'submit', 'admin', $this->getLang('admin_submit'), array( |
|
80 | + 'title' => $this->getLang('admin_submit') |
|
81 | + ) |
|
82 | + ) |
|
83 | + ); |
|
84 | + $form->printForm(); |
|
85 | + } |
|
86 | 86 | } |
@@ -42,10 +42,10 @@ |
||
42 | 42 | * @see DokuWiki_Admin_Plugin::handle() |
43 | 43 | */ |
44 | 44 | public function handle(): void { |
45 | - if(isset ($_REQUEST ['purgeindex'])) { |
|
45 | + if (isset ($_REQUEST ['purgeindex'])) { |
|
46 | 46 | global $conf; |
47 | 47 | $path = $conf ['indexdir'] . '/spatial.idx'; |
48 | - if(file_exists($path) && unlink($path)) { |
|
48 | + if (file_exists($path) && unlink($path)) { |
|
49 | 49 | msg($this->getLang('admin_purged_tiles'), 0); |
50 | 50 | } |
51 | 51 | } |
@@ -24,282 +24,282 @@ |
||
24 | 24 | * @author Mark Prins |
25 | 25 | */ |
26 | 26 | class helper_plugin_spatialhelper_index extends DokuWiki_Plugin { |
27 | - /** |
|
28 | - * directory for index files. |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $idx_dir = ''; |
|
27 | + /** |
|
28 | + * directory for index files. |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $idx_dir = ''; |
|
33 | 33 | |
34 | - /** |
|
35 | - * spatial index, well lookup list/array so we can do spatial queries. |
|
36 | - * entries should be: array("geohash" => {"id1","id3",}) |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $spatial_idx = array(); |
|
34 | + /** |
|
35 | + * spatial index, well lookup list/array so we can do spatial queries. |
|
36 | + * entries should be: array("geohash" => {"id1","id3",}) |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $spatial_idx = array(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor, initialises the spatial index. |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - if(!plugin_load('helper', 'geophp')) { |
|
47 | - $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: required geophp plugin is not available.'; |
|
48 | - msg($message, -1); |
|
49 | - } |
|
42 | + /** |
|
43 | + * Constructor, initialises the spatial index. |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + if(!plugin_load('helper', 'geophp')) { |
|
47 | + $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: required geophp plugin is not available.'; |
|
48 | + msg($message, -1); |
|
49 | + } |
|
50 | 50 | |
51 | - global $conf; |
|
52 | - $this->idx_dir = $conf ['indexdir']; |
|
53 | - // test if there is a spatialindex, if not build one for the wiki |
|
54 | - if(!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
55 | - // creates and stores the index |
|
56 | - $this->generateSpatialIndex(); |
|
57 | - } else { |
|
58 | - $this->spatial_idx = unserialize( |
|
59 | - io_readFile($this->idx_dir . '/spatial.idx', false), |
|
60 | - ['allowed_classes' => false] |
|
61 | - ); |
|
62 | - dbglog($this->spatial_idx, 'done loading spatial index'); |
|
63 | - } |
|
64 | - } |
|
51 | + global $conf; |
|
52 | + $this->idx_dir = $conf ['indexdir']; |
|
53 | + // test if there is a spatialindex, if not build one for the wiki |
|
54 | + if(!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
55 | + // creates and stores the index |
|
56 | + $this->generateSpatialIndex(); |
|
57 | + } else { |
|
58 | + $this->spatial_idx = unserialize( |
|
59 | + io_readFile($this->idx_dir . '/spatial.idx', false), |
|
60 | + ['allowed_classes' => false] |
|
61 | + ); |
|
62 | + dbglog($this->spatial_idx, 'done loading spatial index'); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * (re-)Generates the spatial index by running through all the pages in the wiki. |
|
68 | - * |
|
69 | - * @todo add an option to erase the old index |
|
70 | - */ |
|
71 | - public function generateSpatialIndex(): bool { |
|
72 | - global $conf; |
|
73 | - require_once(DOKU_INC . 'inc/search.php'); |
|
74 | - $pages = array(); |
|
75 | - search($pages, $conf ['datadir'], 'search_allpages', array()); |
|
76 | - foreach($pages as $page) { |
|
77 | - $this->updateSpatialIndex($page ['id']); |
|
78 | - } |
|
79 | - // media |
|
80 | - $media = array(); |
|
81 | - search($media, $conf ['mediadir'], 'search_media', array()); |
|
82 | - foreach($media as $medium) { |
|
83 | - if($medium ['isimg']) { |
|
84 | - $this->indexImage($medium); |
|
85 | - } |
|
86 | - } |
|
87 | - return true; |
|
88 | - } |
|
66 | + /** |
|
67 | + * (re-)Generates the spatial index by running through all the pages in the wiki. |
|
68 | + * |
|
69 | + * @todo add an option to erase the old index |
|
70 | + */ |
|
71 | + public function generateSpatialIndex(): bool { |
|
72 | + global $conf; |
|
73 | + require_once(DOKU_INC . 'inc/search.php'); |
|
74 | + $pages = array(); |
|
75 | + search($pages, $conf ['datadir'], 'search_allpages', array()); |
|
76 | + foreach($pages as $page) { |
|
77 | + $this->updateSpatialIndex($page ['id']); |
|
78 | + } |
|
79 | + // media |
|
80 | + $media = array(); |
|
81 | + search($media, $conf ['mediadir'], 'search_media', array()); |
|
82 | + foreach($media as $medium) { |
|
83 | + if($medium ['isimg']) { |
|
84 | + $this->indexImage($medium); |
|
85 | + } |
|
86 | + } |
|
87 | + return true; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Update the spatial index for the page. |
|
92 | - * |
|
93 | - * @param string $id |
|
94 | - * the document ID |
|
95 | - * @throws Exception |
|
96 | - */ |
|
97 | - public function updateSpatialIndex(string $id): bool { |
|
98 | - $geotags = p_get_metadata($id, 'geo'); |
|
99 | - if(empty ($geotags)) { |
|
100 | - return false; |
|
101 | - } |
|
102 | - if(empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
103 | - return false; |
|
104 | - } |
|
105 | - dbglog($geotags, "Geo metadata found for page $id"); |
|
106 | - $geometry = new Point($geotags ['lon'], $geotags ['lat']); |
|
107 | - $geohash = $geometry->out('geohash'); |
|
108 | - dbglog('Update index for geohash: ' . $geohash); |
|
109 | - return $this->addToIndex($geohash, $id); |
|
110 | - } |
|
90 | + /** |
|
91 | + * Update the spatial index for the page. |
|
92 | + * |
|
93 | + * @param string $id |
|
94 | + * the document ID |
|
95 | + * @throws Exception |
|
96 | + */ |
|
97 | + public function updateSpatialIndex(string $id): bool { |
|
98 | + $geotags = p_get_metadata($id, 'geo'); |
|
99 | + if(empty ($geotags)) { |
|
100 | + return false; |
|
101 | + } |
|
102 | + if(empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
103 | + return false; |
|
104 | + } |
|
105 | + dbglog($geotags, "Geo metadata found for page $id"); |
|
106 | + $geometry = new Point($geotags ['lon'], $geotags ['lat']); |
|
107 | + $geohash = $geometry->out('geohash'); |
|
108 | + dbglog('Update index for geohash: ' . $geohash); |
|
109 | + return $this->addToIndex($geohash, $id); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Store the hash/id entry in the index. |
|
114 | - * |
|
115 | - * @param string $geohash |
|
116 | - * @param string $id |
|
117 | - * page or media id |
|
118 | - * @return bool true when succesful |
|
119 | - */ |
|
120 | - private function addToIndex(string $geohash, string $id): bool { |
|
121 | - $pageIds = array(); |
|
122 | - // check index for key/geohash |
|
123 | - if(!array_key_exists($geohash, $this->spatial_idx)) { |
|
124 | - dbglog("Geohash $geohash not in index, just add $id."); |
|
125 | - $pageIds [] = $id; |
|
126 | - } else { |
|
127 | - dbglog('Geohash for document is in index, find it.'); |
|
128 | - // check the index for document |
|
129 | - $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
130 | - if(empty ($knownHashes)) { |
|
131 | - dbglog("No index record found for document $id, just add"); |
|
132 | - $pageIds = $this->spatial_idx [$geohash]; |
|
133 | - $pageIds [] = $id; |
|
134 | - } |
|
135 | - // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
136 | - $knownHash = $knownHashes [0]; |
|
112 | + /** |
|
113 | + * Store the hash/id entry in the index. |
|
114 | + * |
|
115 | + * @param string $geohash |
|
116 | + * @param string $id |
|
117 | + * page or media id |
|
118 | + * @return bool true when succesful |
|
119 | + */ |
|
120 | + private function addToIndex(string $geohash, string $id): bool { |
|
121 | + $pageIds = array(); |
|
122 | + // check index for key/geohash |
|
123 | + if(!array_key_exists($geohash, $this->spatial_idx)) { |
|
124 | + dbglog("Geohash $geohash not in index, just add $id."); |
|
125 | + $pageIds [] = $id; |
|
126 | + } else { |
|
127 | + dbglog('Geohash for document is in index, find it.'); |
|
128 | + // check the index for document |
|
129 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
130 | + if(empty ($knownHashes)) { |
|
131 | + dbglog("No index record found for document $id, just add"); |
|
132 | + $pageIds = $this->spatial_idx [$geohash]; |
|
133 | + $pageIds [] = $id; |
|
134 | + } |
|
135 | + // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
136 | + $knownHash = $knownHashes [0]; |
|
137 | 137 | |
138 | - if($knownHash === $geohash) { |
|
139 | - dbglog("Document $id was found in index and has the same geohash, nothing to do."); |
|
140 | - return true; |
|
141 | - } |
|
138 | + if($knownHash === $geohash) { |
|
139 | + dbglog("Document $id was found in index and has the same geohash, nothing to do."); |
|
140 | + return true; |
|
141 | + } |
|
142 | 142 | |
143 | - if(!empty ($knownHash)) { |
|
144 | - dbglog("Document/media $id was found in index but has different geohash (it moved)."); |
|
145 | - $knownIds = $this->spatial_idx [$knownHash]; |
|
146 | - dbglog($knownIds, "Known id's for this hash:"); |
|
147 | - // remove it from the old geohash element |
|
148 | - $i = array_search($id, $knownIds); |
|
149 | - dbglog('Unsetting:' . $knownIds [$i]); |
|
150 | - unset ($knownIds [$i]); |
|
151 | - $this->spatial_idx [$knownHash] = $knownIds; |
|
152 | - // set on new geohash element |
|
153 | - $pageIds = $this->spatial_idx [$geohash]; |
|
154 | - $pageIds [] = $id; |
|
155 | - } |
|
156 | - } |
|
157 | - // store and save |
|
158 | - $this->spatial_idx [$geohash] = $pageIds; |
|
159 | - return $this->saveIndex(); |
|
160 | - } |
|
143 | + if(!empty ($knownHash)) { |
|
144 | + dbglog("Document/media $id was found in index but has different geohash (it moved)."); |
|
145 | + $knownIds = $this->spatial_idx [$knownHash]; |
|
146 | + dbglog($knownIds, "Known id's for this hash:"); |
|
147 | + // remove it from the old geohash element |
|
148 | + $i = array_search($id, $knownIds); |
|
149 | + dbglog('Unsetting:' . $knownIds [$i]); |
|
150 | + unset ($knownIds [$i]); |
|
151 | + $this->spatial_idx [$knownHash] = $knownIds; |
|
152 | + // set on new geohash element |
|
153 | + $pageIds = $this->spatial_idx [$geohash]; |
|
154 | + $pageIds [] = $id; |
|
155 | + } |
|
156 | + } |
|
157 | + // store and save |
|
158 | + $this->spatial_idx [$geohash] = $pageIds; |
|
159 | + return $this->saveIndex(); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Looks up the geohash(es) for the document in the index. |
|
164 | - * |
|
165 | - * @param String $id |
|
166 | - * document ID |
|
167 | - * @param array $index |
|
168 | - * spatial index |
|
169 | - */ |
|
170 | - public function findHashesForId(string $id, array $index): array { |
|
171 | - $hashes = array(); |
|
172 | - foreach($index as $hash => $docIds) { |
|
173 | - if(in_array($id, $docIds, false)) { |
|
174 | - $hashes [] = $hash; |
|
175 | - } |
|
176 | - } |
|
177 | - dbglog($hashes, "Found the following hashes for $id (should only be 1)"); |
|
178 | - return $hashes; |
|
179 | - } |
|
162 | + /** |
|
163 | + * Looks up the geohash(es) for the document in the index. |
|
164 | + * |
|
165 | + * @param String $id |
|
166 | + * document ID |
|
167 | + * @param array $index |
|
168 | + * spatial index |
|
169 | + */ |
|
170 | + public function findHashesForId(string $id, array $index): array { |
|
171 | + $hashes = array(); |
|
172 | + foreach($index as $hash => $docIds) { |
|
173 | + if(in_array($id, $docIds, false)) { |
|
174 | + $hashes [] = $hash; |
|
175 | + } |
|
176 | + } |
|
177 | + dbglog($hashes, "Found the following hashes for $id (should only be 1)"); |
|
178 | + return $hashes; |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Save spatial index. |
|
183 | - */ |
|
184 | - private function saveIndex(): bool { |
|
185 | - return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx)); |
|
186 | - } |
|
181 | + /** |
|
182 | + * Save spatial index. |
|
183 | + */ |
|
184 | + private function saveIndex(): bool { |
|
185 | + return io_saveFile($this->idx_dir . '/spatial.idx', serialize($this->spatial_idx)); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Add an index entry for this file having EXIF / IPTC data. |
|
190 | - * |
|
191 | - * @param $img |
|
192 | - * a Dokuwiki image |
|
193 | - * @return bool true when image was succesfully added to the index. |
|
194 | - * @throws Exception |
|
195 | - * @see http://www.php.net/manual/en/function.iptcparse.php |
|
196 | - * @see http://php.net/manual/en/function.exif-read-data.php |
|
197 | - * |
|
198 | - */ |
|
199 | - public function indexImage($img): bool { |
|
200 | - // test for supported files (jpeg only) |
|
201 | - if( |
|
202 | - (substr($img ['file'], -strlen('.jpg')) !== '.jpg') && |
|
203 | - (substr($img ['file'], -strlen('.jpeg')) !== '.jpeg')) { |
|
204 | - return false; |
|
205 | - } |
|
188 | + /** |
|
189 | + * Add an index entry for this file having EXIF / IPTC data. |
|
190 | + * |
|
191 | + * @param $img |
|
192 | + * a Dokuwiki image |
|
193 | + * @return bool true when image was succesfully added to the index. |
|
194 | + * @throws Exception |
|
195 | + * @see http://www.php.net/manual/en/function.iptcparse.php |
|
196 | + * @see http://php.net/manual/en/function.exif-read-data.php |
|
197 | + * |
|
198 | + */ |
|
199 | + public function indexImage($img): bool { |
|
200 | + // test for supported files (jpeg only) |
|
201 | + if( |
|
202 | + (substr($img ['file'], -strlen('.jpg')) !== '.jpg') && |
|
203 | + (substr($img ['file'], -strlen('.jpeg')) !== '.jpeg')) { |
|
204 | + return false; |
|
205 | + } |
|
206 | 206 | |
207 | - $geometry = $this->getCoordsFromExif($img ['id']); |
|
208 | - if(!$geometry) { |
|
209 | - return false; |
|
210 | - } |
|
211 | - $geohash = $geometry->out('geohash'); |
|
212 | - // TODO truncate the geohash to something reasonable, otherwise they are |
|
213 | - // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too |
|
214 | - // precise, limit at ~9 as most GPS are not submeter accurate |
|
215 | - return $this->addToIndex($geohash, 'media__' . $img ['id']); |
|
216 | - } |
|
207 | + $geometry = $this->getCoordsFromExif($img ['id']); |
|
208 | + if(!$geometry) { |
|
209 | + return false; |
|
210 | + } |
|
211 | + $geohash = $geometry->out('geohash'); |
|
212 | + // TODO truncate the geohash to something reasonable, otherwise they are |
|
213 | + // useless as an indexing mechanism eg. u1h73weckdrmskdqec3c9 is far too |
|
214 | + // precise, limit at ~9 as most GPS are not submeter accurate |
|
215 | + return $this->addToIndex($geohash, 'media__' . $img ['id']); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * retrieve GPS decimal coordinates from exif. |
|
220 | - * |
|
221 | - * @param string $id |
|
222 | - * @return Point|false |
|
223 | - * @throws Exception |
|
224 | - */ |
|
225 | - public function getCoordsFromExif(string $id) { |
|
226 | - $exif = exif_read_data(mediaFN($id), 0, true); |
|
227 | - if(empty ($exif ['GPS'])) { |
|
228 | - return false; |
|
229 | - } |
|
218 | + /** |
|
219 | + * retrieve GPS decimal coordinates from exif. |
|
220 | + * |
|
221 | + * @param string $id |
|
222 | + * @return Point|false |
|
223 | + * @throws Exception |
|
224 | + */ |
|
225 | + public function getCoordsFromExif(string $id) { |
|
226 | + $exif = exif_read_data(mediaFN($id), 0, true); |
|
227 | + if(empty ($exif ['GPS'])) { |
|
228 | + return false; |
|
229 | + } |
|
230 | 230 | |
231 | - $lat = $this->convertDMStoD( |
|
232 | - array( |
|
233 | - $exif ['GPS'] ['GPSLatitude'] [0], |
|
234 | - $exif ['GPS'] ['GPSLatitude'] [1], |
|
235 | - $exif ['GPS'] ['GPSLatitude'] [2], |
|
236 | - $exif ['GPS'] ['GPSLatitudeRef'] |
|
237 | - ) |
|
238 | - ); |
|
231 | + $lat = $this->convertDMStoD( |
|
232 | + array( |
|
233 | + $exif ['GPS'] ['GPSLatitude'] [0], |
|
234 | + $exif ['GPS'] ['GPSLatitude'] [1], |
|
235 | + $exif ['GPS'] ['GPSLatitude'] [2], |
|
236 | + $exif ['GPS'] ['GPSLatitudeRef'] |
|
237 | + ) |
|
238 | + ); |
|
239 | 239 | |
240 | - $lon = $this->convertDMStoD( |
|
241 | - array( |
|
242 | - $exif ['GPS'] ['GPSLongitude'] [0], |
|
243 | - $exif ['GPS'] ['GPSLongitude'] [1], |
|
244 | - $exif ['GPS'] ['GPSLongitude'] [2], |
|
245 | - $exif ['GPS'] ['GPSLongitudeRef'] |
|
246 | - ) |
|
247 | - ); |
|
240 | + $lon = $this->convertDMStoD( |
|
241 | + array( |
|
242 | + $exif ['GPS'] ['GPSLongitude'] [0], |
|
243 | + $exif ['GPS'] ['GPSLongitude'] [1], |
|
244 | + $exif ['GPS'] ['GPSLongitude'] [2], |
|
245 | + $exif ['GPS'] ['GPSLongitudeRef'] |
|
246 | + ) |
|
247 | + ); |
|
248 | 248 | |
249 | - return new Point($lon, $lat); |
|
250 | - } |
|
249 | + return new Point($lon, $lat); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * convert DegreesMinutesSeconds to Decimal degrees. |
|
254 | - * |
|
255 | - * @param array $param array of rational DMS |
|
256 | - * @return float |
|
257 | - */ |
|
258 | - public function convertDMStoD(array $param): float { |
|
259 | - if(!is_array($param)) { |
|
260 | - $param = array($param); |
|
261 | - } |
|
262 | - $deg = $this->convertRationaltoFloat($param [0]); |
|
263 | - $min = $this->convertRationaltoFloat($param [1]) / 60; |
|
264 | - $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60; |
|
265 | - // Hemisphere (N, S, W or E) |
|
266 | - $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1; |
|
267 | - return $hem * ($deg + $min + $sec); |
|
268 | - } |
|
252 | + /** |
|
253 | + * convert DegreesMinutesSeconds to Decimal degrees. |
|
254 | + * |
|
255 | + * @param array $param array of rational DMS |
|
256 | + * @return float |
|
257 | + */ |
|
258 | + public function convertDMStoD(array $param): float { |
|
259 | + if(!is_array($param)) { |
|
260 | + $param = array($param); |
|
261 | + } |
|
262 | + $deg = $this->convertRationaltoFloat($param [0]); |
|
263 | + $min = $this->convertRationaltoFloat($param [1]) / 60; |
|
264 | + $sec = $this->convertRationaltoFloat($param [2]) / 60 / 60; |
|
265 | + // Hemisphere (N, S, W or E) |
|
266 | + $hem = ($param [3] === 'N' || $param [3] === 'E') ? 1 : -1; |
|
267 | + return $hem * ($deg + $min + $sec); |
|
268 | + } |
|
269 | 269 | |
270 | - public function convertRationaltoFloat($param): float { |
|
271 | - // rational64u |
|
272 | - $nums = explode('/', $param); |
|
273 | - if((int) $nums[1] > 0) { |
|
274 | - return (float) $nums[0] / (int) $nums[1]; |
|
275 | - } else { |
|
276 | - return (float) $nums[0]; |
|
277 | - } |
|
278 | - } |
|
270 | + public function convertRationaltoFloat($param): float { |
|
271 | + // rational64u |
|
272 | + $nums = explode('/', $param); |
|
273 | + if((int) $nums[1] > 0) { |
|
274 | + return (float) $nums[0] / (int) $nums[1]; |
|
275 | + } else { |
|
276 | + return (float) $nums[0]; |
|
277 | + } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Deletes the page from the index. |
|
282 | - * |
|
283 | - * @param string $id document ID |
|
284 | - */ |
|
285 | - public function deleteFromIndex(string $id): void { |
|
286 | - // check the index for document |
|
287 | - $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
288 | - if(empty ($knownHashes)) { |
|
289 | - return; |
|
290 | - } |
|
280 | + /** |
|
281 | + * Deletes the page from the index. |
|
282 | + * |
|
283 | + * @param string $id document ID |
|
284 | + */ |
|
285 | + public function deleteFromIndex(string $id): void { |
|
286 | + // check the index for document |
|
287 | + $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
|
288 | + if(empty ($knownHashes)) { |
|
289 | + return; |
|
290 | + } |
|
291 | 291 | |
292 | - // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
293 | - $knownHash = $knownHashes [0]; |
|
294 | - $knownIds = $this->spatial_idx [$knownHash]; |
|
295 | - $i = array_search($id, $knownIds); |
|
296 | - dbglog("removing: $knownIds[$i] from the index."); |
|
297 | - unset ($knownIds [$i]); |
|
298 | - $this->spatial_idx [$knownHash] = $knownIds; |
|
299 | - if(empty ($this->spatial_idx [$knownHash])) { |
|
300 | - // dbglog ( "removing key: $knownHash from the index." ); |
|
301 | - unset ($this->spatial_idx [$knownHash]); |
|
302 | - } |
|
303 | - $this->saveIndex(); |
|
304 | - } |
|
292 | + // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
|
293 | + $knownHash = $knownHashes [0]; |
|
294 | + $knownIds = $this->spatial_idx [$knownHash]; |
|
295 | + $i = array_search($id, $knownIds); |
|
296 | + dbglog("removing: $knownIds[$i] from the index."); |
|
297 | + unset ($knownIds [$i]); |
|
298 | + $this->spatial_idx [$knownHash] = $knownIds; |
|
299 | + if(empty ($this->spatial_idx [$knownHash])) { |
|
300 | + // dbglog ( "removing key: $knownHash from the index." ); |
|
301 | + unset ($this->spatial_idx [$knownHash]); |
|
302 | + } |
|
303 | + $this->saveIndex(); |
|
304 | + } |
|
305 | 305 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * Constructor, initialises the spatial index. |
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | - if(!plugin_load('helper', 'geophp')) { |
|
46 | + if (!plugin_load('helper', 'geophp')) { |
|
47 | 47 | $message = 'helper_plugin_spatialhelper_index::spatialhelper_index: required geophp plugin is not available.'; |
48 | 48 | msg($message, -1); |
49 | 49 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | global $conf; |
52 | 52 | $this->idx_dir = $conf ['indexdir']; |
53 | 53 | // test if there is a spatialindex, if not build one for the wiki |
54 | - if(!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
54 | + if (!@file_exists($this->idx_dir . '/spatial.idx')) { |
|
55 | 55 | // creates and stores the index |
56 | 56 | $this->generateSpatialIndex(); |
57 | 57 | } else { |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | require_once(DOKU_INC . 'inc/search.php'); |
74 | 74 | $pages = array(); |
75 | 75 | search($pages, $conf ['datadir'], 'search_allpages', array()); |
76 | - foreach($pages as $page) { |
|
76 | + foreach ($pages as $page) { |
|
77 | 77 | $this->updateSpatialIndex($page ['id']); |
78 | 78 | } |
79 | 79 | // media |
80 | 80 | $media = array(); |
81 | 81 | search($media, $conf ['mediadir'], 'search_media', array()); |
82 | - foreach($media as $medium) { |
|
83 | - if($medium ['isimg']) { |
|
82 | + foreach ($media as $medium) { |
|
83 | + if ($medium ['isimg']) { |
|
84 | 84 | $this->indexImage($medium); |
85 | 85 | } |
86 | 86 | } |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function updateSpatialIndex(string $id): bool { |
98 | 98 | $geotags = p_get_metadata($id, 'geo'); |
99 | - if(empty ($geotags)) { |
|
99 | + if (empty ($geotags)) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | - if(empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
102 | + if (empty ($geotags ['lon']) || empty ($geotags ['lat'])) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | dbglog($geotags, "Geo metadata found for page $id"); |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | private function addToIndex(string $geohash, string $id): bool { |
121 | 121 | $pageIds = array(); |
122 | 122 | // check index for key/geohash |
123 | - if(!array_key_exists($geohash, $this->spatial_idx)) { |
|
123 | + if (!array_key_exists($geohash, $this->spatial_idx)) { |
|
124 | 124 | dbglog("Geohash $geohash not in index, just add $id."); |
125 | 125 | $pageIds [] = $id; |
126 | 126 | } else { |
127 | 127 | dbglog('Geohash for document is in index, find it.'); |
128 | 128 | // check the index for document |
129 | 129 | $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
130 | - if(empty ($knownHashes)) { |
|
130 | + if (empty ($knownHashes)) { |
|
131 | 131 | dbglog("No index record found for document $id, just add"); |
132 | 132 | $pageIds = $this->spatial_idx [$geohash]; |
133 | 133 | $pageIds [] = $id; |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | // TODO shortcut, need to make sure there is only one element, if not the index is corrupt |
136 | 136 | $knownHash = $knownHashes [0]; |
137 | 137 | |
138 | - if($knownHash === $geohash) { |
|
138 | + if ($knownHash === $geohash) { |
|
139 | 139 | dbglog("Document $id was found in index and has the same geohash, nothing to do."); |
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | |
143 | - if(!empty ($knownHash)) { |
|
143 | + if (!empty ($knownHash)) { |
|
144 | 144 | dbglog("Document/media $id was found in index but has different geohash (it moved)."); |
145 | 145 | $knownIds = $this->spatial_idx [$knownHash]; |
146 | 146 | dbglog($knownIds, "Known id's for this hash:"); |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function findHashesForId(string $id, array $index): array { |
171 | 171 | $hashes = array(); |
172 | - foreach($index as $hash => $docIds) { |
|
173 | - if(in_array($id, $docIds, false)) { |
|
172 | + foreach ($index as $hash => $docIds) { |
|
173 | + if (in_array($id, $docIds, false)) { |
|
174 | 174 | $hashes [] = $hash; |
175 | 175 | } |
176 | 176 | } |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function indexImage($img): bool { |
200 | 200 | // test for supported files (jpeg only) |
201 | - if( |
|
201 | + if ( |
|
202 | 202 | (substr($img ['file'], -strlen('.jpg')) !== '.jpg') && |
203 | 203 | (substr($img ['file'], -strlen('.jpeg')) !== '.jpeg')) { |
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $geometry = $this->getCoordsFromExif($img ['id']); |
208 | - if(!$geometry) { |
|
208 | + if (!$geometry) { |
|
209 | 209 | return false; |
210 | 210 | } |
211 | 211 | $geohash = $geometry->out('geohash'); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function getCoordsFromExif(string $id) { |
226 | 226 | $exif = exif_read_data(mediaFN($id), 0, true); |
227 | - if(empty ($exif ['GPS'])) { |
|
227 | + if (empty ($exif ['GPS'])) { |
|
228 | 228 | return false; |
229 | 229 | } |
230 | 230 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @return float |
257 | 257 | */ |
258 | 258 | public function convertDMStoD(array $param): float { |
259 | - if(!is_array($param)) { |
|
259 | + if (!is_array($param)) { |
|
260 | 260 | $param = array($param); |
261 | 261 | } |
262 | 262 | $deg = $this->convertRationaltoFloat($param [0]); |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | public function convertRationaltoFloat($param): float { |
271 | 271 | // rational64u |
272 | 272 | $nums = explode('/', $param); |
273 | - if((int) $nums[1] > 0) { |
|
274 | - return (float) $nums[0] / (int) $nums[1]; |
|
273 | + if (( int ) $nums[1] > 0) { |
|
274 | + return ( float ) $nums[0] / ( int ) $nums[1]; |
|
275 | 275 | } else { |
276 | - return (float) $nums[0]; |
|
276 | + return ( float ) $nums[0]; |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | public function deleteFromIndex(string $id): void { |
286 | 286 | // check the index for document |
287 | 287 | $knownHashes = $this->findHashesForId($id, $this->spatial_idx); |
288 | - if(empty ($knownHashes)) { |
|
288 | + if (empty ($knownHashes)) { |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | dbglog("removing: $knownIds[$i] from the index."); |
297 | 297 | unset ($knownIds [$i]); |
298 | 298 | $this->spatial_idx [$knownHash] = $knownIds; |
299 | - if(empty ($this->spatial_idx [$knownHash])) { |
|
299 | + if (empty ($this->spatial_idx [$knownHash])) { |
|
300 | 300 | // dbglog ( "removing key: $knownHash from the index." ); |
301 | 301 | unset ($this->spatial_idx [$knownHash]); |
302 | 302 | } |
@@ -26,178 +26,178 @@ |
||
26 | 26 | * @author Mark Prins |
27 | 27 | */ |
28 | 28 | class helper_plugin_spatialhelper_search extends DokuWiki_Plugin { |
29 | - /** |
|
30 | - * spatial index. |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $spatial_idx = array(); |
|
35 | - /** |
|
36 | - * Precision, Distance of Adjacent Cell in Meters. |
|
37 | - * |
|
38 | - * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance |
|
39 | - * |
|
40 | - * @var float |
|
41 | - */ |
|
42 | - private $precision = array( |
|
43 | - 5003530, |
|
44 | - 625441, |
|
45 | - 123264, |
|
46 | - 19545, |
|
47 | - 3803, |
|
48 | - 610, |
|
49 | - 118, |
|
50 | - 19, |
|
51 | - 3.7, |
|
52 | - 0.6 |
|
53 | - ); |
|
29 | + /** |
|
30 | + * spatial index. |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $spatial_idx = array(); |
|
35 | + /** |
|
36 | + * Precision, Distance of Adjacent Cell in Meters. |
|
37 | + * |
|
38 | + * @see https://stackoverflow.com/questions/13836416/geohash-and-max-distance |
|
39 | + * |
|
40 | + * @var float |
|
41 | + */ |
|
42 | + private $precision = array( |
|
43 | + 5003530, |
|
44 | + 625441, |
|
45 | + 123264, |
|
46 | + 19545, |
|
47 | + 3803, |
|
48 | + 610, |
|
49 | + 118, |
|
50 | + 19, |
|
51 | + 3.7, |
|
52 | + 0.6 |
|
53 | + ); |
|
54 | 54 | |
55 | - /** |
|
56 | - * constructor; initialize/load spatial index. |
|
57 | - */ |
|
58 | - public function __construct() { |
|
59 | - // parent::__construct (); |
|
60 | - global $conf; |
|
55 | + /** |
|
56 | + * constructor; initialize/load spatial index. |
|
57 | + */ |
|
58 | + public function __construct() { |
|
59 | + // parent::__construct (); |
|
60 | + global $conf; |
|
61 | 61 | |
62 | - if(!plugin_load('helper', 'geophp', false, true)) { |
|
63 | - $message = |
|
64 | - 'helper_plugin_spatialhelper_search::spatialhelper_search: required geophp plugin is not available.'; |
|
65 | - msg($message, -1); |
|
66 | - } |
|
62 | + if(!plugin_load('helper', 'geophp', false, true)) { |
|
63 | + $message = |
|
64 | + 'helper_plugin_spatialhelper_search::spatialhelper_search: required geophp plugin is not available.'; |
|
65 | + msg($message, -1); |
|
66 | + } |
|
67 | 67 | |
68 | - $idx_dir = $conf ['indexdir']; |
|
69 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
70 | - plugin_load('helper', 'spatialhelper_index'); |
|
71 | - } |
|
68 | + $idx_dir = $conf ['indexdir']; |
|
69 | + if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
70 | + plugin_load('helper', 'spatialhelper_index'); |
|
71 | + } |
|
72 | 72 | |
73 | - $this->spatial_idx = unserialize(io_readFile($idx_dir . '/spatial.idx', false), ['allowed_classes' => false]); |
|
74 | - } |
|
73 | + $this->spatial_idx = unserialize(io_readFile($idx_dir . '/spatial.idx', false), ['allowed_classes' => false]); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Find locations based on the coordinate pair. |
|
78 | - * |
|
79 | - * @param float $lat |
|
80 | - * The y coordinate (or latitude) |
|
81 | - * @param float $lon |
|
82 | - * The x coordinate (or longitude) |
|
83 | - */ |
|
84 | - public function findNearbyLatLon(float $lat, float $lon): array { |
|
85 | - $geometry = new Point($lon, $lat); |
|
86 | - return $this->findNearby($geometry->out('geohash'), $geometry); |
|
87 | - } |
|
76 | + /** |
|
77 | + * Find locations based on the coordinate pair. |
|
78 | + * |
|
79 | + * @param float $lat |
|
80 | + * The y coordinate (or latitude) |
|
81 | + * @param float $lon |
|
82 | + * The x coordinate (or longitude) |
|
83 | + */ |
|
84 | + public function findNearbyLatLon(float $lat, float $lon): array { |
|
85 | + $geometry = new Point($lon, $lat); |
|
86 | + return $this->findNearby($geometry->out('geohash'), $geometry); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * finds nearby elements in the index based on the geohash. |
|
91 | - * returns a list of documents and the bunding box. |
|
92 | - * |
|
93 | - * @param string $geohash |
|
94 | - * @param Point|null $p |
|
95 | - * optional point |
|
96 | - * @return array of ... |
|
97 | - * @throws Exception |
|
98 | - */ |
|
99 | - public function findNearby(string $geohash, Point $p = null): array { |
|
100 | - $_geohashClass = new Geohash(); |
|
101 | - if(!$p) { |
|
102 | - $decodedPoint = $_geohashClass->read($geohash); |
|
103 | - } else { |
|
104 | - $decodedPoint = $p; |
|
105 | - } |
|
89 | + /** |
|
90 | + * finds nearby elements in the index based on the geohash. |
|
91 | + * returns a list of documents and the bunding box. |
|
92 | + * |
|
93 | + * @param string $geohash |
|
94 | + * @param Point|null $p |
|
95 | + * optional point |
|
96 | + * @return array of ... |
|
97 | + * @throws Exception |
|
98 | + */ |
|
99 | + public function findNearby(string $geohash, Point $p = null): array { |
|
100 | + $_geohashClass = new Geohash(); |
|
101 | + if(!$p) { |
|
102 | + $decodedPoint = $_geohashClass->read($geohash); |
|
103 | + } else { |
|
104 | + $decodedPoint = $p; |
|
105 | + } |
|
106 | 106 | |
107 | - // find adjacent blocks |
|
108 | - $adjacent = array(); |
|
109 | - $adjacent ['center'] = $geohash; |
|
110 | - $adjacent ['top'] = Geohash::adjacent($adjacent ['center'], 'top'); |
|
111 | - $adjacent ['bottom'] = Geohash::adjacent($adjacent ['center'], 'bottom'); |
|
112 | - $adjacent ['right'] = Geohash::adjacent($adjacent ['center'], 'right'); |
|
113 | - $adjacent ['left'] = Geohash::adjacent($adjacent ['center'], 'left'); |
|
114 | - $adjacent ['topleft'] = Geohash::adjacent($adjacent ['left'], 'top'); |
|
115 | - $adjacent ['topright'] = Geohash::adjacent($adjacent ['right'], 'top'); |
|
116 | - $adjacent ['bottomright'] = Geohash::adjacent($adjacent ['right'], 'bottom'); |
|
117 | - $adjacent ['bottomleft'] = Geohash::adjacent($adjacent ['left'], 'bottom'); |
|
118 | - dbglog($adjacent, "adjacent geo hashes:"); |
|
107 | + // find adjacent blocks |
|
108 | + $adjacent = array(); |
|
109 | + $adjacent ['center'] = $geohash; |
|
110 | + $adjacent ['top'] = Geohash::adjacent($adjacent ['center'], 'top'); |
|
111 | + $adjacent ['bottom'] = Geohash::adjacent($adjacent ['center'], 'bottom'); |
|
112 | + $adjacent ['right'] = Geohash::adjacent($adjacent ['center'], 'right'); |
|
113 | + $adjacent ['left'] = Geohash::adjacent($adjacent ['center'], 'left'); |
|
114 | + $adjacent ['topleft'] = Geohash::adjacent($adjacent ['left'], 'top'); |
|
115 | + $adjacent ['topright'] = Geohash::adjacent($adjacent ['right'], 'top'); |
|
116 | + $adjacent ['bottomright'] = Geohash::adjacent($adjacent ['right'], 'bottom'); |
|
117 | + $adjacent ['bottomleft'] = Geohash::adjacent($adjacent ['left'], 'bottom'); |
|
118 | + dbglog($adjacent, "adjacent geo hashes:"); |
|
119 | 119 | |
120 | - // find all the pages in the index that overlap with the adjacent hashes |
|
121 | - $docIds = array(); |
|
122 | - foreach($adjacent as $adjHash) { |
|
123 | - if(is_array($this->spatial_idx)) { |
|
124 | - foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
125 | - if(strpos($_geohash, $adjHash) !== false) { |
|
126 | - // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
|
127 | - // if $adjHash similar to geohash |
|
128 | - $docIds = array_merge($docIds, $_docIds); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - $docIds = array_unique($docIds); |
|
134 | - dbglog($docIds, "found docIDs"); |
|
120 | + // find all the pages in the index that overlap with the adjacent hashes |
|
121 | + $docIds = array(); |
|
122 | + foreach($adjacent as $adjHash) { |
|
123 | + if(is_array($this->spatial_idx)) { |
|
124 | + foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
125 | + if(strpos($_geohash, $adjHash) !== false) { |
|
126 | + // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
|
127 | + // if $adjHash similar to geohash |
|
128 | + $docIds = array_merge($docIds, $_docIds); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + $docIds = array_unique($docIds); |
|
134 | + dbglog($docIds, "found docIDs"); |
|
135 | 135 | |
136 | - // create associative array of pages + calculate distance |
|
137 | - $pages = array(); |
|
138 | - $media = array(); |
|
139 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
136 | + // create associative array of pages + calculate distance |
|
137 | + $pages = array(); |
|
138 | + $media = array(); |
|
139 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
140 | 140 | |
141 | - foreach($docIds as $id) { |
|
142 | - if(strpos($id, 'media__', 0) === 0) { |
|
143 | - $id = substr($id, strlen('media__')); |
|
144 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
145 | - $point = $indexer->getCoordsFromExif($id); |
|
146 | - $line = new LineString( |
|
147 | - [ |
|
148 | - $decodedPoint, |
|
149 | - $point |
|
150 | - ] |
|
151 | - ); |
|
152 | - $media [] = array( |
|
153 | - 'id' => $id, |
|
154 | - 'distance' => (int) ($line->greatCircleLength()), |
|
155 | - 'lat' => $point->y(), |
|
156 | - 'lon' => $point->x() |
|
157 | - // optionally add other meta such as tag, description... |
|
158 | - ); |
|
159 | - } |
|
160 | - } else { |
|
161 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
162 | - $geotags = p_get_metadata($id, 'geo'); |
|
163 | - $point = new Point($geotags ['lon'], $geotags ['lat']); |
|
164 | - $line = new LineString( |
|
165 | - [ |
|
166 | - $decodedPoint, |
|
167 | - $point |
|
168 | - ] |
|
169 | - ); |
|
170 | - $pages [] = array( |
|
171 | - 'id' => $id, |
|
172 | - 'distance' => (int) ($line->greatCircleLength()), |
|
173 | - 'description' => p_get_metadata($id, 'description')['abstract'], |
|
174 | - 'lat' => $geotags ['lat'], |
|
175 | - 'lon' => $geotags ['lon'] |
|
176 | - // optionally add other meta such as tag... |
|
177 | - ); |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
141 | + foreach($docIds as $id) { |
|
142 | + if(strpos($id, 'media__', 0) === 0) { |
|
143 | + $id = substr($id, strlen('media__')); |
|
144 | + if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
145 | + $point = $indexer->getCoordsFromExif($id); |
|
146 | + $line = new LineString( |
|
147 | + [ |
|
148 | + $decodedPoint, |
|
149 | + $point |
|
150 | + ] |
|
151 | + ); |
|
152 | + $media [] = array( |
|
153 | + 'id' => $id, |
|
154 | + 'distance' => (int) ($line->greatCircleLength()), |
|
155 | + 'lat' => $point->y(), |
|
156 | + 'lon' => $point->x() |
|
157 | + // optionally add other meta such as tag, description... |
|
158 | + ); |
|
159 | + } |
|
160 | + } else { |
|
161 | + if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
162 | + $geotags = p_get_metadata($id, 'geo'); |
|
163 | + $point = new Point($geotags ['lon'], $geotags ['lat']); |
|
164 | + $line = new LineString( |
|
165 | + [ |
|
166 | + $decodedPoint, |
|
167 | + $point |
|
168 | + ] |
|
169 | + ); |
|
170 | + $pages [] = array( |
|
171 | + 'id' => $id, |
|
172 | + 'distance' => (int) ($line->greatCircleLength()), |
|
173 | + 'description' => p_get_metadata($id, 'description')['abstract'], |
|
174 | + 'lat' => $geotags ['lat'], |
|
175 | + 'lon' => $geotags ['lon'] |
|
176 | + // optionally add other meta such as tag... |
|
177 | + ); |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | 181 | |
182 | - // sort all the pages/media using distance |
|
183 | - usort( |
|
184 | - $pages, static function ($a, $b) { |
|
185 | - return strnatcmp($a ['distance'], $b ['distance']); |
|
186 | - } |
|
187 | - ); |
|
188 | - usort( |
|
189 | - $media, static function ($a, $b) { |
|
190 | - return strnatcmp($a ['distance'], $b ['distance']); |
|
191 | - } |
|
192 | - ); |
|
182 | + // sort all the pages/media using distance |
|
183 | + usort( |
|
184 | + $pages, static function ($a, $b) { |
|
185 | + return strnatcmp($a ['distance'], $b ['distance']); |
|
186 | + } |
|
187 | + ); |
|
188 | + usort( |
|
189 | + $media, static function ($a, $b) { |
|
190 | + return strnatcmp($a ['distance'], $b ['distance']); |
|
191 | + } |
|
192 | + ); |
|
193 | 193 | |
194 | - return array( |
|
195 | - 'pages' => $pages, |
|
196 | - 'media' => $media, |
|
197 | - 'lat' => $decodedPoint->y(), |
|
198 | - 'lon' => $decodedPoint->x(), |
|
199 | - 'geohash' => $geohash, |
|
200 | - 'precision' => $this->precision [strlen($geohash)] |
|
201 | - ); |
|
202 | - } |
|
194 | + return array( |
|
195 | + 'pages' => $pages, |
|
196 | + 'media' => $media, |
|
197 | + 'lat' => $decodedPoint->y(), |
|
198 | + 'lon' => $decodedPoint->x(), |
|
199 | + 'geohash' => $geohash, |
|
200 | + 'precision' => $this->precision [strlen($geohash)] |
|
201 | + ); |
|
202 | + } |
|
203 | 203 | } |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | // parent::__construct (); |
60 | 60 | global $conf; |
61 | 61 | |
62 | - if(!plugin_load('helper', 'geophp', false, true)) { |
|
62 | + if (!plugin_load('helper', 'geophp', false, true)) { |
|
63 | 63 | $message = |
64 | 64 | 'helper_plugin_spatialhelper_search::spatialhelper_search: required geophp plugin is not available.'; |
65 | 65 | msg($message, -1); |
66 | 66 | } |
67 | 67 | |
68 | 68 | $idx_dir = $conf ['indexdir']; |
69 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
69 | + if (!@file_exists($idx_dir . '/spatial.idx')) { |
|
70 | 70 | plugin_load('helper', 'spatialhelper_index'); |
71 | 71 | } |
72 | 72 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function findNearby(string $geohash, Point $p = null): array { |
100 | 100 | $_geohashClass = new Geohash(); |
101 | - if(!$p) { |
|
101 | + if (!$p) { |
|
102 | 102 | $decodedPoint = $_geohashClass->read($geohash); |
103 | 103 | } else { |
104 | 104 | $decodedPoint = $p; |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | |
120 | 120 | // find all the pages in the index that overlap with the adjacent hashes |
121 | 121 | $docIds = array(); |
122 | - foreach($adjacent as $adjHash) { |
|
123 | - if(is_array($this->spatial_idx)) { |
|
124 | - foreach($this->spatial_idx as $_geohash => $_docIds) { |
|
125 | - if(strpos($_geohash, $adjHash) !== false) { |
|
122 | + foreach ($adjacent as $adjHash) { |
|
123 | + if (is_array($this->spatial_idx)) { |
|
124 | + foreach ($this->spatial_idx as $_geohash => $_docIds) { |
|
125 | + if (strpos($_geohash, $adjHash) !== false) { |
|
126 | 126 | // dbglog ( "Found adjacent geo hash: $adjHash in $_geohash" ); |
127 | 127 | // if $adjHash similar to geohash |
128 | 128 | $docIds = array_merge($docIds, $_docIds); |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | $media = array(); |
139 | 139 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
140 | 140 | |
141 | - foreach($docIds as $id) { |
|
142 | - if(strpos($id, 'media__', 0) === 0) { |
|
141 | + foreach ($docIds as $id) { |
|
142 | + if (strpos($id, 'media__', 0) === 0) { |
|
143 | 143 | $id = substr($id, strlen('media__')); |
144 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
144 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
145 | 145 | $point = $indexer->getCoordsFromExif($id); |
146 | 146 | $line = new LineString( |
147 | 147 | [ |
@@ -151,14 +151,14 @@ discard block |
||
151 | 151 | ); |
152 | 152 | $media [] = array( |
153 | 153 | 'id' => $id, |
154 | - 'distance' => (int) ($line->greatCircleLength()), |
|
154 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
155 | 155 | 'lat' => $point->y(), |
156 | 156 | 'lon' => $point->x() |
157 | 157 | // optionally add other meta such as tag, description... |
158 | 158 | ); |
159 | 159 | } |
160 | 160 | } else { |
161 | - if(auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
161 | + if (auth_quickaclcheck($id) >= /*AUTH_READ*/ 1) { |
|
162 | 162 | $geotags = p_get_metadata($id, 'geo'); |
163 | 163 | $point = new Point($geotags ['lon'], $geotags ['lat']); |
164 | 164 | $line = new LineString( |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ); |
170 | 170 | $pages [] = array( |
171 | 171 | 'id' => $id, |
172 | - 'distance' => (int) ($line->greatCircleLength()), |
|
172 | + 'distance' => ( int ) ($line->greatCircleLength()), |
|
173 | 173 | 'description' => p_get_metadata($id, 'description')['abstract'], |
174 | 174 | 'lat' => $geotags ['lat'], |
175 | 175 | 'lon' => $geotags ['lon'] |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | |
182 | 182 | // sort all the pages/media using distance |
183 | 183 | usort( |
184 | - $pages, static function ($a, $b) { |
|
184 | + $pages, static function($a, $b) { |
|
185 | 185 | return strnatcmp($a ['distance'], $b ['distance']); |
186 | 186 | } |
187 | 187 | ); |
188 | 188 | usort( |
189 | - $media, static function ($a, $b) { |
|
189 | + $media, static function($a, $b) { |
|
190 | 190 | return strnatcmp($a ['distance'], $b ['distance']); |
191 | 191 | } |
192 | 192 | ); |
@@ -22,224 +22,224 @@ |
||
22 | 22 | * @author Mark Prins |
23 | 23 | */ |
24 | 24 | class helper_plugin_spatialhelper_sitemap extends DokuWiki_Plugin { |
25 | - /** |
|
26 | - * spatial index. |
|
27 | - */ |
|
28 | - private $spatial_idx; |
|
29 | - |
|
30 | - /** |
|
31 | - * constructor, load spatial index. |
|
32 | - */ |
|
33 | - public function __construct() { |
|
34 | - global $conf; |
|
35 | - $idx_dir = $conf['indexdir']; |
|
36 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
37 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
38 | - if($indexer !== null) { |
|
39 | - $indexer->generateSpatialIndex(); |
|
40 | - } |
|
41 | - } |
|
42 | - $this->spatial_idx = unserialize( |
|
43 | - io_readFile($fn = $idx_dir . '/spatial.idx', false), |
|
44 | - ['allowed_classes' => false] |
|
45 | - ); |
|
46 | - } |
|
47 | - |
|
48 | - final public function getMethods(): array { |
|
49 | - $result[] = array( |
|
50 | - 'name' => 'createGeoRSSSitemap', |
|
51 | - 'desc' => 'create a spatial sitemap in GeoRSS format.', |
|
52 | - 'params' => array( |
|
53 | - 'path' => 'string' |
|
54 | - ), |
|
55 | - 'return' => array( |
|
56 | - 'success' => 'boolean' |
|
57 | - ) |
|
58 | - ); |
|
59 | - $result[] = array( |
|
60 | - 'name' => 'createKMLSitemap', |
|
61 | - 'desc' => 'create a spatial sitemap in KML format.', |
|
62 | - 'params' => array( |
|
63 | - 'path' => 'string' |
|
64 | - ), |
|
65 | - 'return' => array( |
|
66 | - 'success' => 'boolean' |
|
67 | - ) |
|
68 | - ); |
|
69 | - return $result; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Create a GeoRSS Simple sitemap (Atom). |
|
74 | - * |
|
75 | - * @param string $mediaID id |
|
76 | - * for the GeoRSS file |
|
77 | - */ |
|
78 | - final public function createGeoRSSSitemap(string $mediaID): bool { |
|
79 | - global $conf; |
|
80 | - $namespace = getNS($mediaID); |
|
81 | - |
|
82 | - $idTag = 'tag:' . parse_url(DOKU_URL, PHP_URL_HOST) . ','; |
|
83 | - |
|
84 | - $RSSstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; |
|
85 | - $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '; |
|
86 | - $RSSstart .= 'xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF; |
|
87 | - $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF; |
|
88 | - if(!empty($conf['tagline'])) { |
|
89 | - $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF; |
|
90 | - } |
|
91 | - $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF; |
|
92 | - $RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF; |
|
93 | - $RSSstart .= '<link href="' . ml($mediaID, '', true, '&', true) . '" rel="self" />' . DOKU_LF; |
|
94 | - $RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF; |
|
95 | - $RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) |
|
96 | - . '</id>' . DOKU_LF; |
|
97 | - $RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF; |
|
98 | - |
|
99 | - $RSSend = '</feed>' . DOKU_LF; |
|
100 | - |
|
101 | - io_createNamespace($mediaID, 'media'); |
|
102 | - @touch(mediaFN($mediaID)); |
|
103 | - @chmod(mediaFN($mediaID), $conf['fmode']); |
|
104 | - $fh = fopen(mediaFN($mediaID), 'wb'); |
|
105 | - fwrite($fh, $RSSstart); |
|
106 | - |
|
107 | - foreach($this->spatial_idx as $idxEntry) { |
|
108 | - // get list of id's |
|
109 | - foreach($idxEntry as $id) { |
|
110 | - // for document item in the index |
|
111 | - if(strpos($id, 'media__', 0) !== 0) { |
|
112 | - if($this->skipPage($id, $namespace)) { |
|
113 | - continue; |
|
114 | - } |
|
115 | - |
|
116 | - $meta = p_get_metadata($id); |
|
117 | - |
|
118 | - // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); |
|
119 | - $desc = strip_tags($meta['description']['abstract']); |
|
120 | - |
|
121 | - $entry = '<entry>' . DOKU_LF; |
|
122 | - $entry .= ' <title>' . $meta['title'] . '</title>' . DOKU_LF; |
|
123 | - $entry .= ' <summary>' . $desc . '</summary>' . DOKU_LF; |
|
124 | - $entry .= ' <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] |
|
125 | - . '</georss:point>' . DOKU_LF; |
|
126 | - if(!empty($meta['geo']['alt'])) { |
|
127 | - $entry .= ' <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF; |
|
128 | - } |
|
129 | - $entry .= ' <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF; |
|
130 | - if(empty($meta['creator'])) { |
|
131 | - $meta['creator'] = $conf['title']; |
|
132 | - } |
|
133 | - $entry .= ' <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF; |
|
134 | - $entry .= ' <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF; |
|
135 | - $entry .= ' <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF; |
|
136 | - $entry .= ' <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':' |
|
137 | - . parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF; |
|
138 | - $entry .= '</entry>' . DOKU_LF; |
|
139 | - fwrite($fh, $entry); |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - fwrite($fh, $RSSend); |
|
145 | - return fclose($fh); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * will return true for non-public or hidden pages or pages that are not below or in the namespace. |
|
150 | - */ |
|
151 | - private function skipPage(string $id, string $namespace): bool { |
|
152 | - dbglog("helper_plugin_spatialhelper_sitemap::skipPage, check for $id in $namespace"); |
|
153 | - if(isHiddenPage($id)) { |
|
154 | - return true; |
|
155 | - } |
|
156 | - if(auth_aclcheck($id, '', null) < AUTH_READ) { |
|
157 | - return true; |
|
158 | - } |
|
159 | - |
|
160 | - if(!empty($namespace)) { |
|
161 | - // only if id is in or below namespace |
|
162 | - if(0 !== strpos(getNS($id), $namespace)) { |
|
163 | - // dbglog("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace"); |
|
164 | - return true; |
|
165 | - } |
|
166 | - } |
|
167 | - return false; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Create a KML sitemap. |
|
172 | - * |
|
173 | - * @param string $mediaID id for the KML file |
|
174 | - */ |
|
175 | - final public function createKMLSitemap(string $mediaID): bool { |
|
176 | - global $conf; |
|
177 | - $namespace = getNS($mediaID); |
|
178 | - |
|
179 | - $KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; |
|
180 | - $KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" '; |
|
181 | - $KMLstart .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '; |
|
182 | - $KMLstart .= 'xmlns:atom="http://www.w3.org/2005/Atom"'; |
|
183 | - $KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 '; |
|
184 | - $KMLstart .= 'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF; |
|
185 | - $KMLstart .= '<Document id="root_doc">' . DOKU_LF; |
|
186 | - $KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF; |
|
187 | - $KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF; |
|
188 | - $KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF; |
|
189 | - $KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>'; |
|
190 | - $KMLstart .= '<Icon><href>' |
|
191 | - . DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF; |
|
192 | - |
|
193 | - $KMLend = '</Document>' . DOKU_LF . '</kml>'; |
|
194 | - |
|
195 | - io_createNamespace($mediaID, 'media'); |
|
196 | - @touch(mediaFN($mediaID)); |
|
197 | - @chmod(mediaFN($mediaID), $conf['fmode']); |
|
198 | - |
|
199 | - $fh = fopen(mediaFN($mediaID), 'wb'); |
|
200 | - fwrite($fh, $KMLstart); |
|
201 | - |
|
202 | - foreach($this->spatial_idx as $idxEntry) { |
|
203 | - // get list of id's |
|
204 | - foreach($idxEntry as $id) { |
|
205 | - // for document item in the index |
|
206 | - if(strpos($id, 'media__', 0) !== 0) { |
|
207 | - if($this->skipPage($id, $namespace)) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - |
|
211 | - $meta = p_get_metadata($id); |
|
212 | - |
|
213 | - // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); |
|
214 | - $desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>'; |
|
215 | - $desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>'; |
|
216 | - |
|
217 | - // create an entry and store it |
|
218 | - $plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF; |
|
219 | - $plcm .= ' <name>' . $meta['title'] . '</name>' . DOKU_LF; |
|
220 | - // TODO escape quotes in: title="' . $meta['title'] . '" |
|
221 | - $plcm .= ' <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' |
|
222 | - . DOKU_LF; |
|
223 | - if(!empty($meta['creator'])) { |
|
224 | - $plcm .= ' <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' |
|
225 | - . DOKU_LF; |
|
226 | - } |
|
227 | - |
|
228 | - $plcm .= ' <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF; |
|
229 | - $plcm .= ' <styleUrl>#icon</styleUrl>' . DOKU_LF; |
|
230 | - |
|
231 | - $plcm .= ' <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat']; |
|
232 | - if(!empty($meta['geo']['alt'])) { |
|
233 | - $plcm .= ',' . $meta['geo']['alt']; |
|
234 | - } |
|
235 | - $plcm .= '</coordinates></Point>' . DOKU_LF; |
|
236 | - $plcm .= '</Placemark>' . DOKU_LF; |
|
237 | - |
|
238 | - fwrite($fh, $plcm); |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - fwrite($fh, $KMLend); |
|
243 | - return fclose($fh); |
|
244 | - } |
|
25 | + /** |
|
26 | + * spatial index. |
|
27 | + */ |
|
28 | + private $spatial_idx; |
|
29 | + |
|
30 | + /** |
|
31 | + * constructor, load spatial index. |
|
32 | + */ |
|
33 | + public function __construct() { |
|
34 | + global $conf; |
|
35 | + $idx_dir = $conf['indexdir']; |
|
36 | + if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
37 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
38 | + if($indexer !== null) { |
|
39 | + $indexer->generateSpatialIndex(); |
|
40 | + } |
|
41 | + } |
|
42 | + $this->spatial_idx = unserialize( |
|
43 | + io_readFile($fn = $idx_dir . '/spatial.idx', false), |
|
44 | + ['allowed_classes' => false] |
|
45 | + ); |
|
46 | + } |
|
47 | + |
|
48 | + final public function getMethods(): array { |
|
49 | + $result[] = array( |
|
50 | + 'name' => 'createGeoRSSSitemap', |
|
51 | + 'desc' => 'create a spatial sitemap in GeoRSS format.', |
|
52 | + 'params' => array( |
|
53 | + 'path' => 'string' |
|
54 | + ), |
|
55 | + 'return' => array( |
|
56 | + 'success' => 'boolean' |
|
57 | + ) |
|
58 | + ); |
|
59 | + $result[] = array( |
|
60 | + 'name' => 'createKMLSitemap', |
|
61 | + 'desc' => 'create a spatial sitemap in KML format.', |
|
62 | + 'params' => array( |
|
63 | + 'path' => 'string' |
|
64 | + ), |
|
65 | + 'return' => array( |
|
66 | + 'success' => 'boolean' |
|
67 | + ) |
|
68 | + ); |
|
69 | + return $result; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Create a GeoRSS Simple sitemap (Atom). |
|
74 | + * |
|
75 | + * @param string $mediaID id |
|
76 | + * for the GeoRSS file |
|
77 | + */ |
|
78 | + final public function createGeoRSSSitemap(string $mediaID): bool { |
|
79 | + global $conf; |
|
80 | + $namespace = getNS($mediaID); |
|
81 | + |
|
82 | + $idTag = 'tag:' . parse_url(DOKU_URL, PHP_URL_HOST) . ','; |
|
83 | + |
|
84 | + $RSSstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; |
|
85 | + $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '; |
|
86 | + $RSSstart .= 'xmlns:dc="http://purl.org/dc/elements/1.1/">' . DOKU_LF; |
|
87 | + $RSSstart .= '<title>' . $conf['title'] . ' spatial feed</title>' . DOKU_LF; |
|
88 | + if(!empty($conf['tagline'])) { |
|
89 | + $RSSstart .= '<subtitle>' . $conf['tagline'] . '</subtitle>' . DOKU_LF; |
|
90 | + } |
|
91 | + $RSSstart .= '<dc:publisher>' . $conf['title'] . '</dc:publisher>' . DOKU_LF; |
|
92 | + $RSSstart .= '<link href="' . DOKU_URL . '" />' . DOKU_LF; |
|
93 | + $RSSstart .= '<link href="' . ml($mediaID, '', true, '&', true) . '" rel="self" />' . DOKU_LF; |
|
94 | + $RSSstart .= '<updated>' . date(DATE_ATOM) . '</updated>' . DOKU_LF; |
|
95 | + $RSSstart .= '<id>' . $idTag . date("Y-m-d") . ':' . parse_url(ml($mediaID), PHP_URL_PATH) |
|
96 | + . '</id>' . DOKU_LF; |
|
97 | + $RSSstart .= '<rights>' . $conf['license'] . '</rights>' . DOKU_LF; |
|
98 | + |
|
99 | + $RSSend = '</feed>' . DOKU_LF; |
|
100 | + |
|
101 | + io_createNamespace($mediaID, 'media'); |
|
102 | + @touch(mediaFN($mediaID)); |
|
103 | + @chmod(mediaFN($mediaID), $conf['fmode']); |
|
104 | + $fh = fopen(mediaFN($mediaID), 'wb'); |
|
105 | + fwrite($fh, $RSSstart); |
|
106 | + |
|
107 | + foreach($this->spatial_idx as $idxEntry) { |
|
108 | + // get list of id's |
|
109 | + foreach($idxEntry as $id) { |
|
110 | + // for document item in the index |
|
111 | + if(strpos($id, 'media__', 0) !== 0) { |
|
112 | + if($this->skipPage($id, $namespace)) { |
|
113 | + continue; |
|
114 | + } |
|
115 | + |
|
116 | + $meta = p_get_metadata($id); |
|
117 | + |
|
118 | + // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); |
|
119 | + $desc = strip_tags($meta['description']['abstract']); |
|
120 | + |
|
121 | + $entry = '<entry>' . DOKU_LF; |
|
122 | + $entry .= ' <title>' . $meta['title'] . '</title>' . DOKU_LF; |
|
123 | + $entry .= ' <summary>' . $desc . '</summary>' . DOKU_LF; |
|
124 | + $entry .= ' <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] |
|
125 | + . '</georss:point>' . DOKU_LF; |
|
126 | + if(!empty($meta['geo']['alt'])) { |
|
127 | + $entry .= ' <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF; |
|
128 | + } |
|
129 | + $entry .= ' <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF; |
|
130 | + if(empty($meta['creator'])) { |
|
131 | + $meta['creator'] = $conf['title']; |
|
132 | + } |
|
133 | + $entry .= ' <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF; |
|
134 | + $entry .= ' <updated>' . date_iso8601($meta['date']['modified']) . '</updated>' . DOKU_LF; |
|
135 | + $entry .= ' <published>' . date_iso8601($meta['date']['created']) . '</published>' . DOKU_LF; |
|
136 | + $entry .= ' <id>' . $idTag . date("Y-m-d", $meta['date']['modified']) . ':' |
|
137 | + . parse_url(wl($id), PHP_URL_PATH) . '</id>' . DOKU_LF; |
|
138 | + $entry .= '</entry>' . DOKU_LF; |
|
139 | + fwrite($fh, $entry); |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + fwrite($fh, $RSSend); |
|
145 | + return fclose($fh); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * will return true for non-public or hidden pages or pages that are not below or in the namespace. |
|
150 | + */ |
|
151 | + private function skipPage(string $id, string $namespace): bool { |
|
152 | + dbglog("helper_plugin_spatialhelper_sitemap::skipPage, check for $id in $namespace"); |
|
153 | + if(isHiddenPage($id)) { |
|
154 | + return true; |
|
155 | + } |
|
156 | + if(auth_aclcheck($id, '', null) < AUTH_READ) { |
|
157 | + return true; |
|
158 | + } |
|
159 | + |
|
160 | + if(!empty($namespace)) { |
|
161 | + // only if id is in or below namespace |
|
162 | + if(0 !== strpos(getNS($id), $namespace)) { |
|
163 | + // dbglog("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace"); |
|
164 | + return true; |
|
165 | + } |
|
166 | + } |
|
167 | + return false; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Create a KML sitemap. |
|
172 | + * |
|
173 | + * @param string $mediaID id for the KML file |
|
174 | + */ |
|
175 | + final public function createKMLSitemap(string $mediaID): bool { |
|
176 | + global $conf; |
|
177 | + $namespace = getNS($mediaID); |
|
178 | + |
|
179 | + $KMLstart = '<?xml version="1.0" encoding="UTF-8"?>' . DOKU_LF; |
|
180 | + $KMLstart .= '<kml xmlns="http://www.opengis.net/kml/2.2" '; |
|
181 | + $KMLstart .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '; |
|
182 | + $KMLstart .= 'xmlns:atom="http://www.w3.org/2005/Atom"'; |
|
183 | + $KMLstart .= ' xsi:schemaLocation="http://www.opengis.net/kml/2.2 '; |
|
184 | + $KMLstart .= 'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">' . DOKU_LF; |
|
185 | + $KMLstart .= '<Document id="root_doc">' . DOKU_LF; |
|
186 | + $KMLstart .= '<name>' . $conf['title'] . ' spatial sitemap</name>' . DOKU_LF; |
|
187 | + $KMLstart .= '<atom:link href="' . DOKU_URL . '" rel="related" type="text/html" />' . DOKU_LF; |
|
188 | + $KMLstart .= '<!-- atom:updated>' . date(DATE_ATOM) . '</atom:updated -->' . DOKU_LF; |
|
189 | + $KMLstart .= '<Style id="icon"><IconStyle><color>ffffffff</color><scale>1</scale>'; |
|
190 | + $KMLstart .= '<Icon><href>' |
|
191 | + . DOKU_BASE . 'lib/plugins/spatialhelper/wikiitem.png</href></Icon></IconStyle></Style>' . DOKU_LF; |
|
192 | + |
|
193 | + $KMLend = '</Document>' . DOKU_LF . '</kml>'; |
|
194 | + |
|
195 | + io_createNamespace($mediaID, 'media'); |
|
196 | + @touch(mediaFN($mediaID)); |
|
197 | + @chmod(mediaFN($mediaID), $conf['fmode']); |
|
198 | + |
|
199 | + $fh = fopen(mediaFN($mediaID), 'wb'); |
|
200 | + fwrite($fh, $KMLstart); |
|
201 | + |
|
202 | + foreach($this->spatial_idx as $idxEntry) { |
|
203 | + // get list of id's |
|
204 | + foreach($idxEntry as $id) { |
|
205 | + // for document item in the index |
|
206 | + if(strpos($id, 'media__', 0) !== 0) { |
|
207 | + if($this->skipPage($id, $namespace)) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + |
|
211 | + $meta = p_get_metadata($id); |
|
212 | + |
|
213 | + // $desc = p_render('xhtmlsummary', p_get_instructions($meta['description']['abstract']), $info); |
|
214 | + $desc = '<p>' . strip_tags($meta['description']['abstract']) . '</p>'; |
|
215 | + $desc .= '<p><a href="' . wl($id, '', true) . '">' . $meta['title'] . '</a></p>'; |
|
216 | + |
|
217 | + // create an entry and store it |
|
218 | + $plcm = '<Placemark id="crc32-' . hash('crc32', $id) . '">' . DOKU_LF; |
|
219 | + $plcm .= ' <name>' . $meta['title'] . '</name>' . DOKU_LF; |
|
220 | + // TODO escape quotes in: title="' . $meta['title'] . '" |
|
221 | + $plcm .= ' <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' |
|
222 | + . DOKU_LF; |
|
223 | + if(!empty($meta['creator'])) { |
|
224 | + $plcm .= ' <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' |
|
225 | + . DOKU_LF; |
|
226 | + } |
|
227 | + |
|
228 | + $plcm .= ' <description><![CDATA[' . $desc . ']]></description>' . DOKU_LF; |
|
229 | + $plcm .= ' <styleUrl>#icon</styleUrl>' . DOKU_LF; |
|
230 | + |
|
231 | + $plcm .= ' <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat']; |
|
232 | + if(!empty($meta['geo']['alt'])) { |
|
233 | + $plcm .= ',' . $meta['geo']['alt']; |
|
234 | + } |
|
235 | + $plcm .= '</coordinates></Point>' . DOKU_LF; |
|
236 | + $plcm .= '</Placemark>' . DOKU_LF; |
|
237 | + |
|
238 | + fwrite($fh, $plcm); |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + fwrite($fh, $KMLend); |
|
243 | + return fclose($fh); |
|
244 | + } |
|
245 | 245 | } |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | public function __construct() { |
34 | 34 | global $conf; |
35 | 35 | $idx_dir = $conf['indexdir']; |
36 | - if(!@file_exists($idx_dir . '/spatial.idx')) { |
|
36 | + if (!@file_exists($idx_dir . '/spatial.idx')) { |
|
37 | 37 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
38 | - if($indexer !== null) { |
|
38 | + if ($indexer !== null) { |
|
39 | 39 | $indexer->generateSpatialIndex(); |
40 | 40 | } |
41 | 41 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $RSSstart .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" '; |
86 | 86 | $RSSstart .= '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; |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | $fh = fopen(mediaFN($mediaID), 'wb'); |
105 | 105 | fwrite($fh, $RSSstart); |
106 | 106 | |
107 | - foreach($this->spatial_idx as $idxEntry) { |
|
107 | + foreach ($this->spatial_idx as $idxEntry) { |
|
108 | 108 | // get list of id's |
109 | - foreach($idxEntry as $id) { |
|
109 | + foreach ($idxEntry as $id) { |
|
110 | 110 | // for document item in the index |
111 | - if(strpos($id, 'media__', 0) !== 0) { |
|
112 | - if($this->skipPage($id, $namespace)) { |
|
111 | + if (strpos($id, 'media__', 0) !== 0) { |
|
112 | + if ($this->skipPage($id, $namespace)) { |
|
113 | 113 | continue; |
114 | 114 | } |
115 | 115 | |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | $entry .= ' <summary>' . $desc . '</summary>' . DOKU_LF; |
124 | 124 | $entry .= ' <georss:point>' . $meta['geo']['lat'] . ' ' . $meta['geo']['lon'] |
125 | 125 | . '</georss:point>' . DOKU_LF; |
126 | - if(!empty($meta['geo']['alt'])) { |
|
126 | + if (!empty($meta['geo']['alt'])) { |
|
127 | 127 | $entry .= ' <georss:elev>' . $meta['geo']['alt'] . '</georss:elev>' . DOKU_LF; |
128 | 128 | } |
129 | 129 | $entry .= ' <link href="' . wl($id) . '" rel="alternate" type="text/html" />' . DOKU_LF; |
130 | - if(empty($meta['creator'])) { |
|
130 | + if (empty($meta['creator'])) { |
|
131 | 131 | $meta['creator'] = $conf['title']; |
132 | 132 | } |
133 | 133 | $entry .= ' <author><name>' . $meta['creator'] . '</name></author>' . DOKU_LF; |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | */ |
151 | 151 | private function skipPage(string $id, string $namespace): bool { |
152 | 152 | dbglog("helper_plugin_spatialhelper_sitemap::skipPage, check for $id in $namespace"); |
153 | - if(isHiddenPage($id)) { |
|
153 | + if (isHiddenPage($id)) { |
|
154 | 154 | return true; |
155 | 155 | } |
156 | - if(auth_aclcheck($id, '', null) < AUTH_READ) { |
|
156 | + if (auth_aclcheck($id, '', null) < AUTH_READ) { |
|
157 | 157 | return true; |
158 | 158 | } |
159 | 159 | |
160 | - if(!empty($namespace)) { |
|
160 | + if (!empty($namespace)) { |
|
161 | 161 | // only if id is in or below namespace |
162 | - if(0 !== strpos(getNS($id), $namespace)) { |
|
162 | + if (0 !== strpos(getNS($id), $namespace)) { |
|
163 | 163 | // dbglog("helper_plugin_spatialhelper_sitemap::skipPage, skipping $id, not in $namespace"); |
164 | 164 | return true; |
165 | 165 | } |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | $fh = fopen(mediaFN($mediaID), 'wb'); |
200 | 200 | fwrite($fh, $KMLstart); |
201 | 201 | |
202 | - foreach($this->spatial_idx as $idxEntry) { |
|
202 | + foreach ($this->spatial_idx as $idxEntry) { |
|
203 | 203 | // get list of id's |
204 | - foreach($idxEntry as $id) { |
|
204 | + foreach ($idxEntry as $id) { |
|
205 | 205 | // for document item in the index |
206 | - if(strpos($id, 'media__', 0) !== 0) { |
|
207 | - if($this->skipPage($id, $namespace)) { |
|
206 | + if (strpos($id, 'media__', 0) !== 0) { |
|
207 | + if ($this->skipPage($id, $namespace)) { |
|
208 | 208 | continue; |
209 | 209 | } |
210 | 210 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | // TODO escape quotes in: title="' . $meta['title'] . '" |
221 | 221 | $plcm .= ' <atom:link href="' . wl($id, '' . true) . '" rel="alternate" type="text/html" />' |
222 | 222 | . DOKU_LF; |
223 | - if(!empty($meta['creator'])) { |
|
223 | + if (!empty($meta['creator'])) { |
|
224 | 224 | $plcm .= ' <atom:author><atom:name>' . $meta['creator'] . '</atom:name></atom:author>' |
225 | 225 | . DOKU_LF; |
226 | 226 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $plcm .= ' <styleUrl>#icon</styleUrl>' . DOKU_LF; |
230 | 230 | |
231 | 231 | $plcm .= ' <Point><coordinates>' . $meta['geo']['lon'] . ',' . $meta['geo']['lat']; |
232 | - if(!empty($meta['geo']['alt'])) { |
|
232 | + if (!empty($meta['geo']['alt'])) { |
|
233 | 233 | $plcm .= ',' . $meta['geo']['alt']; |
234 | 234 | } |
235 | 235 | $plcm .= '</coordinates></Point>' . DOKU_LF; |
@@ -102,18 +102,18 @@ discard block |
||
102 | 102 | // $data[3] – rev: The page revision, false for current wiki pages. |
103 | 103 | |
104 | 104 | dbglog($event->data, "Event data in removeFromIndex."); |
105 | - if(@file_exists($event->data [0] [0])) { |
|
105 | + if (@file_exists($event->data [0] [0])) { |
|
106 | 106 | // file not new |
107 | - if(!$event->data [0] [1]) { |
|
107 | + if (!$event->data [0] [1]) { |
|
108 | 108 | // file is empty, page is being deleted |
109 | - if(empty ($event->data [1])) { |
|
109 | + if (empty ($event->data [1])) { |
|
110 | 110 | // root namespace |
111 | 111 | $id = $event->data [2]; |
112 | 112 | } else { |
113 | 113 | $id = $event->data [1] . ":" . $event->data [2]; |
114 | 114 | } |
115 | 115 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
116 | - if($indexer) { |
|
116 | + if ($indexer) { |
|
117 | 117 | $indexer->deleteFromIndex($id); |
118 | 118 | } |
119 | 119 | } |
@@ -146,15 +146,15 @@ discard block |
||
146 | 146 | // $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already |
147 | 147 | // contains all public pages of the wiki |
148 | 148 | // $event→data['sitemap']: The path of the file the sitemap will be saved to. |
149 | - if($helper = plugin_load('helper', 'spatialhelper_sitemap')) { |
|
149 | + if ($helper = plugin_load('helper', 'spatialhelper_sitemap')) { |
|
150 | 150 | // dbglog($helper, "createSpatialSitemap loaded helper."); |
151 | 151 | |
152 | 152 | $kml = $helper->createKMLSitemap($this->getConf('media_kml')); |
153 | 153 | $rss = $helper->createGeoRSSSitemap($this->getConf('media_georss')); |
154 | 154 | |
155 | - if(!empty ($this->getConf('sitemap_namespaces'))) { |
|
155 | + if (!empty ($this->getConf('sitemap_namespaces'))) { |
|
156 | 156 | $namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces'))); |
157 | - foreach($namespaces as $namespace) { |
|
157 | + foreach ($namespaces as $namespace) { |
|
158 | 158 | $kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml')); |
159 | 159 | $rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss')); |
160 | 160 | dbglog( |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * not used |
180 | 180 | */ |
181 | 181 | public function handleActionActPreprocess(Doku_Event $event, $param): void { |
182 | - if($event->data !== 'findnearby') { |
|
182 | + if ($event->data !== 'findnearby') { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | $event->preventDefault(); |
@@ -195,16 +195,16 @@ discard block |
||
195 | 195 | * 'format'=> HTML | JSON |
196 | 196 | */ |
197 | 197 | public function findnearby(Doku_Event $event, $param): void { |
198 | - if($event->data !== 'findnearby') { |
|
198 | + if ($event->data !== 'findnearby') { |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | $event->preventDefault(); |
202 | 202 | $results = array(); |
203 | 203 | global $INPUT; |
204 | - if($helper = plugin_load('helper', 'spatialhelper_search')) { |
|
205 | - if($INPUT->has('lat') && $INPUT->has('lon')) { |
|
204 | + if ($helper = plugin_load('helper', 'spatialhelper_search')) { |
|
205 | + if ($INPUT->has('lat') && $INPUT->has('lon')) { |
|
206 | 206 | $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon')); |
207 | - } elseif($INPUT->has('geohash')) { |
|
207 | + } elseif ($INPUT->has('geohash')) { |
|
208 | 208 | $results = $helper->findNearby($INPUT->str('geohash')); |
209 | 209 | } else { |
210 | 210 | $results = array( |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | |
216 | 216 | $showMedia = $INPUT->bool('showMedia', true); |
217 | 217 | |
218 | - switch($param['format']) { |
|
218 | + switch ($param['format']) { |
|
219 | 219 | case 'JSON' : |
220 | 220 | $this->printJSON($results); |
221 | 221 | break; |
@@ -246,13 +246,13 @@ discard block |
||
246 | 246 | * @param bool $showMedia |
247 | 247 | */ |
248 | 248 | private function printHTML(array $searchresults, bool $showMedia = true): void { |
249 | - $pages = (array) ($searchresults ['pages']); |
|
250 | - $media = (array) $searchresults ['media']; |
|
251 | - $lat = (float) $searchresults ['lat']; |
|
252 | - $lon = (float) $searchresults ['lon']; |
|
253 | - $geohash = (string) $searchresults ['geohash']; |
|
249 | + $pages = ( array ) ($searchresults ['pages']); |
|
250 | + $media = ( array ) $searchresults ['media']; |
|
251 | + $lat = ( float ) $searchresults ['lat']; |
|
252 | + $lon = ( float ) $searchresults ['lon']; |
|
253 | + $geohash = ( string ) $searchresults ['geohash']; |
|
254 | 254 | |
255 | - if(isset ($searchresults ['error'])) { |
|
255 | + if (isset ($searchresults ['error'])) { |
|
256 | 256 | print '<div class="level1"><p>' . hsc($searchresults ['error']) . '</p></div>'; |
257 | 257 | return; |
258 | 258 | } |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | // print a HTML list |
261 | 261 | print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF; |
262 | 262 | print '<div class="level1">' . DOKU_LF; |
263 | - if(!empty ($pages)) { |
|
263 | + if (!empty ($pages)) { |
|
264 | 264 | $pagelist = '<ol>' . DOKU_LF; |
265 | - foreach($pages as $page) { |
|
265 | + foreach ($pages as $page) { |
|
266 | 266 | $pagelist .= '<li>' . html_wikilink( |
267 | 267 | ':' . $page ['id'], useHeading('navigation') ? null : |
268 | 268 | noNS($page ['id']) |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | print '<p>' . hsc($this->getLang('nothingfound')) . '</p>'; |
283 | 283 | } |
284 | 284 | |
285 | - if(!empty ($media) && $showMedia) { |
|
285 | + if (!empty ($media) && $showMedia) { |
|
286 | 286 | $pagelist = '<ol>' . DOKU_LF; |
287 | - foreach($media as $m) { |
|
287 | + foreach ($media as $m) { |
|
288 | 288 | $opts = array(); |
289 | 289 | $link = ml($m ['id'], $opts, false, '&', false); |
290 | 290 | $opts ['w'] = '100'; |
291 | 291 | $src = ml($m ['id'], $opts); |
292 | - $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' |
|
292 | + $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' |
|
293 | 293 | . $this->getLang('results_distance_prefix') . $page ['distance'] . ' m) ' . hsc($desc) |
294 | 294 | . '</li>' . DOKU_LF; |
295 | 295 | } |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | print '</div>' . DOKU_LF; |
305 | 305 | } |
306 | 306 | print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. '; |
307 | - if(strlen($geohash) > 1) { |
|
307 | + if (strlen($geohash) > 1) { |
|
308 | 308 | $url = wl( |
309 | 309 | getID(), array( |
310 | 310 | 'do' => 'findnearby', |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | |
336 | 336 | // check the list of mimetypes |
337 | 337 | // if it's a supported type call appropriate index function |
338 | - if(substr_compare($event->data [3], 'image/jpeg', 0)) { |
|
338 | + if (substr_compare($event->data [3], 'image/jpeg', 0)) { |
|
339 | 339 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
340 | - if($indexer) { |
|
340 | + if ($indexer) { |
|
341 | 341 | $indexer->indexImage($event->data [2]); |
342 | 342 | } |
343 | 343 | } |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | |
359 | 359 | // remove the media id from the index |
360 | 360 | $indexer = plugin_load('helper', 'spatialhelper_index'); |
361 | - if($indexer) { |
|
361 | + if ($indexer) { |
|
362 | 362 | $indexer->deleteFromIndex('media__' . $event->data ['id']); |
363 | 363 | } |
364 | 364 | } |
@@ -25,416 +25,416 @@ |
||
25 | 25 | */ |
26 | 26 | class action_plugin_spatialhelper extends DokuWiki_Action_Plugin { |
27 | 27 | |
28 | - /** |
|
29 | - * Register for events. |
|
30 | - * |
|
31 | - * @param Doku_Event_Handler $controller |
|
32 | - * DokuWiki's event controller object. Also available as global $EVENT_HANDLER |
|
33 | - */ |
|
34 | - public function register(Doku_Event_Handler $controller): void { |
|
35 | - // listen for page add / delete events |
|
36 | - // http://www.dokuwiki.org/devel:event:indexer_page_add |
|
37 | - $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexerPageAdd'); |
|
38 | - $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'removeFromIndex'); |
|
39 | - |
|
40 | - // http://www.dokuwiki.org/devel:event:sitemap_generate |
|
41 | - $controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'handleSitemapGenerateBefore'); |
|
42 | - // using after will only trigger us if a sitemap was actually created |
|
43 | - $controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handleSitemapGenerateAfter'); |
|
44 | - |
|
45 | - // handle actions we know of |
|
46 | - $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActionActPreprocess', array()); |
|
47 | - // handle HTML eg. /dokuwiki/doku.php?id=start&do=findnearby&geohash=u15vk4 |
|
48 | - $controller->register_hook( |
|
49 | - 'TPL_ACT_UNKNOWN', 'BEFORE', $this, 'findnearby', array( |
|
50 | - 'format' => 'HTML' |
|
51 | - ) |
|
52 | - ); |
|
53 | - // handles AJAX/json eg: jQuery.post("/dokuwiki/lib/exe/ajax.php?id=start&call=findnearby&geohash=u15vk4"); |
|
54 | - $controller->register_hook( |
|
55 | - 'AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'findnearby', array( |
|
56 | - 'format' => 'JSON' |
|
57 | - ) |
|
58 | - ); |
|
59 | - |
|
60 | - // listen for media uploads and deletes |
|
61 | - $controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, 'handleMediaUploaded', array()); |
|
62 | - $controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, 'handleMediaDeleted', array()); |
|
63 | - |
|
64 | - $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput'); |
|
65 | - $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity'); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Update the spatial index for the page. |
|
70 | - * |
|
71 | - * @param Doku_Event $event |
|
72 | - * event object |
|
73 | - * @param mixed $param |
|
74 | - * the parameters passed to register_hook when this handler was registered |
|
75 | - */ |
|
76 | - public function handleIndexerPageAdd(Doku_Event $event, $param): void { |
|
77 | - // $event→data['page'] – the page id |
|
78 | - // $event→data['body'] – empty, can be filled by additional content to index by your plugin |
|
79 | - // $event→data['metadata'] – the metadata that shall be indexed. This is an array where the keys are the |
|
80 | - // metadata indexes and the value a string or an array of strings with the values. |
|
81 | - // title and relation_references will already be set. |
|
82 | - $id = $event->data ['page']; |
|
83 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
84 | - $entries = $indexer->updateSpatialIndex($id); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Update the spatial index, removing the page. |
|
89 | - * |
|
90 | - * @param Doku_Event $event |
|
91 | - * event object |
|
92 | - * @param mixed $param |
|
93 | - * the parameters passed to register_hook when this handler was registered |
|
94 | - */ |
|
95 | - public function removeFromIndex(Doku_Event $event, $param): void { |
|
96 | - // event data: |
|
97 | - // $data[0] – The raw arguments for io_saveFile as an array. Do not change file path. |
|
98 | - // $data[0][0] – the file path. |
|
99 | - // $data[0][1] – the content to be saved, and may be modified. |
|
100 | - // $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns) |
|
101 | - // $data[2] – page_name: The wiki page name. |
|
102 | - // $data[3] – rev: The page revision, false for current wiki pages. |
|
103 | - |
|
104 | - dbglog($event->data, "Event data in removeFromIndex."); |
|
105 | - if(@file_exists($event->data [0] [0])) { |
|
106 | - // file not new |
|
107 | - if(!$event->data [0] [1]) { |
|
108 | - // file is empty, page is being deleted |
|
109 | - if(empty ($event->data [1])) { |
|
110 | - // root namespace |
|
111 | - $id = $event->data [2]; |
|
112 | - } else { |
|
113 | - $id = $event->data [1] . ":" . $event->data [2]; |
|
114 | - } |
|
115 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
116 | - if($indexer) { |
|
117 | - $indexer->deleteFromIndex($id); |
|
118 | - } |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Add a new SitemapItem object that points to the KML of public geocoded pages. |
|
125 | - * |
|
126 | - * @param Doku_Event $event |
|
127 | - * @param mixed $param |
|
128 | - */ |
|
129 | - public function handleSitemapGenerateBefore(Doku_Event $event, $param): void { |
|
130 | - $path = mediaFN($this->getConf('media_kml')); |
|
131 | - $lastmod = @filemtime($path); |
|
132 | - $event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&', true), $lastmod); |
|
133 | - //dbglog($event->data ['items'], |
|
134 | - // "Added a new SitemapItem object that points to the KML of public geocoded pages."); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Create a spatial sitemap or attach the geo/kml map to the sitemap. |
|
139 | - * |
|
140 | - * @param Doku_Event $event |
|
141 | - * event object, not used |
|
142 | - * @param mixed $param |
|
143 | - * parameter array, not used |
|
144 | - */ |
|
145 | - public function handleSitemapGenerateAfter(Doku_Event $event, $param): bool { |
|
146 | - // $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already |
|
147 | - // contains all public pages of the wiki |
|
148 | - // $event→data['sitemap']: The path of the file the sitemap will be saved to. |
|
149 | - if($helper = plugin_load('helper', 'spatialhelper_sitemap')) { |
|
150 | - // dbglog($helper, "createSpatialSitemap loaded helper."); |
|
151 | - |
|
152 | - $kml = $helper->createKMLSitemap($this->getConf('media_kml')); |
|
153 | - $rss = $helper->createGeoRSSSitemap($this->getConf('media_georss')); |
|
154 | - |
|
155 | - if(!empty ($this->getConf('sitemap_namespaces'))) { |
|
156 | - $namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces'))); |
|
157 | - foreach($namespaces as $namespace) { |
|
158 | - $kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml')); |
|
159 | - $rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss')); |
|
160 | - dbglog( |
|
161 | - $kmlN && $rssN, |
|
162 | - "handleSitemapGenerateAfter, created KML / GeoRSS sitemap in $namespace, succes: " |
|
163 | - ); |
|
164 | - } |
|
165 | - } |
|
166 | - return $kml && $rss; |
|
167 | - } else { |
|
168 | - dbglog($helper, "createSpatialSitemap NOT loaded helper."); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * trap findnearby action. |
|
174 | - * This addional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown |
|
175 | - * |
|
176 | - * @param Doku_Event $event |
|
177 | - * event object |
|
178 | - * @param mixed $param |
|
179 | - * not used |
|
180 | - */ |
|
181 | - public function handleActionActPreprocess(Doku_Event $event, $param): void { |
|
182 | - if($event->data !== 'findnearby') { |
|
183 | - return; |
|
184 | - } |
|
185 | - $event->preventDefault(); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * handle findnearby action. |
|
190 | - * |
|
191 | - * @param Doku_Event $event |
|
192 | - * event object |
|
193 | - * @param mixed $param |
|
194 | - * associative array with keys |
|
195 | - * 'format'=> HTML | JSON |
|
196 | - */ |
|
197 | - public function findnearby(Doku_Event $event, $param): void { |
|
198 | - if($event->data !== 'findnearby') { |
|
199 | - return; |
|
200 | - } |
|
201 | - $event->preventDefault(); |
|
202 | - $results = array(); |
|
203 | - global $INPUT; |
|
204 | - if($helper = plugin_load('helper', 'spatialhelper_search')) { |
|
205 | - if($INPUT->has('lat') && $INPUT->has('lon')) { |
|
206 | - $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon')); |
|
207 | - } elseif($INPUT->has('geohash')) { |
|
208 | - $results = $helper->findNearby($INPUT->str('geohash')); |
|
209 | - } else { |
|
210 | - $results = array( |
|
211 | - 'error' => hsc($this->getLang('invalidinput')) |
|
212 | - ); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - $showMedia = $INPUT->bool('showMedia', true); |
|
217 | - |
|
218 | - switch($param['format']) { |
|
219 | - case 'JSON' : |
|
220 | - $this->printJSON($results); |
|
221 | - break; |
|
222 | - case 'HTML' : |
|
223 | - // fall through to default |
|
224 | - default : |
|
225 | - $this->printHTML($results, $showMedia); |
|
226 | - break; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Print seachresults as HTML lists. |
|
232 | - * |
|
233 | - * @param array $searchresults |
|
234 | - */ |
|
235 | - private function printJSON(array $searchresults): void { |
|
236 | - require_once DOKU_INC . 'inc/JSON.php'; |
|
237 | - $json = new JSON(); |
|
238 | - header('Content-Type: application/json'); |
|
239 | - print $json->encode($searchresults); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Print seachresults as HTML lists. |
|
244 | - * |
|
245 | - * @param array $searchresults |
|
246 | - * @param bool $showMedia |
|
247 | - */ |
|
248 | - private function printHTML(array $searchresults, bool $showMedia = true): void { |
|
249 | - $pages = (array) ($searchresults ['pages']); |
|
250 | - $media = (array) $searchresults ['media']; |
|
251 | - $lat = (float) $searchresults ['lat']; |
|
252 | - $lon = (float) $searchresults ['lon']; |
|
253 | - $geohash = (string) $searchresults ['geohash']; |
|
254 | - |
|
255 | - if(isset ($searchresults ['error'])) { |
|
256 | - print '<div class="level1"><p>' . hsc($searchresults ['error']) . '</p></div>'; |
|
257 | - return; |
|
258 | - } |
|
259 | - |
|
260 | - // print a HTML list |
|
261 | - print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF; |
|
262 | - print '<div class="level1">' . DOKU_LF; |
|
263 | - if(!empty ($pages)) { |
|
264 | - $pagelist = '<ol>' . DOKU_LF; |
|
265 | - foreach($pages as $page) { |
|
266 | - $pagelist .= '<li>' . html_wikilink( |
|
267 | - ':' . $page ['id'], useHeading('navigation') ? null : |
|
268 | - noNS($page ['id']) |
|
269 | - ) . ' (' . $this->getLang('results_distance_prefix') |
|
270 | - . $page ['distance'] . ' m) ' . $page ['description'] . '</li>' . DOKU_LF; |
|
271 | - } |
|
272 | - $pagelist .= '</ol>' . DOKU_LF; |
|
273 | - |
|
274 | - print '<h2>' . $this->getLang('results_pages') . hsc( |
|
275 | - ' lat;lon: ' . $lat . ';' . $lon |
|
276 | - . ' (geohash: ' . $geohash . ')' |
|
277 | - ) . '</h2>'; |
|
278 | - print '<div class="level2">' . DOKU_LF; |
|
279 | - print $pagelist; |
|
280 | - print '</div>' . DOKU_LF; |
|
281 | - } else { |
|
282 | - print '<p>' . hsc($this->getLang('nothingfound')) . '</p>'; |
|
283 | - } |
|
284 | - |
|
285 | - if(!empty ($media) && $showMedia) { |
|
286 | - $pagelist = '<ol>' . DOKU_LF; |
|
287 | - foreach($media as $m) { |
|
288 | - $opts = array(); |
|
289 | - $link = ml($m ['id'], $opts, false, '&', false); |
|
290 | - $opts ['w'] = '100'; |
|
291 | - $src = ml($m ['id'], $opts); |
|
292 | - $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' |
|
293 | - . $this->getLang('results_distance_prefix') . $page ['distance'] . ' m) ' . hsc($desc) |
|
294 | - . '</li>' . DOKU_LF; |
|
295 | - } |
|
296 | - $pagelist .= '</ol>' . DOKU_LF; |
|
297 | - |
|
298 | - print '<h2>' . $this->getLang('results_media') . hsc( |
|
299 | - ' lat;lon: ' . $lat . ';' . $lon |
|
300 | - . ' (geohash: ' . $geohash . ')' |
|
301 | - ) . '</h2>' . DOKU_LF; |
|
302 | - print '<div class="level2">' . DOKU_LF; |
|
303 | - print $pagelist; |
|
304 | - print '</div>' . DOKU_LF; |
|
305 | - } |
|
306 | - print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. '; |
|
307 | - if(strlen($geohash) > 1) { |
|
308 | - $url = wl( |
|
309 | - getID(), array( |
|
310 | - 'do' => 'findnearby', |
|
311 | - 'geohash' => substr($geohash, 0, -1) |
|
312 | - ) |
|
313 | - ); |
|
314 | - print '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>' |
|
315 | - . DOKU_LF; |
|
316 | - } |
|
317 | - print '</div>' . DOKU_LF; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * add media to spatial index. |
|
322 | - * |
|
323 | - * @param Doku_Event $event |
|
324 | - * @param mixed $param |
|
325 | - */ |
|
326 | - public function handleMediaUploaded(Doku_Event $event, $param): void { |
|
327 | - // data[0] temporary file name (read from $_FILES) |
|
328 | - // data[1] file name of the file being uploaded |
|
329 | - // data[2] future directory id of the file being uploaded |
|
330 | - // data[3] the mime type of the file being uploaded |
|
331 | - // data[4] true if the uploaded file exists already |
|
332 | - // data[5] (since 2011-02-06) the PHP function used to move the file to the correct location |
|
333 | - |
|
334 | - dbglog($event->data, "handleMediaUploaded::event data"); |
|
335 | - |
|
336 | - // check the list of mimetypes |
|
337 | - // if it's a supported type call appropriate index function |
|
338 | - if(substr_compare($event->data [3], 'image/jpeg', 0)) { |
|
339 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
340 | - if($indexer) { |
|
341 | - $indexer->indexImage($event->data [2]); |
|
342 | - } |
|
343 | - } |
|
344 | - // TODO add image/tiff |
|
345 | - // TODO kml, gpx, geojson... |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * removes the media from the index. |
|
350 | - */ |
|
351 | - public function handleMediaDeleted(Doku_Event $event, $param): void { |
|
352 | - // data['id'] ID data['unl'] unlink return code |
|
353 | - // data['del'] Namespace directory unlink return code |
|
354 | - // data['name'] file name data['path'] full path to the file |
|
355 | - // data['size'] file size |
|
356 | - |
|
357 | - dbglog($event->data, "handleMediaDeleted::event data"); |
|
358 | - |
|
359 | - // remove the media id from the index |
|
360 | - $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
361 | - if($indexer) { |
|
362 | - $indexer->deleteFromIndex('media__' . $event->data ['id']); |
|
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * add a link to the spatial sitemap files in the header. |
|
368 | - * |
|
369 | - * @param Doku_Event $event |
|
370 | - * the DokuWiki event. $event->data is a two-dimensional |
|
371 | - * array of all meta headers. The keys are meta, link and script. |
|
372 | - * @param mixed $param |
|
373 | - * |
|
374 | - * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output |
|
375 | - */ |
|
376 | - public function handleMetaheaderOutput(Doku_Event $event, $param): void { |
|
377 | - // TODO maybe test for exist |
|
378 | - $event->data ["link"] [] = array( |
|
379 | - "type" => "application/atom+xml", |
|
380 | - "rel" => "alternate", |
|
381 | - "href" => ml($this->getConf('media_georss')), |
|
382 | - "title" => "Spatial ATOM Feed" |
|
383 | - ); |
|
384 | - $event->data ["link"] [] = array( |
|
385 | - "type" => "application/vnd.google-earth.kml+xml", |
|
386 | - "rel" => "alternate", |
|
387 | - "href" => ml($this->getConf('media_kml')), |
|
388 | - "title" => "KML Sitemap" |
|
389 | - ); |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Add spatialhelper popularity data. |
|
394 | - * |
|
395 | - * @param Doku_Event $event |
|
396 | - * the DokuWiki event |
|
397 | - */ |
|
398 | - final public function popularity(Doku_Event $event): void { |
|
399 | - $versionInfo = getVersionData(); |
|
400 | - $plugin_info = $this->getInfo(); |
|
401 | - $event->data['spatialhelper']['version'] = $plugin_info['date']; |
|
402 | - $event->data['spatialhelper']['dwversion'] = $versionInfo['date']; |
|
403 | - $event->data['spatialhelper']['combinedversion'] = $versionInfo['date'] . '_' . $plugin_info['date']; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Calculate a new coordinate based on start, distance and bearing |
|
408 | - * |
|
409 | - * @param $start array |
|
410 | - * - start coordinate as decimal lat/lon pair |
|
411 | - * @param $dist float |
|
412 | - * - distance in kilometers |
|
413 | - * @param $brng float |
|
414 | - * - bearing in degrees (compass direction) |
|
415 | - */ |
|
416 | - private function geoDestination(array $start, float $dist, float $brng): array { |
|
417 | - $lat1 = $this->toRad($start [0]); |
|
418 | - $lon1 = $this->toRad($start [1]); |
|
419 | - // http://en.wikipedia.org/wiki/Earth_radius |
|
420 | - // average earth radius in km |
|
421 | - $dist = $dist / 6371.01; |
|
422 | - $brng = $this->toRad($brng); |
|
423 | - |
|
424 | - $lon2 = $lon1 + atan2(sin($brng) * sin($dist) * cos($lat1), cos($dist) - sin($lat1) * sin($lat2)); |
|
425 | - $lon2 = fmod(($lon2 + 3 * M_PI), (2 * M_PI)) - M_PI; |
|
426 | - |
|
427 | - return array( |
|
428 | - $this->toDeg($lat2), |
|
429 | - $this->toDeg($lon2) |
|
430 | - ); |
|
431 | - } |
|
432 | - |
|
433 | - private function toRad(float $deg): float { |
|
434 | - return $deg * M_PI / 180; |
|
435 | - } |
|
436 | - |
|
437 | - private function toDeg(float $rad): float { |
|
438 | - return $rad * 180 / M_PI; |
|
439 | - } |
|
28 | + /** |
|
29 | + * Register for events. |
|
30 | + * |
|
31 | + * @param Doku_Event_Handler $controller |
|
32 | + * DokuWiki's event controller object. Also available as global $EVENT_HANDLER |
|
33 | + */ |
|
34 | + public function register(Doku_Event_Handler $controller): void { |
|
35 | + // listen for page add / delete events |
|
36 | + // http://www.dokuwiki.org/devel:event:indexer_page_add |
|
37 | + $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexerPageAdd'); |
|
38 | + $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'removeFromIndex'); |
|
39 | + |
|
40 | + // http://www.dokuwiki.org/devel:event:sitemap_generate |
|
41 | + $controller->register_hook('SITEMAP_GENERATE', 'BEFORE', $this, 'handleSitemapGenerateBefore'); |
|
42 | + // using after will only trigger us if a sitemap was actually created |
|
43 | + $controller->register_hook('SITEMAP_GENERATE', 'AFTER', $this, 'handleSitemapGenerateAfter'); |
|
44 | + |
|
45 | + // handle actions we know of |
|
46 | + $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActionActPreprocess', array()); |
|
47 | + // handle HTML eg. /dokuwiki/doku.php?id=start&do=findnearby&geohash=u15vk4 |
|
48 | + $controller->register_hook( |
|
49 | + 'TPL_ACT_UNKNOWN', 'BEFORE', $this, 'findnearby', array( |
|
50 | + 'format' => 'HTML' |
|
51 | + ) |
|
52 | + ); |
|
53 | + // handles AJAX/json eg: jQuery.post("/dokuwiki/lib/exe/ajax.php?id=start&call=findnearby&geohash=u15vk4"); |
|
54 | + $controller->register_hook( |
|
55 | + 'AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'findnearby', array( |
|
56 | + 'format' => 'JSON' |
|
57 | + ) |
|
58 | + ); |
|
59 | + |
|
60 | + // listen for media uploads and deletes |
|
61 | + $controller->register_hook('MEDIA_UPLOAD_FINISH', 'BEFORE', $this, 'handleMediaUploaded', array()); |
|
62 | + $controller->register_hook('MEDIA_DELETE_FILE', 'BEFORE', $this, 'handleMediaDeleted', array()); |
|
63 | + |
|
64 | + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput'); |
|
65 | + $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity'); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Update the spatial index for the page. |
|
70 | + * |
|
71 | + * @param Doku_Event $event |
|
72 | + * event object |
|
73 | + * @param mixed $param |
|
74 | + * the parameters passed to register_hook when this handler was registered |
|
75 | + */ |
|
76 | + public function handleIndexerPageAdd(Doku_Event $event, $param): void { |
|
77 | + // $event→data['page'] – the page id |
|
78 | + // $event→data['body'] – empty, can be filled by additional content to index by your plugin |
|
79 | + // $event→data['metadata'] – the metadata that shall be indexed. This is an array where the keys are the |
|
80 | + // metadata indexes and the value a string or an array of strings with the values. |
|
81 | + // title and relation_references will already be set. |
|
82 | + $id = $event->data ['page']; |
|
83 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
84 | + $entries = $indexer->updateSpatialIndex($id); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Update the spatial index, removing the page. |
|
89 | + * |
|
90 | + * @param Doku_Event $event |
|
91 | + * event object |
|
92 | + * @param mixed $param |
|
93 | + * the parameters passed to register_hook when this handler was registered |
|
94 | + */ |
|
95 | + public function removeFromIndex(Doku_Event $event, $param): void { |
|
96 | + // event data: |
|
97 | + // $data[0] – The raw arguments for io_saveFile as an array. Do not change file path. |
|
98 | + // $data[0][0] – the file path. |
|
99 | + // $data[0][1] – the content to be saved, and may be modified. |
|
100 | + // $data[1] – ns: The colon separated namespace path minus the trailing page name. (false if root ns) |
|
101 | + // $data[2] – page_name: The wiki page name. |
|
102 | + // $data[3] – rev: The page revision, false for current wiki pages. |
|
103 | + |
|
104 | + dbglog($event->data, "Event data in removeFromIndex."); |
|
105 | + if(@file_exists($event->data [0] [0])) { |
|
106 | + // file not new |
|
107 | + if(!$event->data [0] [1]) { |
|
108 | + // file is empty, page is being deleted |
|
109 | + if(empty ($event->data [1])) { |
|
110 | + // root namespace |
|
111 | + $id = $event->data [2]; |
|
112 | + } else { |
|
113 | + $id = $event->data [1] . ":" . $event->data [2]; |
|
114 | + } |
|
115 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
116 | + if($indexer) { |
|
117 | + $indexer->deleteFromIndex($id); |
|
118 | + } |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Add a new SitemapItem object that points to the KML of public geocoded pages. |
|
125 | + * |
|
126 | + * @param Doku_Event $event |
|
127 | + * @param mixed $param |
|
128 | + */ |
|
129 | + public function handleSitemapGenerateBefore(Doku_Event $event, $param): void { |
|
130 | + $path = mediaFN($this->getConf('media_kml')); |
|
131 | + $lastmod = @filemtime($path); |
|
132 | + $event->data ['items'] [] = new Item(ml($this->getConf('media_kml'), '', true, '&', true), $lastmod); |
|
133 | + //dbglog($event->data ['items'], |
|
134 | + // "Added a new SitemapItem object that points to the KML of public geocoded pages."); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Create a spatial sitemap or attach the geo/kml map to the sitemap. |
|
139 | + * |
|
140 | + * @param Doku_Event $event |
|
141 | + * event object, not used |
|
142 | + * @param mixed $param |
|
143 | + * parameter array, not used |
|
144 | + */ |
|
145 | + public function handleSitemapGenerateAfter(Doku_Event $event, $param): bool { |
|
146 | + // $event→data['items']: Array of SitemapItem instances, the array of sitemap items that already |
|
147 | + // contains all public pages of the wiki |
|
148 | + // $event→data['sitemap']: The path of the file the sitemap will be saved to. |
|
149 | + if($helper = plugin_load('helper', 'spatialhelper_sitemap')) { |
|
150 | + // dbglog($helper, "createSpatialSitemap loaded helper."); |
|
151 | + |
|
152 | + $kml = $helper->createKMLSitemap($this->getConf('media_kml')); |
|
153 | + $rss = $helper->createGeoRSSSitemap($this->getConf('media_georss')); |
|
154 | + |
|
155 | + if(!empty ($this->getConf('sitemap_namespaces'))) { |
|
156 | + $namespaces = array_map('trim', explode("\n", $this->getConf('sitemap_namespaces'))); |
|
157 | + foreach($namespaces as $namespace) { |
|
158 | + $kmlN = $helper->createKMLSitemap($namespace . $this->getConf('media_kml')); |
|
159 | + $rssN = $helper->createGeoRSSSitemap($namespace . $this->getConf('media_georss')); |
|
160 | + dbglog( |
|
161 | + $kmlN && $rssN, |
|
162 | + "handleSitemapGenerateAfter, created KML / GeoRSS sitemap in $namespace, succes: " |
|
163 | + ); |
|
164 | + } |
|
165 | + } |
|
166 | + return $kml && $rss; |
|
167 | + } else { |
|
168 | + dbglog($helper, "createSpatialSitemap NOT loaded helper."); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * trap findnearby action. |
|
174 | + * This addional handler is required as described at: https://www.dokuwiki.org/devel:event:tpl_act_unknown |
|
175 | + * |
|
176 | + * @param Doku_Event $event |
|
177 | + * event object |
|
178 | + * @param mixed $param |
|
179 | + * not used |
|
180 | + */ |
|
181 | + public function handleActionActPreprocess(Doku_Event $event, $param): void { |
|
182 | + if($event->data !== 'findnearby') { |
|
183 | + return; |
|
184 | + } |
|
185 | + $event->preventDefault(); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * handle findnearby action. |
|
190 | + * |
|
191 | + * @param Doku_Event $event |
|
192 | + * event object |
|
193 | + * @param mixed $param |
|
194 | + * associative array with keys |
|
195 | + * 'format'=> HTML | JSON |
|
196 | + */ |
|
197 | + public function findnearby(Doku_Event $event, $param): void { |
|
198 | + if($event->data !== 'findnearby') { |
|
199 | + return; |
|
200 | + } |
|
201 | + $event->preventDefault(); |
|
202 | + $results = array(); |
|
203 | + global $INPUT; |
|
204 | + if($helper = plugin_load('helper', 'spatialhelper_search')) { |
|
205 | + if($INPUT->has('lat') && $INPUT->has('lon')) { |
|
206 | + $results = $helper->findNearbyLatLon($INPUT->param('lat'), $INPUT->param('lon')); |
|
207 | + } elseif($INPUT->has('geohash')) { |
|
208 | + $results = $helper->findNearby($INPUT->str('geohash')); |
|
209 | + } else { |
|
210 | + $results = array( |
|
211 | + 'error' => hsc($this->getLang('invalidinput')) |
|
212 | + ); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + $showMedia = $INPUT->bool('showMedia', true); |
|
217 | + |
|
218 | + switch($param['format']) { |
|
219 | + case 'JSON' : |
|
220 | + $this->printJSON($results); |
|
221 | + break; |
|
222 | + case 'HTML' : |
|
223 | + // fall through to default |
|
224 | + default : |
|
225 | + $this->printHTML($results, $showMedia); |
|
226 | + break; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Print seachresults as HTML lists. |
|
232 | + * |
|
233 | + * @param array $searchresults |
|
234 | + */ |
|
235 | + private function printJSON(array $searchresults): void { |
|
236 | + require_once DOKU_INC . 'inc/JSON.php'; |
|
237 | + $json = new JSON(); |
|
238 | + header('Content-Type: application/json'); |
|
239 | + print $json->encode($searchresults); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Print seachresults as HTML lists. |
|
244 | + * |
|
245 | + * @param array $searchresults |
|
246 | + * @param bool $showMedia |
|
247 | + */ |
|
248 | + private function printHTML(array $searchresults, bool $showMedia = true): void { |
|
249 | + $pages = (array) ($searchresults ['pages']); |
|
250 | + $media = (array) $searchresults ['media']; |
|
251 | + $lat = (float) $searchresults ['lat']; |
|
252 | + $lon = (float) $searchresults ['lon']; |
|
253 | + $geohash = (string) $searchresults ['geohash']; |
|
254 | + |
|
255 | + if(isset ($searchresults ['error'])) { |
|
256 | + print '<div class="level1"><p>' . hsc($searchresults ['error']) . '</p></div>'; |
|
257 | + return; |
|
258 | + } |
|
259 | + |
|
260 | + // print a HTML list |
|
261 | + print '<h1>' . $this->getLang('results_header') . '</h1>' . DOKU_LF; |
|
262 | + print '<div class="level1">' . DOKU_LF; |
|
263 | + if(!empty ($pages)) { |
|
264 | + $pagelist = '<ol>' . DOKU_LF; |
|
265 | + foreach($pages as $page) { |
|
266 | + $pagelist .= '<li>' . html_wikilink( |
|
267 | + ':' . $page ['id'], useHeading('navigation') ? null : |
|
268 | + noNS($page ['id']) |
|
269 | + ) . ' (' . $this->getLang('results_distance_prefix') |
|
270 | + . $page ['distance'] . ' m) ' . $page ['description'] . '</li>' . DOKU_LF; |
|
271 | + } |
|
272 | + $pagelist .= '</ol>' . DOKU_LF; |
|
273 | + |
|
274 | + print '<h2>' . $this->getLang('results_pages') . hsc( |
|
275 | + ' lat;lon: ' . $lat . ';' . $lon |
|
276 | + . ' (geohash: ' . $geohash . ')' |
|
277 | + ) . '</h2>'; |
|
278 | + print '<div class="level2">' . DOKU_LF; |
|
279 | + print $pagelist; |
|
280 | + print '</div>' . DOKU_LF; |
|
281 | + } else { |
|
282 | + print '<p>' . hsc($this->getLang('nothingfound')) . '</p>'; |
|
283 | + } |
|
284 | + |
|
285 | + if(!empty ($media) && $showMedia) { |
|
286 | + $pagelist = '<ol>' . DOKU_LF; |
|
287 | + foreach($media as $m) { |
|
288 | + $opts = array(); |
|
289 | + $link = ml($m ['id'], $opts, false, '&', false); |
|
290 | + $opts ['w'] = '100'; |
|
291 | + $src = ml($m ['id'], $opts); |
|
292 | + $pagelist .= '<li><a href="' . $link . '"><img src="' . $src . '"></a> (' |
|
293 | + . $this->getLang('results_distance_prefix') . $page ['distance'] . ' m) ' . hsc($desc) |
|
294 | + . '</li>' . DOKU_LF; |
|
295 | + } |
|
296 | + $pagelist .= '</ol>' . DOKU_LF; |
|
297 | + |
|
298 | + print '<h2>' . $this->getLang('results_media') . hsc( |
|
299 | + ' lat;lon: ' . $lat . ';' . $lon |
|
300 | + . ' (geohash: ' . $geohash . ')' |
|
301 | + ) . '</h2>' . DOKU_LF; |
|
302 | + print '<div class="level2">' . DOKU_LF; |
|
303 | + print $pagelist; |
|
304 | + print '</div>' . DOKU_LF; |
|
305 | + } |
|
306 | + print '<p>' . $this->getLang('results_precision') . $searchresults ['precision'] . ' m. '; |
|
307 | + if(strlen($geohash) > 1) { |
|
308 | + $url = wl( |
|
309 | + getID(), array( |
|
310 | + 'do' => 'findnearby', |
|
311 | + 'geohash' => substr($geohash, 0, -1) |
|
312 | + ) |
|
313 | + ); |
|
314 | + print '<a href="' . $url . '" class="findnearby">' . $this->getLang('search_largerarea') . '</a>.</p>' |
|
315 | + . DOKU_LF; |
|
316 | + } |
|
317 | + print '</div>' . DOKU_LF; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * add media to spatial index. |
|
322 | + * |
|
323 | + * @param Doku_Event $event |
|
324 | + * @param mixed $param |
|
325 | + */ |
|
326 | + public function handleMediaUploaded(Doku_Event $event, $param): void { |
|
327 | + // data[0] temporary file name (read from $_FILES) |
|
328 | + // data[1] file name of the file being uploaded |
|
329 | + // data[2] future directory id of the file being uploaded |
|
330 | + // data[3] the mime type of the file being uploaded |
|
331 | + // data[4] true if the uploaded file exists already |
|
332 | + // data[5] (since 2011-02-06) the PHP function used to move the file to the correct location |
|
333 | + |
|
334 | + dbglog($event->data, "handleMediaUploaded::event data"); |
|
335 | + |
|
336 | + // check the list of mimetypes |
|
337 | + // if it's a supported type call appropriate index function |
|
338 | + if(substr_compare($event->data [3], 'image/jpeg', 0)) { |
|
339 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
340 | + if($indexer) { |
|
341 | + $indexer->indexImage($event->data [2]); |
|
342 | + } |
|
343 | + } |
|
344 | + // TODO add image/tiff |
|
345 | + // TODO kml, gpx, geojson... |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * removes the media from the index. |
|
350 | + */ |
|
351 | + public function handleMediaDeleted(Doku_Event $event, $param): void { |
|
352 | + // data['id'] ID data['unl'] unlink return code |
|
353 | + // data['del'] Namespace directory unlink return code |
|
354 | + // data['name'] file name data['path'] full path to the file |
|
355 | + // data['size'] file size |
|
356 | + |
|
357 | + dbglog($event->data, "handleMediaDeleted::event data"); |
|
358 | + |
|
359 | + // remove the media id from the index |
|
360 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
|
361 | + if($indexer) { |
|
362 | + $indexer->deleteFromIndex('media__' . $event->data ['id']); |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * add a link to the spatial sitemap files in the header. |
|
368 | + * |
|
369 | + * @param Doku_Event $event |
|
370 | + * the DokuWiki event. $event->data is a two-dimensional |
|
371 | + * array of all meta headers. The keys are meta, link and script. |
|
372 | + * @param mixed $param |
|
373 | + * |
|
374 | + * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output |
|
375 | + */ |
|
376 | + public function handleMetaheaderOutput(Doku_Event $event, $param): void { |
|
377 | + // TODO maybe test for exist |
|
378 | + $event->data ["link"] [] = array( |
|
379 | + "type" => "application/atom+xml", |
|
380 | + "rel" => "alternate", |
|
381 | + "href" => ml($this->getConf('media_georss')), |
|
382 | + "title" => "Spatial ATOM Feed" |
|
383 | + ); |
|
384 | + $event->data ["link"] [] = array( |
|
385 | + "type" => "application/vnd.google-earth.kml+xml", |
|
386 | + "rel" => "alternate", |
|
387 | + "href" => ml($this->getConf('media_kml')), |
|
388 | + "title" => "KML Sitemap" |
|
389 | + ); |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Add spatialhelper popularity data. |
|
394 | + * |
|
395 | + * @param Doku_Event $event |
|
396 | + * the DokuWiki event |
|
397 | + */ |
|
398 | + final public function popularity(Doku_Event $event): void { |
|
399 | + $versionInfo = getVersionData(); |
|
400 | + $plugin_info = $this->getInfo(); |
|
401 | + $event->data['spatialhelper']['version'] = $plugin_info['date']; |
|
402 | + $event->data['spatialhelper']['dwversion'] = $versionInfo['date']; |
|
403 | + $event->data['spatialhelper']['combinedversion'] = $versionInfo['date'] . '_' . $plugin_info['date']; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Calculate a new coordinate based on start, distance and bearing |
|
408 | + * |
|
409 | + * @param $start array |
|
410 | + * - start coordinate as decimal lat/lon pair |
|
411 | + * @param $dist float |
|
412 | + * - distance in kilometers |
|
413 | + * @param $brng float |
|
414 | + * - bearing in degrees (compass direction) |
|
415 | + */ |
|
416 | + private function geoDestination(array $start, float $dist, float $brng): array { |
|
417 | + $lat1 = $this->toRad($start [0]); |
|
418 | + $lon1 = $this->toRad($start [1]); |
|
419 | + // http://en.wikipedia.org/wiki/Earth_radius |
|
420 | + // average earth radius in km |
|
421 | + $dist = $dist / 6371.01; |
|
422 | + $brng = $this->toRad($brng); |
|
423 | + |
|
424 | + $lon2 = $lon1 + atan2(sin($brng) * sin($dist) * cos($lat1), cos($dist) - sin($lat1) * sin($lat2)); |
|
425 | + $lon2 = fmod(($lon2 + 3 * M_PI), (2 * M_PI)) - M_PI; |
|
426 | + |
|
427 | + return array( |
|
428 | + $this->toDeg($lat2), |
|
429 | + $this->toDeg($lon2) |
|
430 | + ); |
|
431 | + } |
|
432 | + |
|
433 | + private function toRad(float $deg): float { |
|
434 | + return $deg * M_PI / 180; |
|
435 | + } |
|
436 | + |
|
437 | + private function toDeg(float $rad): float { |
|
438 | + return $rad * 180 / M_PI; |
|
439 | + } |
|
440 | 440 | } |