userinvitereminderhandler.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. * Handler for queue items of type 'uinvrem' (user invite reminder)
  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 UserInviteReminderHandler extends UserReminderHandler {
  42. const INVITE_REMINDER = 'invite';
  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 'uinvrem';
  54. }
  55. /**
  56. * Send an invitation reminder. We'll send one after one day, and then
  57. * one after three days.
  58. *
  59. * @todo Abstract this stuff further
  60. *
  61. * @param array $invitem Invitation obj and any special options
  62. * @return boolean success value
  63. */
  64. function sendNextReminder($invitem)
  65. {
  66. list($invitation, $opts) = $invitem;
  67. $invDate = strtotime($invitation->created);
  68. $now = strtotime('now');
  69. // Days since first invitation was sent
  70. $days = ($now - $invDate) / 86499; // 60*60*24 = 86499
  71. // $days = ($now - $regDate) / 120; // Two mins, good for testing
  72. $siteName = common_config('site', 'name');
  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::INVITE_REMINDER, $invitation)) {
  77. common_log(LOG_INFO, "Sending one-time invitation reminder to {$invitation->address}", __FILE__);
  78. $subject = _m("Reminder - you have been invited to join {$siteName}!");
  79. return EmailReminderPlugin::sendReminder(
  80. self::INVITE_REMINDER,
  81. $invitation,
  82. $subject,
  83. -1 // special one-time indicator
  84. );
  85. }
  86. }
  87. switch($days) {
  88. case ($days > 1 && $days < 2):
  89. if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 1)) {
  90. common_log(LOG_INFO, "Sending one day invitation reminder to {$invitation->address}", __FILE__);
  91. // TRANS: Subject for reminder e-mail. %s is the StatusNet sitename.
  92. $subject = sprintf(_m('Reminder - You have been invited to join %s!'),$siteName);
  93. return EmailReminderPlugin::sendReminder(
  94. self::INVITE_REMINDER,
  95. $invitation,
  96. $subject,
  97. 1);
  98. } else {
  99. return true;
  100. }
  101. break;
  102. case ($days > 3 && $days < 4):
  103. if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 3)) {
  104. common_log(LOG_INFO, "Sending three day invitation reminder to {$invitation->address}", __FILE__);
  105. // TRANS: Subject for reminder e-mail. %s is the StatusNet sitename.
  106. $subject = sprintf(_m('Final reminder - you have been invited to join %s!'),$siteName);
  107. return EmailReminderPlugin::sendReminder(
  108. self::INVITE_REMINDER,
  109. $invitation,
  110. $subject,
  111. 3
  112. );
  113. } else {
  114. return true;
  115. }
  116. break;
  117. default:
  118. common_log(LOG_INFO, "No need to send invitation reminder to {$invitation->address}.", __FILE__);
  119. break;
  120. }
  121. return true;
  122. }
  123. }