You are here

function fb_app_fb in Drupal for Facebook 7.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.3 fb_app.module \fb_app_fb()
  4. 6.2 fb_app.module \fb_app_fb()

Implements 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' => ':fba_id',
      'id' => ':id',
      'apikey' => ':apikey',
      // deprecated
      'label' => ':label',
    ) as $key => $placeholder) {
      if (isset($data[$key])) {
        $where[] = "{$key} = {$placeholder}";
        $args[$placeholder] = $data[$key];
      }
    }

    // Status is a special query.  Admin pages include disabled apps.
    if (isset($data['status'])) {
      $where[] = "status >= :status";
      $args[':status'] = $data['status'];
    }
    else {
      $where[] = "status > 0";
    }
    if (count($args)) {
      $fb_app = db_query("SELECT * FROM {fb_app} fba WHERE " . implode(' AND ', $where), $args)
        ->fetchObject();
    }
    if (!empty($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");
    $return = $result
      ->fetchAll();
  }
  elseif ($op == FB_OP_POST_INIT) {

    // Include our admin hooks.
    if (fb_is_fb_admin_page()) {
      require DRUPAL_ROOT . '/' . 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,
      ));
    }
  }
}