compose.spell.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:7k
- <?php
- error_reporting(E_ALL & ~E_NOTICE);
- session_start();
- ############################################################################
- // get rid of slashes in get / post / cookie data
- if (get_magic_quotes_gpc()) {
- function stripslashesarray($array) {
- if (is_array($array)) {
- foreach($array as $key => $val) {
- if (is_array($val)) {
- $array["$key"] = stripslashesarray($val);
- } elseif (is_string($val)) {
- if (get_cfg_var('magic_quotes_sybase')) {
- $array["$key"] = str_replace("''", "'", $val);
- } else {
- $array["$key"] = stripslashes($val);
- }
- }
- }
- }
- return $array;
- }
- $_GET = stripslashesarray($_GET);
- $_POST = stripslashesarray($_POST);
- $_COOKIE = stripslashesarray($_COOKIE);
- $_REQUEST = stripslashesarray($_REQUEST);
- }
- set_magic_quotes_runtime(0);
- require_once('./functions.php');
- // register_globals off/on
- if (!isset($cmd)) {
- $cmd = $_REQUEST['cmd'];
- }
- // ############################################################################
- // Show processing frameset
- if ($cmd == 'procframeset') {
- $_SESSION['spell_wordbox'] = $_REQUEST[$_REQUEST['box']];
- if ($_REQUEST['html']) {
- $spell_html = 1;
- }
- // some variables for template
- $_SESSION['spell_form'] = $_REQUEST['frm'];
- $_SESSION['spell_textarea'] = $_REQUEST['box'];
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "XHTML1-f.dtd">
- <html>
- <head>
- <title>SpellingPRO Spell Checker</title>
- <frameset rows="0,*" framespacing="0" frameborder="no" border="1">
- <frame name="process" scrolling="no" _noresize="noresize" frameborder="no" border="0" src="compose.spell.php?cmd=process&spell_html=<?php echo $spell_html; ?>&sendafter=<?php echo $sendafter; ?>" />
- <frame name="content" scrolling="no" _noresize="noresize" frameborder="no" border="0" marginwidth="0" marginheight="0" src="compose.spell.php?cmd=loading" />
- </frameset>
- </head>
- </html>
- <?php
- }
- // ############################################################################
- // Show "Loading..." screen
- if ($cmd == 'loading') {
- eval(makeeval('echo', 'compose_spell_loading'));
- }
- // ############################################################################
- // Process text and come up with misspelled words and suggestions
- if ($cmd == 'process') {
- require_once('./spell_data.php');
-
- $jsOutput = spell_process($_SESSION['spell_wordbox'], 'metaphone', $spell_html, $sendafter);
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html>
- <head>
- <title>HiveMail: Spell Checker</title>
- <?php //echo '<pre>'.htmlspecialchars($jsOutput); ?>
- <script>
- <!--
- <?php echo $jsOutput; ?>
- // Return context of misspelling
- function getContext(intMissNum) {
- return msMissWordAr[intMissNum][2];
- }
- // Return the original index of the misspelled word from the main word array
- function getOi(intMissNum) {
- return msMissWordAr[intMissNum][1];
- }
- // Return misspelled word
- function getWord(intMissNum) {
- return msMissWordAr[intMissNum][0];
- }
- // Return number of suggestions for word
- function getSuggNum(intMissNum) {
- return msMissWordAr[intMissNum][3].length();
- }
- // Return array of word suggestions
- function getSuggList(intMissNum) {
- return msMissWordAr[intMissNum][3];
- }
- // Return true if we are at the end of the misspelled word array
- function isEnd(intMissNum) {
- return (intMissNum >= (msMissWordAr.length - 1));
- }
- // Return total misspelled
- function getMisspelledCount() {
- return msWc;
- }
- // Sets the corrected word in the original array
- function setNewWord(intMissNum, strNewWord) {
- var oi = getOi(intMissNum);
- var strOWord = getWord(intMissNum);
- msOrigWordAr[oi] = msOrigWordAr[oi].replace(strOWord, strNewWord);
- }
- // Sets the corrected word in the original array
- function setNewWord(intMissNum, strNewWord) {
- var oi = getOi(intMissNum);
- lastOrigWord = getWord(intMissNum);
- msOrigWordAr[oi] = msOrigWordAr[oi].replace(lastOrigWord, strNewWord);
- }
- // Sets the original word in the original array
- function setOrigWord(intMissNum, lastOrigWord) {
- var oi = getOi(intMissNum);
- var strNewWord = msOrigWordAr[oi];
- msOrigWordAr[oi] = msOrigWordAr[oi].replace(strNewWord, lastOrigWord);
- }
- // Returns the whole orginal word array (with assumed spell check corrections in place) for reassembly
- function getOrigAr() {
- return msOrigWordAr;
- }
- // Returns the last original word that was replaced
- function getLastOrigWord() {
- return lastOrigWord;
- }
- // -->
- </script>
- </head>
- <body>
- </body>
- </html>
- <?php
- }
- // ############################################################################
- // Yay! No mistakes found!
- if ($cmd == 'noerrors') {
- eval(makeeval('echo', 'compose_spell_noerrors'));
- }
- // ############################################################################
- // Show suggestions
- if ($cmd == 'suggestions') {
- $textarea_name = $_SESSION['spell_textarea'];
- $form_name = $_SESSION['spell_form'];
- eval(makeeval('echo', 'compose_spell_suggestions'));
- }
- // ############################################################################
- // Update user's dictionary and common mistakes
- if ($_POST['cmd'] == 'updatedata') {
- // Add new words into dictionary
- /*
- ************ NOT DONE YET ************
- $newWords = array_unique(explode("n", $newWords));
- $newValues = array();
- foreach ($newWords as $word) {
- if (trim($word) == '') {
- continue;
- }
- $newValues[] = "('".addslashes($word)."', '".addslashes(metaphone($word))."', $hiveuser[userid])";
- }
- if (!empty($newValues)) {
- $DB_site->query('
- INSERT INTO hive_word
- (word, metaphone, userid)
- VALUES '.implode(', ', $newValues).'
- ');
- }
- // Build combos of bad and good words
- $goodWords = explode("n", $changedTo);
- $badWords = explode("n", $changedFrom);
- $combos = array();
- for ($i = 0; $i < count($goodWords); $i++) {
- $goodWords[$i] = trim($goodWords[$i]);
- $badWords[$i] = trim($badWords[$i]);
- $combos[$i] = strtolower(addslashes($badWords[$i].'~'.$goodWords[$i]));
- }
- // Get existing changes
- $changes = $DB_site->query("
- SELECT *
- FROM hive_wordchange
- WHERE userid = $hiveuser[userid]
- AND combo IN ("".implode('", "', $combos)."")
- ");
- print_R($combos);
- while ($change = $DB_site->fetch_array($changes)) {
- print_R($change);
- // I know this is not very optimizied, but, well... I'll fix it later
- while (($foundKey = array_search($change['combo'], $combos)) !== false) {
- $DB_site->query("
- UPDATE hive_wordchange
- SET times = times + 1
- WHERE userid = $hiveuser[userid]
- AND combo = '".addslashes($change['combo'])."'
- ");
- unset($combos[$foundKey]);
- }
- }
- // Create new records for new combos
- $newCombos = array();
- foreach ($combos as $key => $combo) {
- if (trim($badWords[$key]) == '') {
- continue;
- }
- $newCombos[] = "($hiveuser[userid], '".addslashes($badWords[$key])."', '".addslashes($combo)."', 1)";
- }
- if (!empty($newCombos)) {
- $DB_site->query('
- INSERT INTO hive_wordchange
- (userid, wrongword, combo, times)
- VALUES '.implode(', ', $newCombos).'
- ');
- }
- */
- // Close window
- ?><script language="JavaScript" type="text/javascript">
- <!--
- window.top.window.close();
- //-->
- </script><?php
- exit;
- }
- ?>