This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
txt2tags.form.php
138 lines (105 loc) · 3.64 KB
/
txt2tags.form.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
<?php
/**
txt2tags.class.php : text to HTML convertor in PHP
Written by (c) Petko Yotov 2012 www.pmwiki.org/Petko
Development sponsored by Eric Forgeot.
This is an example use of the txt2tags.class.php script
with a web form.
You can edit this file and adapt it for your needs.
*/
function stripmagic($x) # form helper function from PmWiki
{ return get_magic_quotes_gpc() ? stripslashes($x) : $x; }
require_once('txt2tags.class.php');
# OPTION 1: serve a single file:
#
# $page = file_get_contents("sample.t2t");
# OPTION 2: serve a file called by 'txt2tags.form.php?id='
# Use 'switch' for defined files
# <!> change $fichier = "$id"; for default switch
# if you don't want your visitors to be able
# to execute random code.
# See txt2tags.sample.php for an example of use.
#
# foreach ($_POST as $key => $value) $$key = addslashes($value);
# foreach ($_GET as $key => $value) $$key = addslashes($value);
#
# $id = $_GET['id'];
# if ($_GET['id'] != "undefined")
# {
# switch($id) {
# case "file1":
# $fichier = "file1.t2t";
# break;
# case "file2":
# $fichier = "file2.t2t";
# break;
# case "sample":
# $fichier = "sample.t2t";
# break;
# default:
# $fichier = "$id";
# break;
# }
# }
#
# $page = $text = file_get_contents($fichier);
# OPTION 3: serve a form which visitors can fill themselves (for testing purpose)
$page = <<<EOF
txt2tags
Free online php conversion
%!style: inc/site.css
%%%
Note, we write in the %!postproc below \\n\\1 because it is
inside a PHP variable. In a text file or in a web form, we
would write just \n for newline and \1 for the first match.
%%%
%!postproc: (</head>) <style type='text/css'></style>\\n\\1
%!postproc: (</style>) div.demo, pre {width: 90%; border: 2px solid #ddd; margin: 1em; padding: 1em;}\\n\\1
%!postproc: (</style>) textarea {width: 90%; border: 2px solid #ddd; margin: 1em;}\\n\\1
%!postproc: (</style>) hr { color: #f00; background-color: #f00; width: 90%; }\\n\\1
%!postproc: (</style>) hr.light { height: 2px; }\\n\\1
%!postproc: (</style>) hr.heavy { height: 6px; }\\n\\1
%!postproc: (</title>) ".class.php - online convertor\\1"
%!postproc: "<div style='text-align:center;'>" <div class='header' id='header'>
%!postproc: "(<h1>)(.+.)(</h1>)" \\1<a href="/">\\2</a>\\3
%!postproc: "(<h3>.*</h3>)" \\1\\nby <a href="http://notamment.fr/">Petko Yotov</a>
''' <div class="body" id="body">
= txt2tags.class.php - online convertor =
Here you can test the [txt2tags.class.php txt2tags-php.zip] script.
Write or paste some ``t2t markup`` in the text area below.
'''
<form action="txt2tags.form.php" method="post">
<textarea name="text" rows="12" cols="80">
{(TEXT)}</textarea><br/>
<input type="submit" value="Convert!"/> <a href="txt2tags.form.php">Reset</a>
</form>
'''
== Resulting HTML code ==
``` {(CODE)}
== Rendered HTML ==
''' <div class='demo'>
{(HTML)}
''' </div>
% </div class=body>
''' </div>
EOF;
# create the form page
$x = new T2T($page);
# change the %%mtime
$x->mtime = filemtime(__FILE__);
$x->go();
$html = $x->fullhtml;
# for including in an HTML page: $html = $x->bodyhtml;
# for a complete HTML page: $html = $x->fullhtml;
$search = array('{(CODE)}', '{(HTML)}', '{(TEXT)}');
$replace = array("The result will appear here.", "The result will appear here.", '');
if(@$_POST['text']) {
$text = stripmagic($_POST['text']);
$z = new T2T($text);
$z->go();
$fullhtml = $z->fullhtml;
$onlybody = $z->bodyhtml;
$replace = array( htmlspecialchars($fullhtml), $onlybody, htmlspecialchars($text));
}
$html = str_replace($search, $replace, $html);
echo $html;