#####
# FCKeditor - The text editor for internet
# Copyright (C) 2003-2005 Frederico Caldeira Knabben
#
# Licensed under the terms of the GNU Lesser General Public License:
# http://www.opensource.org/licenses/lgpl-license.php
#
# For further information visit:
# http://www.fckeditor.net/
#
# File Name: FCKeditor.pm
# This is the integration file for Perl.
#
# File Authors:
# Takashi Yamaguchi (jack@omakase.net)
#
# Modified and made into a package by:
# Doug Bierer (doug@unlikelysource.com)
#
# Usage:
# 1. Put this command at the top of your PERL program:
#
# use FCKeditor;
#
# 2. Where you want to place the FCKeditor in your output,
# call FCKeditor::create() as follows:
#
# $html_string = FCKeditor::create($InstanceName,$BasePath);
#
# This will produce an HTML string which effectively replaces
# a <textarea name=$InstanceName></textarea> field in your form.
# Note that there are a few other parameters which you can
# specify in the create() call, noted below. Height and
# width, for example.
#
# You can then integrate this HTML code directly into your
# Output. For example:
#
# use FCKeditor;
# print 'content-type: text/html\n\n';
# print '<html><body><form method=get action="this.pl">';
# print '<p>Enter Your Message Here:</p>';
# print FCKeditor::create();
# print '<input type=submit name="OK" value="OK">';
# print '</form></body></html>';
#
# Or you could send the string to the Template module,
# depending on how you output your HTML. Your return CGI
# program will then look for a parameter "editor", which is
# the default (see $InstanceName).
#
#####
package FCKeditor;
require Exporter;
#---------------------------------------------------------------------------------
our $VERSION = 0.01;
our @ISA = ("Exporter");
our @EXPORT = qw(
&FCKeditor
&Create
&specialchar_cnv
&CreateHtml
&IsCompatible
&GetConfigFieldString
&new
);
our %EXPORT_TAGS = ( );
our @EXPORT_OK = qw(
$InstanceName
$BasePath
$Width
$Height
$ToolbarSet
$Value
%Config
);
use vars qw(
$InstanceName
$BasePath
$Width
$Height
$ToolbarSet
$Value
%Config
);
#---------------------------------------------------------------------------------
# Initialize Globals
$InstanceName = 'editor';
$BasePath = './FCKeditor/';
$Height = '400';
$Width = '100%';
$ToolbarSet = 'Default';
$Value = '';
%Config = ( );
#---------------------------------------------------------------------------------
#
# Inputs: $InstanceName = the <textarea> field you want to replace with FCKeditor output
# $BasePath = the directory where the FCKeditor files reside
# $Height = height you want FCKeditor to reach
# $Width = width you wish FCKeditor to take
# $ToolbarSet = any special set of tools
# $Value = ???
#
# Outputs: An HTML string which implements FCKeditor
#
sub Create
{
$InstanceName = shift;
$BasePath = shift;
$Height = shift;
$Width = shift;
$ToolbarSet = shift;
$Value = shift;
# Check to see if null and reset to original values
if ( !$InstanceName ) { $InstanceName = "editor"; }
if ( !$BasePath ) { $BasePath = './FCKeditor/'; }
if ( !$Height ) { $Height = '400'; }
if ( !$Width ) { $Width = '100%'; }
if ( !$ToolbarSet ) { $ToolbarSet = 'Default'; }
return &CreateHtml();
}
sub specialchar_cnv
{
local($ch) = @_;
$ch =~ s/&/&/g; # &
$ch =~ s/\"/"/g; #"
$ch =~ s/\'/'/g; # '
$ch =~ s/</</g; # <
$ch =~ s/>/>/g; # >
return($ch);
}
sub CreateHtml
{
$HtmlValue = &specialchar_cnv($Value);
$Html = '<div>' ;
if(&IsCompatible()) {
$Link = $BasePath . "editor/fckeditor.html?InstanceName=$InstanceName";
if($ToolbarSet ne '') {
$Link .= "&Toolbar=$ToolbarSet";
}
#// Render the linked hidden field.
$Html .= "<input type=\"hidden\" id=\"$InstanceName\" name=\"$InstanceName\" value=\"$HtmlValue\" />" ;
#// Render the configurations hidden field.
$cfgstr = &GetConfigFieldString();
$wk = $InstanceName."___Config";
$Html .= "<input type=\"hidden\" id=\"$wk\" value=\"$cfgstr\" />" ;
#// Render the editor IFRAME.
$wk = $InstanceName."___Frame";
$Html .= "<iframe id=\"$wk\" src=\"$Link\" width=\"$Width\" height=\"$Height\" frameborder=\"no\" scrolling=\"no\"></iframe>";
} else {
if($Width =~ /\%/g){
$WidthCSS = $Width;
} else {
$WidthCSS = $Width . 'px';
}
if($Height =~ /\%/g){
$HeightCSS = $Height;
} else {
$HeightCSS = $Height . 'px';
}
$Html .= "<textarea name=\"$InstanceName\" rows=\"4\" cols=\"40\" style=\"width: $WidthCSS; height: $HeightCSS\" wrap=\"virtual\">$HtmlValue</textarea>";
}
$Html .= '</div>';
return($Html);
}
sub IsCompatible
{
$sAgent = $ENV{'HTTP_USER_AGENT'};
if(($sAgent =~ /MSIE/i) && !($sAgent =~ /mac/i) && !($sAgent =~ /Opera/i)) {
$iVersion = substr($sAgent,index($sAgent,'MSIE') + 5,3);
return($iVersion >= 5.5) ;
} elsif($sAgent =~ /Gecko\//i) {
$iVersion = substr($sAgent,index($sAgent,'Gecko/') + 6,8);
return($iVersion >= 20030210) ;
} else {
return(0); # 2.0 PR fix
}
}
sub GetConfigFieldString
{
$sParams = '';
$bFirst = 0;
foreach $sKey (keys %Config) {
$sValue = $Config{$sKey};
if($bFirst == 1) {
$sParams .= '&';
} else {
$bFirst = 1;
}
$k = &specialchar_cnv($sKey);
$v = &specialchar_cnv($sValue);
if($sValue eq "true") {
$sParams .= "$k=true";
} elsif($sValue eq "false") {
$sParams .= "$k=false";
} else {
$sParams .= "$k=$v";
}
}
return($sParams);
}
1;
Tue, 09/16/2008 - 20:19
#1
Re: Converted fckeditor.pl into PERL module
Fred --
Please let me know if you want me to email you the FCKeditor.pm file. I work mainly with PERL and a package was easier for me to use. Keep up the good work. You've got one of the best and most useful packages available in the open source community!!!
db
P.S. I vote to NOT change the name
Re: Converted fckeditor.pl into PERL module
I suggest you opening a ticket at our dev site, attaching your file to it. In this way it may be used by other interested on it too.
I'm not satisfied with our current Perl support. The fact is that we don't have a fully active Perl developer in the team, and so it's maintenance is quite sporadic. We'll reviewing our Perl support for V3, and we'll officially support Perl only if we'll really find people seriously interested on maintaining it.
Frederico Knabben
CKEditor Project Lead and CKSource Owner
--
Follow us on: Twitter | Facebook | Google+ | LinkedIn
Re: Converted fckeditor.pl into PERL module
Thanks for the response. I'll post that file on dev as you suggested. I've been writing PERL since 1993 and am willing to pitch in. I'm also hooked up with the local Perlmongers users group, so between myself and the other guys I'm sure we can tackle just about any issue that might arise. FCKeditor and the new CKEditor are EXCELLENT tools which I've already used to good advantage on my customers' websites. Please let me know how I can help the effort. Give a little get a lot, right?
db
Re: Converted fckeditor.pl into PERL module
I believe that, right now, we should wait for the first beta to come out. It will bring the JavaScript core and the PHP implementation. Then, based on that implementation, we can thinking about enlarging the support over other languages.
Stay in touch. Thanks again!
Frederico Knabben
CKEditor Project Lead and CKSource Owner
--
Follow us on: Twitter | Facebook | Google+ | LinkedIn