function serve_get_word($cookie, $word, $reg_code) { global $f_check_limits; /* if ( $word=='wl' ) { write_WORDLIST( "word one\nand another\nand even more\nword three\ntest\nsample\n" ); exit; } if ( $word=='tm' ) { write_MSG( "This is a test message. Do you hear me now?" ); exit; } */ $requests_left = -1; if (!$reg_code && $f_check_limits) { $total_requests = get_total_requests_for_cookie($cookie); $requests_left = TOTAL_REQUESTS_LIMIT - $total_requests + DAILY_REQUESTS_LIMIT; if ($requests_left <= 0) { $today_requests = get_today_requests_for_cookie($cookie); $requests_left = DAILY_REQUESTS_LIMIT - $today_requests; if ($requests_left <= 0) { report_no_lookups_left(); } } else { $requests_left = TOTAL_REQUESTS_LIMIT - $total_requests + DAILY_REQUESTS_LIMIT; } } log_get_word_request($cookie, $word, $reg_code); $word_row = get_word_row_try_stemming($word); if ($word_row) { write_DEF($word_row->word, $word_row->pron, $word_row->def, $requests_left); } else { write_MSG("Definition of word '{$word}' has not been found"); } exit; }
function serve_get_word($cookie, $word) { /* if ( $word=='wl' ) { write_WORDLIST( "word one\nand another\nand even more\nword three\ntest\nsample\n" ); exit; } if ( $word=='tm' ) { write_MSG( "This is a test message. Do you hear me now?" ); exit; } */ $orig_word = $word; log_get_word_request($cookie, $word); $word_row = get_word_row($word); if ($word_row) { write_DEF($word, $word_row->pron, $word_row->def); exit; } # didnt find the exact word, so try a few heuristics # if word ends with "s", try to find word without it e.g. "strings" => "string" if ("s" == substr($word, strlen($word) - 1)) { $word = substr($word, 0, strlen($word) - 1); $word_row = get_word_row($word); if ($word_row) { write_DEF($word, $word_row->pron, $word_row->def); exit; } } # if word ends with "ed", try to find word without it e.g. "glued" => "glue" if ("ed" == substr($word, strlen($word) - 2)) { $word = substr($word, 0, strlen($word) - 2); $word_row = get_word_row($word); if ($word_row) { write_DEF($word, $word_row->pron, $word_row->def); exit; } } # if word ends with "ing", try to find word without it e.g. "working" => "work" if ("ing" == substr($word, strlen($word) - 3)) { $word = substr($word, 0, strlen($word) - 3); $word_row = get_word_row($word); if ($word_row) { write_DEF($word, $word_row->pron, $word_row->def); exit; } } # didnt find the word write_MSG("Definition of word '{$orig_word}' has not been found"); exit; }