Changeset 503 for branches/1.1dev/lib


Ignore:
Timestamp:
Feb 10, 2015 12:03:25 AM (9 years ago)
Author:
anonymous
Message:

Backported spellcheck fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/SpellCheck.inc.php

    r434 r503  
    2020        'highlight_end' => '</strong>',
    2121    );
    22    
     22
    2323    var $_pspell_cfg_handle;
    2424    var $_pspell_handle;
    2525    var $_use_personal_wordlist = false;
    2626    var $_errors = array();
    27    
     27
    2828    /**
    2929     * Constructor.
     
    8585        return $this->_params[$param];
    8686    }
    87    
     87
    8888    /**
    8989     * Check whether any errors have been triggered.
     
    103103        $this->_errors = array();
    104104    }
    105    
     105
    106106    /**
    107107     * Check one word.
     
    123123        }
    124124    }
    125    
     125
    126126    /**
    127127     * Suggest the correct spelling for one misspelled word.
     
    138138        return pspell_suggest($this->_pspell_handle, $word);
    139139    }
    140    
     140
    141141    /**
    142142     * Add a word to a personal list.
     
    154154            if (pspell_add_to_personal($this->_pspell_handle, $word)) {
    155155                logMsg(sprintf('Added "%s" to personal wordlist: %s', $word, $this->getParam('personal_wordlist')), LOG_DEBUG, __FILE__, __LINE__);
    156                 return true;           
     156                return true;
    157157            } else {
    158158                logMsg(sprintf('Failed adding "%s" to personal wordlist: %s', $word, $this->getParam('personal_wordlist')), LOG_ERR, __FILE__, __LINE__);
     
    161161        }
    162162    }
    163    
     163
    164164    /**
    165165     * Save personal list to file.
     
    184184        }
    185185    }
    186    
     186
    187187    /**
    188188     * Returns an array of suggested words for each misspelled word in the given text.
     
    221221        }
    222222    }
    223    
     223
    224224    /**
    225225     * Checks all words in a given string.
     
    255255        }
    256256    }
    257    
     257
    258258    /**
    259259     * Returns a given string with misspelled words highlighted.
     
    267267     */
    268268    function getStringHighlighted($string, $show_footnote=false)
    269     { 
     269    {
    270270        // Split words on punctuation except apostrophes (this regex is used in several places in this class).
    271271        // http://stackoverflow.com/questions/790596/split-a-text-into-single-words
     
    279279                    $footnote = $show_footnote ? '<sup style="color:#999;">' . ++$cnt . '</sup>' : '';
    280280                    $words[$i] = $this->getParam('highlight_start') . $word . $this->getParam('highlight_end') . $footnote;
    281                     $string = preg_replace("/\b$word\b/", $words[$i], $string);
     281                    $string = preg_replace(sprintf('/\b%s\b/', preg_quote($word, '/')), $words[$i], $string);
    282282                }
    283283            }
    284284        }
    285285        return $string;
    286         // return join(' ', $words);
    287     }
    288    
     286    }
     287
    289288    /**
    290289     * Prints the HTML for correcting all misspellings found in the text of one $_FORM element.
     
    302301        <input name="<?php echo $form_name ?>" type="hidden" value="<?php echo oTxt(getFormData($form_name)) ?>" />
    303302        <?php
    304        
     303
    305304        $form_words = $this->getStringSuggestions(getFormData($form_name));
    306305        if (is_array($form_words) && !empty($form_words)) {
     
    315314                <option value="<?php echo $original_word ?>">(<?php echo $original_word ?>)</option>
    316315                <?php
    317                
     316
    318317                foreach ($words as $suggestion) {
    319318                    ?>
     
    321320                    <?php
    322321                }
    323                
     322
    324323                ?>
    325324                </select>
     
    334333        }
    335334    }
    336    
     335
    337336    /**
    338337     * Tests if any form spelling corrections have been submitted.
     
    348347        return (false !== getFormData('spelling_suggestions', false)) || (false !== getFormData('spelling_corrections', false));
    349348    }
    350    
     349
    351350    /**
    352351     * Replace the misspelled words in the text of a specified form with the corrections.
Note: See TracChangeset for help on using the changeset viewer.