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