xref: /plugin/qc/helper.php (revision 992bd36b17f1ea67904eac36379c4eb2f45cd2fd)
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();
8
9class helper_plugin_qc extends DokuWiki_Plugin {
10
11    /**
12     * Output the standard quality header. Needs to be called formt he template
13     */
14    function tpl() {
15        if(!$this->shouldShow()) return;
16
17        echo '<div id="plugin__qc__wrapper">';
18        echo '<div class="summary">';
19        echo $this->getLang('i_qcscore');
20        echo '</div>';
21        echo '<div class="qc-output"></div>';
22        echo '</div>';
23    }
24
25    /**
26     * Should the QC plugin be shown?
27     *
28     * @return bool
29     */
30    function shouldShow() {
31        global $ACT, $INFO, $ID;
32        if($ACT != 'show' || !$INFO['exists']) return false;
33        if(p_get_metadata($ID, 'relation qcplugin_disabled')) return false;
34        if($this->getConf('adminonly')) {
35            if(!isset($_SERVER['REMOTE_USER']) || !auth_isadmin()) {
36                return false;
37            }
38        }
39
40        return true;
41    }
42
43    /**
44     * Return the raw quality data
45     *
46     * Always call this asynchronly!
47     *
48     * @param $theid
49     * @return array
50     */
51    function getQCData($theid) {
52        global $ID;
53        $oldid = $ID;
54        $ID = $theid;
55        $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID));
56        $ID = $oldid;
57        return $data;
58    }
59}
60