3 * StatusNet - the distributed open-source microblogging tool
5 * Handler for queue items of type 'usersum', sends an email summaries
6 * to a particular user.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @author Evan Prodromou <evan@status.net>
24 * @copyright 2010 StatusNet, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
26 * @link http://status.net/
29 if (!defined('STATUSNET')) {
34 * Handler for queue items of type 'usersum', sends an email summaries
35 * to a particular user.
39 * @author Evan Prodromou <evan@status.net>
40 * @copyright 2010 StatusNet, Inc.
41 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
42 * @link http://status.net/
45 class UserEmailSummaryHandler extends QueueHandler
47 // Maximum number of notices to include by default. This is probably too much.
49 const MAX_NOTICES = 200;
52 * Return transport keyword which identifies items this queue handler
53 * services; must be defined for all subclasses.
55 * Must be 8 characters or less to fit in the queue_item database.
56 * ex "email", "jabber", "sms", "irc", ...
67 * Send a summary email to the user
69 * @param mixed $object
70 * @return boolean true on success, false on failure
73 function handle($user_id)
75 // Skip if they've asked not to get summaries
77 $ess = Email_summary_status::staticGet('user_id', $user_id);
79 if (!empty($ess) && !$ess->send_summary) {
80 common_log(LOG_INFO, sprintf('Not sending email summary for user %s by request.', $user_id));
87 $since_id = $ess->last_summary_id;
90 $user = User::staticGet('id', $user_id);
93 common_log(LOG_INFO, sprintf('Not sending email summary for user %s; no such user.', $user_id));
97 if (empty($user->email)) {
98 common_log(LOG_INFO, sprintf('Not sending email summary for user %s; no email address.', $user_id));
102 $profile = $user->getProfile();
104 if (empty($profile)) {
105 common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no profile.', $user_id));
109 $notice = $user->ownFriendsTimeline(0, self::MAX_NOTICES, $since_id);
111 if (empty($notice) || $notice->N == 0) {
112 common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no notices.', $user_id));
116 // XXX: This is risky fingerpoken in der objektvars, but I didn't feel like
117 // figuring out a better way. -ESP
121 if ($notice instanceof ArrayWrapper) {
122 $new_top = $notice->_items[0]->id;
125 $out = new XMLStringer();
127 $out->raw('<style>'.$this->stylesheet().'</style>');
129 $out->raw(sprintf(_('<p>Recent updates from %1s for %2s:</p>'),
130 common_config('site', 'name'),
131 $profile->getBestName()));
133 $nl = new NoticeList($notice, $out);
135 // Outputs to the string
139 $out->raw(sprintf(_('<p><a href="%1s">change your email settings for %2s</a></p>'),
140 common_local_url('emailsettings'),
141 common_config('site', 'name')));
143 $body = $out->getString();
145 // FIXME: do something for people who don't like HTML email
147 mail_to_user($user, _('Updates from your network'), $body,
148 array('Content-Type' => 'text/html; charset=UTF-8'));
152 $ess = new Email_summary_status();
154 $ess->user_id = $user_id;
155 $ess->created = common_sql_now();
156 $ess->last_summary_id = $new_top;
157 $ess->modified = common_sql_now();
165 $ess->last_summary_id = $new_top;
166 $ess->modified = common_sql_now();
174 function stylesheet()
176 $ss = <<<END_OF_STYLESHEET
183 #notices_primary h2 {
188 list-style-type: none;
195 .notice, .profile, .application {
210 .notice .author .fn {
214 #core .vcard .photo {
220 #content .notice .author .photo {
227 #content .notice .entry-title {
228 margin: 2px 7px 0px 59px;
232 text-decoration:none;
235 text-decoration:underline;
238 .notice .entry-title {
240 word-wrap:break-word;
243 .notice .entry-title.ov {
251 #showstream .notice .entry-title, #showstream .notice div.entry-content {
255 #showstream #content .notice .author {
259 #showstream .notice {
263 #shownotice .vcard .photo {
267 #shownotice .notice .entry-title {
275 #shownotice .notice div.entry-content {
279 .notice p.entry-content {
283 .notice div.entry-content {
290 .entry-content .repeat {
294 .entry-content .repeat .photo {
308 .notice-options fieldset {
312 .notice-options legend {
316 .notice-options form, .notice-options a, .notice-options .repeated {
321 .notice-options input, .notice-options a, .notice-options .repeated {
322 text-indent: -9999px;
326 .notice-options input.submit, .notice-options a, .notice-options .repeated {
333 .notice-options input.submit, .notice-options a {
337 .notice-options input.submit:hover, .notice-options a:hover {
341 .notice .attachment {
346 .notice .attachment.more {
350 display:inline-block;
352 vertical-align:middle;
356 #attachments .attachment,
357 .notice .attachment.more {
361 .notice .attachment img {
368 #shownotice .notice .attachment img {
386 list-style-type:decimal;
392 #jOverlayContent #content,
393 #jOverlayContent #content_inner {
394 width: auto !important;
397 #jOverlayContent #content {
400 border: 1px solid #fff;
402 #jOverlayContent .entry-title {
406 #jOverlayContent button {
411 #jOverlayContent h1 {
418 #attachment_view img {
422 #attachment_view #oembed_info {
425 #attachment_view #oembed_info dt,
426 #attachment_view #oembed_info dd {
429 #attachment_view #oembed_info dt {
434 #attachment_view #oembed_info dt:after {
438 #content .notice .notice {
446 background-color:rgba(200, 200, 200, 0.050);
448 .notice .notice .notice {
449 background-color:rgba(200, 200, 200, 0.100);
451 .notice .notice .notice .notice {
452 background-color:rgba(200, 200, 200, 0.150);
454 .notice .notice .notice .notice .notice {
455 background-color:rgba(200, 200, 200, 0.300);