-
Notifications
You must be signed in to change notification settings - Fork 12
/
helper.php
344 lines (273 loc) · 15 KB
/
helper.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
/**
* Siteexport Plugin helper
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author i-net software <[email protected]>
* @author Gerry Weissbach <[email protected]>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
require_once(DOKU_PLUGIN.'siteexport/preload.php');
class helper_plugin_siteexport_page_remove {
private $start, $end;
/**
* @param integer $start
* @param integer $end
*/
public function __construct($start, $end=null) {
$this->start = $start;
$this->end = $end;
}
public function _page_remove($elem) {
return $elem[2] >= $this->start && ( is_null( $this->end ) || $elem[2] <= $this->end);
}
}
class helper_plugin_siteexport extends DokuWiki_Plugin {
/*
* return all the templates that this wiki has
*/
public function __getTemplates() {
// populate $this->_choices with a list of directories
$list = array();
$_dir = DOKU_INC . 'lib/tpl/';
$_pattern = '/^[\w-]+$/';
if ($dh = @opendir($_dir)) {
while (false !== ($entry = readdir($dh))) {
if ($entry == '.' || $entry == '..') {
continue;
}
if ($entry == '.' || $entry == '..') {
continue;
}
if ($_pattern && !preg_match($_pattern,$entry)) {
continue;
}
$file = (is_link($_dir.$entry)) ? readlink($_dir.$entry) : $entry;
if (is_dir($_dir.$file)) {
$list[] = $entry;
}
}
closedir($dh);
}
sort($list);
return $list;
}
/*
* Return array list of plugins that exist
*/
public function __getPluginList() {
global $plugin_controller;
$allPlugins = array();
foreach ($plugin_controller->getList(null, true) as $plugin) { // All plugins
// check for CSS or JS
if (!file_exists(DOKU_PLUGIN . "$plugin/script.js") && !file_exists(DOKU_PLUGIN . "$plugin/style.css") && !file_exists(DOKU_PLUGIN . "$plugin/print.css")) { continue; }
$allPlugins[] = $plugin;
}
return array($allPlugins, $plugin_controller->getList());
}
public function _page_sort($a, $b)
{
if ( $a[2] == $b[2] ) {
return 0;
}
return $a[2] > $b[2] ? -1 : 1;
}
public function __getOrderedListOfPagesForID($IDs, $start=null)
{
global $conf;
require_once(dirname(__FILE__)."/inc/functions.php");
$functions = new siteexport_functions(false);
if ( !is_array($IDs) ) {
$IDs = array($IDs);
}
$sites = $values = array();
foreach( $IDs as $ID ) {
$page = null;
search($sites, $conf['datadir'], 'search_allpages', array(), $functions->getNamespaceFromID($ID, $page));
foreach( $sites as $site ) {
if ( $ID == $site['id'] ) {
continue;
}
$sortIdentifier = intval(p_get_metadata($site['id'], 'mergecompare'));
$entry = array(':' . $site['id'], $functions->getSiteTitle($site['id']), $sortIdentifier);
if ( !in_array($entry[0], array_column($values, 0)) ) {
array_push($values, $entry);
}
}
}
if ( $start != null ) {
// filter using the newerThanPage indicator
$sortIdentifier = intval(p_get_metadata($start, 'mergecompare'));
$values = array_filter($values, array(new helper_plugin_siteexport_page_remove($sortIdentifier), '_page_remove'));
}
usort($values, array($this, '_page_sort'));
return $values;
}
public function __getOrderedListOfPagesForStartEnd($ID, $start, $end)
{
$values = $this->__getOrderedListOfPagesForID($ID);
// filter using the newerThanPage indicator
$values = array_filter($values, array(new helper_plugin_siteexport_page_remove(intval($start), intval($end)), '_page_remove'));
usort($values, array($this, '_page_sort'));
return $values;
}
public function __siteexport_addpage() {
global $ID, $conf;
$templateSwitching = false;
$pdfExport = false;
$translationAvailable = false;
$usenumberedheading = true;
$trans = array();
$preload = plugin_load('preload', 'siteexport');
if ($preload && $preload->__create_preload_function()) {
$templateSwitching = true;
}
$dw2pdf = plugin_load('action', 'dw2pdf');
if ($dw2pdf) {
$pdfExport = true;
}
$translation = plugin_load('helper', 'autotranslation');
if ($translation) {
$translationAvailable = true;
$trans = $translation->translations;
}
print $this->locale_xhtml((defined('DOKU_SITEEXPORT_MANAGER') ? 'manager' : '') . 'intro');
$form = new Doku_Form('siteexport', null, 'post');
$form->startFieldset($this->getLang('startingNamespace'));
$form->addElement(form_makeTextField('ns', $ID, $this->getLang('ns') . ':', 'ns'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeTextField('ens', $ID, $this->getLang('ens') . ':', 'ens'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeListboxField('depthType', array("0.0" => $this->getLang('depth.pageOnly'), "1.0" => $this->getLang('depth.allSubNameSpaces'), "2.0" => $this->getLang('depth.specifiedDepth')), (empty($_REQUEST['depthType']) ? $this->getLang('depth.allSubNameSpaces') : $_REQUEST['depthType']), $this->getLang('depthType') . ':', 'depthType', null, array_merge(array('class' => 'edit'))));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeOpenTag("div", array('style' => 'display:' . ($_REQUEST['depthType'] == "2" ? "block" : "none") . ';', 'id' => 'depthContainer')));
$form->addElement(form_makeTextField('depth', $this->getConf('depth'), $this->getLang('depth') . ':', 'depth'));
$form->addElement(form_makeCloseTag("div"));
$form->endFieldset();
$form->addElement(form_makeTag('br'));
$form->startFieldset($this->getLang('selectYourOptions'));
$form->addElement(form_makeCheckboxField('absolutePath', 1, $this->getLang('absolutePath') . ':', 'absolutePath'));
$form->addElement(form_makeTag('br'));
// The parameter needs lowercase
$form->addElement(form_makeCheckboxField('exportbody', 1, $this->getLang('exportBody') . ':', 'exportbody'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('exportLinkedPages', 1, $this->getLang('exportLinkedPages') . ':', 'exportLinkedPages', 'sendIfNotSet', array('checked' => 'checked')));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('disableCache', 1, $this->getLang('disableCache') . ':', 'disableCache'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('addParams', 1, $this->getLang('addParams') . ':', 'addParams', null, array_merge(array('checked' => ($conf['userewrite'] != 1 ? 'checked' : '')))));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeListboxField('renderer', array_merge(array('', 'xhtml'), plugin_list('renderer')), '', $this->getLang('renderer') . ':', 'renderer', null, array_merge(array('class' => 'edit'))));
$form->addElement(form_makeTag('br'));
if ($templateSwitching) {
$form->addElement(form_makeListboxField('template', $this->__getTemplates(), $conf['template'], $this->getLang('template') . ':', 'template', null, array_merge(array('class' => 'edit'))));
$form->addElement(form_makeTag('br'));
} else
{
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeOpenTag('p', array('style' => 'color: #a00;')));
$form->addElement('Can\'t create preload file in \'inc\' directory. Template switching is not available. Plugin disabling is not available.');
$form->addElement(form_makeCloseTag('p'));
}
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('pdfExport', 1, $this->getLang('pdfExport') . ':', 'pdfExport', null, $pdfExport ? array() : array_merge(array('disabled' => 'disabled'))));
// Hint for dw2pdf
$this->addPluginHint( $form, $pdfExport, "the PDF export", "dw2pdf" );
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('usenumberedheading', 1, $this->getLang('usenumberedheading') . ':', 'usenumberedheading', null, $usenumberedheading && $pdfExport ? array() : array_merge(array('disabled' => 'disabled'))));
$form->addElement(form_makeTag('br'));
// Hint for nodetailsxhtml
$this->addPluginHint( $form, $usenumberedheading, "numbered headings", "nodetailsxhtml" );
$form->endFieldset();
$form->addElement(form_makeTag('br'));
$form->startFieldset($this->getLang('helpCreationOptions'));
$form->addElement(form_makeCheckboxField('eclipseDocZip', 1, $this->getLang('eclipseDocZip') . ':', 'eclipseDocZip'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('JavaHelpDocZip', 1, $this->getLang('JavaHelpDocZip') . ':', 'JavaHelpDocZip'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('useTocFile', 1, $this->getLang('useTocFile') . ':', 'useTocFile'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeCheckboxField('emptyTocElem', 1, $this->getLang('emptyTocElem') . ':', 'emptyTocElem'));
$form->addElement(form_makeTag('br'));
if (!$translationAvailable) {
$form->addElement(form_makeCheckboxField('TOCMapWithoutTranslation', 1, $this->getLang('TOCMapWithoutTranslation') . ':', 'TOCMapWithoutTranslation'));
$form->addElement(form_makeTag('br'));
} else {
if (!is_array($trans)) {
$trans = array($trans);
}
$trans = array_unique(array_merge($trans, array($conf['lang'])));
$form->addElement(form_makeListboxField('defaultLang', $trans, $conf['lang'], $this->getLang('defaultLang') . ':', 'defaultLang'));
$form->addElement(form_makeTag('br'));
}
$form->endFieldset();
$form->addElement(form_makeTag('br'));
if ($templateSwitching)
{
$form->startFieldset($this->getLang('disablePluginsOption'));
$form->addElement(form_makeCheckboxField("disableall", 1, 'Disable All:', "disableall", 'forceVisible'));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeTag('br'));
list($allPlugins, $enabledPlugins) = $this->__getPluginList();
foreach ($allPlugins as $plugin) {
$form->addElement(form_makeCheckboxField("disableplugin[]", $plugin, $plugin . ':', "disableplugin_$plugin", null, (!in_array($plugin, $enabledPlugins) ? array('checked' => 'checked', 'disabled' => 'disabled') : array())));
$form->addElement(form_makeTag('br'));
}
$form->endFieldset();
$form->addElement(form_makeTag('br'));
}
$form->startFieldset( $this->getLang('customOptions') );
$form->addElement(form_makeOpenTag('p'));
$form->addElement( $this->getLang('customOptionsDescription') );
$form->addElement(form_makeCloseTag('p'));
$form->addElement(form_makeOpenTag('ul', array('id' => 'siteexport__customActions')));
$form->addElement(form_makeCloseTag('ul'));
$form->addElement(form_makeTag('br', array('class'=>'clear')));
$form->addElement(form_makeButton('submit', 'addoption', $this->getLang('addCustomOption') , array('style' => 'float:right;') ));
$form->endFieldset();
$form->addElement(form_makeTag('br'));
if ( !defined('DOKU_SITEEXPORT_MANAGER') ) {
$form->startFieldset( $this->getLang('startProcess') );
$form->addElement(form_makeTextField('copyurl', "", $this->getLang('directDownloadLink') . ':', 'copyurl', null, array('readonly' => 'readonly') ));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeTextField('wgeturl', "", $this->getLang('wgetURLLink') . ':', 'wgeturl', null, array('readonly' => 'readonly') ));
$form->addElement(form_makeTag('br'));
$form->addElement(form_makeTextField('curlurl', "", $this->getLang('curlURLLink') . ':', 'curlurl', null, array('readonly' => 'readonly') ));
$form->addElement(form_makeTag('br', array('class'=>'clear')));
$form->addElement(form_makeButton('submit', 'siteexport', $this->getLang('start') , array('style' => 'float:right;')));
$form->endFieldset();
$form->addElement(form_makeTag('br'));
$form->endFieldset();
$form->addElement(form_makeTag('br'));
$form->startFieldset( $this->getLang('status') );
$form->addElement(form_makeOpenTag('span', array('id' => 'siteexport__out')));
$form->addElement(form_makeCloseTag('span'));
$form->addElement(form_makeOpenTag('span', array('class' => 'siteexport__throbber')));
$throbber = DOKU_BASE.'lib/images/loading.gif';
if ( !file_exists( $throbber) ) {
$throbber = DOKU_BASE.'lib/images/throbber.gif';
}
$form->addElement(form_makeTag('img', array('src' => $throbber, 'id' => 'siteexport__throbber')));
$form->addElement(form_makeCloseTag('span'));
$form->endFieldset();
$form->addElement(form_makeTag('br'));
} else {
$form->startFieldset( $this->getLang('startProcess') );
$form->addElement(form_makeButton('submit', 'siteexport', $this->getLang('useOptionsInEditor') , array('style' => 'width:100%;')));
}
$form->endFieldset();
$form->addElement(form_makeTag('br'));
$form->printForm();
}
private function addPluginHint( &$form, $condition, $hint, $plugin ) {
if ($condition) { return; }
$form->addElement(form_makeOpenTag('p', array('style' => 'color: #a00;')));
$form->addElement('In order to use ' . $hint . ', please ');
$form->addElement(form_makeOpenTag('a', array('href' => 'http://www.dokuwiki.org/plugin:' . $plugin, 'alt' => 'install plugin', 'target' => '_blank')));
$form->addElement('install the ' . $plugin . ' plugin.');
$form->addElement(form_makeCloseTag('a'));
$form->addElement(form_makeCloseTag('p'));
}
}