source: trunk/plugins/SpellChecker/aspell_setup.php @ 95

Last change on this file since 95 was 21, checked in by gogo, 15 years ago

Setting more properties.

  • Property svn:eol-style set to native
  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 2.6 KB
Line 
1<?php
2  umask(000);
3  $temptext = tempnam('/tmp', 'spell_');
4  if ((!isset($_POST['dictionary'])) || (strlen(trim($_POST['dictionary'])) < 1))
5  {
6      $lang = 'en_GB';
7  }
8  else
9  {
10      $lang = $_POST['dictionary'];
11  }
12
13  $aspell      = 'aspell';
14  $aspell_args = '-a --lang=' . $lang;
15
16  if(DIRECTORY_SEPARATOR == '\\') //windows
17  {
18    $aspell         = 'C:\Progra~1\Aspell\bin\aspell.exe';
19  }
20  else //linux
21  {
22    // See if there is a local install of aspell here
23    if(file_exists(dirname(__FILE__) . '/aspell/bin/aspell'))
24    {
25      putenv('PATH=' . dirname(__FILE__) . '/aspell/bin:' . getenv('PATH'));
26      putenv('LD_LIBRARY_PATH=' . dirname(__FILE__) . '/aspell/lib:' . getenv('LD_LIBRARY_PATH'));
27      $dicfil = dirname(__FILE__) .'/aspell/lib/' . preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s', '$1', `aspell config dict-dir`);
28      $aspell_args .= ' --dict-dir=' . $dicfil . ' --add-filter-path=' . $dicfil ;
29    }
30  }
31
32
33  // Old aspell doesn't know about encoding, which means that unicode will be broke, but
34  // we should at least let it try.
35  preg_match('/really aspell ([0-9]+)\.([0-9]+)(?:\.([0-9]+))?/i', `$aspell version`, $aVer);
36
37  $aVer = array('major' => (int)$aVer[1], 'minor' => (int)$aVer[2], 'release' => (int)$aVer[3]);
38  if($aVer['major'] >= 0 && $aVer['minor'] >= 60)
39  {
40    $aspell_args   .= ' -H --encoding=utf-8';
41  }
42  elseif(preg_match('/--encoding/', shell_exec('aspell 2>&1')))
43  {
44    $aspell_args   .= ' --mode=none --add-filter=sgml --encoding=utf-8';
45  }
46  else
47  {
48    $aspell_args   .= ' --mode=none --add-filter=sgml';
49  }
50
51  // Personal dictionaries
52  if(!isset($_REQUEST['p_dicts_path']))
53  {
54    $_REQUEST['p_dicts_path'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'personal_dicts';
55  }
56
57  if(file_exists($_REQUEST['p_dicts_path']) && is_writable($_REQUEST['p_dicts_path']))
58  {
59    if(!isset($_REQUEST['p_dicts_name']))
60    {
61      if(isset($_COOKIE['SpellChecker_p_dicts_name']))
62      {
63        $_REQUEST['p_dicts_name'] = $_COOKIE['SpellChecker_p_dicts_name'];
64      }
65      else
66      {
67        $_REQUEST['p_dicts_name'] = uniqid('dict');
68        setcookie('SpellChecker_p_dicts_name', $_REQUEST['p_dicts_name'], time() + 60*60*24*365*10);
69      }
70    }
71    $p_dict_path = $_REQUEST['p_dicts_path'] . DIRECTORY_SEPARATOR . $_REQUEST['p_dicts_name'];
72
73    if(!file_exists($p_dict_path))
74    {
75      mkdir($p_dict_path);
76      chmod($p_dict_path, 02770);
77    }
78
79    if(file_exists($p_dict_path) && is_writable($p_dict_path))
80    {
81      // Good To Go!
82      $aspell_args .= ' --home-dir=' . $p_dict_path ;
83    }
84  }
85
86  $aspelldictionaries = "$aspell dump dicts";
87  $aspellcommand      = "$aspell $aspell_args < $temptext";
88
89
90?>
Note: See TracBrowser for help on using the repository browser.