]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusnetconfig.php
Merge commit 'mainline/0.9.x' into 0.9.x
[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    Evan Prodromou <evan@status.net>
25  * @author    Zach Copley <zach@status.net>
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://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR . '/lib/api.php';
36
37 /**
38  * Gives a full dump of configuration variables for this instance
39  * of StatusNet, minus variables that may be security-sensitive (like
40  * passwords).
41  * URL: http://identi.ca/api/statusnet/config.(xml|json)
42  * Formats: xml, json
43  *
44  * @category API
45  * @package  StatusNet
46  * @author   Evan Prodromou <evan@status.net>
47  * @author   Zach Copley <zach@status.net>
48  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49  * @link     http://status.net/
50  */
51
52 class ApiStatusnetConfigAction extends ApiAction
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         return true;
77     }
78
79     /**
80      * Handle the request
81      *
82      * @param array $args $_REQUEST data (unused)
83      *
84      * @return void
85      */
86
87     function handle($args)
88     {
89         parent::handle($args);
90
91         switch ($this->format) {
92         case 'xml':
93             $this->initDocument('xml');
94             $this->elementStart('config');
95
96             // XXX: check that all sections and settings are legal XML elements
97
98             common_debug(var_export($this->keys, true));
99
100             foreach ($this->keys as $section => $settings) {
101                 $this->elementStart($section);
102                 foreach ($settings as $setting) {
103                     $value = common_config($section, $setting);
104                     if (is_array($value)) {
105                         $value = implode(',', $value);
106                     } else if ($value === false) {
107                         $value = 'false';
108                     } else if ($value === true) {
109                         $value = 'true';
110                     }
111                     $this->element($setting, null, $value);
112                 }
113                 $this->elementEnd($section);
114             }
115             $this->elementEnd('config');
116             $this->endDocument('xml');
117             break;
118         case 'json':
119             $result = array();
120             foreach ($this->keys as $section => $settings) {
121                 $result[$section] = array();
122                 foreach ($settings as $setting) {
123                     $result[$section][$setting]
124                         = common_config($section, $setting);
125                 }
126             }
127             $this->initDocument('json');
128             $this->showJsonObjects($result);
129             $this->endDocument('json');
130             break;
131         default:
132             $this->clientError(
133                 _('API method not found!'),
134                 404,
135                 $this->format
136             );
137             break;
138         }
139     }
140
141 }
142