Hello,

first off, I know that it is stated in the README file that PHP 5.2 is the minimum requirement for this module.

The problem arises in the fact that the module does not use the standard Drupal module way of declaring that, namely adding the simple line
php = 5.2
in the info file, allowing a user to enable it (with the downloaded library) using a PHP version less than the minimum. On a normal production system, this will result in a white screen of death, since the module will crash the whole website installation, which users find undesirable.

Even worse, the module does NOT need PHP 5.2 per se -- which is why I assume it is not set as a strict requirement. It only requires the JSON extension, which comes by default with PHP 5.2, but can be added to earlier versions ( it also needs the cURL extension, but that is just assumed to be there, it's not mentioned in the README ).

And since just whining never accomplishes much, here are two proposed solutions:

  • Add a PHP version restriction in the module's .info file. Though not very elegant, it will make certain that users with limited experience will not screw up their sites
  • Add a bit of handling code in facebook.php so that the module doesn't just crash the site, but instead works with the problem.

I hope that you will agree that the second option is preferable. I've implemented a small patch that replaced the first few lines, and does not interfere if the script is used outside Drupal. However, should either the JSON or the cURL modules not be loaded, it will gracefully throw a Drupal error about the situation, and disable the module to avoid performance degradation until the situation is resolved.

Patch change:
replace the first few lines of /facebook-php-sdk/src/facebook.php that normally are

if (!function_exists('curl_init')) {
  throw new Exception('Facebook needs the CURL PHP extension.');
}
if (!function_exists('json_decode')) {
  throw new Exception('Facebook needs the JSON PHP extension.');
}

with

if (!function_exists('curl_init')) {
  // If Drupal is bootstrapped, and a user with admin priviledges is browsing
  if ( function_exists('user_access') && user_access('administer site configuration') ) {
    // Set an error message about this
    drupal_set_message("Module FBConnect needs the cURL PHP extension, this module will now be disabled", 'error');
    // And disable our modules
    module_disable(array('fbconnect', 'fbconnect-fb_social integration', 'fbconnect_invite','fbconnect_stream_publish'));
    return;
  } else {
    throw new Exception('Facebook needs the CURL PHP extension.'); 
  }
}

if (!function_exists('json_decode')) {
  // If Drupal is bootstrapped, and a user with admin priviledges is browsing
  if ( function_exists('user_access') && user_access('administer site configuration') ) {
    // Set an error message about this
    drupal_set_message("Module FBConnect needs the JSON PHP extension, this module will now be disabled", 'error');
    // And disable our modules
    module_disable(array('fbconnect', 'fbconnect-fb_social integration', 'fbconnect_invite','fbconnect_stream_publish'));
    return;
  } else {
    throw new Exception('Facebook needs the JSON PHP extension.');
  }
}

I hope this helps other that find themselves afflicted with this problem at some point.

Comments

vectoroc’s picture

Category: bug » task
Status: Active » Needs review

perhaps you know that changing third party code is bad practice. I've modified hook_requirements so it wont cause WSOD

http://github.com/vectoroc/fbconnect/commit/446a8b77e1e2cd6dac00b9bcce9d...

hexblot’s picture

Status: Needs review » Reviewed & tested by the community

It is always preferable to avoid changing third party code indeed, thank you for the alternative solution.

I tested the proposed changes, and they indeed prevent WSOD.
On a side note, there is no warning that the module is still inoperable, unless he manually navigates to the status page, but I understand that is the intended behavior.

nancydru’s picture

These requirements need to be stated on the project page as well.

  • vectoroc committed 6155e3a on
    #926862 : prevent to popup XSS error in IE8 at first page loading #...
  • vectoroc committed c3a5041 on
    #766920 by mvc : added theme functions for user profile tab #911432 by...
id.tarzanych’s picture

Status: Reviewed & tested by the community » Closed (won't fix)