]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusnetconfig.php
CamelCase all function names in the API code
[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 ApiAction
51 {
52     var $keys = array(
53         'site' => array('name', 'server', 'theme', 'path', 'fancy', 'language',
54                         'email', 'broughtby', 'broughtbyurl', 'closed',
55                         'inviteonly', 'private'),
56         'license' => array('url', 'title', 'image'),
57         'nickname' => array('featured'),
58         'throttle' => array('enabled', 'count', 'timespan'),
59         'xmpp' => array('enabled', 'server', 'user')
60     );
61
62     /**
63      * Take arguments for running
64      *
65      * @param array $args $_REQUEST args
66      *
67      * @return boolean success flag
68      *
69      */
70
71     function prepare($args)
72     {
73         parent::prepare($args);
74         return true;
75     }
76
77     /**
78      * Handle the request
79      *
80      * @param array $args $_REQUEST data (unused)
81      *
82      * @return void
83      */
84
85     function handle($args)
86     {
87         parent::handle($args);
88
89         switch ($this->format) {
90         case 'xml':
91             $this->initDocument('xml');
92             $this->elementStart('config');
93
94             // XXX: check that all sections and settings are legal XML elements
95
96             common_debug(var_export($this->keys, true));
97
98             foreach ($this->keys as $section => $settings) {
99                 $this->elementStart($section);
100                 foreach ($settings as $setting) {
101                     $value = common_config($section, $setting);
102                     if (is_array($value)) {
103                         $value = implode(',', $value);
104                     } else if ($value === false) {
105                         $value = 'false';
106                     } else if ($value === true) {
107                         $value = 'true';
108                     }
109                     $this->element($setting, null, $value);
110                 }
111                 $this->elementEnd($section);
112             }
113             $this->elementEnd('config');
114             $this->endDocument('xml');
115             break;
116         case 'json':
117             $result = array();
118             foreach ($this->keys as $section => $settings) {
119                 $result[$section] = array();
120                 foreach ($settings as $setting) {
121                     $result[$section][$setting]
122                         = common_config($section, $setting);
123                 }
124             }
125             $this->initDocument('json');
126             $this->showJsonObjects($result);
127             $this->endDocument('json');
128             break;
129         default:
130             $this->clientError(
131                 _('API method not found!'),
132                 404,
133                 $this->format
134             );
135             break;
136         }
137     }
138
139 }
140