Skip to content

Commit 990a6dd

Browse files
committed
update action components with content of action.php
1 parent 1f22dbd commit 990a6dd

File tree

2 files changed

+65
-187
lines changed

2 files changed

+65
-187
lines changed

action/cache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* ODT Plugin: Exports to ODT
3+
* ODT Plugin: extends the dependencies of the cache with ODT related files
44
*
55
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
66
* @author Aurelien Bompard <aurelien@bompard.org>
@@ -14,8 +14,8 @@
1414
*/
1515
class action_plugin_odt_cache extends DokuWiki_Action_Plugin {
1616

17-
/**
18-
* Registers a callback function for a given event
17+
/**
18+
* Register the event
1919
*
2020
* @param Doku_Event_Handler $controller
2121
*/

action/export.php

Lines changed: 62 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,12 @@
1717
* Collect pages and export these. GUI is available via bookcreator.
1818
*/
1919
class action_plugin_odt_export extends DokuWiki_Action_Plugin {
20+
2021
/**
21-
* Settings for current export, collected from url param, plugin config, global config
22-
*
2322
* @var array
2423
*/
25-
protected $exportConfig = null;
26-
protected $tpl;
2724
protected $list = array();
2825

29-
/**
30-
* Constructor. Sets the correct template
31-
*/
32-
public function __construct() {
33-
$this->tpl = $this->getExportConfig('template');
34-
}
35-
3626
/**
3727
* Register the events
3828
*
@@ -43,19 +33,54 @@ public function register(Doku_Event_Handler $controller) {
4333
$controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'addbutton', array());
4434
}
4535

36+
/**
37+
* Add 'export odt'-button to pagetools
38+
*
39+
* @param Doku_Event $event
40+
*/
41+
public function addbutton(Doku_Event $event) {
42+
global $ID, $REV;
43+
44+
if($this->getConf('showexportbutton') && $event->data['view'] == 'main') {
45+
$params = array('do' => 'export_odt');
46+
if($REV) {
47+
$params['rev'] = $REV;
48+
}
49+
50+
// insert button at position before last (up to top)
51+
$event->data['items'] = array_slice($event->data['items'], 0, -1, true) +
52+
array('export_odt' =>
53+
'<li>'
54+
. '<a href="' . wl($ID, $params) . '" class="action export_odt" rel="nofollow" title="' . $this->getLang('export_odt_button') . '">'
55+
. '<span>' . $this->getLang('export_odt_button') . '</span>'
56+
. '</a>'
57+
. '</li>'
58+
) +
59+
array_slice($event->data['items'], -1, 1, true);
60+
}
61+
}
62+
63+
/***********************************************************************************
64+
* Book export *
65+
***********************************************************************************/
66+
4667
/**
4768
* Do article(s) to ODT conversion work
4869
*
4970
* @param Doku_Event $event
50-
* @param array $param
5171
* @return bool
5272
*/
53-
public function convert(Doku_Event $event, $param) {
73+
public function convert(Doku_Event $event) {
5474
global $ACT;
5575
global $ID;
5676

57-
// our event?
58-
if(($ACT != 'export_odtbook') && ($ACT != 'export_odt') && ($ACT != 'export_odtns')) return false;
77+
// single page export: rename to the actual renderer component
78+
if($ACT == 'export_odt') {
79+
$ACT = 'export_odt_page';
80+
}
81+
82+
// the book export?
83+
if(($ACT != 'export_odtbook') && ($ACT != 'export_odtns')) return false;
5984

6085
// check user's rights
6186
if(auth_quickaclcheck($ID) < AUTH_READ) return false;
@@ -194,14 +219,16 @@ private function showPageWithErrorMsg(Doku_Event $event, $msglangkey) {
194219
*/
195220
protected function prepareCache($title, &$depends) {
196221
global $REV;
222+
global $INPUT;
223+
224+
//different caches for varying config settings
225+
$template = $this->getConf("tpl_default");
226+
$template = $INPUT->get->str('odt-template', $template, true);
227+
197228

198229
$cachekey = join(',', $this->list)
199230
. $REV
200-
. $this->getExportConfig('template')
201-
. $this->getExportConfig('pagesize')
202-
. $this->getExportConfig('orientation')
203-
// . $this->getExportConfig('doublesided')
204-
// . ($this->getExportConfig('hasToC') ? join('-', $this->getExportConfig('levels')) : '0')
231+
. $template
205232
. $title;
206233
$cache = new cache($cachekey, '.odt');
207234

@@ -232,8 +259,9 @@ protected function prepareCache($title, &$depends) {
232259

233260
$depends['files'] = array_map('wikiFN', $this->list);
234261
$depends['files'][] = __FILE__;
235-
$depends['files'][] = dirname(__FILE__) . '/../renderer.php';
236-
// $depends['files'][] = dirname(__FILE__) . '/../mpdf/mpdf.php';
262+
$depends['files'][] = dirname(__FILE__) . '/renderer/page.php';
263+
$depends['files'][] = dirname(__FILE__) . '/renderer/book.php';
264+
$depends['files'][] = dirname(__FILE__) . '/plugin.info.txt';
237265
$depends['files'] = array_merge(
238266
$depends['files'],
239267
$dependencies,
@@ -251,59 +279,34 @@ protected function prepareCache($title, &$depends) {
251279
protected function generateODT($cachefile, $title) {
252280
global $ID;
253281
global $REV;
254-
global $INPUT;
255-
256-
//some shortcuts to export settings
257-
// $hasToC = $this->getExportConfig('hasToC');
258-
$levels = $this->getExportConfig('levels');
259-
$isDebug = $this->getExportConfig('isDebug');
260-
//etc etc
261-
262282

283+
/** @var renderer_plugin_odt_book $odt */
284+
$odt = plugin_load('renderer','odt_book');
263285

264286
// store original pageid
265287
$keep = $ID;
266288

267289
// loop over all pages
290+
$xmlcontent = '';
291+
268292
$cnt = count($this->list);
269293
for($n = 0; $n < $cnt; $n++) {
270294
$page = $this->list[$n];
271295

272296
// set global pageid to the rendered page
273297
$ID = $page;
274-
275-
$pagecontent = p_cached_output(wikiFN($page, $REV), 'odt', $page);
276-
if($n < ($cnt - 1)) {
277-
// $pagecontent .= '<pagebreak />';
278-
}
279-
280-
// Store/Buffer page ..
281-
298+
$xmlcontent .= p_render('odt_book', p_cached_instructions(wikiFN($page, $REV),false,$page), $info);
282299
}
300+
283301
//restore ID
284302
$ID = $keep;
285303

286-
// insert the back page
287-
// $body_end = $template['back'];
288-
289-
// $body_end .= '</div>';
290-
291-
// finish body html
292-
//....
293-
294-
//Return html for debugging
295-
if($isDebug) {
296-
if($INPUT->str('debughtml', 'text', true) == 'html') {
297-
echo $html;
298-
} else {
299-
header('Content-Type: text/plain; charset=utf-8');
300-
echo $html;
301-
}
302-
exit();
303-
};
304+
$odt->doc = $xmlcontent;
305+
$odt->setTitle($title);
306+
$odt->finalize_ODTfile();
304307

305308
// write to cache file
306-
//$cachefile = ...;
309+
io_savefile($cachefile, $odt->doc);
307310
}
308311

309312
/**
@@ -318,9 +321,9 @@ protected function sendODTFile($cachefile, $title) {
318321

319322
$filename = rawurlencode(cleanID(strtr($title, ':/;"', ' ')));
320323
if($this->getConf('output') == 'file') {
321-
header('Content-Disposition: attachment; filename="' . $filename . '.pdf";');
324+
header('Content-Disposition: attachment; filename="' . $filename . '.odt";');
322325
} else {
323-
header('Content-Disposition: inline; filename="' . $filename . '.pdf";');
326+
header('Content-Disposition: inline; filename="' . $filename . '.odt";');
324327
}
325328

326329
//try to send file, and exit if done
@@ -370,129 +373,4 @@ public function _pagenamesort($a, $b) {
370373
if($a['id'] > $b['id']) return 1;
371374
return 0;
372375
}
373-
374-
/**
375-
* Return settings read from:
376-
* 1. url parameters
377-
* 2. plugin config
378-
* 3. global config
379-
*
380-
* @return array
381-
*/
382-
protected function loadExportConfig() {
383-
global $INPUT;
384-
global $conf;
385-
386-
$this->exportConfig = array();
387-
388-
// decide on the paper setup from param or config
389-
$this->exportConfig['pagesize'] = $INPUT->str('pagesize', $this->getConf('pagesize'), true);
390-
$this->exportConfig['orientation'] = $INPUT->str('orientation', $this->getConf('orientation'), true);
391-
392-
$doublesided = $INPUT->bool('doublesided', (bool) $this->getConf('doublesided'));
393-
$this->exportConfig['doublesided'] = $doublesided ? '1' : '0';
394-
395-
// $hasToC = $INPUT->bool('toc', (bool) $this->getConf('toc'));
396-
// $levels = array();
397-
// if($hasToC) {
398-
// $toclevels = $INPUT->str('toclevels', $this->getConf('toclevels'), true);
399-
// list($top_input, $max_input) = explode('-', $toclevels, 2);
400-
// list($top_conf, $max_conf) = explode('-', $this->getConf('toclevels'), 2);
401-
// $bounds_input = array(
402-
// 'top' => array(
403-
// (int) $top_input,
404-
// (int) $top_conf
405-
// ),
406-
// 'max' => array(
407-
// (int) $max_input,
408-
// (int) $max_conf
409-
// )
410-
// );
411-
// $bounds = array(
412-
// 'top' => $conf['toptoclevel'],
413-
// 'max' => $conf['maxtoclevel']
414-
//
415-
// );
416-
// foreach($bounds_input as $bound => $values) {
417-
// foreach($values as $value) {
418-
// if($value > 0 && $value <= 5) {
419-
// //stop at valid value and store
420-
// $bounds[$bound] = $value;
421-
// break;
422-
// }
423-
// }
424-
// }
425-
//
426-
// if($bounds['max'] < $bounds['top']) {
427-
// $bounds['max'] = $bounds['top'];
428-
// }
429-
//
430-
// for($level = $bounds['top']; $level <= $bounds['max']; $level++) {
431-
// $levels["H$level"] = $level - 1;
432-
// }
433-
// }
434-
// $this->exportConfig['hasToC'] = $hasToC;
435-
// $this->exportConfig['levels'] = $levels;
436-
437-
$this->exportConfig['maxbookmarks'] = $INPUT->int('maxbookmarks', $this->getConf('maxbookmarks'), true);
438-
439-
$tplconf = $this->getConf('template');
440-
$tpl = $INPUT->str('tpl', $tplconf, true);
441-
if(!is_dir(DOKU_PLUGIN . 'dw2pdf/tpl/' . $tpl)) {
442-
$tpl = $tplconf;
443-
}
444-
if(!$tpl){
445-
$tpl = 'default';
446-
}
447-
$this->exportConfig['template'] = $tpl;
448-
449-
$this->exportConfig['isDebug'] = $conf['allowdebug'] && $INPUT->has('debughtml');
450-
}
451-
452-
/**
453-
* Returns requested config
454-
*
455-
* @param string $name
456-
* @param mixed $notset
457-
* @return mixed|bool
458-
*/
459-
public function getExportConfig($name, $notset = false) {
460-
if ($this->exportConfig === null){
461-
$this->loadExportConfig();
462-
}
463-
464-
if(isset($this->exportConfig[$name])){
465-
return $this->exportConfig[$name];
466-
}else{
467-
return $notset;
468-
}
469-
}
470-
471-
/**
472-
* Add 'export odt'-button to pagetools
473-
*
474-
* @param Doku_Event $event
475-
* @param mixed $param not defined
476-
*/
477-
public function addbutton(Doku_Event $event, $param) {
478-
global $ID, $REV;
479-
480-
if($this->getConf('showexportbutton') && $event->data['view'] == 'main') {
481-
$params = array('do' => 'export_odt');
482-
if($REV) {
483-
$params['rev'] = $REV;
484-
}
485-
486-
// insert button at position before last (up to top)
487-
$event->data['items'] = array_slice($event->data['items'], 0, -1, true) +
488-
array('export_odt' =>
489-
'<li>'
490-
. '<a href="' . wl($ID, $params) . '" class="action export_odt" rel="nofollow" title="' . $this->getLang('export_odt_button') . '">'
491-
. '<span>' . $this->getLang('export_odt_button') . '</span>'
492-
. '</a>'
493-
. '</li>'
494-
) +
495-
array_slice($event->data['items'], -1, 1, true);
496-
}
497-
}
498376
}

0 commit comments

Comments
 (0)