1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 */ 5 6// must be run within Dokuwiki 7if(!defined('DOKU_INC')) die(); 8 9class helper_plugin_qc extends DokuWiki_Plugin { 10 11 /** 12 * Output the standard quality header. Needs to be called formt he template 13 */ 14 public function tpl() { 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 '<div class="qc-output"></div>'; 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 global $ACT, $INFO, $ID; 39 if($id === '') $id = $ID; 40 if(isset($ACT) && $ACT != 'show') return false; 41 if(isset($INFO)) { 42 $exists = $INFO['exists']; 43 } else { 44 $exists = page_exists($id); 45 } 46 if(!$exists) return false; 47 48 if(auth_quickaclcheck($id) < AUTH_READ) return false; 49 50 if(p_get_metadata($id, 'relation qcplugin_disabled')) return false; 51 if($this->getConf('adminonly')) { 52 if(!isset($_SERVER['REMOTE_USER']) || !auth_isadmin()) { 53 return false; 54 } 55 } 56 57 return true; 58 } 59 60 /** 61 * Return the raw quality data 62 * 63 * Always call this asynchronly! 64 * 65 * @param $theid 66 * @return array 67 */ 68 public function getQCData($theid) { 69 global $ID; 70 $oldid = $ID; 71 $ID = $theid; 72 $data = unserialize(p_cached_output(wikiFN($ID), 'qc', $ID)); 73 $ID = $oldid; 74 return $data; 75 } 76} 77