[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/editors/mostlyce/jscripts/tiny_mce/filemanager/connectors/php/Commands/ -> CreateFolder.php (source)

   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   * File Name: CreateFolder.php
  13   *     Implements the CreateFolder command to make a new folder
  14   *     in the current directory. Output is in XML.
  15   * 
  16   * File Authors:
  17   *         Grant French (grant@mcpuk.net)
  18   */
  19  
  20  class CreateFolder {
  21      var $fckphp_config;
  22      var $type;
  23      var $cwd;
  24      var $actual_cwd;
  25      var $newfolder;
  26      
  27  	function CreateFolder($fckphp_config,$type,$cwd) {
  28          $this->fckphp_config=$fckphp_config;
  29          $this->type=$type;
  30          $this->raw_cwd=$cwd;
  31          $this->actual_cwd=str_replace("//","/",($this->fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd));
  32          $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd));
  33          if (isset($_GET['NewFolderName'])) {
  34              $this->newfolder=str_replace(array("..","/"),"",$_GET['NewFolderName']);
  35          } else {
  36              $this->newfolder='';
  37          }
  38      }
  39      
  40  	function checkFolderName($folderName) {
  41          
  42          $folderNameLength = strlen($folderName);
  43          //Check the name is not too long
  44          if ($folderNameLength==0 || ($folderNameLength>$this->fckphp_config['MaxDirNameLength'])) {
  45              return false;
  46          }
  47          
  48          //Check that it only contains valid characters
  49          for($i=0;$i<strlen($folderName);$i++) if (!in_array(substr($folderName,$i,1),$this->fckphp_config['DirNameAllowedChars'])) return false;
  50          
  51          //If it got this far all is ok
  52          return true;
  53      }
  54      
  55  	function run() {
  56          header ("content-type: text/xml");
  57          echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
  58          ?>
  59  <Connector command="CreateFolder" resourceType="<?php echo $this->type; ?>">
  60      <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" />
  61      <?php
  62          $newdir=str_replace("//","/",($this->real_cwd."/".$this->newfolder));
  63          
  64          //Check the new name
  65          if ($this->checkFolderName($this->newfolder)) {
  66              
  67              //Check if it already exists
  68              if (is_dir($newdir)) {
  69                  $err_no=101; //Folder already exists
  70              } else {
  71                  
  72                  //Check if we can create the directory here
  73                  if (is_writeable($this->real_cwd)) {
  74                      
  75                      //Make the directory
  76                      if (mkdir($newdir,0777)) {
  77                          $err_no=0; //Success
  78                      } else {
  79                      
  80                          $err_no=110; //Unknown error
  81                      }    
  82                  } else {
  83                      $err_no=103; //No permissions to create
  84                  }
  85              }
  86          } else {
  87              $err_no=102; //Invalid Folder Name
  88          }
  89          
  90      ?>
  91      <Error number="<?php echo "".$err_no; ?>" />
  92  </Connector>
  93          <?php
  94      }
  95  }
  96  
  97  ?>