]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusnetconfig.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline 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 /**
36  * Gives a full dump of configuration variables for this instance
37  * of StatusNet, minus variables that may be security-sensitive (like
38  * passwords).
39  * URL: http://identi.ca/api/statusnet/config.(xml|json)
40  * Formats: xml, json
41  *
42  * @category API
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
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', 'logo', 'fancy', 'language',
54                         'email', 'broughtby', 'broughtbyurl', 'timezone', 'closed',
55                         'inviteonly', 'private', 'textlimit', 'ssl', 'sslserver', 'shorturllength'),
56         'license' => array('type', 'owner', 'url', 'title', 'image'),
57         'nickname' => array('featured'),
58         'profile' => array('biolimit'),
59         'group' => array('desclimit'),
60         'notice' => array('contentlimit'),
61         'throttle' => array('enabled', 'count', 'timespan'),
62         'xmpp' => array('enabled', 'server', 'port', 'user'),
63         'integration' => array('source')
64     );
65
66     /**
67      * Take arguments for running
68      *
69      * @param array $args $_REQUEST args
70      *
71      * @return boolean success flag
72      *
73      */
74
75     function prepare($args)
76     {
77         parent::prepare($args);
78         return true;
79     }
80
81     /**
82      * Handle the request
83      *
84      * @param array $args $_REQUEST data (unused)
85      *
86      * @return void
87      */
88
89     function handle($args)
90     {
91         parent::handle($args);
92
93         switch ($this->format) {
94         case 'xml':
95             $this->initDocument('xml');
96             $this->elementStart('config');
97
98             // XXX: check that all sections and settings are legal XML elements
99
100             common_debug(var_export($this->keys, true));
101
102             foreach ($this->keys as $section => $settings) {
103                 $this->elementStart($section);
104                 foreach ($settings as $setting) {
105                     $value = common_config($section, $setting);
106                     if (is_array($value)) {
107                         $value = implode(',', $value);
108                     } else if ($value === false) {
109                         $value = 'false';
110                     } else if ($value === true) {
111                         $value = 'true';
112                     }
113                     $this->element($setting, null, $value);
114                 }
115                 $this->elementEnd($section);
116             }
117             $this->elementEnd('config');
118             $this->endDocument('xml');
119             break;
120         case 'json':
121             $result = array();
122             foreach ($this->keys as $section => $settings) {
123                 $result[$section] = array();
124                 foreach ($settings as $setting) {
125                     $result[$section][$setting]
126                         = common_config($section, $setting);
127                 }
128             }
129             $this->initDocument('json');
130             $this->showJsonObjects($result);
131             $this->endDocument('json');
132             break;
133         default:
134             $this->clientError(
135                 _('API method not found.'),
136                 404,
137                 $this->format
138             );
139             break;
140         }
141     }
142
143     /**
144      * Return true if read only.
145      *
146      * MAY override
147      *
148      * @param array $args other arguments
149      *
150      * @return boolean is read only action?
151      */
152
153     function isReadOnly($args)
154     {
155         return true;
156     }
157
158 }
159