]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusnetconfig.php
Merge branch 'qna' into 1.0.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 class ApiStatusnetConfigAction extends ApiAction
50 {
51     var $keys = array(
52         'site' => array('name', 'server', 'theme', 'path', 'logo', 'fancy', 'language',
53                         'email', 'broughtby', 'broughtbyurl', 'timezone', 'closed',
54                         'inviteonly', 'private', 'textlimit', 'ssl', 'sslserver', 'shorturllength'),
55         'license' => array('type', 'owner', 'url', 'title', 'image'),
56         'nickname' => array('featured'),
57         'profile' => array('biolimit'),
58         'group' => array('desclimit'),
59         'notice' => array('contentlimit'),
60         'throttle' => array('enabled', 'count', 'timespan'),
61         'xmpp' => array('enabled', 'server', 'port', 'user'),
62         'integration' => array('source'),
63         'attachments' => array('uploads', 'file_quota')
64     );
65
66     /**
67      * Take arguments for running
68      *
69      * @param array $args $_REQUEST args
70      *
71      * @return boolean success flag
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     function handle($args)
87     {
88         parent::handle($args);
89
90         switch ($this->format) {
91         case 'xml':
92             $this->initDocument('xml');
93             $this->elementStart('config');
94
95             // XXX: check that all sections and settings are legal XML elements
96
97             foreach ($this->keys as $section => $settings) {
98                 $this->elementStart($section);
99                 foreach ($settings as $setting) {
100                     $value = $this->setting($section, $setting);
101                     if (is_array($value)) {
102                         $value = implode(',', $value);
103                     } else if ($value === false || $value == '0') {
104                         $value = 'false';
105                     } else if ($value === true || $value == '1') {
106                         $value = 'true';
107                     }
108
109                     // return theme logo if there's no site specific one
110                     if (empty($value)) {
111                         if ($section == 'site' && $setting == 'logo') {
112                             $value = Theme::path('logo.png');
113                         }
114                     }
115
116                     $this->element($setting, null, $value);
117                 }
118                 $this->elementEnd($section);
119             }
120             $this->elementEnd('config');
121             $this->endDocument('xml');
122             break;
123         case 'json':
124             $result = array();
125             foreach ($this->keys as $section => $settings) {
126                 $result[$section] = array();
127                 foreach ($settings as $setting) {
128                     $result[$section][$setting]
129                         = $this->setting($section, $setting);
130                 }
131             }
132             $this->initDocument('json');
133             $this->showJsonObjects($result);
134             $this->endDocument('json');
135             break;
136         default:
137             $this->clientError(
138                 // TRANS: Client error displayed when trying to handle an unknown API method.
139                 _('API method not found.'),
140                 404,
141                 $this->format
142             );
143             break;
144         }
145     }
146
147     function setting($section, $key) {
148         $result = common_config($section, $key);
149         if ($key == 'file_quota') {
150             // hack: adjust for the live upload limit
151             if (common_config($section, 'uploads')) {
152                 $max = ImageFile::maxFileSizeInt();
153             } else {
154                 $max = 0;
155             }
156             return min($result, $max);
157         }
158         return $result;
159     }
160
161     /**
162      * Return true if read only.
163      *
164      * MAY override
165      *
166      * @param array $args other arguments
167      *
168      * @return boolean is read only action?
169      */
170     function isReadOnly($args)
171     {
172         return true;
173     }
174 }