Changeset 503 for trunk/lib/SpellCheck.inc.php
- Timestamp:
- Feb 10, 2015 12:03:25 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/SpellCheck.inc.php
r502 r503 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 141 141 { 142 142 $app =& App::getInstance(); 143 143 144 144 if (array_key_exists($param, $this->_params)) { 145 145 return $this->_params[$param]; … … 267 267 { 268 268 $corrections = array(); 269 // Split words on punctuation except apostrophes 269 // Split words on punctuation except apostrophes (this regex is used in several places in this class). 270 270 // http://stackoverflow.com/questions/790596/split-a-text-into-single-words 271 $words = preg_split("/((^\p{P}+)|(\p{P}*\s+\p{P}*)|[\p{Pd}-ââ]+|(\+|(\p{P}+$))/", $string); 272 // Remove non-word elements. 273 $words = preg_grep('/\w+/', $words); 274 271 $words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", $string, -1, PREG_SPLIT_DELIM_CAPTURE); 275 272 if (is_array($words) && !empty($words)) { 273 // Remove non-word elements. 274 $words = preg_grep('/\w+/', $words); 275 $words = array_map('strip_tags', $words); 276 276 foreach ($words as $i => $word) { 277 277 if (!$this->check($word)) { … … 303 303 { 304 304 $errors = array(); 305 $words = preg_split('/([\W]+?)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE); 306 // Remove non-word elements. 307 $check_words = preg_grep('/\w+/', $words); 308 309 if (is_array($check_words) && !empty($check_words)) { 310 foreach ($check_words as $i => $word) { 305 // Split words on punctuation except apostrophes (this regex is used in several places in this class). 306 // http://stackoverflow.com/questions/790596/split-a-text-into-single-words 307 $words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", $string, -1, PREG_SPLIT_DELIM_CAPTURE); 308 if (is_array($words) && !empty($words)) { 309 // Remove non-word elements. 310 $words = preg_grep('/\w+/', $words); 311 $words = array_map('strip_tags', $words); 312 foreach ($words as $i => $word) { 311 313 if (!$this->check($word)) { 312 314 $errors[] = $word; … … 334 336 public function getStringHighlighted($string, $show_footnote=false) 335 337 { 336 $words = preg_split('/([\W]+?)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE); 337 $check_words = preg_grep('/\w+/', $words); 338 // Split words on punctuation except apostrophes (this regex is used in several places in this class). 339 // http://stackoverflow.com/questions/790596/split-a-text-into-single-words 340 $words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", $string, -1, PREG_SPLIT_DELIM_CAPTURE); 338 341 $cnt = 0; 339 if (is_array($check_words) && !empty($check_words)) { 340 foreach ($check_words as $i => $word) { 342 if (is_array($words) && !empty($words)) { 343 $words = preg_grep('/\w+/', $words); 344 $words = array_map('strip_tags', $words); 345 foreach ($words as $i => $word) { 341 346 if (!$this->check($word)) { 342 $footnote = $show_footnote ? '<sup>' . ++$cnt . '</sup>' : ''; 343 $words[$i] = $this->getParam('highlight_start') . $word . $this->getParam('highlight_end') . $footnote; 347 $footnote = $show_footnote ? '<sup style="color:#999;">' . ++$cnt . '</sup>' : ''; 348 $words[$i] = $this->getParam('highlight_start') . $word . $this->getParam('highlight_end') . $footnote; 349 $string = preg_replace(sprintf('/\b%s\b/', preg_quote($word, '/')), $words[$i], $string); 344 350 } 345 351 } 346 352 } 347 return join('', $words);353 return $string; 348 354 } 349 355 … … 361 367 { 362 368 ?> 363 <input name="<?php echo $form_name ?>" type="hidden" value="<?php echo getFormData($form_name) ?>" />369 <input name="<?php echo $form_name ?>" type="hidden" value="<?php echo oTxt(getFormData($form_name)) ?>" /> 364 370 <?php 365 371 … … 370 376 ?> 371 377 <li> 372 <select name="spelling_suggestions[<?php echo $form_name ?>][<?php echo $i ?>]" onchange"document.forms[0].elements['spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]'].value = this.value;"> 378 <label style="color:#999;"><sub style="vertical-align:text-top;"><?php echo $j++; ?></sub></label> 379 <select name="spelling_suggestions[<?php echo $form_name ?>][<?php echo $i ?>]" onchange="document.forms[0].elements['spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]'].value = this.value;"> 373 380 <?php $original_word = array_shift($words); ?> 374 381 <option value="<?php echo $original_word ?>">(<?php echo $original_word ?>)</option> … … 383 390 ?> 384 391 </select> 385 <input type="text" name="spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]" value="<?php echo $original_word ?>" class="sc-small" />392 <input type="text" name="spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]" value="<?php echo oTxt($original_word) ?>" size="20"> 386 393 <?php if ($this->_use_personal_wordlist) { ?> 387 394 <input name="save_to_personal_wordlist[]" type="checkbox" value="<?php echo $i ?>" /><?php echo _("Learn spelling") ?> … … 420 427 public function applyFormCorrections($form_name) 421 428 { 422 $form_words = preg_split('/([\W]+?)/', getFormData($form_name), -1, PREG_SPLIT_DELIM_CAPTURE); 429 // Split words on punctuation except apostrophes (this regex is used in several places in this class). 430 // http://stackoverflow.com/questions/790596/split-a-text-into-single-words 431 $form_words = preg_split("/((?:^\p{P}+)|(?:\p{P}*\s+\p{P}*)|[\p{Pd}ââ-]+|(?:\p{P}+$))/", getFormData($form_name), -1, PREG_SPLIT_DELIM_CAPTURE); 423 432 $suggestions = getFormData('spelling_suggestions'); 424 433 $corrections = getFormData('spelling_corrections');
Note: See TracChangeset
for help on using the changeset viewer.