]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailReminder/lib/userconfirmregreminderhandler.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / EmailReminder / lib / userconfirmregreminderhandler.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  *
5  * Handler for queue items of type 'uregem' - sends email registration
6  * confirmation reminders to a particular user.
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 '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 array $regitem confirmation address and any special options
68      * @return boolean success value
69      */
70     function sendNextReminder($regitem)
71     {
72         list($confirm, $opts) = $regitem;
73
74         $regDate = strtotime($confirm->modified); // Seems like my best bet
75         $now     = strtotime('now');
76
77         // Days since registration
78         $days = ($now - $regDate) / 86499; // 60*60*24 = 86499
79         // $days = ($now - $regDate) / 120; // Two mins, good for testing
80
81         if ($days > 7 && isset($opts['onetime'])) {
82             // Don't send the reminder if we're past the normal reminder window and
83             // we've already pestered her at all before
84             if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm)) {
85                 common_log(LOG_INFO, "Sending one-time registration confirmation reminder to {$confirm->address}", __FILE__);
86                 $subject = _m("One time reminder - please confirm your registration!");
87                 return EmailReminderPlugin::sendReminder(
88                     self::REGISTER_REMINDER,
89                     $confirm,
90                     $subject,
91                     -1 // special one-time indicator
92                 );
93             }
94         }
95
96         // Welcome to one of the ugliest switch statement I've ever written
97
98         switch($days) {
99         case ($days > 1 && $days < 2):
100             if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 1)) {
101                 common_log(LOG_INFO, "Sending one day registration confirmation reminder to {$confirm->address}", __FILE__);
102                 // TRANS: Subject for reminder e-mail.
103                 $subject = _m('Reminder - please confirm your registration!');
104                 return EmailReminderPlugin::sendReminder(
105                     self::REGISTER_REMINDER,
106                     $confirm,
107                     $subject,
108                     1
109                 );
110             } else {
111                 return true;
112             }
113             break;
114         case ($days > 3 && $days < 4):
115             if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 3)) {
116                 common_log(LOG_INFO, "Sending three day registration confirmation reminder to {$confirm->address}", __FILE__);
117                 // TRANS: Subject for reminder e-mail.
118                 $subject = _m('Second reminder - please confirm your registration!');
119                     return EmailReminderPlugin::sendReminder(
120                         self::REGISTER_REMINDER,
121                         $confirm,
122                         $subject,
123                         3
124                     );
125                 } else {
126                     return true;
127                 }
128             break;
129         case ($days > 7 && $days < 8):
130             if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 7)) {
131                 common_log(LOG_INFO, "Sending one week registration confirmation reminder to {$confirm->address}", __FILE__);
132                 // TRANS: Subject for reminder e-mail.
133                 $subject = _m('Final reminder - please confirm your registration!');
134                 return EmailReminderPlugin::sendReminder(
135                     self::REGISTER_REMINDER,
136                     $confirm,
137                     $subject,
138                     7
139                 );
140             } else {
141                 return true;
142             }
143             break;
144         }
145         return true;
146     }
147 }