1<?php
2/**
3 * DokuWiki Plugin multiorphan (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  i-net software <tools@inetsoftware.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) {
11    die();
12}
13
14class action_plugin_multiorphan_pluginSiteexport extends DokuWiki_Action_Plugin {
15
16    var $plugin_orphan;
17
18    function __construct() {
19        $this->plugin_orphan = plugin_load('action', 'multiorphan_multiorphan');
20    }
21
22    /**
23     * Registers a callback function for a given event
24     *
25     * @param Doku_Event_Handler $controller DokuWiki's event controller object
26     * @return void
27     */
28    public function register(Doku_Event_Handler $controller) {
29
30        if ( !$this->plugin_orphan ) { return; }
31        $controller->register_hook('MULTIORPHAN_INSTRUCTION_LINKED', 'BEFORE', $this, 'handle_unknown_instructions');
32    }
33
34    /**
35     * Handles unknown instructions using the Event.
36     */
37    public function handle_unknown_instructions(Doku_Event &$event) {
38
39        $instructions = $event->data['instructions'];
40        if ( $event->data['syntax'] != 'plugin' || $instructions[0] != 'siteexport_toc' || !$this->plugin_orphan ) { return false; }
41        if ( !is_array($instructions[1]) || array_key_exists('start', $instructions[1]) ) { return false; }
42
43        $instructions = p_get_instructions($instructions[3]);
44
45        $links = array('pages' => array() );
46        $this->plugin_orphan->walk_instructions( $links, $event->data['pageID'], $instructions );
47
48        $event->data['type'] = 'plugin';
49        foreach( array_keys($links['pages']) as $page ) {
50            $event->data['additionalEntries'][] = array (
51                'type' => 'pages',
52                'entryID' => $page
53            );
54        }
55
56        return true;
57    }
58}
59
60// vim:ts=4:sw=4:et:
61