3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Plugin for sending email reminders about various things
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Zach Copley <zach@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Email reminder plugin
42 * @author Zach Copley <zach@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class EmailReminderPlugin extends Plugin
50 * Set up email_reminder table
55 * @return boolean hook value; true means continue processing, false means stop.
57 function onCheckSchema()
59 $schema = Schema::get();
60 $schema->ensureTable('email_reminder', Email_reminder::schemaDef());
65 * Register our queue handlers
67 * @param QueueManager $qm Current queue manager
69 * @return boolean hook value
71 function onEndInitializeQueueManager($qm)
73 $qm->connect('siterem', 'SiteConfirmReminderHandler');
74 $qm->connect('uregrem', 'UserConfirmRegReminderHandler');
75 $qm->connect('uinvrem', 'UserInviteReminderHandler');
80 function onEndDocFileForTitle($title, $paths, &$filename)
82 if (empty($filename)) {
83 $filename = dirname(__FILE__) . '/mail-src/' . $title;
91 * Send a reminder and record doing so
93 * @param string $type type of reminder
94 * @param mixed $object Confirm_address or Invitation object
95 * @param string $subject subjct of the email reminder
96 * @param int $day number of days
98 static function sendReminder($type, $object, $subject, $day)
100 // XXX: -1 is a for the special one-time reminder (maybe 30) would be
101 // better? Like >= 30 days?
103 $title = "{$type}-onetime";
105 $title = "{$type}-{$day}";
108 // Record the fact that we sent a reminder
109 if (self::sendReminderEmail($type, $object, $subject, $title)) {
111 Email_reminder::recordReminder($type, $object, $day);
114 "Sent {$type} reminder to {$object->address}.",
117 } catch (Exception $e) {
119 common_log(LOG_ERR, $e->getMessage(), __FILE__);
127 * Send a real live email reminder
129 * @todo This would probably be better as two or more sep functions
131 * @param string $type type of reminder
132 * @param mixed $object Confirm_address or Invitation object
133 * @param string $subject subjct of the email reminder
134 * @param string $title title of the email reminder
135 * @return boolean true if the email subsystem doesn't explode
137 static function sendReminderEmail($type, $object, $subject, $title = null) {
139 $sitename = common_config('site', 'name');
140 $recipients = array($object->address);
144 if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
145 $user = User::getKV($object->user_id);
147 $profile = $user->getProfile();
148 $inviter = $profile->getBestName();
149 $inviterUrl = $profile->profileurl;
153 $headers['From'] = mail_notify_from();
154 $headers['To'] = trim($object->address);
155 // TRANS: Subject for confirmation e-mail.
156 // TRANS: %s is the StatusNet sitename.
157 $headers['Subject'] = $subject;
158 $headers['Content-Type'] = 'text/html; charset=UTF-8';
160 $confirmUrl = common_local_url('register', array('code' => $object->code));
162 $template = DocFile::forTitle($title, DocFile::mailPaths());
164 $blankfillers = array('confirmurl' => $confirmUrl);
166 if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
167 $blankfillers['inviter'] = $inviter;
168 $blankfillers['inviterurl'] = $inviterUrl;
169 // @todo private invitation message?
172 $body = $template->toHTML($blankfillers);
174 return mail_send($recipients, $headers, $body);
179 * @param type $versions
182 function onPluginVersion(array &$versions)
185 'name' => 'EmailReminder',
186 'version' => GNUSOCIAL_VERSION,
187 'author' => 'Zach Copley',
188 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/EmailReminder',
189 // TRANS: Plugin description.
190 'rawdescription' => _m('Send email reminders for various things.')