Changeset 503 for branches/1.1dev
- Timestamp:
- Feb 10, 2015 12:03:25 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1dev/lib/SpellCheck.inc.php
r434 r503 20 20 'highlight_end' => '</strong>', 21 21 ); 22 22 23 23 var $_pspell_cfg_handle; 24 24 var $_pspell_handle; 25 25 var $_use_personal_wordlist = false; 26 26 var $_errors = array(); 27 27 28 28 /** 29 29 * Constructor. … … 85 85 return $this->_params[$param]; 86 86 } 87 87 88 88 /** 89 89 * Check whether any errors have been triggered. … … 103 103 $this->_errors = array(); 104 104 } 105 105 106 106 /** 107 107 * Check one word. … … 123 123 } 124 124 } 125 125 126 126 /** 127 127 * Suggest the correct spelling for one misspelled word. … … 138 138 return pspell_suggest($this->_pspell_handle, $word); 139 139 } 140 140 141 141 /** 142 142 * Add a word to a personal list. … … 154 154 if (pspell_add_to_personal($this->_pspell_handle, $word)) { 155 155 logMsg(sprintf('Added "%s" to personal wordlist: %s', $word, $this->getParam('personal_wordlist')), LOG_DEBUG, __FILE__, __LINE__); 156 return true; 156 return true; 157 157 } else { 158 158 logMsg(sprintf('Failed adding "%s" to personal wordlist: %s', $word, $this->getParam('personal_wordlist')), LOG_ERR, __FILE__, __LINE__); … … 161 161 } 162 162 } 163 163 164 164 /** 165 165 * Save personal list to file. … … 184 184 } 185 185 } 186 186 187 187 /** 188 188 * Returns an array of suggested words for each misspelled word in the given text. … … 221 221 } 222 222 } 223 223 224 224 /** 225 225 * Checks all words in a given string. … … 255 255 } 256 256 } 257 257 258 258 /** 259 259 * Returns a given string with misspelled words highlighted. … … 267 267 */ 268 268 function getStringHighlighted($string, $show_footnote=false) 269 { 269 { 270 270 // Split words on punctuation except apostrophes (this regex is used in several places in this class). 271 271 // http://stackoverflow.com/questions/790596/split-a-text-into-single-words … … 279 279 $footnote = $show_footnote ? '<sup style="color:#999;">' . ++$cnt . '</sup>' : ''; 280 280 $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); 282 282 } 283 283 } 284 284 } 285 285 return $string; 286 // return join(' ', $words); 287 } 288 286 } 287 289 288 /** 290 289 * Prints the HTML for correcting all misspellings found in the text of one $_FORM element. … … 302 301 <input name="<?php echo $form_name ?>" type="hidden" value="<?php echo oTxt(getFormData($form_name)) ?>" /> 303 302 <?php 304 303 305 304 $form_words = $this->getStringSuggestions(getFormData($form_name)); 306 305 if (is_array($form_words) && !empty($form_words)) { … … 315 314 <option value="<?php echo $original_word ?>">(<?php echo $original_word ?>)</option> 316 315 <?php 317 316 318 317 foreach ($words as $suggestion) { 319 318 ?> … … 321 320 <?php 322 321 } 323 322 324 323 ?> 325 324 </select> … … 334 333 } 335 334 } 336 335 337 336 /** 338 337 * Tests if any form spelling corrections have been submitted. … … 348 347 return (false !== getFormData('spelling_suggestions', false)) || (false !== getFormData('spelling_corrections', false)); 349 348 } 350 349 351 350 /** 352 351 * Replace the misspelled words in the text of a specified form with the corrections.
Note: See TracChangeset
for help on using the changeset viewer.