Saturday, April 21, 2007

PHP Integration to FCKeditor

PHP Integration to FCKeditor:

It is very easy to use FCKeditor in your PHP web pages. All the
integration files are available in the official distributed package.
Just follow these steps.

Step 1

Suppose that the editor is installed in the /FCKeditor/ path of your
web site. The first thing to do is to include the "PHP Integration
Module" file in the top of your page, just like this:

include("FCKeditor/fckeditor.php");
?>

Step 2

Now the FCKeditor is available and ready to use. So, just insert the
following code in your page to create an instance of the editor
(usually inside a FORM):

$oFCKeditor = new FCKeditor('FCKeditor1');
$oFCKeditor->BasePath = '/FCKeditor/';
$oFCKeditor->Value = 'Default text in editor';
$oFCKeditor->Create();
?>

"FCKeditor1" is the name used to post the editor data on forms.

Step 3

The editor is now ready to be used. Just open the page in your browser
to see it at work.

The complete sample

include("FCKeditor/fckeditor.php") ;
?>


$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath = '/FCKeditor/';
$oFCKeditor->Value = 'Default text in editor';
$oFCKeditor->Create() ;
?>






Handling the posted data

The editor instance just created will behave like a normal
field in a form. It will use the name you've used when creating it (in
the above sample, "FCKeditor1").

So, to retrieve its value you can do something like this:

$sValue = stripslashes( $_POST['FCKeditor1'] ) ;

Samples

You can find some samples on how to use the editor in the "_samples/
php" directory of the distributed package.

Other info

If you want to retrieve the resulting HTML instead of outputting it
directly to the browser (for example if you're using it in a template
engine such as Smarty), you can call the "CreateHtml" method instead:

$output = $oFCKeditor->CreateHtml() ;

*

To change the size of the editor in the page, insert the
following code before calling the Create() or CreateHtml() methods:

$oFCKeditor->Width = '100%' ;
$oFCKeditor->Height = '200' ;

and just change the values to your needs.

* To modify configuration settings in a separate file outside the
editor's directory, add them to the Config property of the editor
object:

$oFCKeditor->Config['CustomConfigurationsPath'] = '/myconfig.js' ;

*

To set the path for saving uploaded files uncomment the
following line in /FCKeditor/editor/filemanager/browser/default/
connectors/php/config.php.
*

(do the same in /FCKeditor/editor/filemanager/upload/php/
config.php, at least in version 2.3)

// $Config['UserFilesPath'] = '/UserFiles/' ;

*

Depending on your version, you may also need to set
$Config['Enabled'] to true in /FCKeditor/editor/filemanager/browser/
default/connectors/php/config.php.
*

(do the same in /FCKeditor/editor/filemanager/upload/php/
config.php, at least in version 2.3)

// SECURITY: You must explicitly enable this "connector". (Set it to
"true").
$Config['Enabled'] = true ;

Note: Set the permission of the upload directory properly. You should
also uncomment the settings of LinkBrowserURL and the ImageBrowserURL
in the /FCKeditor_2.0fc/fckconfig.js file for the browsing and
uploading function to work properly.

Also set _FileBrowserLanguage and _QuickUploadLanguage to php in the
fckconfig.js file.

var _FileBrowserLanguage = 'php' ;
var _QuickUploadLanguage = 'php' ;

See Built-in File Browser for more information.

Important Note for PHP with Safe Mode activated: You'll have to
create /UserFiles/File, /UserFiles/Flash, /UserFiles/Image and /
UserFiles/Media in order for the filebrowser to work. Of course,
you'll also have to set the correct permissions for these directories.
Furthermore, don't use the "Create new folder" button. The folder
would be created but couldn't be used (Safe Mode restriction).

2 comments:

  1. thanks sanjeev's. your blog is very helpful for me .

    ReplyDelete
  2. Thanks...

    ReplyDelete