You are here

function fb_app_fb in Drupal for Facebook 5

Same name and namespace in other branches
  1. 5.2 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 12
Defines a custom node type that stores a facebook application configuration.

Code

function fb_app_fb($fb, $fb_app, $op, &$return, $data) {

  //drupal_set_message("fb_app_fb($fb_app->label, $op)" . dpr($fb_app, 1));
  if ($op == FB_OP_GET_APP) {

    // This operation determines which app the request is for.  Theoretically,
    // the allows fb_app and other app-defining modules to co-exist.  We need
    // to determine if the app is one of ours and if so, return the app
    // details.
    // If apikey or nid was passed to us, use that
    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 ($apikey = $_REQUEST[FB_APP_REQ_API_KEY]) {

          // If facebook has passed the app key, let's use that.
          $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", $apikey));
        }
        else {
          if (function_exists('fb_settings')) {

            // See settings.inc
            if ($nid = fb_settings(FB_SETTINGS_APP_NID)) {

              // Here if we're in iframe, using our /fb_canvas/nid/ path convention.
              $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", $nid));
            }
          }
        }
      }
    }
    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_INITIALIZE) {

        // User init has been moved to fb_user.module.
        // For now, nothing to do here.
      }
      else {
        if ($op == FB_OP_POST_INIT) {

          /* TODO: move this feature to an explicit setting.  For now, we just use site homepage
             // Here we override the front_page settings
             if ($_REQUEST['q'] == '' && $fb_app->nid) {
               menu_set_active_item('node/'.$fb_app->nid);
               // Note, menu_set_active_item only works as intended if fb.module
               // is weighted lighter than node.module!
             }
               */
        }
      }
    }
  }
}