1<?php 2/** 3 * Popularity Feedback Plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8// must be run within Dokuwiki 9if(!defined('DOKU_INC')) die(); 10 11/** 12 * All DokuWiki plugins to extend the admin function 13 * need to inherit from this class 14 */ 15class admin_plugin_popularity extends DokuWiki_Admin_Plugin { 16 var $version; 17 var $helper; 18 var $sentStatus = null; 19 20 function admin_plugin_popularity(){ 21 $this->helper = $this->loadHelper('popularity', false); 22 23 $pluginInfo = $this->getInfo(); 24 $this->version = $pluginInfo['date']; 25 } 26 27 /** 28 * return prompt for admin menu 29 */ 30 function getMenuText($language) { 31 return $this->getLang('name'); 32 } 33 34 /** 35 * return sort order for position in admin menu 36 */ 37 function getMenuSort() { 38 return 2000; 39 } 40 41 /** 42 * Accessible for managers 43 */ 44 function forAdminOnly() { 45 return false; 46 } 47 48 49 /** 50 * handle user request 51 */ 52 function handle() { 53 //Send the data 54 if ( isset($_REQUEST['data']) ){ 55 $this->sentStatus = $this->helper->sendData( $_REQUEST['data'] ); 56 //Deal with the autosubmit option 57 $this->_enableAutosubmit( isset($_REQUEST['autosubmit']) ); 58 } 59 } 60 61 /** 62 * Enable or disable autosubmit 63 * @param bool $enable If TRUE, it will enable autosubmit. Else, it will disable it. 64 */ 65 function _enableAutosubmit( $enable ){ 66 if ( $enable ){ 67 io_saveFile( $this->helper->autosubmitFile, ' '); 68 } else { 69 @unlink($this->helper->autosubmitFile); 70 } 71 } 72 73 /** 74 * Output HTML form 75 */ 76 function html() { 77 if ( ! isset($_REQUEST['data']) ){ 78 echo $this->locale_xhtml('intro'); 79 80 //If there was an error the last time we tried to autosubmit, warn the user 81 if ( $this->helper->isAutoSubmitEnabled() ){ 82 if ( @file_exists($this->helper->autosubmitErrorFile) ){ 83 echo $this->getLang('autosubmitError'); 84 echo io_readFile( $this->helper->autosubmitErrorFile ); 85 } 86 } 87 88 flush(); 89 echo $this->buildForm('server'); 90 } else { 91 //If we just submitted the form 92 if ( $this->sentStatus === '' ){ 93 //If we successfully sent the data 94 echo $this->locale_xhtml('submitted'); 95 } else { 96 //If we failed to submit the data, try directly with the browser 97 echo $this->getLang('submissionFailed') . $this->sentStatus . '<br />'; 98 echo $this->getLang('submitDirectly'); 99 echo $this->buildForm('browser', $_REQUEST['data']); 100 } 101 } 102 } 103 104 105 /** 106 * Build the form which presents the data to be sent 107 * @param string $submit How is the data supposed to be sent? (may be: 'browser' or 'server') 108 * @param string $data The popularity data, if it has already been computed. NULL otherwise. 109 * @return The form, as an html string 110 */ 111 function buildForm($submissionMode, $data = null){ 112 $url = ($submissionMode === 'browser' ? $this->helper->submitUrl : script()); 113 if ( is_null($data) ){ 114 $data = $this->helper->gatherAsString(); 115 } 116 117 $form = '<form method="post" action="'. $url .'" accept-charset="utf-8">' 118 .'<fieldset style="width: 60%;">' 119 .'<textarea class="edit" rows="10" cols="80" readonly="readonly" name="data">' 120 .$data 121 .'</textarea><br />'; 122 123 //If we submit via the server, we give the opportunity to suscribe to the autosubmission option 124 if ( $submissionMode !== 'browser' ){ 125 $form .= '<label for="autosubmit">' 126 .'<input type="checkbox" name="autosubmit" id="autosubmit" ' 127 .($this->helper->isAutosubmitEnabled() ? 'checked' : '' ) 128 .'/>' . $this->getLang('autosubmit') .'<br />' 129 .'</label>' 130 .'<input type="hidden" name="do" value="admin">' 131 .'<input type="hidden" name="page" value="popularity">'; 132 } 133 $form .= '<input type="submit" class="button" value="'.$this->getLang('submit').'"/>' 134 .'</fieldset>' 135 .'</form>'; 136 return $form; 137 } 138} 139