userconfirmregreminderhandler.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. /**
  32. * Handler for queue items of type 'uregrem'
  33. *
  34. * @category Email
  35. * @package StatusNet
  36. * @author Zach Copley <zach@status.net>
  37. * @copyright 2011 StatusNet, Inc.
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  39. * @link http://status.net/
  40. */
  41. class UserConfirmRegReminderHandler extends UserReminderHandler {
  42. const REGISTER_REMINDER = 'register';
  43. /**
  44. * Return transport keyword which identifies items this queue handler
  45. * services; must be defined for all subclasses.
  46. *
  47. * Must be 8 characters or less to fit in the queue_item database.
  48. * ex "email", "jabber", "sms", "irc", ...
  49. *
  50. * @return string
  51. */
  52. function transport() {
  53. return 'uregrem';
  54. }
  55. /**
  56. * Send an email registration confirmation reminder until the user
  57. * confirms her registration. We'll send a reminder after one day,
  58. * three days, and a full week.
  59. *
  60. * @todo abstract this bit further
  61. *
  62. * @param array $regitem confirmation address and any special options
  63. * @return boolean success value
  64. */
  65. function sendNextReminder($regitem)
  66. {
  67. list($confirm, $opts) = $regitem;
  68. $regDate = strtotime($confirm->modified); // Seems like my best bet
  69. $now = strtotime('now');
  70. // Days since registration
  71. $days = ($now - $regDate) / 86499; // 60*60*24 = 86499
  72. // $days = ($now - $regDate) / 120; // Two mins, good for testing
  73. if ($days > 7 && isset($opts['onetime'])) {
  74. // Don't send the reminder if we're past the normal reminder window and
  75. // we've already pestered her at all before
  76. if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm)) {
  77. common_log(LOG_INFO, "Sending one-time registration confirmation reminder to {$confirm->address}", __FILE__);
  78. $subject = _m("Reminder - please confirm your registration!");
  79. return EmailReminderPlugin::sendReminder(
  80. self::REGISTER_REMINDER,
  81. $confirm,
  82. $subject,
  83. -1 // special one-time indicator
  84. );
  85. }
  86. }
  87. // Welcome to one of the ugliest switch statement I've ever written
  88. switch($days) {
  89. case ($days > 1 && $days < 2):
  90. if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 1)) {
  91. common_log(LOG_INFO, "Sending one day registration confirmation reminder to {$confirm->address}", __FILE__);
  92. // TRANS: Subject for reminder e-mail.
  93. $subject = _m('Reminder - please confirm your registration!');
  94. return EmailReminderPlugin::sendReminder(
  95. self::REGISTER_REMINDER,
  96. $confirm,
  97. $subject,
  98. 1
  99. );
  100. } else {
  101. return true;
  102. }
  103. break;
  104. case ($days > 3 && $days < 4):
  105. if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 3)) {
  106. common_log(LOG_INFO, "Sending three day registration confirmation reminder to {$confirm->address}", __FILE__);
  107. // TRANS: Subject for reminder e-mail.
  108. $subject = _m('Second reminder - please confirm your registration!');
  109. return EmailReminderPlugin::sendReminder(
  110. self::REGISTER_REMINDER,
  111. $confirm,
  112. $subject,
  113. 3
  114. );
  115. } else {
  116. return true;
  117. }
  118. break;
  119. case ($days > 7 && $days < 8):
  120. if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 7)) {
  121. common_log(LOG_INFO, "Sending one week registration confirmation reminder to {$confirm->address}", __FILE__);
  122. // TRANS: Subject for reminder e-mail.
  123. $subject = _m('Final reminder - please confirm your registration!');
  124. return EmailReminderPlugin::sendReminder(
  125. self::REGISTER_REMINDER,
  126. $confirm,
  127. $subject,
  128. 7
  129. );
  130. } else {
  131. return true;
  132. }
  133. break;
  134. default:
  135. common_log(LOG_INFO, "No need to send registration reminder to {$confirm->address}.", __FILE__);
  136. break;
  137. }
  138. return true;
  139. }
  140. }