15faeb1e6SAndreas Gohr<?php 25faeb1e6SAndreas Gohr/** 35faeb1e6SAndreas Gohr * Popularity Feedback Plugin 45faeb1e6SAndreas Gohr * 55faeb1e6SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 65faeb1e6SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 75faeb1e6SAndreas Gohr */ 85faeb1e6SAndreas Gohr// must be run within Dokuwiki 95faeb1e6SAndreas Gohrif(!defined('DOKU_INC')) die(); 105faeb1e6SAndreas Gohr 115faeb1e6SAndreas Gohr/** 125faeb1e6SAndreas Gohr * All DokuWiki plugins to extend the admin function 135faeb1e6SAndreas Gohr * need to inherit from this class 145faeb1e6SAndreas Gohr */ 155faeb1e6SAndreas Gohrclass admin_plugin_popularity extends DokuWiki_Admin_Plugin { 1698be6429SGuillaume Turri var $version; 1798be6429SGuillaume Turri var $helper; 1898be6429SGuillaume Turri var $sentStatus = null; 195faeb1e6SAndreas Gohr 2098be6429SGuillaume Turri function admin_plugin_popularity(){ 2198be6429SGuillaume Turri $this->helper = $this->loadHelper('popularity', false); 225faeb1e6SAndreas Gohr 2398be6429SGuillaume Turri $pluginInfo = $this->getInfo(); 2498be6429SGuillaume Turri $this->version = $pluginInfo['date']; 255faeb1e6SAndreas Gohr } 265faeb1e6SAndreas Gohr 275faeb1e6SAndreas Gohr /** 285faeb1e6SAndreas Gohr * return prompt for admin menu 295faeb1e6SAndreas Gohr */ 305faeb1e6SAndreas Gohr function getMenuText($language) { 315faeb1e6SAndreas Gohr return $this->getLang('name'); 325faeb1e6SAndreas Gohr } 335faeb1e6SAndreas Gohr 345faeb1e6SAndreas Gohr /** 355faeb1e6SAndreas Gohr * return sort order for position in admin menu 365faeb1e6SAndreas Gohr */ 375faeb1e6SAndreas Gohr function getMenuSort() { 385faeb1e6SAndreas Gohr return 2000; 395faeb1e6SAndreas Gohr } 405faeb1e6SAndreas Gohr 415faeb1e6SAndreas Gohr /** 421bda8618SAndreas Gohr * Accessible for managers 431bda8618SAndreas Gohr */ 441bda8618SAndreas Gohr function forAdminOnly() { 451bda8618SAndreas Gohr return false; 461bda8618SAndreas Gohr } 471bda8618SAndreas Gohr 481bda8618SAndreas Gohr 491bda8618SAndreas Gohr /** 505faeb1e6SAndreas Gohr * handle user request 515faeb1e6SAndreas Gohr */ 525faeb1e6SAndreas Gohr function handle() { 5398be6429SGuillaume Turri //Send the data 5498be6429SGuillaume Turri if ( isset($_REQUEST['data']) ){ 5598be6429SGuillaume Turri $this->sentStatus = $this->helper->sendData( $_REQUEST['data'] ); 565827ba0bSGuillaume Turri if ( $this->sentStatus === '' ){ 575827ba0bSGuillaume Turri //Update the last time we sent the data 585827ba0bSGuillaume Turri touch ( $this->helper->popularityLastSubmitFile ); 595827ba0bSGuillaume Turri } 6098be6429SGuillaume Turri //Deal with the autosubmit option 6198be6429SGuillaume Turri $this->_enableAutosubmit( isset($_REQUEST['autosubmit']) ); 6298be6429SGuillaume Turri } 6398be6429SGuillaume Turri } 6498be6429SGuillaume Turri 6598be6429SGuillaume Turri /** 6698be6429SGuillaume Turri * Enable or disable autosubmit 6798be6429SGuillaume Turri * @param bool $enable If TRUE, it will enable autosubmit. Else, it will disable it. 6898be6429SGuillaume Turri */ 6998be6429SGuillaume Turri function _enableAutosubmit( $enable ){ 7098be6429SGuillaume Turri if ( $enable ){ 7198be6429SGuillaume Turri io_saveFile( $this->helper->autosubmitFile, ' '); 7298be6429SGuillaume Turri } else { 7398be6429SGuillaume Turri @unlink($this->helper->autosubmitFile); 7498be6429SGuillaume Turri } 755faeb1e6SAndreas Gohr } 765faeb1e6SAndreas Gohr 775faeb1e6SAndreas Gohr /** 781bda8618SAndreas Gohr * Output HTML form 795faeb1e6SAndreas Gohr */ 805faeb1e6SAndreas Gohr function html() { 8198be6429SGuillaume Turri if ( ! isset($_REQUEST['data']) ){ 825faeb1e6SAndreas Gohr echo $this->locale_xhtml('intro'); 835faeb1e6SAndreas Gohr 8498be6429SGuillaume Turri //If there was an error the last time we tried to autosubmit, warn the user 8598be6429SGuillaume Turri if ( $this->helper->isAutoSubmitEnabled() ){ 8698be6429SGuillaume Turri if ( @file_exists($this->helper->autosubmitErrorFile) ){ 8798be6429SGuillaume Turri echo $this->getLang('autosubmitError'); 8898be6429SGuillaume Turri echo io_readFile( $this->helper->autosubmitErrorFile ); 8998be6429SGuillaume Turri } 9098be6429SGuillaume Turri } 9198be6429SGuillaume Turri 925faeb1e6SAndreas Gohr flush(); 9398be6429SGuillaume Turri echo $this->buildForm('server'); 945827ba0bSGuillaume Turri 955827ba0bSGuillaume Turri //Print the last time the data was sent 965827ba0bSGuillaume Turri $lastSent = $this->helper->lastSentTime(); 975827ba0bSGuillaume Turri if ( $lastSent !== 0 ){ 985827ba0bSGuillaume Turri echo $this->getLang('lastSent') . datetime_h($lastSent); 995827ba0bSGuillaume Turri } 1005faeb1e6SAndreas Gohr } else { 10198be6429SGuillaume Turri //If we just submitted the form 10298be6429SGuillaume Turri if ( $this->sentStatus === '' ){ 10398be6429SGuillaume Turri //If we successfully sent the data 10498be6429SGuillaume Turri echo $this->locale_xhtml('submitted'); 10598be6429SGuillaume Turri } else { 10698be6429SGuillaume Turri //If we failed to submit the data, try directly with the browser 10798be6429SGuillaume Turri echo $this->getLang('submissionFailed') . $this->sentStatus . '<br />'; 10898be6429SGuillaume Turri echo $this->getLang('submitDirectly'); 10998be6429SGuillaume Turri echo $this->buildForm('browser', $_REQUEST['data']); 1105faeb1e6SAndreas Gohr } 1115faeb1e6SAndreas Gohr } 1125faeb1e6SAndreas Gohr } 1135faeb1e6SAndreas Gohr 1145faeb1e6SAndreas Gohr 1155faeb1e6SAndreas Gohr /** 11698be6429SGuillaume Turri * Build the form which presents the data to be sent 11798be6429SGuillaume Turri * @param string $submit How is the data supposed to be sent? (may be: 'browser' or 'server') 11898be6429SGuillaume Turri * @param string $data The popularity data, if it has already been computed. NULL otherwise. 11998be6429SGuillaume Turri * @return The form, as an html string 1205faeb1e6SAndreas Gohr */ 12198be6429SGuillaume Turri function buildForm($submissionMode, $data = null){ 12298be6429SGuillaume Turri $url = ($submissionMode === 'browser' ? $this->helper->submitUrl : script()); 12398be6429SGuillaume Turri if ( is_null($data) ){ 12498be6429SGuillaume Turri $data = $this->helper->gatherAsString(); 1255faeb1e6SAndreas Gohr } 1265faeb1e6SAndreas Gohr 12798be6429SGuillaume Turri $form = '<form method="post" action="'. $url .'" accept-charset="utf-8">' 12898be6429SGuillaume Turri .'<fieldset style="width: 60%;">' 12998be6429SGuillaume Turri .'<textarea class="edit" rows="10" cols="80" readonly="readonly" name="data">' 13098be6429SGuillaume Turri .$data 13198be6429SGuillaume Turri .'</textarea><br />'; 13298be6429SGuillaume Turri 13398be6429SGuillaume Turri //If we submit via the server, we give the opportunity to suscribe to the autosubmission option 13498be6429SGuillaume Turri if ( $submissionMode !== 'browser' ){ 13598be6429SGuillaume Turri $form .= '<label for="autosubmit">' 13698be6429SGuillaume Turri .'<input type="checkbox" name="autosubmit" id="autosubmit" ' 13798be6429SGuillaume Turri .($this->helper->isAutosubmitEnabled() ? 'checked' : '' ) 13898be6429SGuillaume Turri .'/>' . $this->getLang('autosubmit') .'<br />' 13998be6429SGuillaume Turri .'</label>' 140*6cd259d7SAnika Henke .'<input type="hidden" name="do" value="admin" />' 141*6cd259d7SAnika Henke .'<input type="hidden" name="page" value="popularity" />'; 1425faeb1e6SAndreas Gohr } 14398be6429SGuillaume Turri $form .= '<input type="submit" class="button" value="'.$this->getLang('submit').'"/>' 14498be6429SGuillaume Turri .'</fieldset>' 14598be6429SGuillaume Turri .'</form>'; 14698be6429SGuillaume Turri return $form; 1475faeb1e6SAndreas Gohr } 1485faeb1e6SAndreas Gohr} 149