-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
172 lines (148 loc) · 4.54 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
<?php
header('X-XSS-Protection: 0');
function render($view, $vars)
{
extract($vars);
ob_start();
include($view);
$content = ob_get_clean();
return $content;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="jquery-1.8.3.min.js"></script>
<title>EDIT</title>
</head>
<style type='text/css'>
#editor{
width:800px;height:300px
}
.textarea-hidden {
display: none;
}
.container{
width: 800px;
margin-right: auto;
margin-left: auto;
}
.ace_editor {
position: relative !important;
border: 1px solid lightgray;
margin: auto;
height: 200px;
width: 80%;
}
input[type=submit] {
padding: 5px 10px;
}
.ace_editor.fullScreen {
width: auto!important;
height: auto !important;
border: 0;
margin: 0;
position: fixed !important;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 10;
background: white;
}
.fullScreen {
overflow: hidden
}
.scrollmargin {
height: 500px;
text-align: center;
}
</style>
<body>
<div class='container'>
<?php
if (!empty($_POST)){
$filename = 'test.php';
$source = $_POST['source'];
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $source) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
?>
<h4 style='color:#666;float:left'>Test.php </h4>
<div style='float:right'>
<a href="#" id='use-jquery'>Use jQuery</a> |
<a href='./dates.php'>Dates</a>
</div>
<div style='clear:both'></div>
<iframe src='test.php' onLoad="autoResize('iframe1');" id="iframe1" frameborder='0' scrolling='no' allowtransparency='true' >
<?php
$source = file_get_contents('test.php');
?>
</iframe>
<br/><br/><br/>
<form method='post'>
<pre id='editor' ><?php echo htmlspecialchars($source)?></pre><br/>
<textarea name='source' class='textarea-hidden' ></textarea>
<input type='submit' id='submit-form'>
</form>
</div>
<script src='ace/build/src/ace.js'></script>
<script type="text/javascript">
var $ = document.getElementById.bind(document);
var dom = require("ace/lib/dom");
var commands = require("ace/commands/default_commands").commands;
commands.push({
name: "Toggle Fullscreen",
bindKey: "F11",
exec: function(editor) {
dom.toggleCssClass(document.body, "fullScreen")
dom.toggleCssClass(editor.container, "fullScreen")
editor.resize()
}
});
commands.push({
name: "Submit",
bindKey: "F9",
exec: function(editor) {
jQuery('#submit-form').trigger('click');
}
})
var editor = ace.edit("editor");
editor.setFontSize('15px');
editor.setTheme("ace/theme/twilight");
editor.session.setMode("ace/mode/php");
jQuery('#submit-form').click(function() {
jQuery("textarea[name='source']").text(editor.getValue());
jQuery(this).closest('form').submit();
})
function autoResize(id){
var newheight;
var newwidth;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}
document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
script=document.createElement('script'); script.type = 'text/javascript';
script.src='jquery-1.8.3.min.js';
jQuery("#use-jquery").click(function() {
editor.insert(script.outerHTML);
})
</script>
</body>
</html>