You are here

function simple_fb_connect_initialize in Simple FB Connect 7.2

Initializes the FB App.

Return value

TRUE if initialization was OK. FALSE otherwise.

3 calls to simple_fb_connect_initialize()
simple_fb_connect_redirect_to_fb in ./simple_fb_connect.module
Page callback for /user/simple-fb-connect.
simple_fb_connect_return_from_fb in ./simple_fb_connect.module
Page callback for /user/simple-fb-connect/return.
simple_fb_connect_user_logout in ./simple_fb_connect.module
Implemets hook_user_logout().

File

./simple_fb_connect.module, line 273
Simple Facebook Login Module for Drupal Sites.

Code

function simple_fb_connect_initialize() {

  // Check that PHP version is 5.4 or higher.
  if (version_compare(phpversion(), '5.4.0', '<')) {
    drupal_set_message(t('Simple FB Connect is not configured properly.'), 'error');
    watchdog('simple_fb_connect', 'Facebook PHP SDK v4 requires PHP 5.4 or higher. Your PHP version is @version', array(
      '@version' => phpversion(),
    ), WATCHDOG_ERROR);
    return FALSE;
  }

  // Check that Facebook PHP SDK is properly installed and that the version is 4.0.x.
  $sdk = libraries_detect('facebook-php-sdk-v4');
  if (!is_array($sdk) || !$sdk['installed'] || $sdk['version'] < '4.0' || $sdk['version'] >= '4.1') {
    drupal_set_message(t('The Facebook PHP SDK is not properly installed.'), 'error');
    watchdog('simple_fb_connect', 'Facebook PHP SDK 4.0.x not found on sites/all/libraries/facebook-php-sdk-v4', array(), WATCHDOG_ERROR);
    return FALSE;
  }

  // Check that the module is configured properly.
  $app_id = variable_get('simple_fb_connect_appid', 0);
  $app_secret = variable_get('simple_fb_connect_skey', 0);
  $api_version = variable_get('simple_fb_connect_api_version', 0);
  if (!$app_id || !$app_secret || !$api_version) {
    drupal_set_message(t('Simple FB Connect not configured properly.'), 'error');
    watchdog('simple_fb_connect', 'Could not initialize FB App. Define App ID, App Secret and API Version on module settings.', array(), WATCHDOG_ERROR);
    return FALSE;
  }

  // If we have not returned FALSE, SDK is found and module has been configured.
  FacebookSession::setDefaultApplication($app_id, $app_secret);
  return TRUE;
}