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
49 const PLUGIN_VERSION = '2.0.0';
52 * Set up email_reminder table
57 * @return boolean hook value; true means continue processing, false means stop.
59 function onCheckSchema()
61 $schema = Schema::get();
62 $schema->ensureTable('email_reminder', Email_reminder::schemaDef());
67 * Register our queue handlers
69 * @param QueueManager $qm Current queue manager
71 * @return boolean hook value
73 function onEndInitializeQueueManager($qm)
75 $qm->connect('siterem', 'SiteConfirmReminderHandler');
76 $qm->connect('uregrem', 'UserConfirmRegReminderHandler');
77 $qm->connect('uinvrem', 'UserInviteReminderHandler');
82 function onEndDocFileForTitle($title, $paths, &$filename)
84 if (empty($filename)) {
85 $filename = dirname(__FILE__) . '/mail-src/' . $title;
93 * Send a reminder and record doing so
95 * @param string $type type of reminder
96 * @param mixed $object Confirm_address or Invitation object
97 * @param string $subject subjct of the email reminder
98 * @param int $day number of days
100 static function sendReminder($type, $object, $subject, $day)
102 // XXX: -1 is a for the special one-time reminder (maybe 30) would be
103 // better? Like >= 30 days?
105 $title = "{$type}-onetime";
107 $title = "{$type}-{$day}";
110 // Record the fact that we sent a reminder
111 if (self::sendReminderEmail($type, $object, $subject, $title)) {
113 Email_reminder::recordReminder($type, $object, $day);
116 "Sent {$type} reminder to {$object->address}.",
119 } catch (Exception $e) {
121 common_log(LOG_ERR, $e->getMessage(), __FILE__);
129 * Send a real live email reminder
131 * @todo This would probably be better as two or more sep functions
133 * @param string $type type of reminder
134 * @param mixed $object Confirm_address or Invitation object
135 * @param string $subject subjct of the email reminder
136 * @param string $title title of the email reminder
137 * @return boolean true if the email subsystem doesn't explode
139 static function sendReminderEmail($type, $object, $subject, $title = null) {
141 $sitename = common_config('site', 'name');
142 $recipients = array($object->address);
146 if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
147 $user = User::getKV($object->user_id);
149 $profile = $user->getProfile();
150 $inviter = $profile->getBestName();
151 $inviterUrl = $profile->profileurl;
155 $headers['From'] = mail_notify_from();
156 $headers['To'] = trim($object->address);
157 // TRANS: Subject for confirmation e-mail.
158 // TRANS: %s is the StatusNet sitename.
159 $headers['Subject'] = $subject;
160 $headers['Content-Type'] = 'text/html; charset=UTF-8';
162 $confirmUrl = common_local_url('register', array('code' => $object->code));
164 $template = DocFile::forTitle($title, DocFile::mailPaths());
166 $blankfillers = array('confirmurl' => $confirmUrl);
168 if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
169 $blankfillers['inviter'] = $inviter;
170 $blankfillers['inviterurl'] = $inviterUrl;
171 // @todo private invitation message?
174 $body = $template->toHTML($blankfillers);
176 return mail_send($recipients, $headers, $body);
181 * @param type $versions
184 function onPluginVersion(array &$versions)
187 'name' => 'EmailReminder',
188 'version' => self::PLUGIN_VERSION,
189 'author' => 'Zach Copley',
190 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/EmailReminder',
191 // TRANS: Plugin description.
192 'rawdescription' => _m('Send email reminders for various things.')