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 { 16*98be6429SGuillaume Turri var $version; 17*98be6429SGuillaume Turri var $helper; 18*98be6429SGuillaume Turri var $sentStatus = null; 195faeb1e6SAndreas Gohr 20*98be6429SGuillaume Turri function admin_plugin_popularity(){ 21*98be6429SGuillaume Turri $this->helper = $this->loadHelper('popularity', false); 225faeb1e6SAndreas Gohr 23*98be6429SGuillaume Turri $pluginInfo = $this->getInfo(); 24*98be6429SGuillaume 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() { 53*98be6429SGuillaume Turri //Send the data 54*98be6429SGuillaume Turri if ( isset($_REQUEST['data']) ){ 55*98be6429SGuillaume Turri $this->sentStatus = $this->helper->sendData( $_REQUEST['data'] ); 56*98be6429SGuillaume Turri //Deal with the autosubmit option 57*98be6429SGuillaume Turri $this->_enableAutosubmit( isset($_REQUEST['autosubmit']) ); 58*98be6429SGuillaume Turri } 59*98be6429SGuillaume Turri } 60*98be6429SGuillaume Turri 61*98be6429SGuillaume Turri /** 62*98be6429SGuillaume Turri * Enable or disable autosubmit 63*98be6429SGuillaume Turri * @param bool $enable If TRUE, it will enable autosubmit. Else, it will disable it. 64*98be6429SGuillaume Turri */ 65*98be6429SGuillaume Turri function _enableAutosubmit( $enable ){ 66*98be6429SGuillaume Turri if ( $enable ){ 67*98be6429SGuillaume Turri io_saveFile( $this->helper->autosubmitFile, ' '); 68*98be6429SGuillaume Turri } else { 69*98be6429SGuillaume Turri @unlink($this->helper->autosubmitFile); 70*98be6429SGuillaume Turri } 715faeb1e6SAndreas Gohr } 725faeb1e6SAndreas Gohr 735faeb1e6SAndreas Gohr /** 741bda8618SAndreas Gohr * Output HTML form 755faeb1e6SAndreas Gohr */ 765faeb1e6SAndreas Gohr function html() { 77*98be6429SGuillaume Turri if ( ! isset($_REQUEST['data']) ){ 785faeb1e6SAndreas Gohr echo $this->locale_xhtml('intro'); 795faeb1e6SAndreas Gohr 80*98be6429SGuillaume Turri //If there was an error the last time we tried to autosubmit, warn the user 81*98be6429SGuillaume Turri if ( $this->helper->isAutoSubmitEnabled() ){ 82*98be6429SGuillaume Turri if ( @file_exists($this->helper->autosubmitErrorFile) ){ 83*98be6429SGuillaume Turri echo $this->getLang('autosubmitError'); 84*98be6429SGuillaume Turri echo io_readFile( $this->helper->autosubmitErrorFile ); 85*98be6429SGuillaume Turri } 86*98be6429SGuillaume Turri } 87*98be6429SGuillaume Turri 885faeb1e6SAndreas Gohr flush(); 89*98be6429SGuillaume Turri echo $this->buildForm('server'); 905faeb1e6SAndreas Gohr } else { 91*98be6429SGuillaume Turri //If we just submitted the form 92*98be6429SGuillaume Turri if ( $this->sentStatus === '' ){ 93*98be6429SGuillaume Turri //If we successfully sent the data 94*98be6429SGuillaume Turri echo $this->locale_xhtml('submitted'); 95*98be6429SGuillaume Turri } else { 96*98be6429SGuillaume Turri //If we failed to submit the data, try directly with the browser 97*98be6429SGuillaume Turri echo $this->getLang('submissionFailed') . $this->sentStatus . '<br />'; 98*98be6429SGuillaume Turri echo $this->getLang('submitDirectly'); 99*98be6429SGuillaume Turri echo $this->buildForm('browser', $_REQUEST['data']); 1005faeb1e6SAndreas Gohr } 1015faeb1e6SAndreas Gohr } 1025faeb1e6SAndreas Gohr } 1035faeb1e6SAndreas Gohr 1045faeb1e6SAndreas Gohr 1055faeb1e6SAndreas Gohr /** 106*98be6429SGuillaume Turri * Build the form which presents the data to be sent 107*98be6429SGuillaume Turri * @param string $submit How is the data supposed to be sent? (may be: 'browser' or 'server') 108*98be6429SGuillaume Turri * @param string $data The popularity data, if it has already been computed. NULL otherwise. 109*98be6429SGuillaume Turri * @return The form, as an html string 1105faeb1e6SAndreas Gohr */ 111*98be6429SGuillaume Turri function buildForm($submissionMode, $data = null){ 112*98be6429SGuillaume Turri $url = ($submissionMode === 'browser' ? $this->helper->submitUrl : script()); 113*98be6429SGuillaume Turri if ( is_null($data) ){ 114*98be6429SGuillaume Turri $data = $this->helper->gatherAsString(); 1155faeb1e6SAndreas Gohr } 1165faeb1e6SAndreas Gohr 117*98be6429SGuillaume Turri $form = '<form method="post" action="'. $url .'" accept-charset="utf-8">' 118*98be6429SGuillaume Turri .'<fieldset style="width: 60%;">' 119*98be6429SGuillaume Turri .'<textarea class="edit" rows="10" cols="80" readonly="readonly" name="data">' 120*98be6429SGuillaume Turri .$data 121*98be6429SGuillaume Turri .'</textarea><br />'; 122*98be6429SGuillaume Turri 123*98be6429SGuillaume Turri //If we submit via the server, we give the opportunity to suscribe to the autosubmission option 124*98be6429SGuillaume Turri if ( $submissionMode !== 'browser' ){ 125*98be6429SGuillaume Turri $form .= '<label for="autosubmit">' 126*98be6429SGuillaume Turri .'<input type="checkbox" name="autosubmit" id="autosubmit" ' 127*98be6429SGuillaume Turri .($this->helper->isAutosubmitEnabled() ? 'checked' : '' ) 128*98be6429SGuillaume Turri .'/>' . $this->getLang('autosubmit') .'<br />' 129*98be6429SGuillaume Turri .'</label>' 130*98be6429SGuillaume Turri .'<input type="hidden" name="do" value="admin">' 131*98be6429SGuillaume Turri .'<input type="hidden" name="page" value="popularity">'; 1325faeb1e6SAndreas Gohr } 133*98be6429SGuillaume Turri $form .= '<input type="submit" class="button" value="'.$this->getLang('submit').'"/>' 134*98be6429SGuillaume Turri .'</fieldset>' 135*98be6429SGuillaume Turri .'</form>'; 136*98be6429SGuillaume Turri return $form; 1375faeb1e6SAndreas Gohr } 1385faeb1e6SAndreas Gohr} 139