Total Complexity | 97 |
Total Lines | 512 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 1 | Features | 2 |
Complex classes like action_plugin_dokusioc often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use action_plugin_dokusioc, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
28 | class action_plugin_dokusioc extends DokuWiki_Action_Plugin |
||
29 | { |
||
30 | |||
31 | private $agentlink = 'http://eye48.com/go/dokusioc?v=0.1.2'; |
||
32 | |||
33 | /** |
||
34 | * Register it's handlers with the DokuWiki's event controller |
||
35 | */ |
||
36 | public function register(Doku_Event_Handler $controller): void |
||
41 | } |
||
42 | |||
43 | /* -- Event handlers ---------------------------------------------------- */ |
||
44 | |||
45 | public function checkAction($action, $controller) |
||
46 | { |
||
47 | global $INFO; |
||
48 | //print_r($INFO); die(); |
||
49 | //print_r(headers_list()); die(); |
||
50 | |||
51 | if ($action->data === 'export_siocxml') { |
||
52 | // give back rdf |
||
53 | $this->exportSioc(); |
||
54 | } elseif (($action->data === 'show' || $action->data === 'index') && $INFO['perm'] && !defined( |
||
55 | 'DOKU_MEDIADETAIL' |
||
56 | ) && ($INFO['exists'] || getDwUserInfo($INFO['id'], $this)) && !isHiddenPage($INFO['id'])) { |
||
|
|||
57 | if ($this->isRdfXmlRequest()) { |
||
58 | // forward to rdfxml document if requested |
||
59 | // print_r(headers_list()); die(); |
||
60 | $location = $this->createRdfLink(); |
||
61 | if (function_exists('header_remove')) { |
||
62 | header_remove(); |
||
63 | } |
||
64 | header('Location: ' . $location['href'], true, 303); |
||
65 | exit(); |
||
66 | } else { |
||
67 | // add meta link to html head |
||
68 | $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'createRdfLink'); |
||
69 | } |
||
70 | } |
||
71 | /* |
||
72 | else |
||
73 | { |
||
74 | print_r(array($action->data, $INFO['perm'], defined('DOKU_MEDIADETAIL'), $INFO['exists'], |
||
75 | getDwUserInfo($INFO['id'],$this), isHiddenPage($INFO['id']))); |
||
76 | die(); |
||
77 | } |
||
78 | */ |
||
79 | } |
||
80 | |||
81 | public function exportSioc() |
||
82 | { |
||
83 | global $ID, $INFO; |
||
84 | |||
85 | if (isHiddenPage($ID)) { |
||
86 | $this->exit("HTTP/1.0 404 Not Found"); |
||
87 | } |
||
88 | |||
89 | $sioc_type = $this->getContenttype(); |
||
90 | |||
91 | // Test for valid types |
||
92 | if (!(($sioc_type == 'post' && $INFO['exists']) || $sioc_type == 'user' || $sioc_type == 'container')) { |
||
93 | $this->exit("HTTP/1.0 404 Not Found"); |
||
94 | } |
||
95 | |||
96 | // Test for permission |
||
97 | if (!$INFO['perm']) { |
||
98 | // not enough rights to see the wiki page |
||
99 | $this->exit("HTTP/1.0 401 Unauthorized"); |
||
100 | } |
||
101 | |||
102 | // Forward to URI with explicit type attribut |
||
103 | if (!isset($_GET['type'])) { |
||
104 | header('Location:' . $_SERVER['REQUEST_URI'] . '&type=' . $sioc_type, true, 302); |
||
105 | } |
||
106 | |||
107 | // Include SIOC libs |
||
108 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sioc_inc.php'); |
||
109 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sioc_dokuwiki.php'); |
||
110 | |||
111 | // Create exporter |
||
112 | |||
113 | $rdf = new SIOCExporter(); |
||
114 | $rdf->profile_url = normalizeUri( |
||
115 | getAbsUrl( |
||
116 | exportlink( |
||
117 | $ID, |
||
118 | 'siocxml', |
||
119 | array('type' => $sioc_type), |
||
120 | false, |
||
121 | '&' |
||
122 | ) |
||
123 | ) |
||
124 | ); |
||
125 | $rdf->setURLParameters('type', 'id', 'page', false); |
||
126 | |||
127 | // Create SIOC-RDF content |
||
128 | |||
129 | switch ($sioc_type) { |
||
130 | case 'container': |
||
131 | $rdf = $this->exportContainercontent($rdf); |
||
132 | break; |
||
133 | |||
134 | case 'user': |
||
135 | $rdf = $this->exportUsercontent($rdf); |
||
136 | break; |
||
137 | |||
138 | case 'post': |
||
139 | default: |
||
140 | $rdf = $this->exportPostcontent($rdf); |
||
141 | break; |
||
142 | } |
||
143 | |||
144 | // export |
||
145 | if ($this->getConf('noindx')) { |
||
146 | header("X-Robots-Tag: noindex", true); |
||
147 | } |
||
148 | $rdf->export(); |
||
149 | |||
150 | //print_r(headers_list()); die(); |
||
151 | die(); |
||
152 | } |
||
153 | |||
154 | private function exit($headermsg) |
||
155 | { |
||
156 | header($headermsg); |
||
157 | die(); |
||
158 | } |
||
159 | |||
160 | /* -- public class methods ---------------------------------------------- */ |
||
161 | |||
162 | private function getContenttype() |
||
182 | } |
||
183 | |||
184 | private function exportContainercontent($exporter) |
||
185 | { |
||
186 | global $ID, $INFO, $conf; |
||
187 | |||
188 | if ($ID == $conf['start']) { |
||
189 | $title = $conf['title']; |
||
190 | } elseif (isset($INFO['meta']['title'])) { |
||
191 | $title = $INFO['meta']['title']; |
||
192 | } else { |
||
193 | $title = $ID; |
||
194 | } |
||
195 | |||
196 | $exporter->setParameters( |
||
197 | 'Container: ' . $title, |
||
198 | getAbsUrl(), |
||
199 | getAbsUrl() . 'doku.php?', |
||
200 | 'utf-8', |
||
201 | $this->agentlink |
||
202 | ); |
||
203 | |||
204 | // create container object |
||
205 | $wikicontainer = new SIOCDokuWikiContainer( |
||
206 | $ID, |
||
207 | normalizeUri($exporter->siocURL('container', $ID)) |
||
208 | ); |
||
209 | |||
210 | /* container is type=wiki */ |
||
211 | if ($ID == $conf['start']) { |
||
212 | $wikicontainer->isWiki(); |
||
213 | } |
||
214 | /* sioc:name */ |
||
215 | if ($INFO['exists']) { |
||
216 | $wikicontainer->addTitle($INFO['meta']['title']); |
||
217 | } |
||
218 | /* has_parent */ |
||
219 | if ($INFO['namespace']) { |
||
220 | $wikicontainer->addParent($INFO['namespace']); |
||
221 | } |
||
222 | |||
223 | // search next level entries (posts, sub containers) in container |
||
224 | require_once(DOKU_INC . 'inc/search.php'); |
||
225 | $dir = utf8_encodeFN(str_replace(':', '/', $ID)); |
||
226 | $entries = array(); |
||
227 | $posts = array(); |
||
228 | $containers = array(); |
||
229 | search($entries, $conf['datadir'], 'search_index', array('ns' => $ID), $dir); |
||
230 | foreach ($entries as $entry) { |
||
231 | if ($entry['type'] === 'f') { |
||
232 | // wikisite |
||
233 | $posts[] = $entry; |
||
234 | } elseif ($entry['type'] === 'd') { |
||
235 | // sub container |
||
236 | $containers[] = $entry; |
||
237 | } |
||
238 | } |
||
239 | |||
240 | // without sub content it can't be a container (so it does not exist as a container) |
||
241 | if (count($posts) + count($containers) == 0) { |
||
242 | $this->exit("HTTP/1.0 404 Not Found"); |
||
243 | } |
||
244 | |||
245 | if (count($posts) > 0) { |
||
246 | $wikicontainer->addArticles($posts); |
||
247 | } |
||
248 | if (count($containers) > 0) { |
||
249 | $wikicontainer->addContainers($containers); |
||
250 | } |
||
251 | |||
252 | //print_r($containers);die(); |
||
253 | |||
254 | // add container to exporter |
||
255 | $exporter->addObject($wikicontainer); |
||
256 | |||
257 | return $exporter; |
||
258 | } |
||
259 | |||
260 | /* -- private helpers --------------------------------------------------- */ |
||
261 | |||
262 | private function exportUsercontent($exporter) |
||
297 | } |
||
298 | |||
299 | private function exportPostcontent($exporter) |
||
300 | { |
||
301 | global $ID, $INFO, $REV, $conf; |
||
302 | |||
303 | $exporter->setParameters( |
||
304 | $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), |
||
305 | $this->getDokuUrl(), |
||
306 | $this->getDokuUrl() . 'doku.php?', |
||
307 | 'utf-8', |
||
308 | $this->agentlink |
||
309 | ); |
||
310 | |||
311 | // create user object |
||
312 | $dwuserpage_id = cleanID($this->getConf('userns')) . ($conf['useslash'] ? '/' : ':') . $INFO['editor']; |
||
313 | // create wiki page object |
||
314 | $wikipage = new SIOCDokuWikiArticle( |
||
315 | $ID, // id |
||
316 | normalizeUri( |
||
317 | $exporter->siocURL( |
||
318 | 'post', |
||
319 | $ID . ($REV ? $exporter->_urlseparator . 'rev' . $exporter->_urlequal . $REV : '') |
||
320 | ) |
||
321 | ), // url |
||
322 | $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), // subject |
||
323 | rawWiki($ID, $REV) // body (content) |
||
324 | ); |
||
325 | /* encoded content */ |
||
326 | $wikipage->addContentEncoded(p_cached_output(wikiFN($ID, $REV), 'xhtml')); |
||
327 | /* created */ |
||
328 | if (isset($INFO['meta']['date']['created'])) { |
||
329 | $wikipage->addCreated(date('c', $INFO['meta']['date']['created'])); |
||
330 | } |
||
331 | /* or modified */ |
||
332 | if (isset($INFO['meta']['date']['modified'])) { |
||
333 | $wikipage->addModified(date('c', $INFO['meta']['date']['modified'])); |
||
334 | } |
||
335 | /* creator/modifier */ |
||
336 | if ($INFO['editor'] && $this->getConf('userns')) { |
||
337 | $wikipage->addCreator(array('foaf:maker' => '#' . $INFO['editor'], 'sioc:modifier' => $dwuserpage_id)); |
||
338 | } |
||
339 | /* is creator */ |
||
340 | if (isset($INFO['meta']['date']['created'])) { |
||
341 | $wikipage->isCreator(); |
||
342 | } |
||
343 | /* intern wiki links */ |
||
344 | $wikipage->addLinks($INFO['meta']['relation']['references']); |
||
345 | |||
346 | // contributors - only for last revision b/c of wrong meta data for older revisions |
||
347 | if (!$REV && $this->getConf('userns') && isset($INFO['meta']['contributor'])) { |
||
348 | $cont_temp = array(); |
||
349 | $cont_ns = $this->getConf('userns') . ($conf['useslash'] ? '/' : ':'); |
||
350 | foreach ($INFO['meta']['contributor'] as $cont_id => $cont_name) { |
||
351 | $cont_temp[$cont_ns . $cont_id] = $cont_name; |
||
352 | } |
||
353 | $wikipage->addContributors($cont_temp); |
||
354 | } |
||
355 | |||
356 | // backlinks - only for last revision |
||
357 | if (!$REV) { |
||
358 | require_once(DOKU_INC . 'inc/fulltext.php'); |
||
359 | $backlinks = ft_backlinks($ID); |
||
360 | if (count($backlinks) > 0) { |
||
361 | $wikipage->addBacklinks($backlinks); |
||
362 | } |
||
363 | } |
||
364 | |||
365 | // TODO: addLinksExtern |
||
366 | |||
367 | /* previous and next revision */ |
||
368 | $changelog = new PageChangeLog($ID); |
||
369 | $pagerevs = $changelog->getRevisions(0, $conf['recent'] + 1); |
||
370 | $prevrev = false; |
||
371 | $nextrev = false; |
||
372 | if (!$REV) { |
||
373 | // latest revision, previous rev is on top in array |
||
374 | $prevrev = 0; |
||
375 | } else { |
||
376 | // other revision |
||
377 | $currentrev = array_search($REV, $pagerevs); |
||
378 | if ($currentrev !== false) { |
||
379 | $prevrev = $currentrev + 1; |
||
380 | $nextrev = $currentrev - 1; |
||
381 | } |
||
382 | } |
||
383 | if ($prevrev !== false && $prevrev > -1 && page_exists($ID, $pagerevs[$prevrev])) { |
||
384 | /* previous revision*/ |
||
385 | $wikipage->addVersionPrevious($pagerevs[$prevrev]); |
||
386 | } |
||
387 | if ($nextrev !== false && $nextrev > -1 && page_exists($ID, $pagerevs[$nextrev])) { |
||
388 | /* next revision*/ |
||
389 | $wikipage->addVersionNext($pagerevs[$nextrev]); |
||
390 | } |
||
391 | |||
392 | /* latest revision */ |
||
393 | if ($REV) { |
||
394 | $wikipage->addVersionLatest(); |
||
395 | } |
||
396 | // TODO: topics |
||
397 | /* has_container */ |
||
398 | if ($INFO['namespace']) { |
||
399 | $wikipage->addContainer($INFO['namespace']); |
||
400 | } |
||
401 | /* has_space */ |
||
402 | if ($this->getConf('owners')) { |
||
403 | $wikipage->addSite($this->getConf('owners')); |
||
404 | } |
||
405 | // TODO: dc:contributor / has_modifier |
||
406 | // TODO: attachment (e.g. pictures in that dwns) |
||
407 | |||
408 | // add wiki page to exporter |
||
409 | $exporter->addObject($wikipage); |
||
410 | //if ($INFO['editor'] && $this->getConf('userns')) $exporter->addObject($pageuser); |
||
411 | |||
412 | return $exporter; |
||
413 | } |
||
414 | |||
415 | private function getDokuUrl($url = null) |
||
416 | { |
||
417 | return getAbsUrl($url); |
||
418 | } |
||
419 | |||
420 | public function isRdfXmlRequest(): bool |
||
466 | } |
||
467 | |||
468 | /** |
||
469 | */ |
||
470 | public function createRdfLink($event = null, $param = null) |
||
540 | } |
||
541 | } |
||
542 | |||
543 | // TODO cleanup and just have this unconditionally |
||
638 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.