You are here

function fb_actions_minifeed in Drupal for Facebook 5

File

./fb_actions.module, line 52
Actions defined here interact with Facebook's API. This makes it possible to notify facebook of various activities as they happen.

Code

function fb_actions_minifeed(&$object, $values = array()) {

  //dpm(func_get_args(), 'fb_actions_minifeed');
  if ($values['hook'] == 'nodeapi') {
    $node = $values['node'];
  }
  else {
    if ($values['hook'] == 'comment') {
      $comment = $values['comment'];
      $node = node_load($comment->nid);
    }
    else {
      if ($values['hook'] == 'user') {
        $account = $values['user'];
      }
    }
  }

  // Log into facebook as the current user.
  if ($fb_app = $GLOBALS['fb_app']) {
    if ($values['fb_app_nid'] == FB_APP_CURRENT || $fb_app->nid == $values['fb_app_nid']) {

      // We're in a canvas page for the desired app.  We're already logged in.
      $fb = $GLOBALS['fb'];
    }
  }
  if (!$fb && $values['fb_app_nid'] != FB_APP_CURRENT) {
    global $user;

    // Need to log into this app.
    $fb_app = fb_get_app(array(
      'nid' => $values['fb_app_nid'],
    ));
    $fbu = fb_get_fbu($user->uid, $fb_app);
    if ($fbu) {
      $fb = fb_api_init($fb_app, $fbu);
    }
  }

  // Even if we have an $fb now, it may not have permission to do all things
  // we ask of it.
  if ($fb) {

    // Replace both node and fb_app related tokens
    $title = token_replace($values['title'], 'node', $node);
    $title = token_replace($title, 'comment', $comment);
    $title = token_replace($title, 'user', $account);
    $title = token_replace($title, 'fb_app', $fb_app);
    $body = token_replace($values['body'], 'node', $node);
    $body = token_replace($body, 'comment', $comment);
    $body = token_replace($body, 'user', $account);
    $body = token_replace($body, 'fb_app', $fb_app);

    // Rewrite links to reference canvas pages
    if ($fb_app->canvas && function_exists('fb_canvas_process_fbml')) {
      $title = fb_canvas_process_fbml($title, $fb_app);
      $body = fb_canvas_process_fbml($body, $fb_app);
    }
    $fb->api_client
      ->feed_publishActionOfUser($title, $body);
    fb_report_errors($fb);
  }
}