xref: /plugin/qc/helper.php (revision 992bd36b17f1ea67904eac36379c4eb2f45cd2fd)
18fce80b1SAndreas Gohr<?php
28fce80b1SAndreas Gohr/**
38fce80b1SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
48fce80b1SAndreas Gohr */
58fce80b1SAndreas Gohr
68fce80b1SAndreas Gohr// must be run within Dokuwiki
78fce80b1SAndreas Gohrif(!defined('DOKU_INC')) die();
88fce80b1SAndreas Gohr
98fce80b1SAndreas Gohrclass helper_plugin_qc extends DokuWiki_Plugin {
108fce80b1SAndreas Gohr
111c845774SAndreas Gohr    /**
121c845774SAndreas Gohr     * Output the standard quality header. Needs to be called formt he template
131c845774SAndreas Gohr     */
148fce80b1SAndreas Gohr    function tpl() {
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>';
21*992bd36bSAndreas Gohr        echo '<div class="qc-output"></div>';
229068e431SAndreas Gohr        echo '</div>';
238fce80b1SAndreas Gohr    }
248fce80b1SAndreas Gohr
251c845774SAndreas Gohr    /**
265d41541bSAndreas Gohr     * Should the QC plugin be shown?
275d41541bSAndreas Gohr     *
285d41541bSAndreas Gohr     * @return bool
295d41541bSAndreas Gohr     */
305d41541bSAndreas Gohr    function shouldShow() {
315d41541bSAndreas Gohr        global $ACT, $INFO, $ID;
325d41541bSAndreas Gohr        if($ACT != 'show' || !$INFO['exists']) return false;
335d41541bSAndreas Gohr        if(p_get_metadata($ID, 'relation qcplugin_disabled')) return false;
345d41541bSAndreas Gohr        if($this->getConf('adminonly')) {
355d41541bSAndreas Gohr            if(!isset($_SERVER['REMOTE_USER']) || !auth_isadmin()) {
365d41541bSAndreas Gohr                return false;
375d41541bSAndreas Gohr            }
385d41541bSAndreas Gohr        }
395d41541bSAndreas Gohr
405d41541bSAndreas Gohr        return true;
415d41541bSAndreas Gohr    }
425d41541bSAndreas Gohr
435d41541bSAndreas Gohr    /**
441c845774SAndreas Gohr     * Return the raw quality data
451c845774SAndreas Gohr     *
461c845774SAndreas Gohr     * Always call this asynchronly!
471c845774SAndreas Gohr     *
481c845774SAndreas Gohr     * @param $theid
491c845774SAndreas Gohr     * @return array
501c845774SAndreas Gohr     */
518fce80b1SAndreas Gohr    function getQCData($theid) {
528fce80b1SAndreas Gohr        global $ID;
538fce80b1SAndreas Gohr        $oldid = $ID;
548fce80b1SAndreas Gohr        $ID = $theid;
558437661aSAdrian Lang        $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID));
568fce80b1SAndreas Gohr        $ID = $oldid;
578fce80b1SAndreas Gohr        return $data;
588fce80b1SAndreas Gohr    }
59193c8bebSJana Deutschländer}
60