1 # ===================================================================== 2 # aspellTinyMCE: W-TW spell checker for the TinyMCE client editor. 3 # 4 # Copyright (c) 2007 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # Local variables and functions 23 # ===================================================================== 24 25 # Re-define csaExit.fault for TinyMCE AJAX error responses. 26 27 fn csaExit.fault { 28 29 # This check may never be triggered if the URL rewriting map 30 # (rest.map) only allows POST for this program. Leaving it 31 # in place will not hurt anyway. 32 33 ~ $2 0071 && xml_err_txt = 'requested method not found' 34 35 ~ $2 () || csaPrintMsg $2 # log the event. 36 37 xml_err_len = `{wc -c <<< $xml_err_txt$'cgi.aspell.id'$'cgi.aspell.cmd'} 38 xml_err_len = `{expr $xml_err_len + 81} # add envelope length. 39 40 # Single-quoted vars do not work in HERE documents. 41 xml_aspell_id = $'cgi.aspell.id' 42 xml_aspell_cmd = $'cgi.aspell.cmd' 43 44 cat < 51 52 EOF 53 csaExit 1 54 } 55 56 cgi.group = () 57 cgi.aspell.id = () 58 cgi.aspell.cmd = () 59 cgi.aspell.lang = $CSA_LANG # set default language 60 61 tmp_file = /dev/null 62 63 xml_err_txt = 'internal server error' 64 65 # ===================================================================== 66 # Main program 67 # ===================================================================== 68 69 # From a REST perspective using GET would be more appropriate here, 70 # but since the amount of input data can be large using POST is more 71 # sensible. 72 73 csaGetArgs POST 74 75 # Check the single most important arg. 76 77 if (~ $'cgi.group' ()) { 78 xml_err_txt = 'requested resource not found' 79 csaExit.fault 80 } 81 82 tw_gstem = $CSA_ROOT/var/pages/$CSA_LANG/$'cgi.group' 83 84 # Load group-level configuration settings if available. 85 csaIsFullPath --exists --quiet $tw_gstem+cf && . $tw_gstem+cf 86 87 # Policy checks should always come after the inclusion 88 # of the group +cf file. 89 90 ~ ,$TNS_AUTH_GRP, *,editor,* || { 91 xml_err_txt = 'access denied' 92 csaExit.fault 93 } 94 95 # A few checks to make sure we are being called the way we 96 # are supposed to. 97 98 ~ $'cgi.aspell.id' () && { 99 xml_err_txt = 'bad or missing args' 100 csaExit.fault 101 } 102 103 ~ $'cgi.aspell.cmd' spell suggest || { 104 xml_err_txt = 'bad or missing args' 105 csaExit.fault 106 } 107 108 csaMkTemp tmp_file 109 110 # We tell aspell(1) to use hard-coded UTF-8. This can be made ad argument 111 # in the future, but since even the default php code supplied with TinyMCE 112 # has it hard-coded it will be ok here too. 113 114 aspell -a -l $'cgi.aspell.lang' \ 115 --encoding'=utf-8' -H < $TNS_ASPELL_DATA > $tmp_file || csaExit.fault 116 117 csaMkTemp tpl.include.tw.page 118 119 # No group/page information is received by this program so it can only 120 # use the default response template. Furthermore, if the response 121 # contains other than what TinyMCS expects, such as the usual CSA 122 # RDF block, it either does not recognize or ignores the received 123 # response, no matter whether it is embedded inside the RDF block or 124 # it is external to it. On the other hand CSA cannot be told that the 125 # output must be strict RDF as otherwise it will strip everything except 126 # the RDF block, so we are left with the sole choice to provide a 127 # separate template and force the proper content-type header for it. PRG 128 # redirection will occur, but TinyMCE (or more likely the AJAX code that 129 # it uses, seems to be clever enough to follow it so it works. 130 131 CSA_MIME_HEADER = 'text/xml; charset='"$CSA_CHARSET" 132 133 csaExit.ok --table $tmp_file \ 134 --file-root $CSA_ROOT/lib/default tw-spellcheck-tinymce.$CSA_TPLEXT 135 136 #EOF