]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusnetconfig.php
6847a48fe13b28d7dd044d2070b5a2878d56bafb
[quix0rs-gnu-social.git] / actions / apistatusnetconfig.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Dump of configuration variables
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    Zach Copley <zach@status.net>
25  * @copyright 2009 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://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/api.php';
35
36 /**
37  * Gives a full dump of configuration variables for this instance
38  * of StatusNet, minus variables that may be security-sensitive (like
39  * passwords).
40  * URL: http://identi.ca/api/statusnet/config.(xml|json)
41  * Formats: xml, json
42  *
43  * @category API
44  * @package  StatusNet
45  * @author   Zach Copley <zach@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://status.net/
48  */
49
50 class ApiStatusnetConfigAction extends TwitterApiAction
51 {
52     var $format = null;
53
54     var $keys = array(
55         'site' => array('name', 'server', 'theme', 'path', 'fancy', 'language',
56                         'email', 'broughtby', 'broughtbyurl', 'closed',
57                         'inviteonly', 'private'),
58         'license' => array('url', 'title', 'image'),
59         'nickname' => array('featured'),
60         'throttle' => array('enabled', 'count', 'timespan'),
61         'xmpp' => array('enabled', 'server', 'user')
62     );
63
64     /**
65      * Take arguments for running
66      *
67      * @param array $args $_REQUEST args
68      *
69      * @return boolean success flag
70      *
71      */
72
73     function prepare($args)
74     {
75         parent::prepare($args);
76         $this->format = $this->arg('format');
77         return true;
78     }
79
80     /**
81      * Handle the request
82      *
83      * @param array $args $_REQUEST data (unused)
84      *
85      * @return void
86      */
87
88     function handle($args)
89     {
90         parent::handle($args);
91
92         switch ($this->format) {
93         case 'xml':
94             $this->init_document('xml');
95             $this->elementStart('config');
96
97             // XXX: check that all sections and settings are legal XML elements
98
99             common_debug(var_export($this->keys, true));
100
101             foreach ($this->keys as $section => $settings) {
102                 $this->elementStart($section);
103                 foreach ($settings as $setting) {
104                     $value = common_config($section, $setting);
105                     if (is_array($value)) {
106                         $value = implode(',', $value);
107                     } else if ($value === false) {
108                         $value = 'false';
109                     } else if ($value === true) {
110                         $value = 'true';
111                     }
112                     $this->element($setting, null, $value);
113                 }
114                 $this->elementEnd($section);
115             }
116             $this->elementEnd('config');
117             $this->end_document('xml');
118             break;
119         case 'json':
120             $result = array();
121             foreach ($this->keys as $section => $settings) {
122                 $result[$section] = array();
123                 foreach ($settings as $setting) {
124                     $result[$section][$setting]
125                         = common_config($section, $setting);
126                 }
127             }
128             $this->init_document('json');
129             $this->show_json_objects($result);
130             $this->end_document('json');
131             break;
132         default:
133             $this->clientError(
134                 _('API method not found!'),
135                 404,
136                 $this->format
137             );
138             break;
139         }
140     }
141
142 }
143