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