]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailReminder/lib/userinvitereminderhandler.php
EmailReminder plugin to send reminders about various things
[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 if (!defined('STATUSNET')) {
29     exit(1);
30 }
31
32 /**
33  * Handler for queue items of type 'uinvrem' (user invite reminder)
34  *
35  * @category  Email
36  * @package   StatusNet
37  * @author    Zach Copley <zach@status.net>
38  * @copyright 2011 StatusNet, Inc.
39  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
40  * @link      http://status.net/
41  */
42 class UserInviteReminderHandler extends UserReminderHandler {
43
44     const INVITE_REMINDER = 'invite';
45
46     /**
47      * Return transport keyword which identifies items this queue handler
48      * services; must be defined for all subclasses.
49      *
50      * Must be 8 characters or less to fit in the queue_item database.
51      * ex "email", "jabber", "sms", "irc", ...
52      *
53      * @return string
54      */
55     function transport() {
56         return 'uinvrem';
57     }
58
59     /**
60      * Send an invitation reminder. We'll send one after one day, and then
61      * one after three days.
62      *
63      * @todo Abstract this stuff further
64      *
65      * @param Invitation $invitation
66      * @return boolean success value
67      */
68     function sendNextReminder($invitation)
69     {
70         $invDate = strtotime($invitation->created);
71         $now     = strtotime('now');
72         
73         // Days since first invitation was sent
74         $days = ($now - $invDate) / 86499; // 60*60*24 = 86499
75
76         $siteName = common_config('site', 'name');
77
78         switch($days) {
79         case ($days > 1 && $days < 2):
80             if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 1)) {
81                 common_log(LOG_INFO, "Sending one day invitation reminder to {$invitation->address}", __FILE__);
82                 $subject = _m("Reminder - You have been invited to join {$siteName}!");
83                 return EmailReminderPlugin::sendReminder(
84                     self::INVITE_REMINDER,
85                     $invitation,
86                     $subject,
87                 1);
88             } else {
89                 return true;
90             }
91             break;
92         case ($days > 3 && $days < 4):
93             if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 3)) {
94                 common_log(LOG_INFO, "Sending three day invitation reminder to {$invitation->address}", __FILE__);
95                 $subject = _m("Final reminder - you have been invited to join {$siteName}!");
96                     return EmailReminderPlugin::sendReminder(
97                         self::INVITE_REMINDER,
98                         $invitation,
99                         $subject,
100                         3
101                     );
102                 } else {
103                     return true;
104                 }
105             break;        
106         }
107         return true;
108     }
109
110 }