]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscriptions.php
Merge remote branch 'statusnet/0.9.x' into 1.0.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(_('%1$s subscriptions, page %2$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         if (Event::handle('StartShowSubscriptionsContent', array($this))) {
83             parent::showContent();
84
85             $offset = ($this->page-1) * PROFILES_PER_PAGE;
86             $limit =  PROFILES_PER_PAGE + 1;
87
88             $cnt = 0;
89
90             if ($this->tag) {
91                 $subscriptions = $this->user->getTaggedSubscriptions($this->tag, $offset, $limit);
92             } else {
93                 $subscriptions = $this->user->getSubscriptions($offset, $limit);
94             }
95
96             if ($subscriptions) {
97                 $subscriptions_list = new SubscriptionsList($subscriptions, $this->user, $this);
98                 $cnt = $subscriptions_list->show();
99                 if (0 == $cnt) {
100                     $this->showEmptyListMessage();
101                 }
102             }
103
104             $subscriptions->free();
105
106             $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
107                               $this->page, 'subscriptions',
108                               array('nickname' => $this->user->nickname));
109
110
111             Event::handle('EndShowSubscriptionsContent', array($this));
112         }
113     }
114
115     function showScripts()
116     {
117         parent::showScripts();
118         $this->autofocus('tag');
119     }
120
121     function showEmptyListMessage()
122     {
123         if (common_logged_in()) {
124             $current_user = common_current_user();
125             if ($this->user->id === $current_user->id) {
126                 $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.');
127             } else {
128                 $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
129             }
130         }
131         else {
132             $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
133         }
134
135         $this->elementStart('div', 'guide');
136         $this->raw(common_markup_to_html($message));
137         $this->elementEnd('div');
138     }
139
140     function showSections()
141     {
142         parent::showSections();
143         $cloud = new SubscriptionsPeopleTagCloudSection($this);
144         $cloud->show();
145
146         $cloud2 = new SubscriptionsPeopleSelfTagCloudSection($this);
147         $cloud2->show();
148     }
149 }
150
151 // XXX SubscriptionsList and SubscriptionList are dangerously close
152
153 class SubscriptionsList extends SubscriptionList
154 {
155     function newListItem($profile)
156     {
157         return new SubscriptionsListItem($profile, $this->owner, $this->action);
158     }
159 }
160
161 class SubscriptionsListItem extends SubscriptionListItem
162 {
163     function showProfile()
164     {
165         $this->startProfile();
166         $this->showAvatar();
167         $this->showFullName();
168         $this->showLocation();
169         $this->showHomepage();
170         $this->showBio();
171         $this->showTags();
172         // Relevant portion!
173         $cur = common_current_user();
174         if (!empty($cur) && $cur->id == $this->owner->id) {
175             $this->showOwnerControls();
176         }
177         $this->endProfile();
178     }
179
180     function showOwnerControls()
181     {
182         $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
183                                            'subscribed' => $this->profile->id));
184         if (!$sub) {
185             return;
186         }
187
188         $transports = array();
189         Event::handle('GetImTransports', array(&$transports));
190         if (!$transports && !common_config('sms', 'enabled')) {
191             return;
192         }
193
194         $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id,
195                                           'method' => 'post',
196                                           'class' => 'form_subscription_edit',
197                                           'action' => common_local_url('subedit')));
198         $this->out->hidden('token', common_session_token());
199         $this->out->hidden('profile', $this->profile->id);
200         if ($transports) {
201             $attrs = array('name' => 'jabber',
202                            'type' => 'checkbox',
203                            'class' => 'checkbox',
204                            'id' => 'jabber-'.$this->profile->id);
205             if ($sub->jabber) {
206                 $attrs['checked'] = 'checked';
207             }
208
209             $this->out->element('input', $attrs);
210             $this->out->element('label', array('for' => 'jabber-'.$this->profile->id), _('IM'));
211         } else {
212             $this->out->hidden('jabber', $sub->jabber);
213         }
214         if (common_config('sms', 'enabled')) {
215             $attrs = array('name' => 'sms',
216                            'type' => 'checkbox',
217                            'class' => 'checkbox',
218                            'id' => 'sms-'.$this->profile->id);
219             if ($sub->sms) {
220                 $attrs['checked'] = 'checked';
221             }
222
223             $this->out->element('input', $attrs);
224             $this->out->element('label', array('for' => 'sms-'.$this->profile->id), _('SMS'));
225         } else {
226             $this->out->hidden('sms', $sub->sms);
227         }
228         $this->out->submit('save', _('Save'));
229         $this->out->elementEnd('form');
230         return;
231     }
232 }