diff --git a/index.php b/index.php index 7043ec5ce4..044010f326 100755 --- a/index.php +++ b/index.php @@ -14,6 +14,7 @@ $cidReset = true; require_once 'main/inc/global.inc.php'; require_once 'main/chat/chat_functions.lib.php'; +require_once 'main/auth/external_login/facebook.inc.php'; // The section (for the tabs). $this_section = SECTION_CAMPUS; @@ -23,6 +24,11 @@ if (!api_is_anonymous()) { $header_title = " "; } +// Facebook connexion, if activated +if (api_is_facebook_auth_activated() && !api_get_user_id()) { + facebookConnect(); +} + $controller = new IndexManager($header_title); //Actions @@ -111,11 +117,6 @@ if (api_get_setting('display_categories_on_homepage') == 'true') { $controller->tpl->assign('course_category_block', $controller->return_courses_in_categories()); } -// Facebook connexion, if activated -if (api_is_facebook_auth_activated() && !api_get_user_id()) { - facebook_connect(); -} - $controller->set_login_form(); //@todo move this inside the IndexManager diff --git a/main/auth/external_login/facebook.inc.php b/main/auth/external_login/facebook.inc.php index d1d3785c7a..c80174b8ee 100755 --- a/main/auth/external_login/facebook.inc.php +++ b/main/auth/external_login/facebook.inc.php @@ -13,7 +13,6 @@ require_once dirname(__FILE__) . '/../../inc/global.inc.php'; require_once dirname(__FILE__) . '/facebook.init.php'; - require_once dirname(__FILE__) . '/facebook-php-sdk/autoload.php'; use Facebook\FacebookSession; @@ -55,7 +54,7 @@ function facebookConnect() $username = changeToValidChamiloLogin($graphObject->getProperty('email')); $email = $graphObject->getProperty('email'); $locale = $graphObject->getProperty('locale'); - $language = getLanguageForFacebook($locale); + $language = facebookPluginGetLanguage($locale); if (!$language) { $language='en_US'; } @@ -70,16 +69,16 @@ function facebookConnect() 'language' => $language, 'password' => DEFAULT_PASSWORD, 'auth_source' => 'facebook', - //'courses' => $user_info['courses'], - //'profile_link' => $user_info['profile_link'], - //'worldwide_bu' => $user_info['worlwide_bu'], - //'manager' => $user_info['manager'], + // 'courses' => $user_info['courses'], + // 'profile_link' => $user_info['profile_link'], + // 'worldwide_bu' => $user_info['worlwide_bu'], + // 'manager' => $user_info['manager'], 'extra' => array() ); $chamiloUinfo = api_get_user_info_from_email($email); if ($chamiloUinfo === false) { - //we have to create the user + // we have to create the user $chamilo_uid = external_add_user($u); if ($chamilo_uid !== false) { $_user['user_id'] = $chamilo_uid; @@ -90,7 +89,8 @@ function facebookConnect() } else { return false; } - } else {//User already exists, update info and login + } else { + // User already exists, update info and login $chamilo_uid = $chamiloUinfo['user_id']; $u['user_id'] = $chamilo_uid; external_update_user($u); @@ -110,7 +110,7 @@ function facebookConnect() /** * Get facebook login url for the platform - * @return mixed + * @return string */ function facebookGetLoginUrl() { @@ -123,8 +123,8 @@ function facebookGetLoginUrl() } /** + * Return a valid Chamilo login * Chamilo login only use characters lettres, des chiffres et les signes _ . - - * return a string containing valid chamilo login characters * @param $in_txt * @return mixed */ @@ -138,13 +138,18 @@ function changeToValidChamiloLogin($in_txt) * @param string $language * @return bool */ -function getLanguageForFacebook($language = 'en_US') +function facebookPluginGetLanguage($language = 'en_US') { $language = substr($language, 0, 2); - $sqlResult = Database::query("SELECT english_name FROM ".Database::get_main_table(TABLE_MAIN_LANGUAGE)." WHERE available = 1 AND isocode = '$language'"); + $sqlResult = Database::query( + "SELECT english_name FROM ". + Database::get_main_table(TABLE_MAIN_LANGUAGE). + " WHERE available = 1 AND isocode = '$language'" + ); if (Database::num_rows($sqlResult)) { $result = Database::fetch_array($sqlResult); return $result['english_name']; } return false; -} +} + diff --git a/main/auth/external_login/facebook.init.php b/main/auth/external_login/facebook.init.php index 0840271a6f..13790a3666 100755 --- a/main/auth/external_login/facebook.init.php +++ b/main/auth/external_login/facebook.init.php @@ -15,11 +15,10 @@ * Facebook application setting * */ - - - //Loads the portal facebook settings /** + * Facebook application setting + * Loads the portal facebook settings * See facebook section of the auth.conf.php file */