|
3 | 3 |
|
4 | 4 | include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); |
5 | 5 | /* |
| 6 | +if (empty($panel)) { |
| 7 | + $command = VESTA_CMD."v-list-user '".$user."' 'json'"; |
| 8 | + exec ($command, $output, $return_var); |
| 9 | + if ( $return_var > 0 ) { |
| 10 | + header("Location: /error/"); |
| 11 | + exit; |
| 12 | + } |
| 13 | + $panel = json_decode(implode('', $output), true); |
| 14 | +} |
| 15 | +*/ |
| 16 | +/* |
6 | 17 | // Check user session |
7 | 18 | if ((!isset($_SESSION['user'])) && (!defined('NO_AUTH_REQUIRED'))) { |
8 | 19 | $_SESSION['request_uri'] = $_SERVER['REQUEST_URI']; |
|
23 | 34 | <script src="/js/cheef-editor/ace/mode-ruby.js"></script> |
24 | 35 | <script src="/js/cheef-editor/jquery-ace.min.js"></script> |
25 | 36 |
|
| 37 | +<div id="message" style="display:none; position: absoulte;background-color: green; color: white; padding: 10px;"></div> |
| 38 | +<div id="error-message" style="display:none; position: absoulte;background-color: red; color: white; padding: 10px;"></div> |
| 39 | + |
26 | 40 | <?php |
27 | 41 |
|
28 | 42 | if (!empty($_REQUEST['path'])) { |
29 | 43 | $content = ''; |
30 | 44 | $path = $_REQUEST['path']; |
31 | 45 | if (is_readable($path)) { |
32 | | - |
33 | 46 | $image = getimagesize($path) ? true : false; |
34 | 47 |
|
35 | 48 | if ($image) { |
|
49 | 62 | } |
50 | 63 | } |
51 | 64 |
|
52 | | - $content = file_get_contents($path); |
53 | | - $content = $content; |
| 65 | + // $content = file_get_contents($path); |
| 66 | + // v-open-fs-file |
| 67 | + |
| 68 | + exec (VESTA_CMD . "v-open-fs-file {$user} {$path}", $content, $return_var); |
| 69 | + if ($return_var != 0) { |
| 70 | + print 'Error while opening file'; // todo: handle this more styled |
| 71 | + exit; |
| 72 | + } |
| 73 | + |
| 74 | + $content = implode("\n", $content); |
54 | 75 | } |
55 | 76 | } |
56 | 77 | else { |
|
59 | 80 |
|
60 | 81 | ?> |
61 | 82 |
|
62 | | -<form method="post"> |
| 83 | +<form id="edit-file-form" method="post"> |
| 84 | +<!-- input id="do-backup" type="button" onClick="javascript:void(0);" name="save" value="backup (ctrl+F2)" class="backup" / --> |
63 | 85 | <input type="submit" name="save" value="Save" class="save" /> |
64 | 86 |
|
65 | 87 |
|
66 | 88 | <textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?php echo $content ?></textarea> |
67 | 89 |
|
68 | 90 | </form> |
69 | | -<script> |
70 | | - $('.editor').ace({ theme: 'twilight', lang: 'ruby' }); |
71 | 91 |
|
72 | | - var dcrt = $('#editor').data('ace'); |
73 | | - var editor = dcrt.editor.ace; |
74 | | - editor.gotoLine(0); |
75 | | - editor.focus(); |
| 92 | +<script type="text/javascript" src="/js/hotkeys.js"></script> |
| 93 | +<script type="text/javascript"> |
| 94 | + $('.editor').ace({ theme: 'twilight', lang: 'ruby' }); |
| 95 | + |
| 96 | + var dcrt = $('#editor').data('ace'); |
| 97 | + var editor = dcrt.editor.ace; |
| 98 | + editor.gotoLine(0); |
| 99 | + editor.focus(); |
| 100 | + |
| 101 | + |
| 102 | + var makeBackup = function() { |
| 103 | + var params = { |
| 104 | + action: 'backup', |
| 105 | + path: '<?= $path ?>' |
| 106 | + }; |
| 107 | + |
| 108 | + $.ajax({url: "/file_manager/fm_api.php", |
| 109 | + method: "POST", |
| 110 | + data: params, |
| 111 | + dataType: 'JSON', |
| 112 | + success: function(reply) { |
| 113 | + var fadeTimeout = 3000; |
| 114 | + if (reply.result) { |
| 115 | + $('#message').text('File backed up as ' + reply.filename); |
| 116 | + clearTimeout(window.msg_tmt); |
| 117 | + $('#message').show(); |
| 118 | + window.msg_tmt = setTimeout(function() {$('#message').fadeOut();}, fadeTimeout); |
| 119 | + } |
| 120 | + else { |
| 121 | + $('#error-message').text(reply.message); |
| 122 | + clearTimeout(window.errmsg_tmt); |
| 123 | + $('#error-message').show(); |
| 124 | + window.errmsg_tmt = setTimeout(function() {$('#error-message').fadeOut();}, fadeTimeout); |
| 125 | + } |
| 126 | + } |
| 127 | + }); |
| 128 | + } |
| 129 | + |
| 130 | + $('#do-backup').on('click', function(evt) { |
| 131 | + evt.preventDefault(); |
| 132 | + |
| 133 | + makeBackup(); |
| 134 | + }); |
| 135 | + // |
| 136 | + // Shortcuts |
| 137 | + // |
| 138 | + shortcut.add("Ctrl+s",function() { |
| 139 | + var inp = $('<input>').attr({'type': 'hidden', 'name': 'save'}).val('Save'); |
| 140 | + $('#edit-file-form').append(inp); |
| 141 | + $('#edit-file-form').submit(); |
| 142 | + },{ |
| 143 | + 'type': 'keydown', |
| 144 | + 'propagate': false, |
| 145 | + 'disable_in_input': false, |
| 146 | + 'target': document |
| 147 | + }); |
| 148 | + shortcut.add("Ctrl+F2",function() { |
| 149 | + makeBackup(); |
| 150 | + },{ |
| 151 | + 'type': 'keydown', |
| 152 | + 'propagate': false, |
| 153 | + 'disable_in_input': false, |
| 154 | + 'target': document |
| 155 | + }); |
| 156 | + |
76 | 157 | </script> |
0 commit comments