1 | #!/usr/bin/env perl
|
---|
2 |
|
---|
3 | #####
|
---|
4 | # FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
5 | # Copyright (C) 2003-2009 Frederico Caldeira Knabben
|
---|
6 | #
|
---|
7 | # == BEGIN LICENSE ==
|
---|
8 | #
|
---|
9 | # Licensed under the terms of any of the following licenses at your
|
---|
10 | # choice:
|
---|
11 | #
|
---|
12 | # - GNU General Public License Version 2 or later (the "GPL")
|
---|
13 | # http://www.gnu.org/licenses/gpl.html
|
---|
14 | #
|
---|
15 | # - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
---|
16 | # http://www.gnu.org/licenses/lgpl.html
|
---|
17 | #
|
---|
18 | # - Mozilla Public License Version 1.1 or later (the "MPL")
|
---|
19 | # http://www.mozilla.org/MPL/MPL-1.1.html
|
---|
20 | #
|
---|
21 | # == END LICENSE ==
|
---|
22 | #
|
---|
23 | # Sample page.
|
---|
24 | #####
|
---|
25 |
|
---|
26 | ## START: Hack for Windows (Not important to understand the editor code... Perl specific).
|
---|
27 | if(Windows_check()) {
|
---|
28 | chdir(GetScriptPath($0));
|
---|
29 | }
|
---|
30 |
|
---|
31 | sub Windows_check
|
---|
32 | {
|
---|
33 | # IIS,PWS(NT/95)
|
---|
34 | $www_server_os = $^O;
|
---|
35 | # Win98 & NT(SP4)
|
---|
36 | if($www_server_os eq "") { $www_server_os= $ENV{'OS'}; }
|
---|
37 | # AnHTTPd/Omni/IIS
|
---|
38 | if($ENV{'SERVER_SOFTWARE'} =~ /AnWeb|Omni|IIS\//i) { $www_server_os= 'win'; }
|
---|
39 | # Win Apache
|
---|
40 | if($ENV{'WINDIR'} ne "") { $www_server_os= 'win'; }
|
---|
41 | if($www_server_os=~ /win/i) { return(1); }
|
---|
42 | return(0);
|
---|
43 | }
|
---|
44 |
|
---|
45 | sub GetScriptPath {
|
---|
46 | local($path) = @_;
|
---|
47 | if($path =~ /[\:\/\\]/) { $path =~ s/(.*?)[\/\\][^\/\\]+$/$1/; } else { $path = '.'; }
|
---|
48 | $path;
|
---|
49 | }
|
---|
50 | ## END: Hack for IIS
|
---|
51 |
|
---|
52 | require '../../fckeditor.pl';
|
---|
53 |
|
---|
54 | # When $ENV{'PATH_INFO'} cannot be used by perl.
|
---|
55 | # $DefRootPath = "/XXXXX/_samples/perl/sample02.cgi"; Please write in script.
|
---|
56 |
|
---|
57 | my $DefServerPath = "";
|
---|
58 | my $ServerPath;
|
---|
59 |
|
---|
60 | $ServerPath = &GetServerPath();
|
---|
61 |
|
---|
62 | if($ENV{'REQUEST_METHOD'} eq "POST") {
|
---|
63 | read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
|
---|
64 | } else {
|
---|
65 | $buffer = $ENV{'QUERY_STRING'};
|
---|
66 | }
|
---|
67 | @pairs = split(/&/,$buffer);
|
---|
68 | foreach $pair (@pairs) {
|
---|
69 | ($name,$value) = split(/=/,$pair);
|
---|
70 | $value =~ tr/+/ /;
|
---|
71 | $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
|
---|
72 | $value =~ s/\t//g;
|
---|
73 | $value =~ s/\r\n/\n/g;
|
---|
74 | $FORM{$name} .= "\0" if(defined($FORM{$name}));
|
---|
75 | $FORM{$name} .= $value;
|
---|
76 | }
|
---|
77 |
|
---|
78 | print "Content-type: text/html\n\n";
|
---|
79 | print <<"_HTML_TAG_";
|
---|
80 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
81 | <html>
|
---|
82 | <head>
|
---|
83 | <title>FCKeditor - Sample</title>
|
---|
84 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
85 | <meta name="robots" content="noindex, nofollow">
|
---|
86 | <link href="../sample.css" rel="stylesheet" type="text/css" />
|
---|
87 | <script type="text/javascript">
|
---|
88 |
|
---|
89 | function FCKeditor_OnComplete( editorInstance )
|
---|
90 | {
|
---|
91 | var oCombo = document.getElementById( 'cmbLanguages' ) ;
|
---|
92 | for ( code in editorInstance.Language.AvailableLanguages )
|
---|
93 | {
|
---|
94 | AddComboOption( oCombo, editorInstance.Language.AvailableLanguages[code] + ' (' + code + ')', code ) ;
|
---|
95 | }
|
---|
96 | oCombo.value = editorInstance.Language.ActiveLanguage.Code ;
|
---|
97 | }
|
---|
98 |
|
---|
99 | function AddComboOption(combo, optionText, optionValue)
|
---|
100 | {
|
---|
101 | var oOption = document.createElement("OPTION") ;
|
---|
102 |
|
---|
103 | combo.options.add(oOption) ;
|
---|
104 |
|
---|
105 | oOption.innerHTML = optionText ;
|
---|
106 | oOption.value = optionValue ;
|
---|
107 |
|
---|
108 | return oOption ;
|
---|
109 | }
|
---|
110 |
|
---|
111 | function ChangeLanguage( languageCode )
|
---|
112 | {
|
---|
113 | window.location.href = window.location.pathname + "?Lang=" + languageCode ;
|
---|
114 | }
|
---|
115 | </script>
|
---|
116 | </head>
|
---|
117 | <body>
|
---|
118 | <h1>FCKeditor - Perl - Sample 2</h1>
|
---|
119 | This sample shows the editor in all its available languages.
|
---|
120 | <hr>
|
---|
121 | <table cellpadding="0" cellspacing="0" border="0">
|
---|
122 | <tr>
|
---|
123 | <td>
|
---|
124 | Select a language:
|
---|
125 | </td>
|
---|
126 | <td>
|
---|
127 | <select id="cmbLanguages" onchange="ChangeLanguage(this.value);">
|
---|
128 | </select>
|
---|
129 | </td>
|
---|
130 | </tr>
|
---|
131 | </table>
|
---|
132 | <br>
|
---|
133 | <form action="sampleposteddata.cgi" method="post" target="_blank">
|
---|
134 | _HTML_TAG_
|
---|
135 |
|
---|
136 | #// Automatically calculates the editor base path based on the _samples directory.
|
---|
137 | #// This is usefull only for these samples. A real application should use something like this:
|
---|
138 | #// $oFCKeditor->BasePath = '/fckeditor/' ; // '/fckeditor/' is the default value.
|
---|
139 | $sBasePath = $ServerPath;
|
---|
140 | $sBasePath = substr( $sBasePath, 0, index($sBasePath,"_samples"));
|
---|
141 |
|
---|
142 | &FCKeditor('FCKeditor1');
|
---|
143 | $BasePath = $sBasePath;
|
---|
144 |
|
---|
145 | if($FORM{'Lang'} ne "") {
|
---|
146 | $Config{'AutoDetectLanguage'} = "false";
|
---|
147 | $lang = $FORM{'Lang'};
|
---|
148 | $lang =~ s/[^a-z\-]//ig;
|
---|
149 | $Config{'DefaultLanguage'} = $lang;
|
---|
150 | } else {
|
---|
151 | $Config{'AutoDetectLanguage'} = "true";
|
---|
152 | $Config{'DefaultLanguage'} = 'en' ;
|
---|
153 | }
|
---|
154 | $Value = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
|
---|
155 | &Create();
|
---|
156 |
|
---|
157 | print <<"_HTML_TAG_";
|
---|
158 | <br>
|
---|
159 | <input type="submit" value="Submit">
|
---|
160 | </form>
|
---|
161 | </body>
|
---|
162 | </html>
|
---|
163 | _HTML_TAG_
|
---|
164 |
|
---|
165 | ################
|
---|
166 | #Please use this function, rewriting it depending on a server's environment.
|
---|
167 | ################
|
---|
168 | sub GetServerPath
|
---|
169 | {
|
---|
170 | my $dir;
|
---|
171 |
|
---|
172 | if($DefServerPath) {
|
---|
173 | $dir = $DefServerPath;
|
---|
174 | } else {
|
---|
175 | if($ENV{'PATH_INFO'}) {
|
---|
176 | $dir = $ENV{'PATH_INFO'};
|
---|
177 | } elsif($ENV{'FILEPATH_INFO'}) {
|
---|
178 | $dir = $ENV{'FILEPATH_INFO'};
|
---|
179 | } elsif($ENV{'REQUEST_URI'}) {
|
---|
180 | $dir = $ENV{'REQUEST_URI'};
|
---|
181 | }
|
---|
182 | }
|
---|
183 | return($dir);
|
---|
184 | }
|
---|