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_pluginDir extends DokuWiki_Action_Plugin {
15
16    var $plugin_dir;
17
18    function __construct() {
19        $this->plugin_dir = plugin_load('syntax', 'dir');
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_dir ) { 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] != 'dir' || !$this->plugin_dir ) { return false; }
41
42        $data = $this->plugin_dir->handle($instructions[1], null, null, new Doku_Handler());
43        $this->plugin_dir->_initRender('xhtml', new Doku_Renderer_xhtml());
44
45        $this->plugin_dir->debug = true;
46        if ( !$this->plugin_dir->_parseOptions($data) ) {
47            print $this->plugin_dir->rdr->doc;
48            return false;
49        }
50
51        $event->data['type'] = 'plugin';
52        foreach( $this->plugin_dir->pages as $page ) {
53            $event->data['additionalEntries'][] = array (
54                'type' => 'pages',
55                'entryID' => $page['id']
56            );
57        }
58
59        return true;
60    }
61}
62
63// vim:ts=4:sw=4:et:
64