This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.php
330 lines (283 loc) · 10.8 KB
/
helper.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php
/**
* dokubookmark plugin helper functions
* Dokuwiki website tagger - act like a weblog
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Robin Gareus <[email protected]>
* @based_on http://wiki.splitbrain.org/wiki:tips:weblog_bookmarklet by riny [at] bk [dot] ru
*/
/**
* - TODO this should use the dokuwiki template header.
*/
function printHeader() {
global $conf;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>Dokuwiki Website Tagger</title>
<?php tpl_metaheaders()?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="<?php echo DOKU_TPL?>images/favicon.ico" />
<script type="text/javascript">
/* <![CDATA[ */
function initTagEntry() {
document.getElementById('blogtng__tags').value = 'Bookmark, ';
}
/* ]]> */
</script>
</head>
<body>
<script type="text/javascript">
/* <![CDATA[ */
window.onload=initTagEntry;
/* ]]> */
</script>
<div class="dokuwiki" style="background: #fff; border:0px; color: #000">
<?php
}
/**
*
*/
function printFooter() { ?>
</div> <!-- class="dokuwiki" -->
</body>
</html>
<?php
}
function escapeJSstring ($o) {
return ( # TODO: use JSON ?!
str_replace("\n", '\\n',
str_replace("\r", '',
str_replace('\'', '\\\'',
str_replace('\\', '\\\\',
$o)))));
}
function parseWikiIdTemplate($idx, $data) {
if (empty($data['name'])) {
$n='';
# check for single word selection -> use this
if (!strstr($data['selection'], ' '))
$n=$data['selection'];
# check if title is a not empty
if (empty($n))
$n=$data['title'];
# if still empty.. mmh - use URL or use 'noname'
if (empty($n)) $n='noname';
#-> replace ': ' and ASCIIfy
$n=strtr($n, ': ','__');
# [^\x20-\x7E] or [^A-Za-z_0-9]
$n=preg_replace('@[^A-Za-z_0-9]@', '', $n);
$n=preg_replace('@__*@', '_', $n);
# trim to 64 chars.
$data['name']=substr($n,0,64);
}
# TODO: replace Placeholders alike ../../../inc/common.php pageTemplate() ?!
return str_replace("@D@",$data['timestamp'],
str_replace("@S@",$data['selection'],
str_replace("@U@",$data['url'],
str_replace("@N@",$data['name'],
str_replace("@F@",$data['foo'],
str_replace("@T@",$data['title'], $idx))))));
}
/**
*
*/
function printForm ($data, $options, $alltags = NULL) {
global $ID;
global $REV;
global $DATE;
global $PRE;
global $SUF;
global $INFO;
global $SUM;
global $lang;
global $conf;
global $TEXT;
global $RANGE;
$SUM = htmlentities($data['title'], ENT_COMPAT, 'UTF-8');
echo '<h3>Dokuwiki - add bookmark / weblog entry</h3>';
if (isset($_REQUEST['changecheck'])) {
$check = $_REQUEST['changecheck'];
} elseif(!$INFO['exists']){
// $TEXT has been loaded from page template
$check = md5('');
} else {
$check = md5($TEXT);
}
$mod = md5($TEXT) !== $check;
$wr = $INFO['writable'] && !$INFO['locked'];
$include = 'edit';
if($wr){
if ($REV) $include = 'editrev';
}else{
// check pseudo action 'source'
if(!actionOK('source')){
msg('Command disabled: source',-1);
return;
}
$include = 'read';
}
global $license;
$wikitext = parseWikiIdTemplate($data['wikitpl'], $data);
$id = parseWikiIdTemplate($data['wikiidtpl'], $data);
$TEXT = $wikitext;
$ID = $id;
$form = new Doku_Form(array('id' => 'dw__editform', 'action' => $data['baseurl']));
$form->addHidden('rev', $REV);
$form->addHidden('date', $DATE);
$form->addHidden('prefix', $PRE . '.');
$form->addHidden('suffix', $SUF);
$form->addHidden('changecheck', $check);
$dataNew = array('form' => $form,
'wr' => $wr,
'media_manager' => true,
'target' => (isset($_REQUEST['target']) && $wr &&
$RANGE !== '') ? $_REQUEST['target'] : 'section',
'intro_locale' => $include);
$data = array_merge($data, $dataNew);
$form->addElement(form_makeOpenTag('p'));
$form->addElement(form_makeTextField('id', htmlentities(parseWikiIdTemplate($data['wikiidtpl'], $data), ENT_COMPAT, 'UTF-8'), 'Id:', 'i_id'));
if ($options['preset']) {
$form->addElement('<br/> Preset:');
$i=0;
foreach ($options['presets'] as $n => $ps) {
$id_ = parseWikiIdTemplate($ps['id'], $data);
$wikitext_ = parseWikiIdTemplate($ps['tpl'], $data);
if ($i>0)
$form->addElement(',');
else
$form->addElement(' ');
$form->addElement(' ');
$additionalJs = '';
if (!empty($wikitext_)) {
$additionalJs = 'document.getElementById(\'wiki__text\').value=\''.escapeJSstring($wikitext_).'\';';
}
$form->addElement(form_makeTag('input', array(
'type' => 'button',
'value' => $n,
'class' => 'button',
'title' => $n,
'onclick' => 'document.getElementById(\'i_id\').value=\''.escapeJSstring($id_).'\';document.getElementById(\'id\').value=\''.escapeJSstring($id_).'\';'.$additionalJs
)));
$i++;
}
} ### done Preset Buttons
$form->addElement(form_makeCloseTag('p'));
if ($data['target'] !== 'section') {
// Only emit event if page is writable, section edit data is valid and
// edit target is not section.
trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
} else {
html_edit_form($data);
}
//if (isset($data['intro_locale'])) {
// echo p_locale_xhtml($data['intro_locale']);
//}
$form->addHidden('target', $data['target']);
$form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
$form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
$form->addElement(form_makeCloseTag('div'));
if ($wr) {
$form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
if ($options['enable_save']) {
$form->addHidden('sectoc', getSecurityToken());
// $form->addElement(form_makeTag('button', array(
// 'id' => 'edbtn__save',
// 'type' => 'submit',
// 'name' => 'do[dokubookmark]',
// 'value' => $lang['btn_save'],
// 'class' => 'button',
// 'title' => $lang['btn_save'] . ' [S]',
// 'accesskey' => 's',
// 'tabindex' => '4'
// )));
// Fixed save button on bootstrap3 template
$form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'p', 'tabindex'=>'5')));
}
$form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
$form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex' => '6', 'onclick' => 'window.close()')));
$form->addElement(form_makeCloseTag('div'));
$form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
$form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
$elem = html_minoredit();
if ($elem) $form->addElement($elem);
$form->addElement(form_makeCloseTag('div'));
}
$form->addElement(form_makeCloseTag('div'));
if($wr && $conf['license']){
$form->addElement(form_makeOpenTag('div', array('class'=>'license')));
$out = $lang['licenseok'];
$out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
$out .= '>'.$license[$conf['license']]['name'].'</a>';
$form->addElement($out);
$form->addElement(form_makeCloseTag('div'));
}
if ($wr) {
// sets changed to true when previewed
echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
echo 'textChanged = ' . ($mod ? 'true' : 'false');
echo '//--><!]]></script>' . NL;
} ?>
<div style="width:99%;">
<div class="toolbar">
<div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
<div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
</div>
<?php
html_form('edit', $form);
print '</div>'.NL;
}
/**
* - unused javascript redirect/POST -
*
* - could be made into a non-interactive bookmarklet -
*/
function printPost($targeturl, $path, $wikiid, $timestamp, $title, $wikitext) {
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<script type="text/javascript">
/* <![CDATA[ */
function postit() {
f = document.createElement('form');
f.method = 'post';
f.action = '<?php echo $targeturl;?>';
i0 = document.createElement('input');
i0.type = 'hidden';
i0.name = 'wikitext';
i0.value = '<?php echo implode('\n', explode("\n",str_replace("'","\\'",$wikitext)));?>';
i1 = document.createElement('input');
i1.type = 'hidden';
i1.name = 'do';
i1.value = 'preview';
i3 = document.createElement('input');
i3.type = 'hidden';
i3.name = 'summary';
i3.value = '<?php echo str_replace("'","\\'",rawurlencode($title));?>';
i4 = document.createElement('input');
i4.type = 'hidden';
i4.name = 'sectok';
i4.value = '<?php echo getSecurityToken();?>';
f.appendChild(i0);
f.appendChild(i1);
f.appendChild(i3);
f.appendChild(i4);
b = document.getElementsByTagName('body')[0];
b.appendChild(f);
f.submit();
}
/* ]]> */
</script>
<body onload="postit();">
</body>
</html>
<?php
}
//Setup VIM: ex: et ts=2 :