sample03.cgi 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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/sample03.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( 'cmbToolbars' ) ;
  81. oCombo.value = editorInstance.ToolbarSet.Name ;
  82. oCombo.style.visibility = '' ;
  83. }
  84. function ChangeToolbar( toolbarName )
  85. {
  86. window.location.href = window.location.pathname + "?Toolbar=" + toolbarName ;
  87. }
  88. </script>
  89. </head>
  90. <body>
  91. <h1>FCKeditor - Perl - Sample 3</h1>
  92. This sample shows how to change the editor toolbar.
  93. <hr>
  94. <table cellpadding="0" cellspacing="0" border="0">
  95. <tr>
  96. <td>
  97. Select the toolbar to load:&nbsp;
  98. </td>
  99. <td>
  100. <select id="cmbToolbars" onchange="ChangeToolbar(this.value);" style="VISIBILITY: hidden">
  101. <option value="Default" selected>Default</option>
  102. <option value="Basic">Basic</option>
  103. </select>
  104. </td>
  105. </tr>
  106. </table>
  107. <br>
  108. <form action="sampleposteddata.cgi" method="post" target="_blank">
  109. _HTML_TAG_
  110. #// Automatically calculates the editor base path based on the _samples directory.
  111. #// This is usefull only for these samples. A real application should use something like this:
  112. #// $oFCKeditor->BasePath = '/fckeditor/' ; // '/fckeditor/' is the default value.
  113. $sBasePath = $ServerPath;
  114. $sBasePath = substr($sBasePath, 0, index( $sBasePath, "_samples" ));
  115. &FCKeditor('FCKeditor1') ;
  116. $BasePath = $sBasePath ;
  117. if($FORM{'Toolbar'} ne "") {
  118. $ToolbarSet = &specialchar_cnv( $FORM{'Toolbar'} );
  119. }
  120. $Value = '<p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.</p>' ;
  121. &Create();
  122. print <<"_HTML_TAG_";
  123. <br>
  124. <input type="submit" value="Submit">
  125. </form>
  126. </body>
  127. </html>
  128. _HTML_TAG_
  129. ################
  130. #Please use this function, rewriting it depending on a server's environment.
  131. ################
  132. sub GetServerPath
  133. {
  134. my $dir;
  135. if($DefServerPath) {
  136. $dir = $DefServerPath;
  137. } else {
  138. if($ENV{'PATH_INFO'}) {
  139. $dir = $ENV{'PATH_INFO'};
  140. } elsif($ENV{'FILEPATH_INFO'}) {
  141. $dir = $ENV{'FILEPATH_INFO'};
  142. } elsif($ENV{'REQUEST_URI'}) {
  143. $dir = $ENV{'REQUEST_URI'};
  144. }
  145. }
  146. return($dir);
  147. }