xref: /plugin/qc/helper.php (revision 193c8beb85fb65058d66e94e144e195b9192d632) !
1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 */
5
6// must be run within Dokuwiki
7if (!defined('DOKU_INC')) die();
8require_once(DOKU_INC.'inc/plugin.php');
9
10class helper_plugin_qc extends DokuWiki_Plugin {
11
12    function tpl(){
13        global $ACT,$INFO,$ID;
14        if (!function_exists('gd_info')) {
15            msg('You have to install php-gd lib to use the QC plugin.');
16            return;
17        }
18        if($ACT != 'show' || !$INFO['exists']) return;
19        if(p_get_metadata($ID, 'relation qcplugin_disabled')) return;
20        if ($this->getConf('adminonly')) {
21            if (!isset($_SERVER['REMOTE_USER']) || !auth_isadmin())
22                return;
23        }
24        echo '<div id="plugin__qc__wrapper" data-id="'.$ID.'">';
25        echo '<img src="'.DOKU_BASE.'lib/plugins/qc/icon.php?id='.$ID.'" width="600" height="25" alt="" id="plugin__qc__icon" />';
26        echo '<div id="plugin__qc__out" style="display:none"></div>';
27        echo '</div>';
28    }
29
30
31    function getQCData($theid){
32        global $ID;
33        $oldid = $ID;
34        $ID = $theid;
35        require_once DOKU_INC.'inc/parserutils.php';
36        $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID));
37        $ID = $oldid;
38        return $data;
39    }
40
41    /**
42     * same function as tpl(), built markup contains additional data-attribute data-errors, which shows the current
43     * error count
44     */
45    function tplErrorCount(){
46        global $ACT,$INFO,$ID;
47        if (!function_exists('gd_info')) {
48            msg('You have to install php-gd lib to use the QC plugin.');
49            return;
50        }
51        if($ACT != 'show' || !$INFO['exists']) return;
52        if(p_get_metadata($ID, 'relation qcplugin_disabled')) return;
53        if ($this->getConf('adminonly')) {
54            if (!isset($_SERVER['REMOTE_USER']) || !auth_isadmin())
55                return;
56        }
57        $qc_data =  $this->getQCData($ID);
58        if($qc_data){
59            $num = $qc_data[score];
60        }
61        echo '<div id="plugin__qc__wrapper" data-errors='.$num .'>';
62        echo '<img src="'.DOKU_BASE.'lib/plugins/qc/icon.php?id='.$ID.'" width="600" height="25" alt="" id="plugin__qc__icon" />';
63        echo '<div id="plugin__qc__out"></div>';
64        echo '</div>';
65    }
66
67}
68// vim:ts=4:sw=4:et:enc=utf-8:
69