3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010 StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Class for activity streams
23 * Includes faves, notices, and subscriptions.
25 * We extend atomusernoticefeed since it does some nice setup for us.
29 class UserActivityStream extends AtomUserNoticeFeed
31 function __construct($user, $indent = true)
33 parent::__construct($user, null, $indent);
35 $subscriptions = $this->getSubscriptions();
36 $subscribers = $this->getSubscribers();
37 $groups = $this->getGroups();
38 $faves = $this->getFaves();
39 $notices = $this->getNotices();
41 $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices);
43 // Sort by create date
45 usort($objs, 'UserActivityStream::compareObject');
47 foreach ($objs as $obj) {
48 $act = $obj->asActivity();
49 // Only show the author sub-element if it's different from default user
50 $str = $act->asString(false, ($act->actor->id != $this->user->uri));
51 $this->addEntryRaw($str);
55 function compareObject($a, $b)
57 $ac = strtotime((empty($a->created)) ? $a->modified : $a->created);
58 $bc = strtotime((empty($b->created)) ? $b->modified : $b->created);
60 return (($ac == $bc) ? 0 : (($ac < $bc) ? 1 : -1));
63 function getSubscriptions()
67 $sub = new Subscription();
69 $sub->subscriber = $this->user->id;
72 while ($sub->fetch()) {
73 if ($sub->subscribed != $this->user->id) {
74 $subs[] = clone($sub);
82 function getSubscribers()
86 $sub = new Subscription();
88 $sub->subscribed = $this->user->id;
91 while ($sub->fetch()) {
92 if ($sub->subscriber != $this->user->id) {
93 $subs[] = clone($sub);
107 $fave->user_id = $this->user->id;
110 while ($fave->fetch()) {
111 $faves[] = clone($fave);
118 function getNotices()
122 $notice = new Notice();
124 $notice->profile_id = $this->user->id;
126 if ($notice->find()) {
127 while ($notice->fetch()) {
128 $notices[] = clone($notice);
139 $gm = new Group_member();
141 $gm->profile_id = $this->user->id;
144 while ($gm->fetch()) {
145 $groups[] = clone($gm);