xref: /plugin/qc/helper.php (revision f7678e42460d81c2f8fe6f0d90eec15336079300)
18fce80b1SAndreas Gohr<?php
28fce80b1SAndreas Gohr/**
38fce80b1SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
48fce80b1SAndreas Gohr */
58fce80b1SAndreas Gohr
68fce80b1SAndreas Gohr// must be run within Dokuwiki
78fce80b1SAndreas Gohrif (!defined('DOKU_INC')) die();
82e820792SAndreas Gohrrequire_once(DOKU_INC.'inc/plugin.php');
98fce80b1SAndreas Gohr
108fce80b1SAndreas Gohrclass helper_plugin_qc extends DokuWiki_Plugin {
118fce80b1SAndreas Gohr
128fce80b1SAndreas Gohr    function tpl(){
138fce80b1SAndreas Gohr        global $ACT,$INFO,$ID;
14d2a33339SDominik Eckelmann        if (!function_exists('gd_info')) {
15d2a33339SDominik Eckelmann            msg('You have to install php-gd lib to use the QC plugin.');
16d2a33339SDominik Eckelmann            return;
17d2a33339SDominik Eckelmann        }
188fce80b1SAndreas Gohr        if($ACT != 'show' || !$INFO['exists']) return;
1932905264SAndreas Gohr        if(p_get_metadata($ID, 'relation qcplugin_disabled')) return;
20c8193605SDominik Eckelmann        if ($this->getConf('adminonly')) {
21c8193605SDominik Eckelmann            if (!isset($_SERVER['REMOTE_USER']) || !auth_isadmin())
22c8193605SDominik Eckelmann                return;
23c8193605SDominik Eckelmann        }
24*f7678e42SJana Deutschländer        echo '<div id="plugin__qc__wrapper">';
2563ee528dSAndreas Gohr        echo '<img src="'.DOKU_BASE.'lib/plugins/qc/icon.php?id='.$ID.'" width="600" height="25" alt="" id="plugin__qc__icon" />';
268fce80b1SAndreas Gohr        echo '<div id="plugin__qc__out" style="display:none"></div>';
279068e431SAndreas Gohr        echo '</div>';
288fce80b1SAndreas Gohr    }
298fce80b1SAndreas Gohr
308fce80b1SAndreas Gohr
318fce80b1SAndreas Gohr    function getQCData($theid){
328fce80b1SAndreas Gohr        global $ID;
338fce80b1SAndreas Gohr        $oldid = $ID;
348fce80b1SAndreas Gohr        $ID = $theid;
358437661aSAdrian Lang        require_once DOKU_INC.'inc/parserutils.php';
368437661aSAdrian Lang        $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID));
378fce80b1SAndreas Gohr        $ID = $oldid;
388fce80b1SAndreas Gohr        return $data;
398fce80b1SAndreas Gohr    }
408fce80b1SAndreas Gohr
41193c8bebSJana Deutschländer    /**
42193c8bebSJana Deutschländer     * same function as tpl(), built markup contains additional data-attribute data-errors, which shows the current
43193c8bebSJana Deutschländer     * error count
44193c8bebSJana Deutschländer     */
45193c8bebSJana Deutschländer    function tplErrorCount(){
46193c8bebSJana Deutschländer        global $ACT,$INFO,$ID;
47193c8bebSJana Deutschländer        if (!function_exists('gd_info')) {
48193c8bebSJana Deutschländer            msg('You have to install php-gd lib to use the QC plugin.');
49193c8bebSJana Deutschländer            return;
50193c8bebSJana Deutschländer        }
51193c8bebSJana Deutschländer        if($ACT != 'show' || !$INFO['exists']) return;
52193c8bebSJana Deutschländer        if(p_get_metadata($ID, 'relation qcplugin_disabled')) return;
53193c8bebSJana Deutschländer        if ($this->getConf('adminonly')) {
54193c8bebSJana Deutschländer            if (!isset($_SERVER['REMOTE_USER']) || !auth_isadmin())
55193c8bebSJana Deutschländer                return;
56193c8bebSJana Deutschländer        }
57193c8bebSJana Deutschländer        $qc_data =  $this->getQCData($ID);
58193c8bebSJana Deutschländer        if($qc_data){
59193c8bebSJana Deutschländer            $num = $qc_data[score];
60193c8bebSJana Deutschländer        }
61193c8bebSJana Deutschländer        echo '<div id="plugin__qc__wrapper" data-errors='.$num .'>';
62193c8bebSJana Deutschländer        echo '<img src="'.DOKU_BASE.'lib/plugins/qc/icon.php?id='.$ID.'" width="600" height="25" alt="" id="plugin__qc__icon" />';
63193c8bebSJana Deutschländer        echo '<div id="plugin__qc__out"></div>';
64193c8bebSJana Deutschländer        echo '</div>';
65193c8bebSJana Deutschländer    }
66193c8bebSJana Deutschländer
678fce80b1SAndreas Gohr}
688fce80b1SAndreas Gohr// vim:ts=4:sw=4:et:enc=utf-8:
69