git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

siteprofile.php 7.7 KB
Newer Older
Zach Copley's avatar
Zach Copley committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * A site profile is a set of default settings for a particular style of
 * StatusNet site: public, private, community, etc.
 *
 * 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  Installation
 * @package   StatusNet
 * @author    Zach Copley <zach@status.net>
 * @copyright 2011 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/
 */

31
if (!defined('GNUSOCIAL')) {
Zach Copley's avatar
Zach Copley committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    exit(1);
}

/**
 * Helper class for getting the settings for a particular site profile
 */
class SiteProfile
{
    /**
     * Returns the config settings for a site profile by name
     *
     * @param  string $name name of a site profile
     * @return array  config settings
     */
    static public function getSettings($name)
    {
        $sprofileClass = ucfirst($name) . "Site";

        if (class_exists($sprofileClass)) {
51
            return call_user_func(array($sprofileClass, 'getSettings'));
Zach Copley's avatar
Zach Copley committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        } else {
            common_log(
                LOG_ERR,
                "Unknown site profile '{$name}' specified in config file.",
                __FILE__
            );
            return array();
        }
    }
}

/**
 * Site profile settings contain the list of the default settings (and
 * possibly other information for a particular flavor of StatusNet
 * installation). These will overwrite base defaults in $config global.
 *
 * @category Installation
 * @package  StatusNet
 * @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/
 */
abstract class SiteProfileSettings
{
76 77 78 79
    static function getSettings()
    {
        throw new MethodNotImplementedException(__METHOD__);
    }
80

81 82 83
    static function corePlugins() {
        return common_config('plugins', 'core');
    }
84
    static function defaultPlugins() {
85
        return common_config('plugins', 'default');
86
    }
Zach Copley's avatar
Zach Copley committed
87 88 89 90 91 92 93 94 95 96 97 98 99
}

/**
 * Settings for a 'public' site
 */
class PublicSite extends SiteProfileSettings
{
    /**
     * Get the settings for this site profile
     *
     * @return type array   an array of settings
     */
    static function getSettings() {
100
        global $config;
Zach Copley's avatar
Zach Copley committed
101
        return array(
102
            // We only want to change these values, not replace entire 'site' array
103
            'site' => array_merge(
104 105 106 107 108 109
                $config['site'], array(
                    'inviteonly' => false,
                    'private'    => false,
                    'closed'     => false
                )
            ),
Zach Copley's avatar
Zach Copley committed
110
            'plugins' => array(
111
                'core'    => self::corePlugins(),
112
                'default' => array_merge(self::defaultPlugins(), array(
113
                    'RegisterThrottle'        => array(),
114
                ))
115 116
            ),
            'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
Zach Copley's avatar
Zach Copley committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        );
    }
}

/**
 * Settings for a 'private' site
 *
 * // XXX Too business oriented?
 */
class PrivateSite extends SiteProfileSettings
{
    /**
     * Get the settings for this site profile
     *
     * @return type array  an array of settings
     */
    static function getSettings() {
134
        global $config;
Zach Copley's avatar
Zach Copley committed
135
        return array(
136
            // We only want to change these values, not replace entire 'site' array
137
            'site' => array_merge(
138 139 140 141 142
                $config['site'], array(
                    'inviteonly' => true,
                    'private'    => true,
                )
            ),
Zach Copley's avatar
Zach Copley committed
143
            'plugins' => array(
144
                'core'    => self::corePlugins(),
145
                'default' => array_merge(self::defaultPlugins(), array(
146 147 148
                    'ExtendedProfile'         => array(),
                    'EmailRegistration'       => array(),
                    'MobileProfile'           => array(),
149 150 151
                )),
                'disable-OStatus' => 1,
                'disable-WebFinger' => 1,
Zach Copley's avatar
Zach Copley committed
152
             ),
153
            'public'        => array('localonly' => true),
Zach Copley's avatar
Zach Copley committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
            'profile'       => array('delete' => 'true'),
            'license'       => array('type'   => 'private'),
            'attachments'   => array(
                // Only allow uploads of pictures and MS Office files
                'supported' => array(
                    'image/png',
                    'image/jpeg',
                    'image/gif',
                    'image/svg+xml',
                    'application/pdf',
                    'application/msword',
                    'application/vnd.ms-office',
                    'application/vnd.ms-excel',
                    'application/vnd.ms-powerpoint',
                    'application/ogg'
                )
             ),
            'discovery' => array('cors'   => false) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
        );
    }
}

/**
 * Settings for a 'community' site
 */
class CommunitySite extends SiteProfileSettings
{
    /**
     * Get the settings for this site profile
     *
     * @return type array  an array of settings
     */
    static function getSettings() {
187
        global $config;
Zach Copley's avatar
Zach Copley committed
188
        return array(
189
            // We only want to change these values, not replace entire 'site' array
190
            'site' => array_merge(
191 192
                $config['site'], array(
                    'private'    => false,
193
                    'inviteonly' => true,
194 195 196
                    'closed'     => false
                )
            ),
Zach Copley's avatar
Zach Copley committed
197
            'plugins' => array(
198
                'core'    => self::corePlugins(),
199 200
                'default' => array_merge(self::defaultPlugins(), array(
                ))
201
            ),
202
            'public'    => array('localonly' => true),
203
            'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
Zach Copley's avatar
Zach Copley committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
        );
    }

}

/**
 * Settings for a 'singleuser' site
 */
class SingleuserSite extends SiteProfileSettings
{
    /**
     * Get the settings for this site profile
     *
     * @return type array  an array of settings
     */
    static function getSettings() {
220
        global $config;
Zach Copley's avatar
Zach Copley committed
221 222
        return array(
            'singleuser' => array('enabled' => true),
223
            // We only want to change these values, not replace entire 'site' array
224
            'site' => array_merge(
225 226 227
                $config['site'], array(
                    'private'    => false,
                    'closed'     => true,
228
                    'localonly'  => true,
229 230
                )
            ),
Zach Copley's avatar
Zach Copley committed
231
            'plugins' => array(
232
                'core'    => self::corePlugins(),
233
                'default' => array_merge(self::defaultPlugins(), array(
234
                    'MobileProfile'           => array(),
235 236
                )),
                'disable-Directory' => 1,
237
            ),
238
            'public'    => array('localonly' => true),
239
            'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
Zach Copley's avatar
Zach Copley committed
240 241 242 243
        );
    }

}