~ubuntu-branches/ubuntu/intrepid/moin/intrepid-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/filemanager/browser/mcpuk/connectors/php/Commands/RenameFile.php

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-02-14 16:09:24 UTC
  • mfrom: (0.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20060214160924-fyrx3gvknzqvt4vj
Tags: 1.5.2-1ubuntu1
Drop python2.3 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php 
2
 
/*
3
 
 * FCKeditor - The text editor for internet
4
 
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
5
 
 * 
6
 
 * Licensed under the terms of the GNU Lesser General Public License:
7
 
 *              http://www.opensource.org/licenses/lgpl-license.php
8
 
 * 
9
 
 * For further information visit:
10
 
 *              http://www.fckeditor.net/
11
 
 * 
12
 
 * "Support Open Source software. What about a donation today?"
13
 
 * 
14
 
 * File Name: RenameFile.php
15
 
 *      Implements the DeleteFile command to delete a file
16
 
 *      in the current directory. Output is in XML
17
 
 * 
18
 
 * File Authors:
19
 
 *              Grant French (grant@mcpuk.net)
20
 
 */
21
 
class RenameFile {
22
 
        var $fckphp_config;
23
 
        var $type;
24
 
        var $cwd;
25
 
        var $actual_cwd;
26
 
        var $newfolder;
27
 
        
28
 
        function RenameFile($fckphp_config,$type,$cwd) {
29
 
                $this->fckphp_config=$fckphp_config;
30
 
                $this->type=$type;
31
 
                $this->raw_cwd=$cwd;
32
 
                $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd));
33
 
                $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd));
34
 
                $this->filename=str_replace(array("..","/"),"",$_GET['FileName']);
35
 
                $this->newname=str_replace(array("..","/"),"",$this->checkName($_GET['NewName']));
36
 
        }
37
 
        
38
 
        function checkName($name) {
39
 
                $newName="";
40
 
                for ($i=0;$i<strlen($name);$i++) {
41
 
                        if (in_array($name[$i],$this->fckphp_config['FileNameAllowedChars'])) $newName.=$name[$i];
42
 
                }
43
 
                return $newName;
44
 
        }
45
 
        
46
 
        function run() {
47
 
                $result1=false;
48
 
                $result2=true;
49
 
                
50
 
                if ($this->newname!='') {
51
 
                
52
 
                        if ($this->nameValid($this->newname)) {
53
 
                                //Remove thumbnail if it exists
54
 
                                $result2=true;
55
 
                                $thumb=$this->real_cwd.'/.thumb_'.$this->filename;
56
 
                                if (file_exists($thumb)) $result2=unlink($thumb);
57
 
                                
58
 
                                $result1=rename($this->real_cwd.'/'.$this->filename,$this->real_cwd.'/'.$this->newname);
59
 
                        } else {
60
 
                                $result1=false;
61
 
                        }
62
 
                }
63
 
                
64
 
                header ("content-type: text/xml");
65
 
                echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
66
 
                ?>
67
 
<Connector command="RenameFile" resourceType="<?php echo $this->type; ?>">
68
 
        <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" />
69
 
        <?php
70
 
                if ($result1&&$result2) {
71
 
                        $err_no=0;
72
 
                } else {
73
 
                        $err_no=502;
74
 
                }
75
 
        ?>
76
 
        <Error number="<?php echo "".$err_no; ?>" />
77
 
</Connector>
78
 
                <?php
79
 
        }
80
 
        
81
 
        function nameValid($fname) {
82
 
                $type_config=$this->fckphp_config['ResourceAreas'][$this->type];
83
 
                
84
 
                $lastdot=strrpos($fname,".");
85
 
                        
86
 
                if ($lastdot!==false) {
87
 
                        $ext=substr($fname,($lastdot+1));
88
 
                        $fname=substr($fname,0,$lastdot);
89
 
                                
90
 
                        if (in_array(strtolower($ext),$type_config['AllowedExtensions'])) {
91
 
                                return true;
92
 
                        } else {
93
 
                                return false;
94
 
                        }
95
 
                }
96
 
        }
97
 
}
98
 
 
99
 
?>
 
 
b'\\ No newline at end of file'