]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apigroupshow.php
if the id is an alias we redirect using group_id
[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  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30  * @link      http://status.net/
31  */
32
33 if (!defined('STATUSNET')) {
34     exit(1);
35 }
36
37 require_once INSTALLDIR . '/lib/apiprivateauth.php';
38
39 /**
40  * Outputs detailed information about the group specified by ID
41  *
42  * @category API
43  * @package  StatusNet
44  * @author   Craig Andrews <candrews@integralblue.com>
45  * @author   Evan Prodromou <evan@status.net>
46  * @author   Jeffery To <jeffery.to@gmail.com>
47  * @author   Zach Copley <zach@status.net>
48  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49  * @link     http://status.net/
50  */
51
52 class ApiGroupShowAction extends ApiPrivateAuthAction
53 {
54     var $group = null;
55
56     /**
57      * Take arguments for running
58      *
59      * @param array $args $_REQUEST args
60      *
61      * @return boolean success flag
62      *
63      */
64
65     function prepare($args)
66     {
67         parent::prepare($args);
68
69         $this->group = $this->getTargetGroup($this->arg('id'));
70
71         return true;
72     }
73
74     /**
75      * Handle the request
76      *
77      * Check the format and show the user info
78      *
79      * @param array $args $_REQUEST data (unused)
80      *
81      * @return void
82      */
83
84     function handle($args)
85     {
86         parent::handle($args);
87
88         if (!$this->group) {
89             $alias = Group_alias::staticGet('alias', common_canonical_nickname($this->arg('id')));
90             if ($alias) {
91                 $args = array('id' => $alias->group_id, 'format'=>$this->format);
92                 common_redirect(common_local_url('ApiGroupShow', $args), 301);
93             } else {
94                 $this->clientError(
95                   _('Group not found!'),
96                   404,
97                   $this->format
98                 );
99             }
100             return;
101         }
102
103         switch($this->format) {
104         case 'xml':
105             $this->showSingleXmlGroup($this->group);
106             break;
107         case 'json':
108             $this->showSingleJsonGroup($this->group);
109             break;
110         default:
111             $this->clientError(_('API method not found.'), 404, $this->format);
112             break;
113         }
114
115     }
116
117     /**
118      * When was this group last modified?
119      *
120      * @return string datestamp of the latest notice in the stream
121      */
122
123     function lastModified()
124     {
125         if (!empty($this->group)) {
126             return strtotime($this->group->modified);
127         }
128
129         return null;
130     }
131
132     /**
133      * An entity tag for this group
134      *
135      * Returns an Etag based on the action name, language, and
136      * timestamps of the notice
137      *
138      * @return string etag
139      */
140
141     function etag()
142     {
143         if (!empty($this->group)) {
144
145             return '"' . implode(
146                 ':',
147                 array($this->arg('action'),
148                       common_language(),
149                       $this->group->id,
150                       strtotime($this->group->modified))
151             )
152             . '"';
153         }
154
155         return null;
156     }
157
158 }