From 9f232b4049035d23415969c10a147097c6c82da9 Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Thu, 19 Oct 2006 15:25:50 +0000 Subject: [PATCH] Adding spellchecker --- docs/changelog/7.x.x.txt | 2 +- docs/gotcha.txt | 9 + docs/upgrades/upgrade_7.1.2-7.2.0.pl | 18 +- etc/WebGUI.conf.original | 17 + lib/WebGUI.pm | 5 +- lib/WebGUI/Asset/RichEdit.pm | 16 +- lib/WebGUI/Operation.pm | 4 + lib/WebGUI/Operation/SpellCheck.pm | 222 +++++++ lib/WebGUI/i18n/English/Asset_RichEdit.pm | 10 + sbin/testEnvironment.pl | 1 + .../tiny_mce/plugins/spellchecker/changelog | 5 + .../spellchecker/classes/HttpClient.class.php | 339 ++++++++++ .../classes/TinyGoogleSpell.class.php | 73 +++ .../spellchecker/classes/TinyPspell.class.php | 64 ++ .../classes/TinyPspellShell.class.php | 100 +++ .../tiny_mce/plugins/spellchecker/config.php | 24 + .../plugins/spellchecker/css/content.css | 5 + .../plugins/spellchecker/css/spellchecker.css | 34 + .../plugins/spellchecker/editor_plugin.js | 601 ++++++++++++++++++ .../plugins/spellchecker/editor_plugin_src.js | 575 +++++++++++++++++ .../spellchecker/images/spellchecker.gif | Bin 0 -> 591 bytes .../plugins/spellchecker/images/wline.gif | Bin 0 -> 46 bytes .../plugins/spellchecker/tinyspell.php | 137 ++++ 23 files changed, 2251 insertions(+), 10 deletions(-) create mode 100644 lib/WebGUI/Operation/SpellCheck.pm create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/changelog create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/classes/HttpClient.class.php create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/classes/TinyGoogleSpell.class.php create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/classes/TinyPspell.class.php create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/config.php create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/css/content.css create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/css/spellchecker.css create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/editor_plugin.js create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/editor_plugin_src.js create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/images/spellchecker.gif create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/images/wline.gif create mode 100644 www/extras/tinymce2/jscripts/tiny_mce/plugins/spellchecker/tinyspell.php diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index eb4271d4c..659a624bd 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,5 @@ 7.2.0 - + - Added server side spellchecker (Martin Kamerbeek / Procolix) 7.1.2 diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 075dd8e75..9a13f0804 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -7,6 +7,15 @@ upgrading from one version to the next, or even between multiple versions. Be sure to heed the warnings contained herein as they will save you many hours of grief. +7.2.0 +-------------------------------------------------------------------- + * Server side spellchecking has been added to this release. You must + install Text::Aspell, and any dictionary you like. If you want to + use spellchecking you have to setup the dictionaries you want your + users to use in the config file. Also you'll have to check the + spellchecker checkbox in the RichEdit asset you're using. + + 7.0.8 -------------------------------------------------------------------- * 7.0.7 was released with a critical bug that broke the search engine diff --git a/docs/upgrades/upgrade_7.1.2-7.2.0.pl b/docs/upgrades/upgrade_7.1.2-7.2.0.pl index a8bf45b0a..66372d097 100644 --- a/docs/upgrades/upgrade_7.1.2-7.2.0.pl +++ b/docs/upgrades/upgrade_7.1.2-7.2.0.pl @@ -20,17 +20,21 @@ my $quiet; # this line required my $session = start(); # this line required -# upgrade functions go here +createDictionaryStorage($session); finish($session); # this line required -##------------------------------------------------- -#sub exampleFunction { -# my $session = shift; -# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet); -# # and here's our code -#} +#------------------------------------------------- +sub createDictionaryStorage { + my $session = shift; + print "\tCreating the directory for the personal dictionaries.\n" unless ($quiet); + + my $dictionaryDirectory = $session->config->get('uploadsPath') .'/dictionaries'; + + mkdir $dictionaryDirectory unless (-e $dictionaryDirectory); + mkdir $dictionaryDirectory.'/oldIds' unless (-e $dictionaryDirectory.'/oldIds'); +} diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index bfe87d1bf..f2aa06d77 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -402,6 +402,23 @@ "WebGUI::Image::Graph::XYGraph::Line" ], +# Here you can define the dictionaries that are available through the tinyMCE spellchecker. You should set +# id to the name the dictionary is known by ASpell (eg. en or en_US or nl), use the name parameter to set +# the name the dictionary is displayed with in tinyMCE. To set the default dictionary please set the 'default' +# parameter. + +#"availableDictionaries" : [ +# { +# "id" : "en", +# "name" : "English", +# "default" : "1" +# }, +# { +# "id" : "nl", +# "name" : "Dutch" +# } +#], + # Optional script to run upon successful login. The script can contain macros # ex: /data/WebGUI/sbin/doLogin.pl --configFile=dev.localhost.localdomain.conf --loginPage=^PageUrl(); diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 251975dbb..eb73bca23 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -56,7 +56,10 @@ sub handler { return Apache2::Const::DECLINED if ($r->uri =~ m/^$url/); } my $uploads = $config->get("uploadsURL"); - if ($r->uri =~ m/^$uploads/) { + if ($r->uri =~ m!^uploads/dictionaries!) { + # Do not allow web-access to personal dictionaries. + $r->push_handlers(PerlAccessHandler => sub { return 401 } ); + } elsif($r->uri =~ m/^$uploads/) { $r->push_handlers(PerlAccessHandler => sub { return uploadsHandler($r, $configFile); } ); } else { $r->push_handlers(PerlResponseHandler => sub { return contentHandler($r, $configFile); } ); diff --git a/lib/WebGUI/Asset/RichEdit.pm b/lib/WebGUI/Asset/RichEdit.pm index 3d922d83f..cffeaa2ab 100644 --- a/lib/WebGUI/Asset/RichEdit.pm +++ b/lib/WebGUI/Asset/RichEdit.pm @@ -19,6 +19,7 @@ use WebGUI::Asset; use WebGUI::Form; use WebGUI::Utility; use WebGUI::International; +use Text::Aspell; our @ISA = qw(WebGUI::Asset); @@ -217,6 +218,7 @@ sub getEditForm { 'fullscreen' => $i18n->get('fullscreen'), 'zoom' => $i18n->get('zoom'), 'print' => $i18n->get('print'), + 'spellchecker' => $i18n->get('Server Side Spell Checker'), # 'advlink' => "Advanced Link", # 'spacer' => "Toolbar Spacer", # 'separator' => "Toolbar Separator", @@ -229,6 +231,7 @@ sub getEditForm { %s %s %s + !, $i18n->get('button'), $i18n->get('row 1'), @@ -260,7 +263,11 @@ sub getEditForm { value=>$key, name=>"toolbarRow3", checked=>$checked3 - }).' + }).''; + if ($key eq 'spellchecker' && !($self->session->config->get('availableDictionaries'))) { + $buttonGrid .= $i18n->get('no dictionaries'); + } + $buttonGrid .= ' '; } @@ -457,8 +464,14 @@ sub getRichEditor { theme_advanced_toolbar_location => $self->getValue("toolbarLocation"), theme_advanced_statusbar_location => "bottom", valid_elements => $self->getValue("validElements"), + wg_userIsVisitor => $self->session->user->userId eq '1' ? 'true' : 'false', ); foreach my $button (@toolbarButtons) { + if ($button eq "spellchecker" && $self->session->config->get('availableDictionaries')) { + push(@plugins,"spellchecker"); + $config{spellchecker_languages} = + join(',', map { ($_->{default} ? '+' : '').$_->{name}.'='.$_->{id} } @{$self->session->config->get('availableDictionaries')}); + } push(@plugins,"table") if ($button eq "tablecontrols"); push(@plugins,"save") if ($button eq "save"); push(@plugins,"advhr") if ($button eq "advhr"); @@ -516,6 +529,7 @@ sub getRichEditor { push(@directives,$key." : '".$config{$key}."'"); } } + $self->session->style->setScript($self->session->url->extras('tinymce2/jscripts/tiny_mce/tiny_mce.js'),{type=>"text/javascript"}); $self->session->style->setScript($self->session->url->extras("tinymce2/jscripts/webgui.js"),{type=>"text/javascript"}); return '