You are here

function fb_feed_fb in Drupal for Facebook 5.2

Implementation of hook_fb().

File

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

Code

function fb_feed_fb($op, $data, &$return) {

  //dpm("fb_feed_fb($op)");
  if ($op == FB_OP_CONNECT_JS_INIT || $op == FB_OP_CANVAS_FBJS_INIT) {

    //dpm(func_get_args(), 'XXX');

    //dpm($_SESSION['fb_feed_dialogs'], 'SESSION[fb_feed_dialogs]'); //XXX
  }
  if (($op == FB_OP_CONNECT_JS_INIT || $op == FB_OP_CANVAS_FBJS_INIT) && isset($_SESSION['fb_feed_dialogs']) && isset($_SESSION['fb_feed_dialogs'][$data['fb_app']->apikey])) {

    // Note that FB.Connect.ShowFeedDialog and Facebook.showFeedDialog take different parameters.  Thanks, facebook!
    // Use javascript to publish feed messages
    foreach ($_SESSION['fb_feed_dialogs'][$data['fb_app']->apikey] as $d) {

      // accept tokens for template_data (backward compatibility
      if ($d['tokens']) {
        $d['options']['template_data'] = $d['tokens'];
      }
      if ($op == FB_OP_CONNECT_JS_INIT) {

        // http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.ShowFeedDialog
        $args = array(
          $d['bundle_id'],
        );
        foreach (array(
          'template_data' => '{}',
          'target_ids' => 'null',
          // note taget_ids array
          'body_general' => 'null',
          'story_size' => 'null',
          'require_connect' => 'null',
          'callback' => 'null',
          'user_message_prompt' => 'null',
          'user_message' => 'null',
        ) as $key => $default) {
          if (isset($d['options'][$key])) {
            if (in_array($key, array(
              'require_connect',
              'callback',
            ))) {
              $args[] = $d['options'][$key];
            }
            else {
              if ($key == 'user_message' && is_string($d['options'][$key])) {
                $args[] = '{value:' . json_encode($d['options'][$key]) . '}';
              }
              else {
                $args[] = json_encode($d['options'][$key]);
              }
            }
          }
          else {
            $args[] = $default;
          }
        }
        $return[] = "FB.Connect.showFeedDialog(" . implode(',', $args) . ");";
      }
      else {
        if ($op == FB_OP_CANVAS_FBJS_INIT) {

          // http://wiki.developers.facebook.com/index.php/Facebook.showFeedDialog
          $args = array(
            $d['bundle_id'],
          );
          foreach (array(
            'template_data' => 'null',
            'body_general' => 'null',
            'target_id' => 'null',
            // note target_id int
            'continuation' => 'null',
            'user_message_prompt' => 'null',
            'user_message' => 'null',
          ) as $key => $default) {
            if (isset($d['options'][$key])) {
              if (in_array($key, array(
                'continuation',
              ))) {
                $args[] = $d['options'][$key];
              }
              else {
                if ($key == 'user_message' && is_string($d['options'][$key])) {
                  $args[] = '{value:' . json_encode($d['options'][$key]) . '}';
                }
                else {
                  $args[] = json_encode($d['options'][$key]);
                }
              }
            }
            else {
              $args[] = $default;
            }
          }

          //dpm($args, "Facebook.showFeedDialog args");
          $return[] = "Facebook.showFeedDialog(" . implode(",\n", $args) . ");";
        }
      }
    }

    // remove displayed items from session
    unset($_SESSION['fb_feed_dialogs'][$data['fb_app']->apikey]);
  }
}