ActionApps PHP Cross Reference Groupware Applications

Source: /misc/htmlarea/plugins/ExtendedFileManager/Classes/ExtendedFileManager.php - 825 lines - 23080 bytes - Summary - Text - Print

Description: ExtendedFileManager, list images, directories, and thumbnails. Authors: Wei Zhuo, Afru, Krzysztof Kotowicz, Raimund Meyer Version: Updated on 08-01-2005 by Afru Version: Updated on 04-07-2006 by Krzysztof Kotowicz Version: Updated on 29-10-2006 by Raimund Meyer Package: ExtendedFileManager (EFM 1.1.3) http://www.afrusoft.com/htmlarea

   1  <?php
   2  /**

   3   * ExtendedFileManager, list images, directories, and thumbnails.

   4   * Authors: Wei Zhuo, Afru, Krzysztof Kotowicz, Raimund Meyer

   5   * Version: Updated on 08-01-2005 by Afru

   6   * Version: Updated on 04-07-2006 by Krzysztof Kotowicz

   7   * Version: Updated on 29-10-2006 by Raimund Meyer

   8   * Package: ExtendedFileManager (EFM 1.1.3)

   9   * http://www.afrusoft.com/htmlarea

  10   */
  11  
  12  /**

  13   * We use classes from ImageManager to avoid code duplication

  14   */
  15  require_once '../ImageManager/Classes/Files.php';
  16  
  17  /**

  18   * ExtendedFileManager Class.

  19   * @author $Author:ray $

  20   * @author $Author:ray $

  21   * @version $Id:ExtendedFileManager.php 957 2008-02-01 22:44:49Z ray $

  22   */
  23  class ExtendedFileManager 
  24  {
  25      /**

  26       * Configuration array.

  27       */
  28      var $config;
  29  
  30      /**

  31       * Array of directory information.

  32       */
  33      var $dirs;
  34      
  35      /**

  36       * Manager mode - image | link

  37       */
  38      var $mode;
  39  
  40      /**

  41       * Constructor. Create a new Image Manager instance.

  42       * @param array $config configuration array, see config.inc.php

  43       */
  44  	function ExtendedFileManager($config, $mode = null)
  45      {
  46          $this->config = $config;
  47          
  48          $this->mode = empty($mode) ? (empty($config['insert_mode']) ? 'image' : $config['insert_mode']): $mode;
  49      }
  50  
  51      /**

  52       * Get the base directory.

  53       * @return string base dir, see config.inc.php

  54       */
  55  	function getImagesDir()
  56      {
  57          if ($this->mode == 'link' && isset($this->config['files_dir']))
  58              Return $this->config['files_dir'];
  59          else Return $this->config['images_dir'];
  60      }
  61  
  62      /**

  63       * Get the base URL.

  64       * @return string base url, see config.inc.php

  65       */
  66  	function getImagesURL()
  67      {
  68          if ($this->mode == 'link' && isset($this->config['files_url']))
  69                  Return $this->config['files_url'];
  70          else Return $this->config['images_url'];
  71      }
  72  
  73  	function isValidBase()
  74      {
  75          return is_dir($this->getImagesDir());
  76      }
  77  
  78      /**

  79       * Get the tmp file prefix.

  80       * @return string tmp file prefix.

  81       */
  82  	function getTmpPrefix() 
  83      {
  84          Return $this->config['tmp_prefix'];
  85      }
  86  
  87      /**

  88       * Get the sub directories in the base dir.

  89       * Each array element contain

  90       * the relative path (relative to the base dir) as key and the 

  91       * full path as value.

  92       * @return array of sub directries

  93       * <code>array('path name' => 'full directory path', ...)</code>

  94       */
  95  	function getDirs() 
  96      {
  97          if(is_null($this->dirs))
  98          {
  99              $dirs = $this->_dirs($this->getImagesDir(),'/');
 100              ksort($dirs);
 101              $this->dirs = $dirs;
 102          }
 103          return $this->dirs;
 104      }
 105  
 106      /**

 107       * Recursively travese the directories to get a list

 108       * of accessable directories.

 109       * @param string $base the full path to the current directory

 110       * @param string $path the relative path name

 111       * @return array of accessiable sub-directories

 112       * <code>array('path name' => 'full directory path', ...)</code>

 113       */
 114  	function _dirs($base, $path) 
 115      {
 116          $base = Files::fixPath($base);
 117          $dirs = array();
 118  
 119          if($this->isValidBase() == false)
 120              return $dirs;
 121  
 122          $d = @dir($base);
 123          
 124          while (false !== ($entry = $d->read())) 
 125          {
 126              //If it is a directory, and it doesn't start with

 127              // a dot, and if is it not the thumbnail directory

 128              if(is_dir($base.$entry) 
 129                  && substr($entry,0,1) != '.'
 130                  && $this->isThumbDir($entry) == false) 
 131              {
 132                  $relative = Files::fixPath($path.$entry);
 133                  $fullpath = Files::fixPath($base.$entry);
 134                  $dirs[$relative] = $fullpath;
 135                  $dirs = array_merge($dirs, $this->_dirs($fullpath, $relative));
 136              }
 137          }
 138          $d->close();
 139  
 140          Return $dirs;
 141      }
 142  
 143      /**

 144       * Get all the files and directories of a relative path.

 145       * @param string $path relative path to be base path.

 146       * @return array of file and path information.

 147       * <code>array(0=>array('relative'=>'fullpath',...), 1=>array('filename'=>fileinfo array(),...)</code>

 148       * fileinfo array: <code>array('url'=>'full url', 

 149       *                       'relative'=>'relative to base', 

 150       *                        'fullpath'=>'full file path', 

 151       *                        'image'=>imageInfo array() false if not image,

 152       *                        'stat' => filestat)</code>

 153       */
 154  	function getFiles($path) 
 155      {
 156          $files = array();
 157          $dirs = array();
 158  
 159          $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions'];
 160  
 161          if($this->isValidBase() == false)
 162              return array($files,$dirs);
 163  
 164          $path = Files::fixPath($path);
 165          $base = Files::fixPath($this->getImagesDir());
 166          $fullpath = Files::makePath($base,$path);
 167  
 168  
 169          $d = @dir($fullpath);
 170          
 171          while (false !== ($entry = $d->read())) 
 172          {
 173              //not a dot file or directory

 174              if(substr($entry,0,1) != '.')
 175              {
 176                  if(is_dir($fullpath.$entry)
 177                      && $this->isThumbDir($entry) == false)
 178                  {
 179                      $relative = Files::fixPath($path.$entry);
 180                      $full = Files::fixPath($fullpath.$entry);
 181                      $count = $this->countFiles($full);
 182                      $dirs[$relative] = array('fullpath'=>$full,'entry'=>$entry,'count'=>$count, 'stat'=>stat($fullpath.$entry));
 183                  }
 184  
 185                  else if(is_file($fullpath.$entry) && $this->isThumb($entry)==false && $this->isTmpFile($entry) == false) 
 186                  {
 187                      $afruext = strtolower(substr(strrchr($entry, "."), 1));
 188  
 189                      if(in_array($afruext,$valid_extensions))
 190                      {
 191  
 192                          $file['url'] = Files::makePath($this->config['base_url'],$path).$entry;
 193                          $file['relative'] = $path.$entry;
 194                          $file['fullpath'] = $fullpath.$entry;
 195                          $img = $this->getImageInfo($fullpath.$entry);
 196                          if(!is_array($img)) $img[0]=$img[1]=0;
 197                          $file['image'] = $img;
 198                          $file['stat'] = stat($fullpath.$entry);
 199                          $file['ext'] = $afruext;
 200                          $files[$entry] = $file;
 201                      }
 202  
 203                  }
 204              }
 205          }
 206          $d->close();
 207          ksort($dirs);
 208          ksort($files);
 209          
 210          Return array($dirs, $files);
 211      }    
 212  
 213      /**

 214       * Count the number of files and directories in a given folder

 215       * minus the thumbnail folders and thumbnails.

 216       */
 217  	function countFiles($path) 
 218      {
 219          $total = 0;
 220  
 221          if(is_dir($path)) 
 222          {
 223              $d = @dir($path);
 224  
 225              while (false !== ($entry = $d->read())) 
 226              {
 227                  //echo $entry."<br>";

 228                  if(substr($entry,0,1) != '.'
 229                      && $this->isThumbDir($entry) == false
 230                      && $this->isTmpFile($entry) == false
 231                      && $this->isThumb($entry) == false) 
 232                  {
 233                      $total++;
 234                  }
 235              }
 236              $d->close();
 237          }
 238          return $total;
 239      }
 240  
 241      /**

 242       * Get image size information.

 243       * @param string $file the image file

 244       * @return array of getImageSize information, 

 245       *  false if the file is not an image.

 246       */
 247  	function getImageInfo($file) 
 248      {
 249          Return @getImageSize($file);
 250      }
 251  
 252      /**

 253       * Check if the file contains the thumbnail prefix.

 254       * @param string $file filename to be checked

 255       * @return true if the file contains the thumbnail prefix, false otherwise.

 256       */
 257  	function isThumb($file) 
 258      {
 259          $len = strlen($this->config['thumbnail_prefix']);
 260          if(substr($file,0,$len)==$this->config['thumbnail_prefix'])
 261              Return true;
 262          else
 263              Return false;
 264      }
 265  
 266      /**

 267       * Check if the given directory is a thumbnail directory.

 268       * @param string $entry directory name

 269       * @return true if it is a thumbnail directory, false otherwise

 270       */
 271  	function isThumbDir($entry) 
 272      {
 273          if($this->config['thumbnail_dir'] == false
 274              || strlen(trim($this->config['thumbnail_dir'])) == 0)
 275              Return false;        
 276          else
 277              Return ($entry == $this->config['thumbnail_dir']);
 278      }
 279  
 280      /**

 281       * Check if the given file is a tmp file.

 282       * @param string $file file name

 283       * @return boolean true if it is a tmp file, false otherwise

 284       */
 285  	function isTmpFile($file) 
 286      {
 287          $len = strlen($this->config['tmp_prefix']);
 288          if(substr($file,0,$len)==$this->config['tmp_prefix'])
 289              Return true;
 290          else
 291              Return false;         
 292      }
 293  
 294      /**

 295       * For a given image file, get the respective thumbnail filename

 296       * no file existence check is done.

 297       * @param string $fullpathfile the full path to the image file

 298       * @return string of the thumbnail file

 299       */
 300  	function getThumbName($fullpathfile) 
 301      {
 302          $path_parts = pathinfo($fullpathfile);
 303          
 304          $thumbnail = $this->config['thumbnail_prefix'].$path_parts['basename'];
 305  
 306          if($this->config['safe_mode'] == true
 307              || strlen(trim($this->config['thumbnail_dir'])) == 0)
 308          {
 309              Return Files::makeFile($path_parts['dirname'],$thumbnail);
 310          }
 311          else
 312          {
 313              if(strlen(trim($this->config['thumbnail_dir'])) > 0)
 314              {
 315                  $path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
 316                  if(!is_dir($path))
 317                      Files::createFolder($path);
 318                  Return Files::makeFile($path,$thumbnail);
 319              }
 320              else //should this ever happen?
 321              {
 322                  //error_log('ExtendedFileManager: Error in creating thumbnail name');

 323              }
 324          }
 325      }
 326      
 327      /**

 328       * Similar to getThumbName, but returns the URL, base on the

 329       * given base_url in config.inc.php

 330       * @param string $relative the relative image file name, 

 331       * relative to the base_dir path

 332       * @return string the url of the thumbnail

 333       */
 334  	function getThumbURL($relative) 
 335      {
 336          $path_parts = pathinfo($relative);
 337          $thumbnail = $this->config['thumbnail_prefix'].$path_parts['basename'];
 338          if($path_parts['dirname']=='\\') $path_parts['dirname']='/';
 339  
 340          if($this->config['safe_mode'] == true
 341              || strlen(trim($this->config['thumbnail_dir'])) == 0)
 342          {
 343              Return Files::makeFile($this->getImagesURL(),$thumbnail);
 344          }
 345          else
 346          {
 347              if(strlen(trim($this->config['thumbnail_dir'])) > 0)
 348              {
 349                  $path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
 350                  $url_path = Files::makePath($this->getImagesURL(), $path);
 351                  Return Files::makeFile($url_path,$thumbnail);
 352              }
 353              else //should this ever happen?
 354              {
 355                  //error_log('ExtendedFileManager: Error in creating thumbnail url');

 356              }
 357  
 358          }
 359      }
 360  
 361     /**

 362      * For a given image file, get the respective resized filename

 363      * no file existence check is done.

 364      * @param string $fullpathfile the full path to the image file

 365      * @param integer $width the intended width

 366      * @param integer $height the intended height

 367      * @param boolean $mkDir whether to attempt to make the resized_dir if it doesn't exist

 368      * @return string of the resized filename

 369      */
 370  	function getResizedName($fullpathfile, $width, $height, $mkDir = TRUE)
 371      {
 372          $path_parts = pathinfo($fullpathfile);
 373  
 374          $thumbnail = $this->config['resized_prefix']."_{$width}x{$height}_{$path_parts['basename']}";
 375  
 376          if( strlen(trim($this->config['resized_dir'])) == 0 || $this->config['safe_mode'] == true )
 377          {
 378              Return Files::makeFile($path_parts['dirname'],$thumbnail);
 379          }
 380          else
 381          {
 382        $path = Files::makePath($path_parts['dirname'],$this->config['resized_dir']);
 383        if($mkDir && !is_dir($path))
 384          Files::createFolder($path);
 385        Return Files::makeFile($path,$thumbnail);
 386          }
 387      }
 388  
 389      /**

 390       * Check if the given path is part of the subdirectories

 391       * under the base_dir.

 392       * @param string $path the relative path to be checked

 393       * @return boolean true if the path exists, false otherwise

 394       */
 395  	function validRelativePath($path) 
 396      {
 397          $dirs = $this->getDirs();
 398          if($path == '/')
 399              Return true;
 400          //check the path given in the url against the 

 401          //list of paths in the system.

 402          for($i = 0; $i < count($dirs); $i++)
 403          {
 404              $key = key($dirs);
 405              //we found the path

 406              if($key == $path)
 407                  Return true;
 408          
 409              next($dirs);
 410          }        
 411          Return false;
 412      }
 413  
 414      /**

 415       * Process uploaded files, assumes the file is in 

 416       * $_FILES['upload'] and $_POST['dir'] is set.

 417       * The dir must be relative to the base_dir and exists.

 418       * @return null

 419       */
 420  	function processUploads() 
 421      {
 422          if($this->isValidBase() == false)
 423              return;
 424  
 425          $relative = null;
 426  
 427          if(isset($_POST['dir'])) 
 428              $relative = rawurldecode($_POST['dir']);
 429          else
 430              return;
 431  
 432          //check for the file, and must have valid relative path

 433          if(isset($_FILES['upload']) && $this->validRelativePath($relative))
 434          {
 435              Return $this->_processFiles($relative, $_FILES['upload']);
 436          }
 437      }
 438  
 439      /**

 440       * Process upload files. The file must be an 

 441       * uploaded file. Any duplicate

 442       * file will be renamed. See Files::copyFile for details

 443       * on renaming.

 444       * @param string $relative the relative path where the file

 445       * should be copied to.

 446       * @param array $file the uploaded file from $_FILES

 447       * @return boolean true if the file was processed successfully, 

 448       * false otherwise

 449       */
 450  	function _processFiles($relative, $file)
 451      {
 452          
 453          if($file['error']!=0)
 454          {
 455              Return false;
 456          }
 457  
 458          if(!is_file($file['tmp_name']))
 459          {
 460              Return false;
 461          }
 462  
 463          if(!is_uploaded_file($file['tmp_name']))
 464          {
 465              Files::delFile($file['tmp_name']);
 466              Return false;
 467          }
 468  
 469          $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions'];
 470          $max_size = $this->mode == 'image' ? $this->config['max_filesize_kb_image'] : $this->config['max_filesize_kb_link'];
 471          $afruext = strtolower(substr(strrchr($file['name'], "."), 1));
 472  
 473          if(!in_array($afruext, $valid_extensions))
 474          {
 475              Files::delFile($file['tmp_name']);
 476              Return 'Cannot upload $extension='.$afruext.'$ Files. Permission denied.';
 477          }
 478  
 479          if($file['size']>($max_size*1024))
 480          {
 481              Files::delFile($file['tmp_name']);
 482              Return 'Unble to upload file. Maximum file size [$max_size='.$max_size.'$ KB] exceeded.';
 483          }
 484  
 485          if(!empty($this->config['max_foldersize_mb']) &&  (Files::dirSize($this->getImagesDir()))+$file['size']> ($this->config['max_foldersize_mb']*1048576))
 486          {
 487              Files::delFile($file['tmp_name']);
 488              Return ("Cannot upload. Maximum folder size reached. Delete unwanted files and try again.");
 489          }
 490  
 491          //now copy the file

 492          $path = Files::makePath($this->getImagesDir(),$relative);
 493          $result = Files::copyFile($file['tmp_name'], $path, $file['name']);
 494  
 495          //no copy error

 496          if(!is_int($result))
 497          {
 498              Files::delFile($file['tmp_name']);
 499              Return 'File "$file='.$file['name'].'$" successfully uploaded.';
 500          }
 501  
 502          //delete tmp files.

 503          Files::delFile($file['tmp_name']);
 504          Return false;
 505  
 506      }
 507  
 508  
 509  	function getDiskInfo()
 510      {
 511          if (empty($this->config['max_foldersize_mb']))
 512              return '';
 513              
 514          $tmpFreeSize=($this->config['max_foldersize_mb']*1048576)-Files::dirSize($this->getImagesDir());
 515  
 516          if(!is_numeric($tmpFreeSize) || $tmpFreeSize<0)    $tmpFreeSize=0;
 517          
 518          Return 'Total Size : $max_foldersize_mb='.$this->config['max_foldersize_mb'].'$ MB, Free Space: $free_space='.Files::formatSize($tmpFreeSize).'$';
 519      }
 520  
 521  
 522  
 523      /**

 524       * Get the URL of the relative file.

 525       * basically appends the relative file to the 

 526       * base_url given in config.inc.php

 527       * @param string $relative a file the relative to the base_dir

 528       * @return string the URL of the relative file.

 529       */
 530  	function getFileURL($relative) 
 531      {
 532          Return Files::makeFile($this->getImagesURL(),$relative);
 533      }
 534  
 535      /**

 536       * Get the fullpath to a relative file.

 537       * @param string $relative the relative file.

 538       * @return string the full path, .ie. the base_dir + relative.

 539       */
 540  	function getFullPath($relative) 
 541      {
 542          Return Files::makeFile($this->getImagesDir(),$relative);;
 543      }
 544  
 545      /**

 546       * Get the default thumbnail.

 547       * @return string default thumbnail, empty string if 

 548       * the thumbnail doesn't exist.

 549       */
 550  	function getDefaultThumb() 
 551      {
 552          if(is_file($this->config['default_thumbnail']))
 553              Return $this->config['default_thumbnail'];
 554          else 
 555              Return '';
 556      }
 557  
 558  
 559      /**

 560       * Checks image size. If the image size is less than default size

 561       * returns the original size else returns default size to display thumbnail

 562      */
 563  	function checkImageSize($relative)
 564      {
 565          $fullpath = Files::makeFile($this->getImagesDir(),$relative);
 566  
 567          $afruext = strtolower(substr(strrchr($relative, "."), 1));
 568          
 569          if(!in_array($afruext,$this->config['thumbnail_extensions']))
 570          {
 571              $imgInfo=array(0,0);
 572              Return $imgInfo;
 573          }
 574          else
 575          {
 576              $imgInfo = @getImageSize($fullpath);
 577              //not an image

 578              if(!is_array($imgInfo))
 579              {
 580                  $imgInfo=array(0,0);
 581                  Return $imgInfo;
 582              }
 583              else
 584              {
 585                  if($imgInfo[0] > $this->config['thumbnail_width'])
 586                  $imgInfo[0] = $this->config['thumbnail_width'];
 587  
 588                  if($imgInfo[1] > $this->config['thumbnail_height'])
 589                  $imgInfo[1] = $this->config['thumbnail_height'];
 590  
 591                  Return $imgInfo;
 592              }
 593          }
 594  
 595      }
 596  
 597  
 598      /**

 599       * Get the thumbnail url to be displayed. 

 600       * If the thumbnail exists, and it is up-to-date

 601       * the thumbnail url will be returns. If the 

 602       * file is not an image, a default image will be returned.

 603       * If it is an image file, and no thumbnail exists or 

 604       * the thumbnail is out-of-date (i.e. the thumbnail 

 605       * modified time is less than the original file)

 606       * then a thumbs.php?img=filename.jpg is returned.

 607       * The thumbs.php url will generate a new thumbnail

 608       * on the fly. If the image is less than the dimensions

 609       * of the thumbnails, the image will be display instead.

 610       * @param string $relative the relative image file.

 611       * @return string the url of the thumbnail, be it

 612       * actually thumbnail or a script to generate the

 613       * thumbnail on the fly.

 614       */
 615  	function getThumbnail($relative) 
 616      {
 617          global $IMConfig;
 618          
 619          $fullpath = Files::makeFile($this->getImagesDir(),$relative);
 620  
 621          //not a file???

 622          if(!is_file($fullpath))
 623              Return $this->getDefaultThumb();
 624  
 625          $afruext = strtolower(substr(strrchr($relative, "."), 1));
 626          
 627          if(!in_array($afruext,$this->config['thumbnail_extensions']))
 628          {
 629              if(is_file('icons/'.$afruext.'.gif')) 
 630                  Return('icons/'.$afruext.'.gif');
 631              else
 632                  Return $this->getDefaultThumb();
 633          }
 634  
 635          $imgInfo = @getImageSize($fullpath);
 636  
 637          //not an image

 638          if(!is_array($imgInfo))
 639              Return $this->getDefaultThumb();
 640  
 641  
 642          //Returning original image as thumbnail without Image Library by Afru

 643          if(!$this->config['img_library']) Return $this->getFileURL($relative);
 644  
 645  
 646          //the original image is smaller than thumbnails,

 647          //so just return the url to the original image.

 648          if ($imgInfo[0] <= $this->config['thumbnail_width']
 649           && $imgInfo[1] <= $this->config['thumbnail_height'])
 650              Return $this->getFileURL($relative);
 651  
 652          $thumbnail = $this->getThumbName($fullpath);
 653          
 654          //check for thumbnails, if exists and

 655          // it is up-to-date, return the thumbnail url

 656          if(is_file($thumbnail))
 657          {
 658              if(filemtime($thumbnail) >= filemtime($fullpath))
 659                  Return $this->getThumbURL($relative);
 660          }
 661  
 662          //well, no thumbnail was found, so ask the thumbs.php

 663          //to generate the thumbnail on the fly.

 664          Return $IMConfig['backend_url'] . '__function=thumbs&img='.rawurlencode($relative)."&mode=$this->mode";
 665      }
 666  
 667      /**

 668       * Delete and specified files.

 669       * @return boolean true if delete, false otherwise

 670       */
 671  	function deleteFiles() 
 672      {
 673          if(isset($_GET['delf']))
 674              return $this->_delFile(rawurldecode($_GET['delf']));
 675          return false;
 676      }
 677  
 678      /**

 679       * Delete and specified directories.

 680       * @return boolean true if delete, false otherwise

 681       */
 682  	function deleteDirs() 
 683      {
 684           if(isset($_GET['deld']))
 685              return $this->_delDir(rawurldecode($_GET['deld']));        
 686           else
 687               Return false;
 688      }
 689  
 690      /**

 691       * Delete the relative file, and any thumbnails.

 692       * @param string $relative the relative file.

 693       * @return boolean true if deleted, false otherwise.

 694       */
 695  	function _delFile($relative) 
 696      {
 697          $fullpath = Files::makeFile($this->getImagesDir(),$relative);
 698      
 699          $afruext = strtolower(substr(strrchr($relative, "."), 1));
 700  
 701          $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions'];
 702  
 703          if(!in_array($afruext,$valid_extensions))
 704          {
 705              return false;
 706          }
 707  
 708          //check that the file is an image

 709          if(is_array($this->getImageInfo($fullpath)))
 710          {
 711              $thumbnail = $this->getThumbName($fullpath);
 712              Files::delFile($thumbnail);
 713          }
 714  
 715          Return Files::delFile($fullpath);
 716      }
 717  
 718      /**

 719       * Delete directories recursively.

 720       * @param string $relative the relative path to be deleted.

 721       * @return boolean true if deleted, false otherwise.

 722       */
 723  	function _delDir($relative) 
 724      {
 725          $fullpath = Files::makePath($this->getImagesDir(),$relative);
 726      //    if($this->countFiles($fullpath) <= 0)

 727              return Files::delFolder($fullpath,true); //delete recursively.

 728          //else

 729              //Return false;

 730      }
 731  
 732      /**

 733       * Create new directories.

 734       * If in safe_mode, nothing happens.

 735       * @return boolean true if created, false otherwise.

 736       */
 737  	function processNewDir() 
 738      {
 739          if($this->config['safe_mode'] == true)
 740              Return false;
 741  
 742          if(isset($_GET['newDir']) && isset($_GET['dir']))
 743          {
 744              $newDir = rawurldecode($_GET['newDir']);
 745              $dir = rawurldecode($_GET['dir']);
 746              $path = Files::makePath($this->getImagesDir(),$dir);
 747              $fullpath = Files::makePath($path, Files::escape($newDir));
 748              if(is_dir($fullpath))
 749                  Return false;
 750  
 751              Return Files::createFolder($fullpath);
 752          }
 753      }
 754  
 755      /**

 756       * Renames files if certain GET variables are set

 757       * @return bool

 758       */
 759  	function processRenames()
 760      {
 761          if(!empty($_GET['rename']) && !empty($_GET['renameTo']))
 762          {
 763              // new file name (without path and extension)

 764              $newName = Files::escape(rawurldecode($_GET['renameTo']));
 765              $newName = str_replace('.', '', $newName);
 766  
 767              // path to file (from base images directory)

 768              $oldName = rawurldecode($_GET['rename']);
 769  
 770              // strip parent dir ("..") to avoid escaping from base directiory

 771              $oldName = preg_replace('#\.\.#', '', $oldName);
 772  
 773              if (is_dir($oldPath = Files::makeFile($this->getImagesDir(), $_GET['dir'].$oldName)))
 774              {
 775                  $newPath = Files::makeFile($this->getImagesDir(), $_GET['dir'].$newName);
 776                  return Files::rename($oldPath,$newPath);
 777              }
 778              else 
 779              {
 780                  // path to old file

 781                  $oldPath = Files::makeFile($this->getImagesDir(), $oldName);
 782      
 783                  $ret = Files::renameFile($oldPath, $newName);
 784                  if ($ret === true) {
 785                      // delete old thumbnail

 786                      Files::delFile($this->getThumbname($oldPath));
 787                  }
 788              }
 789              return $ret;
 790          }
 791          
 792          return null;
 793      }
 794  
 795  	function processPaste()
 796      {
 797          switch ($_GET['paste'])
 798          {
 799              case 'copyFile':
 800                  $src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']);
 801                  $file = $_GET['file'];
 802                  $dest = Files::makeFile($this->getImagesDir(), $_GET['dir']);
 803                  return Files::copyFile($src,$dest,$file);
 804              break;
 805              case 'copyDir':
 806                  $basePath = $this->getImagesDir();
 807                  $src = $_GET['srcdir'].$_GET['file'];
 808                  $dest = $_GET['dir'].$_GET['file'];
 809                  return Files::copyDir($basePath,$src,$dest);
 810              break;
 811              case 'moveFile':
 812                  $src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']);
 813                  $dest = Files::makeFile($this->getImagesDir(), $_GET['dir'].$_GET['file']);
 814                  return Files::rename($src,$dest);
 815              break;
 816              case 'moveDir':
 817                  $src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']);
 818                  $dest = Files::makeFile($this->getImagesDir(), $_GET['dir'].$_GET['file']);
 819                  return Files::rename($src,$dest);
 820              break;
 821          }
 822      }
 823  }
 824  
 825  ?>

title

Description

title

Description

title

Description

title

title

Body