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