]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailReminder/lib/userconfirmregreminderhandler.php
EmailReminder plugin to send reminders about various things
[quix0rs-gnu-social.git] / plugins / EmailReminder / lib / userconfirmregreminderhandler.php
1 <?php
2
3 /**
4  * StatusNet - the distributed open-source microblogging tool
5  *
6  * Handler for queue items of type 'uregem' - sends email registration
7  * confirmation reminders to a particular user.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Email
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2011 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
27  * @link      http://status.net/
28  */
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 /**
34  * Handler for queue items of type 'uregrem'
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 UserConfirmRegReminderHandler extends UserReminderHandler {
44
45     const REGISTER_REMINDER = 'register';
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 'uregrem';
58     }
59
60     /**
61      * Send an email registration confirmation reminder until the user
62      * confirms her registration. We'll send a reminder after one day,
63      * three days, and a full week.
64      *
65      * @todo abstract this bit further
66      *
67      * @param Confirm_address $confirm
68      * @return boolean success value
69      */
70     function sendNextReminder($confirm)
71     {
72         $regDate = strtotime($confirm->modified); // Seems like my best bet
73         $now     = strtotime('now');
74
75         // Days since registration
76         $days = ($now - $regDate) / 86499; // 60*60*24 = 86499
77
78         // Welcome to one of the ugliest switch statement I've ever written
79
80         switch($days) {
81         case ($days > 1 && $days < 2):
82             if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 1)) {
83                 common_log(LOG_INFO, "Sending one day registration confirmation reminder to {$confirm->address}", __FILE__);
84                 $subject = _m("Reminder - please confirm your registration!");
85                 return EmailReminderPlugin::sendReminder(
86                     self::REGISTER_REMINDER,
87                     $confirm,
88                     $subject,
89                 1);
90             } else {
91                 return true;
92             }
93             break;
94         case ($days > 3 && $days < 4):
95             if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 3)) {
96                 common_log(LOG_INFO, "Sending three day registration confirmation reminder to {$confirm->address}", __FILE__);
97                 $subject = _m("Second reminder - please confirm your registration!");
98                     return EmailReminderPlugin::sendReminder(
99                         self::REGISTER_REMINDER,
100                         $confirm,
101                         $subject,
102                         3
103                     );
104                 } else {
105                     return true;
106                 }
107             break;
108         case ($days > 7 && $days < 8):
109             if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 7)) {
110                 common_log(LOG_INFO, "Sending one week registration confirmation reminder to {$confirm->address}", __FILE__);
111                 $subject = _m("Final reminder - please confirm your registration!");
112                 return EmailReminderPlugin::sendReminder(
113                     self::REGISTER_REMINDER,
114                     $confirm,
115                     $subject,
116                     7
117                 );
118             } else {
119                 return true;
120             }
121             break;
122         }
123         return true;
124     }
125
126 }