View previous topic :: View next topic |
Author |
Message |
gazoot Smarty Regular
Joined: 20 Feb 2005 Posts: 35
|
Posted: Fri May 05, 2006 12:22 pm Post subject: Plugin for FCKeditor |
|
|
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 |
|
webvivekar Smarty Rookie
Joined: 21 Oct 2003 Posts: 8
|
Posted: Sat May 20, 2006 7:15 am Post subject: |
|
|
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 |
|
JOat Smarty Rookie
Joined: 02 Sep 2004 Posts: 10
|
Posted: Thu May 25, 2006 11:05 am Post subject: |
|
|
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 |
|
gazoot Smarty Regular
Joined: 20 Feb 2005 Posts: 35
|
Posted: Fri May 26, 2006 11:03 am Post subject: Example smarty code |
|
|
Hi webvivekar, sorry for the long reply time. There isn't any demo page because the code would be very short. 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 |
|
lucky1977 Smarty n00b
Joined: 31 May 2006 Posts: 1
|
Posted: Wed May 31, 2006 10:06 am Post subject: |
|
|
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 |
|
wjdennen Smarty Rookie
Joined: 23 Oct 2004 Posts: 24
|
Posted: Fri Jun 09, 2006 3:10 pm Post subject: |
|
|
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 |
|
cope Smarty n00b
Joined: 22 Jun 2006 Posts: 1
|
Posted: Thu Jun 22, 2006 10:16 am Post subject: |
|
|
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 |
|
gazoot Smarty Regular
Joined: 20 Feb 2005 Posts: 35
|
Posted: Wed Jul 12, 2006 7:18 am Post subject: |
|
|
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 |
|
mjs Smarty Rookie
Joined: 13 May 2006 Posts: 9 Location: Lithuania, Vilnius
|
|
Back to top |
|
flourishing Smarty Rookie
Joined: 15 Oct 2005 Posts: 6
|
Posted: Sat Aug 05, 2006 4:53 pm Post subject: |
|
|
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 |
|
Psyche Smarty Regular
Joined: 16 Apr 2006 Posts: 35
|
Posted: Wed Aug 16, 2006 7:30 am Post subject: |
|
|
I'm using this plugin and FCKeditor but I don't get any display? What's going wrong? |
|
Back to top |
|
bogdan_t3 Smarty n00b
Joined: 20 Aug 2006 Posts: 1
|
Posted: Sun Aug 20, 2006 4:43 pm Post subject: |
|
|
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 |
|
reivax Smarty n00b
Joined: 28 Dec 2006 Posts: 1 Location: Luxemburg
|
Posted: Thu Dec 28, 2006 7:27 am Post subject: save plugin |
|
|
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 |
|
unextmandy Smarty n00b
Joined: 19 Jan 2007 Posts: 3
|
Posted: Fri Jan 19, 2007 8:55 pm Post subject: |
|
|
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?
|
|
Back to top |
|
TGKnIght Smarty Junkie
Joined: 07 Sep 2005 Posts: 580 Location: Philadelphia, PA
|
|
Back to top |
|
|