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 | if (!defined('DOKU_INC')) { |
||
72 | die(); |
||
73 | } |
||
74 | if (!defined('DOKU_PLUGIN')) { |
||
75 | define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); |
||
1 ignored issue
–
show
Bug
introduced
by
![]() |
|||
76 | } |
||
77 | require_once(DOKU_PLUGIN.'action.php'); |
||
78 | |||
79 | class action_plugin_dokusioc extends DokuWiki_Action_Plugin { |
||
80 | |||
81 | var $agentlink = 'http://eye48.com/go/dokusioc?v=0.1.2'; |
||
82 | |||
83 | |||
84 | /* -- Methods to manage plugin ------------------------------------------ */ |
||
85 | |||
86 | /** |
||
87 | * Register its handlers with the DokuWiki's event controller |
||
88 | */ |
||
89 | public function register(Doku_Event_Handler $controller) |
||
90 | { |
||
91 | //print_r(headers_list()); die(); |
||
92 | |||
93 | // test the requested action |
||
94 | $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'checkAction', $controller); |
||
95 | // pingthesemanticweb.com |
||
96 | if ($this->getConf('pingsw')) { |
||
97 | $controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'pingService', $controller); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /* -- Event handlers ---------------------------------------------------- */ |
||
102 | |||
103 | public function checkAction($action, $controller) |
||
104 | { |
||
105 | global $INFO; |
||
106 | //print_r($INFO); die(); |
||
107 | //print_r(headers_list()); die(); |
||
108 | |||
109 | if ($action->data == 'export_siocxml') |
||
110 | { |
||
111 | // give back rdf |
||
112 | $this->exportSioc(); |
||
113 | } elseif (($action->data == 'show' || $action->data == 'index') && $INFO['perm'] && !defined('DOKU_MEDIADETAIL') && ($INFO['exists'] || getDwUserInfo($INFO['id'], $this)) && !isHiddenPage($INFO['id'])) |
||
114 | { |
||
115 | if ($this->isRdfXmlRequest()) |
||
116 | { |
||
117 | // forward to rdfxml document if requested |
||
118 | // print_r(headers_list()); die(); |
||
119 | $location = $this->createRdfLink(); |
||
120 | if (function_exists('header_remove')) { |
||
121 | header_remove(); |
||
122 | } |
||
123 | header('Location: '.$location['href'], true, 303); exit(); |
||
124 | } else |
||
125 | { |
||
126 | // add meta link to html head |
||
127 | $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'createRdfLink'); |
||
128 | } |
||
129 | } |
||
130 | /* |
||
131 | else |
||
132 | { |
||
133 | print_r(array($action->data, $INFO['perm'], defined('DOKU_MEDIADETAIL'), $INFO['exists'], getDwUserInfo($INFO['id'],$this), isHiddenPage($INFO['id']))); |
||
134 | die(); |
||
135 | } |
||
136 | */ |
||
137 | } |
||
138 | |||
139 | public function pingService($data, $controller) |
||
140 | { |
||
141 | // TODO: test acl |
||
142 | // TODO: write in message queue (?) |
||
143 | |||
144 | if ($data->data['preact'] == array('save'=>'Save') || $data->data['preact'] == 'save') |
||
145 | { |
||
146 | //die('http://pingthesemanticweb.com/rest/?url='.urlencode(getAbsUrl(wl($data->data['id'])))); |
||
147 | //$ping = fopen('http://pingthesemanticweb.com/rest/?url='.urlencode(getAbsUrl(wl($data->data['id']))),'r'); |
||
148 | // it must be a post, and it's the last revision |
||
149 | $ping = @fopen('http://pingthesemanticweb.com/rest/?url='.urlencode(normalizeUri(getAbsUrl(exportlink($data->data['id'], 'siocxml', array('type'=>'post'), false, '&')))), 'r'); |
||
150 | @fclose($ping); |
||
151 | } |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | */ |
||
156 | public function createRdfLink($event = null, $param = null) |
||
157 | { |
||
158 | global $ID, $INFO, $conf; |
||
159 | |||
160 | // Test for hidden pages |
||
161 | |||
162 | if (isHiddenPage($ID)) { |
||
163 | return false; |
||
164 | } |
||
165 | |||
166 | // Get type of SIOC content |
||
167 | |||
168 | $sioc_type = $this->_getContenttype(); |
||
169 | |||
170 | // Test for valid types |
||
171 | |||
172 | if (!(($sioc_type == 'post' && $INFO['exists']) || $sioc_type == 'user' || $sioc_type == 'container')) { |
||
173 | return false; |
||
174 | } |
||
175 | |||
176 | // Test for permission |
||
177 | |||
178 | if (!$INFO['perm']) { |
||
179 | // not enough rights to see the wiki page |
||
180 | return false; |
||
181 | } |
||
182 | |||
183 | $userinfo = getDwUserInfo($ID, $this); |
||
184 | |||
185 | // Create attributes for meta link |
||
186 | |||
187 | $metalink['type'] = 'application/rdf+xml'; |
||
188 | $metalink['rel'] = 'meta'; |
||
189 | |||
190 | switch ($sioc_type) |
||
191 | { |
||
192 | case 'container': |
||
193 | $title = htmlentities("Container '".(isset($INFO['meta']['title']) ? $INFO['meta']['title'] : $ID)."' (SIOC document as RDF/XML)"); |
||
194 | $queryAttr = array('type'=>'container'); |
||
195 | break; |
||
196 | |||
197 | case 'user': |
||
198 | $title = htmlentities("User account '".$userinfo['name']."' (SIOC document as RDF/XML)"); |
||
199 | $queryAttr = array('type'=>'user'); |
||
200 | break; |
||
201 | |||
202 | case 'post': |
||
203 | default: |
||
204 | $title = htmlentities("Article '".$INFO['meta']['title']."' (SIOC document as RDF/XML)"); |
||
205 | $queryAttr = array('type'=>'post'); |
||
206 | if (isset($_GET['rev']) && $_GET['rev'] == intval($_GET['rev'])) { |
||
207 | $queryAttr['rev'] = $_GET['rev']; |
||
208 | } |
||
209 | break; |
||
210 | } |
||
211 | |||
212 | $metalink['title'] = $title; |
||
213 | $metalink['href'] = normalizeUri(getAbsUrl(exportlink($ID, 'siocxml', $queryAttr, false, '&'))); |
||
214 | |||
215 | if ($event !== null) |
||
216 | { |
||
217 | $event->data['link'][] = $metalink; |
||
218 | |||
219 | // set canocial link for type URIs to prevent indexing double content |
||
220 | if ($_GET['type']) { |
||
221 | $event->data['link'][] = array('rel'=>'canonical', 'href'=>getAbsUrl(wl($ID))); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | return $metalink; |
||
226 | } |
||
227 | |||
228 | /* -- public class methods ---------------------------------------------- */ |
||
229 | |||
230 | public function exportSioc() |
||
231 | { |
||
232 | global $ID, $INFO, $conf, $REV, $auth; |
||
233 | |||
234 | // Test for hidden pages |
||
235 | |||
236 | if (isHiddenPage($ID)) { |
||
237 | $this->_exit("HTTP/1.0 404 Not Found"); |
||
238 | } |
||
239 | |||
240 | // Get type of SIOC content |
||
241 | |||
242 | $sioc_type = $this->_getContenttype(); |
||
243 | |||
244 | // Test for valid types |
||
245 | |||
246 | if (!(($sioc_type == 'post' && $INFO['exists']) || $sioc_type == 'user' || $sioc_type == 'container')) { |
||
247 | $this->_exit("HTTP/1.0 404 Not Found"); |
||
248 | } |
||
249 | |||
250 | // Test for permission |
||
251 | |||
252 | if (!$INFO['perm']) { |
||
253 | // not enough rights to see the wiki page |
||
254 | $this->_exit("HTTP/1.0 401 Unauthorized"); |
||
255 | } |
||
256 | |||
257 | // Forward to URI with explicit type attribut |
||
258 | if (!isset($_GET['type'])) { |
||
259 | header('Location:'.$_SERVER['REQUEST_URI'].'&type='.$sioc_type, true, 302); |
||
260 | } |
||
261 | |||
262 | // Include SIOC libs |
||
263 | |||
264 | require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'sioc_inc.php'); |
||
265 | require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'sioc_dokuwiki.php'); |
||
266 | |||
267 | // Create exporter |
||
268 | |||
269 | $rdf = new SIOCExporter(); |
||
270 | $rdf->_profile_url = normalizeUri(getAbsUrl(exportlink($ID, 'siocxml', array('type'=>$sioc_type), false, '&'))); |
||
271 | $rdf->setURLParameters('type', 'id', 'page', false); |
||
272 | |||
273 | // Create SIOC-RDF content |
||
274 | |||
275 | switch ($sioc_type) |
||
276 | { |
||
277 | case 'container': |
||
278 | $rdf = $this->_exportContainercontent($rdf); |
||
279 | break; |
||
280 | |||
281 | case 'user': |
||
282 | $rdf = $this->_exportUsercontent($rdf); |
||
283 | break; |
||
284 | |||
285 | case 'post': |
||
286 | default: |
||
287 | $rdf = $this->_exportPostcontent($rdf); |
||
288 | break; |
||
289 | } |
||
290 | |||
291 | // export |
||
292 | if ($this->getConf('noindx')) { |
||
293 | header("X-Robots-Tag: noindex", true); |
||
294 | } |
||
295 | $rdf->export(); |
||
296 | |||
297 | //print_r(headers_list()); die(); |
||
298 | die(); |
||
299 | } |
||
300 | |||
301 | public function isRdfXmlRequest() |
||
302 | { |
||
303 | // get accepted types |
||
304 | $http_accept = trim($_SERVER['HTTP_ACCEPT']); |
||
305 | |||
306 | // save accepted types in array |
||
307 | $accepted = explode(',', $http_accept); |
||
308 | |||
309 | /* |
||
310 | $debuginfo = implode(' // ', array(date('c',$_SERVER['REQUEST_TIME']), $_SERVER['HTTP_REFERER'], $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_HOST'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_ACCEPT'])); |
||
311 | global $conf; //print_r($conf); die(); |
||
312 | //die($debuginfo); |
||
313 | $debuglog = @fopen($conf['tmpdir'].DIRECTORY_SEPARATOR.'requests.log', 'ab'); |
||
314 | @fwrite($debuglog, $debuginfo."\n"); |
||
315 | @fclose($debuglog); |
||
316 | @chmod($conf['tmpdir'].DIRECTORY_SEPARATOR.'requests.log', 0777); |
||
317 | */ |
||
318 | |||
319 | // soft check, route to RDF when client requests it (don't check quality of request) |
||
320 | |||
321 | if ($this->getConf('softck') && strpos($_SERVER['HTTP_ACCEPT'], 'application/rdf+xml') !== false) |
||
322 | { |
||
323 | return true; |
||
324 | } |
||
325 | |||
326 | if (count($accepted) > 0) |
||
327 | { |
||
328 | // hard check, only serve RDF if it is requested first or equal to first type |
||
329 | |||
330 | // extract accepting ratio |
||
331 | $test_accept = array(); |
||
332 | foreach ($accepted as $format) |
||
333 | { |
||
334 | $formatspec = explode(';', $format); |
||
335 | $k = trim($formatspec[0]); |
||
336 | if (count($formatspec) == 2) |
||
337 | { |
||
338 | $test_accept[$k] = trim($formatspec[1]); |
||
339 | } else |
||
340 | { |
||
341 | $test_accept[$k] = 'q=1.0'; |
||
342 | } |
||
343 | } |
||
344 | |||
345 | // sort by ratio |
||
346 | arsort($test_accept); $accepted_order = array_keys($test_accept); |
||
347 | |||
348 | if ($accepted_order[0] == 'application/rdf+xml' || $test_accept['application/rdf+xml'] == 'q=1.0') |
||
349 | { |
||
350 | return true; |
||
351 | } |
||
352 | } |
||
353 | |||
354 | // print_r($accepted_order);print_r($test_accept);die(); |
||
355 | |||
356 | return false; |
||
357 | |||
358 | } |
||
359 | |||
360 | /* -- private helpers --------------------------------------------------- */ |
||
361 | |||
362 | private function _getContenttype() |
||
363 | { |
||
364 | global $ID, $conf; |
||
365 | |||
366 | // check for type if unknown |
||
367 | if (!$_GET['type']) |
||
368 | { |
||
369 | $userinfo = getDwUserInfo($ID, $this); |
||
370 | |||
371 | if ($userinfo) |
||
372 | { |
||
373 | $type = 'user'; |
||
374 | } elseif (isset($_GET['do']) && $_GET['do'] == 'index') |
||
375 | { |
||
376 | $type = 'container'; |
||
377 | } else |
||
378 | { |
||
379 | $type = 'post'; |
||
380 | } |
||
381 | |||
382 | } else |
||
383 | { |
||
384 | $type = $_GET['type']; |
||
385 | } |
||
386 | |||
387 | return $type; |
||
388 | |||
389 | } |
||
390 | |||
391 | private function _exportPostcontent($exporter) |
||
392 | { |
||
393 | global $ID, $INFO, $REV, $conf; |
||
394 | |||
395 | $exporter->setParameters('Article: '.$INFO['meta']['title'].($REV ? ' (rev '.$REV.')' : ''), |
||
396 | $this->_getDokuUrl(), |
||
397 | $this->_getDokuUrl().'doku.php?', |
||
398 | 'utf-8', |
||
399 | $this->agentlink |
||
400 | ); |
||
401 | |||
402 | // create user object |
||
403 | // $id, $uri, $name, $email, $homepage='', $foaf_uri='', $role=false, $nick='', $sioc_url='', $foaf_url='' |
||
404 | $dwuserpage_id = cleanID($this->getConf('userns')).($conf['useslash'] ? '/' : ':').$INFO['editor']; |
||
405 | /* |
||
406 | if ($INFO['editor'] && $this->getConf('userns')) |
||
407 | $pageuser = new SIOCUser($INFO['editor'], |
||
408 | normalizeUri(getAbsUrl(exportlink($dwuserpage_id, 'siocxml', array('type'=>'user'), false, '&'))), // user page |
||
409 | $INFO['meta']['contributor'][$INFO['editor']], |
||
410 | getDwUserInfo($dwuserpage_id,$this,'mail'), |
||
411 | '', // no homepage is saved for dokuwiki user |
||
412 | '#'.$INFO['editor'], // local uri |
||
413 | false, // no roles right now |
||
414 | '', // no nick name is saved for dokuwiki user |
||
415 | normalizeUri($exporter->siocURL('user', $dwuserpage_id)) |
||
416 | ); |
||
417 | */ |
||
418 | |||
419 | // create wiki page object |
||
420 | $wikipage = new SIOCDokuWikiArticle($ID, // id |
||
421 | normalizeUri($exporter->siocURL('post', $ID.($REV ? $exporter->_urlseparator.'rev'.$exporter->_urlequal.$REV : ''))), // url |
||
422 | $INFO['meta']['title'].($REV ? ' (rev '.$REV.')' : ''), // subject |
||
423 | rawWiki($ID, $REV) // body (content) |
||
424 | ); |
||
425 | /* encoded content */ $wikipage->addContentEncoded(p_cached_output(wikiFN($ID, $REV), 'xhtml')); |
||
426 | /* created */ if (isset($INFO['meta']['date']['created'])) { |
||
427 | $wikipage->addCreated(date('c', $INFO['meta']['date']['created'])); |
||
428 | } |
||
429 | /* or modified */ if (isset($INFO['meta']['date']['modified'])) { |
||
430 | $wikipage->addModified(date('c', $INFO['meta']['date']['modified'])); |
||
431 | } |
||
432 | /* creator/modifier */ if ($INFO['editor'] && $this->getConf('userns')) { |
||
433 | $wikipage->addCreator(array('foaf:maker'=>'#'.$INFO['editor'], 'sioc:modifier'=>$dwuserpage_id)); |
||
434 | } |
||
435 | /* is creator */ if (isset($INFO['meta']['date']['created'])) { |
||
436 | $wikipage->isCreator(); |
||
437 | } |
||
438 | /* intern wiki links */ $wikipage->addLinks($INFO['meta']['relation']['references']); |
||
439 | |||
440 | // contributors - only for last revision b/c of wrong meta data for older revisions |
||
441 | if (!$REV && $this->getConf('userns') && isset($INFO['meta']['contributor'])) |
||
442 | { |
||
443 | $cont_temp = array(); |
||
444 | $cont_ns = $this->getConf('userns').($conf['useslash'] ? '/' : ':'); |
||
445 | foreach ($INFO['meta']['contributor'] as $cont_id => $cont_name) { |
||
446 | $cont_temp[$cont_ns.$cont_id] = $cont_name; |
||
447 | } |
||
448 | $wikipage->addContributors($cont_temp); |
||
449 | } |
||
450 | |||
451 | // backlinks - only for last revision |
||
452 | if (!$REV) |
||
453 | { |
||
454 | require_once(DOKU_INC.'inc/fulltext.php'); |
||
455 | $backlinks = ft_backlinks($ID); |
||
456 | if (count($backlinks) > 0) { |
||
457 | $wikipage->addBacklinks($backlinks); |
||
458 | } |
||
459 | } |
||
460 | |||
461 | // TODO: addLinksExtern |
||
462 | |||
463 | /* previous and next revision */ |
||
464 | $changelog = new PageChangeLog($ID); |
||
465 | $pagerevs = $changelog->getRevisions(0, $conf['recent'] + 1); |
||
466 | $prevrev = false; $nextrev = false; |
||
467 | if (!$REV) |
||
468 | { |
||
469 | // latest revision, previous rev is on top in array |
||
470 | $prevrev = 0; |
||
471 | } else |
||
472 | { |
||
473 | // other revision |
||
474 | $currentrev = array_search($REV, $pagerevs); |
||
475 | if ($currentrev !== false) |
||
476 | { |
||
477 | $prevrev = $currentrev + 1; |
||
478 | $nextrev = $currentrev - 1; |
||
479 | } |
||
480 | } |
||
481 | if ($prevrev !== false && $prevrev > -1 && page_exists($ID, $pagerevs[$prevrev])) { |
||
482 | /* previous revision*/ $wikipage->addVersionPrevious($pagerevs[$prevrev]); |
||
483 | } |
||
484 | if ($nextrev !== false && $nextrev > -1 && page_exists($ID, $pagerevs[$nextrev])) { |
||
485 | /* next revision*/ $wikipage->addVersionNext($pagerevs[$nextrev]); |
||
486 | } |
||
487 | |||
488 | /* latest revision */ if ($REV) { |
||
489 | $wikipage->addVersionLatest(); |
||
490 | } |
||
491 | // TODO: topics |
||
492 | /* has_container */ if ($INFO['namespace']) { |
||
493 | $wikipage->addContainer($INFO['namespace']); |
||
494 | } |
||
495 | /* has_space */ if ($this->getConf('owners')) { |
||
496 | $wikipage->addSite($this->getConf('owners')); |
||
497 | } |
||
498 | // TODO: dc:contributor / has_modifier |
||
499 | // TODO: attachment (e.g. pictures in that dwns) |
||
500 | |||
501 | // add wiki page to exporter |
||
502 | $exporter->addObject($wikipage); |
||
503 | //if ($INFO['editor'] && $this->getConf('userns')) $exporter->addObject($pageuser); |
||
504 | |||
505 | return $exporter; |
||
506 | |||
507 | } |
||
508 | |||
509 | private function _exportContainercontent($exporter) |
||
510 | { |
||
511 | global $ID, $INFO, $conf; |
||
512 | |||
513 | if ($ID == $conf['start']) |
||
514 | { |
||
515 | $title = $conf['title']; |
||
516 | } elseif (isset($INFO['meta']['title'])) |
||
517 | { |
||
518 | $title = $INFO['meta']['title']; |
||
519 | } else |
||
520 | { |
||
521 | $title = $ID; |
||
522 | } |
||
523 | |||
524 | |||
525 | $exporter->setParameters('Container: '.$title, |
||
526 | getAbsUrl(), |
||
527 | getAbsUrl().'doku.php?', |
||
528 | 'utf-8', |
||
529 | $this->agentlink |
||
530 | ); |
||
531 | |||
532 | // create container object |
||
533 | $wikicontainer = new SIOCDokuWikiContainer($ID, |
||
534 | normalizeUri($exporter->siocURL('container', $ID)) |
||
535 | ); |
||
536 | |||
537 | /* container is type=wiki */ if ($ID == $conf['start']) { |
||
538 | $wikicontainer->isWiki(); |
||
539 | } |
||
540 | /* sioc:name */ if ($INFO['exists']) { |
||
541 | $wikicontainer->addTitle($INFO['meta']['title']); |
||
542 | } |
||
543 | /* has_parent */ if ($INFO['namespace']) { |
||
544 | $wikicontainer->addParent($INFO['namespace']); |
||
545 | } |
||
546 | |||
547 | // search next level entries (posts, sub containers) in container |
||
548 | require_once(DOKU_INC.'inc/search.php'); |
||
549 | $dir = utf8_encodeFN(str_replace(':', '/', $ID)); |
||
550 | $entries = array(); |
||
551 | $posts = array(); |
||
552 | $containers = array(); |
||
553 | search($entries, $conf['datadir'], 'search_index', array('ns' => $ID), $dir); |
||
554 | foreach ($entries as $entry) |
||
555 | { |
||
556 | if ($entry['type'] === 'f') |
||
557 | { |
||
558 | // wikisite |
||
559 | $posts[] = $entry; |
||
560 | } elseif ($entry['type'] === 'd') |
||
561 | { |
||
562 | // sub container |
||
563 | $containers[] = $entry; |
||
564 | } |
||
565 | } |
||
566 | |||
567 | // without sub content it can't be a container (so it does not exist as a container) |
||
568 | if (count($posts) + count($containers) == 0) { |
||
569 | $this->_exit("HTTP/1.0 404 Not Found"); |
||
570 | } |
||
571 | |||
572 | if (count($posts) > 0) { |
||
573 | $wikicontainer->addArticles($posts); |
||
574 | } |
||
575 | if (count($containers) > 0) { |
||
576 | $wikicontainer->addContainers($containers); |
||
577 | } |
||
578 | |||
579 | //print_r($containers);die(); |
||
580 | |||
581 | // add container to exporter |
||
582 | $exporter->addObject($wikicontainer); |
||
583 | |||
584 | return $exporter; |
||
585 | } |
||
586 | |||
587 | private function _exportUsercontent($exporter) |
||
588 | { |
||
589 | global $ID; |
||
590 | |||
591 | // get user info |
||
592 | $userinfo = getDwUserInfo($ID, $this); |
||
593 | |||
594 | // no userinfo means there is n user space or user does not exists |
||
595 | if ($userinfo === false) { |
||
596 | $this->_exit("HTTP/1.0 404 Not Found"); |
||
597 | } |
||
598 | |||
599 | $exporter->setParameters('Account: '.$userinfo['name'], |
||
600 | getAbsUrl(), |
||
601 | getAbsUrl().'doku.php?', |
||
602 | 'utf-8', |
||
603 | $this->agentlink |
||
604 | ); |
||
605 | // create user object |
||
606 | //print_r($userinfo); die(); |
||
607 | $wikiuser = new SIOCDokuWikiUser($ID, |
||
608 | normalizeUri($exporter->siocURL('user', $ID)), |
||
609 | $userid, |
||
610 | $userinfo['name'], |
||
611 | $userinfo['mail']); |
||
612 | /* TODO: avatar (using Gravatar) */ |
||
613 | /* TODO: creator_of */ |
||
614 | // add user to exporter |
||
615 | $exporter->addObject($wikiuser); |
||
616 | |||
617 | //print_r(headers_list());die(); |
||
618 | return $exporter; |
||
619 | } |
||
620 | |||
621 | private function _exit($headermsg) |
||
622 | { |
||
623 | header($headermsg); |
||
624 | die(); |
||
625 | } |
||
626 | |||
627 | private function _getDokuUrl($url = null) |
||
628 | { |
||
629 | return getAbsUrl($url); |
||
630 | } |
||
631 | |||
632 | private function _getDate($date, $date_alt = null) |
||
633 | { |
||
634 | if (!$date) { |
||
635 | $date = $date_alt; |
||
636 | } |
||
637 | return date('c', $date); |
||
638 | } |
||
639 | |||
640 | } |
||
641 | |||
642 | if (!function_exists('getAbsUrl')) |
||
643 | { |
||
644 | function getAbsUrl($url = null) |
||
645 | { |
||
646 | if ($url == null) { |
||
647 | $url = DOKU_BASE; |
||
648 | } |
||
649 | return str_replace(DOKU_BASE, DOKU_URL, $url); |
||
650 | } |
||
651 | } |
||
652 | |||
653 | if (!function_exists('getDwUserEmail')) |
||
654 | { |
||
655 | function getDwUserEmail($user) |
||
656 | { |
||
657 | global $auth; |
||
658 | if ($info = $auth->getUserData($user)) |
||
659 | { |
||
660 | return $info['mail']; |
||
661 | } else |
||
662 | { |
||
663 | return false; |
||
664 | } |
||
665 | } |
||
666 | } |
||
667 | |||
668 | if (!function_exists('getDwUserInfo')) |
||
669 | { |
||
670 | function getDwUserInfo($id, $pobj, $key = null) |
||
671 | { |
||
672 | global $auth, $conf; |
||
673 | |||
674 | if (!$pobj->getConf('userns')) { |
||
675 | return false; |
||
676 | } |
||
677 | |||
678 | // get user id |
||
679 | $userid = str_replace(cleanID($pobj->getConf('userns')).($conf['useslash'] ? '/' : ':'), '', $id); |
||
680 | |||
681 | if ($info = $auth->getUserData($userid)) |
||
682 | { |
||
683 | if ($key) |
||
684 | { |
||
685 | return $info['key']; |
||
686 | } else |
||
687 | { |
||
688 | return $info; |
||
689 | } |
||
690 | } else |
||
691 | { |
||
692 | return false; |
||
693 | } |
||
694 | } |
||
695 | } |
||
696 | |||
697 | // sort query attributes by name |
||
698 | if (!function_exists('normalizeUri')) |
||
699 | { |
||
700 | function normalizeUri($uri) |
||
701 | { |
||
702 | // part URI |
||
703 | $parts = explode('?', $uri); |
||
704 | |||
705 | // part query |
||
706 | if (isset($parts[1])) |
||
707 | { |
||
708 | $query = $parts[1]; |
||
709 | |||
710 | // test separator |
||
711 | $sep = '&'; |
||
712 | if (strpos($query, '&') !== false) { |
||
713 | $sep = '&'; |
||
714 | } |
||
715 | $attr = explode($sep, $query); |
||
716 | |||
717 | sort($attr); |
||
718 | |||
719 | $parts[1] = implode($sep, $attr); |
||
720 | } |
||
721 | |||
722 | return implode('?', $parts); |
||
723 | } |
||
724 | } |
||
725 | |||
726 |