Ticket #2784: fckeditor.pl

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