]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/useractivitystream.php
* fix some i18n and L10n issues
[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 class UserActivityStream extends AtomUserNoticeFeed
29 {
30     public $activities = array();
31
32     function __construct($user, $indent = true)
33     {
34         parent::__construct($user, null, $indent);
35
36         $subscriptions = $this->getSubscriptions();
37         $subscribers   = $this->getSubscribers();
38         $groups        = $this->getGroups();
39         $faves         = $this->getFaves();
40         $notices       = $this->getNotices();
41
42         $objs = array_merge($subscriptions, $subscribers, $groups, $faves, $notices);
43
44         // Sort by create date
45
46         usort($objs, 'UserActivityStream::compareObject');
47
48         foreach ($objs as $obj) {
49             $this->activities[] = $obj->asActivity();
50         }
51     }
52
53     function renderEntries()
54     {
55         foreach ($this->activities as $act) {
56             // Only show the author sub-element if it's different from default user
57             $act->outputTo($this, false, ($act->actor->id != $this->user->uri));
58         }
59     }
60
61     function compareObject($a, $b)
62     {
63         $ac = strtotime((empty($a->created)) ? $a->modified : $a->created);
64         $bc = strtotime((empty($b->created)) ? $b->modified : $b->created);
65
66         return (($ac == $bc) ? 0 : (($ac < $bc) ? 1 : -1));
67     }
68
69     function getSubscriptions()
70     {
71         $subs = array();
72
73         $sub = new Subscription();
74
75         $sub->subscriber = $this->user->id;
76
77         if ($sub->find()) {
78             while ($sub->fetch()) {
79                 if ($sub->subscribed != $this->user->id) {
80                     $subs[] = clone($sub);
81                 }
82             }
83         }
84
85         return $subs;
86     }
87
88     function getSubscribers()
89     {
90         $subs = array();
91
92         $sub = new Subscription();
93
94         $sub->subscribed = $this->user->id;
95
96         if ($sub->find()) {
97             while ($sub->fetch()) {
98                 if ($sub->subscriber != $this->user->id) {
99                     $subs[] = clone($sub);
100                 }
101             }
102         }
103
104         return $subs;
105     }
106
107     function getFaves()
108     {
109         $faves = array();
110
111         $fave = new Fave();
112
113         $fave->user_id = $this->user->id;
114
115         if ($fave->find()) {
116             while ($fave->fetch()) {
117                 $faves[] = clone($fave);
118             }
119         }
120
121         return $faves;
122     }
123
124     function getNotices()
125     {
126         $notices = array();
127
128         $notice = new Notice();
129
130         $notice->profile_id = $this->user->id;
131
132         if ($notice->find()) {
133             while ($notice->fetch()) {
134                 $notices[] = clone($notice);
135             }
136         }
137
138         return $notices;
139     }
140
141     function getGroups()
142     {
143         $groups = array();
144
145         $gm = new Group_member();
146
147         $gm->profile_id = $this->user->id;
148
149         if ($gm->find()) {
150             while ($gm->fetch()) {
151                 $groups[] = clone($gm);
152             }
153         }
154
155         return $groups;
156     }
157 }