ANIL KUMAR PANIGRAHI 's Blog

How to integrate fckeditor in smarty application?

Posted by: Anil Kumar Panigrahi in: ● November 26, 2009

Integration of fckeditor in smarty application

1 . in libs\plugins write the foolowing file called function.fckeditor.php

<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/

/**
* Smarty function plugin
* Requires PHP >= 4.3.0
* ————————————————————-
* Type: function
* Name: fckeditor
* Version: 1.0
* Author: gazoot (gazoot care of gmail dot com)
* Purpose: Creates a FCKeditor, a very powerful textarea replacement.
* ————————————————————-
* @param InstanceName Editor instance name (form field name)
* @param BasePath optional Path to the FCKeditor directory. Need only be set once on page. Default: /FCKeditor/
* @param Value optional data that control will start with, default is taken from the javascript file
* @param Width optional width (css units)
* @param Height optional height (css units)
* @param ToolbarSet optional what toolbar to use from configuration
* @param CheckBrowser optional check the browser compatibility when rendering the editor
* @param DisplayErrors optional show error messages on errors while rendering the editor
*
* Default values for optional parameters (except BasePath) are taken from fckeditor.js.
*
* All other parameters used in the function will be put into the configuration section,
* CustomConfigurationsPath is useful for example.
* See http://wiki.fckeditor.net/Developer%27s_Guide/Configuration/Configurations_File for more configuration info.
*/
function smarty_function_fckeditor($params, &$smarty)
{
if(!isset($params['InstanceName']) || empty($params['InstanceName']))
{
$smarty->trigger_error(‘fckeditor: required parameter “InstanceName” missing’);
}

static $base_arguments = array();
static $config_arguments = array();

// Test if editor has been loaded before
if(!count($base_arguments)) $init = TRUE;
else $init = FALSE;

// BasePath must be specified once.
if(isset($params['BasePath']))
{
$base_arguments['BasePath'] = $params['BasePath'];
}
else if(empty($base_arguments['BasePath']))
{
$base_arguments['BasePath'] = ‘/FCKeditor/’;
}

$base_arguments['InstanceName'] = $params['InstanceName'];

if(isset($params['Value']))
$base_arguments['Value'] = $params['Value'];
else
$base_arguments['Value'] = ”;

if(isset($params['Width'])) $base_arguments['Width'] = $params['Width'];
if(isset($params['Height'])) $base_arguments['Height'] = $params['Height'];
if(isset($params['ToolbarSet'])) $base_arguments['ToolbarSet'] = $params['ToolbarSet'];
if(isset($params['CheckBrowser'])) $base_arguments['CheckBrowser'] = $params['CheckBrowser'];
if(isset($params['DisplayErrors'])) $base_arguments['DisplayErrors'] = $params['DisplayErrors'];

// Use all other parameters for the config array (replace if needed)
$other_arguments = array_diff_assoc($params, $base_arguments);
$config_arguments = array_merge($config_arguments, $other_arguments);

$out = ”;

if($init)
{
$out .= ‘<script type=”text/javascript” src=”‘ . $base_arguments['BasePath'] . ‘fckeditor.js”></script>’;
}

$out .= “\n<script type=\”text/javascript\”>\n”;
$out .= “var oFCKeditor = new FCKeditor(‘” . $base_arguments['InstanceName'] . “‘);\n”;

foreach($base_arguments as $key => $value)
{
if(!is_bool($value))
{
// Fix newlines, javascript cannot handle multiple line strings very well.
$value = ‘”‘ . preg_replace(“/[\r\n]+/”, ‘” + $0″‘, addslashes($value)) . ‘”‘;
}
$out .= “oFCKeditor.$key = $value; “;
}

foreach($config_arguments as $key => $value)
{
if(!is_bool($value))
{
$value = ‘”‘ . preg_replace(“/[\r\n]+/”, ‘” + $0″‘, addslashes($value)) . ‘”‘;
}
$out .= “oFCKeditor.Config[\"$key\"] = $value; “;
}

$out .= “\noFCKeditor.Create();\n”;
$out .= “</script>\n”;

return $out;
}

/* vim: set expandtab: */

?>

2 download the fckeditor from the http://www.fckeditor.net/ and save it in the smarty folder

3 in the php file we include the fckeditor.php file

4 in the tpl file we write the following code

{fckeditor BasePath=”../includes/fckeditor/” InstanceName=”news_desc” Width=”650px” Height=”300px” Value=”$news_desc”}

Share on Twitter

4 Comments to "How to integrate fckeditor in smarty application?"

1 | How to integrate fckeditor in smarty application? « ANIL KUMAR … Scripts Rss

27 de November de 2009 to ● 3:03 am

[...] posted here: How to integrate fckeditor in smarty application? « ANIL KUMAR … By admin | category: Object, Smarty | tags: file-called, foolowing, integrate-fckeditor, [...]

2 | jagoanweb

23 de December de 2009 to ● 8:18 am

mmm…
do you know about create captcha using PHP?
actually i have to apply it to my toko online :)

3 | Jim Li

1 de February de 2010 to ● 4:23 am

@anil2u nice post!
@jagoanweb checkout http://www.phpcaptcha.org/, i used it on several occasions, pretty configurable and easy to use.

4 | toufeeq ahmad

16 de July de 2010 to ● 5:21 am

How to integrate fckeditor in smarty application

Write Comment

About Me

  Anil Kumar Panigrahi
  Software Engineer (PHP)
  Blogger & Founder of Anil Labs
  Baruva, India

You can share with me . . .

My Own Contributions

1) First contribution for codeigniter framework ( multi language support using google translate API ). we can get files from http://github.com/nyros/codeigniter_multilanguage


2) Audio and Video Streaming using FFMpeg and PHP -complete doc file : http://www.docstoc.com/docs/8300349/Audio-and-Video-Streaming

Twitter Updates

Follow me @anil2u
  • We will always be thankful to our teacher for all the hard work and efforts they have put in, for educating us.- Happy teachers Day . . . :) - posted on 05/09/2010 05:39:13
  • Working on shipping cost functionality (UPS and USPS) for oscommerce shopping cart - posted on 01/09/2010 09:40:03
  • If your freedom hurts others, you are not free. You must not hurt others. - Vivekananda - posted on 31/08/2010 06:02:49
  • Another day starts with full of energy . Good Morning - posted on 31/08/2010 02:54:12
  • Nice explanation about php oops concept : http://youropensource.com/projects/182-OOPS-Concepts-in-PHP - posted on 30/08/2010 19:56:17