From: Thyamad c. <th...@us...> - 2005-09-29 19:50:05
|
Update of /cvsroot/thyapi/thyapi/thywidgets/external/fckeditor/editor/filemanager/browser/mcpuk/connectors/php/Commands In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv563/thywidgets/external/fckeditor/editor/filemanager/browser/mcpuk/connectors/php/Commands Added Files: CreateFolder.php DeleteFile.php DeleteFolder.php FileUpload.php GetFolders.php GetFoldersAndFiles.php GetUploadProgress.php RenameFile.php RenameFolder.php Thumbnail.php Log Message: Commiting file additions and modification from SVN revision 2028 to 2029... Changes made by frank on 2005-09-29 21:42:57 +0200 (Thu, 29 Sep 2005) corresponding to SVN revision 2029 with message: updating fckeditor in dynapi --- NEW FILE: DeleteFolder.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: DeleteFolder.php * Implements the DeleteFolder command to delete a folder * in the current directory. Output is in XML. * * File Authors: * Grant French (gr...@mc...) */ class DeleteFolder { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $newfolder; function DeleteFolder($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($this->fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); $this->foldername=str_replace(array("..","/"),"",$_GET['FolderName']); } function run() { if ($this->delDir($this->real_cwd.'/'.$this->foldername)) { $err_no=0; } else { $err_no=402; } header ("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <Connector command="DeleteFolder" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <Error number="<?php echo "".$err_no; ?>" /> </Connector> <?php } function delDir($dir) { $dh=opendir($dir); if ($dh) { while ($entry=readdir($dh)) { if (($entry!=".")&&($entry!="..")) { if (is_dir($dir.'/'.$entry)) { $this->delDir($dir.'/'.$entry); } else { $thumb=$dir.'/.thumb_'.$entry; if (file_exists($thumb)) if (!unlink($thumb)) return false; if (!unlink($dir.'/'.$entry)) return false; } } } closedir($dh); return rmdir($dir); } else { return false; } } } ?> --- NEW FILE: RenameFile.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: RenameFile.php * Implements the DeleteFile command to delete a file * in the current directory. Output is in XML * * File Authors: * Grant French (gr...@mc...) */ class RenameFile { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $newfolder; function RenameFile($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); $this->filename=str_replace(array("..","/"),"",$_GET['FileName']); $this->newname=str_replace(array("..","/"),"",$this->checkName($_GET['NewName'])); } function checkName($name) { $newName=""; for ($i=0;$i<strlen($name);$i++) { if (in_array($name[$i],$this->fckphp_config['FileNameAllowedChars'])) $newName.=$name[$i]; } return $newName; } function run() { $result1=false; $result2=true; if ($this->newname!='') { if ($this->nameValid($this->newname)) { //Remove thumbnail if it exists $result2=true; $thumb=$this->real_cwd.'/.thumb_'.$this->filename; if (file_exists($thumb)) $result2=unlink($thumb); $result1=rename($this->real_cwd.'/'.$this->filename,$this->real_cwd.'/'.$this->newname); } else { $result1=false; } } header ("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <Connector command="RenameFile" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <?php if ($result1&&$result2) { $err_no=0; } else { $err_no=502; } ?> <Error number="<?php echo "".$err_no; ?>" /> </Connector> <?php } function nameValid($fname) { $type_config=$this->fckphp_config['ResourceAreas'][$this->type]; $lastdot=strrpos($fname,"."); if ($lastdot!==false) { $ext=substr($fname,($lastdot+1)); $fname=substr($fname,0,$lastdot); if (in_array(strtolower($ext),$type_config['AllowedExtensions'])) { return true; } else { return false; } } } } ?> --- NEW FILE: GetFoldersAndFiles.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: GetFoldersAndFiles.php * Implements the GetFoldersAndFiles command, to list * files and folders in the current directory. * Output is in XML * * File Authors: * Grant French (gr...@mc...) */ class GetFoldersAndFiles { var $fckphp_config; var $type; var $cwd; var $actual_cwd; function GetFoldersAndFiles($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); } function run() { header ("Content-Type: application/xml; charset=utf-8"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <!DOCTYPE Connector [ <?php include "dtd/iso-lat1.ent";?> <!ELEMENT Connector (CurrentFolder,Folders,Files)> <!ATTLIST Connector command CDATA "noname"> <!ATTLIST Connector resourceType CDATA "0"> <!ELEMENT CurrentFolder (#PCDATA)> <!ATTLIST CurrentFolder path CDATA "noname"> <!ATTLIST CurrentFolder url CDATA "0"> <!ELEMENT Folders (#PCDATA)> <!ELEMENT Folder (#PCDATA)> <!ATTLIST Folder name CDATA "noname_dir"> <!ELEMENT Files (#PCDATA)> <!ELEMENT File (#PCDATA)> <!ATTLIST File name CDATA "noname_file"> <!ATTLIST File size CDATA "0"> ] > <Connector command="GetFoldersAndFiles" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->fckphp_config['urlprefix'] . $this->actual_cwd; ?>" /> <Folders> <?php $files=array(); if ($dh=opendir($this->real_cwd)) { while (($filename=readdir($dh))!==false) { if (($filename!=".")&&($filename!="..")) { if (is_dir($this->real_cwd."/$filename")) { //check if$fckphp_configured not to show this folder $hide=false; for($i=0;$i<sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders']);$i++) $hide=(ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders'][$i],$filename)?true:$hide); if (!$hide) echo "\t\t<Folder name=\"$filename\" />\n"; } else { array_push($files,$filename); } } } closedir($dh); } echo "\t</Folders>\n"; echo "\t<Files>\n"; for ($i=0;$i<sizeof($files);$i++) { $lastdot=strrpos($files[$i],"."); $ext=(($lastdot!==false)?(substr($files[$i],$lastdot+1)):""); if (in_array(strtolower($ext),$this->fckphp_config['ResourceAreas'][$this->type]['AllowedExtensions'])) { //check if$fckphp_configured not to show this file $editable=$hide=false; for($j=0;$j<sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles']);$j++) $hide=(ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles'][$j],$files[$i])?true:$hide); if (!$hide) { if ($this->fckphp_config['ResourceAreas'][$this->type]['AllowImageEditing']) $editable=$this->isImageEditable($this->real_cwd."/".$files[$i]); echo "\t\t<File name=\"".htmlentities($files[$i])."\" size=\"".ceil(filesize($this->real_cwd."/".$files[$i])/1024)."\" editable=\"" . ( $editable?"1":"0" ) . "\" />\n"; } } } echo "\t</Files>\n"; echo "</Connector>\n"; } function isImageEditable($file) { $fh=fopen($file,"r"); if ($fh) { $start4=fread($fh,4); fclose($fh); $start3=substr($start4,0,3); if ($start4=="\x89PNG") { //PNG return (function_exists("imagecreatefrompng") && function_exists("imagepng")); } elseif ($start3=="GIF") { //GIF return (function_exists("imagecreatefromgif") && function_exists("imagegif")); } elseif ($start3=="\xFF\xD8\xFF") { //JPEG return (function_exists("imagecreatefromjpeg")&& function_exists("imagejpeg")); } elseif ($start4=="hsi1") { //JPEG return (function_exists("imagecreatefromjpeg")&& function_exists("imagejpeg")); } else { return false; } } else { return false; } } } ?> --- NEW FILE: FileUpload.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: FileUpload.php * Implements the FileUpload command, * Checks the file uploaded is allowed, * then moves it to the user data area. * * File Authors: * Grant French (gr...@mc...) */ class FileUpload { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $newfolder; function FileUpload($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($this->fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); } function cleanFilename($filename) { $n_filename=""; //Check that it only contains valid characters for($i=0;$i<strlen($filename);$i++) if (in_array(substr($filename,$i,1),$this->fckphp_config['FileNameAllowedChars'])) $n_filename.=substr($filename,$i,1); //If it got this far all is ok return $n_filename; } function run() { //If using CGI Upload script, get file info and insert into $_FILE array if ( (sizeof($_FILES)==0) && isset($_GET['file']) && isset($_GET['file']['NewFile']) && is_array($_GET['file']['NewFile']) ) { if (isset($_GET['file']['NewFile']['name'])&&$_GET['file']['NewFile']['size']&&$_GET['file']['NewFile']['tmp_name']) { $_FILES['NewFile']['name']=basename(str_replace("\\","/",$_GET['file']['NewFile']['name'])); $_FILES['NewFile']['size']=$_GET['file']['NewFile']['size']; $_FILES['NewFile']['tmp_name']=$_GET['file']['NewFile']['tmp_name']; } else { $disp="202,'Incomplete file information from upload CGI'"; } } // if (isset($_FILES['NewFile'])&&isset($_FILES['NewFile']['name'])&&($_FILES['NewFile']['name']!="")) // $_FILES['NewFile']['name']=$_FILES['NewFile']['name']; //$this->cleanFilename($_FILES['NewFile']['name']); $typeconfig=$this->fckphp_config['ResourceAreas'][$this->type]; header ("content-type: text/html"); if (sizeof($_FILES)>0) { if (array_key_exists("NewFile",$_FILES)) { if ($_FILES['NewFile']['size']<($typeconfig['MaxSize']*1024)) { $filename=basename(str_replace("\\","/",$_FILES['NewFile']['name'])); $lastdot=strrpos($filename,"."); if ($lastdot!==false) { $ext=substr($filename,($lastdot+1)); $filename=substr($filename,0,$lastdot); if (in_array(strtolower($ext),$typeconfig['AllowedExtensions'])) { $test=0; $dirSizes=array(); $globalSize=0; $failSizeCheck=false; if ($this->fckphp_config['DiskQuota']['Global']!=-1) { foreach ($this->fckphp_config['ResourceTypes'] as $resType) { $dirSizes[$resType]= $this->getDirSize( $this->fckphp_config['basedir']."/".$this->fckphp_config['UserFilesPath']."/$resType"); if ($dirSizes[$resType]===false) { //Failed to stat a directory, fall out $failSizeCheck=true; $msg="\\nUnable to determine the size of a folder."; break; } $globalSize+=$dirSizes[$resType]; } $globalSize+=$_FILES['NewFile']['size']; if (!$failSizeCheck) { if ($globalSize>($this->fckphp_config['DiskQuota']['Global']*1048576)) { $failSizeCheck=true; $msg="\\nYou are over the global disk quota."; } } } if (($typeconfig['DiskQuota']!=-1)&&(!$failSizeCheck)) { if ($this->fckphp_config['DiskQuota']['Global']==-1) { $dirSizes[$this->type]= $this->getDirSize( $this->fckphp_config['basedir']."/".$this->fckphp_config['UserFilesPath']."/".$this->type); } if (($dirSizes[$this->type]+$_FILES['NewFile']['size'])> ($typeconfig['DiskQuota']*1048576)) { $failSizeCheck=true; $msg="\\nYou are over the disk quota for this resource type."; } } if ((($this->fckphp_config['DiskQuota']['Global']!=-1)||($typeconfig['DiskQuota']!=-1))&&$failSizeCheck) { //Disk Quota over $disp="202,'Over disk quota, ".$msg."'"; } else { if (file_exists($this->real_cwd."/$filename.$ext")) { $taskDone=false; //File already exists, try renaming //If there are more than 200 files with // the same name giveup for ($i=1;(($i<200)&&($taskDone==false));$i++) { if (!file_exists($this->real_cwd."/$filename($i).$ext")) { if (is_uploaded_file($_FILES['NewFile']['tmp_name'])) { if (move_uploaded_file($_FILES['NewFile']['tmp_name'],($this->real_cwd."/$filename($i).$ext"))) { chmod(($this->real_cwd."/$filename($i).$ext"),0777); $disp="201,'..$filename($i).$ext'"; } else { $disp="202,'Failed to upload file, internal error.'"; } } else { if (rename($_FILES['NewFile']['tmp_name'],($this->real_cwd."/$filename($i).$ext"))) { chmod(($this->real_cwd."/$filename($i).$ext"),0777); $disp="201,'$filename($i).$ext'"; } else { $disp="202,'Failed to upload file, internal error.'"; } } $taskDone=true; } } if ($taskDone==false) { $disp="202,'Failed to upload file, internal error..'"; } } else { //Upload file if (is_uploaded_file($_FILES['NewFile']['tmp_name'])) { if (move_uploaded_file($_FILES['NewFile']['tmp_name'],($this->real_cwd."/$filename.$ext"))) { chmod(($this->real_cwd."/$filename.$ext"),0777); $disp="0"; } else { $disp="202,'Failed to upload file, internal error...'"; } } else { if (rename($_FILES['NewFile']['tmp_name'],($this->real_cwd."/$filename.$ext"))) { chmod(($this->real_cwd."/$filename.$ext"),0777); $disp="0"; } else { $disp="202,'Failed to upload file, internal error...'"; } } } } } else { //Disallowed file extension $disp="202,'Disallowed file type.'"; } } else { //No file extension to check $disp="202,'Unable to determine file type of file'"; } } else { //Too big $disp="202,'This file exceeds the maximum upload size.'"; } } else { //No file uploaded with field name NewFile $disp="202,'Unable to find uploaded file.'"; } } else { //No files uploaded //Should really send something back saying //invalid file, but this breaks the filemanager //with firefox, so for now we'll just exit exit(0); //$disp="202"; } ?> <html> <head> <title>Upload Complete</title> </head> <body> <script type="text/javascript"> window.parent.frames['frmUpload'].OnUploadCompleted(<?php echo $disp; ?>) ; </script> </body> </html> <?php } function getDirSize($dir) { $dirSize=0; if ($dh=@opendir($dir)) { while ($file=@readdir($dh)) { if (($file!=".")&&($file!="..")) { if (is_dir($dir."/".$file)) { $tmp_dirSize=$this->getDirSize($dir."/".$file); if ($tmp_dirSize!==false) $dirSize+=$tmp_dirSize; } else { $dirSize+=filesize($dir."/".$file); } } } @closedir($dh); } else { return false; } return $dirSize; } } ?> --- NEW FILE: CreateFolder.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: CreateFolder.php * Implements the CreateFolder command to make a new folder * in the current directory. Output is in XML. * * File Authors: * Grant French (gr...@mc...) */ class CreateFolder { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $newfolder; function CreateFolder($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($this->fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); $this->newfolder=str_replace(array("..","/"),"",$_GET['NewFolderName']); } function checkFolderName($folderName) { //Check the name is not too long if (strlen($folderName)>$this->fckphp_config['MaxDirNameLength']) return false; //Check that it only contains valid characters for($i=0;$i<strlen($folderName);$i++) if (!in_array(substr($folderName,$i,1),$this->fckphp_config['DirNameAllowedChars'])) return false; //If it got this far all is ok return true; } function run() { header ("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <Connector command="CreateFolder" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <?php $newdir=str_replace("//","/",($this->real_cwd."/".$this->newfolder)); //Check the new name if ($this->checkFolderName($this->newfolder)) { //Check if it already exists if (is_dir($newdir)) { $err_no=101; //Folder already exists } else { //Check if we can create the directory here if (is_writeable($this->real_cwd)) { //Make the directory if (mkdir($newdir,0777)) { $err_no=0; //Success } else { $err_no=110; //Unknown error } } else { $err_no=103; //No permissions to create } } } else { $err_no=102; //Invalid Folder Name } ?> <Error number="<?php echo "".$err_no; ?>" /> </Connector> <?php } } ?> --- NEW FILE: GetFolders.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: GetFolders.php * Implements the GetFolders command, to list the folders * in the current directory. Output is in XML * * File Authors: * Grant French (gr...@mc...) */ class GetFolders { var $fckphp_config; var $type; var $cwd; var $actual_cwd; function GetFolders($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); } function run() { header ("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <Connector command="GetFolders" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <Folders> <?php if ($dh=opendir($this->real_cwd)) { while (($filename=readdir($dh))!==false) { if (($filename!=".")&&($filename!="..")) { if (is_dir($this->real_cwd."/$filename")) { //check if$fckphp_configured not to show this folder $hide=false; for($i=0;$i<sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders']);$i++) $hide=(ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders'][$i],$filename)?true:$hide); if (!$hide) echo "<Folder name=\"$filename\" />\n"; } } } closedir($dh); } ?> </Folders> </Connector> <?php } } ?> --- NEW FILE: RenameFolder.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: RenameFolder.php * Implements the DeleteFile command to delete a file * in the current directory. Output is in XML * * File Authors: * Grant French (gr...@mc...) */ class RenameFolder { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $newfolder; function RenameFolder($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); $this->foldername=str_replace(array("..","/"),"",$_GET['FolderName']); $this->newname=str_replace(array("..","/"),"",$this->checkName($_GET['NewName'])); } function checkName($name) { $newName=""; for ($i=0;$i<strlen($name);$i++) { if (in_array($name[$i],$this->fckphp_config['DirNameAllowedChars'])) $newName.=$name[$i]; } return $newName; } function run() { $result1=false; if ($this->newname!='') { $result1=rename($this->real_cwd.'/'.$this->foldername,$this->real_cwd.'/'.$this->newname); } header ("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <Connector command="RenameFolder" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <?php if ($result1) { $err_no=0; } else { $err_no=602; } ?> <Error number="<?php echo "".$err_no; ?>" /> </Connector> <?php } } ?> --- NEW FILE: Thumbnail.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: Thumbnail.php * Implements the Thumbnail command, to return * a thumbnail to the browser for the sent file, * if the file is an image an attempt is made to * generate a thumbnail, otherwise an appropriate * icon is returned. * Output is image data * * File Authors: * Grant French (gr...@mc...) */ include "helpers/iconlookup.php"; class Thumbnail { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $filename; function Thumbnail($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); $this->filename=str_replace(array("..","/"),"",$_GET['FileName']); } function run() { //$mimeIcon=getMimeIcon($mime); $fullfile=$this->real_cwd.'/'.$this->filename; $thumbfile=$this->real_cwd.'/.thumb_'.$this->filename; $icon=false; if (file_exists($thumbfile)) { $icon=$thumbfile; } else { $mime=$this->getMIME($fullfile); $ext=strtolower($this->getExtension($this->filename)); if ($this->isImage($mime,$ext)) { //Try and find a thumbnail, else try to generate one // else send generic picture icon. if ($this->isJPEG($mime,$ext)) { $result=$this->resizeFromJPEG($fullfile); } elseif ($this->isGIF($mime,$ext)) { $result=$this->resizeFromGIF($fullfile); } elseif ($this->isPNG($mime,$ext)) { $result=$this->resizeFromPNG($fullfile); } if ($result!==false) { if (function_exists("imagejpeg")) { imagejpeg($result,$thumbfile,70); chmod($thumbfile,0777); $icon=$thumbfile; } elseif (function_exists("imagepng")) { imagepng($result,$thumbfile); chmod($thumbfile,0777); $icon=$thumbfile; } elseif (function_exists("imagegif")) { imagegif($result,$thumbfile); chmod($thumbfile,0777); $icon=$thumbfile; } else { $icon=iconLookup($mime,$ext); } } else { $icon=iconLookup($mime,$ext); } } else { $icon=iconLookup($mime,$ext); } } $iconMime=$this->image2MIME($icon); if ($iconMime==false) $iconMime="image/jpeg"; header("Content-type: $iconMime",true); readfile($icon); } function getMIME($file) { $mime="text/plain"; //If mime magic is installed if (function_exists("mime_content_type")) { $mime=mime_content_type($file); } else { $mime=$this->image2MIME($file); } return strtolower($mime); } function image2MIME($file) { $fh=fopen($file,"r"); if ($fh) { $start4=fread($fh,4); $start3=substr($start4,0,3); if ($start4=="\x89PNG") { return "image/png"; } elseif ($start3=="GIF") { return "image/gif"; } elseif ($start3=="\xFF\xD8\xFF") { return "image/jpeg"; } elseif ($start4=="hsi1") { return "image/jpeg"; } else { return false; } unset($start3);unset($start4); fclose($fh); } else { return false; } } function isImage($mime,$ext) { if ( ($mime=="image/gif")|| ($mime=="image/jpeg")|| ($mime=="image/jpg")|| ($mime=="image/pjpeg")|| ($mime=="image/png")|| ($ext=="jpg")|| ($ext=="jpeg")|| ($ext=="png")|| ($ext=="gif") ) { return true; } else { return false; } } function isJPEG($mime,$ext) { if (($mime=="image/jpeg")||($mime=="image/jpg")||($mime=="image/pjpeg")||($ext=="jpg")||($ext=="jpeg")) { return true; } else { return false; } } function isGIF($mime,$ext) { if (($mime=="image/gif")||($ext=="gif")) { return true; } else { return false; } } function isPNG($mime,$ext) { if (($mime=="image/png")||($ext=="png")) { return true; } else { return false; } } function getExtension($filename) { //Get Extension $ext=""; $lastpos=strrpos($this->filename,'.'); if ($lastpos!==false) $ext=substr($this->filename,($lastpos+1)); return strtolower($ext); } function resizeFromJPEG($file) { if (function_exists("imagecreatefromjpeg")) { $img=@imagecreatefromjpeg($this->real_cwd.'/'.$this->filename); return (($img)?$this->resizeImage($img):false); } else { return false; } } function resizeFromGIF($file) { if (function_exists("imagecreatefromgif")) { $img=@imagecreatefromgif($this->real_cwd.'/'.$this->filename); return (($img)?$this->resizeImage($img):false); } else { return false; } } function resizeFromPNG($file) { if (function_exists("imagecreatefrompng")) { $img=@imagecreatefrompng($this->real_cwd.'/'.$this->filename); return (($img)?$this->resizeImage($img):false); } else { return false; } } function resizeImage($img) { //Get size for thumbnail $width=imagesx($img); $height=imagesy($img); if ($width>$height) { $n_height=$height*(96/$width); $n_width=96; } else { $n_width=$width*(96/$height); $n_height=96; } $x=0;$y=0; if ($n_width<96) $x=round((96-$n_width)/2); if ($n_height<96) $y=round((96-$n_height)/2); $thumb=imagecreatetruecolor(96,96); #Background colour fix by: #Ben Lancaster (be...@st...) $bgcolor = imagecolorallocate($thumb,255,255,255); imagefill($thumb, 0, 0, $bgcolor); if (function_exists("imagecopyresampled")) { if (!($result=@imagecopyresampled($thumb,$img,$x,$y,0,0,$n_width,$n_height,$width,$height))) { $result=imagecopyresized($thumb,$img,$x,$y,0,0,$n_width,$n_height,$width,$height); } } else { $result=imagecopyresized($thumb,$img,$x,$y,0,0,$n_width,$n_height,$width,$height); } return ($result)?$thumb:false; } } ?> --- NEW FILE: DeleteFile.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: DeleteFile.php * Implements the DeleteFile command to delete a file * in the current directory. Output is in XML. * * File Authors: * Grant French (gr...@mc...) */ class DeleteFile { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $newfolder; function DeleteFile($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($this->fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); $this->filename=str_replace(array("..","/"),"",$_GET['FileName']); } function run() { $result1=false; $result2=true; $thumb=$this->real_cwd.'/.thumb_'.$this->filename; $result1=unlink($this->real_cwd.'/'.$this->filename); if (file_exists($thumb)) $result2=unlink($thumb); header ("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <Connector command="DeleteFile" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <?php if ($result1&&$result2) { $err_no=0; } else { $err_no=302; } ?> <Error number="<?php echo "".$err_no; ?>" /> </Connector> <?php } } ?> --- NEW FILE: GetUploadProgress.php --- <?php /* * FCKeditor - The text editor for internet * Copyright (C) 2003-2005 Frederico Caldeira Knabben * * Licensed under the terms of the GNU Lesser General Public License: * http://www.opensource.org/licenses/lgpl-license.php * * For further information visit: * http://www.fckeditor.net/ * * File Name: GetUploadProgress.php * Implements the GetFolders command, to list the folders * in the current directory. Output is in XML * * File Authors: * Grant French (gr...@mc...) */ class GetUploadProgress { var $fckphp_config; var $type; var $cwd; var $actual_cwd; var $uploadID; function GetUploadProgress($fckphp_config,$type,$cwd) { $this->fckphp_config=$fckphp_config; $this->type=$type; $this->raw_cwd=$cwd; $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd)); $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd)); $this->uploadID=$_GET['uploadID']; $this->refreshURL=$_GET['refreshURL']; } function run() { if (isset($this->refreshURL)&&($this->refreshURL!="")) { //Continue monitoring $uploadProgress=file($this->refreshURL); $url=$this->refreshURL; } else { //New download $uploadProgressHandler=$this->fckphp_config['uploadProgressHandler']; if ($uploadProgressHandler=='') { //Progresshandler not specified, return generic response ?> <Connector command="GetUploadProgress" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <Progress max="2" value="1" /> <RefreshURL url="" /> </Connector> <?php exit(0); } $url=$uploadProgressHandler."?iTotal=0&iRead=0&iStatus=1&sessionid=".$this->uploadID."&dtnow=".time()."&dtstart=".time(); $_SESSION[$this->uploadID]=$url; $uploadProgress=file($url); } $uploadProgress2=implode("\n",$uploadProgress); $parser = xml_parser_create(); xml_parse_into_struct($parser, $uploadProgress2, $vals, $index); $refreshURL=isset($vals[$index['REFRESHURL'][0]]['value'])?$vals[$index['REFRESHURL'][0]]['value']:""; $totalBytes=isset($vals[$index['TOTALBYTES'][0]]['value'])?$vals[$index['TOTALBYTES'][0]]['value']:0; $readBytes=isset($vals[$index['READBYTES'][0]]['value'])?$vals[$index['READBYTES'][0]]['value']:0; $status=isset($vals[$index['STATUS'][0]]['value'])?$vals[$index['STATUS'][0]]['value']:1; header ("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; ?> <Connector command="GetUploadProgress" resourceType="<?php echo $this->type; ?>"> <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" /> <Progress max="<?php echo $totalBytes; ?>" value="<?php echo $readBytes; ?>" /> <RefreshURL url="<?php echo htmlentities($refreshURL); ?>" /> </Connector> <?php xml_parser_free($parser); } } ?> |