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