-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaction.php
148 lines (120 loc) · 4.87 KB
/
action.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
<?php
/**
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_epub extends DokuWiki_Action_Plugin {
private $helper;
/**
* Register callbacks
*/
function register(Doku_Event_Handler $controller) {
$controller->register_hook( 'TPL_METAHEADER_OUTPUT', 'AFTER', $this, 'loadScript');
$controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'create_ebook_button');
$controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'get_epub');
$controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'check_scriptLoaded');
$controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'prevent_cache');
}
/**
*/
function create_ebook_button($event,$param) {
global $INFO;
global $ACT;
if(!$this->getConf('permalink')) return;
if($ACT != 'show') return;
if(!$this->helper) {
$this->helper = $this->loadHelper('epub', true);
}
if (!$this->helper->is_inCache($INFO['id'])) return;
$auth = auth_quickaclcheck($INFO['id']);
if($auth) {
$page_data = $this->helper->get_page_data($INFO['id']);
if(!$page_data) return;
$ebook = $page_data['epub'];
$link = ml($ebook);
$title = $page_data['title'];
echo $this->getLang('download'); //The most recent ebook for this page is:
echo " <a href='$link' title='$title'>$title ($ebook)</a>.<br />";
echo $this->getLang('download_click'); // To download it, click on the link.
echo $this->getLang('download_alt'); // If you have an ebook reader plugin installed, right-click on the link and select 'Save . . . As'.";
}
}
function get_epub($event, $param) {
global $ID;
global $USERINFO;
if(!isset($USERINFO)) return;
$user = $USERINFO['name'];
global $ACT;
global $INFO;
if($ACT != 'show') return;
if(!$this->helper) {
$this->helper = $this->loadHelper('epub', true);
}
if (!$this->helper->is_inCache($INFO['id'])) return; //cache set in syntax.php
if(strpos($INFO['id'],'epub') === false) return;
$wiki_file = wikiFN($INFO['id']);
if(!@file_exists($wiki_file)) return;
$epub_group = $this->getConf('group');
$groups=$USERINFO['grps'];
$auth = auth_quickaclcheck('epub:*');
if($auth < 8 && !in_array($epub_group,$groups)) return;
$auth = auth_quickaclcheck($INFO['id']);
if($auth < 4) return;
$client=$INFO['client'];
$button_name = $this->getLang('button_start'); //"Start"; //$this->getLang('btn_generate');
$button="<form class='button'>";
$button .= "<div class='no' id='show_throbberbutton'><input type='button' value='$button_name' class='button' title='start' onclick=\"_epub_show_throbber('$user','$client');\"/>";
$button .=" ";
$button .= $this->getLang('label_start'); //"Click the Start Button to Create your eBook";
$button .="</div></form>";
echo $button;
$id = $INFO['id'];
$button_name = $this->getLang('button_remove');
$button="<p><form class='button'>";
$button .= "<div class='no' id='epub_remove_button'><input type='button' value='$button_name' class='button' title='start' onclick=\"epub_remove_creator('$id');\"/></div></form>";
$button .= '</br>'. $this->locale_xhtml('remove');
echo $button;
}
function prevent_cache(&$event) {
global $INFO;
if(!$this->helper) {
$this->helper = $this->loadHelper('epub', true);
}
if (!$this->helper->is_inCache($INFO['id'])) return; //cache set in syntax.php
$event->preventDefault();
}
function loadScript(&$event) {
echo <<<SCRIPT
<script type="text/javascript">
//<![CDATA[
function epub_LoadScript( url )
{
document.write( '<scr' + 'ipt type="text/javascript" src="' + url + '"><\/scr' + 'ipt>' ) ;
}
//]]>
</script>
SCRIPT;
}
function check_scriptLoaded(&$event) {
$url = DOKU_URL . 'lib/plugins/epub/script.js';
echo <<<SCRIPT
<script type="text/javascript">
//<![CDATA[
if(!window._epub_show_throbber){
epub_LoadScript("$url");
}
//]]>
</script>
SCRIPT;
}
function write_debug($what) {
return;
$what = print_r($what,true);
$handle = fopen('epub-action.txt', 'a');
fwrite($handle,"$what\n");
fclose($handle);
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :