]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/twitapistatusnet.php
change Laconica and Control Yourself to StatusNet in PHP files
[quix0rs-gnu-social.git] / actions / twitapistatusnet.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * StatusNet-only extensions to the Twitter-like API
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    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/twitterapi.php';
35
36 /**
37  * StatusNet-specific API methods
38  *
39  * This class handles all /laconica/ API methods.
40  *
41  * @category  Twitter
42  * @package   StatusNet
43  * @author    Evan Prodromou <evan@controlyourself.ca>
44  * @copyright 2008 StatusNet, Inc.
45  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46  * @link      http://laconi.ca/
47  */
48
49 class TwitapilaconicaAction extends TwitterapiAction
50 {
51     /**
52      * A version stamp for the API
53      *
54      * Returns a version number for this version of StatusNet, which
55      * should make things a bit easier for upgrades.
56      * URL: http://identi.ca/api/laconica/version.(xml|json)
57      * Formats: xml, json
58      *
59      * @param array $args    Web arguments
60      * @param array $apidata Twitter API data
61      *
62      * @return void
63      *
64      * @see ApiAction::process_command()
65      */
66
67     function version($args, $apidata)
68     {
69         parent::handle($args);
70         switch ($apidata['content-type']) {
71          case 'xml':
72             $this->init_document('xml');
73             $this->element('version', null, LACONICA_VERSION);
74             $this->end_document('xml');
75             break;
76          case 'json':
77             $this->init_document('json');
78             print '"'.LACONICA_VERSION.'"';
79             $this->end_document('json');
80             break;
81          default:
82             $this->clientError(_('API method not found!'), $code=404);
83         }
84     }
85
86     /**
87      * Dump of configuration variables
88      *
89      * Gives a full dump of configuration variables for this instance
90      * of StatusNet, minus variables that may be security-sensitive (like
91      * passwords).
92      * URL: http://identi.ca/api/laconica/config.(xml|json)
93      * Formats: xml, json
94      *
95      * @param array $args    Web arguments
96      * @param array $apidata Twitter API data
97      *
98      * @return void
99      *
100      * @see ApiAction::process_command()
101      */
102
103     function config($args, $apidata)
104     {
105         static $keys = array('site' => array('name', 'server', 'theme', 'path', 'fancy', 'language',
106                                              'email', 'broughtby', 'broughtbyurl', 'closed',
107                                              'inviteonly', 'private'),
108                              'license' => array('url', 'title', 'image'),
109                              'nickname' => array('featured'),
110                              'throttle' => array('enabled', 'count', 'timespan'),
111                              'xmpp' => array('enabled', 'server', 'user'));
112
113         parent::handle($args);
114
115         switch ($apidata['content-type']) {
116          case 'xml':
117             $this->init_document('xml');
118             $this->elementStart('config');
119             // XXX: check that all sections and settings are legal XML elements
120             foreach ($keys as $section => $settings) {
121                 $this->elementStart($section);
122                 foreach ($settings as $setting) {
123                     $value = common_config($section, $setting);
124                     if (is_array($value)) {
125                         $value = implode(',', $value);
126                     } else if ($value === false) {
127                         $value = 'false';
128                     } else if ($value === true) {
129                         $value = 'true';
130                     }
131                     $this->element($setting, null, $value);
132                 }
133                 $this->elementEnd($section);
134             }
135             $this->elementEnd('config');
136             $this->end_document('xml');
137             break;
138          case 'json':
139             $result = array();
140             foreach ($keys as $section => $settings) {
141                 $result[$section] = array();
142                 foreach ($settings as $setting) {
143                     $result[$section][$setting] = common_config($section, $setting);
144                 }
145             }
146             $this->init_document('json');
147             $this->show_json_objects($result);
148             $this->end_document('json');
149             break;
150          default:
151             $this->clientError(_('API method not found!'), $code=404);
152         }
153     }
154
155     /**
156      * WADL description of the API
157      *
158      * Gives a WADL description of the API provided by this version of the
159      * software.
160      *
161      * @param array $args    Web arguments
162      * @param array $apidata Twitter API data
163      *
164      * @return void
165      *
166      * @see ApiAction::process_command()
167      */
168
169     function wadl($args, $apidata)
170     {
171         parent::handle($args);
172         $this->serverError(_('API method under construction.'), 501);
173     }
174
175 }