1package CGI::FCKeditor;
2use strict;
3use warnings;
4
5our $VERSION = '0.02';
6
7sub new {
8	my $class = shift;
9	my $self = {
10		name => undef,
11		base => undef,
12		width => '100%',
13		height => '500',
14		set => undef,
15		value => undef,
16		fck => undef,
17	};
18	bless($self, $class);
19
20	my ($name,$base,$set,$value) =@_;
21	$self->set_name($name || 'fck');
22	$self->set_base($base || 'FCKeditor');
23	$self->set_set($set || 'Default');
24	$self->set_value($value || '');
25	return $self;
26}
27
28sub set_name {
29	my $self = shift;
30	if (@_) { $self->{name} = shift }
31	return $self->{name};
32}
33
34sub set_base {
35	my $self = shift;
36	if (@_) { $self->{base} = shift }
37	return $self->{base};
38}
39
40sub set_width {
41	my $self = shift;
42	if (@_) { $self->{width} = shift }
43	return $self->{width};
44}
45
46sub set_height {
47	my $self = shift;
48	if (@_) { $self->{height} = shift }
49	return $self->{height};
50}
51
52sub set_set {
53	my $self = shift;
54	if (@_) { $self->{set} = shift }
55	return $self->{set};
56}
57
58sub set_value {
59	my $self = shift;
60	if (@_) { $self->{value} = shift }
61	return $self->{value};
62}
63
64sub fck {
65	my $self = shift;
66	my $value = $self->{value};
67
68	#For HTML Convert
69	$value =~ s/&/&/g;		# &
70	$value =~ s/\"/"/g;	# "
71	$value =~ s/\'/'/g;		# '
72	$value =~ s/</&lt;/g;		# <
73	$value =~ s/>/&gt;/g;		# >
74
75	#Browser Check
76	unless ($ENV{'HTTP_USER_AGENT'}) {
77		$ENV{'HTTP_USER_AGENT'} = 'test';
78	}
79	my $sAgent = $ENV{'HTTP_USER_AGENT'};
80	my $iVersion = undef;
81	my $uFlag = 0;
82	if(($sAgent =~ /MSIE/i) && !($sAgent =~ /mac/i) && !($sAgent =~ /Opera/i)) {
83		$iVersion = substr($sAgent,index($sAgent,'MSIE') + 5,3);
84		if ($iVersion >= 5.5){
85			$uFlag++;
86		}
87	} elsif($sAgent =~ /Gecko\//i) {
88		$iVersion = substr($sAgent,index($sAgent,'Gecko/') + 6,8);
89		if ($iVersion >= 20030210){
90			$uFlag++;
91		}
92	}
93
94	#Start Form Render
95	my $name = $self->{name};
96	my $base = $self->{base};
97	my $width = $self->{width};
98	my $height = $self->{height};
99	my $set = $self->{set};
100
101	my $Html = '<div>';
102	if($uFlag) {
103		my $Link = $base . "editor/fckeditor.html?InstanceName=$name";
104		if($set ne '') {
105			$Link .= "&amp;Toolbar=$set";
106		}
107		#// Render the linked hidden field.
108		$Html .= "<input type=\"hidden\" id=\"$name\" name=\"$name\" value=\"$value\" style=\"display:none\" />" ;
109
110		#// Render the configurations hidden field.
111		my $wk = $name."___Config";
112		$Html .= "<input type=\"hidden\" id=\"$wk\" value=\"\" style=\"display:none\" />" ;
113
114		#// Render the editor IFRAME.
115		$wk = $name."___Frame";
116		$Html .= "<iframe id=\"$wk\" src=\"$Link\" width=\"$width\" height=\"$height\" frameborder=\"0\" scrolling=\"no\"></iframe>";
117	} else {
118		my $WidthCSS = undef;
119		my $HeightCSS = undef;
120
121		if($width =~ /\%/g){
122			$WidthCSS = $width;
123		} else {
124			$WidthCSS = $width . 'px';
125		}
126		if($height =~ /\%/g){
127			$HeightCSS = $height;
128		} else {
129			$HeightCSS = $height . 'px';
130		}
131		$Html .= "<textarea name=\"$name\" rows=\"4\" cols=\"40\" style=\"width: $WidthCSS; height: $HeightCSS\">$value</textarea>";
132	}
133	$Html .= '</div>';
134
135	$self->{fck} = $Html;
136	return $self->{fck};
137}
138
1391;
140__END__
141
142=head1 NAME
143
144CGI::FCKeditor - FCKeditor For OOP Module
145
146=head1 SYNOPSIS
147
148  use CGI::FCKeditor;
149
150  #Simple
151  my $fck = CGI::FCKeditor->new();
152  $fck->set_base('/FCKeditor/');  #FCKeditor Directory
153  my $form_input_source = $fck->fck;    #output html source
154
155  #Basic
156  my $fck = CGI::FCKeditor->new();
157  $fck->set_name('fck');	#HTML <input name>(default 'fck')
158  $fck->set_base('/FCKeditor/');	#FCKeditor Directory
159  $fck->set_set('Basic');	#FCKeditor Style(default 'Default')
160  $fck->set_value('READ ME');	#input field default value(default '')
161  my $form_input_source = $fck->fck;	#output html source
162
163  #Short
164  my $fck = CGI::FCKeditor->new('fck','/FCKeditor/','Basic','READ ME');
165  my $form_input_source = $fck->fck;
166
167=head1 DESCRIPTION
168
169CGI::FCKeditor is FCKeditor(http://www.fckeditor.net/) Controller for Perl OOP.
170FCKeditor(http://www.fckeditor.net/) is necessary though it is natural.
171
172=head1 METHODS
173
174=head2 new
175
176  my $fck = CGI::FCKeditor->new();
177
178Constructs instance.
179
180=head2 set_name
181
182  $fck->set_name('fck');
183
184Set <input name="fck"> on HTML source.
185Default 'fck'.
186
187=head2 set_base
188
189  $fck->set_base('/dir/FCKeditor/');
190
191Set URL directory with fckeditor.js.
192Default '/FCKeditor'.
193
194=head2 set_width
195
196  $fck->set_width('100%');
197
198Set FCKeditor Width.
199Default '100%'.
200
201=head2 set_height
202
203  $fck->set_height('500');
204
205Set FCKeditor Height.
206Default '500'.
207
208=head2 set_set
209
210  $fck->set_set('Basic');
211
212Set FCKeditor Style.
213Default 'Default'.
214
215=head2 set_value
216
217  $fck->set_value('Read ME');
218
219Set <input value="Read ME"> on HTML source.
220Default ''.
221
222=head2 fck
223
224  $form_input_source = $fck->fck;
225
226FCKeditor Render on HTML.
227
228=head1 AUTHOR
229
230Kazuma Shiraiwa
231
232This module owes a lot in code to
233fckeditor.pl(Author:Takashi Yamaguchi) in FCKeditor_2.3.2.
234
235=head1 COPYRIGHT AND LICENSE
236
237Copyright (C) 2006 by Kazuma Shiraiwa.
238This program is free software; you may redistribute it and/or modify it
239under the same terms as Perl itself.
240
241=cut
242
243