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