public function site()
    {
        if (!userHasPermission('admin:admin:settings:site:.*')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oInput = Factory::service('Input');
        if ($oInput->post()) {

            $aSettings = [];

            if (userHasPermission('admin:admin:settings:site:customjscss')) {
                $aSettings['site_custom_js']     = $oInput->post('site_custom_js');
                $aSettings['site_custom_css']    = $oInput->post('site_custom_css');
                $aSettings['site_custom_markup'] = $oInput->post('site_custom_markup');
            }

            if (userHasPermission('admin:admin:settings:site:analytics')) {
                $aSettings['google_analytics_account'] = $oInput->post('google_analytics_account');
            }

            if (userHasPermission('admin:admin:settings:site:maintenance')) {
                $sRawIPs                                 = $oInput->post('maintenance_mode_whitelist');
                $aSettings['maintenance_mode_enabled']   = (bool) $oInput->post('maintenance_mode_enabled');
                $aSettings['maintenance_mode_whitelist'] = $this->prepareWhitelist($sRawIPs);
                $aSettings['maintenance_mode_title']     = $oInput->post('maintenance_mode_title');
                $aSettings['maintenance_mode_body']      = $oInput->post('maintenance_mode_body');
            }

            if (!empty($aSettings)) {

                $oAppSettingService = Factory::service('AppSetting');
                if ($oAppSettingService->set($aSettings, 'site')) {
                    $this->data['success'] = 'Site settings have been saved.';
                } else {
                    $this->data['error'] = 'There was a problem saving site settings.';
                }

            } else {
                $this->data['message'] = 'No settings to save.';
            }
        }

        // --------------------------------------------------------------------------

        //  Get data
        $this->data['settings'] = appSetting(null, 'app', true);

        // --------------------------------------------------------------------------

        //  Set page title
        $this->data['page']->title = 'Settings &rsaquo; Site';

        // --------------------------------------------------------------------------

        //  Load assets
        $oAsset = Factory::service('Asset');
        $oAsset->load('nails.admin.settings.min.js', 'NAILS');
        $oAsset->load('nails.admin.admin.settings.min.js', 'NAILS');

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('site');
    }