]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Do not display site pages when in Walled Garden mode, excepting system-defined whitelist.
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 11 May 2010 21:37:12 +0000 (21:37 +0000)
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 11 May 2010 21:37:12 +0000 (21:37 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@6004 36083f99-b078-4883-b0ff-0f9b5a30f544

actions/admin/site/update_advanced.php
actions/systemsettings/install.php
engine/lib/elgglib.php
engine/lib/sites.php
engine/lib/upgrades/2010050701.php
views/default/admin/site/advanced.php

index 7e6bd0cc6576c6061e0a54f34331d6dad3a0f66f..e65919ce1f7a14afb7bb89783c91e6b6a137054c 100644 (file)
@@ -56,6 +56,13 @@ if (datalist_get('default_site')) {
        } else {
                set_config('allow_registration', FALSE, $site->getGUID());
        }
+       
+       // setup walled garden
+       if (get_input('walled_garden', FALSE)) {
+               set_config('walled_garden', TRUE, $site->getGUID());
+       } else {
+               set_config('walled_garden', FALSE, $site->getGUID());
+       }
 
        $https_login = get_input('https_login');
        if ($https_login) {
index 3b841caf96480ab0c29bf5a75f9f19d1799313c7..6f3b75a3d3305051c235ff473e8bf0ef23c3ab75 100644 (file)
@@ -69,6 +69,7 @@ if (get_input('settings') == 'go') {
                set_config('language', get_input('language'), $site->getGUID());
                set_config('default_access', get_input('default_access'), $site->getGUID());
                set_config('allow_registration', TRUE, $site->getGUID());
+               set_config('walled_garden', FALSE, $site->getGUID());
 
                $debug = get_input('debug');
                if ($debug) {
index 9ee85c559d549d0da32786dce60c10034babd9d4..4e141bb84e81ebb9651421207a87263b56999685 100644 (file)
@@ -3107,16 +3107,28 @@ function __elgg_shutdown_hook() {
 function elgg_init() {
        // Page handler for JS
        register_page_handler('js','js_page_handler');
-
+       
        // Register an event triggered at system shutdown
        register_shutdown_function('__elgg_shutdown_hook');
 }
 
+function elgg_walled_garden_index() {
+       global $CONFIG;
+       
+       $login = elgg_view('account/forms/login');
+       $layout = elgg_view_layout('one_column', $login);
+       
+       echo page_draw('', $layout);
+       return TRUE;
+}
+
 /**
  * Boot Elgg
  * @return unknown_type
  */
 function elgg_boot() {
+       global $CONFIG;
+       
        // Actions
        register_action('comments/add');
        register_action('comments/delete');
@@ -3126,6 +3138,11 @@ function elgg_boot() {
        elgg_view_register_simplecache('css');
        elgg_view_register_simplecache('js/friendsPickerv1');
        elgg_view_register_simplecache('js/initialise_elgg');
+       
+       // check for external page view
+       if (isset($CONFIG->site) && $CONFIG->site instanceof ElggSite) {
+               $CONFIG->site->check_walled_garden();
+       }
 }
 
 /**
index 13521a257a107f49df81195817875c4476972b3c..c976384c2f85f9348e0a7e0345b9425ef0d99df6 100644 (file)
@@ -243,6 +243,51 @@ class ElggSite extends ElggEntity {
                        'url',
                ));
        }
+       
+       public function check_walled_garden() {
+               global $CONFIG;
+               
+               if ($CONFIG->walled_garden && !isloggedin()) {
+                       register_plugin_hook('index', 'system', 'elgg_walled_garden_index');
+                       
+                       if (!$this->is_public_page()) {
+                               register_error(elgg_echo('walled_garden:private_page') . current_page_url());
+                               forward();
+                       }
+               }
+       }
+       
+       public function is_public_page($url='') {
+               global $CONFIG;
+               
+               if (empty($url)) {
+                       $url = current_page_url();
+                       
+                       // do not check against URL queries
+                       if ($pos = strpos($url, '?')) {
+                               $url = substr($url, 0, $pos);
+                       }
+               }
+               
+               // default public pages
+               $public = array(
+                       $CONFIG->url,
+                       "{$CONFIG->url}action/login",
+                       "{$CONFIG->url}upgrade.php",
+               );
+               
+               // include a hook for plugin authors to include public pages
+               
+               // lookup admin-specific public pages
+               
+               // allow public pages
+               if (in_array($url, $public)) {
+                       return TRUE;
+               }
+               
+               // non-public page
+               return FALSE;
+       }
 }
 
 /**
index 33e4b5bae1556694116c2633953b098d25a3200d..4a02a77c68d581b3b8de47d51fafd3bc4d3b9529 100644 (file)
@@ -8,8 +8,10 @@ $access = elgg_set_ignore_access(TRUE);
 if (is_plugin_enabled('walledgarden')) {
        disable_plugin('walledgarden');
        set_config('allow_registration', FALSE);
+       set_config('walled_garden', TRUE);
 } else {
        set_config('allow_registration', TRUE);
+       set_config('walled_garden', FALSE);
 }
 
 elgg_set_ignore_access($access);
index e8c6e9b9ac44790284bdc36cf8a3a97dd5212de9..35c57356d545d616ea1c4bddc90033f39b7ef689 100644 (file)
@@ -33,6 +33,7 @@ $form_body .= "<p>" . elgg_echo('installation:debug');
 $form_body .= elgg_view('input/pulldown', array('options_values' => $debug_options, 'internalname' => 'debug', 'value' => $vars['config']->debug));
 $form_body .= '</p>';
 
+// control new user registration
 $options = array(
        'options' => array(elgg_echo('installation:registration:label')),
        'internalname' => 'allow_registration',
@@ -41,6 +42,15 @@ $options = array(
 $form_body .= '<p>' . elgg_echo('installation:registration:description');
 $form_body .= '<br />' .elgg_view('input/checkboxes', $options) . '</p>';
 
+// control walled garden
+$options = array(
+       'options' => array(elgg_echo('installation:walled_garden:label')),
+       'internalname' => 'walled_garden',
+       'value' => $vars['config']->walled_garden ? elgg_echo('installation:walled_garden:label') : '',
+);
+$form_body .= '<p>' . elgg_echo('installation:walled_garden:description');
+$form_body .= '<br />' . elgg_view('input/checkboxes', $options) . '</p>';
+
 $form_body .= "<p>" . elgg_echo('installation:httpslogin') . "<br />" .elgg_view("input/checkboxes", array('options' => array(elgg_echo('installation:httpslogin:label')), 'internalname' => 'https_login', 'value' => ($vars['config']->https_login ? elgg_echo('installation:httpslogin:label') : "") )) . "</p>";
 
 $form_body .= "<p>" . elgg_echo('installation:disableapi') . "<br />";