1<?php
2// must be run within Dokuwiki
3if(!defined('DOKU_INC')) die();
4
5if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
6require_once(DOKU_PLUGIN.'admin.php');
7
8/**
9 * All DokuWiki plugins to extend the admin function
10 * need to inherit from this class
11 */
12class admin_plugin_unameban extends DokuWiki_Admin_Plugin {
13
14    /**
15     * access for managers
16     */
17    function forAdminOnly(){
18        return false;
19    }
20
21    /**
22     * return sort order for position in admin menu
23     */
24    function getMenuSort() {
25        return 41;
26    }
27
28    /**
29     * handle user request
30     */
31    function handle() {
32        global $conf;
33        if($_REQUEST['banusername']){
34            $newban = trim($_REQUEST['banusername'])."\t".time()."\t".$_SERVER['REMOTE_USER'];
35            $cause  = trim(preg_replace('/[\n\r\t]+/','',$_REQUEST['cause']));
36            $newban .= "\t".$cause."\n";
37            io_savefile($conf['cachedir'].'/unamebanplugin.txt',$newban,true);
38        }
39
40        if(is_array($_REQUEST['delusername'])){
41            $del = trim(array_shift(array_keys($_REQUEST['delusername'])));
42            $del = preg_quote($del,'/');
43            $new = array();
44            $bans = @file($conf['cachedir'].'/unamebanplugin.txt');
45            if(is_array($bans)) foreach($bans as $ban){
46                if(!preg_match('/^'.$del.'\t/',$ban)) $new[] = $ban;
47            }
48            io_savefile($conf['cachedir'].'/unamebanplugin.txt',join('',$new));
49        }
50    }
51
52    /**
53     * output appropriate html
54     */
55    function html() {
56        global $conf;
57
58        echo $this->locale_xhtml('intro');
59
60        echo '<form method="post" action="">';
61        echo '<table class="inline" width="100%">';
62        echo '<tr>';
63        echo '<th>'.$this->getLang('username').'</th>';
64        echo '<th>'.$this->getLang('date').'</th>';
65        echo '<th>'.$this->getLang('by').'</th>';
66        echo '<th>'.$this->getLang('cause').'</th>';
67        echo '<th>'.$this->getLang('del').'</th>';
68        echo '</tr>';
69        $bans = @file($conf['cachedir'].'/unamebanplugin.txt');
70        if(is_array($bans)) foreach($bans as $ban){
71            $fields = explode("\t",$ban);
72            echo '<tr>';
73            echo '<td>'.hsc($fields[0]).'</td>';
74            echo '<td>'.strftime($conf['dformat'],$fields[1]).'</td>';
75            echo '<td>'.hsc($fields[2]).'</td>';
76            echo '<td>'.hsc($fields[3]).'</td>';
77            echo '<td><input type="submit" name="delusername['.$fields[0].']" value="'.$this->getLang('del').'" class="button" /></td>';
78            echo '</tr>';
79        }
80        echo '<tr>';
81        echo '<th colspan="6">';
82        echo '<div>'.$this->getLang('newban').':</div>';
83        echo '<label for="plg__unameban_username">'.$this->getLang('username').':</label>';
84        echo '<input type="text" name="banusername" id="plg__unameban_username" class="edit" /> ';
85        echo '<label for="plg__unameban_cause">'.$this->getLang('cause').':</label>';
86        echo '<input type="text" name="cause" id="plg__unameban_cause" class="edit" /> ';
87        echo '<input type="submit" class="button" value="'.$this->getLang('ban').'" />';
88        echo '</th>';
89        echo '</tr>';
90        echo '</table>';
91        echo '</form>';
92
93    }
94
95
96}
97