1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
<?php
/**
* DokuWiki Plugin farmer (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Michael Große <grosse@cosmocode.de>
* @author Andreas Gohr <gohr@cosmocode.de>
*/
// must be run within Dokuwiki
use dokuwiki\Form\Form;
if(!defined('DOKU_INC')) die();
/**
* Information about the farm and the current instance
*/
class admin_plugin_farmer_delete extends DokuWiki_Admin_Plugin {
/** @var helper_plugin_farmer */
protected $helper;
/**
* admin_plugin_farmer_info constructor.
*/
public function __construct() {
$this->helper = plugin_load('helper', 'farmer');
}
/**
* @return bool admin only!
*/
public function forAdminOnly() {
return true;
}
/**
* Should carry out any processing required by the plugin.
*/
public function handle() {
global $INPUT;
global $ID;
if(!$INPUT->has('delete')) return;
if($INPUT->filter('trim')->str('delanimal') === '') {
msg($this->getLang('delete_noanimal'), -1);
return;
}
if($INPUT->str('delanimal') != $INPUT->str('confirm')) {
msg($this->getLang('delete_mismatch'), -1);
return;
}
$animaldir = DOKU_FARMDIR . $INPUT->str('delanimal');
if(!$this->helper->isInPath($animaldir, DOKU_FARMDIR) || !is_dir($animaldir)) {
msg($this->getLang('delete_invalid'), -1);
return;
}
// let's delete it
$ok = io_rmdir($animaldir, true);
if($ok) {
msg($this->getLang('delete_success'), 1);
} else {
msg($this->getLang('delete_fail'), -1);
}
$link = wl($ID, array('do'=>'admin', 'page'=>'farmer', 'sub' => 'delete'), true, '&');
send_redirect($link);
}
/**
* Render HTML output, e.g. helpful text and a form
*/
public function html() {
$form = new Form();
$form->addFieldsetOpen($this->getLang('delete_animal'));
$animals = $this->helper->getAllAnimals();
array_unshift($animals, '');
$form->addDropdown('delanimal', $animals)->addClass('farmer_chosen_animals');
$form->addTextInput('confirm', $this->getLang('delete_confirm'));
$form->addButton('delete', $this->getLang('delete'));
$form->addFieldsetClose();
echo $form->toHTML();
}
}
// vim:ts=4:sw=4:et:
|