apikey])) { $_SESSION[FB_STREAM_DIALOGS][$fb_app->apikey] = array(); } $_SESSION[FB_STREAM_DIALOGS][$fb_app->apikey][] = $params; } /** * Get the data for one or more stream dialogs. Use this function in * ajax callbacks, where you want to publish dialog(s) in response to * javascript events. */ function fb_stream_get_stream_dialog_data($fb_app = null) { if (!$fb_app) $fb_app = $GLOBALS['fb_app']; if (isset($_SESSION[FB_STREAM_DIALOGS]) && isset($_SESSION[FB_STREAM_DIALOGS][$fb_app->apikey])) { $data = $_SESSION[FB_STREAM_DIALOGS][$fb_app->apikey]; unset($_SESSION[FB_STREAM_DIALOGS][$fb_app->apikey]); return $data; } else { return array(); } } /** * Implementation of hook_fb(). * * When adding javascript to FBML and Conect pages, we add */ function fb_stream_fb($op, $data, &$return) { if ($op == FB_OP_CONNECT_JS_INIT || $op == FB_OP_CANVAS_FBJS_INIT) { // arguments for JS and FBJS methods are the same! $params_array = fb_stream_get_stream_dialog_data($data['fb_app']); $js = fb_stream_js($params_array); $return += $js; } } /** * Convert our data structure in javascript. */ function fb_stream_js($params_array) { $return = array(); foreach ($params_array as $params) { $args = array(); // These are the defaults: foreach (array('user_message' => '', 'attachment' => '{}', 'action_links' => '{}', 'target_id' => 'null', 'user_message_prompt' => 'null', 'callback' => 'null', 'auto_publish' => 'null', 'actor_id' => 'null', ) as $key => $default) { if (isset($params[$key])) { // Encode the params passed to fb_stream_publish_dialog. if (in_array($key, array('callback', 'auto_publish'))) { // no encoding $args[] = $params[$key]; } else { $args[] = json_encode($params[$key]); } } else { // Use default $args[] = $default; } } if (!fb_is_fbml_canvas()) { // Add stream dialog javascript to a facebook connect page. $return[] = "FB.Connect.streamPublish(" . implode(', ', $args) . ");\n"; } else { // Add stream dialog javascript to a canvas page. $return[] = "Facebook.streamPublish(" . implode(', ', $args) . ");\n"; } // debug //dpm($return, "fb_stream_fb added javascript"); } return $return; }