Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  /**

   3   * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $

   4   *

   5   * @package MCManager.includes

   6   * @author Moxiecode

   7   * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.

   8   */
   9  
  10  class PSpell extends SpellChecker {
  11  	 /**

  12  	  * Spellchecks an array of words.

  13  	  *

  14  	  * @param {String} $lang Language code like sv or en.

  15  	  * @param {Array} $words Array of words to spellcheck.

  16  	  * @return {Array} Array of misspelled words.

  17  	  */
  18  	 function &checkWords($lang, $words) {
  19  	 	 $plink = $this->_getPLink($lang);
  20  
  21  	 	 $outWords = array();
  22  	 	 foreach ($words as $word) {
  23  	 	 	 if (!pspell_check($plink, trim($word)))
  24  	 	 	 	 $outWords[] = $word;
  25  	 	 }
  26  
  27  	 	 return $outWords;
  28  	 }
  29  
  30  	 /**

  31  	  * Returns suggestions of for a specific word.

  32  	  *

  33  	  * @param {String} $lang Language code like sv or en.

  34  	  * @param {String} $word Specific word to get suggestions for.

  35  	  * @return {Array} Array of suggestions for the specified word.

  36  	  */
  37  	 function &getSuggestions($lang, $word) {
  38  	 	 $words = pspell_suggest($this->_getPLink($lang), $word);
  39  
  40  	 	 return $words;
  41  	 }
  42  
  43  	 /**

  44  	  * Opens a link for pspell.

  45  	  */
  46  	 function &_getPLink($lang) {
  47  	 	 // Check for native PSpell support

  48  	 	 if (!function_exists("pspell_new"))
  49  	 	 	 $this->throwError("PSpell support not found in PHP installation.");
  50  
  51  	 	 // Setup PSpell link

  52  	 	 $plink = pspell_new(
  53  	 	 	 $lang,
  54  	 	 	 $this->_config['PSpell.spelling'],
  55  	 	 	 $this->_config['PSpell.jargon'],
  56  	 	 	 empty($this->_config['PSpell.encoding']) ? 'utf-8' : $this->_config['PSpell.encoding'],
  57  	 	 	 $this->_config['PSpell.mode']
  58  	 	 );
  59  
  60  	 	 // Setup PSpell link

  61  /*	 	 if (!$plink) {

  62  	 	 	 $pspellConfig = pspell_config_create(

  63  	 	 	 	 $lang,

  64  	 	 	 	 $this->_config['PSpell.spelling'],

  65  	 	 	 	 $this->_config['PSpell.jargon'],

  66  	 	 	 	 $this->_config['PSpell.encoding']

  67  	 	 	 );

  68  

  69  	 	 	 $plink = pspell_new_config($pspell_config);

  70  	 	 }*/
  71  
  72  	 	 if (!$plink)
  73  	 	 	 $this->throwError("No PSpell link found opened.");
  74  
  75  	 	 return $plink;
  76  	 }
  77  }
  78  
  79  ?>