[ Index ]
 

Code source de FCKeditor 2.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/editor/dialog/fck_spellerpages/spellerpages/server-scripts/ -> spellchecker.cfm (source)

   1  <cfsilent>
   2  <!--- 
   3  This code uses a CF User Defined Function and should work in CF version 5.0
   4  and up without alteration.
   5  
   6  Also if you are hosting your site at an ISP, you will have to check with them
   7  to see if the use of <CFEXECUTE> is allowed. In most cases ISP will not allow
   8  the use of that tag for security reasons. Clients would be able to access each
   9  others files in certain cases.
  10  --->
  11   
  12  <!--- 
  13  The following variables values must reflect your installation needs.
  14  --->
  15  <cfset apsell_dir    = "c:\aspell\bin">
  16  
  17  <cfset lang            = "en_US">
  18  <cfset aspell_opts    = "-a --lang=#lang# --encoding=utf-8 -H">
  19  
  20  <!--- Be sure the temporary folder exists --->
  21  <cfset tempFolder    = "c:\aspell\temp">
  22  <cfset tempfile        = "spell_#randrange(1,10000)#">
  23  
  24  <cfset spellercss    = "../spellerStyle.css">
  25  <cfset word_win_src    = "../wordWindow.js">
  26  
  27  <cfset form.checktext = form["textinputs[]"]>
  28  
  29  <cfscript>
  30    function LastIndexOf(subs, str)
  31    {
  32      return Len(str) - Find(subs, Reverse(str)) + 1;
  33    }
  34  </cfscript>
  35  
  36  <!--- Takes care of those pesky smart quotes from MS apps, replaces them with regular quotes --->
  37  <cfparam name="url.checktext" default="">
  38  <cfparam name="form.checktext" default="#url.checktext#">
  39  <cfset submitted_text = replacelist(form.checktext,"%u201C,%u201D","%22,%22")> 
  40  
  41  <!--- submitted_text now is ready for processing --->
  42  
  43  <!--- use carat on each line to escape possible aspell commands --->
  44  <cfset text = "">
  45  <cfset crlf = Chr(13) & Chr(10)>
  46  
  47  <cfloop list="#submitted_text#" index="field" delimiters=",">
  48    <cfset text = text & "%" & crlf
  49                       & "^A" & crlf
  50                       & "!" & crlf>
  51    <cfset field = URLDecode(field)>
  52    <cfloop list="#field#" index="line" delimiters="#crlf#">
  53  <!---     <cfset submitted_text = replace(submitted_text,"'","\'","All")>
  54      <cfset submitted_text = replace(submitted_text,"""","\""","All")> --->
  55        <cfset text = text & "^" & Trim(JSStringFormat(line)) & "#crlf#">
  56    </cfloop>
  57  </cfloop>
  58  
  59  
  60  <!--- need to escape special javascript characters such as ' --->
  61  <cfset unaltered_text = submitted_text>
  62  
  63  <!--- create temp file from the submitted text, this will be passed to aspell to be check for misspelled words --->
  64  <cffile action="write" file="#tempFolder#\#tempfile#.txt" output="#text#" charset="utf-8">
  65  
  66  <!--- cfsavecontent is used to set the variable that will be returned with the results from aspell.
  67  If your using the new version of mx 6.1 you can  use the following cfexecute tag instead:
  68  <cfexecute name="C:\WINDOWS\SYSTEM32\cmd.exe" arguments="/c type c:\test\#tempfile#.txt | c:\aspell\bin\aspell #aspell_opts#" timeout="100" variable="results"></cfexecute> --->
  69  
  70  
  71  
  72  <cfsavecontent variable="food">
  73  <cfexecute name="C:\WINDOWS\SYSTEM32\cmd.exe" arguments="/c type #tempFolder#\#tempfile#.txt | #apsell_dir#\aspell #aspell_opts#" timeout="100"></cfexecute>
  74  </cfsavecontent>
  75  
  76  
  77  
  78  <!--- remove temp file --->
  79  <cffile action="delete" file="#tempFolder#\#tempfile#.txt">
  80  
  81  <cfset texts = StructNew()>
  82  <cfset texts.textinputs = "">
  83  <cfset texts.words = "">
  84  <cfset texts.abort = "">
  85  
  86  <!--- Generate Text Inputs --->
  87  
  88  <cfset i = "0">
  89  <cfloop index="text" list="#form.checktext#">
  90    <cfset texts.textinputs = ListAppend(texts.textinputs, 'textinputs[#i#] = decodeURIComponent("#text#");', '#Chr(13)##Chr(10)#')>
  91    <cfset i = i + "1">
  92  </cfloop>
  93  
  94  <!--- Generate Words Lists --->
  95  
  96  <cfset cnt = "1">
  97  <cfset word_cnt = "0">
  98  <cfset input_cnt = "-1">
  99  <cfloop list="#food#" index="list" delimiters="#chr(10)##chr(13)#">
 100      <!--- removes the first line of the aspell output "@(#) International Ispell Version 3.1.20 (but really Aspell 0.50.3)" --->
 101      <cfif NOT cnt IS "1">
 102          <cfif Find("&", list) OR Find("##", list)>
 103              <!--- word that misspelled --->
 104              <cfset bad_word = listGetAt(list, "2", " ")>
 105              <!--- sugestions --->
 106              <cfset wrdList = mid(list,(LastIndexOf(':', list) + 2),(len(list) - (LastIndexOf(':', list) + 2)))>
 107              <cfset wrdsList = "">
 108              <cfloop list="#wrdList#" index="idx">
 109                  <cfset wrdsList = ListAppend(wrdsList, " '" & trim(replace(idx,"'","\'","All")) & "'", ", ")>
 110              </cfloop>
 111        <cfset wrdsList = Right(wrdsList, Len(wrdsList) - 1)>
 112              <!--- javascript --->
 113              <cfset texts.words = ListAppend(texts.words, "words[#input_cnt#][#word_cnt#] = '#trim(replace(bad_word,"'","\'","All"))#';", "#Chr(13)##Chr(10)#")>
 114              <cfset texts.words = ListAppend(texts.words, "suggs[#input_cnt#][#word_cnt#] = [#trim(wrdsList)#];", "#Chr(13)##Chr(10)#")>
 115              <cfset word_cnt = word_cnt + 1>
 116          <cfelseif find("*", list)>
 117        <cfset input_cnt = input_cnt + "1">
 118        <cfset word_cnt = "0">
 119        <cfset texts.words = ListAppend(texts.words, "words[#input_cnt#] = [];", "#crlf#")>
 120        <cfset texts.words = ListAppend(texts.words, "suggs[#input_cnt#] = [];", "#crlf#")>
 121          </cfif>            
 122      </cfif>
 123      <cfset cnt = cnt + 1>
 124  </cfloop>
 125  
 126  <cfif texts.words IS "">
 127    <cfset texts.abort = "alert('Spell check complete.\n\nNo misspellings found.');#chrlf#top.window.close();">
 128  </cfif>
 129  
 130  </cfsilent><cfoutput><cfcontent type="text/html"><html>
 131  <head>
 132  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 133  <link rel="stylesheet" type="text/css" href="#spellercss#" />
 134  <script language="javascript" src="#word_win_src#"></script>
 135  <script language="javascript">
 136  var suggs = new Array();
 137  var words = new Array();
 138  var textinputs = new Array();
 139  var error;
 140  
 141  #texts.textinputs##Chr(13)##Chr(10)#
 142  #texts.words#
 143  #texts.abort#
 144  
 145  var wordWindowObj = new wordWindow();
 146  wordWindowObj.originalSpellings = words;
 147  wordWindowObj.suggestions = suggs;
 148  wordWindowObj.textInputs = textinputs;
 149  
 150  function init_spell() {
 151      // check if any error occured during server-side processing
 152      if( error ) {
 153          alert( error );
 154      } else {
 155          // call the init_spell() function in the parent frameset
 156          if (parent.frames.length) {
 157              parent.init_spell( wordWindowObj );
 158          } else {
 159              alert('This page was loaded outside of a frameset. It might not display properly');
 160          }
 161      }
 162  }
 163  
 164  </script>
 165  
 166  </head>
 167  <body onLoad="init_spell();">
 168  
 169  <script type="text/javascript">
 170  wordWindowObj.writeBody();
 171  </script>
 172  
 173  </body>
 174  </html></cfoutput>


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7