PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_extplorer/include/rename.php

https://github.com/cavila/Astica
PHP | 159 lines | 111 code | 13 blank | 35 comment | 12 complexity | 58c859177719ff1848300d6f5aff34f4 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. // ensure this file is being included by a parent file
  3. if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
  4. /**
  5. * @version $Id: rename.php 203 2011-07-25 06:51:11Z soeren $
  6. * @package eXtplorer
  7. * @copyright soeren 2007-2009
  8. * @author The eXtplorer project (http://extplorer.net)
  9. * @author The The QuiX project (http://quixplorer.sourceforge.net)
  10. *
  11. * @license
  12. * The contents of this file are subject to the Mozilla Public License
  13. * Version 1.1 (the "License"); you may not use this file except in
  14. * compliance with the License. You may obtain a copy of the License at
  15. * http://www.mozilla.org/MPL/
  16. *
  17. * Software distributed under the License is distributed on an "AS IS"
  18. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  19. * License for the specific language governing rights and limitations
  20. * under the License.
  21. *
  22. * Alternatively, the contents of this file may be used under the terms
  23. * of the GNU General Public License Version 2 or later (the "GPL"), in
  24. * which case the provisions of the GPL are applicable instead of
  25. * those above. If you wish to allow use of your version of this file only
  26. * under the terms of the GPL and not to allow others to use
  27. * your version of this file under the MPL, indicate your decision by
  28. * deleting the provisions above and replace them with the notice and
  29. * other provisions required by the GPL. If you do not delete
  30. * the provisions above, a recipient may use your version of this file
  31. * under either the MPL or the GPL."
  32. *
  33. */
  34. /**
  35. * Allows to rename files and dirs
  36. *
  37. */
  38. class ext_Rename extends ext_Action {
  39. function execAction($dir, $item) { // rename directory or file
  40. if(($GLOBALS["permissions"]&01)!=01) {
  41. ext_Result::sendResult('rename', false, $GLOBALS["error_msg"]["accessfunc"]);
  42. }
  43. if(isset($GLOBALS['__POST']["confirm"]) && $GLOBALS['__POST']["confirm"]=="true") {
  44. $newitemname=$GLOBALS['__POST']["newitemname"];
  45. $newitemname=trim(basename(stripslashes($newitemname)));
  46. if($newitemname=='' ) {
  47. ext_Result::sendResult('rename', false, $GLOBALS["error_msg"]["miscnoname"]);
  48. }
  49. if( !ext_isFTPMode()) {
  50. $abs_old = get_abs_item($dir,$item);
  51. $abs_new = get_abs_item($dir,$newitemname);
  52. } else {
  53. $abs_old = get_item_info($dir,$item);
  54. $abs_new = get_item_info($dir,$newitemname);
  55. }
  56. if(@$GLOBALS['ext_File']->file_exists($abs_new)) {
  57. ext_Result::sendResult('rename', false, ext_TextEncoding::toUTF8($newitemname).": ".$GLOBALS["error_msg"]["itemdoesexist"]);
  58. }
  59. $perms_old = $GLOBALS['ext_File']->fileperms( $abs_old );
  60. $ok=$GLOBALS['ext_File']->rename( get_abs_item($dir,$item), get_abs_item($dir,$newitemname) );
  61. if( ext_isFTPMode()) {
  62. $abs_new = get_item_info($dir,$newitemname);
  63. }
  64. $GLOBALS['ext_File']->chmod( $abs_new, $perms_old );
  65. if($ok===false || PEAR::isError($ok)) {
  66. ext_Result::sendResult('rename', false, 'Could not rename '.$dir.'/'.$item.' to '.$newitemname);
  67. }
  68. $msg = sprintf( $GLOBALS['messages']['success_rename_file'], $item, $newitemname );
  69. ext_Result::sendResult('rename', true, $msg );
  70. }
  71. $is_dir = get_is_dir(ext_isFTPMode() ? get_item_info($dir,$item) : get_abs_item($dir,$item));
  72. ?>
  73. {
  74. "xtype": "form",
  75. "width": "350",
  76. "height": "150",
  77. "id": "simpleform",
  78. "labelWidth": 125,
  79. "url":"<?php echo basename( $GLOBALS['script_name']) ?>",
  80. "dialogtitle": "<?php echo $GLOBALS['messages']['rename_file'] ?>",
  81. "frame": true,
  82. "items": [{
  83. "xtype": "textfield",
  84. "fieldLabel": "<?php echo ext_Lang::msg( 'newname', true ) ?>",
  85. "name": "newitemname",
  86. "id": "newitemname",
  87. "value": "<?php echo str_replace("'", "\'", stripslashes($item) ) ?>",
  88. "width":175,
  89. "allowBlank":false
  90. }
  91. ],
  92. "listeners": { "afterrender": {
  93. fn: function( form ) {
  94. form.findById("newitemname").focus(true);
  95. }
  96. }
  97. },
  98. "buttons": [{
  99. "text": "<?php echo ext_Lang::msg( 'btnsave', true ) ?>",
  100. "handler": function() {
  101. statusBarMessage( 'Please wait...', true );
  102. form = Ext.getCmp("simpleform").getForm();
  103. form.submit({
  104. //reset: true,
  105. reset: false,
  106. success: function(form, action) {
  107. <?php
  108. if( $is_dir ) {
  109. ?>
  110. if( dirTree.getSelectionModel().getSelectedNode() ) {
  111. parentDir = dirTree.getSelectionModel().getSelectedNode().parentNode;parentDir.reload();parentDir.select();
  112. }
  113. <?php
  114. }
  115. ?>
  116. datastore.reload();
  117. statusBarMessage( action.result.message, false, true );
  118. Ext.getCmp("dialog").destroy();
  119. },
  120. failure: function(form, action) {
  121. if( !action.result ) return;
  122. Ext.MessageBox.alert('Error!', action.result.error);
  123. statusBarMessage( action.result.error, false, false );
  124. },
  125. scope: form,
  126. // add some vars to the request, similar to hidden fields
  127. params: {
  128. option: 'com_extplorer',
  129. action: 'rename',
  130. dir: '<?php echo stripslashes($dir) ?>',
  131. item: '<?php echo stripslashes($item) ?>',
  132. confirm: 'true'
  133. }
  134. });
  135. }
  136. },{
  137. "text": "<?php echo ext_Lang::msg( 'btncancel', true ) ?>",
  138. "handler": function() { Ext.getCmp("dialog").destroy(); }
  139. }]
  140. }
  141. <?php
  142. }
  143. }
  144. ?>