3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 # XXX: make distinct from similar definitions in showstream.php
24 define('SUBSCRIPTIONS_PER_ROW', 8);
25 define('SUBSCRIPTIONS_PER_PAGE', 80);
27 class SubscriptionsAction extends Action {
29 function handle($args) {
30 parent::handle($args);
31 $nickname = $this->arg('nickname');
32 $profile = Profile::staticGet('nickname', $nickname);
34 $this->no_such_user();
36 $user = User::staticGet($profile->id);
38 $this->no_such_user();
40 $page = $this->arg('page') || 1;
41 common_show_header($profile->nickname . ": " . _t('Subscriptions'),
43 array($this, 'show_top'));
44 $this->show_subscriptions($profile, $page);
48 function show_top($profile) {
49 $user = common_current_user();
50 common_element('p', 'instructions',
51 _t('These are the people whose notices ') .
52 (($user && ($user->id == $profile->id)) ? _t('you listen to.') : ($profile->nickname . _t(' listens to.'))));
55 function show_subscriptions($profile, $page) {
57 $subs = DB_DataObject::factory('subscription');
58 $subs->subscriber = $profile->id;
60 $subs->orderBy('created DESC');
62 # We ask for an extra one to know if we need to do another page
64 $subs->limit((($page-1)*SUBSCRIPTIONS_PER_PAGE), SUBSCRIPTIONS_PER_PAGE + 1);
66 $subs_count = $subs->find();
68 common_element_start('div', 'subscriptions');
72 while ($subs->fetch()) {
76 $other = Profile::staticGet($subs->subscribed);
78 common_element_start('a', array('title' => ($other->fullname) ?
81 'href' => $other->profileurl,
82 'class' => 'subscription'));
83 $avatar = $other->getAvatar(AVATAR_STREAM_SIZE);
86 (($avatar) ? $avatar->url :
87 common_default_avatar(AVATAR_STREAM_SIZE)),
88 'width' => AVATAR_STREAM_SIZE,
89 'height' => AVATAR_STREAM_SIZE,
90 'class' => 'avatar stream',
91 'alt' => ($other->fullname) ?
94 common_element_end('a');
96 # XXX: subscribe form here
98 if ($idx == SUBSCRIPTIONS_PER_PAGE) {
103 common_element_end('div');
105 common_pagination($page > 1, $subs_count > SUBSCRIPTIONS_PER_PAGE,
106 $page, 'subscriptions', array('nickname' => $profile->nickname));