]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribe.php
35961d05170181cccbcfbadf9f01cdadeeecc9fe
[quix0rs-gnu-social.git] / actions / subscribe.php
1 <?php
2
3 class SubscribeAction extends Action {
4         function handle($args) {
5                 parent::handle($args);
6                 
7                 if (!common_logged_in()) {
8                         common_user_error(_t('Not logged in.'));
9                         return;
10                 }
11                 
12                 $other_nickname = $this->arg('subscribeto');
13
14                 $other = User::staticGet('nickname', $other_nickname);
15                 
16                 if (!$other) {
17                         common_user_error(_t('No such user.'));
18                         return;
19                 }
20                 
21                 $user = common_current_user();
22
23                 if ($user->isSubscribed($other)) {
24                         common_user_error(_t('Already subscribed!.'));
25                         return;
26                 }
27                 
28                 $sub = new Subscription();
29                 $sub->subscriber = $user->id;
30                 $sub->subscribed = $other->id;
31                 
32                 $sub->created = time();
33                 
34                 if (!$sub->insert()) {
35                         common_server_error(_t('Couldn\'t create subscription.'));
36                         return;
37                 }
38                 
39                 common_redirect(common_local_url('all', array('nickname' =>
40                                                                                                           $user->nickname)));
41         }
42 }