/source/Plug-in/fck/fckeditor.pl

http://prosporous.googlecode.com/ · Perl · 144 lines · 97 code · 15 blank · 32 comment · 16 complexity · 2a03f17efb7a6ae329599bd37362d221 MD5 · raw file

  1. #####
  2. # FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. # Copyright (C) 2003-2007 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 = '<div>' ;
  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. $Html .= '</div>';
  86. return($Html);
  87. }
  88. sub IsCompatible
  89. {
  90. $sAgent = $ENV{'HTTP_USER_AGENT'};
  91. if(($sAgent =~ /MSIE/i) && !($sAgent =~ /mac/i) && !($sAgent =~ /Opera/i)) {
  92. $iVersion = substr($sAgent,index($sAgent,'MSIE') + 5,3);
  93. return($iVersion >= 5.5) ;
  94. } elsif($sAgent =~ /Gecko\//i) {
  95. $iVersion = substr($sAgent,index($sAgent,'Gecko/') + 6,8);
  96. return($iVersion >= 20030210) ;
  97. } elsif($sAgent =~ /Opera\//i) {
  98. $iVersion = substr($sAgent,index($sAgent,'Opera/') + 6,4);
  99. return($iVersion >= 9.5) ;
  100. } elsif($sAgent =~ /AppleWebKit\/(\d+)/i) {
  101. return($1 >= 522) ;
  102. } else {
  103. return(0); # 2.0 PR fix
  104. }
  105. }
  106. sub GetConfigFieldString
  107. {
  108. $sParams = '';
  109. $bFirst = 0;
  110. foreach $sKey (keys %Config) {
  111. $sValue = $Config{$sKey};
  112. if($bFirst == 1) {
  113. $sParams .= '&amp;';
  114. } else {
  115. $bFirst = 1;
  116. }
  117. $k = &specialchar_cnv($sKey);
  118. $v = &specialchar_cnv($sValue);
  119. if($sValue eq "true") {
  120. $sParams .= "$k=true";
  121. } elsif($sValue eq "false") {
  122. $sParams .= "$k=false";
  123. } else {
  124. $sParams .= "$k=$v";
  125. }
  126. }
  127. return($sParams);
  128. }
  129. 1;