]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GroupPrivateMessage/showgroupmessage.php
copy-paste TagSub to SearchSub :D
[quix0rs-gnu-social.git] / plugins / GroupPrivateMessage / 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
48 class ShowgroupmessageAction extends Action
49 {
50     var $gm;
51     var $group;
52     var $sender;
53     var $user;
54
55     /**
56      * For initializing members of the class.
57      *
58      * @param array $argarray misc. arguments
59      *
60      * @return boolean true
61      */
62
63     function prepare($argarray)
64     {
65         parent::prepare($argarray);
66
67         $this->user = common_current_user();
68
69         if (empty($this->user)) {
70             throw new ClientException(_('Only logged-in users can view private messages.'),
71                                       403);
72         }
73
74         $id = $this->trimmed('id');
75
76         $this->gm = Group_message::staticGet('id', $id);
77
78         if (empty($this->gm)) {
79             throw new ClientException(_('No such message'), 404);
80         }
81
82         $this->group = User_group::staticGet('id', $this->gm->to_group);
83
84         if (empty($this->group)) {
85             throw new ServerException(_('Group not found.'));
86         }
87
88         if (!$this->user->isMember($this->group)) {
89             throw new ClientException(_('Cannot read message.'), 403);
90         }
91
92         $this->sender = Profile::staticGet('id', $this->gm->from_profile);
93
94         if (empty($this->sender)) {
95             throw new ServerException(_('No sender found.'));
96         }
97
98         return true;
99     }
100
101     /**
102      * Handler method
103      *
104      * @param array $argarray is ignored since it's now passed in in prepare()
105      *
106      * @return void
107      */
108
109     function handle($argarray=null)
110     {
111         $this->showPage();
112     }
113
114     /**
115      * Title of the page
116      */
117
118     function title()
119     {
120         return sprintf(_('Message from %1$s to group %2$s on %3$s'),
121                        $this->sender->nickname,
122                        $this->group->nickname,
123                        common_exact_date($this->gm->created));
124     }
125
126     /**
127      * Show the content area.
128      */
129
130     function showContent()
131     {
132         $this->elementStart('ul', 'notices messages');
133         $gmli = new GroupMessageListItem($this, $this->gm);
134         $gmli->show();
135         $this->elementEnd('ul');
136     }
137
138     /**
139      * Return true if read only.
140      *
141      * MAY override
142      *
143      * @param array $args other arguments
144      *
145      * @return boolean is read only action?
146      */
147
148     function isReadOnly($args)
149     {
150         return true;
151     }
152
153     /**
154      * Return last modified, if applicable.
155      *
156      * MAY override
157      *
158      * @return string last modified http header
159      */
160     function lastModified()
161     {
162         return max(strtotime($this->group->modified),
163                    strtotime($this->sender->modified),
164                    strtotime($this->gm->modified));
165     }
166
167     /**
168      * Return etag, if applicable.
169      *
170      * MAY override
171      *
172      * @return string etag http header
173      */
174     function etag()
175     {
176         $avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
177
178         $avtime = ($avatar) ? strtotime($avatar->modified) : 0;
179
180         return 'W/"' . implode(':', array($this->arg('action'),
181                                           common_user_cache_hash(),
182                                           common_language(),
183                                           $this->gm->id,
184                                           strtotime($this->sender->modified),
185                                           strtotime($this->group->modified),
186                                           $avtime)) . '"';
187     }
188 }