~ubuntu-branches/ubuntu/trusty/fusionforge/trusty

« back to all changes in this revision

Viewing changes to plugins/fckeditor/www/_samples/perl/sample04.cgi

  • Committer: Bazaar Package Importer
  • Author(s): Roland Mas
  • Date: 2011-04-15 14:55:34 UTC
  • mfrom: (4.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20110415145534-mvn1nochufjmw177
Tags: 5.0.3-1
New upstream bugfix release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
#####
 
4
#  FCKeditor - The text editor for Internet - http://www.fckeditor.net
 
5
#  Copyright (C) 2003-2008 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/sample04.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
#!!Caution javascript \ Quart
 
79
 
 
80
        print "Content-type: text/html\n\n";
 
81
        print <<"_HTML_TAG_";
 
82
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
83
<html>
 
84
        <head>
 
85
                <title>FCKeditor - Sample</title>
 
86
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
87
                <meta name="robots" content="noindex, nofollow">
 
88
                <link href="../sample.css" rel="stylesheet" type="text/css" />
 
89
                <script type="text/javascript">
 
90
 
 
91
function FCKeditor_OnComplete( editorInstance )
 
92
{
 
93
        var oCombo = document.getElementById( 'cmbSkins' ) ;
 
94
 
 
95
        // Get the active skin.
 
96
        var sSkin = editorInstance.Config['SkinPath'] ;
 
97
        sSkin = sSkin.match(/[^\\/]+(?=\\/\$)/g) ;
 
98
 
 
99
        oCombo.value = sSkin ;
 
100
        oCombo.style.visibility = '' ;
 
101
}
 
102
 
 
103
function ChangeSkin( skinName )
 
104
{
 
105
        window.location.href = window.location.pathname + "?Skin=" + skinName ;
 
106
}
 
107
 
 
108
                </script>
 
109
        </head>
 
110
        <body>
 
111
                <h1>FCKeditor - Perl - Sample 4</h1>
 
112
                This sample shows how to change the editor skin.
 
113
                <hr>
 
114
                <table cellpadding="0" cellspacing="0" border="0">
 
115
                        <tr>
 
116
                                <td>
 
117
                                        Select the skin to load:&nbsp;
 
118
                                </td>
 
119
                                <td>
 
120
                                        <select id="cmbSkins" onchange="ChangeSkin(this.value);" style="VISIBILITY: hidden">
 
121
                                                <option value="default" selected>Default</option>
 
122
                                                <option value="office2003">Office 2003</option>
 
123
                                                <option value="silver">Silver</option>
 
124
                                        </select>
 
125
                                </td>
 
126
                        </tr>
 
127
                </table>
 
128
                <br>
 
129
                <form action="sampleposteddata.cgi" method="post" target="_blank">
 
130
_HTML_TAG_
 
131
 
 
132
        #// Automatically calculates the editor base path based on the _samples directory.
 
133
        #// This is usefull only for these samples. A real application should use something like this:
 
134
        #// $oFCKeditor->BasePath = '/fckeditor/' ;     // '/fckeditor/' is the default value.
 
135
        $sBasePath = $ServerPath;
 
136
        $sBasePath = substr( $sBasePath, 0, index( $sBasePath, "_samples" ) ) ;
 
137
 
 
138
        &FCKeditor('FCKeditor1');
 
139
        $BasePath = $sBasePath;
 
140
 
 
141
        if($FORM{'Skin'} ne "") {
 
142
                $Config{'SkinPath'} = $sBasePath . 'editor/skins/' . &specialchar_cnv( $FORM{'Skin'} ) . '/' ;
 
143
        }
 
144
        $Value = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
 
145
        &Create() ;
 
146
 
 
147
        print <<"_HTML_TAG_";
 
148
                        <br>
 
149
                        <input type="submit" value="Submit">
 
150
                </form>
 
151
        </body>
 
152
</html>
 
153
_HTML_TAG_
 
154
 
 
155
################
 
156
#Please use this function, rewriting it depending on a server's environment.
 
157
################
 
158
sub GetServerPath
 
159
{
 
160
my $dir;
 
161
 
 
162
        if($DefServerPath) {
 
163
                $dir = $DefServerPath;
 
164
        } else {
 
165
                if($ENV{'PATH_INFO'}) {
 
166
                        $dir  = $ENV{'PATH_INFO'};
 
167
                } elsif($ENV{'FILEPATH_INFO'}) {
 
168
                        $dir  = $ENV{'FILEPATH_INFO'};
 
169
                } elsif($ENV{'REQUEST_URI'}) {
 
170
                        $dir  = $ENV{'REQUEST_URI'};
 
171
                }
 
172
        }
 
173
        return($dir);
 
174
}