]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscriptions.php
define undefined, order subs
[quix0rs-gnu-social.git] / actions / subscriptions.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', 10);
25 define('SUBSCRIPTIONS_PER_PAGE', 80);
26
27 class SubscriptionsAction extends Action {
28
29         function handle($args) {
30                 parent::handle($args);
31                 $nickname = $this->arg('nickname');
32                 $profile = Profile::staticGet('nickname', $nickname);
33                 if (!$profile) {
34                         $this->no_such_user();
35                 }
36                 $user = User::staticGet($profile->id);
37                 if (!$user) {
38                         $this->no_such_user();
39                 }
40                 $page = $this->arg('page') || 1;
41                 common_show_header($profile->nickname . ": " . _t('Subscriptions'));
42                 $this->show_subscriptions($profile, $page);
43                 common_show_footer();
44         }
45
46         function show_subscriptions($profile, $page) {
47
48                 $subs = DB_DataObject::factory('subscription');
49                 $subs->subscriber = $profile->id;
50
51                 $subs->orderBy('created DESC');
52
53                 # We ask for an extra one to know if we need to do another page
54
55                 $subs->limit((($page-1)*SUBSCRIPTIONS_PER_PAGE), SUBSCRIPTIONS_PER_PAGE + 1);
56
57                 $subs_count = $subs->find();
58
59                 common_element_start('div', 'subscriptions');
60
61                 $idx = 0;
62
63                 while ($subs->fetch()) {
64                         $idx++;
65                         if ($idx % SUBSCRIPTIONS_PER_ROW == 1) {
66                                 common_element_start('div', 'row');
67                         }
68
69                         common_element_start('a', array('title' => ($subs->fullname) ?
70                                                                                         $subs->fullname :
71                                                                                         $subs->nickname,
72                                                                                         'href' => $subs->profileurl,
73                                                                                         'class' => 'subscription'));
74                         $avatar = $subs->getAvatar(AVATAR_STREAM_SIZE);
75                         common_element('img', 
76                                                    array('src' => 
77                                                                  (($avatar) ? $avatar->url : 
78                                                                   common_default_avatar(AVATAR_STREAM_SIZE)),
79                                                                  'width' => AVATAR_STREAM_SIZE,
80                                                                  'height' => AVATAR_STREAM_SIZE,
81                                                                  'class' => 'avatar stream',
82                                                                  'alt' => ($subs->fullname) ?
83                                                                  $subs->fullname :
84                                                                  $subs->nickname));
85                         common_element_end('a');
86
87                         # XXX: subscribe form here
88
89                         if ($idx % SUBSCRIPTIONS_PER_ROW == 0) {
90                                 common_element_end('div');
91                         }
92
93                         if ($idx == SUBSCRIPTIONS_PER_PAGE) {
94                                 break;
95                         }
96                 }
97
98                 if ($page > 1) {
99                         common_element('a', array('href' =>
100                                                                           common_local_url('subscriptions',
101                                                                                                            array('nickname' => $profile->nickname,
102                                                                                                                          'page' => $page - 1)),
103                                                                           'class' => 'prev'),
104                                            _t('Previous'));
105                 }
106
107                 if ($subs_count > SUBSCRIPTIONS_PER_PAGE) {
108                         common_element('a', array('href' =>
109                                                                           common_local_url('subscriptions',
110                                                                                                            array('nickname' => $profile->nickname,
111                                                                                                                          'page' => $page + 1)),
112                                                                           'class' => 'next'),
113                                            _t('Next'));
114                 }
115                 common_element_end('div');
116         }
117 }