index.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. session_start();
  3. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  4. /*
  5. // Check user session
  6. if ((!isset($_SESSION['user'])) && (!defined('NO_AUTH_REQUIRED'))) {
  7. $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
  8. header("Location: /login/");
  9. exit;
  10. }
  11. */
  12. ?>
  13. <title>Edit file <?= htmlspecialchars($_REQUEST['path']) ?></title>
  14. <meta charset="utf-8" />
  15. <link href="/css/file_manager_editor.css" type="text/css" rel="stylesheet">
  16. <script src="/js/cheef-editor/jquery/jquery-1.8.3.min.js"></script>
  17. <script src="/js/cheef-editor/ace/ace.js"></script>
  18. <script src="/js/cheef-editor/ace/theme-twilight.js"></script>
  19. <script src="/js/cheef-editor/ace/mode-ruby.js"></script>
  20. <script src="/js/cheef-editor/jquery-ace.min.js"></script>
  21. <?php
  22. if (!empty($_REQUEST['path'])) {
  23. $content = '';
  24. $path = $_REQUEST['path'];
  25. if (is_readable($path)) {
  26. $image = getimagesize($path) ? true : false;
  27. if ($image) {
  28. header('Location: /view/file/?path='.$path);
  29. exit;
  30. }
  31. if (!empty($_POST['save'])) {
  32. $fn = tempnam ('/tmp', 'vst-save-file-');
  33. if ($fn) {
  34. $f = fopen ($fn, 'w+');
  35. fwrite($f, $_POST['contents']);
  36. if ($f) {
  37. copy($fn, $path);
  38. }
  39. unlink($fn);
  40. }
  41. }
  42. $content = file_get_contents($path);
  43. $content = $content;
  44. }
  45. }
  46. else {
  47. $content = '';
  48. }
  49. ?>
  50. <form method="post">
  51. <input type="submit" name="save" value="Save" class="save" />
  52. <textarea name="contents" class="editor" id="editor" rows="4" style="display:none;width: 100%; height: 100%;"><?php echo $content ?></textarea>
  53. </form>
  54. <script>
  55. $('.editor').ace({ theme: 'twilight', lang: 'ruby' });
  56. var dcrt = $('#editor').data('ace');
  57. var editor = dcrt.editor.ace;
  58. editor.gotoLine(0);
  59. editor.focus();
  60. </script>