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