xref: /plugin/qc/action/ajax.php (revision 1c8457749c0d73df0789872e745e575b222391d8)
1<?php
2/**
3 * DokuWiki Plugin qc (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr <gohr@cosmocode.de>
7 */
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11use dokuwiki\plugin\qc\Output;
12
13class action_plugin_qc_ajax extends DokuWiki_Action_Plugin {
14
15    /**
16     * Registers a callback function for a given event
17     *
18     * @param Doku_Event_Handler $controller DokuWiki's event controller object
19     * @return void
20     */
21    public function register(Doku_Event_Handler $controller) {
22        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax', array());
23    }
24
25    /**
26     * Out put the wanted HTML
27     *
28     * @param Doku_Event $event
29     * @param $param
30     */
31    public function ajax(Doku_Event $event, $param) {
32        if(substr($event->data, 0, 10) != 'plugin_qc_') return;
33        $event->preventDefault();
34        $event->stopPropagation();
35        global $INPUT;
36
37        $id = cleanID($INPUT->str('id'));
38        if(blank($id)) die('no id given');
39
40        $out = new Output($id);
41        if($event->data == 'plugin_qc_short') {
42            echo $out->short();
43        } elseif($event->data == 'plugin_qc_long') {
44            echo $out->long();
45        }
46    }
47
48}
49