Changeset 42 for trunk/lib/SpellCheck.inc.php
- Timestamp:
- Dec 18, 2005 12:16:03 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/SpellCheck.inc.php
r41 r42 9 9 * @version 1.1 10 10 */ 11 11 12 12 /* Implementation example: 13 13 -------------------------------------------------------------------------------- … … 17 17 // Instantiate with parameters. In this example we'll set the language and the path to the personal wordlist file. 18 18 $spell = new SpellCheck(array( 19 'language' => 'en', 19 'language' => 'en', 20 20 'personal_wordlist' => '/tmp/my_custom_dict' 21 21 )); … … 49 49 'highlight_end' => '</strong>', 50 50 ); 51 51 52 52 var $_pspell_cfg_handle; 53 53 var $_pspell_handle; 54 54 var $_use_personal_wordlist = false; 55 55 var $_errors = array(); 56 56 57 57 /** 58 58 * Constructor. 59 59 * 60 60 * @param array $params Array of parameters (key => val pairs). 61 61 */ 62 62 function SpellCheck($params) 63 63 { 64 65 66 67 68 64 if (!is_array($params) || empty($params)) { 65 trigger_error('SpellCheck parameters not set properly', E_USER_ERROR); 66 } 67 68 $this->setParam($params); 69 69 70 70 $this->_pspell_cfg_handle = pspell_config_create($this->getParam('language')); … … 75 75 if ('' != $this->getParam('personal_wordlist')) { 76 76 if (!is_writable(dirname($this->getParam('personal_wordlist'))) || !is_writable($this->getParam('personal_wordlist'))) { 77 77 App::logMsg(sprintf('Personal wordlist file not writable: %s', $this->getParam('personal_wordlist')), LOG_WARNING, __FILE__, __LINE__); 78 78 } else { 79 79 pspell_config_personal($this->_pspell_cfg_handle, $this->getParam('personal_wordlist')); … … 118 118 } 119 119 } 120 120 121 121 /** 122 122 * Check whether any errors have been triggered. … … 136 136 $this->_errors = array(); 137 137 } 138 138 139 139 /** 140 140 * Check one word. … … 156 156 } 157 157 } 158 158 159 159 /** 160 160 * Suggest the correct spelling for one misspelled word. … … 171 171 return pspell_suggest($this->_pspell_handle, $word); 172 172 } 173 173 174 174 /** 175 175 * Add a word to a personal list. … … 186 186 if ($this->_use_personal_wordlist) { 187 187 if (pspell_add_to_personal($this->_pspell_handle, $word)) { 188 189 return true; 190 191 192 193 194 } 195 } 196 188 App::logMsg(sprintf('Added "%s" to personal wordlist: %s', $word, $this->getParam('personal_wordlist')), LOG_DEBUG, __FILE__, __LINE__); 189 return true; 190 } else { 191 App::logMsg(sprintf('Failed adding "%s" to personal wordlist: %s', $word, $this->getParam('personal_wordlist')), LOG_WARNING, __FILE__, __LINE__); 192 return false; 193 } 194 } 195 } 196 197 197 /** 198 198 * Save personal list to file. … … 217 217 } 218 218 } 219 219 220 220 /** 221 221 * Returns an array of suggested words for each mispelled word in the given text. … … 252 252 } 253 253 } 254 254 255 255 /** 256 256 * Checks all words in a given string. … … 284 284 } 285 285 } 286 286 287 287 /** 288 288 * Returns a given string with misspelled words highlighted. … … 310 310 return join('', $words); 311 311 } 312 312 313 313 /** 314 314 * Prints the HTML for correcting all mispellings found in the text of one $_FORM element. … … 326 326 <input name="<?php echo $form_name ?>" type="hidden" value="<?php echo getFormData($form_name) ?>" /> 327 327 <?php 328 328 329 329 $form_words = $this->getStringSuggestions(getFormData($form_name)); 330 330 if (is_array($form_words) && !empty($form_words)) { … … 337 337 <option value="<?php echo $original_word ?>">(<?php echo $original_word ?>)</option> 338 338 <?php 339 339 340 340 foreach ($words as $suggestion) { 341 341 ?> … … 343 343 <?php 344 344 } 345 345 346 346 ?> 347 347 </select> … … 356 356 } 357 357 } 358 358 359 359 /** 360 360 * Tests if any form spelling corrections have been submitted. … … 370 370 return (false !== getFormData('spelling_suggestions', false)) || (false !== getFormData('spelling_corrections', false)); 371 371 } 372 372 373 373 /** 374 374 * Replace the misspelled words in the text of a specified form with the corrections.
Note: See TracChangeset
for help on using the changeset viewer.