xref: /plugin/siteexport/helper.php (revision 0571ece201b9e3bc14846f6c88d943a4f1512014)
1<?php
2/**
3 * Translation Plugin: Simple multilanguage plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     i-net software <tools@inetsoftware.de>
7 * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8 */
9
10// must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12require_once(DOKU_PLUGIN.'siteexport/preload.php');
13
14class helper_plugin_siteexport_page_remove {
15    private $start, $end;
16
17    /**
18     * @param integer $start
19     * @param integer $end
20     */
21    function __construct($start, $end=null) {
22        $this->start = $start;
23        $this->end = $end;
24    }
25
26    function _page_remove($elem) {
27        return $elem[2] >= $this->start && ( is_null( $this->end ) || $elem[2] <= $this->end);
28    }
29}
30
31class helper_plugin_siteexport extends DokuWiki_Plugin {
32
33    /**
34     * for backward compatability
35     * @see inc/DokuWiki_Plugin#getInfo()
36     */
37    function getInfo(){
38        if ( method_exists(parent, 'getInfo')) {
39            $info = parent::getInfo();
40        }
41        return is_array($info) ? $info : confToHash(dirname(__FILE__).'/plugin.info.txt');
42    }
43
44    /*
45     * return all the templates that this wiki has
46     */
47	function __getTemplates() {
48
49		// populate $this->_choices with a list of directories
50		$list = array();
51
52		$_dir = DOKU_INC . 'lib/tpl/';
53		$_pattern = '/^[\w-]+$/';
54		if ($dh = @opendir($_dir)) {
55			while (false !== ($entry = readdir($dh))) {
56				if ($entry == '.' || $entry == '..') {
57				    continue;
58				}
59				if ($entry == '.' || $entry == '..') {
60				    continue;
61				}
62				if ($_pattern && !preg_match($_pattern,$entry)) {
63				    continue;
64				}
65
66				$file = (is_link($_dir.$entry)) ? readlink($_dir.$entry) : $entry;
67				if (is_dir($_dir.$file)) {
68				    $list[] = $entry;
69				}
70			}
71			closedir($dh);
72		}
73
74
75		sort($list);
76		return $list;
77	}
78
79	/*
80	 * Return array list of plugins that exist
81	 */
82	function __getPluginList() {
83	    global $plugin_controller;
84
85	    $allPlugins = array();
86	    foreach ($plugin_controller->getList(null, true) as $plugin) { // All plugins
87	    	// check for CSS or JS
88	    	if (!file_exists(DOKU_PLUGIN . "$plugin/script.js") && !file_exists(DOKU_PLUGIN . "$plugin/style.css") && !file_exists(DOKU_PLUGIN . "$plugin/print.css")) { continue; }
89	    	$allPlugins[] = $plugin;
90	    }
91
92    	return array($allPlugins, $plugin_controller->getList());
93	}
94
95    private function _page_sort($a, $b)
96    {
97	    if ( $a[2] == $b[2] ) {
98		    return 0;
99	    }
100
101	    return $a[2] > $b[2] ? -1 : 1;
102    }
103
104    function __getOrderedListOfPagesForID($ID, $start=null)
105	{
106		global $conf;
107		require_once(dirname(__FILE__)."/inc/functions.php");
108		$functions = new siteexport_functions(false);
109
110        $sites = $values = array();
111        $page = null;
112		search($sites, $conf['datadir'], 'search_allpages', array(), $functions->getNamespaceFromID($ID, $page));
113        foreach( $sites as $site ) {
114
115        	if ( $ID == $site['id'] ) {
116        	    continue;
117        	}
118        	$sortIdentifier = intval(p_get_metadata($site['id'], 'mergecompare'));
119            array_push($values, array(':' . $site['id'], $functions->getSiteTitle($site['id']), $sortIdentifier));
120        }
121
122        if ( $start != null ) {
123
124        	// filter using the newerThanPage indicator
125            $sortIdentifier = intval(p_get_metadata($start, 'mergecompare'));
126	        $values = array_filter($values, array(new helper_plugin_siteexport_page_remove($sortIdentifier), '_page_remove'));
127        }
128
129        usort($values, array($this, '_page_sort'));
130
131        return $values;
132	}
133
134    function __getOrderedListOfPagesForStartEnd($ID, $start, $end)
135	{
136    	$values = $this->__getOrderedListOfPagesForID($ID);
137
138       	// filter using the newerThanPage indicator
139        $values = array_filter($values, array(new helper_plugin_siteexport_page_remove(intval($start), intval($end)), '_page_remove'));
140
141        usort($values, array($this, '_page_sort'));
142        return $values;
143	}
144
145	function __siteexport_addpage() {
146
147        global $ID, $conf;
148
149	    $templateSwitching = false;
150	    $pdfExport = false;
151	    $usenumberedheading = false;
152	    $translation = null;
153	    $translationAvailable = false;
154	    $usenumberedheading = true;
155
156        $preload = plugin_load('preload', 'siteexport');
157        if ($preload && $preload->__create_preload_function()) {
158            $templateSwitching = true;
159        }
160
161        $dw2pdf = plugin_load('action', 'dw2pdf');
162        if ($dw2pdf) {
163            $pdfExport = true;
164        }
165
166        $translation = plugin_load('helper', 'translation');
167        if ($translation) {
168            $translationAvailable = true;
169        }
170
171        $regenerateScript = '';
172        print $this->locale_xhtml((defined('DOKU_SITEEXPORT_MANAGER') ? 'manager' : '') . 'intro');
173
174        $form = new Doku_Form('siteexport', null, 'post');
175        $form->startFieldset($this->getLang('startingNamespace'));
176
177        $form->addElement(form_makeTextField('ns', $ID, $this->getLang('ns') . ':', 'ns'));
178        $form->addElement(form_makeTag('br'));
179        $form->addElement(form_makeTextField('ens', $ID, $this->getLang('ens') . ':', 'ens'));
180
181        $form->addElement(form_makeTag('br'));
182        $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'))));
183
184        $form->addElement(form_makeTag('br'));
185        $form->addElement(form_makeOpenTag("div", array('style' => 'display:' . ($_REQUEST['depthType'] == "2" ? "block" : "none") . ';', 'id' => 'depthContainer')));
186        $form->addElement(form_makeTextField('depth', $this->getConf('depth'), $this->getLang('depth') . ':', 'depth'));
187        $form->addElement(form_makeCloseTag("div"));
188
189        $form->endFieldset();
190        $form->addElement(form_makeTag('br'));
191
192        $form->startFieldset($this->getLang('selectYourOptions'));
193        $form->addElement(form_makeCheckboxField('absolutePath', 1, $this->getLang('absolutePath') . ':', 'absolutePath'));
194        $form->addElement(form_makeTag('br'));
195        // The parameter needs lowercase
196        $form->addElement(form_makeCheckboxField('exportbody', 1, $this->getLang('exportBody') . ':', 'exportbody'));
197        $form->addElement(form_makeTag('br'));
198        $form->addElement(form_makeCheckboxField('exportLinkedPages', 1, $this->getLang('exportLinkedPages') . ':', 'exportLinkedPages', null, array('checked' => 'checked')));
199        $form->addElement(form_makeTag('br'));
200        $form->addElement(form_makeCheckboxField('disableCache', 1, $this->getLang('disableCache') . ':', 'disableCache'));
201        $form->addElement(form_makeTag('br'));
202        $form->addElement(form_makeCheckboxField('addParams', 1, $this->getLang('addParams') . ':', 'addParams', null, array_merge(array('checked' => ($conf['userewrite'] != 1 ? 'checked' : '')))));
203        $form->addElement(form_makeTag('br'));
204        $form->addElement(form_makeTag('br'));
205        $form->addElement(form_makeListboxField('renderer', array_merge(array('', 'xhtml'), plugin_list('renderer')), '', $this->getLang('renderer') . ':', 'renderer', null, array_merge(array('class' => 'edit'))));
206
207        $form->addElement(form_makeTag('br'));
208        if ($templateSwitching) {
209            $form->addElement(form_makeListboxField('template', $this->__getTemplates(), $conf['template'], $this->getLang('template') . ':', 'template', null, array_merge(array('class' => 'edit'))));
210            $form->addElement(form_makeTag('br'));
211        } else
212        {
213            $form->addElement(form_makeTag('br'));
214            $form->addElement(form_makeOpenTag('p', array('style' => 'color: #a00;')));
215            $form->addElement('Can\'t create preload file in \'inc\' directory. Template switching is not available. Plugin disabling is not available.');
216            $form->addElement(form_makeCloseTag('p'));
217        }
218
219        $form->addElement(form_makeTag('br'));
220        $form->addElement(form_makeCheckboxField('pdfExport', 1, $this->getLang('pdfExport') . ':', 'pdfExport', null, $pdfExport ? array() : array_merge(array('disabled' => 'disabled'))));
221        if (!$pdfExport) {
222            $form->addElement(form_makeOpenTag('p', array('style' => 'color: #a00;')));
223            $form->addElement('In order to use the PDF export, please ');
224            $form->addElement(form_makeOpenTag('a', array('href' => 'http://www.dokuwiki.org/plugin:dw2pdf', 'alt' => 'install plugin', 'target' => '_blank')));
225            $form->addElement('install the dw2pdf plugin.');
226            $form->addElement(form_makeCloseTag('a'));
227            $form->addElement(form_makeCloseTag('p'));
228        }
229
230        $form->addElement(form_makeTag('br'));
231        $form->addElement(form_makeCheckboxField('usenumberedheading', 1, $this->getLang('usenumberedheading') . ':', 'usenumberedheading', null, $usenumberedheading && $pdfExport ? array() : array_merge(array('disabled' => 'disabled'))));
232        $form->addElement(form_makeTag('br'));
233
234        if (!$usenumberedheading) {
235            $form->addElement(form_makeOpenTag('p', array('style' => 'color: #a00;')));
236            $form->addElement('In order to use numbered headings, please ');
237            $form->addElement(form_makeOpenTag('a', array('href' => 'http://www.dokuwiki.org/plugin:nodetailsxhtml', 'alt' => 'install plugin', 'target' => '_blank')));
238            $form->addElement('install the nodetailsxhtml plugin.');
239            $form->addElement(form_makeCloseTag('a'));
240            $form->addElement(form_makeCloseTag('p'));
241        }
242
243        $form->endFieldset();
244        $form->addElement(form_makeTag('br'));
245
246        $form->startFieldset($this->getLang('helpCreationOptions'));
247        $form->addElement(form_makeCheckboxField('eclipseDocZip', 1, $this->getLang('eclipseDocZip') . ':', 'eclipseDocZip'));
248        $form->addElement(form_makeTag('br'));
249        $form->addElement(form_makeCheckboxField('JavaHelpDocZip', 1, $this->getLang('JavaHelpDocZip') . ':', 'JavaHelpDocZip'));
250        $form->addElement(form_makeTag('br'));
251        $form->addElement(form_makeCheckboxField('useTocFile', 1, $this->getLang('useTocFile') . ':', 'useTocFile'));
252        $form->addElement(form_makeTag('br'));
253        $form->addElement(form_makeCheckboxField('emptyTocElem', 1, $this->getLang('emptyTocElem') . ':', 'emptyTocElem'));
254        $form->addElement(form_makeTag('br'));
255        if (!$translationAvailable) {
256            $form->addElement(form_makeCheckboxField('TOCMapWithoutTranslation', 1, $this->getLang('TOCMapWithoutTranslation') . ':', 'TOCMapWithoutTranslation'));
257            $form->addElement(form_makeTag('br'));
258        } else {
259
260            if (!is_array($trans)) {
261                $trans = array($trans);
262            }
263
264            $trans = array_unique(array_merge($trans, array($conf['lang'])));
265            $form->addElement(form_makeListboxField('defaultLang', $trans, $conf['lang'], $this->getLang('defaultLang') . ':', 'defaultLang'));
266            $form->addElement(form_makeTag('br'));
267        }
268        $form->endFieldset();
269        $form->addElement(form_makeTag('br'));
270
271        if ($templateSwitching)
272        {
273            $form->startFieldset($this->getLang('disablePluginsOption'));
274
275            $form->addElement(form_makeCheckboxField("disableall", 1, 'Disable All:', "disableall", 'forceVisible'));
276            $form->addElement(form_makeTag('br'));
277            $form->addElement(form_makeTag('br'));
278
279            list($allPlugins, $enabledPlugins) = $this->__getPluginList();
280            foreach ($allPlugins as $plugin) {
281                $form->addElement(form_makeCheckboxField("disableplugin[]", $plugin, $plugin . ':', "disableplugin_$plugin", null, (!in_array($plugin, $enabledPlugins) ? array('checked' => 'checked', 'disabled' => 'disabled') : array())));
282                $form->addElement(form_makeTag('br'));
283            }
284
285            $form->endFieldset();
286            $form->addElement(form_makeTag('br'));
287        }
288
289        $form->startFieldset( $this->getLang('customOptions') );
290        $form->addElement(form_makeOpenTag('p'));
291        $form->addElement( $this->getLang('customOptionsDescription') );
292        $form->addElement(form_makeCloseTag('p'));
293
294        $form->addElement(form_makeOpenTag('ul', array('id' => 'siteexport__customActions')));
295        $form->addElement(form_makeCloseTag('ul'));
296        $form->addElement(form_makeTag('br', array('class'=>'clear')));
297        $form->addElement(form_makeButton('submit', 'addoption', $this->getLang('addCustomOption') , array('style' => 'float:right;') ));
298
299        $form->endFieldset();
300        $form->addElement(form_makeTag('br'));
301
302        if ( !defined('DOKU_SITEEXPORT_MANAGER') ) {
303
304
305            $form->startFieldset( $this->getLang('startProcess') );
306            $form->addElement(form_makeTextField('copyurl', "", $this->getLang('directDownloadLink') . ':', 'copyurl', null, array('readonly' => 'readonly') ));
307            $form->addElement(form_makeTag('br'));
308            $form->addElement(form_makeTextField('wgeturl', "", $this->getLang('wgetURLLink') . ':', 'wgeturl', null, array('readonly' => 'readonly') ));
309            $form->addElement(form_makeTag('br'));
310            $form->addElement(form_makeTextField('curlurl', "", $this->getLang('curlURLLink') . ':', 'curlurl', null, array('readonly' => 'readonly') ));
311            $form->addElement(form_makeTag('br', array('class'=>'clear')));
312            $form->addElement(form_makeButton('submit', 'siteexport', $this->getLang('start') , array('style' => 'float:right;')));
313            $form->endFieldset();
314            $form->addElement(form_makeTag('br'));
315
316            $form->endFieldset();
317            $form->addElement(form_makeTag('br'));
318
319            $form->startFieldset( $this->getLang('status') );
320            $form->addElement(form_makeOpenTag('span', array('id' => 'siteexport__out')));
321
322            $form->addElement(form_makeCloseTag('span'));
323            $form->addElement(form_makeOpenTag('span', array('class' => 'siteexport__throbber')));
324            $form->addElement(form_makeTag('img', array('src' => DOKU_BASE.'lib/images/loading.gif', 'id' => 'siteexport__throbber')));
325            $form->addElement(form_makeCloseTag('span'));
326            $form->endFieldset();
327            $form->addElement(form_makeTag('br'));
328
329        } else {
330            $form->startFieldset( $this->getLang('startProcess') );
331            $form->addElement(form_makeButton('submit', 'siteexport', $this->getLang('useOptionsInEditor') , array('style' => 'width:100%;')));
332        }
333
334        $form->endFieldset();
335        $form->addElement(form_makeTag('br'));
336
337        $form->printForm();
338    }
339}
340