Aleksander Machniak
2016-05-22 77b5d7ee304a688a2eb115ce04b460b43c0dd700
program/lib/Roundcube/rcube_spellchecker.php
@@ -1,6 +1,6 @@
<?php
/*
/**
 +-----------------------------------------------------------------------+
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2011-2013, Kolab Systems AG                             |
@@ -46,7 +46,7 @@
    {
        $this->rc     = rcube::get_instance();
        $this->engine = $this->rc->config->get('spellcheck_engine', 'googie');
        $this->lang   = $lang ? $lang : 'en';
        $this->lang   = $lang ?: 'en';
        $this->options = array(
            'ignore_syms' => $this->rc->config->get('spellcheck_ignore_syms'),
@@ -104,6 +104,9 @@
            }
        }
        // remove possible duplicates (#1489395)
        $languages = array_unique($languages);
        asort($languages);
        return $languages;
@@ -134,7 +137,6 @@
        return $this->found() == 0;
    }
    /**
     * Number of mispellings found (after check)
     *
@@ -144,7 +146,6 @@
    {
        return count($this->matches);
    }
    /**
     * Returns suggestions for the specified word
@@ -161,7 +162,6 @@
        return array();
    }
    /**
     * Returns misspelled words
@@ -184,7 +184,6 @@
        return array();
    }
    /**
     * Returns checking result in XML (Googiespell) format
     *
@@ -206,7 +205,6 @@
        return $out;
    }
    /**
     * Returns checking result (misspelled words with suggestions)
     *
@@ -223,12 +221,22 @@
            else {
                $word = mb_substr($this->content, $item[1], $item[2], RCUBE_CHARSET);
            }
            $result[$word] = is_array($item[4]) ? implode("\t", $item[4]) : $item[4];
            if (is_array($item[4])) {
                $suggestions = $item[4];
            }
            else if (empty($item[4])) {
                $suggestions = array();
            }
            else {
                $suggestions = explode("\t", $item[4]);
            }
            $result[$word] = $suggestions;
        }
        return $result;
    }
    /**
     * Returns error message
@@ -237,16 +245,14 @@
     */
    function error()
    {
        return $this->error ? $this->error : ($this->backend ? $this->backend->error() : false);
        return $this->error ?: ($this->backend ? $this->backend->error() : false);
    }
    private function html2text($text)
    {
        $h2t = new rcube_html2text($text, false, true, 0);
        $h2t = new rcube_html2text($text, false, false, 0);
        return $h2t->get_text();
    }
    /**
     * Check if the specified word is an exception accoring to 
@@ -259,7 +265,7 @@
    public function is_exception($word)
    {
        // Contain only symbols (e.g. "+9,0", "2:2")
        if (!$word || preg_match('/^[0-9@#$%^&_+~*=:;?!,.-]+$/', $word))
        if (!$word || preg_match('/^[0-9@#$%^&_+~*<>=:;?!,.-]+$/', $word))
            return true;
        // Contain symbols (e.g. "g@@gle"), all symbols excluding separators
@@ -286,7 +292,6 @@
        return false;
    }
    /**
     * Add a word to dictionary
     *
@@ -310,7 +315,6 @@
        }
    }
    /**
     * Remove a word from dictionary
     *
@@ -325,7 +329,6 @@
            $this->update_dict();
        }
    }
    /**
     * Update dictionary row in DB
@@ -346,29 +349,28 @@
        if ($this->have_dict) {
            if (!empty($this->dict)) {
                $this->rc->db->query(
                    "UPDATE ".$this->rc->db->table_name('dictionary')
                    ." SET data = ?"
                    ." WHERE user_id " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
                        ." AND " . $this->rc->db->quoteIdentifier('language') . " = ?",
                    "UPDATE " . $this->rc->db->table_name('dictionary', true)
                    ." SET `data` = ?"
                    ." WHERE `user_id` " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
                        ." AND `language` = ?",
                    implode(' ', $plugin['dictionary']), $plugin['language']);
            }
            // don't store empty dict
            else {
                $this->rc->db->query(
                    "DELETE FROM " . $this->rc->db->table_name('dictionary')
                    ." WHERE user_id " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
                        ." AND " . $this->rc->db->quoteIdentifier('language') . " = ?",
                    "DELETE FROM " . $this->rc->db->table_name('dictionary', true)
                    ." WHERE `user_id` " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
                        ." AND `language` = ?",
                    $plugin['language']);
            }
        }
        else if (!empty($this->dict)) {
            $this->rc->db->query(
                "INSERT INTO " .$this->rc->db->table_name('dictionary')
                ." (user_id, " . $this->rc->db->quoteIdentifier('language') . ", data) VALUES (?, ?, ?)",
                "INSERT INTO " . $this->rc->db->table_name('dictionary', true)
                ." (`user_id`, `language`, `data`) VALUES (?, ?, ?)",
                $plugin['userid'], $plugin['language'], implode(' ', $plugin['dictionary']));
        }
    }
    /**
     * Get dictionary from DB
@@ -389,9 +391,9 @@
        if (empty($plugin['abort'])) {
            $dict = array();
            $sql_result = $this->rc->db->query(
                "SELECT data FROM ".$this->rc->db->table_name('dictionary')
                ." WHERE user_id ". ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
                    ." AND " . $this->rc->db->quoteIdentifier('language') . " = ?",
                "SELECT `data` FROM " . $this->rc->db->table_name('dictionary', true)
                ." WHERE `user_id` ". ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL")
                    ." AND `language` = ?",
                $plugin['language']);
            if ($sql_arr = $this->rc->db->fetch_assoc($sql_result)) {
@@ -413,5 +415,4 @@
        return $this->dict;
    }
}