You are here

function fb_app_fb in Drupal for Facebook 5.2

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

hook_fb

File

./fb_app.module, line 18
Defines a custom node type that stores a facebook application configuration.

Code

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

    // Load app data, using the criteria passed in
    if ($data['nid']) {
      $fb_app = db_fetch_object(db_query("SELECT * FROM {fb_app} fb INNER JOIN {node} n ON n.nid=fb.nid WHERE fb.nid=%d and status=1", $data['nid']));
    }
    else {
      if ($data['apikey']) {
        $fb_app = db_fetch_object(db_query("SELECT * FROM {fb_app} fb INNER JOIN {node} n ON n.nid=fb.nid WHERE apikey='%s' and status=1", $data['apikey']));
      }
      else {
        if ($data['label']) {
          $fb_app = db_fetch_object(db_query("SELECT * FROM {fb_app} fb INNER JOIN {node} n ON n.nid=fb.nid WHERE label='%s' and status=1", $data['label']));
        }
      }
    }
    if ($fb_app) {
      $return = $fb_app;
    }

    // If we didn't find the app, maybe someone else has written a module that
    // stores app info in a different way.
  }
  else {
    if ($op == FB_OP_GET_ALL_APPS) {

      // Return all known applications
      $result = _fb_app_query_all();
      while ($app = db_fetch_object($result)) {
        $return[] = $app;
      }
    }
    else {
      if ($op == FB_OP_SET_PROPERTIES) {
        $url = url(FB_SETTINGS_APP_NID . '/' . $fb_app->nid . '/' . FB_APP_PATH_EVENT, NULL, NULL, TRUE) . '/';
        $return['uninstall_url'] = $url . FB_APP_EVENT_POST_REMOVE;
        $return['authorize_url'] = $url . FB_APP_EVENT_POST_AUTHORIZE;
      }
      else {
        if ($op == FB_OP_LIST_PROPERTIES) {
          $return[t('Application Name')] = 'application_name';
          $return[t('About URL')] = 'about_url';
          $return[t('Post-Authorize Callback URL')] = 'authorize_url';
          $return[t('Post-Remove Callback URL')] = 'uninstall_url';
        }
      }
    }
  }
}