123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- class EmailReminderPlugin extends Plugin
- {
-
- function onCheckSchema()
- {
- $schema = Schema::get();
- $schema->ensureTable('email_reminder', Email_reminder::schemaDef());
- return true;
- }
-
- function onEndInitializeQueueManager($qm)
- {
- $qm->connect('siterem', 'SiteConfirmReminderHandler');
- $qm->connect('uregrem', 'UserConfirmRegReminderHandler');
- $qm->connect('uinvrem', 'UserInviteReminderHandler');
- return true;
- }
- function onEndDocFileForTitle($title, $paths, &$filename)
- {
- if (empty($filename)) {
- $filename = dirname(__FILE__) . '/mail-src/' . $title;
- return false;
- }
- return true;
- }
-
- static function sendReminder($type, $object, $subject, $day)
- {
-
-
- if ($day == -1) {
- $title = "{$type}-onetime";
- } else {
- $title = "{$type}-{$day}";
- }
-
- if (self::sendReminderEmail($type, $object, $subject, $title)) {
- try {
- Email_reminder::recordReminder($type, $object, $day);
- common_log(
- LOG_INFO,
- "Sent {$type} reminder to {$object->address}.",
- __FILE__
- );
- } catch (Exception $e) {
-
- common_log(LOG_ERR, $e->getMessage(), __FILE__);
- }
- }
- return true;
- }
-
- static function sendReminderEmail($type, $object, $subject, $title = null) {
- $sitename = common_config('site', 'name');
- $recipients = array($object->address);
- $inviter = null;
- $inviterurl = null;
- if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
- $user = User::getKV($object->user_id);
- if (!empty($user)) {
- $profile = $user->getProfile();
- $inviter = $profile->getBestName();
- $inviterUrl = $profile->profileurl;
- }
- }
- $headers['From'] = mail_notify_from();
- $headers['To'] = trim($object->address);
-
-
- $headers['Subject'] = $subject;
- $headers['Content-Type'] = 'text/html; charset=UTF-8';
- $confirmUrl = common_local_url('register', array('code' => $object->code));
- $template = DocFile::forTitle($title, DocFile::mailPaths());
- $blankfillers = array('confirmurl' => $confirmUrl);
- if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
- $blankfillers['inviter'] = $inviter;
- $blankfillers['inviterurl'] = $inviterUrl;
-
- }
- $body = $template->toHTML($blankfillers);
- return mail_send($recipients, $headers, $body);
- }
-
- function onPluginVersion(&$versions)
- {
- $versions[] = array(
- 'name' => 'EmailReminder',
- 'version' => GNUSOCIAL_VERSION,
- 'author' => 'Zach Copley',
- 'homepage' => 'http://status.net/wiki/Plugin:EmailReminder',
-
- 'rawdescription' => _m('Send email reminders for various things.')
- );
- return true;
- }
- }
|