1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-24 09:25:01 +00:00

- Add option to enable remote spell checking capabilities

- Add option to install a local spell checker

Approved by:	maintainer
This commit is contained in:
Alex Dupre 2007-01-03 21:38:46 +00:00
parent 0f0cf3b65a
commit 9fcdadecee
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=181372
4 changed files with 86 additions and 1 deletions

View File

@ -57,10 +57,11 @@ LOCALBASE?= /usr/local
OPTIONS= MYSQL "Use MySQL backend" on \
PGSQL "Use PostgreSQL backend" off
.if defined(PHP_VER) && ${PHP_VER} == 5
OPTIONS+= SQLITE "Use SQLite backend" off
.endif
OPTIONS+= SPELLCHECK "Enable spellchecking" off \
LOCALCHECK "Install internal spellchecker" off
.include <bsd.port.pre.mk>
@ -80,11 +81,28 @@ USE_PHP+= pgsql
USE_PHP+= sqlite
.endif
.if defined(WITH_SPELLCHECK)
USE_PHP+= openssl sockets
.endif
.if defined(WITH_LOCALCHECK)
RCUBECOMP+= spellchecker.php
USE_PHP+= pspell simplexml
PLIST_SUB+= SPELLCHECK=""
.else
PLIST_SUB+= SPELLCHECK="@comment "
.endif
# Avoid INDEX breakage when WITHOUT_MYSQL is defined.
USE_PHP?= yes
.include "${PORTSDIR}/Mk/bsd.php.mk"
.if defined(WITH_LOCALCHECK)
post-extract:
@${CP} ${FILESDIR}/spellchecker.php ${WRKSRC}
.endif
.if defined(WITH_REPLACE_MAIL_URL)
post-patch:
@${REINPLACE_CMD} "s/'mail'/'${MAIL}'/g" ${WRKSRC}/index.php \

View File

@ -0,0 +1,13 @@
--- config/main.inc.php.dist.orig Sat Dec 9 19:55:13 2006
+++ config/main.inc.php.dist Sat Dec 9 19:57:58 2006
@@ -160,8 +160,8 @@
// Make use of the built-in spell checker. It is based on GoogieSpell.
$rcmail_config['enable_spellcheck'] = TRUE;
-// For a locally installed Nox Spell Server, please specify the URI to call it.
-// Get Nox Spell Server from http://orangoo.com/labs/?page_id=72
+// For a locally installed spellcheker, specify the URI to call it, for example:
+// 'http://' . $_SERVER['HTTP_HOST'] . '/spellchecker.php?lang='
// Leave empty to use the Google spell checking service, what means
// that the message content will be sent to Google in order to check spelling
$rcmail_config['spellcheck_uri'] = '';

View File

@ -0,0 +1,53 @@
<?php
/*-
* Copyright (c) 2006 Alex Dupre. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
$lang = $_REQUEST["lang"];
$xml = new SimpleXMLElement(file_get_contents("php://input"));
$spell = pspell_new($lang, "", "", "utf-8", PSPELL_NORMAL);
$suggestions = array();
$offset = 0;
mb_regex_encoding("UTF-8");
foreach (mb_split("\n", $xml->text) as $line) {
$len = mb_strlen($line, "UTF-8");
mb_ereg_search_init($line, "\w+");
while (($wpos = mb_ereg_search_pos()) != FALSE) {
$word = mb_substr($line, $wpos[0], $wpos[1]);
if (!pspell_check($spell, $word)) {
$woffset = mb_strlen(mb_substr($line, 0, $wpos[0]), "UTF-8");
$wlen = mb_strlen($word, "UTF-8");
array_push($suggestions, array($offset + $woffset, $wlen, pspell_suggest($spell, $word)));
}
}
$offset += $len + 1;
}
$xml = new SimpleXMLElement("<spellresponse/>");
$xml->addAttribute("error", count($suggestions) ? "1" : "0");
foreach ($suggestions as $s) {
$c = $xml->addChild("c", join("\t", $s[2]));
$c->addAttribute("o", $s[0]);
$c->addAttribute("l", $s[1]);
$c->addAttribute("s", "1");
}
header('Content-Type: text/xml');
echo $xml->asXML();

View File

@ -577,6 +577,7 @@
%%RCUBEDIR%%/skins/default/templates/settings.html
%%RCUBEDIR%%/skins/default/templates/showcontact.html
%%RCUBEDIR%%/skins/default/watermark.html
%%SPELLCHECK%%%%RCUBEDIR%%/spellchecker.php
%%RCUBEDIR%%/temp/.htaccess
@dirrm %%RCUBEDIR%%/skins/default/templates
@dirrm %%RCUBEDIR%%/skins/default/includes