]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
1eb060fdc943c2b653b541e6c53acb5e988f4a5a
[quix0rs-gnu-social.git] / actions / showstream.php
1 <?php
2
3 define('SUBSCRIPTIONS_PER_ROW', 5);
4 define('SUBSCRIPTIONS', 80);
5
6 class ShowstreamAction extends StreamAction {
7
8         function handle($args) {
9                 
10                 parent::handle($args);
11
12                 $nickname = $this->arg('profile');
13                 $profile = Profile::staticGet('nickname', strtolower($nickname));
14         
15                 if (!$profile) {
16                         $this->no_such_user();
17                 } 
18                 
19                 $user = User::staticGet($profile->id);
20                 
21                 if (!$user) {
22                         // remote profile
23                         $this->no_such_user();
24                 }
25                 
26                 # Looks like we're good; show the header
27                 
28                 common_show_header($profile->nickname);
29                 
30                 if ($profile->id == current_user()->id) {
31                         $this->notice_form();
32                 }
33         
34                 $this->show_profile($profile);
35
36                 $this->show_last_notice($profile);
37                 
38                 $this->show_statistics($profile);
39                 
40                 $this->show_subscriptions($profile);
41                 
42                 $this->show_notices($profile);
43                 
44                 common_show_footer();
45         }
46         
47         function no_such_user() {
48                 common_user_error('No such user');
49         }
50         
51         function notice_form() {
52                 common_start_element('form', array('id' => 'newnotice', 'method' => 'POST',
53                                                                                    'action' => common_local_url('newnotice')));
54                 common_element('textarea', array('rows' => 4, 'cols' => 80, 'id' => 'content'));
55                 common_element('input', array('type' => 'submit'), 'Send');
56                 common_end_element('form');
57         }
58         
59         function show_profile($profile) {
60                 common_start_element('div', 'profile');
61                 common_element('span', 'nickname', $profile->nickname);
62                 if ($profile->fullname) {
63                         if ($profile->homepage) {
64                                 common_element('a', array('href' => $profile->homepage, 
65                                                                                   'class' => 'fullname'),
66                                                            $profile->fullname);
67                         } else {
68                                 common_element('span', 'fullname', $profile->fullname);
69                         }
70                 }
71                 if ($profile->location) {
72                         common_element('span', 'location', $profile->location);
73                 }
74                 if ($profile->bio) {
75                         common_element('div', 'bio', $profile->bio);
76                 }
77         }
78         
79         function show_subscriptions($profile) {
80
81                 # XXX: add a limit
82                 
83                 $subs = $profile->getLink('id', 'subscription', 'subscriber');
84
85                 common_start_element('div', 'subscriptions');
86                 
87                 $cnt = 0;
88                 
89                 while ($subs->fetch()) {
90                         $cnt++;
91                         if ($cnt % SUBSCRIPTIONS_PER_ROW == 1) {
92                                 common_start_element('div', 'row');
93                         }
94
95                         common_start_element('a', array('title' => $subs->fullname ||
96                                                                                                    $subs->nickname,
97                                                                                         'href' => $subs->profileurl,
98                                                                                         'class' => 'subscription'));
99                         common_element('img', array('src' => $subs->avatar,
100                                                                                 'class' => 'avatar'));
101                         common_end_element('a');
102                         
103                         if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
104                                 common_end_element('div');
105                         }
106                         
107                         if ($cnt == SUBSCRIPTIONS) {
108                                 break;
109                         }
110                 }
111
112                 common_element('a', array('href' => common_local_url('subscriptions', 
113                                                                                                                          array('profile' => $profile->nickname))
114                                                                   'class' => 'moresubscriptions'),
115                                            _t('All subscriptions'));
116                 
117                 common_end_element('div');
118         }
119
120         function show_statistics($profile) {
121
122                 // XXX: WORM cache this
123                 $subs = DB_DataObject::factory('subscription');
124                 $subs->subscriber = $profile->id;
125                 $subs_count = $subs->count();
126                 
127                 $subbed = DB_DataObject::factory('subscription');
128                 $subbed->subscribed = $profile->id;
129                 $subbed_count = $subbed->count();
130                 
131                 $notices = DB_DataObject::factory('notice');
132                 $notice->profile_id = $profile->id;
133                 $notice_count = $notice->count();
134                 
135                 # Other stats...?
136                 common_start_element('dl', 'statistics');
137                 common_element('dt', _t('Subscriptions'));
138                 common_element('dd', $subs_count);
139                 common_element('dt', _t('Subscribers'));
140                 common_element('dd', $subbed_count);
141                 common_element('dt', _t('Notices'));
142                 common_element('dd', $notice_count);
143                 common_end_element('dl');
144         }
145         
146         function show_notices($profile) {
147
148                 $notice = DB_DataObject::factory('notice');
149                 $notice->profile_id = $profile->id;
150                 
151                 $notice->orderBy('created DESC');
152                 
153                 $page = $this->arg('page') || 1;
154                 
155                 $notice->limit((($page-1)*NOTICES_PER_PAGE) + 1, NOTICES_PER_PAGE);
156                 
157                 $notice->find();
158
159                 common_start_element('div', 'notices');
160                 
161                 while ($notice->fetch()) {
162                         $this->show_notice($notice);
163                 }
164                 
165                 common_end_element('div');
166         }
167         
168         function show_last_notice($profile) {
169                 $notice = DB_DataObject::factory('notice');
170                 $notice->profile_id = $profile->id;
171                 $notice->orderBy('created DESC');
172                 $notice->limit(1, 1);
173                 $notice->find();
174                 
175                 while ($notice->fetch()) {
176                         # FIXME: URL, image, video, audio
177                         common_element('span', array('class' => 'content'), $notice->content);
178                         common_element('span', array('class' => 'date'),
179                                                    common_date_string($notice->created));
180                 }
181         }
182 }