You are here

function fb_app_fb in Drupal for Facebook 6.3

Same name and namespace in other branches
  1. 5.2 fb_app.module \fb_app_fb()
  2. 5 fb_app.module \fb_app_fb()
  3. 6.2 fb_app.module \fb_app_fb()
  4. 7.3 fb_app.module \fb_app_fb()

Implementation of hook_fb().

File

./fb_app.module, line 26
Implementation of Drupal for Facebook application.

Code

function fb_app_fb($op, $data, &$return) {
  $fb = isset($data['fb']) ? $data['fb'] : NULL;
  $fb_app = isset($data['fb_app']) ? $data['fb_app'] : NULL;
  if ($op == FB_OP_GET_APP) {

    // Load app data, using the criteria passed in.
    $args = array();
    $where = array();

    // We also support these ways to query an app.  Columns in fb_app table.
    foreach (array(
      'fba_id' => '%d',
      'id' => "'%s'",
      // varchar, not int, in db schema
      'apikey' => "'%s'",
      // deprecated
      'label' => "'%s'",
    ) as $key => $type) {
      if (isset($data[$key])) {
        $where[] = "{$key} = {$type}";
        $args[] = $data[$key];
      }
    }

    // Status is a special query.  Admin pages include disabled apps.
    if (isset($data['status'])) {
      $where[] = "status >= %d";
      $args[] = $data['status'];
    }
    else {
      $where[] = "status > 0";
    }
    if (count($args)) {
      $fb_app = db_fetch_object(db_query("SELECT * FROM {fb_app} fba WHERE " . implode(' AND ', $where), $args));
    }
    if ($fb_app) {
      $return = $fb_app;
    }
  }
  elseif ($op == FB_OP_GET_ALL_APPS) {

    // Return all known applications, including disabled.
    $result = db_query("SELECT fba.* FROM {fb_app} fba");
    while ($app = db_fetch_object($result)) {
      $return[] = $app;
    }
  }
  elseif ($op == FB_OP_POST_INIT) {

    // Include our admin hooks.
    if (fb_is_fb_admin_page()) {
      require drupal_get_path('module', 'fb_app') . '/fb_app.admin.inc';
    }
  }
  elseif ($op == FB_OP_CURRENT_APP) {

    // Try to determine the current application from fb_settings.
    // If we fail, fb_canvas or fb_connect module will hopefully succeed.
    if (!$return && ($id = fb_settings(FB_SETTINGS_ID))) {
      $return = fb_get_app(array(
        'id' => $id,
      ));
    }
    elseif (!$return && ($apikey = fb_settings(FB_SETTINGS_APIKEY))) {

      // deprecated XXX
      $return = fb_get_app(array(
        'apikey' => $apikey,
      ));
    }
  }
}