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