FCKeditor4CMSimple - delete something in the filemanager

Questions about how to use the online - editors and suggestions how to improve them
Post Reply
priks
Posts: 3
Joined: Thu Jun 04, 2009 9:42 pm

FCKeditor4CMSimple - delete something in the filemanager

Post by priks » Thu Jun 04, 2009 11:07 pm

Hello

I have a problem in relation to the FCKeditor4CMSimple (http://www.webdeerns.de/?FCKeditor4CMSimple).
It works fine but some guys know the problem that it isn't possible to delete an uploaded file (image or whatever) without using an ftp client.
I really want to use the FCKe because it's very fast and offers more tools. So i found this helpful page http://peter-rehm.de/plugin/tag/fck. It helps adding the delete function for the normal version of FCKeditor. I hope you can understand the content of the page. At the end you can see my translation.

In general exactly what i've searched for. But now there's one little conflict :x
There are just two files to change:

frmresourceslist.html

LOCATION

FCKeditor - editor/filemanager/browser/default/
FCKeditor4CMSimple - editor/filemanager/browser/default/

no problem

commands.php

LOCATION

FCKeditor - editor/filemanager/browser/default/connectors/
FCKeditor4CMSimple - editor/filemanager/connectors/php

problem!



option 1)
I nevertheless change the file in the directory "php"
--> FCKeditor works but there is no delete-option (image delete.gif isn't there)

option 2)
I move the directory connectors to
editor/filemanager/browser/default/
--> FCKeditor works, filemanager doesn't work


My question is now:
Can somebody write a working tutorial for me?






Tutorial from http://peter-rehm.de/plugin/tag/fck

1.) create an ICON in
CODE:
editor/filemanager/browser/default/images/delete.gif


2.) change the file frmresourceslist.html
CODE:
editor/filemanager/browser/default/frmresourceslist.html


search the line:
CODE:
var sLink = '<a href="#" onclick="OpenFile(\'' + fileUrl + '\');return false;">' ;


add following line:
CODE:
// Added by Bramus!
var dLink = '<a href="#" title="Delete file" onclick="DeleteFile(\'' + escape(fileName) + '\');return false;">' ;



Replace following block...:
CODE:
return '<tr>' +
'<td width="16">' +
sLink +
'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"></a>' +
'</td><td>&nbsp;' +
sLink +
fileName +
'</a>' +
'</td><td align="right" nowrap>&nbsp;' +
fileSize +
' KB' +
'</td></tr>' ;


...with this one.
CODE:
return '<tr>' +
'<td width="35">' +
sLink +
'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"></a>' +
dLink + '<img alt="" src="images/delete.gif" width="16" height="16" border="0"></a>' +
'</td><td>&nbsp;' +
sLink +
fileName +
'</a>' +
'</td><td align="right" nowrap>&nbsp;' +
fileSize +
' KB' +
'</td></tr>' ;


At the end of this file you see this block.
CODE:
window.onload = function()
{
window.top.IsLoadedResourcesList = true ;
}


Add following block above!
CODE:
// Added by Bramus!
function DeleteFile( fileName, fileUrl ) {
if (confirm('Are you sure you wish to delete ' + unescape(fileName) + '?')) {
oConnector.SendCommand( 'DeleteFile', "FileName=" + fileName, DeleteFileCallBack ) ;
}
}

// Added by Bramus!
function DeleteFileCallBack ( fckXml ) {
var oNodes = fckXml.SelectNodes( 'Connector/Error' );
if (oNodes!=null && oNodes.length>0) {
var errNo = parseInt(oNodes[0].attributes.getNamedItem('number').value) ;
switch (errNo) {
case 0 :
break;
case 102 :
case 103 :
alert(oNodes[0].attributes.getNamedItem('originalDescription').value);
break;
default:
alert('DFi: Invalid XML response from connector..');
}
} else {
alert('DFi: Invalid XML response from connector.');
}
Refresh();
}


3.) Now open the file commands.php
CODE:
editor/filemanager/browser/default/connectors/commands.php


copy following code in front of the ?>.
CODE:
function DeleteFile($resourceType, $currentFolder) {
$sErrorNumber = '0' ;
$sErrorMsg = '' ;

if ( isset( $_GET['FileName'] ) ) {

// Map the virtual path to the local server path.
$sServerDir = ServerMapFolder( $resourceType, $currentFolder ) ;

$sFileName = $_GET['FileName'] ;

if ( strpos( $sFileName, '..' ) !== FALSE ) {
$sErrorNumber = '102' ; // Invalid file name.
$sErrorMsg = 'Invalid file name';
} else {
if ( @unlink($sServerDir.$sFileName) ) {
$sErrorNumber = '0' ; // deleted
} else {
$sErrorNumber = '103' ; // not deleted
$sErrorMsg = 'Could not delete file '.$sServerDir.$sFileName;
}
}
} else {
$sErrorNumber = '102' ; // no file set
$sErrorMsg = 'No file specified';
}

// Create the "Error" node.
echo '<Error number="' . $sErrorNumber . '" originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />' ;
}


4.) Customizing the Connector
In the Connector you have to customize the switch statement
CODE:
editor/filemanager/browser/default/connectors/commands.php


Just add this case below the others:
CODE:
case 'DeleteFile' :
DeleteFile( $sResourceType, $sCurrentFolder ) ;
break ;


In version 2.4.3 it should look like this.
CODE:
// Execute the required command.
switch ( $sCommand )
{
case 'GetFolders' :
GetFolders( $sResourceType, $sCurrentFolder ) ;
break ;
case 'GetFoldersAndFiles' :
GetFoldersAndFiles( $sResourceType, $sCurrentFolder ) ;
break ;
case 'CreateFolder' :
CreateFolder( $sResourceType, $sCurrentFolder ) ;
break ;

case 'DeleteFile' :
DeleteFile( $sResourceType, $sCurrentFolder ) ;
break ;

}

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: FCKeditor4CMSimple - delete something in the filemanager

Post by Holger » Fri Jun 05, 2009 8:49 am

Hi priks,

the hack from the link you've posted is thought for an older version of FCKeditor so it's not working without changes.
I think it should be better to replace the inbuild "Filemanager" with an advanced one.
So there's no need to hack core files with every update.

A good replacement is the AjaxFile/Image-Manager from phpletter.com:
http://www.phpletter.com/Demo/FCKeditor ... e-Manager/

WBR
Holger

Post Reply