]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/useractivitystream.php
Merge remote branch 'gitorious/1.0.x' into 1.0.x
[quix0rs-gnu-social.git] / lib / useractivitystream.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010 StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 /**
21  * Class for activity streams
22  *
23  * Includes faves, notices, and subscriptions.
24  *
25  * We extend atomusernoticefeed since it does some nice setup for us.
26  *
27  */
28
29 class UserActivityStream extends AtomUserNoticeFeed
30 {
31     function __construct($user, $indent = true)
32     {
33         parent::__construct($user, null, $indent);
34
35         $subscriptions = $this->getSubscriptions();
36         $subscribers   = $this->getSubscribers();
37         $groups        = $this->getGroups();
38         $faves         = $this->getFaves();
39         $notices       = $this->getNotices();
40
41         $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices);
42
43         // Sort by create date
44
45         usort($objs, 'UserActivityStream::compareObject');
46
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);
52         }
53     }
54
55     function compareObject($a, $b)
56     {
57         $ac = strtotime((empty($a->created)) ? $a->modified : $a->created);
58         $bc = strtotime((empty($b->created)) ? $b->modified : $b->created);
59
60         return (($ac == $bc) ? 0 : (($ac < $bc) ? 1 : -1));
61     }
62
63     function getSubscriptions()
64     {
65         $subs = array();
66
67         $sub = new Subscription();
68
69         $sub->subscriber = $this->user->id;
70
71         if ($sub->find()) {
72             while ($sub->fetch()) {
73                 if ($sub->subscribed != $this->user->id) {
74                     $subs[] = clone($sub);
75                 }
76             }
77         }
78
79         return $subs;
80     }
81
82     function getSubscribers()
83     {
84         $subs = array();
85
86         $sub = new Subscription();
87
88         $sub->subscribed = $this->user->id;
89
90         if ($sub->find()) {
91             while ($sub->fetch()) {
92                 if ($sub->subscriber != $this->user->id) {
93                     $subs[] = clone($sub);
94                 }
95             }
96         }
97
98         return $subs;
99     }
100
101     function getFaves()
102     {
103         $faves = array();
104
105         $fave = new Fave();
106
107         $fave->user_id = $this->user->id;
108
109         if ($fave->find()) {
110             while ($fave->fetch()) {
111                 $faves[] = clone($fave);
112             }
113         }
114
115         return $faves;
116     }
117
118     function getNotices()
119     {
120         $notices = array();
121
122         $notice = new Notice();
123
124         $notice->profile_id = $this->user->id;
125
126         if ($notice->find()) {
127             while ($notice->fetch()) {
128                 $notices[] = clone($notice);
129             }
130         }
131
132         return $notices;
133     }
134
135     function getGroups()
136     {
137         $groups = array();
138
139         $gm = new Group_member();
140
141         $gm->profile_id = $this->user->id;
142
143         if ($gm->find()) {
144             while ($gm->fetch()) {
145                 $groups[] = clone($gm);
146             }
147         }
148
149         return $groups;
150     }
151 }