-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
147 lines (130 loc) · 5.66 KB
/
admin.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* DokuWiki Plugin farmsync (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Michael Große <[email protected]>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
use dokuwiki\Form\Form;
use dokuwiki\plugin\farmsync\meta\FarmSyncUtil;
class admin_plugin_farmsync extends DokuWiki_Admin_Plugin {
/**
* @return int sort number in admin menu
*/
public function getMenuSort() {
return 43; // One behind the Farmer Entry
}
/**
* @return bool true if only access for superuser, false is for superusers and moderators
*/
public function forAdminOnly() {
return true;
}
public $farm_util;
/** @var \helper_plugin_struct_imexport $struct */
private $struct;
function __construct() {
$this->farm_util = new FarmSyncUtil();
}
/**
* Should carry out any processing required by the plugin.
*/
public function handle() {
}
/**
* Render HTML output, e.g. helpful text and a form
*/
public function html() {
$farmer = plugin_load('helper', 'farmer');
if (!$farmer) {
msg('The farmsync plugin requires the farmer plugin to work. Please install it', -1);
return;
}
global $INPUT;
if (!($INPUT->has('farmsync-animals') && $INPUT->has('farmsync'))) {
echo "<div id=\"plugin__farmsync\">";
echo '<h1>' . $this->getLang('heading:Update animals') . '</h1>';
$animals = $this->farm_util->getAllAnimals();
$form = new Form();
$form->addFieldsetOpen($this->getLang('legend:choose source'));
$form->addDropdown('farmsync[source]', $animals, $this->getLang('label:source'))->addClass('make_chosen');
$form->addFieldsetClose();
$form->addFieldsetOpen($this->getLang('legend:choose documents'));
$form->addTextarea('farmsync[pages]', $this->getLang('label:PageEntry'));
$form->addHTML("<br>");
$form->addTextarea('farmsync[media]', $this->getLang('label:MediaEntry'));
$form->addHTML("<br>");
if (plugin_load('helper', 'struct_imexport')) {
$form->addCheckbox('farmsync[struct]', $this->getLang('label:struct synchronisation'));
$form->addTagOpen('div')->addClass('structsync')->attr('style','display: none;');
$form->addTagClose('div');
} elseif (plugin_load('helper', 'struct_imexport', false, true)) {
echo '<div style="color: grey;">' . $this->getLang('notice:struct disabled') . '</div>';
}
$form->addFieldsetClose();
$form->addFieldsetOpen($this->getLang('legend:choose animals'));
foreach ($animals as $animal) {
$form->addCheckbox('farmsync-animals[' . $animal . ']', $animal);
}
$form->addFieldsetClose();
$form->addButton('submit', $this->getLang('button:submit'));
echo $form->toHTML();
echo $this->locale_xhtml('update');
echo "</div>";
return;
} else {
set_time_limit(0);
$targets = array_keys($INPUT->arr('farmsync-animals'));
$options = $INPUT->arr('farmsync');
$textare_linebreak = "\r\n";
$pages = array_filter(explode($textare_linebreak, $options['pages']));
$media = array_filter(explode($textare_linebreak, $options['media']));
$struct = array_keys($INPUT->arr('farmsync_struct'));
$source = $options['source']; // ToDo: validate thath source exists
/** @var \dokuwiki\plugin\farmsync\meta\EntityUpdates[] $updaters */
$updaters = array();
if (!empty($pages)) {
$updaters[] = new \dokuwiki\plugin\farmsync\meta\PageUpdates($source, $targets, $pages);
$updaters[] = new \dokuwiki\plugin\farmsync\meta\TemplateUpdates($source, $targets, $pages);
}
if (!empty($media)) {
$updaters[] = new \dokuwiki\plugin\farmsync\meta\MediaUpdates($source, $targets, $media);
}
if (!empty($struct)) {
$updaters[] = new \dokuwiki\plugin\farmsync\meta\StructUpdates($source, $targets, $struct);
}
echo "<div id=\"plugin__farmsync\"><div id=\"results\" data-source='$options[source]'>";
echo "<span class='progress'>Progress and Errors</span>";
echo "<div class='progress'>";
foreach ($updaters as $updater) {
$updater->updateEntities();
}
echo "</div>";
echo "<h1>" . $this->getLang('heading:Update done') . "</h1>";
foreach ($targets as $target) {
$conflicts = 0;
foreach ($updaters as $updater) {
$conflicts += $updater->getNumberOfAnimalConflicts($target);
}
if ($conflicts == 0) {
$class = 'noconflicts';
$heading = sprintf($this->getLang('heading:animal noconflict'), $target);
} else {
$class = 'withconflicts';
$heading = sprintf($this->getLang('heading:animal conflict'), $target, $conflicts);
}
echo "<div class='result $class'><h2>" . $heading . "</h2>";
echo "<div>";
foreach ($updaters as $updater) {
$updater->printAnimalResultHTML($target);
}
echo "</div>";
echo "</div>";
}
echo "</div></div>";
}
}
}
// vim:ts=4:sw=4:et: