~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/_samples/perl/sample04.cgi

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

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
 
5
#  Copyright (C) 2003-2005 Frederico Caldeira Knabben
 
6
#  
 
7
#  Licensed under the terms of the GNU Lesser General Public License:
 
8
#               http://www.opensource.org/licenses/lgpl-license.php
 
9
#  
 
10
#  For further information visit:
 
11
#               http://www.fckeditor.net/
 
12
#  
 
13
#  "Support Open Source software. What about a donation today?"
 
14
#  
 
15
#  File Name: sample04.cgi
 
16
#       Sample page.
 
17
#  
 
18
#  File Authors:
 
19
#               Takashi Yamaguchi (jack@omakase.net)
 
20
#####
 
21
 
 
22
## START: Hack for Windows (Not important to understand the editor code... Perl specific).
 
23
if(Windows_check()) {
 
24
        chdir(GetScriptPath($0));
 
25
}
 
26
 
 
27
sub Windows_check
 
28
{
 
29
        # IIS,PWS(NT/95)
 
30
        $www_server_os = $^O;
 
31
        # Win98 & NT(SP4)
 
32
        if($www_server_os eq "") { $www_server_os= $ENV{'OS'}; }
 
33
        # AnHTTPd/Omni/IIS
 
34
        if($ENV{'SERVER_SOFTWARE'} =~ /AnWeb|Omni|IIS\//i) { $www_server_os= 'win'; }
 
35
        # Win Apache
 
36
        if($ENV{'WINDIR'} ne "") { $www_server_os= 'win'; }
 
37
        if($www_server_os=~ /win/i) { return(1); }
 
38
        return(0);
 
39
}
 
40
 
 
41
sub GetScriptPath {
 
42
        local($path) = @_;
 
43
        if($path =~ /[\:\/\\]/) { $path =~ s/(.*?)[\/\\][^\/\\]+$/$1/; } else { $path = '.'; }
 
44
        $path;
 
45
}
 
46
## END: Hack for IIS
 
47
 
 
48
require '../../fckeditor.pl';
 
49
 
 
50
# When $ENV{'PATH_INFO'} cannot be used by perl.
 
51
# $DefRootPath = "/XXXXX/_samples/perl/sample04.cgi"; Please write in script.
 
52
 
 
53
my $DefServerPath = "";
 
54
my $ServerPath;
 
55
 
 
56
        $ServerPath = &GetServerPath();
 
57
 
 
58
        if($ENV{'REQUEST_METHOD'} eq "POST") {
 
59
                read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
60
        } else {
 
61
                $buffer = $ENV{'QUERY_STRING'};
 
62
        }
 
63
        @pairs = split(/&/,$buffer);
 
64
        foreach $pair (@pairs) {
 
65
                ($name,$value) = split(/=/,$pair);
 
66
                $value =~ tr/+/ /;
 
67
                $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 
68
                $value =~ s/\t//g;
 
69
                $value =~ s/\r\n/\n/g;
 
70
                $FORM{$name} .= "\0"                    if(defined($FORM{$name}));
 
71
                $FORM{$name} .= $value;
 
72
        }
 
73
 
 
74
#!!Caution javascript \ Quart
 
75
 
 
76
        print "Content-type: text/html\n\n";
 
77
        print <<"_HTML_TAG_";
 
78
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
79
<html>
 
80
        <head>
 
81
                <title>FCKeditor - Sample</title>
 
82
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
83
                <meta name="robots" content="noindex, nofollow">
 
84
                <link href="../sample.css" rel="stylesheet" type="text/css" />
 
85
                <script type="text/javascript">
 
86
 
 
87
function FCKeditor_OnComplete( editorInstance )
 
88
{
 
89
        var oCombo = document.getElementById( 'cmbSkins' ) ;
 
90
 
 
91
        // Get the active skin.
 
92
        var sSkin = editorInstance.Config['SkinPath'] ;
 
93
        sSkin = sSkin.match(/[^\\/]+(?=\\/\$)/g) ;
 
94
 
 
95
        oCombo.value = sSkin ;
 
96
        oCombo.style.visibility = '' ;
 
97
}
 
98
 
 
99
function ChangeSkin( skinName )
 
100
{
 
101
        window.location.href = window.location.pathname + "?Skin=" + skinName ;
 
102
}
 
103
 
 
104
                </script>
 
105
        </head>
 
106
        <body>
 
107
                <h1>FCKeditor - Perl - Sample 4</h1>
 
108
                This sample shows how to change the editor skin.
 
109
                <hr>
 
110
                <table cellpadding="0" cellspacing="0" border="0">
 
111
                        <tr>
 
112
                                <td>
 
113
                                        Select the skin to load:&nbsp;
 
114
                                </td>
 
115
                                <td>
 
116
                                        <select id="cmbSkins" onchange="ChangeSkin(this.value);" style="VISIBILITY: hidden">
 
117
                                                <option value="default" selected>Default</option>
 
118
                                                <option value="office2003">Office 2003</option>
 
119
                                                <option value="silver">Silver</option>
 
120
                                        </select>
 
121
                                </td>
 
122
                        </tr>
 
123
                </table>
 
124
                <br>
 
125
                <form action="sampleposteddata.cgi" method="post" target="_blank">
 
126
_HTML_TAG_
 
127
 
 
128
        #// Automatically calculates the editor base path based on the _samples directory.
 
129
        #// This is usefull only for these samples. A real application should use something like this:
 
130
        #// $oFCKeditor->BasePath = '/FCKeditor/' ;     // '/FCKeditor/' is the default value.
 
131
        $sBasePath = $ServerPath;
 
132
        $sBasePath = substr( $sBasePath, 0, index( $sBasePath, "_samples" ) ) ;
 
133
 
 
134
        &FCKeditor('FCKeditor1');
 
135
        $BasePath = $sBasePath;
 
136
 
 
137
        if($FORM{'Skin'} ne "") {
 
138
                $Config{'SkinPath'} = $sBasePath . 'editor/skins/' . $FORM{'Skin'} . '/' ;
 
139
        }
 
140
        $Value = 'This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.' ;
 
141
        &Create() ;
 
142
 
 
143
        print <<"_HTML_TAG_";
 
144
                        <br>
 
145
                        <input type="submit" value="Submit">
 
146
                </form>
 
147
        </body>
 
148
</html>
 
149
_HTML_TAG_
 
150
 
 
151
################
 
152
#Please use this function, rewriting it depending on a server's environment.
 
153
################
 
154
sub GetServerPath
 
155
{
 
156
my $dir;
 
157
 
 
158
        if($DefServerPath) {
 
159
                $dir = $DefServerPath;
 
160
        } else {
 
161
                if($ENV{'PATH_INFO'}) {
 
162
                        $dir  = $ENV{'PATH_INFO'};
 
163
                } elsif($ENV{'FILEPATH_INFO'}) {
 
164
                        $dir  = $ENV{'FILEPATH_INFO'};
 
165
                }
 
166
        }
 
167
        return($dir);
 
168
}