Ejemplo n.º 1
0
function showSuggestions($word, $id)
{
    global $editablePersonalDict;
    //bool to set editability of personal dictionary
    global $allowCustomInserts;
    //bool to set the option to allow custom text inserts
    global $pspell_link;
    //the global link to the pspell module
    global $cp;
    //the CPAINT object
    $retVal = "";
    $suggestions = pspell_suggest($pspell_link, utf8_decode($word));
    //an array of all the suggestions that psepll returns for $word.
    // If the number of suggestions returned by pspell is less than the maximum
    // number, just use the number of suggestions returned.
    $numSuggestions = count($suggestions);
    $tmpNum = min($numSuggestions, MAX_SUGGESTIONS);
    if ($tmpNum > 0) {
        //this creates the table of suggestions.
        //in the onclick event it has a call to the replaceWord javascript function which does the actual replacing on the page
        for ($i = 0; $i < $tmpNum; $i++) {
            $retVal .= "<div class=\"suggestion\"  onmouseover=\"this.className='suggestion_hover'\" onmouseout=\"this.className='suggestion'\" onclick=\"replaceWord('" . addslashes_custom($id) . "', '" . addslashes($suggestions[$i]) . "'); return false;\">" . $suggestions[$i] . "</div>";
        }
        if ($allowCustomInserts) {
            $retVal .= "<div class=\"customInsert\" onmouseover=\"this.className='customInsert_hover'\" onmouseout=\"this.className='customInsert'\"><form name=\"custom_form\" style=\"margin:0px;\"><input type=\"text\" id=\"custom_form_box\" class=\"customInsertText\" onclick=\"get_id('custom_form_box').focus(); return false;\"><input type=\"button\" value=\"Insert\" class=\"customInsertAdd\" onclick=\"addWord('" . addslashes_custom($id) . "'); return false;\"></form></div>";
        }
        if ($editablePersonalDict) {
            $retVal .= "<div class=\"addtoDictionary\" onmouseover=\"this.className='addtoDictionary_hover'\" onmouseout=\"this.className='addtoDictionary'\" onclick=\"addWord('" . addslashes_custom($id) . "'); return false;\">Add To Dictionary</div>";
        }
    } else {
        $retVal .= "No Suggestions";
    }
    $cp->set_data($retVal);
    //the return value - a string containing the table of suggestions.
}
Ejemplo n.º 2
0
function showSuggestions($word, $id)
{
    global $usePersonalDict;
    //bool to set usage of personal dictionary
    global $pspell_link;
    //the global link to the pspell module
    global $cp;
    //the CPAINT object
    $retVal = "";
    $suggestions = pspell_suggest($pspell_link, $word);
    //an array of all the suggestions that psepll returns for $word.
    $numSuggestions = count($suggestions);
    $numSuggestionsToReturn = 10;
    //the maximum number of suggestions to return.
    //if the number of suggestions returned by pspell is less than the maximum number, just use the number of suggestions returned.
    if ($numSuggestions < $numSuggestionsToReturn) {
        $tmpNum = $numSuggestions;
    } else {
        //else, just the custom number
        $tmpNum = $numSuggestionsToReturn;
    }
    if ($tmpNum > 0) {
        //$retVal .= "<table>";
        //this creates the table of suggestions.
        //in the onclick event it has a call to the replaceWord javascript function which does the actual replacing on the page
        for ($i = 0; $i < $tmpNum; $i++) {
            $retVal .= "<div class=\"suggestion\" onclick=\"replaceWord('" . addslashes_custom($id) . "', '" . addslashes($suggestions[$i]) . "')\">" . $suggestions[$i] . "</div>";
        }
        if ($usePersonalDict) {
            $retVal .= "<div class=\"addtoDictionary\" onclick=\"addWord('" . addslashes_custom($id) . "')\">Add To Dictionary</div>";
        }
    } else {
        $retVal .= "No Suggestions";
    }
    $cp->set_data($retVal);
    //the return value - a string containing the table of suggestions.
}