-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.php
103 lines (85 loc) · 2.17 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
<?php
/*
* Sorry to the one who has to read this code massacre.
* I didn't want to use a real template system like Twig
* because I wanted to keep the converter as lightweight as possible
* and I'm still quite new in the web development area.
*
* A cat as an excuse:
*
* /\ /\
* { `---' }
* { O O }
* ~|~ V ~|~
* \ \|/ /
* `-----'__
* / \ `^\_
* { }\ |\_\_ W
* | \_/ |/ / \_\_( )
* \__/ /(_E \__/
* ( /
* MM
*/
require 'php/converter.php';
require 'php/types.php';
$converter = new Converter();
$types = new Types();
$input = isset($_POST['input']) ? $_POST['input'] : false;
$result = [
'error' => [
'err' => 0,
'msg' => ''
],
'time' => 0
];
$output = '';
if($input !== false) {
$result = $converter->convert($input, false, $types->getTypes(), false);
if(isset($_POST['layout'])) {
$output .= '// Layout: ' . $_POST['layout']. "\n" . 'layout("'.$_POST['layout'].'");' . "\n\n";
}
foreach($result['output'] as $o) {
$output .= "$o\n";
}
}
$page_content = file_get_contents('page/index.phtml');
$vars = [
'input' => $input,
'output' => $output,
'input' => isset($_POST['input']) ? $_POST['input'] : '',
'error_msg' => $result['error']['err'] === 1 ? $result['error']['msg'] : '',
'execution_time' => $result['time'],
'layout' => isset($_POST['layout']) ? $_POST['layout'] : ''
];
$page_lines = explode("\n", $page_content);
$ignore = false;
foreach($page_lines as $line) {
foreach($vars as $key => $val) {
$line = str_replace("{{ $key }}", $val, $line);
}
$t = trim($line);
if($t == '{{ if_output_convert }}') {
if($input === false) {
$ignore = true;
}
continue;
}
if($t == '{{ end_if_output_convert }}') {
$ignore = false;
continue;
}
if($t == '{{ if_error }}') {
if($result['error']['err'] === 0) {
$ignore = true;
}
continue;
}
if($t == '{{ end_if_error }}') {
$ignore = false;
continue;
}
if($ignore) {
continue;
}
echo "$line\n";
}