xref: /plugin/qc/action/ajax.php (revision 5230d0cde2eb9c6329467b1b6d98989e0fd4aef1)
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        /** @var helper_plugin_qc $helper */
41        $helper = plugin_load('helper', 'qc');
42        if(!$helper->shouldShow($id)) {
43            http_status(404, 'No QC data available');
44            exit();
45        }
46
47        $out = new Output($id);
48        if($event->data == 'plugin_qc_short') {
49            echo $out->short();
50        } elseif($event->data == 'plugin_qc_long') {
51            echo $out->long();
52        }
53    }
54
55}
56