]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GroupPrivateMessage/actions/showgroupmessage.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / GroupPrivateMessage / actions / showgroupmessage.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Show a single group message
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  GroupPrivateMessage
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Show a single private group message
39  *
40  * @category  GroupPrivateMessage
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2011 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47 class ShowgroupmessageAction extends Action
48 {
49     var $gm;
50     var $group;
51     var $sender;
52     var $user;
53
54     /**
55      * For initializing members of the class.
56      *
57      * @param array $argarray misc. arguments
58      *
59      * @return boolean true
60      */
61     function prepare($argarray)
62     {
63         parent::prepare($argarray);
64
65         $this->user = common_current_user();
66
67         if (empty($this->user)) {
68             // TRANS: Client exception thrown when trying to view group private messages without being logged in.
69             throw new ClientException(_m('Only logged-in users can view private messages.'),
70                                       403);
71         }
72
73         $id = $this->trimmed('id');
74
75         $this->gm = Group_message::getKV('id', $id);
76
77         if (empty($this->gm)) {
78             // TRANS: Client exception thrown when trying to view a non-existing group private message.
79             throw new ClientException(_m('No such message.'), 404);
80         }
81
82         $this->group = User_group::getKV('id', $this->gm->to_group);
83
84         if (empty($this->group)) {
85             // TRANS: Server exception thrown when trying to view group private messages for a non-exsting group.
86             throw new ServerException(_m('Group not found.'));
87         }
88
89         if (!$this->user->isMember($this->group)) {
90             // TRANS: Client exception thrown when trying to view a group private message without being a group member.
91             throw new ClientException(_m('Cannot read message.'), 403);
92         }
93
94         $this->sender = Profile::getKV('id', $this->gm->from_profile);
95
96         if (empty($this->sender)) {
97             // TRANS: Server exception thrown when trying to view a group private message without a sender.
98             throw new ServerException(_m('No sender found.'));
99         }
100
101         return true;
102     }
103
104     /**
105      * Handler method
106      *
107      * @param array $argarray is ignored since it's now passed in in prepare()
108      *
109      * @return void
110      */
111     function handle($argarray=null)
112     {
113         $this->showPage();
114     }
115
116     /**
117      * Title of the page
118      */
119     function title()
120     {
121         // TRANS: Title for private group message.
122         // TRANS: %1$s is the sender name, %2$s is the group name, %3$s is a timestamp.
123         return sprintf(_m('Message from %1$s to group %2$s on %3$s'),
124                        $this->sender->nickname,
125                        $this->group->nickname,
126                        common_exact_date($this->gm->created));
127     }
128
129     /**
130      * Show the content area.
131      */
132     function showContent()
133     {
134         $this->elementStart('ul', 'notices messages');
135         $gmli = new GroupMessageListItem($this, $this->gm);
136         $gmli->show();
137         $this->elementEnd('ul');
138     }
139
140     /**
141      * Return true if read only.
142      *
143      * MAY override
144      *
145      * @param array $args other arguments
146      *
147      * @return boolean is read only action?
148      */
149     function isReadOnly(array $args=array())
150     {
151         return true;
152     }
153
154     /**
155      * Return last modified, if applicable.
156      *
157      * MAY override
158      *
159      * @return string last modified http header
160      */
161     function lastModified()
162     {
163         return max(strtotime($this->group->modified),
164                    strtotime($this->sender->modified),
165                    strtotime($this->gm->modified));
166     }
167
168     /**
169      * Return etag, if applicable.
170      *
171      * MAY override
172      *
173      * @return string etag http header
174      */
175     function etag()
176     {
177         try {
178             $avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
179             $avtime = strtotime($avatar->modified);
180         } catch (Exception $e) {
181             $avtime = 0;
182         }
183
184         return 'W/"' . implode(':', array($this->arg('action'),
185                                           common_user_cache_hash(),
186                                           common_language(),
187                                           $this->gm->id,
188                                           strtotime($this->sender->modified),
189                                           strtotime($this->group->modified),
190                                           $avtime)) . '"';
191     }
192 }