xref: /plugin/qc/helper.php (revision b6b2145cc338cb25cf403c26dea71467a23fd215)
1<?php
2
3/**
4 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
5 */
6class helper_plugin_qc extends DokuWiki_Plugin
7{
8
9    /**
10     * Output the standard quality header. Needs to be called formt he template
11     */
12    public function tpl()
13    {
14        if (!$this->shouldShow()) return;
15
16        echo '<div id="plugin__qc__wrapper">';
17        echo '<div class="summary">';
18        echo $this->getLang('i_qcscore');
19        echo '</div>';
20        echo '<aside class="qc-output"></aside>';
21        echo '</div>';
22    }
23
24    /**
25     * Should the QC plugin be shown?
26     *
27     * It checks if the page exists, if QC was disabled for this page, general
28     * settings and ACLs
29     *
30     * This may be called from page context as well as from AJAX. In AJAX context
31     * the page id needs to be passed as parameter
32     *
33     * @param string $id the page ID, defaults to global $ID
34     * @return bool
35     */
36    public function shouldShow($id = '')
37    {
38        global $ACT, $INFO, $ID;
39        if ($id === '') $id = $ID;
40        if (isset($ACT) && $ACT != 'show') return false;
41        if (isset($INFO)) {
42            $exists = $INFO['exists'];
43        } else {
44            $exists = page_exists($id);
45        }
46        if (!$exists) return false;
47
48        if (auth_quickaclcheck($id) < AUTH_READ) return false;
49
50        if (p_get_metadata($id, 'relation qcplugin_disabled')) return false;
51        if ($this->getConf('adminonly')) {
52            if (!isset($_SERVER['REMOTE_USER']) || !auth_isadmin()) {
53                return false;
54            }
55        }
56
57        return true;
58    }
59
60    /**
61     * Return the raw quality data
62     *
63     * Always call this asynchronly!
64     *
65     * @param $theid
66     * @return array
67     */
68    public function getQCData($theid)
69    {
70        global $ID;
71        $oldid = $ID;
72        $ID = $theid;
73        $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID));
74        $ID = $oldid;
75        return $data;
76    }
77}
78