Skip to content
fb.install 3.93 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
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);
  }
  $num_deleted = db_delete("variable")
    ->condition('name', 'fb_language_%', 'like')
    ->execute();
function _fb_install_set_weight() {
  db_update('system')
    ->fields(array(
      'weight' => -2
    ))
    ->condition('name', 'fb')
    ->execute();
// TODO AVA doesn't appear to be called by anything
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();
    $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'))));

}