File: spelling.php3

package info (click to toggle)
imp 3%3A2.2.6-5.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,476 kB
  • ctags: 766
  • sloc: php: 4,253; sh: 831; makefile: 98; perl: 50; pascal: 15
file content (121 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php

/*
 
 File: spelling.php3
 $Author: rich $
 $Revision: 2.2.2.12 $
 $Date: 2000/09/13 17:07:23 $
 
 IMP: Copyright 1999, 2000 Charles J. Hagenbuch  <chuck@horde.org>
 
 You should have received a copy of the GNU Public
 License along with this package; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.
 
 */

function estrtok (&$token, &$delim, $string, $separators) {
  static $lastString = '';
  static $stringLen = 0;
  
  if ($lastString != $string) {
    $lastString = $string;
    $stringLen = strlen($string);
    $aStrTok = strtok($string, $separators);
    $stringLen -= strlen($aStrTok) + 1;
  } else {
    $aStrTok = strtok($separators);
    $stringLen -= strlen($aStrTok) + 1;
  }
  
  $token = $aStrTok;
  $pos = strlen($string) - $stringLen - 1;
  if ($pos < strlen($string))
    $delim = $string[$pos];
  else
    $delim = '';
  
  if (!$aStrTok)
    return $stringLen>=0;
  else
    return true;
}

function member ($string, $array) {
  while (list($key, $val) = each($array)) {
    if ($val == $string)
      return true;
  }
  return false;
}


require '../lib/horde.lib';
require './lib/imp.lib';             /* IMPlib is the IMP function library  */
require './config/defaults.php3';    /* Defaults configuration file */
require './config/html.php3';

require './config/lang.php3';
$language = select_lang();
require './lib/postconf.php3';
require "./locale/$language/spelling.lang";
require './locale/local/spelling.lang';
require './config/lang.php3';

error_reporting($default->error_level); /* set error level from imp.lib   */

$title = $lang->spelling_title;
$sidebar = false;
require "$default->include_dir/doctype.inc";
require "$default->include_dir/generic-header.inc";

if (isset($default->ispell_lang) && isset($spell_lang)) {
  $spell_opt = $default->ispell_lang[$spell_lang];
} else {
  $spell_opt = '';
}

$message = stripSlashes($message);

// special traitement depending on language (quotes are not equally treated by
// ispell in english and in french)
switch ($spell_lang) {
 case "fr":
   // $tocheck = str_replace("'", "\\'", escapeShellCmd($message));
   // break;
 default:
   $tocheck = strtr($message, "\n", ' ');
   $tocheck = escapeShellCmd($tocheck);
}

exec("echo $tocheck | $default->path_to_ispell $spell_opt  -l", $warnings);
sort($warnings);

$prev = '';
while (list($key, $val) = each($warnings)) {
   if ($val != $prev) {
      $errors[] = $val;
   }
   $prev = $val;
}

$message = htmlspecialchars($message);

if (isset($errors)) {
  $msg = '';
  while (estrtok($tok, $delim, $message, " ,.:;'\"&%!?()[]{}/|\n\\")) {
    if (member($tok, $errors))
      $msg .= "<font color=\"ff0000\">$tok</font>$delim";
    else
      $msg .= $tok . $delim;
  }
  echo nl2br($msg);
} else {
  echo $lang->no_errors;
}

require "$default->include_dir/spelling/footer.inc";

?>