xref: /plugin/qc/helper.php (revision 2fc45e0c1b2076ea358377649512960c5d3d694a)
18fce80b1SAndreas Gohr<?php
276bbc49cSAnna Dabrowska
3*2fc45e0cSsplitbrainuse dokuwiki\Extension\Plugin;
4*2fc45e0cSsplitbrain
58fce80b1SAndreas Gohr/**
68fce80b1SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
78fce80b1SAndreas Gohr */
8*2fc45e0cSsplitbrainclass helper_plugin_qc extends Plugin
976bbc49cSAnna Dabrowska{
101c845774SAndreas Gohr    /**
111c845774SAndreas Gohr     * Output the standard quality header. Needs to be called formt he template
121c845774SAndreas Gohr     */
1376bbc49cSAnna Dabrowska    public function tpl()
1476bbc49cSAnna Dabrowska    {
155d41541bSAndreas Gohr        if (!$this->shouldShow()) return;
161c845774SAndreas Gohr
17f7678e42SJana Deutschländer        echo '<div id="plugin__qc__wrapper">';
181c845774SAndreas Gohr        echo '<div class="summary">';
191c845774SAndreas Gohr        echo $this->getLang('i_qcscore');
201c845774SAndreas Gohr        echo '</div>';
21393c144dSAndreas Gohr        echo '<aside class="qc-output"></aside>';
229068e431SAndreas Gohr        echo '</div>';
238fce80b1SAndreas Gohr    }
248fce80b1SAndreas Gohr
251c845774SAndreas Gohr    /**
265d41541bSAndreas Gohr     * Should the QC plugin be shown?
275d41541bSAndreas Gohr     *
2833274f74SAndreas Gohr     * It checks if the page exists, if QC was disabled for this page, general
2933274f74SAndreas Gohr     * settings and ACLs
3033274f74SAndreas Gohr     *
3133274f74SAndreas Gohr     * This may be called from page context as well as from AJAX. In AJAX context
3233274f74SAndreas Gohr     * the page id needs to be passed as parameter
3333274f74SAndreas Gohr     *
3433274f74SAndreas Gohr     * @param string $id the page ID, defaults to global $ID
355d41541bSAndreas Gohr     * @return bool
365d41541bSAndreas Gohr     */
3776bbc49cSAnna Dabrowska    public function shouldShow($id = '')
3876bbc49cSAnna Dabrowska    {
395d41541bSAndreas Gohr        global $ACT, $INFO, $ID;
4033274f74SAndreas Gohr        if ($id === '') $id = $ID;
4133274f74SAndreas Gohr        if (isset($ACT) && $ACT != 'show') return false;
4233274f74SAndreas Gohr        if (isset($INFO)) {
4333274f74SAndreas Gohr            $exists = $INFO['exists'];
4433274f74SAndreas Gohr        } else {
4533274f74SAndreas Gohr            $exists = page_exists($id);
4633274f74SAndreas Gohr        }
4733274f74SAndreas Gohr        if (!$exists) return false;
4833274f74SAndreas Gohr
4933274f74SAndreas Gohr        if (auth_quickaclcheck($id) < AUTH_READ) return false;
5033274f74SAndreas Gohr
5133274f74SAndreas Gohr        if (p_get_metadata($id, 'relation qcplugin_disabled')) return false;
525d41541bSAndreas Gohr        if ($this->getConf('adminonly')) {
535d41541bSAndreas Gohr            if (!isset($_SERVER['REMOTE_USER']) || !auth_isadmin()) {
545d41541bSAndreas Gohr                return false;
555d41541bSAndreas Gohr            }
565d41541bSAndreas Gohr        }
575d41541bSAndreas Gohr
585d41541bSAndreas Gohr        return true;
595d41541bSAndreas Gohr    }
605d41541bSAndreas Gohr
615d41541bSAndreas Gohr    /**
621c845774SAndreas Gohr     * Return the raw quality data
631c845774SAndreas Gohr     *
641c845774SAndreas Gohr     * Always call this asynchronly!
651c845774SAndreas Gohr     *
661c845774SAndreas Gohr     * @param $theid
671c845774SAndreas Gohr     * @return array
681c845774SAndreas Gohr     */
6976bbc49cSAnna Dabrowska    public function getQCData($theid)
7076bbc49cSAnna Dabrowska    {
718fce80b1SAndreas Gohr        global $ID;
728fce80b1SAndreas Gohr        $oldid = $ID;
738fce80b1SAndreas Gohr        $ID = $theid;
748437661aSAdrian Lang        $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID));
758fce80b1SAndreas Gohr        $ID = $oldid;
768fce80b1SAndreas Gohr        return $data;
778fce80b1SAndreas Gohr    }
78193c8bebSJana Deutschländer}
79