Revision b5c278be
Added by Sjon Hortensius over 10 years ago
usr/local/www/edit.php | ||
---|---|---|
46 | 46 |
switch($_POST['action']) { |
47 | 47 |
case 'load': |
48 | 48 |
if(strlen($_POST['file']) < 1) { |
49 |
print('|5|' . '<div class="alert alert-danger" role="alert">'.gettext("No file name specified").'</div>' . '|');
|
|
49 |
print('|5|' . '<div class="alert alert-danger" role="alert">'.gettext("No file name specified").'</div>' . '|');
|
|
50 | 50 |
} elseif(is_dir($_POST['file'])) { |
51 | 51 |
print('|4|' . '<div class="alert alert-danger" role="alert">' . gettext("Loading a directory is not supported") .'</div>' . '|'); |
52 | 52 |
} elseif(! is_file($_POST['file'])) { |
... | ... | |
57 | 57 |
print('|1|' . '<div class="alert alert-danger" role="alert">' . gettext("Failed to read file") . '</div>' . '|'); |
58 | 58 |
} else { |
59 | 59 |
$data = base64_encode($data); |
60 |
print("|0|{$_POST['file']}|{$data}|");
|
|
60 |
print("|0|{$_POST['file']}|{$data}|"); |
|
61 | 61 |
} |
62 | 62 |
} |
63 | 63 |
exit; |
64 |
|
|
64 |
|
|
65 | 65 |
case 'save': |
66 | 66 |
if(strlen($_POST['file']) < 1) { |
67 | 67 |
print('|' . '<div class="alert alert-danger" role="alert">'.gettext("No file name specified").'</div>' . '|'); |
... | ... | |
88 | 88 |
exit; |
89 | 89 |
} |
90 | 90 |
|
91 |
$closehead = false; |
|
92 | 91 |
require("head.inc"); |
93 | 92 |
?> |
94 |
|
|
95 | 93 |
<!-- file status box --> |
96 | 94 |
<div style="display:none; background:#eeeeee;" id="fileStatusBox"> |
97 | 95 |
<strong id="fileStatus"></strong> |
98 | 96 |
</div> |
99 | 97 |
|
100 |
<div class="panel panel-info"> |
|
101 |
<div class="panel-heading"> |
|
102 |
<?=gettext("Save / Load from path"); ?>: |
|
103 |
<!-- <input type="text" class="formfld file" id="fbTarget" size="45%"/> --> |
|
104 |
<input type="text" class="form-control" id="fbTarget"/> |
|
105 |
<input type="button" class="btn btn-default btn-sm" onclick="loadFile();" value="<?=gettext('Load')?>" /> |
|
106 |
<input type="button" class="btn btn-default btn-sm" id="fbOpen" value="<?=gettext('Browse')?>" /> |
|
107 |
<input type="button" class="btn btn-default btn-sm" onclick="saveFile();" value="<?=gettext('Save')?>" /> |
|
108 |
</div> |
|
109 |
|
|
98 |
<div class="panel panel-default"> |
|
99 |
<div class="panel-heading"><?=gettext("Save / Load a file from the filesystem")?></div> |
|
110 | 100 |
<div class="panel-body"> |
111 |
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"> |
|
112 |
</div> |
|
113 |
|
|
114 |
<div style="background:#eeeeee;" id="fileOutput"> |
|
115 |
<script type="text/javascript"> |
|
116 |
//<![CDATA[ |
|
117 |
window.onload=function(){ |
|
118 |
document.getElementById("fileContent").wrap='off'; |
|
119 |
} |
|
120 |
//]]> |
|
121 |
</script> |
|
122 |
<textarea id="fileContent" name="fileContent" class="form-control" rows="30" cols=""></textarea> |
|
123 |
</div> |
|
124 |
</div> |
|
125 |
</div> |
|
126 |
|
|
127 |
<?php include("foot.inc"); |
|
128 |
|
|
129 |
outputJavaScriptFileInline("filebrowser/browser.js"); |
|
130 |
outputJavaScriptFileInline("javascript/base64.js"); |
|
131 |
?> |
|
101 |
<form> |
|
102 |
<input type="text" class="form-control" id="fbTarget"/> |
|
103 |
<input type="button" class="btn btn-default btn-sm" onclick="loadFile();" value="<?=gettext('Load')?>" /> |
|
104 |
<input type="button" class="btn btn-default btn-sm" id="fbOpen" value="<?=gettext('Browse')?>" /> |
|
105 |
<input type="button" class="btn btn-default btn-sm" onclick="saveFile();" value="<?=gettext('Save')?>" /> |
|
106 |
</form> |
|
107 |
|
|
108 |
<div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div> |
|
109 |
|
|
110 |
<div style="background:#eeeeee;" id="fileOutput"> |
|
111 |
<script type="text/javascript"> |
|
112 |
//<![CDATA[ |
|
113 |
window.onload=function(){ |
|
114 |
document.getElementById("fileContent").wrap='off'; |
|
115 |
} |
|
116 |
//]]> |
|
117 |
</script> |
|
118 |
<textarea id="fileContent" name="fileContent" class="form-control" rows="30" cols=""></textarea> |
|
119 |
</div> |
|
132 | 120 |
|
133 |
<!-- Since the jQuery, bootstrap etc libraries are included from foot.inc, JavaScript functions that require jQuery need to move down here -->
|
|
134 |
<script type="text/javascript" src="/javascript/niftyjsCode.js"></script>
|
|
121 |
</div>
|
|
122 |
</div>
|
|
135 | 123 |
|
136 |
<script type="text/javascript"> |
|
137 |
//<![CDATA[ |
|
124 |
<script> |
|
138 | 125 |
function loadFile() { |
139 |
jQuery("#fileStatus").html("");
|
|
126 |
jQuery("#fileStatus").html("");
|
|
140 | 127 |
jQuery("#fileStatusBox").show(500); |
141 | 128 |
jQuery.ajax( |
142 | 129 |
"<?=$_SERVER['SCRIPT_NAME']?>", { |
... | ... | |
154 | 141 |
|
155 | 142 |
if(values.shift() == "0") { |
156 | 143 |
var file = values.shift(); |
157 |
var fileContent = Base64.decode(values.join("|")); |
|
158 |
|
|
159 |
jQuery("#fileContent").val(fileContent); |
|
144 |
var fileContent = window.atob(values.join("|")); |
|
160 | 145 |
|
161 |
var lang = "none"; |
|
162 |
if(file.indexOf(".php") > 0) lang = "php"; |
|
163 |
else if(file.indexOf(".inc") > 0) lang = "php"; |
|
164 |
else if(file.indexOf(".xml") > 0) lang = "xml"; |
|
165 |
else if(file.indexOf(".js" ) > 0) lang = "js"; |
|
166 |
else if(file.indexOf(".css") > 0) lang = "css"; |
|
167 |
|
|
168 |
if(jQuery("#highlight").checked && lang != "none") { |
|
169 |
jQuery("fileContent").prop("className",lang + ":showcolumns"); |
|
170 |
dp.SyntaxHighlighter.HighlightAll("fileContent", true, false); |
|
171 |
} |
|
146 |
jQuery("#fileContent").val(fileContent); |
|
172 | 147 |
} |
173 | 148 |
else { |
174 | 149 |
jQuery("#fileStatus").html(values[0]); |
175 | 150 |
jQuery("#fileContent").val(""); |
176 | 151 |
} |
152 |
|
|
177 | 153 |
jQuery("#fileContent").show(1000); |
178 | 154 |
} |
179 | 155 |
|
180 | 156 |
function saveFile(file) { |
181 |
jQuery("#fileStatus").html("");
|
|
182 |
jQuery("#fileStatusBox").show(500);
|
|
157 |
jQuery("#fileStatus").html("");
|
|
158 |
jQuery("#fileStatusBox").show(500);
|
|
183 | 159 |
var fileContent = Base64.encode(jQuery("#fileContent").val()); |
184 | 160 |
fileContent = fileContent.replace(/\+/g,"%2B"); |
185 |
|
|
161 |
|
|
186 | 162 |
jQuery.ajax( |
187 | 163 |
"<?=$_SERVER['SCRIPT_NAME']?>", { |
188 | 164 |
type: "post", |
... | ... | |
196 | 172 |
); |
197 | 173 |
} |
198 | 174 |
|
199 |
jQuery(window).load( |
|
200 |
function() { |
|
201 |
jQuery("#fbTarget").focus(); |
|
202 |
|
|
203 |
NiftyCheck(); |
|
204 |
Rounded("div#fileStatusBox", "all", "#ffffff", "#eeeeee", "smooth"); |
|
205 |
} |
|
206 |
); |
|
207 |
|
|
208 | 175 |
<?php if($_GET['action'] == "load"): ?> |
209 |
jQuery(window).load( |
|
210 |
function() { |
|
211 |
jQuery("#fbTarget").val("<?=htmlspecialchars($_GET['path'])?>"); |
|
212 |
loadFile(); |
|
213 |
} |
|
214 |
); |
|
176 |
events.push(function() { |
|
177 |
jQuery("#fbTarget").val("<?=htmlspecialchars($_GET['path'])?>"); |
|
178 |
loadFile(); |
|
179 |
}); |
|
215 | 180 |
<?php endif; ?> |
216 |
//]]> |
|
217 |
</script> |
|
181 |
</script> |
|
182 |
|
|
183 |
<?php include("foot.inc"); |
|
184 |
|
|
185 |
outputJavaScriptFileInline("filebrowser/browser.js"); |
Also available in: Unified diff
Complete conversion; add <form>, remove dead sntxhgh, use events
refs #94