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