-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
493 lines (417 loc) · 18.3 KB
/
index.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?php
error_reporting(0);
//error_reporting(E_ALL); //debug
$is_submit = false;
$revID = "0.1.8";
$revDate = '2010-02-07 15:00';
function aD(){
echo "<pre>".$htmloutput."</pre>";die;
}
function writeLog($message){
if ($message){
echo '<p><strong style="color: red;">'.$message.'</strong></p>';
} else {
echo '<!-- writeLog message undefined-->';
}
}
/*
* strip_attributes()
*
* @author http://phpfunda.blogspot.com/2007/08/function-strip-attributes.html
*
* @param $msg string - The text you want to strip attributes from.
* @param $tag string - The tag you want to strip attributes fom (p, for instancee).
* @param $attr string (optional) - An array with the name of the attributes you want to strip (leaving the rest intact).
* - If the array is empty, the function will strip all attributes.
* @param $suffix string (optional) - An optional text to append to the tag. It may be a new attribute, for instance.
*
*/
function strip_attributes($msg, $tag, $attr = false, $suffix = ""){
$lengthfirst = 0;
while (strstr(substr($msg, $lengthfirst), "<$tag ") != ""){
$tag_start = $lengthfirst + strpos(substr($msg, $lengthfirst), "<$tag ");
$partafterwith = substr($msg, $tag_start);
$img = substr($partafterwith, 0, strpos($partafterwith, ">") + 1);
$img = str_replace(" =", "=", $img);
$out = "<$tag";
for($i=0; $i < count($attr); $i++){
if (empty($attr[$i])) {
continue;
}
$long_val =
(strpos($img, " ", strpos($img, $attr[$i] . "=")) === FALSE) ?
strpos($img, ">", strpos($img, $attr[$i] . "=")) - (strpos($img, $attr[$i] . "=") + strlen($attr[$i]) + 1) :
strpos($img, " ", strpos($img, $attr[$i] . "=")) - (strpos($img, $attr[$i] . "=") + strlen($attr[$i]) + 1);
$val = substr($img, strpos($img, $attr[$i] . "=" ) + strlen($attr[$i]) + 1, $long_val);
if (!empty($val)){
$out .= " " . $attr[$i] . "=" . $val;
}
}
if (!empty($suffix)) {
$out .= " " . $suffix;
}
$out .= ">";
$partafter = substr($partafterwith, strpos($partafterwith,">") + 1);
$msg = substr($msg, 0, $tag_start). $out. $partafter;
$lengthfirst = $tag_start + 3;
}
return $msg;
}
// CHECK TO SEE IF THIS IS A SUBMIT
if (isset($_POST['htmlinput'])){
//
// CONFIG
//
// Building a whitelist array with keys which will send through the form, no others would be accepted later on
$whitelist = array('htmlinput', 'wikitable', 'cleaner', 'rmbreak', 'copy2clipboard');
// Building an array with the $_POST-superglobal
foreach ($_POST as $key=>$item){
// Check if the value $key (fieldname from $_POST) can be found in the whitelisting array,
// if not, die with a short message to the hacker
if (!in_array($key, $whitelist)){
writeLog('Unknown form fields');
die('Hack-Attempt detected. Please use only the fields in the form');
}
}
//
// INITIALISE
//
//Get input and trim whitespace around
$htmloutput = trim($_POST['htmlinput']);
// Multi space to space
$htmloutput = preg_replace('/\ +/',' ',$htmloutput);
// Eliminate any space in front of tags
$htmloutput = preg_replace('/\ +\</','<',$htmloutput);
// Convert all tags to lowercase
$htmloutput = preg_replace('/<(.+?)>/ies','strtolower("<\\1>")',$htmloutput);
//
// option :: cleaner
//
if ($_POST['cleaner'] == 'on'){
$cleaner = "on";
$htmloutput = strip_attributes($htmloutput, "table");
$htmloutput = strip_attributes($htmloutput, "th");
$htmloutput = strip_attributes($htmloutput, "td");
$htmloutput = strip_attributes($htmloutput, "tr");
} else {
$cleaner = "off";
}
//
// HTML2Wiki :: set variables
//
// Static replacements
$newTableHTMLfirstHead_ = '<table>\r\n <tr>';
$newTableHTMLfirstHead = '<table>\r\n<tr>';
$newTableHTML = '<table>'; $newTableWiki = '{|';
$newHeadHTML = '<th>'; $newHeadWiki = '! ';
$newCellHTML = '<td>'; $newCellWiki = '| ';
$newRowHTML_ = '\n<tr>'; $newRowWiki = '|-';
$newRowHTML = '<tr>'; $newRowWiki = '|-';
$closeTableHTML_ = '\r\n</table>'; $closeTableWiki = '|}';
$closeTableHTML = '</table>'; $closeTableWiki = '|}';
// To strip
$endTagTH = '</th>';
$endTagTD = '</td>';
$endTagTR = '</tr>';
$endTagLB = '\r\n\r\n';
//
// option :: wikitable
//
if ($_POST['wikitable'] == 'on'){
$wikitable = "on";
// Initialise wikitable
$newTableWiki = '{| class="wikitable"';
// strip style from heading
$htmloutput = strip_attributes($htmloutput, "th");
// convert grey-cells to heading
$colorCel_efefef = '<td style=\"background:#efefef;\">';
$htmloutput = str_replace($colorCel_efefef, $newHeadWiki, $htmloutput);
} else {
$wikitable = "off";
}
//
// optoin :: copy2clipboard
//
if ($_POST['copy2clipboard'] == 'on'){
$copy2clipboard = "on";
} else {
$copy2clipboard = "off";
}
//
// HTML2Wiki :: Convert attributes
//
$TDattrHTML = '/<th\ (.*?)\>/';
$TDattrWiki = '! \\1| ';
$htmloutput = preg_replace($TDattrHTML, $TDattrWiki, $htmloutput);
$TDattrHTML = '/<td\ (.*?)\>/';
$TDattrWiki = '| \\1| ';
$htmloutput = preg_replace($TDattrHTML, $TDattrWiki, $htmloutput);
$TDattrHTML = '/<tr\ (.*?)\>/';
$TDattrWiki = '|- \\1 ';
$htmloutput = preg_replace($TDattrHTML, $TDattrWiki, $htmloutput);
//
// HTML2Wiki :: Do it !
//
// Replacements
$htmloutput = str_replace($newTableHTMLfirstHead_, $newTableWiki, $htmloutput);
$htmloutput = str_replace($newTableHTMLfirstHead, $newTableWiki, $htmloutput);
$htmloutput = str_replace($newTableHTML, $newTableWiki, $htmloutput);
$htmloutput = str_replace($newHeadHTML, $newHeadWiki, $htmloutput);
$htmloutput = str_replace($newCellHTML, $newCellWiki, $htmloutput);
$htmloutput = str_replace($newRowHTML_, $newRowWiki, $htmloutput);
$htmloutput = str_replace($newRowHTML, $newRowWiki, $htmloutput);
$htmloutput = str_replace($closeTableHTML_, $closeTableWiki, $htmloutput);
$htmloutput = str_replace($closeTableHTML, $closeTableWiki, $htmloutput);
// Strip
$htmloutput = str_replace($endTagTH, '', $htmloutput);
$htmloutput = str_replace($endTagTD, '', $htmloutput);
$htmloutput = str_replace($endTagTR, '', $htmloutput);
$htmloutput = str_replace($endTagLB, '', $htmloutput);
//
// option :: rmbreak
//
if ($_POST['rmbreak'] == 'on'){
$rmbreak = "on";
$htmloutput = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $htmloutput);
} else {
$rmbreak = "off";
}
// Set Succesfull
$is_submit = true;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Krinkle - HTML2Wiki Tables</title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="ZeroClipboard.js"></script>
<script type="text/javascript" src="html2wiki.php?copyJS=<?php echo $copy2clipboard; ?>"></script>
</head>
<body>
<div id="copied-notice2"><div id="copied-notice"><img src="clipboard-64px.png" style="vertical-align:middle" alt="" />Copied to clipboard!</div></div>
<div id="page-wrap">
<h1><small>Krinkle</small> | HTML2Wiki Tables</h1>
<small><em>Version <?php echo $revID; ?> as uploaded on <?php echo $revDate; ?> by Krinkle</em></small>
<div style="background-color:yellow;">
</div>
<?php if ($is_submit) {
date_default_timezone_set('Europe/Amsterdam');
?>
<p class="msg thanks">Succesfully submitted the data on <?php echo date('l, d F Y - H:i'); ?><br />
<a href="#Krinkle_HTML2Wiki">Do another one !</a></p>
<p>Code (output) :</p>
<p class="msg"> <?php
if ($wikitable == "on") echo "Wikitable is <span class='thanks'>on</span>";
else echo "Wikitable is <span class='error'>off</span>";
?>
<br /><?php
if ($rmbreak == "on") echo "Remove empty lines is <span class='thanks'>on</span>";
else echo "Remove empty lines is <span class='error'>off</span>";
?>
<br /><?php
if ($cleaner == "on") echo "Style-stripper is <span class='thanks'>on</span>";
else echo "Style-stripper is <span class='error'>off</span>";
?>
<br />
<br /><?php /*
if ($copy2clipboard == "on") {
echo "Output <span class='thanks'>is copied</span> to clipboard !";
}
else {
echo "<span style='font-weight: normal;'>Output is not copied to clipboard</span>";
}
*/ ?>
</p>
<div id="htmloutput-wrap">
<pre id="htmloutput"><?php echo htmlentities(stripslashes($htmloutput), ENT_NOQUOTES, "UTF-8"); ?></pre>
</div>
<?php } ?>
<form action="index.php" method="post" id="Krinkle_HTML2Wiki">
<label for="htmlinput">Code (input) <span class="req">*</span> :</label>
<input type="submit" value="Submit data!" />
<textarea cols="100%" rows="40" id="htmlinput" name="htmlinput" class="required" minlength="2"><?php echo htmlentities(stripslashes($htmlinput), ENT_NOQUOTES, "UTF-8"); ?></textarea>
<input type="checkbox" name="wikitable" <?php if (!($wikitable == "off")) echo 'checked="checked"'; ?> value="on" />
<label for="wikitable">Convert to <code>class="wikitable"</code></label>
<br />
<input type="checkbox" name="cleaner" <?php if (!($cleaner == "off")) echo 'checked="checked"'; ?> value="on" />
<label for="cleaner">Enable style-stripper (strips any style, class, or border attributes)</label>
<br />
<input type="checkbox" name="rmbreak" <?php if (!($rmbreak == "off")) echo 'checked="checked"'; ?> value="on" />
<label for="rmbreak">Remove empty lines</label>
<br />
<br />
<!-- <input type="checkbox" name="copy2clipboard" <?php if (!($copy2clipboard == "off")) echo 'checked="checked"'; ?> value="on" />
<label for="copy2clipboard">Copy output to clipboard</label> -->
<input type="hidden" name="copy2clipboard" value="on" />
<br />
<input type="submit" value="Submit data!" />
</form>
<h3 id="known-issues">Known Issues</h3>
<ul>
<li>Redundant <code>|-</code> stays on top of the table (doesn't hurt, but may be stripped)</li>
</ul>
<h3 id="whats-new">What's New ?</h3>
<ul>
<li>2010-01-16 - Added function to remember previous choosen options</li>
<li>2010-01-16 - Added function-button to copy the output to clipboard.</li>
<li>2010-01-15 - Added option "Remove emptylines" (rmbreak)</li>
<li>2010-01-15 - Added option "Style-stripper" (cleaner)</li>
<li>2010-01-15 - Added option "wikitable" (wikitable)</li>
<li>2010-01-14 - Fixed issue with special characters (like î and ´)</li>
<li>2010-01-14 - Added sample code</li>
<li>2010-01-14 - Initial version</li>
</ul>
<h3 id="todos">Todo's</h3>
<ul>
<li>Add option for copy2clipboard when submitting. Output will be copied directly.</li>
<li>AJAX submit</li>
</ul>
<h3 id="author">Author</h3>
<p><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0;margin:0 auto;display:block;" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" /></a><span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Text" property="dc:title" rel="dc:type">HTML2Wiki</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://nl.wikipedia.org/wiki/Gebruiker:Krinkle" property="cc:attributionName" rel="cc:attributionURL">Krinkle</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>.</p>
<hr />
<p>If you have any suggestions, bug reports or feature requests. Or questions regarding the re-use of this tool feel free to contact me at <em>krinklemail<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/88/At_sign.svg/15px-At_sign.svg.png" alt="at" />gmail·com</em>, or leave a message at <a href="http://nl.wikipedia.org/w/index.php?title=Overleg_gebruiker:Krinkle&action=edit§ion=new&preload=Overleg_gebruiker:Krinkle/newPreload&uselang=en&editintro=Overleg_gebruiker:Krinkle/EditnoticeENG">my Wikipedia Talk-page here</a>.</p>
<div id="cc">
<h4 id="attr-code">Attribution-code</h4>
<code style="font-size: 80%;">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" /></a><br /><span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Text" property="dc:title" rel="dc:type">HTML2Wiki</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://nl.wikipedia.org/wiki/Gebruiker:Krinkle" property="cc:attributionName" rel="cc:attributionURL">Krinkle</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>.<br />Based on a work at <a xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://krinkle-tools.grizzdesign.nl/HTML2Wiki/" rel="dc:source">krinkle-tools.grizzdesign.nl</a>.<br />Permissions beyond the scope of this license may be available at <a xmlns:cc="http://creativecommons.org/ns#" href="http://krinkle-tools.grizzdesign.nl/HTML2Wiki/#author" rel="cc:morePermissions">http://krinkle-tools.grizzdesign.nl/HTML2Wiki/#author</a>.
</code>
<h4 id="preview">Preview</h4>
<div><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" /></a><br /><span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Text" property="dc:title" rel="dc:type">HTML2Wiki</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://nl.wikipedia.org/wiki/Gebruiker:Krinkle" property="cc:attributionName" rel="cc:attributionURL">Krinkle</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>.<br />Based on a work at <a xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://krinkle-tools.grizzdesign.nl/HTML2Wiki/" rel="dc:source">krinkle-tools.grizzdesign.nl</a>.<br />Permissions beyond the scope of this license may be available at:<br /> <a xmlns:cc="http://creativecommons.org/ns#" href="http://krinkle-tools.grizzdesign.nl/HTML2Wiki/#author" rel="cc:morePermissions">http://krinkle-tools.grizzdesign.nl/HTML2Wiki/#author</a>.</div>
</div>
<h3 id="sample">Sample code</h3>
<textarea cols="100%" rows="40"><TABLE>
<TR>
<TH STYLE="BACKGROUND:#EFEFEF;"> multiple spaces </TH>
<TH STYLE="BACKGROUND:#EFEFEF;">Land</TH>
<TH STYLE="BACKGROUND:#EFEFEF;">Artiest(en)</TH>
<TH STYLE="BACKGROUND:#EFEFEF;">Lied</TH>
<TH STYLE="BACKGROUND:#EFEFEF;">Punten</TH>
</TR>
<TR STYLE="BACKGROUND:#FFD700;">
<TD>1</TH>
<TD>{{LU}}</TH>
<TD>[[Anne-Marie David]]</TH>
<TD>''Tu te reconnaîtras''</TH>
<TD>129</TH>
</TR>
<TR>
<TD>2</TH>
<TD>{{ES-1939}}</TH>
<TD>[[Mocedades]]</TH>
<TD>''Eres tú''</TH>
<TD>125</TH>
</TR>
<TR>
<TD>3</TH>
<TD>{{GB}}</TH>
<TD>[[Cliff Richard]]</TH>
<TD>''Power to all our friends''</TH>
<TD>123</TH>
</TR>
<TR>
<TD>4</TH>
<TD>{{IL}}</TH>
<TD>[[Ilanit]]</TH>
<TD>''Ey-sham''</TH>
<TD>97</TH>
</TR>
<TR>
<TD>5</TH>
<TD>{{SE}}</TH>
<TD>[[Nova and The Dolls]]</TH>
<TD>''You're summer''</TH>
<TD>94</TH>
</TR>
<TR>
<TD>6</TH>
<TD>{{FI}}</TH>
<TD>[[Marion Rung]]</TH>
<TD>''Tom tom tom''</TH>
<TD>93</TH>
</TR>
<TR>
<TD>7</TH>
<TD>{{NO}}</TH>
<TD>[[Bendik Singers]]</TH>
<TD>''It's just a game''</TH>
<TD>89</TH>
</TR>
<TR>
<TD>8</TH>
<TD>{{WD-esf}}</TH>
<TD>[[Gitte Hénning|Gitte]]</TH>
<TD>''Junger Tag''</TH>
<TD>85</TH>
</TR>
<TR>
<TD>8</TH>
<TD>{{MC}}</TH>
<TD>[[Marie (zangeres)|Marie]]</TH>
<TD>''Un train qui part''</TH>
<TD>85</TH>
</TR>
<TR>
<TD>10</TH>
<TD>{{IE}}</TH>
<TD>[[Maxi]]</TH>
<TD>''Do I dream?''</TH>
<TD>80</TH>
</TR>
<TR>
<TD>10</TH>
<TD>{{PT}}</TH>
<TD>[[Fernando Tordo]]</TH>
<TD>''Tourada''</TH>
<TD>80</TH>
</TR>
<TR>
<TD>12</TH>
<TD>{{CH}}</TH>
<TD>[[Patrick Juvet]]</TH>
<TD>''Je vais me marier, Marie''</TH>
<TD>79</TH>
</TR>
<TR>
<TD>13</TH>
<TD>{{IT}}</TH>
<TD>[[Massimo Ranieri]]</TH>
<TD>''Chi sare con te''</TH>
<TD>74</TH>
</TR>
<TR>
<TD>14</TH>
<TD>{{NL}}</TH>
<TD>[[Ben Cramer]]</TH>
<TD>''De oude muzikant''</TH>
<TD>69</TH>
</TR>
<TR>
<TD>15</TH>
<TD>{{YU}}</TH>
<TD>[[Zdravko Colic|Zdravko Čolić]]</TH>
<TD>''Gori Vatra''</TH>
<TD>65</TH>
</TR>
<TR>
<TD>15</TH>
<TD>{{FR}}</TH>
<TD>[[Martine Clémenceau]]</TH>
<TD>''Sans toi''</TH>
<TD>65</TH>
</TR>
<TR>
<TD>17</TH>
<TD>{{BE}}</TH>
<TD>[[Nicole & Hugo]]</TH>
<TD>''Baby baby''</TH>
<TD>58</TH>
</TR>
</TABLE>
</textarea>
</div>
<a href="./" style="display:none;" id="home">Reload</a>
</body>
</html>