11c845774SAndreas Gohr<?php 276bbc49cSAnna Dabrowska 3*8ae469bfSAndreas Gohr 4*8ae469bfSAndreas Gohruse dokuwiki\plugin\qc\Output; 5*8ae469bfSAndreas Gohr 61c845774SAndreas Gohr/** 71c845774SAndreas Gohr * DokuWiki Plugin qc (Action Component) 81c845774SAndreas Gohr * 91c845774SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 101c845774SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 111c845774SAndreas Gohr */ 1276bbc49cSAnna Dabrowskaclass action_plugin_qc_ajax extends DokuWiki_Action_Plugin 1376bbc49cSAnna Dabrowska{ 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 */ 2176bbc49cSAnna Dabrowska public function register(Doku_Event_Handler $controller) 2276bbc49cSAnna Dabrowska { 231c845774SAndreas Gohr $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax', array()); 241c845774SAndreas Gohr } 251c845774SAndreas Gohr 261c845774SAndreas Gohr /** 271c845774SAndreas Gohr * Out put the wanted HTML 281c845774SAndreas Gohr * 291c845774SAndreas Gohr * @param Doku_Event $event 301c845774SAndreas Gohr * @param $param 311c845774SAndreas Gohr */ 3276bbc49cSAnna Dabrowska public function ajax(Doku_Event $event, $param) 3376bbc49cSAnna Dabrowska { 341c845774SAndreas Gohr if (substr($event->data, 0, 10) != 'plugin_qc_') return; 351c845774SAndreas Gohr $event->preventDefault(); 361c845774SAndreas Gohr $event->stopPropagation(); 371c845774SAndreas Gohr global $INPUT; 381c845774SAndreas Gohr 391c845774SAndreas Gohr $id = cleanID($INPUT->str('id')); 401c845774SAndreas Gohr if (blank($id)) die('no id given'); 411c845774SAndreas Gohr 4233274f74SAndreas Gohr /** @var helper_plugin_qc $helper */ 4333274f74SAndreas Gohr $helper = plugin_load('helper', 'qc'); 4433274f74SAndreas Gohr if (!$helper->shouldShow($id)) { 4533274f74SAndreas Gohr http_status(404, 'No QC data available'); 4633274f74SAndreas Gohr exit(); 4733274f74SAndreas Gohr } 4833274f74SAndreas Gohr 491c845774SAndreas Gohr $out = new Output($id); 501c845774SAndreas Gohr if ($event->data == 'plugin_qc_short') { 511c845774SAndreas Gohr echo $out->short(); 521c845774SAndreas Gohr } elseif ($event->data == 'plugin_qc_long') { 531c845774SAndreas Gohr echo $out->long(); 541c845774SAndreas Gohr } 551c845774SAndreas Gohr } 561c845774SAndreas Gohr} 57