]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribed.php
considerable coding
[quix0rs-gnu-social.git] / actions / subscribed.php
1 <?php
2
3 class SubscribedAction extends Action {
4
5         # Who is subscribed to a given user?
6         
7         function handle($args) {
8                 parent::handle($args);
9                 $nickname = $this->arg('nickname');
10                 $profile = Profile::staticGet('nickname', $nickname);
11                 if (!$profile) {
12                         $this->no_such_user();
13                 }
14                 $user = User::staticGet($profile->id);
15                 if (!$user) {
16                         $this->no_such_user();
17                 }
18                 
19                 $page = $this->arg('page') || 1;
20                 $this->show_subscribed($profile, $page);
21         }
22
23         function show_subscribed($profile, $page) {
24
25                 $sub = DB_DataObject::factory('subscriptions');
26                 $sub->subscribed = $profile->id;
27                 
28                 # We ask for an extra one to know if we need to do another page
29                 
30                 $sub->limit((($page-1)*SUBSCRIPTIONS_PER_PAGE)+1, SUBSCRIPTIONS_PER_PAGE + 1);
31
32                 $subs_count = $subs->find();
33                 
34                 common_start_element('div', 'subscriptions');
35                 
36                 $idx = 0;
37                 
38                 while ($subs->fetch()) {
39                         $idx++;
40                         if ($idx % SUBSCRIPTIONS_PER_ROW == 1) {
41                                 common_start_element('div', 'row');
42                         }
43
44                         common_start_element('a', array('title' => $subs->fullname ||
45                                                                                                    $subs->nickname,
46                                                                                         'href' => $subs->profileurl,
47                                                                                         'class' => 'subscription'));
48                         common_element('img', array('src' => $subs->avatar,
49                                                                                 'class' => 'avatar'));
50                         common_end_element('a');
51                         
52                         if ($idx % SUBSCRIPTIONS_PER_ROW == 0) {
53                                 common_end_element('div');
54                         }
55                         
56                         if ($idx == SUBSCRIPTIONS_PER_PAGE) {
57                                 break;
58                         }
59                 }
60
61                 if ($page > 1) {
62                         common_element('a', array('href' => 
63                                                                           common_local_url('subscriptions',
64                                                                                                            array('nickname' => $profile->nickname,
65                                                                                                                          'page' => $page - 1)),
66                                                                           'class' => 'prev'),
67                                            _t('Previous'));
68                 }
69                 
70                 if ($subs_count > SUBSCRIPTIONS_PER_PAGE) {
71                         common_element('a', array('href' => 
72                                                                           common_local_url('subscriptions',
73                                                                                                            array('nickname' => $profile->nickname,
74                                                                                                                          'page' => $page + 1)),
75                                                                           'class' => 'next'),
76                                            _t('Next'));
77                 }
78                 common_end_element('div');
79         }
80 }