You are here

function fb_feed_action_show_dialog in Drupal for Facebook 5.2

1 string reference to 'fb_feed_action_show_dialog'
fb_feed_action_info in ./fb_feed.module

File

./fb_feed.module, line 877
Helpers for Facebook feeds (http://wiki.developers.facebook.com/index.php/New_Design_Feed_Wall)

Code

function fb_feed_action_show_dialog(&$context, $values = array()) {

  //dpm(func_get_args(), "fb_feed_action_show_dialog");

  // Get the template
  $template = node_load($values['fb_feed_template_nid']);

  // Params we will pass to alter hook, then to fb_feed_show_dialog
  $params = array(
    'template' => $template,
    'tokens' => array(),
    'options' => array(
      'user_message_prompt' => $values['user_message_prompt'],
    ),
    'cancel' => FALSE,
  );

  // Get the objects we're acting upon.
  $objects = array();
  if ($values['hook'] == 'nodeapi') {
    $objects['node'] = $values['node'];
    $params['options']['user_message'] = check_plain($objects['node']->body);
  }
  else {
    if ($values['hook'] == 'comment') {
      $objects['comment'] = $values['comment'];
      $objects['node'] = node_load($values['comment']->nid);
      $params['options']['user_message'] = check_plain($objects['comment']->comment);
    }
    else {
      if ($values['hook'] == 'user') {
        $account = $values['user'];
        $objects['user'] = $account;
      }
    }
  }

  // TODO: Sanity check that bundle has been registered with Facebook.
  // And the app
  $fb_app = fb_get_app(array(
    'nid' => $template->fb_app_nid,
  ));
  $objects['fb_app'] = $fb_app;

  // TODO: Sanity check that apikeys match.
  if ($values['token_enable']) {

    // Use tokens for every kind of object we know about
    foreach (array(
      'node',
      'comment',
      'user',
      'fb_app',
    ) as $type) {
      if ($objects[$type]) {
        $toks = token_get_values($type, $objects[$type], FALSE, $options);

        //watchdog('fb_feed_debug', "token_get_values($type) returned " . dprint_r($toks, 1));
        if ($toks && is_array($toks->tokens)) {
          foreach ($toks->tokens as $i => $key) {
            dpm($toks->values[$i], "Token for {$key} is " . strlen($toks->values[$i]) . " chars");
          }
          $params['tokens'][$key] = $toks->values[$i];
        }
      }
    }
  }

  // Invoke a hook so that other modules have a chance to modify the params before we pass them to facebook.
  fb_drupal_alter('fb_feed_show_dialog', $params, array(
    'context' => $context,
    'objects' => $objects,
  ));

  //dpm($params, "params after fb_drupal_alter");

  /*
  // Invoke a hook so that other modules have a chance to modify the params before we pass them to facebook.
  $params = fb_feed_invoke($fb_app, FB_FEED_OP_TOKEN_ALTER,
                           $params, array('template' => $template,
                                          'objects' => $objects,
                                          'context' => $context));
  */
  if (!$params['cancel']) {
    fb_feed_show_dialog($params['template'], $params['tokens'], $params['options']);
  }
}