Skip to content
fb.install 5.43 KiB
Newer Older
/**
 * @file
 * Install file to support fb.module.
Dave Cohen's avatar
Dave Cohen committed
 *
/**
 * Implementation of hook_requirements().
 */
function fb_requirements($phase) {
  $t = get_t();
  $items = array();
Dave Cohen's avatar
Dave Cohen committed

  // Disable these checks at install time, because failure then causes more
  // problems, due to module dependencies and Drupal's poor handling of
  // requirement errors.
Dave Cohen's avatar
Dave Cohen committed

  $status = array('title' => $t('Drupal for Facebook Settings'));
  if (function_exists('fb_settings')) {
    if ($phase == 'runtime') {
      $status['value'] = $t('Included');
    }
    $status['severity'] = REQUIREMENT_OK;
  }
  else {
    if ($phase == 'runtime') {
      $status['value'] = $t('Not included');
    }
    $status['severity'] = REQUIREMENT_ERROR;
    $path = drupal_get_path('module', 'fb');
    if (!$path)
      // Not set during install.php
      $path = 'modules/fb';
Dave Cohen's avatar
Dave Cohen committed

    $status['description'] = $t('Add something like <strong>include "%path";</strong> to your settings.php.', array('%path' => $path . '/fb_settings.inc'));
  }
  $items[] = $status;
Dave Cohen's avatar
Dave Cohen committed

  $status = array('title' => $t('Facebook PHP SDK'));
  $fb_platform = variable_get(FB_VAR_API_FILE, 'sites/all/libraries/facebook-php-sdk/src/facebook.php');
Dave Cohen's avatar
Dave Cohen committed
  if (class_exists('Facebook')) {
    $status['description'] = $t('Facebook PHP SDK loaded.');
Dave Cohen's avatar
Dave Cohen committed
    $status['severity'] = REQUIREMENT_OK;
    $status['value'] = $t('Loaded');
  }
  elseif (include($fb_platform)) { // include() better than file_exists().
    $status['description'] = $t('Facebook SDK found at %path',
                                array('%path' => $fb_platform));
    $status['severity'] = REQUIREMENT_OK;
    if ($phase == 'runtime') {
      $status['value'] = $t('Found');
    }
  }
  else {
    $status['description'] = $t('Facebook client API not found.  See modules/fb/README.txt');
    $status['severity'] = REQUIREMENT_ERROR;
    if ($phase == 'runtime') {
      $status['value'] = $t('Not found');
    }
  }
  $items[] = $status;
Dave Cohen's avatar
Dave Cohen committed


function fb_install() {
  _fb_install_set_weight();

  drupal_set_message(st('Drupal for Facebook modules enabled.  Be sure to install facebook\'s client libraries and modify your settings.php!  Read modules/fb/README.txt and <a href="!doc_url" target="_blank">the online documentation for Drupal for Facebook</a> for details.',
      array('!doc_url' => 'http://drupal.org/node/195035')
Dave Cohen's avatar
Dave Cohen committed
                       ));
  foreach (array(
             FB_VAR_LANGUAGE_OVERRIDE,
             FB_VAR_JS_SDK,
             FB_VAR_API_FILE,
             FB_VAR_JS_CHANNEL,
             FB_VAR_VERBOSE,
             FB_VAR_APIKEY,
           ) as $var) {
    variable_del($var);
  }
  db_query("DELETE FROM {variable} WHERE name like 'fb_language_%'");
function _fb_install_set_weight() {
  db_query("UPDATE {system} SET weight=-2 WHERE name='fb'");
}

function fb_update_6000() {
  $ret = array();
Dave Cohen's avatar
Dave Cohen committed
  //_fb_install_alter_session_table(); // no longer need to do this.
  $ret = array();
  $message = 'IMPORTANT: Drupal for Facebook modules have moved around!  Check your <em>modules/fb/</em> directory, and make sure you do not have duplicates of fb_feed.module or fb_views.module.  If so, delete the entire <em>modules/fb/</em> directory and re-install.';
  drupal_set_message($message);
  watchdog('fb', $message);
  return $ret;
}

function fb_update_6002() {
  $ret = array();
  $message = 'IMPORTANT: Drupal for Facebook connect URLs have changed.  You must manually edit each of your applications.  Pressing the save button will update the connect URL property.';
  drupal_set_message($message);
Dave Cohen's avatar
Dave Cohen committed
  watchdog('fb', $message);
}


function fb_update_6003() {
  $ret = array();
  $result = db_query("SELECT * FROM {fb_app}");
  $items = array();
  while ($data = db_fetch_object($result)) {
    $items[] = l($data->title, 'admin/build/fb/app/' . $data->label . '/fb/set_props');
  }
  if (count($items)) {
    $message = 'Manual action required!.  Callback URLs for canvas page applications have changed.  Click below to update the settings, on facebook, for each of your applications.';
    $message .= theme('item_list', $items);
    drupal_set_message($message);
    watchdog('fb', $message, array(), WATCHDOG_WARNING);
  }

  $ret[] = array('success' => FALSE, 'query' => t('Manual action required.  Go to !link and set properties for each facebook application.', array('!link' => l('Facebook Applications', 'admin/build/fb'))));
  return $ret;
Dave Cohen's avatar
Dave Cohen committed
 * Convenience function to display messages like the one from fb_app_update_6003.
 */
function fb_install_property_message(&$ret, $reason) {
  $result = db_query("SELECT * FROM {fb_app}");
  $items = array();
  while ($data = db_fetch_object($result)) {
    $items[] = l($data->title, 'admin/build/fb/app/' . $data->label . '/fb/set_props', array('attributes' => array('target' => '_blank')));
  }
  if (count($items)) {
    $message = 'Manual action required!.  !reason  Click below to update the settings, on facebook, for each of your applications.  !list';
    $args = array(
      '!reason' => $reason,
      '!list' => theme('item_list', $items),
    );
    drupal_set_message(t($message, $args), 'warning', FALSE);
    watchdog('fb', $message, $args, WATCHDOG_WARNING);
  }

  $ret[] = array('success' => FALSE, 'query' => t('Manual action required.  Go to !link and set properties for each facebook application.', array('!link' => l('Facebook Applications', 'admin/build/fb'))));

}