[vhffs-dev] [1370] added a new pseudo service, users can now subscribe or unsubscribe to a global users mailing-list |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [1370] added a new pseudo service, users can now subscribe or unsubscribe to a global users mailing-list
- From: subversion@xxxxxxxxxxxxx
- Date: Wed, 11 Mar 2009 20:48:31 +0100
Revision: 1370
Author: gradator
Date: 2009-03-11 20:48:30 +0100 (Wed, 11 Mar 2009)
Log Message:
-----------
added a new pseudo service, users can now subscribe or unsubscribe to a global users mailing-list
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Makefile.am
trunk/vhffs-backend/conf/vhffs.conf.dist.in
trunk/vhffs-panel/subscribe.pl
trunk/vhffs-panel/templates/user/create.tmpl
trunk/vhffs-panel/templates/user/prefs.tmpl
trunk/vhffs-panel/user/prefs.pl
Added Paths:
-----------
trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm
Modified: trunk/vhffs-api/src/Vhffs/Makefile.am
===================================================================
--- trunk/vhffs-api/src/Vhffs/Makefile.am 2009-03-11 07:04:37 UTC (rev 1369)
+++ trunk/vhffs-api/src/Vhffs/Makefile.am 2009-03-11 19:48:30 UTC (rev 1370)
@@ -60,6 +60,7 @@
Services/Web.pm \
Services/Mail.pm \
Services/MailingList.pm \
+ Services/Newsletter.pm \
Services/MailUser.pm \
Services/MailGroup.pm \
Services/Mysql.pm \
Added: trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm (rev 0)
+++ trunk/vhffs-api/src/Vhffs/Services/Newsletter.pm 2009-03-11 19:48:30 UTC (rev 1370)
@@ -0,0 +1,91 @@
+#!%PERL%
+# Copyright (c) vhffs project and its contributors
+# 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.
+#3. Neither the name of vhffs nor the names of its contributors
+# may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#"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
+#COPYRIGHT OWNER OR CONTRIBUTORS 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.
+
+
+# This file is a part of VHFFS4 software, a hosting platform suite
+# Please respect the licence of this file and whole program
+
+# This module helps you to manage a newsletter to contact your users
+
+use strict;
+use utf8;
+
+package Vhffs::Services::Newsletter;
+
+use Vhffs::Services::MailingList;
+
+
+# Create a new instance of the current class
+sub init
+{
+ my $class = shift;
+ my $vhffs = shift;
+ my $user = shift;
+
+ return undef unless ( defined $vhffs && defined $user && $vhffs->get_config->get_service_availability('newsletter') );
+ my $config = $vhffs->get_config->get_service('newsletter');
+
+ # Fetches the mail domain defined in config
+ my $mailinglist_service;
+ if( defined $config->{'mailinglist'} ) {
+ my ( $localpart , $domain ) = ( $config->{'mailinglist'} =~ /(.+)\@(.+)/ );
+ $mailinglist_service = Vhffs::Services::MailingList::get_by_mladdress( $vhffs, $localpart, $domain );
+ }
+ return undef unless defined $mailinglist_service;
+
+ my $this = {};
+ $this->{main} = $vhffs;
+ $this->{config} = $config;
+ $this->{user} = $user;
+ $this->{mailinglist_service} = $mailinglist_service;
+ bless( $this , $class );
+ return $this;
+}
+
+sub exists
+{
+ my $self = shift;
+ return defined $self->{'mailinglist_service'}->get_members->{ $self->{'user'}->get_mail };
+}
+
+sub add
+{
+ my $self = shift;
+ return $self->{'mailinglist_service'}->add_sub( $self->{'user'}->get_mail , Vhffs::Constants::ML_RIGHT_SUB );
+}
+
+sub del
+{
+ my $self = shift;
+ return $self->{'mailinglist_service'}->del_sub( $self->{'user'}->get_mail );
+}
+
+1;
Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in 2009-03-11 07:04:37 UTC (rev 1369)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in 2009-03-11 19:48:30 UTC (rev 1370)
@@ -409,6 +409,29 @@
url_doc = http://help.myhoster.net/ml
</mailinglist>
+ # The newsletter service allows a user to subscribe or unsubscribe to a global users mailing
+ # list at subscription to the service and after that in the users preferences
+ <newsletter>
+ # Use this module or not
+ activate = no
+
+ # How the subscription to the newsletter is done when the user registers to the service
+ # active_optin : The user have to voluntarily check a box to allow receiving mails,
+ # this is the default.
+ # passive_optin : Same as active_optin, but the box is checked by default.
+ # active_optout : The user have to voluntarily check a box to *deny* receiving mails.
+ # passive_optout : The user is subscribed to the newsletter at subscription, but
+ # he is allowed to change that in user preferences.
+ # permanent : The user is permanently subscribed to the newsletter.
+ collectmode = active_optin
+
+ # The name of the used mailinglist, it MUST exist in vhffs database
+ mailinglist = newsletter@lists.myhost
+
+ # URL to the documentation (optional)
+ url_doc = http://help.myhoster.net/mailuser
+ </newsletter>
+
# Configuration of download repositories
<repository>
# Use this module or not
Modified: trunk/vhffs-panel/subscribe.pl
===================================================================
--- trunk/vhffs-panel/subscribe.pl 2009-03-11 07:04:37 UTC (rev 1369)
+++ trunk/vhffs-panel/subscribe.pl 2009-03-11 19:48:30 UTC (rev 1370)
@@ -53,6 +53,7 @@
use Vhffs::Constants;
use Vhffs::Panel::Main;
use Vhffs::Panel::Captcha;
+use Vhffs::Services::Newsletter;
my $panel = new Vhffs::Panel::Main();
exit 0 unless $panel;
@@ -92,6 +93,8 @@
my $zipcode = Encode::decode_utf8( $cgi->param("ZIPCODE") );
my $country = Encode::decode_utf8( $cgi->param("COUNTRY") );
my $address = Encode::decode_utf8( $cgi->param("ADDRESS") );
+ my $newslettercheckbox = $cgi->param('NEWSLETTER');
+ $newslettercheckbox = ( defined $newslettercheckbox && $newslettercheckbox eq 'on' );
if( $usecaptcha ) {
my $codeuser = $cgi->param('CONFIRMATION');
@@ -193,6 +196,21 @@
Vhffs::Acl::add_acl( $user , $user , Vhffs::Constants::ACL_DELETE , $vhffs );
Vhffs::Acl::add_acl( $user->get_group , $user , Vhffs::Constants::ACL_DENIED , $vhffs );
+
+ # Newsletter
+ my $newsletter = init Vhffs::Services::Newsletter( $vhffs , $user );
+ if( $newsletter ) {
+ my $mode = $newsletter->{'config'}->{'collectmode'} || 'undef';
+ if( ( $mode eq 'undef' && $newslettercheckbox )
+ || ( $mode eq 'active_optin' && $newslettercheckbox )
+ || ( $mode eq 'passive_optin' && $newslettercheckbox )
+ || ( $mode eq 'active_optout' && !$newslettercheckbox )
+ || ( $mode eq 'passive_optout' )
+ || ( $mode eq 'permanent' )
+ ) {
+ $newsletter->add;
+ }
+ }
}
}
}
@@ -208,7 +226,7 @@
$template->param( CITY_VALUE => $city );
$template->param( COUNTRY_VALUE => $country );
$template->param( ADDRESS_VALUE => $address );
-
+ $template->param( NEWSLETTER_CHECKED => $newslettercheckbox );
}
} else {
$template = new HTML::Template( filename => $templatedir."/panel/user/create.tmpl" );
@@ -244,6 +262,19 @@
$template->param( CONFIRMATION_SOUND_TEXT => gettext('Or listen to the code') );
}
+ if( $vhffs->get_config->get_service_availability('newsletter') ) {
+ my $conf = $vhffs->get_config->get_service('newsletter');
+ if( $conf->{'collectmode'} eq 'active_optin' ) {
+ $template->param( NEWSLETTER_TEXT => gettext('Subscribe to the newsletter') );
+ } elsif ( $conf->{'collectmode'} eq 'passive_optin' ) {
+ $template->param( NEWSLETTER_TEXT => gettext('Subscribe to the newsletter') );
+ $template->param( NEWSLETTER_CHECKED => 1 ) unless defined $submitted;
+ } elsif ( $conf->{'collectmode'} eq 'active_optout' ) {
+ $template->param( NEWSLETTER_TEXT => gettext('Don\'t subscribe to the newsletter') );
+ }
+ }
+
+
$template->param( USERNAME_TIP_TEXT => gettext('Your username. It must contains only alphanumeric characters in lowercase, its length must be between 3 and 12 chars') );
$template->param( EMAIL_TIP_TEXT => gettext('Your email address. It will be used to contact you when needed and as a destination address if you use our email forwarding service') );
}
Modified: trunk/vhffs-panel/templates/user/create.tmpl
===================================================================
--- trunk/vhffs-panel/templates/user/create.tmpl 2009-03-11 07:04:37 UTC (rev 1369)
+++ trunk/vhffs-panel/templates/user/create.tmpl 2009-03-11 19:48:30 UTC (rev 1370)
@@ -60,6 +60,14 @@
</label>
<span><input type="text" name="ZIPCODE" id="ZIPCODE" maxlength="16" value="<TMPL_VAR ESCAPE=1 NAME="ZIPCODE_VALUE">" onkeyup="javascript:check(this.id, validZip);" onchange="javascript:check(this.id, validZip);"/> </span>
</p>
+<TMPL_IF NAME="NEWSLETTER_TEXT">
+ <p>
+ <label for="NEWSLETTER">
+ <TMPL_VAR ESCAPE=1 NAME="NEWSLETTER_TEXT">
+ </label>
+ <span><input type="checkbox" name="NEWSLETTER" id="NEWSLETTER" <TMPL_IF NAME="NEWSLETTER_CHECKED">checked="checked"</TMPL_IF>/></span>
+ </p>
+</TMPL_IF>
<TMPL_IF NAME="USECAPTCHA">
<p>
<label for="CONFIRMATION">
Modified: trunk/vhffs-panel/templates/user/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/user/prefs.tmpl 2009-03-11 07:04:37 UTC (rev 1369)
+++ trunk/vhffs-panel/templates/user/prefs.tmpl 2009-03-11 19:48:30 UTC (rev 1370)
@@ -70,7 +70,12 @@
<TMPL_VAR ESCAPE=0 NAME="SHELL_LIST">
</select>
</p>
-
+<TMPL_IF NAME="NEWSLETTER_TEXT">
+ <p>
+ <label for="NEWSLETTER"><TMPL_VAR ESCAPE=1 NAME="NEWSLETTER_TEXT"> :</label>
+ <input type="checkbox" name="NEWSLETTER" id="NEWSLETTER" <TMPL_IF NAME="NEWSLETTER_CHECKED">checked="checked"</TMPL_IF>/>
+ </p>
+</TMPL_IF>
<TMPL_VAR ESCAPE=0 NAME="MAILUSER">
<p class="button" id="buttonModify">
Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl 2009-03-11 07:04:37 UTC (rev 1369)
+++ trunk/vhffs-panel/user/prefs.pl 2009-03-11 19:48:30 UTC (rev 1370)
@@ -47,6 +47,7 @@
use Vhffs::Panel::Object;
use Vhffs::Panel::Template;
use Vhffs::Services::MailUser;
+use Vhffs::Services::Newsletter;
my $panel = new Vhffs::Panel::Main();
exit 0 unless $panel;
@@ -92,10 +93,11 @@
my $address = Encode::decode_utf8( $cgi->param( 'ADDRESS' ) );
my $pass1 = $cgi->param( 'PASSWORD1' );
my $pass2 = $cgi->param( 'PASSWORD2' );
-
my $theme = $cgi->param( 'THEME' );
my $lang = $cgi->param( 'LANG' );
my $shell = $cgi->param( 'SHELL' );
+ my $newslettercheckbox = $cgi->param('NEWSLETTER');
+ $newslettercheckbox = ( defined $newslettercheckbox && $newslettercheckbox eq 'on' );
my $pwd_change = 0;
my $mail_change = 0;
@@ -176,6 +178,10 @@
my $prevmail = $userp->get_mail();
if( $prevmail ne $mail ) {
$mail_change = 1;
+
+ my $newsletter = init Vhffs::Services::Newsletter( $vhffs , $userp );
+ $newsletter->del if defined $newsletter;
+
$userp->set_mail( $mail );
my $subject = gettext("Mailbox modified");
my $content = sprintf( gettext("Hello %s %s,\n\nYou changed your email, here are your new personal information :\n\nUser: %s\nMail: %s\n\nVHFFS administrators\n"), $userp->get_firstname, $userp->get_lastname, $userp->get_username, $userp->get_mail);
@@ -285,6 +291,19 @@
$mu->delforward;
}
}
+
+ # -- Newsletter
+ my $newsletter = init Vhffs::Services::Newsletter( $vhffs , $userp );
+ if( defined $newsletter ) {
+ if( $newslettercheckbox && !$newsletter->exists ) {
+ $newsletter->add;
+ } elsif( !$newslettercheckbox && $newsletter->exists ) {
+ if( !defined $newsletter->{'config'}->{'collectmode'} || $newsletter->{'config'}->{'collectmode'} ne 'permanent' ) {
+ $newsletter->del;
+ }
+ }
+ }
+
}
}
}
@@ -444,6 +463,14 @@
$template->param( MAILUSER => $subtemplate->output );
}
+ my $newsletter = init Vhffs::Services::Newsletter( $vhffs , $userp );
+ if( defined $newsletter ) {
+ if( !defined $newsletter->{'config'}->{'collectmode'} || $newsletter->{'config'}->{'collectmode'} ne 'permanent' ) {
+ $template->param( NEWSLETTER_TEXT => gettext('Receive mails from the newsletter') );
+ $template->param( NEWSLETTER_CHECKED => $newsletter->exists );
+ }
+ }
+
if($user->is_admin) {
my $adminpart = Vhffs::Panel::Object::admin_part( $panel, $userp );
$template->param( ADMIN_PART => $adminpart->output ) if( defined $adminpart );