/EQT_V1/EQTWebApp/fckeditor/_samples/perl/sample02.cgi

http://sgsoft-las.googlecode.com/ · Perl · 182 lines · 123 code · 22 blank · 37 comment · 16 complexity · 462d4ccdc4d163749b091612c62b81ba MD5 · raw file

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