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