18fce80b1SAndreas Gohr<?php 2*76bbc49cSAnna Dabrowska 38fce80b1SAndreas Gohr/** 48fce80b1SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 58fce80b1SAndreas Gohr */ 68fce80b1SAndreas Gohr 78fce80b1SAndreas Gohr// must be run within Dokuwiki 88fce80b1SAndreas Gohrif (!defined('DOKU_INC')) die(); 98fce80b1SAndreas Gohr 10*76bbc49cSAnna Dabrowskaclass helper_plugin_qc extends DokuWiki_Plugin 11*76bbc49cSAnna Dabrowska{ 128fce80b1SAndreas Gohr 131c845774SAndreas Gohr /** 141c845774SAndreas Gohr * Output the standard quality header. Needs to be called formt he template 151c845774SAndreas Gohr */ 16*76bbc49cSAnna Dabrowska public function tpl() 17*76bbc49cSAnna Dabrowska { 185d41541bSAndreas Gohr if (!$this->shouldShow()) return; 191c845774SAndreas Gohr 20f7678e42SJana Deutschländer echo '<div id="plugin__qc__wrapper">'; 211c845774SAndreas Gohr echo '<div class="summary">'; 221c845774SAndreas Gohr echo $this->getLang('i_qcscore'); 231c845774SAndreas Gohr echo '</div>'; 24393c144dSAndreas Gohr echo '<aside class="qc-output"></aside>'; 259068e431SAndreas Gohr echo '</div>'; 268fce80b1SAndreas Gohr } 278fce80b1SAndreas Gohr 281c845774SAndreas Gohr /** 295d41541bSAndreas Gohr * Should the QC plugin be shown? 305d41541bSAndreas Gohr * 3133274f74SAndreas Gohr * It checks if the page exists, if QC was disabled for this page, general 3233274f74SAndreas Gohr * settings and ACLs 3333274f74SAndreas Gohr * 3433274f74SAndreas Gohr * This may be called from page context as well as from AJAX. In AJAX context 3533274f74SAndreas Gohr * the page id needs to be passed as parameter 3633274f74SAndreas Gohr * 3733274f74SAndreas Gohr * @param string $id the page ID, defaults to global $ID 385d41541bSAndreas Gohr * @return bool 395d41541bSAndreas Gohr */ 40*76bbc49cSAnna Dabrowska public function shouldShow($id = '') 41*76bbc49cSAnna Dabrowska { 425d41541bSAndreas Gohr global $ACT, $INFO, $ID; 4333274f74SAndreas Gohr if ($id === '') $id = $ID; 4433274f74SAndreas Gohr if (isset($ACT) && $ACT != 'show') return false; 4533274f74SAndreas Gohr if (isset($INFO)) { 4633274f74SAndreas Gohr $exists = $INFO['exists']; 4733274f74SAndreas Gohr } else { 4833274f74SAndreas Gohr $exists = page_exists($id); 4933274f74SAndreas Gohr } 5033274f74SAndreas Gohr if (!$exists) return false; 5133274f74SAndreas Gohr 5233274f74SAndreas Gohr if (auth_quickaclcheck($id) < AUTH_READ) return false; 5333274f74SAndreas Gohr 5433274f74SAndreas Gohr if (p_get_metadata($id, 'relation qcplugin_disabled')) return false; 555d41541bSAndreas Gohr if ($this->getConf('adminonly')) { 565d41541bSAndreas Gohr if (!isset($_SERVER['REMOTE_USER']) || !auth_isadmin()) { 575d41541bSAndreas Gohr return false; 585d41541bSAndreas Gohr } 595d41541bSAndreas Gohr } 605d41541bSAndreas Gohr 615d41541bSAndreas Gohr return true; 625d41541bSAndreas Gohr } 635d41541bSAndreas Gohr 645d41541bSAndreas Gohr /** 651c845774SAndreas Gohr * Return the raw quality data 661c845774SAndreas Gohr * 671c845774SAndreas Gohr * Always call this asynchronly! 681c845774SAndreas Gohr * 691c845774SAndreas Gohr * @param $theid 701c845774SAndreas Gohr * @return array 711c845774SAndreas Gohr */ 72*76bbc49cSAnna Dabrowska public function getQCData($theid) 73*76bbc49cSAnna Dabrowska { 748fce80b1SAndreas Gohr global $ID; 758fce80b1SAndreas Gohr $oldid = $ID; 768fce80b1SAndreas Gohr $ID = $theid; 778437661aSAdrian Lang $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID)); 788fce80b1SAndreas Gohr $ID = $oldid; 798fce80b1SAndreas Gohr return $data; 808fce80b1SAndreas Gohr } 81193c8bebSJana Deutschländer} 82