-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
148 lines (140 loc) · 4.61 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
<?php
$ds = DIRECTORY_SEPARATOR;
$history_file = dirname(__FILE__).$ds.'history';
$error = '';
if (!is_writable($history_file)) {
$error = 'History file is not writable. Your written code will not be saved.';
}
$value = '';
if (file_exists($history_file)) {
$value = file_get_contents($history_file);
}
$template_dir = dirname(__FILE__).$ds.'templates'.$ds;
$files = scandir($template_dir);
$templates = array();
$i = 1;
foreach ($files as $file) {
if (in_array($file, array('.', '..','.gitkeep'))) {
continue;
}
$data = file_get_contents($template_dir.$file);
$templates[$i] = array(
'caption' => pathinfo($file, PATHINFO_FILENAME),
'code' => $data
);
$i++;
}
?><!DOCTYPE html>
<html>
<head>
<title>PHP console</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="styles/style.css" type="text/css"/>
<link rel="stylesheet" href="node_modules/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="node_modules/codemirror/theme/ambiance.css">
<link rel="stylesheet" href="node_modules/codemirror/addon/scroll/simplescrollbars.css">
<link href="//fonts.googleapis.com/css?family=Roboto&subset=cyrillic" rel="stylesheet">
<script src="node_modules/codemirror/lib/codemirror.js"></script>
<script src="node_modules/codemirror/addon/edit/matchbrackets.js"></script>
<script src="node_modules/codemirror/addon/scroll/simplescrollbars.js"></script>
<script src="node_modules/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="node_modules/codemirror/mode/xml/xml.js"></script>
<script src="node_modules/codemirror/mode/javascript/javascript.js"></script>
<script src="node_modules/codemirror/mode/css/css.js"></script>
<script src="node_modules/codemirror/mode/clike/clike.js"></script>
<script src="node_modules/codemirror/mode/php/php.js"></script>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/jquery.hotkeys/jquery.hotkeys.js"></script>
<script src="scripts/main.js"></script>
<link rel="icon" href="favicon.ico?v=1.1">
</head>
<body>
<div class="ide">
<header>
<div class="ide__toolbar">
<div class="ide__loading hidden" id="loading">
<div class="sk-fading-circle">
<div class="sk-circle1 sk-circle"></div>
<div class="sk-circle2 sk-circle"></div>
<div class="sk-circle3 sk-circle"></div>
<div class="sk-circle4 sk-circle"></div>
<div class="sk-circle5 sk-circle"></div>
<div class="sk-circle6 sk-circle"></div>
<div class="sk-circle7 sk-circle"></div>
<div class="sk-circle8 sk-circle"></div>
<div class="sk-circle9 sk-circle"></div>
<div class="sk-circle10 sk-circle"></div>
<div class="sk-circle11 sk-circle"></div>
<div class="sk-circle12 sk-circle"></div>
</div>
</div>
<ul>
<li>
<button type="button" onclick="phpSandbox.execute();" title="Press F9 shortcut to execute from keyboard" class="primary">Execute</button>
<button type="button" onclick="phpSandbox.clear();">Clear</button>
</li>
<li>
<label>
<input type="checkbox" checked id="auto" /> Auto update
</label>
</li>
<li>
<label class="form-label">Layout:</label>
<div class="select-style">
<select id="layout-selector" onchange="phpSandbox.setLayout(this.value)">
<option value="vertical">Vertical</option>
<option value="horizontal">Horizontal</option>
</select>
</div>
</li>
<li>
<label class="form-label">Template:</label>
<div class="select-style">
<select id="template-selector" onchange="phpSandbox.setTemplate(this.value)">
<optgroup label="Templates">
<?php
if (!empty($templates)) {
?>
<option value="0"></option>
<?php
foreach ($templates as $index => $template) {
?>
<option value="<?=$index?>"><?=$template['caption']?></option>
<?php
}
} else {
?>
<option disabled="disabled">No templates found.</option>
<?php
}
?>
</optgroup>
</select>
</div>
</li>
<?php
if ($error) {
echo '<li class="error">'.$error.'</li>';
}
?>
</ul>
</div>
</header>
<main>
<div id="ide" class="code">
<div class="code__source" id="code">
</div>
<div class="code__result">
<iframe id="results"></iframe>
</div>
</div>
</main>
</div>
<script>
$(function(){
phpSandbox.value = <?=json_encode($value)?>;
phpSandbox.templates = <?=json_encode($templates)?>;
phpSandbox.init();
});
</script>
</body>