dokeos
[ class tree: dokeos ] [ index: dokeos ] [ all elements ]

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-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: 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.         $oFile $_FILES['NewFile';
  155.  
  156.         // Map the virtual path to the local server path.
  157.         $sServerDir ServerMapFolder$resourceType$currentFolder ;
  158.  
  159.         // Get the uploaded file name.
  160.         $sFileName $oFile['name';
  161.         $sOriginalFileName $sFileName ;
  162.         $sExtension substr$sFileNamestrrpos($sFileName'.') ) ;
  163.         $sExtension strtolower$sExtension ;
  164.  
  165.         global $Config ;
  166.  
  167.         $arAllowed    $Config['AllowedExtensions'][$resourceType;
  168.         $arDenied    $Config['DeniedExtensions'][$resourceType;
  169.  
  170.         $perm api_get_setting('permissions_for_new_files');
  171.         $perm octdec(!empty($perm)?$perm:'0660');
  172.  
  173.         if ( ( count($arAllowed== || in_array$sExtension$arAllowed ) ) && count($arDenied== || !in_array$sExtension$arDenied ) ) )
  174.         {
  175.             $iCounter ;
  176.  
  177.             while true )
  178.             {
  179.                 $sFilePath $sServerDir $sFileName ;
  180.  
  181.                 if is_file$sFilePath ) )
  182.                 {
  183.                     $iCounter++ ;
  184.                     $sFileName RemoveExtension$sOriginalFileName '(' $iCounter ').' $sExtension ;
  185.                     $sErrorNumber '201' ;
  186.                 }
  187.                 else
  188.                 {
  189.                     move_uploaded_file$oFile['tmp_name']$sFilePath ;
  190.  
  191.                     if is_file$sFilePath ) )
  192.                     {
  193.                         $oldumask umask(0;
  194.                         chmod$sFilePath$perm ;
  195.                         umask$oldumask ;
  196.                     }
  197.  
  198.                     break ;
  199.                 }
  200.             }
  201.         }
  202.         else
  203.             $sErrorNumber '202' ;
  204.     }
  205.     else
  206.         $sErrorNumber '202' ;
  207.  
  208.     echo '<script type="text/javascript">' ;
  209.     echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' $sErrorNumber ',"' str_replace'"''\\"'$sFileName '") ;' ;
  210.     echo '</script>' ;
  211.  
  212.     exit ;
  213. }
  214. ?>

Documentation generated on Thu, 12 Jun 2008 13:08:05 -0500 by phpDocumentor 1.4.1