Skip to content

Instantly share code, notes, and snippets.

@worthers
Created November 16, 2012 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save worthers/4086884 to your computer and use it in GitHub Desktop.
Save worthers/4086884 to your computer and use it in GitHub Desktop.
ckfinder 2.3 ftp support diff
diff -rP ckfinder_php_2.3/config.php ckfinder_php_2.3_ftp/config.php
87a88,94
> $config['Ftp'] = Array(
> 'host' => 'localhost',
> 'user' => '',
> 'pass' => '',
> 'path' => '',
> 'system_path' => $baseDir);
>
96c103
< 'directAccess' => false,
---
> 'directAccess' => true,
diff -rP ckfinder_php_2.3/core/connector/php/connector.php ckfinder_php_2.3_ftp/core/connector/php/connector.php
56a57
> require_once CKFINDER_CONNECTOR_LIB_DIR . "/Utils/Ftp.php";
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/CommandHandlerBase.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/CommandHandlerBase.php
14a15,16
> require_once CKFINDER_CONNECTOR_LIB_DIR . "/Utils/FtpEnabledBase.php";
>
30c32
< class CKFinder_Connector_CommandHandler_CommandHandlerBase
---
> class CKFinder_Connector_CommandHandler_CommandHandlerBase extends CKFinder_Connector_Utils_FtpEnabledBase
58a61,62
>
> parent::__construct();
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/CopyFiles.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/CopyFiles.php
201c201
< if (!@copy($sourceFilePath, $destinationFilePath)) {
---
> if (!$this->_ftp->copy($sourceFilePath, $destinationFilePath)) {
218c218
< if (!@copy($sourceFilePath, $destinationFilePath)) {
---
> if (!$this->_ftp->copy($sourceFilePath, $destinationFilePath)) {
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/CreateFolder.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/CreateFolder.php
71c71
< if (!is_writeable($this->_currentFolder->getServerPath())) {
---
> if (!$this->_ftp->is_writeable($this->_currentFolder->getServerPath())) {
83c83
< $bCreated = @mkdir($sServerDir, $perms);
---
> $bCreated = $this->_ftp->mkdir($sServerDir, $perms);
87c87
< $bCreated = @mkdir($sServerDir);
---
> $bCreated = $this->_ftp->mkdir($sServerDir);
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/DeleteFiles.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/DeleteFiles.php
137c137
< @unlink($thumbPath);
---
> $this->_ftp->unlink($thumbPath);
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/FileUpload.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/FileUpload.php
151c151
< if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
---
> if (false === $this->_ftp->move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
156c156
< @unlink($sFilePath);
---
> $this->_ftp->unlink($sFilePath);
160c160
< @unlink($sFilePath);
---
> $this->_ftp->unlink($sFilePath);
166c166
< chmod($sFilePath, $perms);
---
> $this->_ftp->chmod($sFilePath, $perms);
189c189
< @unlink($sFilePath);
---
> $this->_ftp->unlink($sFilePath);
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/MoveFiles.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/MoveFiles.php
190c190
< if (!@unlink($destinationFilePath)) {
---
> if (!$this->_ftp->unlink($destinationFilePath)) {
196c196
< if (!@rename($sourceFilePath, $destinationFilePath)) {
---
> if (!$this->_ftp->rename($sourceFilePath, $destinationFilePath)) {
223c223
< if (!@rename($sourceFilePath, $destinationFilePath)) {
---
> if (!$this->_ftp->rename($sourceFilePath, $destinationFilePath)) {
240c240
< if (!@rename($sourceFilePath, $destinationFilePath)) {
---
> if (!$this->_ftp->rename($sourceFilePath, $destinationFilePath)) {
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/RenameFile.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/RenameFile.php
104c104
< if (!is_writable(dirname($newFilePath))) {
---
> if (!$this->_ftp->is_writable(dirname($newFilePath))) {
108c108
< if (!is_writable($filePath)) {
---
> if (!$this->_ftp->is_writable($filePath)) {
116c116
< $bMoved = @rename($filePath, $newFilePath);
---
> $bMoved = $this->_ftp->rename($filePath, $newFilePath);
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/RenameFolder.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/RenameFolder.php
93c93
< $bMoved = @rename($oldFolderPath, $newFolderPath);
---
> $bMoved = $this->_ftp->rename($oldFolderPath, $newFolderPath);
99c99
< if (!@rename($this->_currentFolder->getThumbsServerPath(), $newThumbsServerPath)) {
---
> if (!$this->_ftp->rename($this->_currentFolder->getThumbsServerPath(), $newThumbsServerPath)) {
diff -rP ckfinder_php_2.3/core/connector/php/php5/CommandHandler/Thumbnail.php ckfinder_php_2.3_ftp/core/connector/php/php5/CommandHandler/Thumbnail.php
141a142,143
> $_ftp = new CKFinder_Connector_Utils_Ftp;
>
161c163
< copy($sourceFile, $targetFile);
---
> $_ftp->copy($sourceFile, $targetFile);
252a255,256
> ob_start();
>
256c260
< imagegif($oThumbImage, $targetFile);
---
> imagegif($oThumbImage);
260c264
< imagejpeg($oThumbImage, $targetFile, $quality);
---
> imagejpeg($oThumbImage, NULL, $quality);
263c267
< imagepng($oThumbImage, $targetFile);
---
> imagepng($oThumbImage);
266c270
< imagewbmp($oThumbImage, $targetFile);
---
> imagewbmp($oThumbImage);
268a273,278
>
> $r_file = tmpfile();
> fwrite($r_file,ob_get_clean());
> rewind($r_file);
> ftp_fput($_ftp->getConnection(),$_ftp->ftpPathFromServerPath($targetFile),$r_file,FTP_BINARY);
> fclose($r_file);
273c283
< chmod($targetFile, $perms);
---
> $_ftp->chmod($targetFile, $perms);
diff -rP ckfinder_php_2.3/core/connector/php/php5/Utils/FileSystem.php ckfinder_php_2.3_ftp/core/connector/php/php5/Utils/FileSystem.php
14a15,16
> require_once CKFINDER_CONNECTOR_LIB_DIR . "/Utils/Ftp.php";
>
150a153,154
> $_ftp = new CKFinder_Connector_Utils_Ftp;
>
158c162
< return @unlink($path);
---
> return $_ftp->unlink($path);
175c179
< if(!@rmdir($path)) {
---
> if(!$_ftp->rmdir($path)) {
461a466,467
> $_ftp = new CKFinder_Connector_Utils_Ftp;
>
472c478
< $bCreated = @mkdir($dir, $perms, true);
---
> $bCreated = $_ftp->mkdir($dir, $perms, true);
476c482
< $bCreated = @mkdir($dir, 0777, true);
---
> $bCreated = $_ftp->mkdir($dir, 0777, true);
diff -rP ckfinder_php_2.3/core/connector/php/php5/Utils/Ftp.php ckfinder_php_2.3_ftp/core/connector/php/php5/Utils/Ftp.php
0a1,113
> <?
> if (!defined('IN_CKFINDER')) exit;
>
> class CKFinder_Connector_Utils_Ftp
> {
> protected $r_connection,$s_ftpPath,$b_ftpLoggedIn;
>
> public function __construct () {
>
> static $r_connection;
>
> if (!is_resource($r_connection)) {
>
> // connect to FTP server and login
> $r_connection = ftp_connect($GLOBALS['config']['Ftp']['host']);
> $b_ftpLoggedIn = ftp_login($r_connection,$GLOBALS['config']['Ftp']['user'],$GLOBALS['config']['Ftp']['pass']);
>
> // change to ftp_path on FTP server
> ftp_chdir($r_connection,$GLOBALS['config']['Ftp']['path']);
> }
>
> $this->r_connection = $r_connection;
>
> // build filesystem path to ftp_path
> $this->s_ftpPath = $GLOBALS['config']['Ftp']['system_path'];
> }
>
> public function ftpPathFromServerPath ($s_path) {
>
> if (substr($s_path,0,strlen($this->s_ftpPath)) == $this->s_ftpPath) {
> return substr($s_path,strlen($this->s_ftpPath));
> } else {
> return false;
> }
> }
>
> public function rename ($oldname,$newname) {
>
> return @ftp_rename($this->r_connection,$this->ftpPathFromServerPath($oldname),$this->ftpPathFromServerPath($newname));
> }
>
> public function unlink ($file) {
>
> return @ftp_delete($this->r_connection,$this->ftpPathFromServerPath($file));
> }
>
> public function mkdir ($dir,$perms = null,$recursive = false) {
>
> if ($recursive) {
>
> $pwd = ftp_pwd($this->r_connection);
> if (@ftp_chdir($this->r_connection,$dir)) {
> ftp_chdir($this->r_connection,$pwd);
> $isDir = true;
> }
>
> if ($isDir || @ftp_mkdir($this->r_connection,$this->ftpPathFromServerPath($dir))) { return true; }
>
> if (!$this->mkdir(dirname($dir),null,true)) { return false; }
> }
>
> return @ftp_mkdir($this->r_connection,$this->ftpPathFromServerPath($dir));
> }
>
> public function rmdir ($dir) {
>
> return @ftp_rmdir($this->r_connection,$this->ftpPathFromServerPath($dir));
> }
>
> public function copy ($source,$dest) {
>
> $success = true;
>
> $r_file = tmpfile();
> if (!ftp_fget($this->r_connection,$r_file,$this->ftpPathFromServerPath($source),FTP_BINARY)) {
> $success = false;
> }
> rewind($r_file);
> if (!ftp_fput($this->r_connection,$this->ftpPathFromServerPath($dest),$r_file,FTP_BINARY)) {
> $success = false;
> }
> fclose($r_file);
>
> return $success;
> }
>
> public function move_uploaded_file ($filename,$destination) {
>
> $readable = is_readable($filename);
>
> if (!$readable) {
> global $s_pathToTemp;
> $tmpname = $s_pathToTemp . basename($filename);
> move_uploaded_file($filename,$tmpname);
> $filename = $tmpname;
> }
>
> $success = @ftp_put($this->r_connection,$this->ftpPathFromServerPath($destination),$filename,FTP_BINARY);
>
> if (!$readable) { unlink($tmpname); }
>
> return $success;
> }
>
> public function getConnection () {
>
> return $this->r_connection;
> }
>
> public function chmod () { return true; }
> public function is_writeable () { return true; }
> public function is_writable () { return true; }
> }
\ No newline at end of file
diff -rP ckfinder_php_2.3/core/connector/php/php5/Utils/FtpEnabledBase.php ckfinder_php_2.3_ftp/core/connector/php/php5/Utils/FtpEnabledBase.php
0a1,14
> <?
> if (!defined('IN_CKFINDER')) exit;
>
> require_once CKFINDER_CONNECTOR_LIB_DIR . "/Utils/Ftp.php";
>
> abstract class CKFinder_Connector_Utils_FtpEnabledBase {
>
> protected $_ftp;
>
> public function __construct () {
>
> $this->_ftp = new CKFinder_Connector_Utils_Ftp;
> }
> }
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment