fckeditor.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #####
  2. # FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. # Copyright (C) 2003-2009 Frederico Caldeira Knabben
  4. #
  5. # == BEGIN LICENSE ==
  6. #
  7. # Licensed under the terms of any of the following licenses at your
  8. # choice:
  9. #
  10. # - GNU General Public License Version 2 or later (the "GPL")
  11. # http://www.gnu.org/licenses/gpl.html
  12. #
  13. # - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14. # http://www.gnu.org/licenses/lgpl.html
  15. #
  16. # - Mozilla Public License Version 1.1 or later (the "MPL")
  17. # http://www.mozilla.org/MPL/MPL-1.1.html
  18. #
  19. # == END LICENSE ==
  20. #
  21. # This is the integration file for Perl.
  22. #####
  23. #my $InstanceName;
  24. #my $BasePath;
  25. #my $Width;
  26. #my $Height;
  27. #my $ToolbarSet;
  28. #my $Value;
  29. #my %Config;
  30. sub FCKeditor
  31. {
  32. local($instanceName) = @_;
  33. $InstanceName = $instanceName;
  34. $BasePath = '/fckeditor/';
  35. $Width = '100%';
  36. $Height = '200';
  37. $ToolbarSet = 'Default';
  38. $Value = '';
  39. }
  40. sub Create
  41. {
  42. print &CreateHtml();
  43. }
  44. sub specialchar_cnv
  45. {
  46. local($ch) = @_;
  47. $ch =~ s/&/&/g; # &
  48. $ch =~ s/\"/"/g; #"
  49. $ch =~ s/\'/'/g; # '
  50. $ch =~ s/</&lt;/g; # <
  51. $ch =~ s/>/&gt;/g; # >
  52. return($ch);
  53. }
  54. sub CreateHtml
  55. {
  56. $HtmlValue = &specialchar_cnv($Value);
  57. $Html = '' ;
  58. if(&IsCompatible()) {
  59. $Link = $BasePath . "editor/fckeditor.html?InstanceName=$InstanceName";
  60. if($ToolbarSet ne '') {
  61. $Link .= "&amp;Toolbar=$ToolbarSet";
  62. }
  63. #// Render the linked hidden field.
  64. $Html .= "<input type=\"hidden\" id=\"$InstanceName\" name=\"$InstanceName\" value=\"$HtmlValue\" style=\"display:none\" />" ;
  65. #// Render the configurations hidden field.
  66. $cfgstr = &GetConfigFieldString();
  67. $wk = $InstanceName."___Config";
  68. $Html .= "<input type=\"hidden\" id=\"$wk\" value=\"$cfgstr\" style=\"display:none\" />" ;
  69. #// Render the editor IFRAME.
  70. $wk = $InstanceName."___Frame";
  71. $Html .= "<iframe id=\"$wk\" src=\"$Link\" width=\"$Width\" height=\"$Height\" frameborder=\"0\" scrolling=\"no\"></iframe>";
  72. } else {
  73. if($Width =~ /\%/g){
  74. $WidthCSS = $Width;
  75. } else {
  76. $WidthCSS = $Width . 'px';
  77. }
  78. if($Height =~ /\%/g){
  79. $HeightCSS = $Height;
  80. } else {
  81. $HeightCSS = $Height . 'px';
  82. }
  83. $Html .= "<textarea name=\"$InstanceName\" rows=\"4\" cols=\"40\" style=\"width: $WidthCSS; height: $HeightCSS\">$HtmlValue</textarea>";
  84. }
  85. return($Html);
  86. }
  87. sub IsCompatible
  88. {
  89. $sAgent = $ENV{'HTTP_USER_AGENT'};
  90. if(($sAgent =~ /MSIE/i) && !($sAgent =~ /mac/i) && !($sAgent =~ /Opera/i)) {
  91. $iVersion = substr($sAgent,index($sAgent,'MSIE') + 5,3);
  92. return($iVersion >= 5.5) ;
  93. } elsif($sAgent =~ /Gecko\//i) {
  94. $iVersion = substr($sAgent,index($sAgent,'Gecko/') + 6,8);
  95. return($iVersion >= 20030210) ;
  96. } elsif($sAgent =~ /Opera\//i) {
  97. $iVersion = substr($sAgent,index($sAgent,'Opera/') + 6,4);
  98. return($iVersion >= 9.5) ;
  99. } elsif($sAgent =~ /AppleWebKit\/(\d+)/i) {
  100. return($1 >= 522) ;
  101. } else {
  102. return(0); # 2.0 PR fix
  103. }
  104. }
  105. sub GetConfigFieldString
  106. {
  107. $sParams = '';
  108. $bFirst = 0;
  109. foreach $sKey (keys %Config) {
  110. $sValue = $Config{$sKey};
  111. if($bFirst == 1) {
  112. $sParams .= '&amp;';
  113. } else {
  114. $bFirst = 1;
  115. }
  116. $k = &specialchar_cnv($sKey);
  117. $v = &specialchar_cnv($sValue);
  118. if($sValue eq "true") {
  119. $sParams .= "$k=true";
  120. } elsif($sValue eq "false") {
  121. $sParams .= "$k=false";
  122. } else {
  123. $sParams .= "$k=$v";
  124. }
  125. }
  126. return($sParams);
  127. }
  128. 1;