]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribed.php
fix copy-and-paste error
[quix0rs-gnu-social.git] / actions / subscribed.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, 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 if (!defined('LACONICA')) { exit(1); }
21
22 # XXX: make distinct from similar definitions in showstream.php
23
24 define('SUBSCRIPTIONS_PER_ROW', 8);
25 define('SUBSCRIPTIONS_PER_PAGE', 80);
26
27 class SubscribedAction extends Action {
28
29         # Who is subscribed to a given user?
30
31         function handle($args) {
32                 parent::handle($args);
33                 $nickname = $this->arg('nickname');
34                 $profile = Profile::staticGet('nickname', $nickname);
35                 if (!$profile) {
36                         $this->no_such_user();
37                 }
38                 $user = User::staticGet($profile->id);
39                 if (!$user) {
40                         $this->no_such_user();
41                 }
42
43                 $page = $this->arg('page') || 1;
44                 common_show_header($profile->nickname . ": " . _t('Subscribers'),
45                                                    NULL, $profile,
46                                                    array($this, 'show_top'));
47                 $this->show_subscribed($profile, $page);
48                 common_show_footer();
49         }
50
51         function show_top($profile) {
52                 $user = common_current_user();
53                 common_element('p', 'instructions',
54                                            _t('These are the people who listen to ') .
55                                            (($user && ($user->id == $profile->id)) ? _t('your notices.') : ($profile->nickname . _t('\'s notices.'))));
56         }
57
58         function show_subscribed($profile, $page) {
59                 global $config;
60                 
61                 $subs = DB_DataObject::factory('subscription');
62                 $subs->subscribed = $profile->id;
63
64                 $subs->orderBy('created DESC');
65
66                 # We ask for an extra one to know if we need to do another page
67
68                 $subs->limit((($page-1)*SUBSCRIPTIONS_PER_PAGE), SUBSCRIPTIONS_PER_PAGE + 1);
69
70                 $subs_count = $subs->find();
71
72                 common_element_start('div', 'subscriptions');
73
74                 $idx = 0;
75
76                 while ($subs->fetch()) {
77                         $idx++;
78                         if ($idx % SUBSCRIPTIONS_PER_ROW == 1) {
79                                 common_element_start('div', 'row');
80                         }
81
82                         $other = Profile::staticGet($subs->subscriber);
83                         
84                         common_element_start('a', array('title' => ($other->fullname) ?
85                                                                                         $other->fullname :
86                                                                                         $other->nickname,
87                                                                                         'href' => $other->profileurl,
88                                                                                         'class' => 'subscription'));
89                         $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
90                         common_element('img', array('src' => (($avatar) ? $avatar->url : common_default_avatar(AVATAR_STREAM_SIZE)),
91                                                                                 'width' => AVATAR_STREAM_SIZE,
92                                                                                 'height' => AVATAR_STREAM_SIZE,
93                                                                                 'class' => 'avatar stream',
94                                                                                 'alt' => ($other->fullname) ?
95                                                                                         $other->fullname :
96                                                                                         $other->nickname));
97                         common_element_end('a');
98
99                         # XXX: subscribe form here
100
101                         if ($idx % SUBSCRIPTIONS_PER_ROW == 0) {
102                                 common_element_end('div');
103                         }
104
105                         if ($idx == SUBSCRIPTIONS_PER_PAGE) {
106                                 break;
107                         }
108                 }
109
110                 if ($page > 1) {
111                         common_element('a', array('href' =>
112                                                                           common_local_url('subscriptions',
113                                                                                                            array('nickname' => $profile->nickname,
114                                                                                                                          'page' => $page - 1)),
115                                                                           'class' => 'prev'),
116                                            _t('Previous'));
117                 }
118
119                 if ($subs_count > SUBSCRIPTIONS_PER_PAGE) {
120                         common_element('a', array('href' =>
121                                                                           common_local_url('subscriptions',
122                                                                                                            array('nickname' => $profile->nickname,
123                                                                                                                          'page' => $page + 1)),
124                                                                           'class' => 'next'),
125                                            _t('Next'));
126                 }
127                 common_element_end('div');
128         }
129 }