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 * Load related modules when needed
67 * @param string $cls Name of the class to be loaded
69 * @return boolean hook value; true means continue processing, false
72 function onAutoload($cls) {
73 $base = dirname(__FILE__);
74 $lower = strtolower($cls);
76 $files = array("$base/classes/$cls.php",
77 "$base/lib/$lower.php");
78 if (substr($lower, -6) == 'action') {
79 $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
81 foreach ($files as $file) {
82 if (file_exists($file)) {
91 * Register our queue handlers
93 * @param QueueManager $qm Current queue manager
95 * @return boolean hook value
97 function onEndInitializeQueueManager($qm)
99 $qm->connect('siterem', 'SiteConfirmReminderHandler');
100 $qm->connect('uregrem', 'UserConfirmRegReminderHandler');
101 $qm->connect('uinvrem', 'UserInviteReminderHandler');
106 function onEndDocFileForTitle($title, $paths, &$filename)
108 if (empty($filename)) {
109 $filename = dirname(__FILE__) . '/mail-src/' . $title;
117 * Send a reminder and record doing so
119 * @param string $type type of reminder
120 * @param mixed $object Confirm_address or Invitation object
121 * @param string $subject subjct of the email reminder
122 * @param int $day number of days
124 static function sendReminder($type, $object, $subject, $day)
126 // XXX: -1 is a for the special one-time reminder (maybe 30) would be
127 // better? Like >= 30 days?
129 $title = "{$type}-onetime";
131 $title = "{$type}-{$day}";
134 // Record the fact that we sent a reminder
135 if (self::sendReminderEmail($type, $object, $subject, $title)) {
137 Email_reminder::recordReminder($type, $object, $day);
140 "Sent {$type} reminder to {$object->address}.",
143 } catch (Exception $e) {
145 common_log(LOG_ERR, $e->getMessage(), __FILE__);
153 * Send a real live email reminder
155 * @todo This would probably be better as two or more sep functions
157 * @param string $type type of reminder
158 * @param mixed $object Confirm_address or Invitation object
159 * @param string $subject subjct of the email reminder
160 * @param string $title title of the email reminder
161 * @return boolean true if the email subsystem doesn't explode
163 static function sendReminderEmail($type, $object, $subject, $title = null) {
165 $sitename = common_config('site', 'name');
166 $recipients = array($object->address);
170 if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
171 $user = User::staticGet($object->user_id);
173 $profile = $user->getProfile();
174 $inviter = $profile->getBestName();
175 $inviterUrl = $profile->profileurl;
179 $headers['From'] = mail_notify_from();
180 $headers['To'] = trim($object->address);
181 // TRANS: Subject for confirmation e-mail.
182 // TRANS: %s is the StatusNet sitename.
183 $headers['Subject'] = $subject;
184 $headers['Content-Type'] = 'text/html; charset=UTF-8';
186 $confirmUrl = common_local_url('register', array('code' => $object->code));
188 $template = DocFile::forTitle($title, DocFile::mailPaths());
190 $blankfillers = array('confirmurl' => $confirmUrl);
192 if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
193 $blankfillers['inviter'] = $inviter;
194 $blankfillers['inviterurl'] = $inviterUrl;
195 // @todo private invitation message?
198 $body = $template->toHTML($blankfillers);
200 return mail_send($recipients, $headers, $body);
205 * @param type $versions
208 function onPluginVersion(&$versions)
211 'name' => 'EmailReminder',
212 'version' => STATUSNET_VERSION,
213 'author' => 'Zach Copley',
214 'homepage' => 'http://status.net/wiki/Plugin:EmailReminder',
215 // TRANS: Plugin description.
216 'rawdescription' => _m('Send email reminders for various things.')