Ignore:
Timestamp:
Nov 13, 2005 4:51:22 AM (19 years ago)
Author:
scdev
Message:

M trunk/tests/run_tests.sh
Now can run tests without being in tests dir.

M trunk/tests/_config.inc.php
No change

M trunk/tests/Auth_SQLTest.php
...

M trunk/lib/RecordVersion.inc.php
Removed debugging.

M trunk/lib/DB.inc.php
Added die on connect error only if db_die_on_failure is true.

M trunk/lib/DBSessionHandler.inc.php
Added more accurate error-checking.

M trunk/lib/FormValidator.inc.php
Fixed email regex bugs.

M trunk/lib/SpellCheck.inc.php
Integrated lots of bug fixes from UK update.

M trunk/lib/Auth_SQL.inc.php
Lots of minor bug fixes.

M trunk/lib/App.inc.php
A couple minor bug fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/SpellCheck.inc.php

    r14 r15  
    77 *
    88 * @author  Quinn Comendant <quinn@strangecode.com>
    9  * @version 1.0
     9 * @version 1.1
    1010 */
    1111 
    1212/* Implementation example:
    1313--------------------------------------------------------------------------------
    14 include '_config.inc.php';
     14include_once dirname(__FILE__) . '/_config.inc.php';
    1515include 'codebase/lib/SpellCheck.inc.php';
    1616
    17 // Instantiate with language and optionally the path to the custom wordlist file.
    18 $spell = new SpellCheck('en', '/tmp/my_custom_dict');
     17// Instantiate with parameters. In this example we'll set the language and the path to the personal wordlist file.
     18$spell = new SpellCheck(array(
     19    'language' => 'en',
     20    'personal_wordlist' => '/tmp/my_custom_dict'
     21));
     22
     23// Just for the heck of it add a new word to persistent personal wordlist file.
     24$spell->add('mealworm');
    1925
    2026$text_to_check = 'donky rinds taste like mealworm paste';
    21 
    22 // Add new word to persistent custom wordlist file.
    23 $spell->add('mealworm');
    2427
    2528if (!$spell->checkString($text_to_check)) {
    2629    $suggestions = $spell->getStringSuggestions($text_to_check);
    27     echo 'Spelling errors:';
     30    echo 'Spelling errors! Here are suggested alternatives:';
    2831    print_r($suggestions);
    2932} else {
     
    3942
    4043    var $_params = array(
    41         'personal_wordlist' => '',
    42         'skip_len' => 3,
     44        'language' => 'en',
     45        'personal_wordlist' => '', // Text file to save custom words to.
     46        'skip_length' => 3, // Words with this many chars or less will not be checked.
    4347        'mode' => PSPELL_NORMAL, // PSPELL_FAST, PSPELL_NORMAL, or PSPELL_BAD_SPELLERS.
    4448        'highlight_start' => '<strong style="color:red;">',
     
    5357    /**
    5458     * Constructor.
    55      */
    56     function SpellCheck($lang='en', $personal_wordlist=null)
    57     {
    58         $this->_pspell_cfg_handle = pspell_config_create($lang);
    59 
    60         pspell_config_ignore($this->_pspell_cfg_handle, $skip_len);
    61         pspell_config_mode($this->_pspell_cfg_handle, $mode);
    62 
    63         if (isset($personal_wordlist)) {
    64             if (!is_writable(dirname($personal_wordlist)) && !is_writable($personal_wordlist)) {
    65                 App::logMsg(sprintf('Personal wordlist file not writable: %s', $personal_wordlist), LOG_NOTICE, __FILE__, __LINE__);
     59     *
     60     * @param  array    $params     Array of parameters (key => val pairs).
     61     */
     62    function SpellCheck($params)
     63    {
     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
     70        $this->_pspell_cfg_handle = pspell_config_create($this->getParam('language'));
     71
     72        pspell_config_ignore($this->_pspell_cfg_handle, $this->getParam('skip_length'));
     73        pspell_config_mode($this->_pspell_cfg_handle, $this->getParam('mode'));
     74
     75        if ('' != $this->getParam('personal_wordlist')) {
     76            if (!is_writable(dirname($this->getParam('personal_wordlist'))) || !is_writable($this->getParam('personal_wordlist'))) {
     77                App::logMsg(sprintf('Personal wordlist file not writable: %s', $this->getParam('personal_wordlist')), LOG_WARNING, __FILE__, __LINE__);
    6678            } else {
    67                 $this->setParam(array('personal_wordlist' => $personal_wordlist));
    68                 pspell_config_personal($this->_pspell_cfg_handle, $personal_wordlist);
     79                pspell_config_personal($this->_pspell_cfg_handle, $this->getParam('personal_wordlist'));
    6980                $this->_use_personal_wordlist = true;
    70                 App::logMsg(sprintf('Using personal wordlist: %s', $personal_wordlist), LOG_DEBUG, __FILE__, __LINE__);
     81                App::logMsg(sprintf('Using personal wordlist: %s', $this->getParam('personal_wordlist')), LOG_DEBUG, __FILE__, __LINE__);
    7182            }
    7283        }
     
    174185    {
    175186        if ($this->_use_personal_wordlist) {
    176             App::logMsg(sprintf('Added "%s" to personal wordlist: %s', $word, $this->getParam('personal_wordlist')), LOG_DEBUG, __FILE__, __LINE__);
    177             return pspell_add_to_personal($this->_pspell_handle, $word);
     187            if (pspell_add_to_personal($this->_pspell_handle, $word)) {
     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_ERR, __FILE__, __LINE__);
     192                return false;
     193            }
    178194        }
    179195    }
Note: See TracChangeset for help on using the changeset viewer.