]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/twitapigroups.php
Merge branch '0.8.x' of git@gitorious.org:laconica/mainline into 0.8.x
[quix0rs-gnu-social.git] / actions / twitapigroups.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Laconica 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   Laconica
24  * @author    Craig Andrews
25  * @author    Zach Copley <zach@controlyourself.ca>
26  * @copyright 2009 Control Yourself, 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 Laconica group API methods.
41  *
42  * @category  Twitter
43  * @package   Laconica
44  * @author    Craig Andrews
45  * @author    Zach Copley <zach@controlyourself.ca>
46  * @copyright 2009 Control Yourself, 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 show($args, $apidata)
55      {
56          parent::handle($args);
57
58          common_debug("in groups api action");
59
60          $this->auth_user = $apidata['user'];
61          $group = $this->get_group($apidata['api_arg'], $apidata);
62
63          if (empty($group)) {
64              $this->clientError('Not Found', 404, $apidata['content-type']);
65              return;
66          }
67
68          switch($apidata['content-type']) {
69           case 'xml':
70              $this->show_single_xml_group($group);
71              break;
72           case 'json':
73              $this->show_single_json_group($group);
74              break;
75           default:
76              $this->clientError(_('API method not found!'), $code = 404);
77          }
78      }
79
80      function timeline($args, $apidata)
81      {
82          parent::handle($args);
83
84          common_debug("in groups api action");
85
86          $this->auth_user = $apidata['user'];
87          $group = $this->get_group($apidata['api_arg'], $apidata);
88
89          if (empty($group)) {
90              $this->clientError('Not Found', 404, $apidata['content-type']);
91              return;
92          }
93
94          $sitename   = common_config('site', 'name');
95          $title      = sprintf(_("%s timeline"), $group->nickname);
96          $taguribase = common_config('integration', 'taguri');
97          $id         = "tag:$taguribase:GroupTimeline:".$group->id;
98          $link       = common_local_url('showgroup',
99              array('nickname' => $group->nickname));
100          $subtitle   = sprintf(_('Updates from %1$s on %2$s!'),
101              $group->nickname, $sitename);
102
103          $page     = (int)$this->arg('page', 1);
104          $count    = (int)$this->arg('count', 20);
105          $max_id   = (int)$this->arg('max_id', 0);
106          $since_id = (int)$this->arg('since_id', 0);
107          $since    = $this->arg('since');
108
109          $notice = $group->getNotices(($page-1)*$count,
110              $count, $since_id, $max_id, $since);
111
112          switch($apidata['content-type']) {
113           case 'xml':
114              $this->show_xml_timeline($notice);
115              break;
116           case 'rss':
117              $this->show_rss_timeline($notice, $title, $link,
118                  $subtitle, $suplink);
119              break;
120           case 'atom':
121              if (isset($apidata['api_arg'])) {
122                  $selfuri = common_root_url() .
123                      'api/laconica/groups/timeline/' .
124                          $apidata['api_arg'] . '.atom';
125              } else {
126                  $selfuri = common_root_url() .
127                   'api/laconica/groups/timeline.atom';
128              }
129              $this->show_atom_timeline($notice, $title, $id, $link,
130                  $subtitle, $suplink, $selfuri);
131              break;
132           case 'json':
133              $this->show_json_timeline($notice);
134              break;
135           default:
136              $this->clientError(_('API method not found!'), $code = 404);
137          }
138      }
139
140 }