Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

FCKit: FCKeditor The Next Generation

Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
Smarty Regular

Joined: 03 Sep 2007
Posts: 84

PostPosted: Mon Jul 19, 2010 3:14 pm    Post subject: FCKit: FCKeditor The Next Generation Reply with quote

This plugin was made for people like me, who use ajax with smarty. The plugin by Gazoot does not work while using AJAX, so I created FCKit!

The purpose of this function, is to create an FCKeditor region inside your form. It has 2 inclusion processes. You can leave Inclusion NULL and it will include via the normal javascript inclusion method created by Gazoot.

If you wish to have the PHP inclusion method you would have set Inclusion="PHP" in your instance.

I'm sure there are some more options I need to include into the PHP inclusion method (as far as configurability goes), but here is V.1.0 ready and working for your viewing pleasure!

 * Smarty Plugin
 * @package Smarty
 * @subpackage plugins
  * Smarty Function Plugin
  * Requires PHP >= 4.3.0
  * ------------------------------------------------------------------------------
  * Type:      Functions
  * Name:       fckit
  * Version:   1.0
  * Author:      ucntkilme
  * Credit:      All of the javascript inclusion, as well as all of the other functions, credit to gazoot or anyone he wishes to credit.
  *          I have only added in another param, and created the ability to include via PHP or JS.  Nothing more. 
  * Purpose:   To create a FCKeditor inclusion using either PHP or Javascript depending on your current wants, desires or capabilities.
  * -------------------------------------------------------------------------------------
  * @param InstanceName Editor Instance Name (form field name)
  * @param BasePath optional Path to the FCKeditor directory, need only be set once on page.
  * @param Value optional data that control will start with
  * @param Width optional (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
  * @param Inclusion optional, PHP or JS - default is JS
  * Default Values for optional parameters (except BasePath) are taken from fckeditor.js or fckeditor.php
  * All other parameters used in this function will be put into the configuration section,
  * CustomConfigurationsPath is useful for example.
  * See for more configuration info.
 function smarty_function_fckit($params, &$smarty) {
     if(!isset($params['InstanceName']) || empty($params['InstanceName'])) {
        $smarty->trigger_error('fckit: required parameter "InstanceName" missing');
     static $base_arguments = array();
     static $config_argument = array();
     $init = count($base_arguments);
     if(isset($params['BasePath'])) {
        $base_arguments['BasePath'] = $params['BasePath'];
     }else if(empty($base_arguments['BasePath'])) {
        $base_arguments['BasePath'] = '../inc/fckeditor/';
     $base_arguments['InstanceName'] = $params['InstanceName'];
        $base_arguments['Value'] = $params['Value'];
        $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['ToolbarSet'];
      if(isset($params['DisplayErrors'])) $base_arguments['DisplayErrors'] = $params['DisplayErrors'];
      if(!isset($params['Inclusion']) || empty($params['Inclusion']) || $params['Inclusion'] == 'JS') {
          $out = '';
          $out .= '<script type="text/javascript" src="../inc/fckeditor/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)) {
                  $value = '"' . fck_escapejschars($value) . '"';
               $out .= "oFCKeditor.$key = $value; ";
         foreach($config_arguments as $key => $value) {
            if(!is_bool($value)) {
               $value = '"' . fck_escapejschars($value) . '"';
            $out .= "oFCKeditor.Config[\"$key\"] = $value; ";
         $out .= "\noFCKeditor.Create();\n";
            $out .= "</script>\n";
          return $out;
      }else if(isset($params['Inclusion']) && $params['Inclusion'] == 'PHP') {
         $oFCKeditor = new FCKeditor($base_arguments['InstanceName']);
         $oFCKeditor->BasePath = $base_arguments['BasePath'];
         $oFCKeditor->InstanceName = $base_arguments['InstanceName'];
         $oFCKeditor->Height = $base_arguments['Height'];
         $oFCKeditor->Width = $base_arguments['Width'];
         $oFCKeditor->ToolbarSet = $base_arguments['ToolbarSet'];
         $oFCKeditor->Value = $base_arguments['Value'];
         $out = $oFCKeditor->CreateHTML();
         return $out;
      } else {
         $smarty->trigger_error('fckeditor: invalid inclusion type "'.$params['Inclusion'].'" PHP or JS are only allowed.');
function fck_escapejschars($str)
    $str = mb_ereg_replace("\\\\", "\\\\", $str);
    $str = mb_ereg_replace("\"", "\\\"", $str);
    $str = mb_ereg_replace("'", "\\'", $str);
    $str = mb_ereg_replace("\r\n", "\\n", $str);
    $str = mb_ereg_replace("\r", "\\n", $str);
    $str = mb_ereg_replace("\n", "\\n", $str);
    $str = mb_ereg_replace("\t", "\\t", $str);
    $str = mb_ereg_replace("<", "\\x3C", $str); // for inclusion in HTML
    $str = mb_ereg_replace(">", "\\x3E", $str);

    return $str;
/* vim: set expandtab: */


{fckit BasePath="../inc/fckeditor/" InstanceName="about" Width="90%" Height="400px" ToolbarSet="Default" Inclusion="PHP" Value=$data}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP