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