1<?php
2/**
3 * TotD Plugin:  Display a random wiki page section within another wiki page
4 *
5 * Action plugin component, uses the include plugin
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     i-net software / Gerry Wei�bach <tools@inetsoftware.de>
9 */
10if(!defined('DOKU_INC')) die();  // no Dokuwiki, no go
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'action.php');
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class action_plugin_totd extends DokuWiki_Action_Plugin {
20
21    /**
22     * plugin should use this method to register its handlers with the dokuwiki's event controller
23     */
24    function register(Doku_Event_Handler $controller) {
25        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax_totd_loadnew');
26    }
27
28    function ajax_totd_loadnew( Doku_Event &$event ) {
29
30        if ( $event->data != '_totd_loadnew' ) {
31            return;
32        }
33
34        $event->preventDefault();
35        $event->stopPropagation();
36
37        $ID = urldecode($_REQUEST['id']);
38        list($ID, $params) = explode('&', $ID, 2);
39        if ( !empty($params) ) $params = '&' . $params;
40
41        $ID = cleanID($ID);
42        $section = cleanID($_REQUEST['totd']); // Not needed here, but in the plugin
43
44        $ins = p_get_instructions("{{totd>$ID{$params}}}");
45        $data = p_render('xhtml', $ins, $INFO);
46
47        header('Content-Type: text/html; charset=utf-8');
48        print $data;
49        return;
50    }
51
52}
53//vim:ts=4:sw=4:et:enc=utf-8:
54