]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apistatusnetconfig.php
First revision of new theme, cleaner.
[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     );
64
65     /**
66      * Take arguments for running
67      *
68      * @param array $args $_REQUEST args
69      *
70      * @return boolean success flag
71      */
72     function prepare($args)
73     {
74         parent::prepare($args);
75         return true;
76     }
77
78     /**
79      * Handle the request
80      *
81      * @param array $args $_REQUEST data (unused)
82      *
83      * @return void
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             foreach ($this->keys as $section => $settings) {
97                 $this->elementStart($section);
98                 foreach ($settings as $setting) {
99                     $value = common_config($section, $setting);
100                     if (is_array($value)) {
101                         $value = implode(',', $value);
102                     } else if ($value === false || $value == '0') {
103                         $value = 'false';
104                     } else if ($value === true || $value == '1') {
105                         $value = 'true';
106                     }
107
108                     // return theme logo if there's no site specific one
109                     if (empty($value)) {
110                         if ($section == 'site' && $setting == 'logo') {
111                             $value = Theme::path('logo.png');
112                         }
113                     }
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                 // TRANS: Client error displayed when trying to handle an unknown API method.
138                 _('API method not found.'),
139                 404,
140                 $this->format
141             );
142             break;
143         }
144     }
145
146     /**
147      * Return true if read only.
148      *
149      * MAY override
150      *
151      * @param array $args other arguments
152      *
153      * @return boolean is read only action?
154      */
155     function isReadOnly($args)
156     {
157         return true;
158     }
159 }