| 1 | <?php |
|---|
| 2 | $text = stripslashes($_POST['content']); |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | if(!isset($_REQUEST['utf8_to_entitis']) || $_REQUEST['utf8_to_entities']) |
|---|
| 9 | { |
|---|
| 10 | $text = preg_replace('/([\xC0-\xDF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text); |
|---|
| 11 | $text = preg_replace('/([\xE0-\xEF][\x80-\xBF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text); |
|---|
| 12 | $text = preg_replace('/([\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text); |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | function utf8_ord($chr) |
|---|
| 16 | { |
|---|
| 17 | switch(strlen($chr)) |
|---|
| 18 | { |
|---|
| 19 | case 1 : |
|---|
| 20 | return ord($chr); |
|---|
| 21 | |
|---|
| 22 | case 2 : |
|---|
| 23 | $ord = ord($chr{1}) & 63; |
|---|
| 24 | $ord = $ord | ((ord($chr{0}) & 31) << 6); |
|---|
| 25 | return $ord; |
|---|
| 26 | |
|---|
| 27 | case 3 : |
|---|
| 28 | $ord = ord($chr{2}) & 63; |
|---|
| 29 | $ord = $ord | ((ord($chr{1}) & 63) << 6); |
|---|
| 30 | $ord = $ord | ((ord($chr{0}) & 15) << 12); |
|---|
| 31 | return $ord; |
|---|
| 32 | |
|---|
| 33 | case 4 : |
|---|
| 34 | $ord = ord($chr{3}) & 63; |
|---|
| 35 | $ord = $ord | ((ord($chr{2}) & 63) << 6); |
|---|
| 36 | $ord = $ord | ((ord($chr{1}) & 63) << 12); |
|---|
| 37 | $ord = $ord | ((ord($chr{0}) & 7) << 18); |
|---|
| 38 | return $ord; |
|---|
| 39 | |
|---|
| 40 | default : |
|---|
| 41 | trigger_error('Character not utf-8', E_USER_ERROR); |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'aspell_setup.php'); |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | header('Content-Type: text/html; charset=utf-8'); |
|---|
| 49 | echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|---|
| 50 | <html> |
|---|
| 51 | <head> |
|---|
| 52 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|---|
| 53 | <link rel="stylesheet" type="text/css" media="all" href="spell-check-style.css" />'; |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | $textarray = array(); |
|---|
| 58 | $varlines = '<script type="text/javascript">var suggested_words = { '; |
|---|
| 59 | $infolines = 'var spellcheck_info = {'; |
|---|
| 60 | $counter = 0; |
|---|
| 61 | $suggest_count = 0; |
|---|
| 62 | |
|---|
| 63 | if (trim($text) != "") |
|---|
| 64 | { |
|---|
| 65 | if ($fd = fopen($temptext, 'w')) |
|---|
| 66 | { |
|---|
| 67 | $textarray = explode("\n", $text); |
|---|
| 68 | fwrite ($fd, "!\n"); |
|---|
| 69 | foreach ($textarray as $key=>$value) |
|---|
| 70 | { |
|---|
| 71 | |
|---|
| 72 | fwrite($fd, "^$value\n"); |
|---|
| 73 | } |
|---|
| 74 | fclose($fd); |
|---|
| 75 | chmod($temptext, 0777); |
|---|
| 76 | |
|---|
| 77 | $return = shell_exec($aspellcommand . ' 2>&1'); |
|---|
| 78 | |
|---|
| 79 | unlink($temptext); |
|---|
| 80 | $returnarray = explode("\n", $return); |
|---|
| 81 | $returnlines = count($returnarray); |
|---|
| 82 | |
|---|
| 83 | $textlines = count($textarray); |
|---|
| 84 | |
|---|
| 85 | $lineindex = -1; |
|---|
| 86 | $poscorrect = 0; |
|---|
| 87 | foreach ($returnarray as $key=>$value) |
|---|
| 88 | { |
|---|
| 89 | |
|---|
| 90 | if (substr($value, 0, 1) == '&') |
|---|
| 91 | { |
|---|
| 92 | $counter=$counter+1; |
|---|
| 93 | $correction = explode(' ', $value); |
|---|
| 94 | $word = $correction[1]; |
|---|
| 95 | $suggest_count += $correction[2]; |
|---|
| 96 | $absposition = substr($correction[3], 0, -1) - 1; |
|---|
| 97 | $position = $absposition + $poscorrect; |
|---|
| 98 | $niceposition = $lineindex.','.$absposition; |
|---|
| 99 | $suggstart = strpos($value, ':') + 2; |
|---|
| 100 | $suggestions = substr($value, $suggstart); |
|---|
| 101 | $suggestionarray = explode(', ', $suggestions); |
|---|
| 102 | |
|---|
| 103 | $beforeword = substr($textarray[$lineindex], 0, $position); |
|---|
| 104 | $afterword = substr($textarray[$lineindex], $position + strlen($word)); |
|---|
| 105 | $textarray[$lineindex] = $beforeword.'<span class="HA-spellcheck-error">'.$word.'</span>'.$afterword; |
|---|
| 106 | |
|---|
| 107 | $suggestion_list = ''; |
|---|
| 108 | foreach ($suggestionarray as $key=>$value) |
|---|
| 109 | { |
|---|
| 110 | $suggestion_list .= $value.','; |
|---|
| 111 | } |
|---|
| 112 | $suggestion_list = substr($suggestion_list, 0, strlen($suggestion_list) - 1); |
|---|
| 113 | $varlines .= '"'.$word.'":"'.$suggestion_list.'",'; |
|---|
| 114 | |
|---|
| 115 | $poscorrect = $poscorrect + 41; |
|---|
| 116 | } |
|---|
| 117 | elseif (substr($value, 0, 1) == '#') |
|---|
| 118 | { |
|---|
| 119 | $correction = explode(' ', $value); |
|---|
| 120 | $word = $correction[1]; |
|---|
| 121 | $absposition = $correction[2] - 1; |
|---|
| 122 | $position = $absposition + $poscorrect; |
|---|
| 123 | $niceposition = $lineindex.','.$absposition; |
|---|
| 124 | $beforeword = substr($textarray[$lineindex], 0, $position); |
|---|
| 125 | $afterword = substr($textarray[$lineindex], $position + strlen($word)); |
|---|
| 126 | $textarray[$lineindex] = $beforeword.$word.$afterword; |
|---|
| 127 | $textarray[$lineindex] = $beforeword.'<span class="HA-spellcheck-error">'.$word.'</span><span class="HA-spellcheck-suggestions">'.$word.'</span>'.$afterword; |
|---|
| 128 | |
|---|
| 129 | $poscorrect = $poscorrect + 88 + strlen($word); |
|---|
| 130 | } |
|---|
| 131 | else |
|---|
| 132 | { |
|---|
| 133 | |
|---|
| 134 | $poscorrect = 0; |
|---|
| 135 | $lineindex = $lineindex + 1; |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | |
|---|
| 142 | $return = 'failed to open!'; |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | else |
|---|
| 146 | { |
|---|
| 147 | $returnlines=0; |
|---|
| 148 | } |
|---|
| 149 | $infolines .= '"Language Used":"'.$lang.'",'; |
|---|
| 150 | $infolines .= '"Mispelled words":"'.$counter.'",'; |
|---|
| 151 | $infolines .= '"Total words suggested":"'.$suggest_count.'",'; |
|---|
| 152 | $infolines .= '"Total Lines Checked":"'.$returnlines.'"'; |
|---|
| 153 | $infolines .= '};'; |
|---|
| 154 | $varlines = substr($varlines, 0, strlen($varlines) - 1); |
|---|
| 155 | echo $varlines.'};'.$infolines.'</script>'; |
|---|
| 156 | |
|---|
| 157 | echo '</head> |
|---|
| 158 | <body onload="window.parent.finishedSpellChecking();">'; |
|---|
| 159 | |
|---|
| 160 | foreach ($textarray as $key=>$value) |
|---|
| 161 | { |
|---|
| 162 | echo $value; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | $dictionaries = str_replace(chr(10),",", shell_exec($aspelldictionaries)); |
|---|
| 166 | if(ereg(",$",$dictionaries)) |
|---|
| 167 | $dictionaries = ereg_replace(",$","",$dictionaries); |
|---|
| 168 | echo '<div id="HA-spellcheck-dictionaries">'.$dictionaries.'</div>'; |
|---|
| 169 | |
|---|
| 170 | echo '</body></html>'; |
|---|
| 171 | ?> |
|---|