]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apigroupshow.php
Merge activity plugin into mainline
[quix0rs-gnu-social.git] / actions / apigroupshow.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show information about a group
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  API
23  * @package   StatusNet
24  * @author    Craig Andrews <candrews@integralblue.com>
25  * @author    Evan Prodromou <evan@status.net>
26  * @author    Jeffery To <jeffery.to@gmail.com>
27  * @author    Zach Copley <zach@status.net>
28  * @copyright 2009 StatusNet, Inc.
29  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
30  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31  * @link      http://status.net/
32  */
33
34 if (!defined('STATUSNET')) {
35     exit(1);
36 }
37
38 require_once INSTALLDIR . '/lib/apiprivateauth.php';
39
40 /**
41  * Outputs detailed information about the group specified by ID
42  *
43  * @category API
44  * @package  StatusNet
45  * @author   Craig Andrews <candrews@integralblue.com>
46  * @author   Evan Prodromou <evan@status.net>
47  * @author   Jeffery To <jeffery.to@gmail.com>
48  * @author   Zach Copley <zach@status.net>
49  * @author   Michele <macno@macno.org>
50  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
51  * @link     http://status.net/
52  */
53 class ApiGroupShowAction extends ApiPrivateAuthAction
54 {
55     var $group = null;
56
57     /**
58      * Take arguments for running
59      *
60      * @param array $args $_REQUEST args
61      *
62      * @return boolean success flag
63      */
64     function prepare($args)
65     {
66         parent::prepare($args);
67
68         $this->group = $this->getTargetGroup($this->arg('id'));
69
70         if (empty($this->group)) {
71             $alias = Group_alias::staticGet(
72                 'alias',
73                 common_canonical_nickname($this->arg('id'))
74             );
75             if (!empty($alias)) {
76                 $args = array('id' => $alias->group_id, 'format' => $this->format);
77                 common_redirect(common_local_url('ApiGroupShow', $args), 301);
78             } else {
79                 $this->clientError(
80                     // TRANS: Client error displayed when trying to show a group that could not be found.
81                     _('Group not found.'),
82                     404,
83                     $this->format
84                 );
85             }
86             return;
87         }
88
89         return true;
90     }
91
92     /**
93      * Handle the request
94      *
95      * Check the format and show the user info
96      *
97      * @param array $args $_REQUEST data (unused)
98      *
99      * @return void
100      */
101     function handle($args)
102     {
103         parent::handle($args);
104
105         switch($this->format) {
106         case 'xml':
107             $this->showSingleXmlGroup($this->group);
108             break;
109         case 'json':
110             $this->showSingleJsonGroup($this->group);
111             break;
112         default:
113             // TRANS: Client error displayed when coming across a non-supported API method.
114             $this->clientError(_('API method not found.'), 404, $this->format);
115             break;
116         }
117     }
118
119     /**
120      * When was this group last modified?
121      *
122      * @return string datestamp of the latest notice in the stream
123      */
124     function lastModified()
125     {
126         if (!empty($this->group)) {
127             return strtotime($this->group->modified);
128         }
129
130         return null;
131     }
132
133     /**
134      * An entity tag for this group
135      *
136      * Returns an Etag based on the action name, language, and
137      * timestamps of the notice
138      *
139      * @return string etag
140      */
141     function etag()
142     {
143         if (!empty($this->group)) {
144
145             return '"' . implode(
146                 ':',
147                 array($this->arg('action'),
148                       common_user_cache_hash($this->auth_user),
149                       common_language(),
150                       $this->group->id,
151                       strtotime($this->group->modified))
152             )
153             . '"';
154         }
155
156         return null;
157     }
158
159     /**
160      * Return true if read only.
161      *
162      * MAY override
163      *
164      * @param array $args other arguments
165      *
166      * @return boolean is read only action?
167      */
168     function isReadOnly($args)
169     {
170         return true;
171     }
172 }