-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.php
54 lines (53 loc) · 1.83 KB
/
editor.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
<html>
<?php
include 'php/template.php';
head($_GET['file'], 'Editor for the following file:'.$_GET['file']);
?>
<body>
<?php
navBar();
?>
<style type="text/css" media="screen">
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
<div class="container" style="width: 100%;">
<div class="row">
<div class="col-lg-12" style="height: 100%;">
<div id="editor">Loading file...</div>
</div>
</div>
</div>
<script src="/js/ace/src-min/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode(<?php echo '"ace/mode/'.($_GET['lang']?:'java').'"'?>);
editor.setShowPrintMargin(false);
<?php
if (isset($_GET['file'])){
$components = parse_url($_GET['file']);
#load via PHP if file is local to server, load via js otherwise
if(empty($components['host']) || strcasecmp($components['host'], $_SERVER['HTTP_HOST']))
echo('editor.setValue('.json_encode(file_get_contents($_GET['file'])).')');
else{
echo('
Online file functionality
var client = new XMLHttpRequest();
client.open("GET", '.'"'.$_GET['file'].'");
client.onreadystatechange = function() {
editor.setValue(client.responseText);
}
client.send();');
}
} else
echo('editor.setValue()');
?>
</script>
</body>
</html>