Skip to content

Commit

Permalink
Item9551: More restructuring and modernize
Browse files Browse the repository at this point in the history
 - Change Jabber to XMPP
 - Change to object style for handlers
 - Add template to define the xmpp message
 - Dynamic load based upon config
 - tidy

git-svn-id: http://svn.foswiki.org/trunk/ImmediateNotifyPlugin@12051 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jun 26, 2011
1 parent ad1d2cd commit 34682c5
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 162 deletions.
25 changes: 13 additions & 12 deletions data/System/ImmediateNotifyPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ Add a set statement to the topic. WikiNames (or groups) are listed in a comma se

---+++ User configuration

The user may optionally configure their desired notification method. Since SMTP and Jabber are currently the only available methods, this consists of:
The user may optionally configure their desired notification method. Since SMTP and XMPP are currently the only available methods, this consists of:

* Adding a line =" * Set IMMEDIATENOTIFYMETHOD = Jabber(userid)"= (or "SMTP", respectively) to their user topic.
* Adding a line =" * Set IMMEDIATENOTIFYMETHOD = XMPP(userid)"= (or "SMTP", respectively) to their user topic.

If no notification method is selected, the user will be notified using SMTP.

| *Desired Notifications* | *Setting in User topic* |
| Email sent to default ID registered on Foswiki. | =* Set IMMEDIATENOTIFYMETHOD = SMTP= <br />Or don't set anything - this is the default. |
| XMPP / Jabber IM sent to wikiuser@openfire. | =* Set IMMEDIATENOTIFYMETHOD = Jabber(wikiuser@openfire)= |
| XMPP / Jabber IM sent to wikiuser@openfire. | =* Set IMMEDIATENOTIFYMETHOD = XMPP(wikiuser@openfire)= |

---++ <nop>%TOPIC% Global Settings

Expand All @@ -63,13 +63,13 @@ If no notification method is selected, the user will be notified using SMTP.
%X% This version of the plugin must be configured in the Foswiki system configuration using the [[%SCRIPTURL{"configure"}%][configure script]].

* Enable the desired notification methods in the configuration. If a notification method is not enabled here, it will be unavailable for users to use.
* ={ImmediateNotifyPlugin}{SMTP}{Enabled}=
* ={ImmediateNotifyPlugin}{Jabber}{Enabled}=
* ={Plugins}{ImmediateNotifyPlugin}{SMTP}{Enabled}=
* ={Plugins}{ImmediateNotifyPlugin}{XMPP}{Enabled}=

* For XMPP (Jabber) instant message notifications, the servername, userid and password for the sever account must be configured.
* ={ImmediateNotifyPlugin}{Jabber}{Server}=
* ={ImmediateNotifyPlugin}{Jabber}{Username}=
* ={ImmediateNotifyPlugin}{Jabber}{Password}=
* ={Plugins}{ImmediateNotifyPlugin}{XMPP}{Server}=
* ={Plugins}{ImmediateNotifyPlugin}{XMPP}{Username}=
* ={Plugins}{ImmediateNotifyPlugin}{XMPP}{Password}=

* For SMTP, see the configure Email and Proxies Tab.

Expand All @@ -80,14 +80,15 @@ __Note:__ You do not need to install anything on the browser to use this plugin.
| *File:* | *Description:* |
%$MANIFEST%
* Visit =configure= in your Foswiki installation, and enable the plugin in the {Plugins} section.
* Under the tab for %TOPIC%, enable the desired methods, and configure the Jabber / XMPP server information
* Under the tab for %TOPIC%, enable the desired methods, and configure the XMPP server information
* Set up notification methods (default is SMTP)
* Currently the only available methods are via SMTP and Jabber.
* Currently the only available methods are via SMTP and XMPP.
* SMTP
* The site's global email configuration is used - no additional configuration is needed.
* Jabber
* XMPP
* Set up a Jabber account for the wiki with a standard client.
* Create a =Web<nop>ImmediateNotify= topic in each web for users to list their names in for notification.
* Create a =Web<nop>ImmediateNotify= topic in each web for users to list their names in for notification. __or__
* Instruct users to add IMMEDIATENOTIFY settings to individual topics

---++ Plugin Info

Expand Down
77 changes: 44 additions & 33 deletions lib/Foswiki/Plugins/ImmediateNotifyPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ our $NO_PREFS_IN_TOPIC = 1;

our $debug;

my %methodHandlers; # Loaded handlers
my %methodAllowed; # Methods permitted by config.
my %methodHandlers; # Loaded handlers
my %methodAllowed; # Methods permitted by config.

# Regular expressions used in topic processing

Expand Down Expand Up @@ -64,18 +64,19 @@ sub initPlugin {
# Get plugin debug flag
$debug = Foswiki::Func::getPluginPreferencesFlag("DEBUG") || 0;

my @available = qw( Jabber SMTP );

foreach my $method ( @available ) {
if ( $Foswiki::cfg{ImmediateNotifyPlugin}{$method}{Enabled} ) {
# Find any configured methods and make available.
foreach my $method ( keys %{$Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}} ) {
next if ($method eq "Module" );
next if ($method eq "Enabled" );
if ( $Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{$method}{Enabled} ) {
debug("Allowing method $method");
$methodAllowed{$method} = 1;
$methodCount++;
}
}

# Plugin correctly initialized
if ( $methodCount ) {
if ($methodCount) {
debug(
"- Foswiki::Plugins::ImmediateNotifyPlugin::initPlugin( $web.$topic ) is OK"
);
Expand All @@ -84,36 +85,43 @@ sub initPlugin {
else {
warning("ImmediateNotifyPlugin - no methods enabled");
return 0;
}
}
}

sub finishPlugin {

debug("finishPlugin entered");
foreach my $handler (%methodHandlers) {
next unless $handler;
$methodHandlers{$handler}->disconnect();
$methodHandlers{$handler} = '';
}
}

sub _loadHandler {
my $method = shift;
return 1 if $methodHandlers{$method}; # Already loaded
return 1 if $methodHandlers{$method}; # Already loaded

my $handler;

if ($methodAllowed{$method} ) {
if ( $methodAllowed{$method} ) {
debug("- ImmediateNotifyPlugin: Loading method $method...");
my $modulePresent =
eval { require "Foswiki/Plugins/ImmediateNotifyPlugin/$method.pm"; 1 };
unless ( defined($modulePresent) ) {
warning("- ImmediateNotifyPlugin::$method failed to load: $@ $!");
debug("- ImmediateNotifyPlugin::$method failed to load: $@ $!");
return 0;
}

my $module = "Foswiki::Plugins::ImmediateNotifyPlugin::${method}::";
if ( eval $module . 'initMethod()' ) {
$methodHandlers{$method} = eval '\&' . $module . 'handleNotify';
}
else {
debug("- ImmediateNotifyPlugin: initMethod failed $@ $!");
}
my $module = 'Foswiki::Plugins::ImmediateNotifyPlugin::' . $method;
eval {
( my $file = $module ) =~ s|::|/|g;
require $file . '.pm';
$handler = $module->new();
1;
}
or do {
print STDERR "FAILED TO LOAD $@";
warning("- ImmediateNotifyPlugin::$method failed to load $@ $!");
return 0;
};

if ( defined( $methodHandlers{$method} ) ) {
if ( $handler->connect() ) {
$methodHandlers{$method} = $handler;
debug("- ImmediateNotifyPlugin::$method OK");
return 1;
}
Expand All @@ -123,7 +131,8 @@ sub _loadHandler {
}
}
else {
warning("- ImmediateNotifyPlugin::$method not permitted by configuration!");
warning(
"- ImmediateNotifyPlugin::$method not permitted by configuration!");
return 0;
}
}
Expand Down Expand Up @@ -185,8 +194,8 @@ sub afterSaveHandler {

my $topicInfo = $topicObject->getRevisionInfo();
$topicInfo->{topic} = $topic;
$topicInfo->{web} = $web;
$topicInfo->{user} = $user;
$topicInfo->{web} = $web;
$topicInfo->{user} = $user;

# This handler is called by Foswiki::Store::saveTopic just after the save action.

Expand Down Expand Up @@ -217,7 +226,7 @@ sub afterSaveHandler {
}
}

# Retrieve the WebImmediateNotify topic and extract names
# Retrieve the WebImmediateNotify topic and extract names
my $notifyTopic =
Foswiki::Func::readTopicText( $web, "WebImmediateNotify" );
debug("- ImmediateNotifyPlugin: no WebImmediateNotify topic found in $web")
Expand All @@ -236,13 +245,13 @@ sub afterSaveHandler {
return;
}

# Recursively expand all users / groups into a list of names to notify
# Recursively expand all users / groups into a list of names to notify
my ( %users, %groups );
foreach my $name (@names) {
processName( $name, \%users, \%groups );
}

# Extract required methods from the users list and lazy load them
# Extract required methods from the users list and lazy load them
my %userMethods;
foreach my $user ( keys %users ) {
debug("- ImmediateNotifyPlugin processing Users: $user");
Expand All @@ -253,7 +262,9 @@ sub afterSaveHandler {
foreach my $method (@methodList) {
if ( _loadHandler($method) ) {
$userMethods{$user}{$method} = 1;
debug("- ImmediateNotifyPlugin: Handler loaded - Set method to $method for $user ");
debug(
"- ImmediateNotifyPlugin: Handler loaded - Set method to $method for $user "
);
}
}
}
Expand All @@ -275,7 +286,7 @@ sub afterSaveHandler {
debug( "- ImmediateNotifyPlugin: $method userlist "
. join( " ", keys %methodUsers ) );
if (%methodUsers) {
&{ $methodHandlers{$method} }( \%methodUsers, $topicInfo );
$methodHandlers{$method}->notify( \%methodUsers, $topicInfo );
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/Foswiki/Plugins/ImmediateNotifyPlugin/Config.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# **BOOLEAN**
# Enable SMTP for mailing messages. Note: This plugin uses Foswiki core email support for sending
# notifications. See the "Mail and Proxies" tab for the configuration.
$Foswiki::cfg{ImmediateNotifyPlugin}{SMTP}{Enabled} = $FALSE;
$Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{SMTP}{Enabled} = $FALSE;

# **REGEX**
# Define the regular expression that an email address entered in WebNotify
Expand All @@ -12,23 +12,23 @@ $Foswiki::cfg{ImmediateNotifyPlugin}{SMTP}{Enabled} = $FALSE;
# domain.<br />
# If this is not defined, then the default setting of
# <code>[A-Za-z0-9.+-_]+\@[A-Za-z0-9.-]+</code> is used.
$Foswiki::cfg{ImmediateNotifyPlugin}{SMTP}{EmailFilterIn} = '';
$Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{SMTP}{EmailFilterIn} = '';

# **BOOLEAN**
# Enable XMPP (Jabber) for notifications.
$Foswiki::cfg{ImmediateNotifyPlugin}{Jabber}{Enabled} = $FALSE;
# Enable XMPP (XMPP) for notifications.
$Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{XMPP}{Enabled} = $FALSE;

# **STRING 30**
# Hostname of the XMPP / Jabber server
$Foswiki::cfg{ImmediateNotifyPlugin}{Jabber}{Server} = '';
# Hostname of the XMPP / XMPP server
$Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{XMPP}{Server} = '';

# **STRING 30**
# Username for the Jabber account used by the ImmediateNotifyPlugin. If configured here, the
# Username for the XMPP account used by the ImmediateNotifyPlugin. If configured here, the
# topic based setting will be ignored.
$Foswiki::cfg{ImmediateNotifyPlugin}{Jabber}{Username} = '';
$Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{XMPP}{Username} = '';

# **PASSWORD 30**
# Password for the Jabber account used by the ImmediateNotifyPlugin. If configured here, the
# Password for the XMPP account used by the ImmediateNotifyPlugin. If configured here, the
# topic based setting will be ignored.
$Foswiki::cfg{ImmediateNotifyPlugin}{Jabber}{Password} = '';
$Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{XMPP}{Password} = '';

97 changes: 0 additions & 97 deletions lib/Foswiki/Plugins/ImmediateNotifyPlugin/Jabber.pm

This file was deleted.

3 changes: 2 additions & 1 deletion lib/Foswiki/Plugins/ImmediateNotifyPlugin/MANIFEST
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
lib/Foswiki/Plugins/ImmediateNotifyPlugin.pm
lib/Foswiki/Plugins/ImmediateNotifyPlugin/Jabber.pm
lib/Foswiki/Plugins/ImmediateNotifyPlugin/XMPP.pm
lib/Foswiki/Plugins/ImmediateNotifyPlugin/SMTP.pm
lib/Foswiki/Plugins/ImmediateNotifyPlugin/Config.spec
data/System/ImmediateNotifyPlugin.txt
templates/smtp.immediatenotify.tmpl
templates/xmpp.immediatenotify.tmpl
Loading

0 comments on commit 34682c5

Please sign in to comment.