| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\PspellException; |
| 6 |
|
| 7 |
/** |
| 8 |
* |
| 9 |
* |
| 10 |
* @param int $dictionary_link |
| 11 |
* @param string $word The added word. |
| 12 |
* @throws PspellException |
| 13 |
* |
| 14 |
*/ |
| 15 |
function pspell_add_to_personal(int $dictionary_link, string $word): void |
| 16 |
{ |
| 17 |
error_clear_last(); |
| 18 |
$result = \pspell_add_to_personal($dictionary_link, $word); |
| 19 |
if ($result === false) { |
| 20 |
throw PspellException::createFromPhpError(); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* |
| 27 |
* |
| 28 |
* @param int $dictionary_link |
| 29 |
* @param string $word The added word. |
| 30 |
* @throws PspellException |
| 31 |
* |
| 32 |
*/ |
| 33 |
function pspell_add_to_session(int $dictionary_link, string $word): void |
| 34 |
{ |
| 35 |
error_clear_last(); |
| 36 |
$result = \pspell_add_to_session($dictionary_link, $word); |
| 37 |
if ($result === false) { |
| 38 |
throw PspellException::createFromPhpError(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* |
| 45 |
* |
| 46 |
* @param int $dictionary_link |
| 47 |
* @throws PspellException |
| 48 |
* |
| 49 |
*/ |
| 50 |
function pspell_clear_session(int $dictionary_link): void |
| 51 |
{ |
| 52 |
error_clear_last(); |
| 53 |
$result = \pspell_clear_session($dictionary_link); |
| 54 |
if ($result === false) { |
| 55 |
throw PspellException::createFromPhpError(); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* Create a config used to open a dictionary. |
| 62 |
* |
| 63 |
* pspell_config_create has a very similar syntax to |
| 64 |
* pspell_new. In fact, using |
| 65 |
* pspell_config_create immediately followed by |
| 66 |
* pspell_new_config will produce the exact same result. |
| 67 |
* However, after creating a new config, you can also use |
| 68 |
* pspell_config_* functions before calling |
| 69 |
* pspell_new_config to take advantage of some |
| 70 |
* advanced functionality. |
| 71 |
* |
| 72 |
* For more information and examples, check out inline manual pspell |
| 73 |
* website:http://aspell.net/. |
| 74 |
* |
| 75 |
* @param string $language The language parameter is the language code which consists of the |
| 76 |
* two letter ISO 639 language code and an optional two letter ISO |
| 77 |
* 3166 country code after a dash or underscore. |
| 78 |
* @param string|null $spelling The spelling parameter is the requested spelling for languages |
| 79 |
* with more than one spelling such as English. Known values are |
| 80 |
* 'american', 'british', and 'canadian'. |
| 81 |
* @param string|null $jargon The jargon parameter contains extra information to distinguish |
| 82 |
* two different words lists that have the same language and |
| 83 |
* spelling parameters. |
| 84 |
* @param string|null $encoding The encoding parameter is the encoding that words are expected to |
| 85 |
* be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r', |
| 86 |
* 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned |
| 87 |
* 32'. This parameter is largely untested, so be careful when |
| 88 |
* using. |
| 89 |
* |
| 90 |
* @return int Returns a pspell config identifier. |
| 91 |
* @throws PspellException |
| 92 |
* |
| 93 |
*/ |
| 94 |
function pspell_config_create(string $language, ?string $spelling = null, ?string $jargon = null, ?string $encoding = null): int |
| 95 |
{ |
| 96 |
error_clear_last(); |
| 97 |
if ($encoding !== null) { |
| 98 |
$result = \pspell_config_create($language, $spelling, $jargon, $encoding); |
| 99 |
} elseif ($jargon !== null) { |
| 100 |
$result = \pspell_config_create($language, $spelling, $jargon); |
| 101 |
} elseif ($spelling !== null) { |
| 102 |
$result = \pspell_config_create($language, $spelling); |
| 103 |
} else { |
| 104 |
$result = \pspell_config_create($language); |
| 105 |
} |
| 106 |
if ($result === false) { |
| 107 |
throw PspellException::createFromPhpError(); |
| 108 |
} |
| 109 |
return $result; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
/** |
| 114 |
* This function is |
| 115 |
* currently not documented; only its argument list is available. |
| 116 |
* |
| 117 |
* |
| 118 |
* @param int $conf |
| 119 |
* @param string $directory |
| 120 |
* @throws PspellException |
| 121 |
* |
| 122 |
*/ |
| 123 |
function pspell_config_data_dir(int $conf, string $directory): void |
| 124 |
{ |
| 125 |
error_clear_last(); |
| 126 |
$result = \pspell_config_data_dir($conf, $directory); |
| 127 |
if ($result === false) { |
| 128 |
throw PspellException::createFromPhpError(); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
* This function is |
| 135 |
* currently not documented; only its argument list is available. |
| 136 |
* |
| 137 |
* |
| 138 |
* @param int $conf |
| 139 |
* @param string $directory |
| 140 |
* @throws PspellException |
| 141 |
* |
| 142 |
*/ |
| 143 |
function pspell_config_dict_dir(int $conf, string $directory): void |
| 144 |
{ |
| 145 |
error_clear_last(); |
| 146 |
$result = \pspell_config_dict_dir($conf, $directory); |
| 147 |
if ($result === false) { |
| 148 |
throw PspellException::createFromPhpError(); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
/** |
| 154 |
* |
| 155 |
* |
| 156 |
* @param int $dictionary_link |
| 157 |
* @param int $n Words less than n characters will be skipped. |
| 158 |
* @throws PspellException |
| 159 |
* |
| 160 |
*/ |
| 161 |
function pspell_config_ignore(int $dictionary_link, int $n): void |
| 162 |
{ |
| 163 |
error_clear_last(); |
| 164 |
$result = \pspell_config_ignore($dictionary_link, $n); |
| 165 |
if ($result === false) { |
| 166 |
throw PspellException::createFromPhpError(); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
/** |
| 172 |
* |
| 173 |
* |
| 174 |
* @param int $dictionary_link |
| 175 |
* @param int $mode The mode parameter is the mode in which spellchecker will work. |
| 176 |
* There are several modes available: |
| 177 |
* |
| 178 |
* |
| 179 |
* |
| 180 |
* PSPELL_FAST - Fast mode (least number of |
| 181 |
* suggestions) |
| 182 |
* |
| 183 |
* |
| 184 |
* |
| 185 |
* |
| 186 |
* PSPELL_NORMAL - Normal mode (more suggestions) |
| 187 |
* |
| 188 |
* |
| 189 |
* |
| 190 |
* |
| 191 |
* PSPELL_BAD_SPELLERS - Slow mode (a lot of |
| 192 |
* suggestions) |
| 193 |
* |
| 194 |
* |
| 195 |
* |
| 196 |
* @throws PspellException |
| 197 |
* |
| 198 |
*/ |
| 199 |
function pspell_config_mode(int $dictionary_link, int $mode): void |
| 200 |
{ |
| 201 |
error_clear_last(); |
| 202 |
$result = \pspell_config_mode($dictionary_link, $mode); |
| 203 |
if ($result === false) { |
| 204 |
throw PspellException::createFromPhpError(); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
/** |
| 210 |
* Set a file that contains personal wordlist. The personal wordlist will be |
| 211 |
* loaded and used in addition to the standard one after you call |
| 212 |
* pspell_new_config. The file is also the file where |
| 213 |
* pspell_save_wordlist will save personal wordlist to. |
| 214 |
* |
| 215 |
* pspell_config_personal should be used on a config |
| 216 |
* before calling pspell_new_config. |
| 217 |
* |
| 218 |
* @param int $dictionary_link |
| 219 |
* @param string $file The personal wordlist. If the file does not exist, it will be created. |
| 220 |
* The file should be writable by whoever PHP runs as (e.g. nobody). |
| 221 |
* @throws PspellException |
| 222 |
* |
| 223 |
*/ |
| 224 |
function pspell_config_personal(int $dictionary_link, string $file): void |
| 225 |
{ |
| 226 |
error_clear_last(); |
| 227 |
$result = \pspell_config_personal($dictionary_link, $file); |
| 228 |
if ($result === false) { |
| 229 |
throw PspellException::createFromPhpError(); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
/** |
| 235 |
* Set a file that contains replacement pairs. |
| 236 |
* |
| 237 |
* The replacement pairs improve the quality of the spellchecker. When a word |
| 238 |
* is misspelled, and a proper suggestion was not found in the list, |
| 239 |
* pspell_store_replacement can be used to store a |
| 240 |
* replacement pair and then pspell_save_wordlist to |
| 241 |
* save the wordlist along with the replacement pairs. |
| 242 |
* |
| 243 |
* pspell_config_repl should be used on a config |
| 244 |
* before calling pspell_new_config. |
| 245 |
* |
| 246 |
* @param int $dictionary_link |
| 247 |
* @param string $file The file should be writable by whoever PHP runs as (e.g. nobody). |
| 248 |
* @throws PspellException |
| 249 |
* |
| 250 |
*/ |
| 251 |
function pspell_config_repl(int $dictionary_link, string $file): void |
| 252 |
{ |
| 253 |
error_clear_last(); |
| 254 |
$result = \pspell_config_repl($dictionary_link, $file); |
| 255 |
if ($result === false) { |
| 256 |
throw PspellException::createFromPhpError(); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
/** |
| 262 |
* This function determines whether run-together words will be treated as |
| 263 |
* legal compounds. That is, "thecat" will be a legal compound, although |
| 264 |
* there should be a space between the two words. Changing this setting only |
| 265 |
* affects the results returned by pspell_check; |
| 266 |
* pspell_suggest will still return suggestions. |
| 267 |
* |
| 268 |
* pspell_config_runtogether should be used on a config |
| 269 |
* before calling pspell_new_config. |
| 270 |
* |
| 271 |
* @param int $dictionary_link |
| 272 |
* @param bool $flag TRUE if run-together words should be treated as legal compounds, |
| 273 |
* FALSE otherwise. |
| 274 |
* @throws PspellException |
| 275 |
* |
| 276 |
*/ |
| 277 |
function pspell_config_runtogether(int $dictionary_link, bool $flag): void |
| 278 |
{ |
| 279 |
error_clear_last(); |
| 280 |
$result = \pspell_config_runtogether($dictionary_link, $flag); |
| 281 |
if ($result === false) { |
| 282 |
throw PspellException::createFromPhpError(); |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
/** |
| 288 |
* pspell_config_save_repl determines whether |
| 289 |
* pspell_save_wordlist will save the replacement pairs |
| 290 |
* along with the wordlist. Usually there is no need to use this function |
| 291 |
* because if pspell_config_repl is used, the |
| 292 |
* replacement pairs will be saved by |
| 293 |
* pspell_save_wordlist anyway, and if it is not, |
| 294 |
* the replacement pairs will not be saved. |
| 295 |
* |
| 296 |
* pspell_config_save_repl should be used on a config |
| 297 |
* before calling pspell_new_config. |
| 298 |
* |
| 299 |
* @param int $dictionary_link |
| 300 |
* @param bool $flag TRUE if replacement pairs should be saved, FALSE otherwise. |
| 301 |
* @throws PspellException |
| 302 |
* |
| 303 |
*/ |
| 304 |
function pspell_config_save_repl(int $dictionary_link, bool $flag): void |
| 305 |
{ |
| 306 |
error_clear_last(); |
| 307 |
$result = \pspell_config_save_repl($dictionary_link, $flag); |
| 308 |
if ($result === false) { |
| 309 |
throw PspellException::createFromPhpError(); |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
/** |
| 315 |
* |
| 316 |
* |
| 317 |
* @param int $config The config parameter is the one returned by |
| 318 |
* pspell_config_create when the config was created. |
| 319 |
* @return int Returns a dictionary link identifier on success. |
| 320 |
* @throws PspellException |
| 321 |
* |
| 322 |
*/ |
| 323 |
function pspell_new_config(int $config): int |
| 324 |
{ |
| 325 |
error_clear_last(); |
| 326 |
$result = \pspell_new_config($config); |
| 327 |
if ($result === false) { |
| 328 |
throw PspellException::createFromPhpError(); |
| 329 |
} |
| 330 |
return $result; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
/** |
| 335 |
* pspell_new opens up a new dictionary and |
| 336 |
* returns the dictionary link identifier for use in other pspell |
| 337 |
* functions. |
| 338 |
* |
| 339 |
* For more information and examples, check out inline manual pspell |
| 340 |
* website:http://aspell.net/. |
| 341 |
* |
| 342 |
* @param string $language The language parameter is the language code which consists of the |
| 343 |
* two letter ISO 639 language code and an optional two letter ISO |
| 344 |
* 3166 country code after a dash or underscore. |
| 345 |
* @param string|null $spelling The spelling parameter is the requested spelling for languages |
| 346 |
* with more than one spelling such as English. Known values are |
| 347 |
* 'american', 'british', and 'canadian'. |
| 348 |
* @param string|null $jargon The jargon parameter contains extra information to distinguish |
| 349 |
* two different words lists that have the same language and |
| 350 |
* spelling parameters. |
| 351 |
* @param string|null $encoding The encoding parameter is the encoding that words are expected to |
| 352 |
* be in. Valid values are 'utf-8', 'iso8859-*', 'koi8-r', |
| 353 |
* 'viscii', 'cp1252', 'machine unsigned 16', 'machine unsigned |
| 354 |
* 32'. This parameter is largely untested, so be careful when |
| 355 |
* using. |
| 356 |
* @param int $mode The mode parameter is the mode in which spellchecker will work. |
| 357 |
* There are several modes available: |
| 358 |
* |
| 359 |
* |
| 360 |
* |
| 361 |
* PSPELL_FAST - Fast mode (least number of |
| 362 |
* suggestions) |
| 363 |
* |
| 364 |
* |
| 365 |
* |
| 366 |
* |
| 367 |
* PSPELL_NORMAL - Normal mode (more suggestions) |
| 368 |
* |
| 369 |
* |
| 370 |
* |
| 371 |
* |
| 372 |
* PSPELL_BAD_SPELLERS - Slow mode (a lot of |
| 373 |
* suggestions) |
| 374 |
* |
| 375 |
* |
| 376 |
* |
| 377 |
* |
| 378 |
* PSPELL_RUN_TOGETHER - Consider run-together words |
| 379 |
* as legal compounds. That is, "thecat" will be a legal compound, |
| 380 |
* although there should be a space between the two words. Changing this |
| 381 |
* setting only affects the results returned by |
| 382 |
* pspell_check; pspell_suggest |
| 383 |
* will still return suggestions. |
| 384 |
* |
| 385 |
* |
| 386 |
* |
| 387 |
* Mode is a bitmask constructed from different constants listed above. |
| 388 |
* However, PSPELL_FAST, |
| 389 |
* PSPELL_NORMAL and |
| 390 |
* PSPELL_BAD_SPELLERS are mutually exclusive, so you |
| 391 |
* should select only one of them. |
| 392 |
* |
| 393 |
* @return int Returns the dictionary link identifier on success. |
| 394 |
* @throws PspellException |
| 395 |
* |
| 396 |
*/ |
| 397 |
function pspell_new(string $language, ?string $spelling = null, ?string $jargon = null, ?string $encoding = null, int $mode = 0): int |
| 398 |
{ |
| 399 |
error_clear_last(); |
| 400 |
if ($mode !== 0) { |
| 401 |
$result = \pspell_new($language, $spelling, $jargon, $encoding, $mode); |
| 402 |
} elseif ($encoding !== null) { |
| 403 |
$result = \pspell_new($language, $spelling, $jargon, $encoding); |
| 404 |
} elseif ($jargon !== null) { |
| 405 |
$result = \pspell_new($language, $spelling, $jargon); |
| 406 |
} elseif ($spelling !== null) { |
| 407 |
$result = \pspell_new($language, $spelling); |
| 408 |
} else { |
| 409 |
$result = \pspell_new($language); |
| 410 |
} |
| 411 |
if ($result === false) { |
| 412 |
throw PspellException::createFromPhpError(); |
| 413 |
} |
| 414 |
return $result; |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
/** |
| 419 |
* |
| 420 |
* |
| 421 |
* @param int $dictionary_link A dictionary link identifier opened with |
| 422 |
* pspell_new_personal. |
| 423 |
* @throws PspellException |
| 424 |
* |
| 425 |
*/ |
| 426 |
function pspell_save_wordlist(int $dictionary_link): void |
| 427 |
{ |
| 428 |
error_clear_last(); |
| 429 |
$result = \pspell_save_wordlist($dictionary_link); |
| 430 |
if ($result === false) { |
| 431 |
throw PspellException::createFromPhpError(); |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
/** |
| 437 |
* |
| 438 |
* |
| 439 |
* @param int $dictionary_link A dictionary link identifier, opened with |
| 440 |
* pspell_new_personal |
| 441 |
* @param string $misspelled The misspelled word. |
| 442 |
* @param string $correct The fixed spelling for the misspelled word. |
| 443 |
* @throws PspellException |
| 444 |
* |
| 445 |
*/ |
| 446 |
function pspell_store_replacement(int $dictionary_link, string $misspelled, string $correct): void |
| 447 |
{ |
| 448 |
error_clear_last(); |
| 449 |
$result = \pspell_store_replacement($dictionary_link, $misspelled, $correct); |
| 450 |
if ($result === false) { |
| 451 |
throw PspellException::createFromPhpError(); |
| 452 |
} |
| 453 |
} |
| 454 |
|