]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/twitapigroups.php
5ac21faca609563a2524573eb4529df60c7fe572
[quix0rs-gnu-social.git] / actions / twitapigroups.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * StatusNet extensions to the Twitter-like API for groups
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  Twitter
23  * @package   StatusNet
24  * @author    Craig Andrews
25  * @author    Zach Copley <zach@controlyourself.ca>
26  * @copyright 2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/twitterapi.php';
36
37 /**
38  * Group-specific API methods
39  *
40  * This class handles StatusNet group API methods.
41  *
42  * @category  Twitter
43  * @package   StatusNet
44  * @author    Craig Andrews
45  * @author    Zach Copley <zach@controlyourself.ca>
46  * @copyright 2009 StatusNet, Inc.
47  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48  * @link      http://laconi.ca/
49  */
50
51  class TwitapigroupsAction extends TwitterapiAction
52  {
53
54      function list_groups($args, $apidata)
55      {
56          parent::handle($args);
57          
58          common_debug("in groups api action");
59          
60          $this->auth_user = $apidata['user'];
61          $user = $this->get_user($apidata['api_arg'], $apidata);
62
63          if (empty($user)) {
64              $this->clientError('Not Found', 404, $apidata['content-type']);
65              return;
66          }
67
68          $page     = (int)$this->arg('page', 1);
69          $count    = (int)$this->arg('count', 20);
70          $max_id   = (int)$this->arg('max_id', 0);
71          $since_id = (int)$this->arg('since_id', 0);
72          $since    = $this->arg('since');
73          $group = $user->getGroups(($page-1)*$count,
74              $count, $since_id, $max_id, $since);
75
76          $sitename   = common_config('site', 'name');
77          $title      = sprintf(_("%s's groups"), $user->nickname);
78          $taguribase = common_config('integration', 'taguri');
79          $id         = "tag:$taguribase:Groups";
80          $link       = common_root_url();
81          $subtitle   = sprintf(_("groups %s is a member of on %s"), $user->nickname, $sitename);
82
83          switch($apidata['content-type']) {
84          case 'xml':
85              $this->show_xml_groups($group);
86              break;
87          case 'rss':
88              $this->show_rss_groups($group, $title, $link, $subtitle);
89              break;
90          case 'atom':
91              $selfuri = common_root_url() . 'api/laconica/groups/list/' . $user->id . '.atom';
92              $this->show_atom_groups($group, $title, $id, $link,
93                  $subtitle, $selfuri);
94              break;
95          case 'json':
96              $this->show_json_groups($group);
97              break;
98          default:
99              $this->clientError(_('API method not found!'), $code = 404);
100              break;
101          }
102      }
103
104      function list_all($args, $apidata)
105      {
106          parent::handle($args);
107          
108          common_debug("in groups api action");
109          
110          $page     = (int)$this->arg('page', 1);
111          $count    = (int)$this->arg('count', 20);
112          $max_id   = (int)$this->arg('max_id', 0);
113          $since_id = (int)$this->arg('since_id', 0);
114          $since    = $this->arg('since');
115
116          /*      TODO:
117          Use the $page, $count, $max_id, $since_id, and $since parameters
118          */
119          $group = new User_group();
120          $group->orderBy('created DESC');
121          $group->find();
122
123          $sitename   = common_config('site', 'name');
124          $title      = sprintf(_("%s groups"), $sitename);
125          $taguribase = common_config('integration', 'taguri');
126          $id         = "tag:$taguribase:Groups";
127          $link       = common_root_url();
128          $subtitle   = sprintf(_("groups on %s"), $sitename);
129
130          switch($apidata['content-type']) {
131          case 'xml':
132              $this->show_xml_groups($group);
133              break;
134          case 'rss':
135              $this->show_rss_groups($group, $title, $link, $subtitle);
136              break;
137          case 'atom':
138              $selfuri = common_root_url() . 'api/laconica/groups/list_all.atom';
139              $this->show_atom_groups($group, $title, $id, $link,
140                  $subtitle, $selfuri);
141              break;
142          case 'json':
143              $this->show_json_groups($group);
144              break;
145          default:
146              $this->clientError(_('API method not found!'), $code = 404);
147              break;
148          }
149      }
150
151      function show($args, $apidata)
152      {
153          parent::handle($args);
154
155          common_debug("in groups api action");
156
157          $this->auth_user = $apidata['user'];
158          $group = $this->get_group($apidata['api_arg'], $apidata);
159
160          if (empty($group)) {
161              $this->clientError('Not Found', 404, $apidata['content-type']);
162              return;
163          }
164
165          switch($apidata['content-type']) {
166           case 'xml':
167              $this->show_single_xml_group($group);
168              break;
169           case 'json':
170              $this->show_single_json_group($group);
171              break;
172           default:
173              $this->clientError(_('API method not found!'), $code = 404);
174          }
175      }
176
177      function timeline($args, $apidata)
178      {
179          parent::handle($args);
180
181          common_debug("in groups api action");
182
183          $this->auth_user = $apidata['user'];
184          $group = $this->get_group($apidata['api_arg'], $apidata);
185
186          if (empty($group)) {
187              $this->clientError('Not Found', 404, $apidata['content-type']);
188              return;
189          }
190
191          $sitename   = common_config('site', 'name');
192          $title      = sprintf(_("%s timeline"), $group->nickname);
193          $taguribase = common_config('integration', 'taguri');
194          $id         = "tag:$taguribase:GroupTimeline:".$group->id;
195          $link       = common_local_url('showgroup',
196              array('nickname' => $group->nickname));
197          $subtitle   = sprintf(_('Updates from %1$s on %2$s!'),
198              $group->nickname, $sitename);
199
200          $page     = (int)$this->arg('page', 1);
201          $count    = (int)$this->arg('count', 20);
202          $max_id   = (int)$this->arg('max_id', 0);
203          $since_id = (int)$this->arg('since_id', 0);
204          $since    = $this->arg('since');
205
206          $notice = $group->getNotices(($page-1)*$count,
207              $count, $since_id, $max_id, $since);
208
209          switch($apidata['content-type']) {
210           case 'xml':
211              $this->show_xml_timeline($notice);
212              break;
213           case 'rss':
214              $this->show_rss_timeline($notice, $title, $link, $subtitle);
215              break;
216           case 'atom':
217              if (isset($apidata['api_arg'])) {
218                  $selfuri = common_root_url() .
219                      'api/laconica/groups/timeline/' .
220                          $apidata['api_arg'] . '.atom';
221              } else {
222                  $selfuri = common_root_url() .
223                   'api/laconica/groups/timeline.atom';
224              }
225              $this->show_atom_timeline($notice, $title, $id, $link,
226                  $subtitle, null, $selfuri);
227              break;
228           case 'json':
229              $this->show_json_timeline($notice);
230              break;
231           default:
232              $this->clientError(_('API method not found!'), $code = 404);
233          }
234      }
235
236 }