-
Notifications
You must be signed in to change notification settings - Fork 9
/
syntax.php
136 lines (110 loc) · 4.01 KB
/
syntax.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
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_epub extends DokuWiki_Syntax_Plugin {
protected $title;
private $helper;
function getInfo() {
return array(
'author' => 'Myron Turner',
'email' => '[email protected]',
'date' => '2011-07-1',
'name' => 'epub',
'desc' => 'ebook creator',
'url' => 'http://www.dokuwiki.org/plugin:epub');
}
function getType(){ return 'container'; }
function getPType(){ return 'block'; }
function getAllowedTypes() {
return array();
}
function getSort(){ return 25; }
function connectTo($mode) {
$this->Lexer->addEntryPattern('<epub.*?>(?=.*?</epub>)',$mode,'plugin_epub');
}
function postConnect() {
$this->Lexer->addExitPattern('</epub>','plugin_epub');
}
function __construct() {
$this->helper =& plugin_load('helper', 'epub');
}
function handle($match, $state, $pos, Doku_Handler $handler) {
$match = str_replace(';',';',$match);
$match = str_replace(',',',',$match);
switch ($state) {
case DOKU_LEXER_ENTER :
$title = substr($match, 6, -1);
if($title)
$this->title = $title;
else
$this->title="Dokuwiki EBook";
return array($state, trim($title));
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
case DOKU_LEXER_EXIT :
return array($state,$match);
default:
return array($state,$match);
}
}
function render($mode, Doku_Renderer $renderer, $data) {
global $INFO;
if($mode == 'xhtml'){
$renderer->nocache();
list($state, $match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER :
$this->helper->writeCache($INFO['id']);
$renderer->doc .= '<div>';
break;
case DOKU_LEXER_UNMATCHED :
$id = $INFO['id'];
$renderer->doc .= "\n<SCRIPT type='text/javascript'>\n//<![CDATA[\n" ;
$renderer->doc .= "\nvar book_id = '$id';";
$renderer->doc .= "\nvar epub_wikilink = new Array();\nvar epub_id = new Array();\n";
$files = explode("\n",$match);
for($i=0;$i<count($files);$i++) {
$file = trim($files[$i],'][');
list($file,$rest) = explode('|',$file);
$file=trim($file);
$file=trim($file,'/');
if(!$file) continue;
if(!auth_quickaclcheck($file)) {
continue;
}
$renderer->doc .= "epub_id[$i]='" . str_replace('/',':',$file) . "';\n" ;
$rest = trim($rest," ][");
if(!$rest) {
$ar = explode(':',$file);
$n = count($ar) -1;
$rest = $ar[$n];
}
$rest=hsc($rest);
$rest = str_replace(':',':',$rest);
$renderer->doc .= "epub_wikilink[$i]='" . str_replace('/',':',$rest) . "';\n" ;
}
$renderer->doc .= 'epub_title="' . $this->title . '";';
$renderer->doc .= "\n// ]]>\n</SCRIPT>\n";
break;
case DOKU_LEXER_EXIT :
$throbber = DOKU_BASE . 'lib/plugins/epub/throbber.gif';
$renderer->doc .= '<div id="epub_throbber" style="display:none;"><center><img src="' . $throbber .'"></center><br /><span id="epub_progress">progress</span></div>';
$renderer->doc .= "\n</div>";
break;
}
return true;
}
// unsupported $mode
return false;
}
function write_debug($what) {
return;
if(is_array($what)) $what = print_r($what,true);
$handle = fopen('epub.txt', 'a');
fwrite($handle,"$what\n");
fclose($handle);
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>