]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailSummary/EmailSummaryPlugin.php
fixed parser error (opps)
[quix0rs-gnu-social.git] / plugins / EmailSummary / EmailSummaryPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Sends an email summary of the inbox to users in the network
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Sample
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2010 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * Plugin for sending email summaries to users
37  *
38  * @category  Email
39  * @package   StatusNet
40  * @author    Brion Vibber <brionv@status.net>
41  * @author    Evan Prodromou <evan@status.net>
42  * @copyright 2010 StatusNet, Inc.
43  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
44  * @link      http://status.net/
45  */
46 class EmailSummaryPlugin extends Plugin
47 {
48     const PLUGIN_VERSION = '2.0.0';
49     /**
50      * Database schema setup
51      *
52      * @return boolean hook value
53      */
54     function onCheckSchema()
55     {
56         $schema = Schema::get();
57
58         // For storing user-submitted flags on profiles
59         $schema->ensureTable('email_summary_status', Email_summary_status::schemaDef());
60         return true;
61     }
62
63     /**
64      * Version info for this plugin
65      *
66      * @param array &$versions array of version data
67      *
68      * @return boolean hook value; true means continue processing, false means stop.
69      */
70     function onPluginVersion(array &$versions)
71     {
72         $versions[] = array('name' => 'EmailSummary',
73                             'version' => self::PLUGIN_VERSION,
74                             'author' => 'Evan Prodromou',
75                             'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/EmailSummary',
76                             'rawdescription' =>
77                             // TRANS: Plugin description.
78                             _m('Send an email summary of the inbox to users.'));
79         return true;
80     }
81
82     /**
83      * Register our queue handlers
84      *
85      * @param QueueManager $qm Current queue manager
86      *
87      * @return boolean hook value
88      */
89     function onEndInitializeQueueManager($qm)
90     {
91         $qm->connect('sitesum', 'SiteEmailSummaryHandler');
92         $qm->connect('usersum', 'UserEmailSummaryHandler');
93         return true;
94     }
95
96     /**
97      * Add a checkbox to turn off email summaries
98      *
99      * @param Action $action Action being executed (emailsettings)
100      * @param Profile $scoped Profile for whom settings are configured (current user)
101      *
102      * @return boolean hook value
103      */
104     public function onEndEmailFormData(Action $action, Profile $scoped)
105     {
106         $action->elementStart('li');
107         $action->checkbox('emailsummary',
108                           // TRANS: Checkbox label in e-mail preferences form.
109                           _m('Send me a periodic summary of updates from my network'),
110                           Email_summary_status::getSendSummary($scoped->id));
111         $action->elementEnd('li');
112         return true;
113     }
114
115     /**
116      * Add a checkbox to turn off email summaries
117      *
118      * @param Action $action Action being executed (emailsettings)
119      * @param Profile $scoped Profile for whom settings are configured (current user)
120      *
121      * @return boolean hook value
122      */
123     public function onEndEmailSaveForm(Action $action, Profile $scoped)
124     {
125         $sendSummary = $action->boolean('emailsummary');
126
127         $ess = Email_summary_status::getKV('user_id', $scoped->id);
128
129         if (empty($ess)) {
130
131             $ess = new Email_summary_status();
132
133             $ess->user_id      = $scoped->id;
134             $ess->send_summary = $sendSummary;
135             $ess->created      = common_sql_now();
136             $ess->modified     = common_sql_now();
137
138             $ess->insert();
139
140         } else {
141
142             $orig = clone($ess);
143
144             $ess->send_summary = $sendSummary;
145             $ess->modified     = common_sql_now();
146
147             $ess->update($orig);
148         }
149
150         return true;
151     }
152 }