xref: /plugin/qc/action/ajax.php (revision 76bbc49c3993db5faa9303ad0615cbeca3339685)
11c845774SAndreas Gohr<?php
2*76bbc49cSAnna Dabrowska
31c845774SAndreas Gohr/**
41c845774SAndreas Gohr * DokuWiki Plugin qc (Action Component)
51c845774SAndreas Gohr *
61c845774SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
71c845774SAndreas Gohr * @author  Andreas Gohr <gohr@cosmocode.de>
81c845774SAndreas Gohr */
9*76bbc49cSAnna Dabrowska
101c845774SAndreas Gohr// must be run within Dokuwiki
111c845774SAndreas Gohrif (!defined('DOKU_INC')) die();
121c845774SAndreas Gohr
131c845774SAndreas Gohruse dokuwiki\plugin\qc\Output;
141c845774SAndreas Gohr
15*76bbc49cSAnna Dabrowskaclass action_plugin_qc_ajax extends DokuWiki_Action_Plugin
16*76bbc49cSAnna Dabrowska{
171c845774SAndreas Gohr
181c845774SAndreas Gohr    /**
191c845774SAndreas Gohr     * Registers a callback function for a given event
201c845774SAndreas Gohr     *
211c845774SAndreas Gohr     * @param Doku_Event_Handler $controller DokuWiki's event controller object
221c845774SAndreas Gohr     * @return void
231c845774SAndreas Gohr     */
24*76bbc49cSAnna Dabrowska    public function register(Doku_Event_Handler $controller)
25*76bbc49cSAnna Dabrowska    {
261c845774SAndreas Gohr        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax', array());
271c845774SAndreas Gohr    }
281c845774SAndreas Gohr
291c845774SAndreas Gohr    /**
301c845774SAndreas Gohr     * Out put the wanted HTML
311c845774SAndreas Gohr     *
321c845774SAndreas Gohr     * @param Doku_Event $event
331c845774SAndreas Gohr     * @param $param
341c845774SAndreas Gohr     */
35*76bbc49cSAnna Dabrowska    public function ajax(Doku_Event $event, $param)
36*76bbc49cSAnna Dabrowska    {
371c845774SAndreas Gohr        if (substr($event->data, 0, 10) != 'plugin_qc_') return;
381c845774SAndreas Gohr        $event->preventDefault();
391c845774SAndreas Gohr        $event->stopPropagation();
401c845774SAndreas Gohr        global $INPUT;
411c845774SAndreas Gohr
421c845774SAndreas Gohr        $id = cleanID($INPUT->str('id'));
431c845774SAndreas Gohr        if (blank($id)) die('no id given');
441c845774SAndreas Gohr
4533274f74SAndreas Gohr        /** @var helper_plugin_qc $helper */
4633274f74SAndreas Gohr        $helper = plugin_load('helper', 'qc');
4733274f74SAndreas Gohr        if (!$helper->shouldShow($id)) {
4833274f74SAndreas Gohr            http_status(404, 'No QC data available');
4933274f74SAndreas Gohr            exit();
5033274f74SAndreas Gohr        }
5133274f74SAndreas Gohr
521c845774SAndreas Gohr        $out = new Output($id);
531c845774SAndreas Gohr        if ($event->data == 'plugin_qc_short') {
541c845774SAndreas Gohr            echo $out->short();
551c845774SAndreas Gohr        } elseif ($event->data == 'plugin_qc_long') {
561c845774SAndreas Gohr            echo $out->long();
571c845774SAndreas Gohr        }
581c845774SAndreas Gohr    }
591c845774SAndreas Gohr}
60