We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

apistatusnetconfig.php 5.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * Dump of configuration variables
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  API
 * @package   StatusNet
Zach Copley's avatar
Zach Copley committed
24
 * @author    Evan Prodromou <evan@status.net>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 * @author    Zach Copley <zach@status.net>
 * @copyright 2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

if (!defined('STATUSNET')) {
    exit(1);
}

/**
 * Gives a full dump of configuration variables for this instance
 * of StatusNet, minus variables that may be security-sensitive (like
 * passwords).
 * URL: http://identi.ca/api/statusnet/config.(xml|json)
 * Formats: xml, json
 *
 * @category API
 * @package  StatusNet
Zach Copley's avatar
Zach Copley committed
44
 * @author   Evan Prodromou <evan@status.net>
45 46 47 48
 * @author   Zach Copley <zach@status.net>
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
49
class ApiStatusnetConfigAction extends ApiAction
50 51
{
    var $keys = array(
52 53 54 55
        'site' => array('name', 'server', 'theme', 'path', 'logo', 'fancy', 'language',
                        'email', 'broughtby', 'broughtbyurl', 'timezone', 'closed',
                        'inviteonly', 'private', 'textlimit', 'ssl', 'sslserver', 'shorturllength'),
        'license' => array('type', 'owner', 'url', 'title', 'image'),
56
        'nickname' => array('featured'),
57 58 59
        'profile' => array('biolimit'),
        'group' => array('desclimit'),
        'notice' => array('contentlimit'),
60
        'throttle' => array('enabled', 'count', 'timespan'),
61
        'xmpp' => array('enabled', 'server', 'port', 'user'),
62 63
        'integration' => array('source'),
        'attachments' => array('uploads', 'file_quota')
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    );

    /**
     * Take arguments for running
     *
     * @param array $args $_REQUEST args
     *
     * @return boolean success flag
     */
    function prepare($args)
    {
        parent::prepare($args);
        return true;
    }

    /**
     * Handle the request
     *
     * @param array $args $_REQUEST data (unused)
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);

        switch ($this->format) {
        case 'xml':
92
            $this->initDocument('xml');
93 94 95 96 97 98 99
            $this->elementStart('config');

            // XXX: check that all sections and settings are legal XML elements

            foreach ($this->keys as $section => $settings) {
                $this->elementStart($section);
                foreach ($settings as $setting) {
100
                    $value = $this->setting($section, $setting);
101 102
                    if (is_array($value)) {
                        $value = implode(',', $value);
103
                    } else if ($value === false || $value == '0') {
104
                        $value = 'false';
105
                    } else if ($value === true || $value == '1') {
106 107
                        $value = 'true';
                    }
108 109 110 111 112 113 114 115

                    // return theme logo if there's no site specific one
                    if (empty($value)) {
                        if ($section == 'site' && $setting == 'logo') {
                            $value = Theme::path('logo.png');
                        }
                    }

116 117 118 119 120
                    $this->element($setting, null, $value);
                }
                $this->elementEnd($section);
            }
            $this->elementEnd('config');
121
            $this->endDocument('xml');
122 123 124 125 126 127 128
            break;
        case 'json':
            $result = array();
            foreach ($this->keys as $section => $settings) {
                $result[$section] = array();
                foreach ($settings as $setting) {
                    $result[$section][$setting]
129
                        = $this->setting($section, $setting);
130 131
                }
            }
132 133 134
            $this->initDocument('json');
            $this->showJsonObjects($result);
            $this->endDocument('json');
135 136 137
            break;
        default:
            $this->clientError(
138
                // TRANS: Client error displayed when coming across a non-supported API method.
139
                _('API method not found.'),
140 141 142 143 144 145 146
                404,
                $this->format
            );
            break;
        }
    }

147 148 149 150 151 152 153 154 155 156 157 158 159 160
    function setting($section, $key) {
        $result = common_config($section, $key);
        if ($key == 'file_quota') {
            // hack: adjust for the live upload limit
            if (common_config($section, 'uploads')) {
                $max = ImageFile::maxFileSizeInt();
            } else {
                $max = 0;
            }
            return min($result, $max);
        }
        return $result;
    }

161 162 163 164 165 166 167 168 169 170 171 172 173
    /**
     * Return true if read only.
     *
     * MAY override
     *
     * @param array $args other arguments
     *
     * @return boolean is read only action?
     */
    function isReadOnly($args)
    {
        return true;
    }
174
}