]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailReminder/lib/userinvitereminderhandler.php
* only send the one invitation reminder per email address, regardless of how many...
[quix0rs-gnu-social.git] / plugins / EmailReminder / lib / userinvitereminderhandler.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  *
5  * Handler for queue items of type 'uinvrem' - sends an email reminder to
6  * an email address of someone who has been invited to the site
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @category  Email
22  * @package   StatusNet
23  * @author    Zach Copley <zach@status.net>
24  * @copyright 2011 StatusNet, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 /**
34  * Handler for queue items of type 'uinvrem' (user invite reminder)
35  *
36  * @category  Email
37  * @package   StatusNet
38  * @author    Zach Copley <zach@status.net>
39  * @copyright 2011 StatusNet, Inc.
40  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
41  * @link      http://status.net/
42  */
43 class UserInviteReminderHandler extends UserReminderHandler {
44
45     const INVITE_REMINDER = 'invite';
46
47     /**
48      * Return transport keyword which identifies items this queue handler
49      * services; must be defined for all subclasses.
50      *
51      * Must be 8 characters or less to fit in the queue_item database.
52      * ex "email", "jabber", "sms", "irc", ...
53      *
54      * @return string
55      */
56     function transport() {
57         return 'uinvrem';
58     }
59
60     /**
61      * Send an invitation reminder. We'll send one after one day, and then
62      * one after three days.
63      *
64      * @todo Abstract this stuff further
65      *
66      * @param array $invitem Invitation obj and any special options
67      * @return boolean success value
68      */
69     function sendNextReminder($invitem)
70     {
71         list($invitation, $opts) = $invitem;
72
73         $invDate = strtotime($invitation->created);
74         $now     = strtotime('now');
75
76         // Days since first invitation was sent
77         $days = ($now - $invDate) / 86499; // 60*60*24 = 86499
78         // $days = ($now - $regDate) / 120; // Two mins, good for testing
79
80         $siteName = common_config('site', 'name');
81
82         if ($days > 7 && isset($opts['onetime'])) {
83             // Don't send the reminder if we're past the normal reminder window and
84             // we've already pestered her at all before
85             if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation)) {
86                 common_log(LOG_INFO, "Sending one-time invitation reminder to {$invitation->address}", __FILE__);
87                 $subject = _m("Reminder - you have been invited to join {$siteName}!");
88                 return EmailReminderPlugin::sendReminder(
89                     self::INVITE_REMINDER,
90                     $invitation,
91                     $subject,
92                     -1 // special one-time indicator
93                 );
94             }
95         }
96
97         switch($days) {
98         case ($days > 1 && $days < 2):
99             if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 1)) {
100                 common_log(LOG_INFO, "Sending one day invitation reminder to {$invitation->address}", __FILE__);
101                 // TRANS: Subject for reminder e-mail. %s is the StatusNet sitename.
102                 $subject = sprintf(_m('Reminder - You have been invited to join %s!'),$siteName);
103                 return EmailReminderPlugin::sendReminder(
104                     self::INVITE_REMINDER,
105                     $invitation,
106                     $subject,
107                 1);
108             } else {
109                 return true;
110             }
111             break;
112         case ($days > 3 && $days < 4):
113             if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 3)) {
114                 common_log(LOG_INFO, "Sending three day invitation reminder to {$invitation->address}", __FILE__);
115                 // TRANS: Subject for reminder e-mail. %s is the StatusNet sitename.
116                 $subject = sprintf(_m('Final reminder - you have been invited to join %s!'),$siteName);
117                     return EmailReminderPlugin::sendReminder(
118                         self::INVITE_REMINDER,
119                         $invitation,
120                         $subject,
121                         3
122                     );
123                 } else {
124                     return true;
125                 }
126             break;
127         default:
128             common_log(LOG_INFO, "No need to send invitation reminder to {$invitation->address}.", __FILE__);
129             break;
130         }
131         return true;
132     }
133 }