xref: /plugin/qc/action/ajax.php (revision 8ae469bf7217f195a3a1b4ddd0d2857bc1c123f9)
1<?php
2
3
4use dokuwiki\plugin\qc\Output;
5
6/**
7 * DokuWiki Plugin qc (Action Component)
8 *
9 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
10 * @author  Andreas Gohr <gohr@cosmocode.de>
11 */
12class action_plugin_qc_ajax extends DokuWiki_Action_Plugin
13{
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    {
23        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax', array());
24    }
25
26    /**
27     * Out put the wanted HTML
28     *
29     * @param Doku_Event $event
30     * @param $param
31     */
32    public function ajax(Doku_Event $event, $param)
33    {
34        if (substr($event->data, 0, 10) != 'plugin_qc_') return;
35        $event->preventDefault();
36        $event->stopPropagation();
37        global $INPUT;
38
39        $id = cleanID($INPUT->str('id'));
40        if (blank($id)) die('no id given');
41
42        /** @var helper_plugin_qc $helper */
43        $helper = plugin_load('helper', 'qc');
44        if (!$helper->shouldShow($id)) {
45            http_status(404, 'No QC data available');
46            exit();
47        }
48
49        $out = new Output($id);
50        if ($event->data == 'plugin_qc_short') {
51            echo $out->short();
52        } elseif ($event->data == 'plugin_qc_long') {
53            echo $out->long();
54        }
55    }
56}
57