Aleksander Machniak
2014-05-02 3e49064dcfe10ea03fe8892143aba56b4ce1321f
program/lib/Roundcube/rcube_spellchecker.php
@@ -65,6 +65,52 @@
        }
    }
    /**
     * Return a list of supported languages
     */
    function languages()
    {
        // trust configuration
        $configured = $this->rc->config->get('spellcheck_languages');
        if (!empty($configured) && is_array($configured) && !$configured[0]) {
            return $configured;
        }
        else if (!empty($configured)) {
            $langs = (array)$configured;
        }
        else if ($this->backend) {
            $langs = $this->backend->languages();
        }
        // load index
        @include(RCUBE_LOCALIZATION_DIR . 'index.inc');
        // add correct labels
        $languages = array();
        foreach ($langs as $lang) {
            $langc = strtolower(substr($lang, 0, 2));
            $alias = $rcube_language_aliases[$langc];
            if (!$alias) {
                $alias = $langc.'_'.strtoupper($langc);
            }
            if ($rcube_languages[$lang]) {
                $languages[$lang] = $rcube_languages[$lang];
            }
            else if ($rcube_languages[$alias]) {
                $languages[$lang] = $rcube_languages[$alias];
            }
            else {
                $languages[$lang] = ucfirst($lang);
            }
        }
        // remove possible duplicates (#1489395)
        $languages = array_unique($languages);
        asort($languages);
        return $languages;
    }
    /**
     * Set content and check spelling
@@ -152,7 +198,7 @@
        // send output
        $out = '<?xml version="1.0" encoding="'.RCUBE_CHARSET.'"?><spellresult charschecked="'.mb_strlen($this->content).'">';
        foreach ($this->matches as $item) {
        foreach ((array)$this->matches as $item) {
            $out .= '<c o="'.$item[1].'" l="'.$item[2].'">';
            $out .= is_array($item[4]) ? implode("\t", $item[4]) : $item[4];
            $out .= '</c>';
@@ -173,7 +219,7 @@
    {
        $result = array();
        foreach ($this->matches as $item) {
        foreach ((array)$this->matches as $item) {
            if ($this->engine == 'pspell') {
                $word = $item[0];
            }
@@ -216,7 +262,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
@@ -306,7 +352,7 @@
                    "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') . " = ?",
                        ." AND " . $this->rc->db->quote_identifier('language') . " = ?",
                    implode(' ', $plugin['dictionary']), $plugin['language']);
            }
            // don't store empty dict
@@ -314,14 +360,14 @@
                $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') . " = ?",
                        ." AND " . $this->rc->db->quote_identifier('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 (?, ?, ?)",
                ." (user_id, " . $this->rc->db->quote_identifier('language') . ", data) VALUES (?, ?, ?)",
                $plugin['userid'], $plugin['language'], implode(' ', $plugin['dictionary']));
        }
    }
@@ -348,7 +394,7 @@
            $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') . " = ?",
                    ." AND " . $this->rc->db->quote_identifier('language') . " = ?",
                $plugin['language']);
            if ($sql_arr = $this->rc->db->fetch_assoc($sql_result)) {