1 | <?php |
||||||
2 | /** |
||||||
3 | * DokuSIOC - SIOC plugin for DokuWiki |
||||||
4 | * |
||||||
5 | * version 0.1.2 |
||||||
6 | * |
||||||
7 | * DokuSIOC integrates the SIOC ontology within DokuWiki and provides an |
||||||
8 | * alternate RDF/XML views of the wiki documents. |
||||||
9 | * |
||||||
10 | * For DokuWiki we can't use the Triplify script because DokuWiki has not a RDBS |
||||||
11 | * backend. But the wiki API provides enough methods to get the data out, so |
||||||
12 | * DokuSIOC as a plugin uses the export hook to provide accessible data as |
||||||
13 | * RDF/XML, using the SIOC ontology as vocabulary. |
||||||
14 | * |
||||||
15 | * METADATA |
||||||
16 | * |
||||||
17 | * @author Michael Haschke @ eye48.com |
||||||
18 | * @copyright 2009 Michael Haschke |
||||||
19 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License 2.0 (GPLv2) |
||||||
20 | * @version 0.1.2 |
||||||
21 | * |
||||||
22 | * WEBSITES |
||||||
23 | * |
||||||
24 | * @link http://eye48.com/go/dokusioc Plugin Website and Overview |
||||||
25 | * @link http://github.com/haschek/DokuWiki-Plugin-DokuSIOC/issues Issue tracker |
||||||
26 | * |
||||||
27 | * LICENCE |
||||||
28 | * |
||||||
29 | * This program is free software: you can redistribute it and/or modify it under |
||||||
30 | * the terms of the GNU General Public License as published by the Free Software |
||||||
31 | * Foundation, version 2 of the License. |
||||||
32 | * |
||||||
33 | * This program is distributed in the hope that it will be useful, but WITHOUT |
||||||
34 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
||||||
35 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
||||||
36 | * |
||||||
37 | * @link http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License 2.0 (GPLv2) |
||||||
38 | * |
||||||
39 | * CHANGELOG |
||||||
40 | * |
||||||
41 | * 0.1.2 |
||||||
42 | * - fix: meta link to post type is standard use now (issue 9) |
||||||
43 | * - mod: titles for SIOC documents (issue 10) |
||||||
44 | * - mod: use sioc:UserAccount instead of deprecated sioc:User (issue 2) |
||||||
45 | * 0.1.1 (bugfix release) |
||||||
46 | * - fix header output for content negotiation |
||||||
47 | * - fix URIs for profile and SIOC ressource |
||||||
48 | * - better dc:title for revisions |
||||||
49 | * - add complete URI to rdf:about for foaf:Document (Profile) to make it explicit |
||||||
50 | * - add rel="canonical" for URIs with type parameter, to prevent double content |
||||||
51 | * 0.1 |
||||||
52 | * - exchange licence b/c CC-BY-SA was incompatible with GPL |
||||||
53 | * - restructuring code base |
||||||
54 | * - fix: wrong meta link for revisions |
||||||
55 | * - add: possibility to send noindex by x-robots-tag via HTTP header |
||||||
56 | * - add: soft check for requested application type |
||||||
57 | * - mod: use search method to get container content on next sub level |
||||||
58 | * - mod: better dc:title for foaf:document, |
||||||
59 | * - mod: better distinction between user/container/post resources |
||||||
60 | * - mod: normalize URIs |
||||||
61 | * - fix: URIs for SIOC documents |
||||||
62 | * - mod: use dcterms:created and sioc:has_creator only for first revision of wiki page b/c of inadequate meta data |
||||||
63 | * - add: backlinks from wiki via dcterms:isReferencedBy |
||||||
64 | * - add: contributors by sioc:has_modifier (only for last revision b/c of wrong meta data for older revisions) |
||||||
65 | * - rem: foaf:person link in sioct:WikiArticle b/c it routes to same data like sioc:has_creater/modifier |
||||||
66 | * - rem: Talis SIOC widget for comments b/c incompatibility with DokuWiki JS |
||||||
67 | * poc |
||||||
68 | * - proof of concept release under CC-BY-SA |
||||||
69 | **/ |
||||||
70 | |||||||
71 | class action_plugin_dokusioc extends DokuWiki_Action_Plugin |
||||||
72 | { |
||||||
73 | |||||||
74 | private $agentlink = 'http://eye48.com/go/dokusioc?v=0.1.2'; |
||||||
75 | |||||||
76 | /* -- Methods to manage plugin ------------------------------------------ */ |
||||||
77 | |||||||
78 | /** |
||||||
79 | * Register it's handlers with the DokuWiki's event controller |
||||||
80 | */ |
||||||
81 | public function register(Doku_Event_Handler $controller): void |
||||||
82 | { |
||||||
83 | //print_r(headers_list()); die(); |
||||||
84 | // test the requested action |
||||||
85 | $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'checkAction', $controller); |
||||||
86 | } |
||||||
87 | |||||||
88 | /* -- Event handlers ---------------------------------------------------- */ |
||||||
89 | |||||||
90 | public function checkAction($action, $controller) |
||||||
91 | { |
||||||
92 | global $INFO; |
||||||
93 | //print_r($INFO); die(); |
||||||
94 | //print_r(headers_list()); die(); |
||||||
95 | |||||||
96 | if ($action->data === 'export_siocxml') { |
||||||
97 | // give back rdf |
||||||
98 | $this->exportSioc(); |
||||||
99 | } elseif (($action->data === 'show' || $action->data === 'index') && $INFO['perm'] && !defined( |
||||||
100 | 'DOKU_MEDIADETAIL' |
||||||
101 | ) && ($INFO['exists'] || getDwUserInfo($INFO['id'], $this)) && !isHiddenPage($INFO['id'])) { |
||||||
0 ignored issues
–
show
|
|||||||
102 | if ($this->isRdfXmlRequest()) { |
||||||
103 | // forward to rdfxml document if requested |
||||||
104 | // print_r(headers_list()); die(); |
||||||
105 | $location = $this->createRdfLink(); |
||||||
106 | if (function_exists('header_remove')) { |
||||||
107 | header_remove(); |
||||||
108 | } |
||||||
109 | header('Location: ' . $location['href'], true, 303); |
||||||
110 | exit(); |
||||||
111 | } else { |
||||||
112 | // add meta link to html head |
||||||
113 | $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'createRdfLink'); |
||||||
114 | } |
||||||
115 | } |
||||||
116 | /* |
||||||
117 | else |
||||||
118 | { |
||||||
119 | print_r(array($action->data, $INFO['perm'], defined('DOKU_MEDIADETAIL'), $INFO['exists'], |
||||||
120 | getDwUserInfo($INFO['id'],$this), isHiddenPage($INFO['id']))); |
||||||
121 | die(); |
||||||
122 | } |
||||||
123 | */ |
||||||
124 | } |
||||||
125 | |||||||
126 | public function exportSioc() |
||||||
127 | { |
||||||
128 | global $ID, $INFO; |
||||||
129 | |||||||
130 | if (isHiddenPage($ID)) { |
||||||
131 | $this->exit("HTTP/1.0 404 Not Found"); |
||||||
132 | } |
||||||
133 | |||||||
134 | $sioc_type = $this->getContenttype(); |
||||||
135 | |||||||
136 | // Test for valid types |
||||||
137 | if (!(($sioc_type == 'post' && $INFO['exists']) || $sioc_type == 'user' || $sioc_type == 'container')) { |
||||||
138 | $this->exit("HTTP/1.0 404 Not Found"); |
||||||
139 | } |
||||||
140 | |||||||
141 | // Test for permission |
||||||
142 | if (!$INFO['perm']) { |
||||||
143 | // not enough rights to see the wiki page |
||||||
144 | $this->exit("HTTP/1.0 401 Unauthorized"); |
||||||
145 | } |
||||||
146 | |||||||
147 | // Forward to URI with explicit type attribut |
||||||
148 | if (!isset($_GET['type'])) { |
||||||
149 | header('Location:' . $_SERVER['REQUEST_URI'] . '&type=' . $sioc_type, true, 302); |
||||||
150 | } |
||||||
151 | |||||||
152 | // Include SIOC libs |
||||||
153 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sioc_inc.php'); |
||||||
154 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sioc_dokuwiki.php'); |
||||||
155 | |||||||
156 | // Create exporter |
||||||
157 | |||||||
158 | $rdf = new SIOCExporter(); |
||||||
159 | $rdf->profile_url = normalizeUri( |
||||||
0 ignored issues
–
show
The function
normalizeUri() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
160 | getAbsUrl( |
||||||
0 ignored issues
–
show
The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
161 | exportlink( |
||||||
162 | $ID, |
||||||
163 | 'siocxml', |
||||||
164 | array('type' => $sioc_type), |
||||||
165 | false, |
||||||
166 | '&' |
||||||
167 | ) |
||||||
168 | ) |
||||||
169 | ); |
||||||
170 | $rdf->setURLParameters('type', 'id', 'page', false); |
||||||
171 | |||||||
172 | // Create SIOC-RDF content |
||||||
173 | |||||||
174 | switch ($sioc_type) { |
||||||
175 | case 'container': |
||||||
176 | $rdf = $this->exportContainercontent($rdf); |
||||||
177 | break; |
||||||
178 | |||||||
179 | case 'user': |
||||||
180 | $rdf = $this->exportUsercontent($rdf); |
||||||
181 | break; |
||||||
182 | |||||||
183 | case 'post': |
||||||
184 | default: |
||||||
185 | $rdf = $this->exportPostcontent($rdf); |
||||||
186 | break; |
||||||
187 | } |
||||||
188 | |||||||
189 | // export |
||||||
190 | if ($this->getConf('noindx')) { |
||||||
191 | header("X-Robots-Tag: noindex", true); |
||||||
192 | } |
||||||
193 | $rdf->export(); |
||||||
194 | |||||||
195 | //print_r(headers_list()); die(); |
||||||
196 | die(); |
||||||
197 | } |
||||||
198 | |||||||
199 | private function exit($headermsg) |
||||||
200 | { |
||||||
201 | header($headermsg); |
||||||
202 | die(); |
||||||
203 | } |
||||||
204 | |||||||
205 | /* -- public class methods ---------------------------------------------- */ |
||||||
206 | |||||||
207 | private function getContenttype() |
||||||
208 | { |
||||||
209 | global $ID, $conf; |
||||||
210 | |||||||
211 | // check for type if unknown |
||||||
212 | if (!($_GET['type'] ?? "")) { |
||||||
213 | $userinfo = getDwUserInfo($ID, $this); |
||||||
0 ignored issues
–
show
The function
getDwUserInfo() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
214 | |||||||
215 | if ($userinfo) { |
||||||
216 | $type = 'user'; |
||||||
217 | } elseif (isset($_GET['do']) && $_GET['do'] == 'index') { |
||||||
218 | $type = 'container'; |
||||||
219 | } else { |
||||||
220 | $type = 'post'; |
||||||
221 | } |
||||||
222 | } else { |
||||||
223 | $type = $_GET['type']; |
||||||
224 | } |
||||||
225 | |||||||
226 | return $type; |
||||||
227 | } |
||||||
228 | |||||||
229 | private function exportContainercontent($exporter) |
||||||
230 | { |
||||||
231 | global $ID, $INFO, $conf; |
||||||
232 | |||||||
233 | if ($ID == $conf['start']) { |
||||||
234 | $title = $conf['title']; |
||||||
235 | } elseif (isset($INFO['meta']['title'])) { |
||||||
236 | $title = $INFO['meta']['title']; |
||||||
237 | } else { |
||||||
238 | $title = $ID; |
||||||
239 | } |
||||||
240 | |||||||
241 | $exporter->setParameters( |
||||||
242 | 'Container: ' . $title, |
||||||
243 | getAbsUrl(), |
||||||
0 ignored issues
–
show
The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
244 | getAbsUrl() . 'doku.php?', |
||||||
0 ignored issues
–
show
The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
245 | 'utf-8', |
||||||
246 | $this->agentlink |
||||||
247 | ); |
||||||
248 | |||||||
249 | // create container object |
||||||
250 | $wikicontainer = new SIOCDokuWikiContainer( |
||||||
251 | $ID, normalizeUri($exporter->siocURL('container', $ID)) |
||||||
0 ignored issues
–
show
The function
normalizeUri() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
252 | ); |
||||||
253 | |||||||
254 | /* container is type=wiki */ |
||||||
255 | if ($ID == $conf['start']) { |
||||||
256 | $wikicontainer->isWiki(); |
||||||
257 | } |
||||||
258 | /* sioc:name */ |
||||||
259 | if ($INFO['exists']) { |
||||||
260 | $wikicontainer->addTitle($INFO['meta']['title']); |
||||||
261 | } |
||||||
262 | /* has_parent */ |
||||||
263 | if ($INFO['namespace']) { |
||||||
264 | $wikicontainer->addParent($INFO['namespace']); |
||||||
265 | } |
||||||
266 | |||||||
267 | // search next level entries (posts, sub containers) in container |
||||||
268 | require_once(DOKU_INC . 'inc/search.php'); |
||||||
269 | $dir = utf8_encodeFN(str_replace(':', '/', $ID)); |
||||||
270 | $entries = array(); |
||||||
271 | $posts = array(); |
||||||
272 | $containers = array(); |
||||||
273 | search($entries, $conf['datadir'], 'search_index', array('ns' => $ID), $dir); |
||||||
274 | foreach ($entries as $entry) { |
||||||
275 | if ($entry['type'] === 'f') { |
||||||
276 | // wikisite |
||||||
277 | $posts[] = $entry; |
||||||
278 | } elseif ($entry['type'] === 'd') { |
||||||
279 | // sub container |
||||||
280 | $containers[] = $entry; |
||||||
281 | } |
||||||
282 | } |
||||||
283 | |||||||
284 | // without sub content it can't be a container (so it does not exist as a container) |
||||||
285 | if (count($posts) + count($containers) == 0) { |
||||||
286 | $this->exit("HTTP/1.0 404 Not Found"); |
||||||
287 | } |
||||||
288 | |||||||
289 | if (count($posts) > 0) { |
||||||
290 | $wikicontainer->addArticles($posts); |
||||||
291 | } |
||||||
292 | if (count($containers) > 0) { |
||||||
293 | $wikicontainer->addContainers($containers); |
||||||
294 | } |
||||||
295 | |||||||
296 | //print_r($containers);die(); |
||||||
297 | |||||||
298 | // add container to exporter |
||||||
299 | $exporter->addObject($wikicontainer); |
||||||
300 | |||||||
301 | return $exporter; |
||||||
302 | } |
||||||
303 | |||||||
304 | /* -- private helpers --------------------------------------------------- */ |
||||||
305 | |||||||
306 | private function exportUsercontent($exporter) |
||||||
307 | { |
||||||
308 | global $ID; |
||||||
309 | |||||||
310 | // get user info |
||||||
311 | $userinfo = getDwUserInfo($ID, $this); |
||||||
0 ignored issues
–
show
The function
getDwUserInfo() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
312 | |||||||
313 | // no userinfo means there is no user space or user does not exists |
||||||
314 | if ($userinfo === false) { |
||||||
315 | $this->exit("HTTP/1.0 404 Not Found"); |
||||||
316 | } |
||||||
317 | |||||||
318 | $exporter->setParameters( |
||||||
319 | 'Account: ' . $userinfo['name'], |
||||||
320 | getAbsUrl(), |
||||||
0 ignored issues
–
show
The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
321 | getAbsUrl() . 'doku.php?', |
||||||
0 ignored issues
–
show
The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
322 | 'utf-8', |
||||||
323 | $this->agentlink |
||||||
324 | ); |
||||||
325 | // create user object |
||||||
326 | //print_r($userinfo); die(); |
||||||
327 | // $id, $url, $userid, $name, $email |
||||||
328 | $wikiuser = new SIOCDokuWikiUser( |
||||||
329 | $ID, normalizeUri($exporter->siocURL('user', $ID)), $userinfo['user'], $userinfo['name'], $userinfo['mail'] |
||||||
0 ignored issues
–
show
The function
normalizeUri() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
330 | ); |
||||||
331 | /* TODO: avatar (using Gravatar) */ /* TODO: creator_of */ |
||||||
332 | // add user to exporter |
||||||
333 | $exporter->addObject($wikiuser); |
||||||
334 | |||||||
335 | //print_r(headers_list());die(); |
||||||
336 | return $exporter; |
||||||
337 | } |
||||||
338 | |||||||
339 | private function exportPostcontent($exporter) |
||||||
340 | { |
||||||
341 | global $ID, $INFO, $REV, $conf; |
||||||
342 | |||||||
343 | $exporter->setParameters( |
||||||
344 | 'Article: ' . $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), |
||||||
345 | $this->getDokuUrl(), |
||||||
346 | $this->getDokuUrl() . 'doku.php?', |
||||||
347 | 'utf-8', |
||||||
348 | $this->agentlink |
||||||
349 | ); |
||||||
350 | |||||||
351 | // create user object |
||||||
352 | // $id, $uri, $name, $email, $homepage='', $foaf_uri='', $role=false, $nick='', $sioc_url='', $foaf_url='' |
||||||
353 | $dwuserpage_id = cleanID($this->getConf('userns')) . ($conf['useslash'] ? '/' : ':') . $INFO['editor']; |
||||||
354 | /* |
||||||
355 | if ($INFO['editor'] && $this->getConf('userns')) |
||||||
356 | $pageuser = new SIOCUser($INFO['editor'], |
||||||
357 | normalizeUri(getAbsUrl(exportlink($dwuserpage_id, 'siocxml', |
||||||
358 | array('type'=>'user'), false, '&'))), // user page |
||||||
359 | $INFO['meta']['contributor'][$INFO['editor']], |
||||||
360 | getDwUserInfo($dwuserpage_id,$this,'mail'), |
||||||
361 | '', // no homepage is saved for dokuwiki user |
||||||
362 | '#'.$INFO['editor'], // local uri |
||||||
363 | false, // no roles right now |
||||||
364 | '', // no nick name is saved for dokuwiki user |
||||||
365 | normalizeUri($exporter->siocURL('user', $dwuserpage_id)) |
||||||
366 | ); |
||||||
367 | */ |
||||||
368 | |||||||
369 | // create wiki page object |
||||||
370 | $wikipage = new SIOCDokuWikiArticle( |
||||||
371 | $ID, // id |
||||||
372 | normalizeUri( |
||||||
0 ignored issues
–
show
The function
normalizeUri() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
373 | $exporter->siocURL( |
||||||
374 | 'post', |
||||||
375 | $ID . ($REV ? $exporter->_urlseparator . 'rev' . $exporter->_urlequal . $REV : '') |
||||||
376 | ) |
||||||
377 | ), // url |
||||||
378 | $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), // subject |
||||||
379 | rawWiki($ID, $REV) // body (content) |
||||||
380 | ); |
||||||
381 | /* encoded content */ |
||||||
382 | $wikipage->addContentEncoded(p_cached_output(wikiFN($ID, $REV), 'xhtml')); |
||||||
383 | /* created */ |
||||||
384 | if (isset($INFO['meta']['date']['created'])) { |
||||||
385 | $wikipage->addCreated(date('c', $INFO['meta']['date']['created'])); |
||||||
386 | } |
||||||
387 | /* or modified */ |
||||||
388 | if (isset($INFO['meta']['date']['modified'])) { |
||||||
389 | $wikipage->addModified(date('c', $INFO['meta']['date']['modified'])); |
||||||
390 | } |
||||||
391 | /* creator/modifier */ |
||||||
392 | if ($INFO['editor'] && $this->getConf('userns')) { |
||||||
393 | $wikipage->addCreator(array('foaf:maker' => '#' . $INFO['editor'], 'sioc:modifier' => $dwuserpage_id)); |
||||||
394 | } |
||||||
395 | /* is creator */ |
||||||
396 | if (isset($INFO['meta']['date']['created'])) { |
||||||
397 | $wikipage->isCreator(); |
||||||
398 | } |
||||||
399 | /* intern wiki links */ |
||||||
400 | $wikipage->addLinks($INFO['meta']['relation']['references']); |
||||||
401 | |||||||
402 | // contributors - only for last revision b/c of wrong meta data for older revisions |
||||||
403 | if (!$REV && $this->getConf('userns') && isset($INFO['meta']['contributor'])) { |
||||||
404 | $cont_temp = array(); |
||||||
405 | $cont_ns = $this->getConf('userns') . ($conf['useslash'] ? '/' : ':'); |
||||||
406 | foreach ($INFO['meta']['contributor'] as $cont_id => $cont_name) { |
||||||
407 | $cont_temp[$cont_ns . $cont_id] = $cont_name; |
||||||
408 | } |
||||||
409 | $wikipage->addContributors($cont_temp); |
||||||
410 | } |
||||||
411 | |||||||
412 | // backlinks - only for last revision |
||||||
413 | if (!$REV) { |
||||||
414 | require_once(DOKU_INC . 'inc/fulltext.php'); |
||||||
415 | $backlinks = ft_backlinks($ID); |
||||||
416 | if (count($backlinks) > 0) { |
||||||
417 | $wikipage->addBacklinks($backlinks); |
||||||
418 | } |
||||||
419 | } |
||||||
420 | |||||||
421 | // TODO: addLinksExtern |
||||||
422 | |||||||
423 | /* previous and next revision */ |
||||||
424 | $changelog = new PageChangeLog($ID); |
||||||
425 | $pagerevs = $changelog->getRevisions(0, $conf['recent'] + 1); |
||||||
426 | $prevrev = false; |
||||||
427 | $nextrev = false; |
||||||
428 | if (!$REV) { |
||||||
429 | // latest revision, previous rev is on top in array |
||||||
430 | $prevrev = 0; |
||||||
431 | } else { |
||||||
432 | // other revision |
||||||
433 | $currentrev = array_search($REV, $pagerevs); |
||||||
434 | if ($currentrev !== false) { |
||||||
435 | $prevrev = $currentrev + 1; |
||||||
436 | $nextrev = $currentrev - 1; |
||||||
437 | } |
||||||
438 | } |
||||||
439 | if ($prevrev !== false && $prevrev > -1 && page_exists($ID, $pagerevs[$prevrev])) { |
||||||
440 | /* previous revision*/ |
||||||
441 | $wikipage->addVersionPrevious($pagerevs[$prevrev]); |
||||||
442 | } |
||||||
443 | if ($nextrev !== false && $nextrev > -1 && page_exists($ID, $pagerevs[$nextrev])) { |
||||||
444 | /* next revision*/ |
||||||
445 | $wikipage->addVersionNext($pagerevs[$nextrev]); |
||||||
446 | } |
||||||
447 | |||||||
448 | /* latest revision */ |
||||||
449 | if ($REV) { |
||||||
450 | $wikipage->addVersionLatest(); |
||||||
451 | } |
||||||
452 | // TODO: topics |
||||||
453 | /* has_container */ |
||||||
454 | if ($INFO['namespace']) { |
||||||
455 | $wikipage->addContainer($INFO['namespace']); |
||||||
456 | } |
||||||
457 | /* has_space */ |
||||||
458 | if ($this->getConf('owners')) { |
||||||
459 | $wikipage->addSite($this->getConf('owners')); |
||||||
460 | } |
||||||
461 | // TODO: dc:contributor / has_modifier |
||||||
462 | // TODO: attachment (e.g. pictures in that dwns) |
||||||
463 | |||||||
464 | // add wiki page to exporter |
||||||
465 | $exporter->addObject($wikipage); |
||||||
466 | //if ($INFO['editor'] && $this->getConf('userns')) $exporter->addObject($pageuser); |
||||||
467 | |||||||
468 | return $exporter; |
||||||
469 | } |
||||||
470 | |||||||
471 | private function getDokuUrl($url = null) |
||||||
472 | { |
||||||
473 | return getAbsUrl($url); |
||||||
0 ignored issues
–
show
The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
474 | } |
||||||
475 | |||||||
476 | public function isRdfXmlRequest(): bool |
||||||
477 | { |
||||||
478 | // get accepted types |
||||||
479 | $http_accept = trim($_SERVER['HTTP_ACCEPT']); |
||||||
480 | |||||||
481 | // save accepted types in array |
||||||
482 | $accepted = explode(',', $http_accept); |
||||||
483 | |||||||
484 | /* |
||||||
485 | $debuginfo = implode(' // ', array(date('c',$_SERVER['REQUEST_TIME']), $_SERVER['HTTP_REFERER'], |
||||||
486 | $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_HOST'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_ACCEPT'])); |
||||||
487 | global $conf; //print_r($conf); die(); |
||||||
488 | //die($debuginfo); |
||||||
489 | $debuglog = @fopen($conf['tmpdir'].DIRECTORY_SEPARATOR.'requests.log', 'ab'); |
||||||
490 | @fwrite($debuglog, $debuginfo."\n"); |
||||||
491 | @fclose($debuglog); |
||||||
492 | @chmod($conf['tmpdir'].DIRECTORY_SEPARATOR.'requests.log', 0777); |
||||||
493 | */ |
||||||
494 | |||||||
495 | // soft check, route to RDF when client requests it (don't check quality of request) |
||||||
496 | |||||||
497 | if ($this->getConf('softck') && strpos($_SERVER['HTTP_ACCEPT'], 'application/rdf+xml') !== false) { |
||||||
498 | return true; |
||||||
499 | } |
||||||
500 | |||||||
501 | if (count($accepted) > 0) { |
||||||
502 | // hard check, only serve RDF if it is requested first or equal to first type |
||||||
503 | |||||||
504 | // extract accepting ratio |
||||||
505 | $test_accept = array(); |
||||||
506 | foreach ($accepted as $format) { |
||||||
507 | $formatspec = explode(';', $format); |
||||||
508 | $k = trim($formatspec[0]); |
||||||
509 | if (count($formatspec) === 2) { |
||||||
510 | $test_accept[$k] = trim($formatspec[1]); |
||||||
511 | } else { |
||||||
512 | $test_accept[$k] = 'q=1.0'; |
||||||
513 | } |
||||||
514 | } |
||||||
515 | |||||||
516 | // sort by ratio |
||||||
517 | arsort($test_accept); |
||||||
518 | $accepted_order = array_keys($test_accept); |
||||||
519 | |||||||
520 | if ($accepted_order[0] === 'application/rdf+xml' || (array_key_exists( |
||||||
521 | 'application/rdf+xml', |
||||||
522 | $test_accept |
||||||
523 | ) && $test_accept['application/rdf+xml'] === 'q=1.0')) { |
||||||
524 | return true; |
||||||
525 | } |
||||||
526 | } |
||||||
527 | |||||||
528 | // print_r($accepted_order);print_r($test_accept);die(); |
||||||
529 | |||||||
530 | return false; |
||||||
531 | } |
||||||
532 | |||||||
533 | /** |
||||||
534 | */ |
||||||
535 | public function createRdfLink($event = null, $param = null) |
||||||
536 | { |
||||||
537 | global $ID, $INFO, $conf; |
||||||
538 | |||||||
539 | // Test for hidden pages |
||||||
540 | |||||||
541 | if (isHiddenPage($ID)) { |
||||||
542 | return false; |
||||||
543 | } |
||||||
544 | |||||||
545 | // Get type of SIOC content |
||||||
546 | |||||||
547 | $sioc_type = $this->getContenttype(); |
||||||
548 | |||||||
549 | // Test for valid types |
||||||
550 | |||||||
551 | if (!(($sioc_type === 'post' && $INFO['exists']) || $sioc_type === 'user' || $sioc_type === 'container')) { |
||||||
552 | return false; |
||||||
553 | } |
||||||
554 | |||||||
555 | // Test for permission |
||||||
556 | |||||||
557 | if (!$INFO['perm']) { |
||||||
558 | // not enough rights to see the wiki page |
||||||
559 | return false; |
||||||
560 | } |
||||||
561 | |||||||
562 | $userinfo = getDwUserInfo($ID, $this); |
||||||
0 ignored issues
–
show
The function
getDwUserInfo() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
563 | |||||||
564 | // Create attributes for meta link |
||||||
565 | |||||||
566 | $metalink['type'] = 'application/rdf+xml'; |
||||||
567 | $metalink['rel'] = 'meta'; |
||||||
568 | |||||||
569 | switch ($sioc_type) { |
||||||
570 | case 'container': |
||||||
571 | $title = htmlentities( |
||||||
572 | "Container '" . ($INFO['meta']['title'] ?? $ID) . "' (SIOC document as RDF/XML)" |
||||||
573 | ); |
||||||
574 | $queryAttr = array('type' => 'container'); |
||||||
575 | break; |
||||||
576 | |||||||
577 | case 'user': |
||||||
578 | $title = htmlentities("User account '" . $userinfo['name'] . "' (SIOC document as RDF/XML)"); |
||||||
579 | $queryAttr = array('type' => 'user'); |
||||||
580 | break; |
||||||
581 | |||||||
582 | case 'post': |
||||||
583 | default: |
||||||
584 | $title = htmlentities("Article '" . $INFO['meta']['title'] . "' (SIOC document as RDF/XML)"); |
||||||
585 | $queryAttr = array('type' => 'post'); |
||||||
586 | if (isset($_GET['rev']) && $_GET['rev'] === (int)$_GET['rev']) { |
||||||
587 | $queryAttr['rev'] = $_GET['rev']; |
||||||
588 | } |
||||||
589 | break; |
||||||
590 | } |
||||||
591 | |||||||
592 | $metalink['title'] = $title; |
||||||
593 | $metalink['href'] = normalizeUri(getAbsUrl(exportlink($ID, 'siocxml', $queryAttr, false, '&'))); |
||||||
0 ignored issues
–
show
The function
normalizeUri() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
594 | |||||||
595 | if ($event !== null) { |
||||||
596 | $event->data['link'][] = $metalink; |
||||||
597 | |||||||
598 | // set canocial link for type URIs to prevent indexing double content |
||||||
599 | if ($_GET['type'] ?? "") { |
||||||
600 | $event->data['link'][] = array('rel' => 'canonical', 'href' => getAbsUrl(wl($ID))); |
||||||
0 ignored issues
–
show
The function
getAbsUrl() has been deprecated: cleanup, use build-in function
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
601 | } |
||||||
602 | } |
||||||
603 | |||||||
604 | return $metalink; |
||||||
605 | } |
||||||
606 | } |
||||||
607 | |||||||
608 | // TODO cleanup and just have this unconditionally |
||||||
609 | if (!function_exists('getAbsUrl')) { |
||||||
610 | /** |
||||||
611 | * @param $url |
||||||
612 | * @return string |
||||||
613 | * @deprecated cleanup, use build-in function |
||||||
614 | */ |
||||||
615 | function getAbsUrl($url = null): string |
||||||
616 | { |
||||||
617 | if ($url === null) { |
||||||
618 | $url = DOKU_BASE; |
||||||
619 | } |
||||||
620 | return str_replace(DOKU_BASE, DOKU_URL, $url); |
||||||
621 | } |
||||||
622 | } |
||||||
623 | |||||||
624 | if (!function_exists('getDwUserEmail')) { |
||||||
625 | /** |
||||||
626 | * @param $user |
||||||
627 | * @return string |
||||||
628 | * @deprecated not used, will be removed |
||||||
629 | */ |
||||||
630 | function getDwUserEmail($user): string |
||||||
631 | { |
||||||
632 | global $auth; |
||||||
633 | if ($info = $auth->getUserData($user)) { |
||||||
634 | return $info['mail']; |
||||||
635 | } else { |
||||||
636 | return false; |
||||||
0 ignored issues
–
show
|
|||||||
637 | } |
||||||
638 | } |
||||||
639 | } |
||||||
640 | |||||||
641 | if (!function_exists('getDwUserInfo')) { |
||||||
642 | /** |
||||||
643 | * @param $id |
||||||
644 | * @param $pobj |
||||||
645 | * @param $key |
||||||
646 | * @return array|false |
||||||
647 | * @deprecated cleanup, use build-in function |
||||||
648 | */ |
||||||
649 | function getDwUserInfo($id, $pobj, $key = null) |
||||||
650 | { |
||||||
651 | global $auth, $conf; |
||||||
652 | |||||||
653 | if (!$pobj->getConf('userns')) { |
||||||
654 | return false; |
||||||
655 | } |
||||||
656 | |||||||
657 | // get user id |
||||||
658 | $userid = str_replace(cleanID($pobj->getConf('userns')) . ($conf['useslash'] ? '/' : ':'), '', $id); |
||||||
659 | |||||||
660 | if ($info = $auth->getUserData($userid)) { |
||||||
661 | if ($key) { |
||||||
662 | return $info['key']; |
||||||
663 | } else { |
||||||
664 | return $info; |
||||||
665 | } |
||||||
666 | } else { |
||||||
667 | return false; |
||||||
668 | } |
||||||
669 | } |
||||||
670 | } |
||||||
671 | |||||||
672 | // sort query attributes by name |
||||||
673 | if (!function_exists('normalizeUri')) { |
||||||
674 | /** |
||||||
675 | * @param $uri |
||||||
676 | * @return string |
||||||
677 | * @deprecated cleanup, use build-in function |
||||||
678 | */ |
||||||
679 | function normalizeUri($uri): string |
||||||
680 | { |
||||||
681 | // part URI |
||||||
682 | $parts = explode('?', $uri); |
||||||
683 | |||||||
684 | // part query |
||||||
685 | if (isset($parts[1])) { |
||||||
686 | $query = $parts[1]; |
||||||
687 | |||||||
688 | // test separator |
||||||
689 | $sep = '&'; |
||||||
690 | if (strpos($query, '&') !== false) { |
||||||
691 | $sep = '&'; |
||||||
692 | } |
||||||
693 | $attr = explode($sep, $query); |
||||||
694 | |||||||
695 | sort($attr); |
||||||
696 | |||||||
697 | $parts[1] = implode($sep, $attr); |
||||||
698 | } |
||||||
699 | |||||||
700 | return implode('?', $parts); |
||||||
701 | } |
||||||
702 | } |
||||||
703 | |||||||
704 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.