]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscriptions.php
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / actions / subscriptions.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of a user's subscriptions
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Social
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * A list of the user's subscriptions
37  *
38  * @category Social
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42  * @link     http://status.net/
43  */
44
45 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
46
47 class SubscriptionsAction extends GalleryAction
48 {
49     function title()
50     {
51         if ($this->page == 1) {
52             return sprintf(_('%s subscriptions'), $this->user->nickname);
53         } else {
54             return sprintf(_('%s subscriptions, page %d'),
55                            $this->user->nickname,
56                            $this->page);
57         }
58     }
59
60     function showPageNotice()
61     {
62         $user =& common_current_user();
63         if ($user && ($user->id == $this->profile->id)) {
64             $this->element('p', null,
65                            _('These are the people whose notices '.
66                              'you listen to.'));
67         } else {
68             $this->element('p', null,
69                            sprintf(_('These are the people whose '.
70                                      'notices %s listens to.'),
71                                    $this->profile->nickname));
72         }
73     }
74
75     function getAllTags()
76     {
77         return $this->getTags('subscribed', 'subscriber');
78     }
79
80     function showContent()
81     {
82         parent::showContent();
83
84         $offset = ($this->page-1) * PROFILES_PER_PAGE;
85         $limit =  PROFILES_PER_PAGE + 1;
86
87         $cnt = 0;
88
89         if ($this->tag) {
90             $subscriptions = $this->user->getTaggedSubscriptions($this->tag, $offset, $limit);
91         } else {
92             $subscriptions = $this->user->getSubscriptions($offset, $limit);
93         }
94
95         if ($subscriptions) {
96             $subscriptions_list = new SubscriptionsList($subscriptions, $this->user, $this);
97             $cnt = $subscriptions_list->show();
98             if (0 == $cnt) {
99                 $this->showEmptyListMessage();
100             }
101         }
102
103         $subscriptions->free();
104
105         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
106                           $this->page, 'subscriptions',
107                           array('nickname' => $this->user->nickname));
108     }
109
110     function showScripts()
111     {
112         parent::showScripts();
113         $this->autofocus('tag');
114     }
115
116     function showEmptyListMessage()
117     {
118         if (common_logged_in()) {
119             $current_user = common_current_user();
120             if ($this->user->id === $current_user->id) {
121                 $message = _('You\'re not listening to anyone\'s notices right now, try subscribing to people you know. Try [people search](%%action.peoplesearch%%), look for members in groups you\'re interested in and in our [featured users](%%action.featured%%). If you\'re a [Twitter user](%%action.twittersettings%%), you can automatically subscribe to people you already follow there.');
122             } else {
123                 $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
124             }
125         }
126         else {
127             $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
128         }
129
130         $this->elementStart('div', 'guide');
131         $this->raw(common_markup_to_html($message));
132         $this->elementEnd('div');
133     }
134
135     function showSections()
136     {
137         parent::showSections();
138         $cloud = new SubscriptionsPeopleTagCloudSection($this);
139         $cloud->show();
140
141         $cloud2 = new SubscriptionsPeopleSelfTagCloudSection($this);
142         $cloud2->show();
143     }
144 }
145
146 // XXX SubscriptionsList and SubscriptionList are dangerously close
147
148 class SubscriptionsList extends SubscriptionList
149 {
150     function newListItem($profile)
151     {
152         return new SubscriptionsListItem($profile, $this->owner, $this->action);
153     }
154 }
155
156 class SubscriptionsListItem extends SubscriptionListItem
157 {
158     function showProfile()
159     {
160         $this->startProfile();
161         $this->showAvatar();
162         $this->showFullName();
163         $this->showLocation();
164         $this->showHomepage();
165         $this->showBio();
166         $this->showTags();
167         // Relevant portion!
168         $cur = common_current_user();
169         if (!empty($cur) && $cur->id == $this->owner->id) {
170             $this->showOwnerControls();
171         }
172         $this->endProfile();
173     }
174
175     function showOwnerControls()
176     {
177         $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
178                                            'subscribed' => $this->profile->id));
179         if (!$sub) {
180             return;
181         }
182
183         if (!common_config('xmpp', 'enabled') && !common_config('sms', 'enabled')) {
184             return;
185         }
186
187         $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id,
188                                           'method' => 'post',
189                                           'class' => 'form_subscription_edit',
190                                           'action' => common_local_url('subedit')));
191         $this->out->hidden('token', common_session_token());
192         $this->out->hidden('profile', $this->profile->id);
193         if (common_config('xmpp', 'enabled')) {
194             $this->out->checkbox('jabber', _('Jabber'), $sub->jabber);
195         } else {
196             $this->out->hidden('jabber', $sub->jabber);
197         }
198         if (common_config('sms', 'enabled')) {
199             $this->out->checkbox('sms', _('SMS'), $sub->sms);
200         } else {
201             $this->out->hidden('sms', $sub->sms);
202         }
203         $this->out->submit('save', _('Save'));
204         $this->out->elementEnd('form');
205         return;
206     }
207 }