Check-in [e38fe2836e]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | pspell extension |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
e38fe2836e74c8d4223cfcf8c800184f |
User & Date: | mario 2010-06-22 17:23:53 |
Context
2010-06-22
| ||
17:26 | test of test-up script, contains some new 5.3 functions, -> backport to real upgrade.php necessary check-in: c8a4b413d6 user: mario tags: trunk | |
17:23 | pspell extension check-in: e38fe2836e user: mario tags: trunk | |
17:22 | deleted old readme check-in: 8150c72049 user: mario tags: trunk | |
Changes
Added ext/pspell.php.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | <?php /** * api: php * title: pspell emulation * description: aspell wrapper functions for PHP pspell extension * type: functions * support: untested * config: <var name="$__pspell[]" priority="never" description="helper variable"> * version: 1.1 * license: Public Domain * * Has no support for replacement and personal dictionaries, nor wordlist files. * (Some of these features are possible with the aspell cmdline arguments eventually.) * * Only works with aspell binary, not ispell. * */ if (!function_exists("pspell_check")) { // helper variable, holds indexes to configured dictionaries global $__pspell; $__pspell[0] = array( // array names do match aspell --cmdline options 1:1 "lang" => "en", "variety" => "", "jargon" => "", "encoding" => "utf-8", "ignore" => 1, "sug-mode" => "normal", // pspell_*() emu internal options prefixed with _ "_mode" => 0, "_bin" => trim(`which aspell`), "_insert" => "", ); // ?? define("PSPELL_FAST", 0x01); define("PSPELL_NORMAL", 0x02); define("PSPELL_BAD_SPELLERS", 0x04); define("PSPELL_RUN_TOGETHER", 0x08); define("PSPELL_ULTRA", 0x20); // non-standard /** * Check if a single word exists in the dictionary as-is. * */ function pspell_check($i, $word) { // exec $cmd = pspell_cmd($i, "check --dont-suggest"); $word = escapeshellarg($word); $r = `echo $word | $cmd`; // "*" means successful match return preg_match("/^[\*]/m", $r); } /** * non-standard, for emulation only * */ function pspell_cmd($i, $insert="") { global $__pspell; # /usr/bin/aspell pipe check $cmd = $__pspell[$i]["_bin"] . " pipe $insert " . $__pspell[$i]["_insert"]; # --lang= --ignore= --variety= --jargon= --personal= --repl= --extra-dicts= --dict-dir= foreach ($__pspell[$i] as $name=>$value) { if (strlen($value) && !strstr(",_bin,_mode",$name) && ($name[0]!="_")) { $cmd .= " --$name=$value"; } } return $cmd; } /** * If word does not exist in dictionary, returns list of alternatives. * */ function pspell_suggest($i, $word) { // exec $cmd = pspell_cmd($i, "--suggest"); $word = escapeshellarg($word); $r = `echo $word | $cmd`; // "&" multiple matches if (preg_match("/^[\&] (.+?) (\d+) (\d+): (.+)$/m", $r, $uu)) { return preg_split("/,\s*/", $uu[4]); } else { //return($word); //@todo: native behaviour? } } /** * Set aspell options. * */ function pspell_new($lang="en", $spelling="", $jargon="", $enc="utf-8", $mode=0) { global $__pspell; $i = count($__pspell); $__pspell[$i] = array_merge($__pspell[0], array( "lang" => $lang, "variety" => $spelling, "jargon" => $jargon, "encoding" => $enc, )); if ($mode) { pspell_config_mode($i, $mode); } return($i); } /** * Various other dictionary options. * Just set $__pspell[][] cmdline --options array. * */ function pspell_config_create($lang, $spelling=NULL, $jargon=NULL, $enc=NULL) { return pspell_new($lang, $spelling, $jargon, $enc); } function pspell_new_config($i) { return $i; // dictionary and config are the same in this implementation } function pspell_config_mode($i, $mode) { global $__pspell; $__pspell[$i]["_mode"] = $mode; $modes = array(0x00=>"normal", PSPELL_NORMAL=>"normal", PSPELL_FAST=>"fast", PSPELL_ULTRA=>"ultra", PSPELL_BAD_SPELLERS=>"bad-spellers"); $__pspell[$i]["sug-mode"] = $modes[$mode & 0x27]; pspell_config_runtogether($i, $mode & PSPELL_RUN_TOGETHER); } function pspell_config_ignore($i, $minlength) { global $__pspell; $__pspell[$i]["ignore"] = (int)$minlength; } function pspell_config_personal($i, $file) { global $__pspell; $__pspell[$i]["personal"] = escapeshellarg($file); } function pspell_config_data_dir($i, $dir) { global $__pspell; $__pspell[$i]["data-dir"] = escapeshellarg($dir); } function pspell_config_dict_dir($i, $dir) { global $__pspell; $__pspell[$i]["dict-dir"] = escapeshellarg($dir); } function pspell_config_runtogether($i, $is) { global $__pspell; $__pspell[$i]["_insert"] = $is ? "--runtogether" : ""; } } ?> |
Changes to upgrade.php.
1 2 3 4 5 | <?php /** * api: php * title: upgrade.php * description: Emulates functions from new PHP versions on older interpreters. | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php /** * api: php * title: upgrade.php * description: Emulates functions from new PHP versions on older interpreters. * version: 17 * license: Public Domain * url: http://freshmeat.net/projects/upgradephp * type: functions * category: library * priority: auto * load_if: (PHP_VERSION<5.2) * sort: -255 |
︙ | ︙ |