]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/lib/favcommand.php
Found some unreachable code in Favorite
[quix0rs-gnu-social.git] / plugins / Favorite / lib / favcommand.php
1 <?php
2
3 class FavCommand extends Command 
4
5     var $other = null; 
6  
7     function __construct($user, $other) 
8     { 
9         parent::__construct($user); 
10         $this->other = $other; 
11     } 
12  
13     function handle($channel) 
14     { 
15         $notice = $this->getNotice($this->other); 
16  
17         $fave            = new Fave(); 
18         $fave->user_id   = $this->user->id; 
19         $fave->notice_id = $notice->id; 
20         $fave->find(); 
21  
22         if ($fave->fetch()) { 
23             // TRANS: Error message text shown when a favorite could not be set because it has already been favorited. 
24             $channel->error($this->user, _('Could not create favorite: Already favorited.')); 
25             return; 
26         } 
27  
28         try {
29             $fave = Fave::addNew($this->user->getProfile(), $notice); 
30         } catch (Exception $e) {
31             $channel->error($this->user, $e->getMessage());
32             return;
33         }
34  
35         // @fixme favorite notification should be triggered 
36         // at a lower level 
37  
38         $other = User::getKV('id', $notice->profile_id); 
39  
40         if ($other && $other->id != $this->user->id && !empty($other->email)) { 
41             require_once INSTALLDIR.'/lib/mail.php';
42
43             mail_notify_fave($other, $this->user->getProfile(), $notice);
44         } 
45  
46         Fave::blowCacheForProfileId($this->user->id);
47  
48         // TRANS: Text shown when a notice has been marked as favourite successfully. 
49         $channel->output($this->user, _('Notice marked as fave.')); 
50     } 
51 }