File Coverage

lib/Egg/Plugin/WYSIWYG/FCKeditor.pm
Criterion Covered Total %
statement 12 54 22.2
branch 0 28 0.0
condition 0 32 0.0
subroutine 4 10 40.0
pod 1 1 100.0
total 17 125 13.6


line stmt bran cond sub pod time code
1             package Egg::Plugin::WYSIWYG::FCKeditor;
2             #
3             # Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
4             #
5             # $Id: FCKeditor.pm 337 2008-05-14 12:30:09Z lushe $
6             #
7 1     1   642 use strict;
  1         3  
  1         48  
8 1     1   6 use warnings;
  1         3  
  1         295  
9              
10             our $VERSION = '3.00';
11              
12             sub _setup {
13 0     0     my($e)= @_;
14 0 0         $e->isa('Egg::Plugin::Tools')
15             || die q{ I want 'Egg::Plugin::Tools' loaded. };
16 0   0       my $c= $e->config->{plugin_wysiwyg_fckeditor} ||= {};
17 0   0       $c->{width} ||= '100%';
18 0   0       $c->{height} ||= '450px';
19 0   0       $c->{style} ||= "width:$c->{width}; height:$c->{height}";
20 0   0       $c->{instance} ||= 'FCKfield';
21 0   0       $c->{tool_bar} ||= 'Default';
22 0   0       $c->{base_uri} ||= '/FCKeditor';
23 0           $c->{base_uri}=~s{/+$} [];
24 0           $e->next::method;
25             }
26             sub fck {
27 0   0 0 1   $_[0]->{fck_editor} ||= Egg::Plugin::WYSIWYG::FCKeditor::handler->new(@_);
28             }
29              
30             package Egg::Plugin::WYSIWYG::FCKeditor::handler;
31 1     1   6 use strict;
  1         3  
  1         34  
32 1     1   6 use base qw/ Egg::Base /;
  1         3  
  1         872  
33              
34             sub new {
35 0     0     my($class, $e)= @_;
36 0           $class->SUPER::new($e, $e->config->{plugin_wysiwyg_fckeditor});
37             }
38             sub is_compat {
39 0 0   0     return $_[0]->{is_compat} if exists($_[0]->{is_compat});
40 0           $_[0]->{is_compat}= do {
41 0           my $a= $_[0]->e->request->agent;
42             ($a=~/MSIE/i and $a!~/mac/i and $a!~/Opera/i) ? do {
43 0 0         return 0 if $a!~m{\d};
44 0 0         substr($a, index($a, 'MSIE')+ 5, 3)>= 5.5 ? 1: 0;
45             }:
46             ($a=~/Gecko\//i) ? do {
47 0 0         substr($a, index($a,'Gecko/')+ 6, 8)>= 20030210 ? 1: 0;
48 0 0 0       }: do { 0 };
  0 0          
49             };
50             }
51             sub html {
52 0     0     my $self= shift;
53 0 0         my $attr= $_[1] ? {@_}: (ref($_[0]) eq 'HASH' ? $_[0]: {});
    0          
54 0 0 0       if ($attr->{width} or $attr->{height}) {
55 0   0       $attr->{style}=
      0        
56             'width:' . ($attr->{width} || $self->params->{width})
57             . ';height:'. ($attr->{height} || $self->params->{height});
58             }
59 0           my $p= { %{$self->params}, %$attr };
  0            
60 0           my $query;
61 0 0 0       if ($query= $self->e->request->param($p->{instance}) || "") {
62 0           $query= $self->e->escape_html($query);
63             }
64             return $self->is_compat ? do {
65             <<END_HTML
66             <textarea id="$p->{instance}"
67             name="$p->{instance}" style="$p->{style}">$query</textarea>
68             END_HTML
69 0 0         }: do {
  0            
70 0           my $uri= "$p->{base_uri}/editor/fckeditor.html"
71             . "?InstanceName=$p->{instance}&Toolbar=$p->{tool_bar}";
72             <<END_HTML
73             <input type="hidden" id="$p->{instance}"
74             name="$p->{instance}" value="$query" style="display:none" />
75             <input type="hidden" id="$p->{instance}___Config" value="" style="display:none" />
76             <iframe id="$p->{instance}___Frame" src="$uri"
77             scrolling="no" border="0" frameborder="no" style="$p->{style}"></iframe>
78             END_HTML
79 0           };
80             }
81             sub js {
82 0     0     my $self = shift;
83 0 0         my $p= { %{$self->params},
  0 0          
84 0           %{$_[1] ? {@_}: (ref($_[0]) eq 'HASH' ? $_[0]: {}) } };
85 0           $p->{width} =~s{px$} [];
86 0           $p->{height}=~s{px$} [];
87 0           <<END_JS;
88             <script type="text/javascript" src="$p->{base_uri}/fckeditor.js"></script>
89             <script type="text/javascript"><!-- //
90             window.onload = function() {
91             var oFCKeditor= new FCKeditor('$p->{instance}');
92             oFCKeditor.BasePath= "$p->{base_uri}/";
93             oFCKeditor.Width = "$p->{width}";
94             oFCKeditor.Height= "$p->{height}";
95             oFCKeditor.ReplaceTextarea();
96             }
97             // --></script>
98             END_JS
99             }
100              
101             1;
102              
103             __END__
104              
105             =head1 NAME
106              
107             Egg::Plugin::WYSIWYG::FCKeditor - Plugin to use FCKeditor that is WYSIWYG.
108              
109             =head1 SYNOPSIS
110              
111             use Egg qw/ WYSIWYG::FCKeditor Tools /;
112            
113             my $fck= $e->fck;
114            
115             # Input form HTML source for FCKeditor is obtained.
116             $e->stash->{fck_input_form}= $fck->html;
117            
118             # The JAVA script for FCKeditor is obtained.
119             $e->stash->{fck_javascript}= $fck->js;
120            
121             # The received source is used with the template etc.
122              
123             =head1 DESCRIPTION
124              
125             It is a plugin to use FCKeditor.
126              
127             FCKeditor is WYSIWYG HTML editor distributed under LGPL.
128              
129             An original distribution site is here. L<http://www.fckeditor.net/>
130              
131             It is necessary to be installed in the site that FCKeditor uses beforehand to
132             use this plugin.
133              
134             In addition, please load L<Egg::Plugin::Tools> by the controller.
135              
136             =head1 INSTALL
137              
138             The directory of the name 'FCKeditor' is made for the document route of and the
139             project.
140              
141             The document route of the project is a place set to dir->{htdocs} of the
142             configuration.
143              
144             If it is default, it is "[PROJECT_ROOT]/htdocs".
145              
146             When the package is downloaded on the distribution site of FCKeditor,
147             it defrosts in a suitable place, and all fckeditor.js and the editor directory
148             in that are arranged in this 'FCKeditor'.
149              
150             The preparation for using FCKeditor by this is completed.
151              
152             Any name of the directory made in the document route is not cared about.
153              
154             Please set the name of the made directory to 'base_uri' of the configuration.
155              
156             =head1 CONFIGURATION
157              
158             The configuration is set with 'plugin_wysiwyg_fckeditor' key.
159              
160             plugin_wysiwyg_fckeditor => {
161             ............
162             ....
163             },
164              
165             =head2 width
166              
167             Width of input form.
168              
169             Default is '100%'
170              
171             width => '100%',
172              
173             =head2 height
174              
175             Width of length of input form.
176              
177             Default is '450px'.
178              
179             height => '450px',
180              
181             =head2 style
182              
183             Style of input form.
184              
185             Default is "width:[width]; height:[height]".
186              
187             =head2 instance
188              
189             Parameter name of input form.
190              
191             Default is 'FCKfield'.
192              
193             The content input to FCKeditor will be received by this name.
194              
195             instance => 'FCKfield',
196              
197             =head2 tool_bar
198              
199             Setting of toolbar of FCKeditor.
200              
201             Default is 'Default'.
202              
203             tool_bar => 'Default',
204              
205             =head2 base_uri
206              
207             URI of the place where the component of FCKeditor was installed is set.
208              
209             Default is '/FCKeditor'.
210              
211             base_uri => '/FCKeditor',
212              
213             =head1 METHODS
214              
215             =head2 fck
216              
217             The Egg::Plugin::WYSIWYG::FCKeditor::handler object is returned.
218              
219             my $fck= $e->fck;
220              
221             =head1 HANDLER METHODS
222              
223             =head2 new
224              
225             Constructor. When the fck method is called, it is called internally.
226              
227             =head2 is_compat
228              
229             The interchangeability of FCKeditor is judged.
230              
231             'Html' method refers to this.
232             I do not think that there is a thing used from the application usually.
233              
234             if ($fck->is_compat) {
235             .........
236             } else {
237             .........
238             }
239              
240             =head2 html ([OPTION_HASH])
241              
242             The HTML source for the input form of FCKeditor is returned.
243              
244             When OPTION_HASH is passed, the configuration is overwrited.
245              
246             my $inputo_form= $e->fck->html(
247             width => '500px', height => '300px',
248             );
249              
250             =head2 js ([OPTION_HASH])
251              
252             The JAVA script for FCKeditor is returned.
253              
254             When OPTION_HASH is passed, the configuration is overwrited.
255              
256             my $javascript= $e->fck->js(
257             width => '500px', height => '300px',
258             );
259              
260             =head1 SEE ALSO
261              
262             L<Egg::Release>,
263             L<Egg::Base>,
264             L<Egg::Plugin::Tools>,
265             L<http://www.fckeditor.net/>,
266              
267             =head1 AUTHOR
268              
269             Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt>
270              
271             =head1 COPYRIGHT AND LICENSE
272              
273             Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>.
274              
275             This library is free software; you can redistribute it and/or modify
276             it under the same terms as Perl itself, either Perl version 5.8.6 or,
277             at your option, any later version of Perl 5 you may have available.
278              
279             =cut
280