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