xref: /plugin/qc/action/ajax.php (revision 33274f7406e2702aea8552ab313efab4930865ce)
11c845774SAndreas Gohr<?php
21c845774SAndreas Gohr/**
31c845774SAndreas Gohr * DokuWiki Plugin qc (Action Component)
41c845774SAndreas Gohr *
51c845774SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
61c845774SAndreas Gohr * @author  Andreas Gohr <gohr@cosmocode.de>
71c845774SAndreas Gohr */
81c845774SAndreas Gohr// must be run within Dokuwiki
91c845774SAndreas Gohrif(!defined('DOKU_INC')) die();
101c845774SAndreas Gohr
111c845774SAndreas Gohruse dokuwiki\plugin\qc\Output;
121c845774SAndreas Gohr
131c845774SAndreas Gohrclass action_plugin_qc_ajax extends DokuWiki_Action_Plugin {
141c845774SAndreas Gohr
151c845774SAndreas Gohr    /**
161c845774SAndreas Gohr     * Registers a callback function for a given event
171c845774SAndreas Gohr     *
181c845774SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
191c845774SAndreas Gohr     * @return void
201c845774SAndreas Gohr     */
211c845774SAndreas Gohr    public function register(Doku_Event_Handler $controller) {
221c845774SAndreas Gohr        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax', array());
231c845774SAndreas Gohr    }
241c845774SAndreas Gohr
251c845774SAndreas Gohr    /**
261c845774SAndreas Gohr     * Out put the wanted HTML
271c845774SAndreas Gohr     *
281c845774SAndreas Gohr     * @param Doku_Event $event
291c845774SAndreas Gohr     * @param $param
301c845774SAndreas Gohr     */
311c845774SAndreas Gohr    public function ajax(Doku_Event $event, $param) {
321c845774SAndreas Gohr        if(substr($event->data, 0, 10) != 'plugin_qc_') return;
331c845774SAndreas Gohr        $event->preventDefault();
341c845774SAndreas Gohr        $event->stopPropagation();
351c845774SAndreas Gohr        global $INPUT;
361c845774SAndreas Gohr
371c845774SAndreas Gohr        $id = cleanID($INPUT->str('id'));
381c845774SAndreas Gohr        if(blank($id)) die('no id given');
391c845774SAndreas Gohr
40*33274f74SAndreas Gohr        /** @var helper_plugin_qc $helper */
41*33274f74SAndreas Gohr        $helper = plugin_load('helper', 'qc');
42*33274f74SAndreas Gohr        if(!$helper->shouldShow($id)) {
43*33274f74SAndreas Gohr            http_status(404, 'No QC data available');
44*33274f74SAndreas Gohr            exit();
45*33274f74SAndreas Gohr        }
46*33274f74SAndreas Gohr
471c845774SAndreas Gohr        $out = new Output($id);
481c845774SAndreas Gohr        if($event->data == 'plugin_qc_short') {
491c845774SAndreas Gohr            echo $out->short();
501c845774SAndreas Gohr        } elseif($event->data == 'plugin_qc_long') {
511c845774SAndreas Gohr            echo $out->long();
521c845774SAndreas Gohr        }
531c845774SAndreas Gohr    }
541c845774SAndreas Gohr
551c845774SAndreas Gohr}
56