1#####
2#  FCKeditor - The text editor for Internet - http://www.fckeditor.net
3#  Copyright (C) 2003-2007 Frederico Caldeira Knabben
4#
5#  == BEGIN LICENSE ==
6#
7#  Licensed under the terms of any of the following licenses at your
8#  choice:
9#
10#   - GNU General Public License Version 2 or later (the "GPL")
11#     http://www.gnu.org/licenses/gpl.html
12#
13#   - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14#     http://www.gnu.org/licenses/lgpl.html
15#
16#   - Mozilla Public License Version 1.1 or later (the "MPL")
17#     http://www.mozilla.org/MPL/MPL-1.1.html
18#
19#  == END LICENSE ==
20#
21#  This is the integration file for Perl.
22#####
23
24#my $InstanceName;
25#my $BasePath;
26#my $Width;
27#my $Height;
28#my $ToolbarSet;
29#my $Value;
30#my %Config;
31
32sub FCKeditor
33{
34
35	local($instanceName) = @_;
36	$InstanceName	= $instanceName;
37	$BasePath		= '/fckeditor/';
38	$Width			= '100%';
39	$Height			= '200';
40	$ToolbarSet		= 'Default';
41	$Value			= '';
42}
43
44sub Create
45{
46	print &CreateHtml();
47}
48
49sub specialchar_cnv
50{
51
52	local($ch) = @_;
53
54	$ch =~ s/&/&/g;		# &
55	$ch =~ s/\"/"/g;	#"
56	$ch =~ s/\'/'/g;	# '
57	$ch =~ s/</&lt;/g;		# <
58	$ch =~ s/>/&gt;/g;		# >
59	return($ch);
60}
61
62sub CreateHtml
63{
64
65	$HtmlValue = &specialchar_cnv($Value);
66	$Html = '<div>' ;
67	if(&IsCompatible()) {
68		$Link = $BasePath . "editor/fckeditor.html?InstanceName=$InstanceName";
69		if($ToolbarSet ne '') {
70			$Link .= "&amp;Toolbar=$ToolbarSet";
71		}
72		#// Render the linked hidden field.
73		$Html .= "<input type=\"hidden\" id=\"$InstanceName\" name=\"$InstanceName\" value=\"$HtmlValue\" style=\"display:none\" />" ;
74
75		#// Render the configurations hidden field.
76		$cfgstr = &GetConfigFieldString();
77		$wk = $InstanceName."___Config";
78		$Html .= "<input type=\"hidden\" id=\"$wk\" value=\"$cfgstr\" style=\"display:none\" />" ;
79
80		#// Render the editor IFRAME.
81		$wk = $InstanceName."___Frame";
82		$Html .= "<iframe id=\"$wk\" src=\"$Link\" width=\"$Width\" height=\"$Height\" frameborder=\"0\" scrolling=\"no\"></iframe>";
83	} else {
84		if($Width =~ /\%/g){
85			$WidthCSS = $Width;
86		} else {
87			$WidthCSS = $Width . 'px';
88		}
89		if($Height =~ /\%/g){
90			$HeightCSS = $Height;
91		} else {
92			$HeightCSS = $Height . 'px';
93		}
94		$Html .= "<textarea name=\"$InstanceName\" rows=\"4\" cols=\"40\" style=\"width: $WidthCSS; height: $HeightCSS\">$HtmlValue</textarea>";
95	}
96	$Html .= '</div>';
97	return($Html);
98}
99
100sub IsCompatible
101{
102
103	$sAgent = $ENV{'HTTP_USER_AGENT'};
104	if(($sAgent =~ /MSIE/i) && !($sAgent =~ /mac/i) && !($sAgent =~ /Opera/i)) {
105		$iVersion = substr($sAgent,index($sAgent,'MSIE') + 5,3);
106		return($iVersion >= 5.5) ;
107	} elsif($sAgent =~ /Gecko\//i) {
108		$iVersion = substr($sAgent,index($sAgent,'Gecko/') + 6,8);
109		return($iVersion >= 20030210) ;
110	} elsif($sAgent =~ /Opera\//i) {
111		$iVersion = substr($sAgent,index($sAgent,'Opera/') + 6,4);
112		return($iVersion >= 9.5) ;
113	} elsif($sAgent =~ /AppleWebKit\/(\d+)/i) {
114		return($1 >= 522) ;
115	} else {
116		return(0);		# 2.0 PR fix
117	}
118}
119
120sub GetConfigFieldString
121{
122	$sParams = '';
123	$bFirst = 0;
124	foreach $sKey (keys %Config) {
125		$sValue = $Config{$sKey};
126		if($bFirst == 1) {
127			$sParams .= '&amp;';
128		} else {
129			$bFirst = 1;
130		}
131		$k = &specialchar_cnv($sKey);
132		$v = &specialchar_cnv($sValue);
133		if($sValue eq "true") {
134			$sParams .= "$k=true";
135		} elsif($sValue eq "false") {
136			$sParams .= "$k=false";
137		} else {
138			$sParams .= "$k=$v";
139		}
140	}
141	return($sParams);
142}
143
1441;
145