]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/lib/favcommand.php
94658b8a53390e7173294977ecd0faa25943bd4e
[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         $fave = Fave::addNew($this->user->getProfile(), $notice); 
29  
30         if (!$fave) { 
31             // TRANS: Error message text shown when a favorite could not be set. 
32             $channel->error($this->user, _('Could not create favorite.')); 
33             return; 
34         } 
35  
36         // @fixme favorite notification should be triggered 
37         // at a lower level 
38  
39         $other = User::getKV('id', $notice->profile_id); 
40  
41         if ($other && $other->id != $this->user->id && !empty($other->email)) { 
42             require_once INSTALLDIR.'/lib/mail.php';
43
44             mail_notify_fave($other, $this->user->getProfile(), $notice);
45         } 
46  
47         Fave::blowCacheForProfileId($this->user->id);
48  
49         // TRANS: Text shown when a notice has been marked as favourite successfully. 
50         $channel->output($this->user, _('Notice marked as fave.')); 
51     } 
52 }