From ec78f98c6a4152c328a9bcf9dd59397df653d81d Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 31 Jul 2012 02:18:54 -0400
Subject: [PATCH] Don't send complete error page to the spellchecker on error (when pspell extension isn't found)

---
 program/include/rcube_spellchecker.php |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/program/include/rcube_spellchecker.php b/program/include/rcube_spellchecker.php
index f38720b..b615edb 100644
--- a/program/include/rcube_spellchecker.php
+++ b/program/include/rcube_spellchecker.php
@@ -57,13 +57,6 @@
         $this->engine = $this->rc->config->get('spellcheck_engine', 'googie');
         $this->lang   = $lang ? $lang : 'en';
 
-        if ($this->engine == 'pspell' && !extension_loaded('pspell')) {
-            rcube::raise_error(array(
-                'code' => 500, 'type' => 'php',
-                'file' => __FILE__, 'line' => __LINE__,
-                'message' => "Pspell extension not available"), true, true);
-        }
-
         $this->options = array(
             'ignore_syms' => $this->rc->config->get('spellcheck_ignore_syms'),
             'ignore_nums' => $this->rc->config->get('spellcheck_ignore_nums'),
@@ -235,8 +228,8 @@
             else if (!pspell_check($this->plink, $word)) {
                 $suggestions = pspell_suggest($this->plink, $word);
 
-	            if (sizeof($suggestions) > self::MAX_SUGGESTIONS)
-	                $suggestions = array_slice($suggestions, 0, self::MAX_SUGGESTIONS);
+                if (sizeof($suggestions) > self::MAX_SUGGESTIONS)
+                    $suggestions = array_slice($suggestions, 0, self::MAX_SUGGESTIONS);
 
                 $matches[] = array($word, $pos, $len, null, $suggestions);
             }
@@ -321,6 +314,16 @@
     private function _pspell_init()
     {
         if (!$this->plink) {
+            if (!extension_loaded('pspell')) {
+                $this->error = "Pspell extension not available";
+                rcube::raise_error(array(
+                    'code' => 500, 'type' => 'php',
+                    'file' => __FILE__, 'line' => __LINE__,
+                    'message' => $this->error), true, false);
+
+                return;
+            }
+
             $this->plink = pspell_new($this->lang, null, null, RCMAIL_CHARSET, PSPELL_FAST);
         }
 

--
Gitblit v1.9.1