| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
- $user = $_SESSION['user'];
- // Check module activation
- if (!$_SESSION['FILEMANAGER_KEY']) {
- $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
- header("Location: /login/");
- exit;
- }
- // Check login_as feature
- if (($_SESSION['user'] == 'admin') && (!empty($_SESSION['look']))) {
- $user=$_SESSION['look'];
- }
- ?>
- <title>Edit file <?= htmlspecialchars($_REQUEST['path']) ?></title>
- <meta charset="utf-8" />
- <link href="/css/file_manager_editor.css" type="text/css" rel="stylesheet">
- <script src="/js/cheef-editor/jquery/jquery-1.8.3.min.js"></script>
- <script src="/js/cheef-editor/ace/ace.js"></script>
- <script src="/js/cheef-editor/ace/theme-twilight.js"></script>
- <script src="/js/cheef-editor/ace/mode-ruby.js"></script>
- <script src="/js/cheef-editor/jquery-ace.min.js"></script>
- <div id="message" style="display:none; position: absoulte;background-color: green; color: white; padding: 10px;"></div>
- <div id="error-message" style="display:none; position: absoulte;background-color: red; color: white; padding: 10px;"></div>
- <?php
- if (!empty($_REQUEST['path'])) {
- $content = '';
- $path = $_REQUEST['path'];
- if (!empty($_POST['save'])) {
- $fn = tempnam('/tmp', 'vst-save-file-');
- if ($fn) {
- $contents = $_POST['contents'];
- $contents = preg_replace("/\r/", "", $contents);
- $f = fopen($fn, 'w+');
- fwrite($f, $contents);
- fclose($f);
- chmod($fn, 0644);
- if ($f) {
- $return_var = v_exec('v-copy-fs-file', [$user, $fn, $path]);
- if ($return_var != 0) {
- print('<p style="color: white">Error while saving file</p>');
- exit;
- }
- }
- unlink($fn);
- }
- }
- $return_var = v_exec('v-open-fs-file', [$user, $path], false, $content);
- if ($return_var != 0) {
- print 'Error while opening file'; // todo: handle this more styled
- exit;
- }
- $content = $content . "\n";
- } else {
- $content = '';
- }
- ?>
- <form id="edit-file-form" method="post">
- <!-- input id="do-backup" type="button" onClick="javascript:void(0);" name="save" value="backup (ctrl+F2)" class="backup" / -->
- <input type="submit" name="save" value="Save" class="save" />
- <textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?php echo $content ?></textarea>
- </form>
- <script type="text/javascript" src="/js/hotkeys.js"></script>
- <script type="text/javascript">
- $('.editor').ace({ theme: 'twilight', lang: 'ruby' });
- var dcrt = $('#editor').data('ace');
- dcrt.editor.ace.getSession().setNewLineMode('unix');
- var aceInstance = dcrt.editor.ace;
- aceInstance.gotoLine(0);
- aceInstance.focus();
-
- var makeBackup = function() {
- var params = {
- action: 'backup',
- path: '<?= $path ?>'
- };
-
- $.ajax({url: "/file_manager/fm_api.php",
- method: "POST",
- data: params,
- dataType: 'JSON',
- success: function(reply) {
- var fadeTimeout = 3000;
- if (reply.result) {
- $('#message').text('File backed up as ' + reply.filename);
- clearTimeout(window.msg_tmt);
- $('#message').show();
- window.msg_tmt = setTimeout(function() {$('#message').fadeOut();}, fadeTimeout);
- }
- else {
- $('#error-message').text(reply.message);
- clearTimeout(window.errmsg_tmt);
- $('#error-message').show();
- window.errmsg_tmt = setTimeout(function() {$('#error-message').fadeOut();}, fadeTimeout);
- }
- }
- });
- }
- $('#do-backup').on('click', function(evt) {
- evt.preventDefault();
-
- makeBackup();
- });
- //
- // Shortcuts
- //
- shortcut.add("Ctrl+s",function() {
- var inp = $('<input>').attr({'type': 'hidden', 'name': 'save'}).val('Save');
- $('#edit-file-form').append(inp);
- $('#edit-file-form').submit();
- },{
- 'type': 'keydown',
- 'propagate': false,
- 'disable_in_input': false,
- 'target': document
- });
- shortcut.add("Ctrl+F2",function() {
- makeBackup();
- },{
- 'type': 'keydown',
- 'propagate': false,
- 'disable_in_input': false,
- 'target': document
- });
-
- </script>
|