]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/twitapigroups.php
Merge branch '0.9.x' into private-rss
[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 timeline($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          $sitename   = common_config('site', 'name');
69          $title      = sprintf(_("%s timeline"), $group->nickname);
70          $taguribase = common_config('integration', 'taguri');
71          $id         = "tag:$taguribase:GroupTimeline:".$group->id;
72          $link       = common_local_url('showgroup',
73              array('nickname' => $group->nickname));
74          $subtitle   = sprintf(_('Updates from %1$s on %2$s!'),
75              $group->nickname, $sitename);
76
77          $page     = (int)$this->arg('page', 1);
78          $count    = (int)$this->arg('count', 20);
79          $max_id   = (int)$this->arg('max_id', 0);
80          $since_id = (int)$this->arg('since_id', 0);
81          $since    = $this->arg('since');
82
83          $notice = $group->getNotices(($page-1)*$count,
84              $count, $since_id, $max_id, $since);
85
86          switch($apidata['content-type']) {
87           case 'xml':
88              $this->show_xml_timeline($notice);
89              break;
90           case 'rss':
91              $this->show_rss_timeline($notice, $title, $link,
92                  $subtitle, $suplink);
93              break;
94           case 'atom':
95              if (isset($apidata['api_arg'])) {
96                  $selfuri = common_root_url() .
97                      'api/laconica/groups/timeline/' .
98                          $apidata['api_arg'] . '.atom';
99              } else {
100                  $selfuri = common_root_url() .
101                   'api/laconica/groups/timeline.atom';
102              }
103              $this->show_atom_timeline($notice, $title, $id, $link,
104                  $subtitle, $suplink, $selfuri);
105              break;
106           case 'json':
107              $this->show_json_timeline($notice);
108              break;
109           default:
110              $this->clientError(_('API method not found!'), $code = 404);
111          }
112      }
113
114 }