PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/_plugins_/spixplorer/action/spx_edit.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 132 lines | 73 code | 9 blank | 50 comment | 12 complexity | 3b3b82e843525f5f9ca9e528cebefb8e MD5 | raw file
  1. <?php
  2. /*------------------------------------------------------------------------------
  3. The contents of this file are subject to the Mozilla Public License
  4. Version 1.1 (the "License"); you may not use this file except in
  5. compliance with the License. You may obtain a copy of the License at
  6. http://www.mozilla.org/MPL/
  7. Software distributed under the License is distributed on an "AS IS"
  8. basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. License for the specific language governing rights and limitations
  10. under the License.
  11. The Original Code is fun_edit.php, released on 2003-03-31.
  12. The Initial Developer of the Original Code is The QuiX project.
  13. Alternatively, the contents of this file may be used under the terms
  14. of the GNU General Public License Version 2 or later (the "GPL"), in
  15. which case the provisions of the GPL are applicable instead of
  16. those above. If you wish to allow use of your version of this file only
  17. under the terms of the GPL and not to allow others to use
  18. your version of this file under the MPL, indicate your decision by
  19. deleting the provisions above and replace them with the notice and
  20. other provisions required by the GPL. If you do not delete
  21. the provisions above, a recipient may use your version of this file
  22. under either the MPL or the GPL."
  23. ------------------------------------------------------------------------------*/
  24. /*------------------------------------------------------------------------------
  25. Author: The QuiX project
  26. quix@free.fr
  27. http://www.quix.tk
  28. http://quixplorer.sourceforge.net
  29. Comment:
  30. QuiXplorer Version 2.3
  31. File-Edit Functions
  32. Have Fun...
  33. Adaptation spip, plugin spixplorer : bertrand@toggg.com © 2007
  34. ------------------------------------------------------------------------------*/
  35. if (!defined("_ECRIRE_INC_VERSION")) return;
  36. function action_spx_edit()
  37. {
  38. include_spip('inc/spx_init');
  39. edit_file($GLOBALS['spx']["dir"], $GLOBALS['spx']["item"]);
  40. exit;
  41. }
  42. //------------------------------------------------------------------------------
  43. function savefile($file_name) { // save edited file
  44. $code = _request('code');
  45. $fp = @fopen($file_name, "w");
  46. if($fp===false) show_error(basename($file_name).": "._T('spixplorer:savefile'));
  47. fputs($fp, $code);
  48. @fclose($fp);
  49. }
  50. //------------------------------------------------------------------------------
  51. function edit_file($dir, $item) { // edit file
  52. if(($GLOBALS['spx']["permissions"]&01)!=01) show_error(_T('spixplorer:accessfunc'));
  53. if(!get_is_file($dir, $item)) show_error($item.": "._T('spixplorer:fileexist'));
  54. if(!get_show_item($dir, $item)) show_error($item.": "._T('spixplorer:accessfile'));
  55. $fname = get_abs_item($dir, $item);
  56. if(_request("dosave")=="yes") {
  57. // Save / Save As
  58. $item=basename(stripslashes(_request('fname')));
  59. $fname2=get_abs_item($dir, $item);
  60. if(!isset($item) || $item=="") show_error(_T('spixplorer:miscnoname'));
  61. if($fname!=$fname2 && @file_exists($fname2)) show_error($item.": "._T('spixplorer:itemdoesexist'));
  62. savefile($fname2);
  63. $fname=$fname2;
  64. }
  65. // open file
  66. $fp = @fopen($fname, "r");
  67. if($fp===false) show_error($item.": "._T('spixplorer:openfile'));
  68. // header
  69. $s_item=get_rel_item($dir,$item); if(strlen($s_item)>50) $s_item="...".substr($s_item,-47);
  70. show_header(_T('spixplorer:actedit').": /".$s_item);
  71. // Wordwrap (works only in IE)
  72. echo '
  73. <script language="JavaScript1.2" type="text/javascript">
  74. <!--
  75. function chwrap() {
  76. if(document.editfrm.wrap.checked) {
  77. document.editfrm.code.wrap="soft";
  78. } else {
  79. document.editfrm.code.wrap="off";
  80. }
  81. }
  82. // -->
  83. </script>
  84. ' .
  85. // Form
  86. '
  87. <br /><FORM name="editfrm" method="post" action="' . make_link("edit",$dir,$item) . '">
  88. <input type="hidden" name="dosave" value="yes">
  89. <TEXTAREA NAME="code" rows="25" cols="120" wrap="off">';
  90. // Show File In TextArea
  91. $buffer="";
  92. while(!feof ($fp)) {
  93. $buffer .= fgets($fp, 4096);
  94. }
  95. @fclose($fp);
  96. echo htmlspecialchars($buffer) . '</TEXTAREA><br />
  97. <TABLE><TR><TD>Wordwrap: (IE only)</TD><TD><INPUT type="checkbox" name="wrap"
  98. onClick="javascript:chwrap();" value="1"></TD></TR></TABLE><br />
  99. <TABLE><TR><TD><INPUT type="text" name="fname" value="' . $item . '"></TD>
  100. <TD><input type="submit" value="' . _T('spixplorer:btnsave') . '"></TD>
  101. <TD><input type="reset" value="' . _T('spixplorer:btnreset') . '"></TD>
  102. <TD>
  103. <input type="button" value="' . _T('spixplorer:btnclose') . '" onClick="javascript:location=\''
  104. . make_link("list",$dir,NULL) . '\';">
  105. </TD></TR></FORM></TABLE><br />
  106. <script language="JavaScript1.2" type="text/javascript">
  107. <!--
  108. if(document.editfrm) document.editfrm.code.focus();
  109. // -->
  110. </script>
  111. ';
  112. show_footer();
  113. }
  114. //------------------------------------------------------------------------------
  115. ?>