Source for file commands.php

Documentation is available at commands.php

  1. <?php 
  2. /*
  3.  * FCKeditor - The text editor for internet
  4.  * Copyright (C) 2003-2006 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: commands.php
  15.  *     This is the File Manager Connector for PHP.
  16.  * 
  17.  * File Authors:
  18.  *         Frederico Caldeira Knabben (fredck@fckeditor.net)
  19.  */
  20.  
  21. function GetFolders$resourceType$currentFolder )
  22. {
  23.     // Map the virtual path to the local server path.
  24.     $sServerDir ServerMapFolder$resourceType$currentFolder ;
  25.  
  26.     // Array that will hold the folders names.
  27.     $aFolders    array(;
  28.  
  29.     $oCurrentFolder opendir$sServerDir ;
  30.  
  31.     while $sFile readdir$oCurrentFolder ) )
  32.     {
  33.         if $sFile != '.' && $sFile != '..' && is_dir$sServerDir $sFile ) )
  34.             $aFolders['<Folder name="' ConvertToXmlAttribute$sFile '" />' ;
  35.     }
  36.  
  37.     closedir$oCurrentFolder ;
  38.  
  39.     // Open the "Folders" node.
  40.     echo "<Folders>" ;
  41.     
  42.     natcasesort$aFolders ;
  43.     foreach $aFolders as $sFolder )
  44.         echo $sFolder ;
  45.  
  46.     // Close the "Folders" node.
  47.     echo "</Folders>" ;
  48. }
  49.  
  50. function GetFoldersAndFiles$resourceType$currentFolder )
  51. {
  52.     // Map the virtual path to the local server path.
  53.     $sServerDir ServerMapFolder$resourceType$currentFolder ;
  54.  
  55.     // Arrays that will hold the folders and files names.
  56.     $aFolders    array(;
  57.     $aFiles        array(;
  58.  
  59.     $oCurrentFolder opendir$sServerDir ;
  60.  
  61.     while $sFile readdir$oCurrentFolder ) )
  62.     {
  63.         if $sFile != '.' && $sFile != '..' )
  64.         {
  65.             if is_dir$sServerDir $sFile ) )
  66.                 $aFolders['<Folder name="' ConvertToXmlAttribute$sFile '" />' ;
  67.             else
  68.             {
  69.                 $iFileSize filesize$sServerDir $sFile ;
  70.                 if $iFileSize )
  71.                 {
  72.                     $iFileSize round$iFileSize 1024 ;
  73.                     if $iFileSize $iFileSize ;
  74.                 }
  75.  
  76.                 $aFiles['<File name="' ConvertToXmlAttribute$sFile '" size="' $iFileSize '" />' ;
  77.             }
  78.         }
  79.     }
  80.  
  81.     // Send the folders
  82.     natcasesort$aFolders ;
  83.     echo '<Folders>' ;
  84.  
  85.     foreach $aFolders as $sFolder )
  86.         echo $sFolder ;
  87.  
  88.     echo '</Folders>' ;
  89.  
  90.     // Send the files
  91.     natcasesort$aFiles ;
  92.     echo '<Files>' ;
  93.  
  94.     foreach $aFiles as $sFiles )
  95.         echo $sFiles ;
  96.  
  97.     echo '</Files>' ;
  98. }
  99.  
  100. function CreateFolder$resourceType$currentFolder )
  101. {
  102.     $sErrorNumber    '0' ;
  103.     $sErrorMsg        '' ;
  104.  
  105.     if isset$_GET['NewFolderName') )
  106.     {
  107.         $sNewFolderName $_GET['NewFolderName';
  108.  
  109.         if strpos$sNewFolderName'..' !== FALSE )
  110.             $sErrorNumber '102' ;        // Invalid folder name.
  111.         else
  112.         {
  113.             // Map the virtual path to the local server path of the current folder.
  114.             $sServerDir ServerMapFolder$resourceType$currentFolder ;
  115.  
  116.             if is_writable$sServerDir ) )
  117.             {
  118.                 $sServerDir .= $sNewFolderName ;
  119.  
  120.                 $sErrorMsg CreateServerFolder$sServerDir ;
  121.  
  122.                 switch $sErrorMsg )
  123.                 {
  124.                     case '' :
  125.                         $sErrorNumber '0' ;
  126.                         break ;
  127.                     case 'Invalid argument' :
  128.                     case 'No such file or directory' :
  129.                         $sErrorNumber '102' ;        // Path too long.
  130.                         break ;
  131.                     default :
  132.                         $sErrorNumber '110' ;
  133.                         break ;
  134.                 }
  135.             }
  136.             else
  137.                 $sErrorNumber '103' ;
  138.         }
  139.     }
  140.     else
  141.         $sErrorNumber '102' ;
  142.  
  143.     // Create the "Error" node.
  144.     echo '<Error number="' $sErrorNumber '" originalDescription="' ConvertToXmlAttribute$sErrorMsg '" />' ;
  145. }
  146.  
  147. function FileUpload$resourceType$currentFolder )
  148. {
  149.     $sErrorNumber '0' ;
  150.     $sFileName '' ;
  151.  
  152.     if isset$_FILES['NewFile'&& !is_null$_FILES['NewFile']['tmp_name') )
  153.     {
  154.         global $Config ;
  155.  
  156.         $oFile $_FILES['NewFile';
  157.  
  158.         // Map the virtual path to the local server path.
  159.         $sServerDir ServerMapFolder$resourceType$currentFolder ;
  160.  
  161.         // Get the uploaded file name.
  162.         $sFileName $oFile['name';
  163.         
  164.         // Replace dots in the name with underscores (only one dot can be there... security issue).
  165.         if $Config['ForceSingleExtension')
  166.             $sFileName preg_replace'/\\.(?![^.]*$)/''_'$sFileName ;
  167.  
  168.         $sOriginalFileName $sFileName ;
  169.  
  170.         // Get the extension.
  171.         $sExtension substr$sFileNamestrrpos($sFileName'.') ) ;
  172.         $sExtension strtolower$sExtension ;
  173.  
  174.         $arAllowed    $Config['AllowedExtensions'][$resourceType;
  175.         $arDenied    $Config['DeniedExtensions'][$resourceType;
  176.  
  177.         if ( ( count($arAllowed== || in_array$sExtension$arAllowed ) ) && count($arDenied== || !in_array$sExtension$arDenied ) ) )
  178.         {
  179.             $iCounter ;
  180.  
  181.             while true )
  182.             {
  183.                 $sFilePath $sServerDir $sFileName ;
  184.  
  185.                 if is_file$sFilePath ) )
  186.                 {
  187.                     $iCounter++ ;
  188.                     $sFileName RemoveExtension$sOriginalFileName '(' $iCounter ').' $sExtension ;
  189.                     $sErrorNumber '201' ;
  190.                 }
  191.                 else
  192.                 {
  193.                     move_uploaded_file$oFile['tmp_name']$sFilePath ;
  194.  
  195.                     if is_file$sFilePath ) )
  196.                     {
  197.                         $oldumask umask(0;
  198.                         chmod$sFilePath0777 ;
  199.                         umask$oldumask ;
  200.                     }
  201.  
  202.                     break ;
  203.                 }
  204.             }
  205.         }
  206.         else
  207.             $sErrorNumber '202' ;
  208.     }
  209.     else
  210.         $sErrorNumber '202' ;
  211.  
  212.     echo '<script type="text/javascript">' ;
  213.     echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' $sErrorNumber ',"' str_replace'"''\\"'$sFileName '") ;' ;
  214.     echo '</script>' ;
  215.  
  216.     exit ;
  217. }
  218. ?>

Documentation generated on Sun, 09 Mar 2008 23:50:54 -0300 by phpDocumentor 1.4.0

SourceForge.net Logo Support This Project