Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Plugin for FCKeditor
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
gazoot
Smarty Regular


Joined: 20 Feb 2005
Posts: 35

PostPosted: Fri May 05, 2006 12:22 pm    Post subject: Plugin for FCKeditor Reply with quote

Hello, just finished a function plugin for the excellent FCKeditor (a textarea replacement), so I thought I would share the effort. It's used as any other function, and I think the documentation explains what you need to know. What you need from the fckeditor package is only the fckeditor.js implementation, no PHP or any other languages.

More info about the editor here: http://www.fckeditor.net/
Installation instructions: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Installation

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

/**
* Smarty function plugin
* Requires PHP >= 4.3.0
* -------------------------------------------------------------
* Type:     function
* Name:     fckeditor
* Version:  1.1
* 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: /js/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://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options 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
   $init = count($base_arguments) == 0;
   
   // BasePath must be specified once.
   if(isset($params['BasePath']))
   {
      $base_arguments['BasePath'] = $params['BasePath'];
   }
   else if(empty($base_arguments['BasePath']))
   {
      $base_arguments['BasePath'] = '/js/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))
      {
         $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;
}

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: */


Good luck, and let me know if you have any questions!


/Gazoot


Last edited by gazoot on Thu Nov 06, 2008 10:42 pm; edited 3 times in total
Back to top
View user's profile Send private message
webvivekar
Smarty Rookie


Joined: 21 Oct 2003
Posts: 8

PostPosted: Sat May 20, 2006 7:15 am    Post subject: Reply with quote

Hi,

Do you have any demo page?
It would be helpful if you show how to use this in the code.

Thank you.
Back to top
View user's profile Send private message
JOat
Smarty Rookie


Joined: 02 Sep 2004
Posts: 10

PostPosted: Thu May 25, 2006 11:05 am    Post subject: Reply with quote

mmmmm i dont get the fileupload working.

the upload for PHP is enabled ...

the dir. looks like this:

FCKeditor
libs
templates
templates_c
UserFiles

the USerFiles dir. has 777 but i can not upload ....
Back to top
View user's profile Send private message
gazoot
Smarty Regular


Joined: 20 Feb 2005
Posts: 35

PostPosted: Fri May 26, 2006 11:03 am    Post subject: Example smarty code Reply with quote

Hi webvivekar, sorry for the long reply time. There isn't any demo page because the code would be very short. Smile If you install FCKeditor properly (in /javascripts/fckeditor for this example), all you need to do in smarty to create an editor is this:

Code:
<html>
<body>
Here's a nice FCKeditor for you:<br>
{fckeditor BasePath="/javascripts/fckeditor/" InstanceName="test" Width="650px" Height="300px"}
</body>
</html>


Note that /javascripts/fckeditor must be in the webserver root. This is how a properly installed FCKeditor dir could look like:

/javascripts/fckeditor/
..
editor

fckconfig.js
fckeditor.js
fckstyles.xml
fcktemplates.xml

/javascripts/fckeditor/editor
..
css
dialog
filemanager

fckblank.html
fckeditor.html
... other files and dirs ...

I left out some files in the /javascripts/fckeditor/editor dir (and all files below of course), but you see how the structure should be, right?
Let me know if something is unclear. Good luck!

/Gazoot
Back to top
View user's profile Send private message
lucky1977
Smarty n00b


Joined: 31 May 2006
Posts: 1

PostPosted: Wed May 31, 2006 10:06 am    Post subject: Reply with quote

thank you very much, your plugin is very very good.
I'm writing a CMS for my company and this plugin is that I musted have.
I'm sorry for my english but i'm begin study english 5 month ago.

Bye
Luca
Back to top
View user's profile Send private message
wjdennen
Smarty Rookie


Joined: 23 Oct 2004
Posts: 24

PostPosted: Fri Jun 09, 2006 3:10 pm    Post subject: Reply with quote

This is great.

Is it possible for one to have a custom set of toolbars, using this plugin?

Edit:

Ah, this works:

Code:
{fckeditor BasePath="/javascripts/FCKeditor/" InstanceName="test" Width="650px" Height="300px" ToolbarSet="Basic"}
Back to top
View user's profile Send private message
cope
Smarty n00b


Joined: 22 Jun 2006
Posts: 1

PostPosted: Thu Jun 22, 2006 10:16 am    Post subject: Reply with quote

i'm abs. noob at smarty.
I've created libs/plugins/function.fckeditor.php and pasted the above code in.
how do i call it in php? i've googled, and found jack squat!

thats the error i get.

Code:

Error: FCKeditor is not defined
Source File: http://dev/nfia/index2.php
Line: 6


my php is
[php:1:279f302faf]
<?
include ('includes/libs/Smarty.class.php');

$smarty = new Smarty();
$smarty->compile_check = true;

$smarty->display('hello.tpl');
?>
[/php:1:279f302faf]

and template
Code:

<html>
<body>
Here's a nice FCKeditor for you:<br>
{fckeditor BasePath="/fckeditor/" InstanceName="test" Width="650px" Height="300px"}
</body>
</html>
Back to top
View user's profile Send private message
gazoot
Smarty Regular


Joined: 20 Feb 2005
Posts: 35

PostPosted: Wed Jul 12, 2006 7:18 am    Post subject: Reply with quote

Hi cope, just saw your question about the problem you have. Any progress? I'm not sure what could be the problem, it could be as simple as a filename misspelling or that you put the file in the wrong place. Your code seems right.


/Gazoot
Back to top
View user's profile Send private message
mjs
Smarty Rookie


Joined: 13 May 2006
Posts: 9
Location: Lithuania, Vilnius

PostPosted: Fri Aug 04, 2006 2:07 pm    Post subject: Reply with quote

Maybe somebody can help?
http://www.phpinsider.com/smarty-forum/viewtopic.php?p=33050#33050
Back to top
View user's profile Send private message Visit poster's website
flourishing
Smarty Rookie


Joined: 15 Oct 2005
Posts: 6

PostPosted: Sat Aug 05, 2006 4:53 pm    Post subject: Reply with quote

cope wrote:
i'm abs. noob at smarty.
I've created libs/plugins/function.fckeditor.php and pasted the above code in.
how do i call it in php? i've googled, and found jack squat!

thats the error i get.

Code:

Error: FCKeditor is not defined
Source File: http://dev/nfia/index2.php
Line: 6


my php is
[php:1:340c19fdf3]
<?
include ('includes/libs/Smarty.class.php');

$smarty = new Smarty();
$smarty->compile_check = true;

$smarty->display('hello.tpl');
?>
[/php:1:340c19fdf3]

and template
Code:

<html>
<body>
Here's a nice FCKeditor for you:<br>
{fckeditor BasePath="/fckeditor/" InstanceName="test" Width="650px" Height="300px"}
</body>
</html>


something wrong , and i test it .
$smarty = new Smarty(); here should be $smarty = new Smarty;
$smarty->compile_check = true;
add this :
$smarty->template_dir = '.';
$smarty->compile_dir = '/tmp';
$smarty->display('hello.tpl');

fckeditor and this php file should be in same directory.
and default fckeditor name should be FCKeditor. so if you just tar zxvf the source tar.gz ,you should modify hello.tpl set dir name FCKeditor.

now it should works
Back to top
View user's profile Send private message MSN Messenger
Psyche
Smarty Regular


Joined: 16 Apr 2006
Posts: 35

PostPosted: Wed Aug 16, 2006 7:30 am    Post subject: Reply with quote

I'm using this plugin and FCKeditor but I don't get any display? What's going wrong?
Back to top
View user's profile Send private message
bogdan_t3
Smarty n00b


Joined: 20 Aug 2006
Posts: 1

PostPosted: Sun Aug 20, 2006 4:43 pm    Post subject: Reply with quote

Cope,

Instead of
{fckeditor BasePath="/fckeditor/" InstanceName="test" Width="650px" Height="300px"}

try using

{fckeditor BasePath="fckeditor/" InstanceName="test" Width="650px" Height="300px"}

That did the trick for me.. Good luck!
Back to top
View user's profile Send private message
reivax
Smarty n00b


Joined: 28 Dec 2006
Posts: 1
Location: Luxemburg

PostPosted: Thu Dec 28, 2006 7:27 am    Post subject: save plugin Reply with quote

hello, i have fout the plugin yesterday. but i have 2 little problems, the first one is to save the data, in witch variable is it saven?

if im using:
<form action="{$currpage}" enctype="multipart/form-data">{fckeditor BasePath="FCKeditor/" InstanceName="editor" Width="100%" Height="90%"}</form>

he gives me back the form data in the link line but this is not optimal, without the form tag he doesent even do nothing.

the second problem is with the images the browser works wihout any problems, but he doesent schows me the images while i selectet them.
image folder: /UserFiles/img
themplate folder: /browsers/ff/default/...

thanx

Reivax
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
unextmandy
Smarty n00b


Joined: 19 Jan 2007
Posts: 3

PostPosted: Fri Jan 19, 2007 8:55 pm    Post subject: Reply with quote

I'm also having problems with the plugin, and I can't figure out what I am doing wrong. I have to work with someone else to install stuff (I don't have permission), so it could be a path issue, but I'm just not sure.

Here is what I have in my template:
{fckeditor BasePath="/includes/lib/FCKeditor/" InstanceName="test" Width="650px" Height="300px"}

No errors, but the only thing that shows up is text that says "Source Style Format Font Size". Underneath there is apparently a text box with no borders, because I can type in the empty space.

I tried re-adding all of the files in FCKEditor to cvs, but it doesn't seem to make a difference.

Help?

Embarassed
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Mon Jan 22, 2007 2:28 pm    Post subject: Reply with quote

BasePath parameter indicates the path to where the FCKeditor lib files are..

This needs to be the web-readable path..

e.g. If FCK is accessible via: http://domain.com/javascript/fck/fckeditor.js

Then you would set your BasePath as: BasePath="/javascript/fck/"
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
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