/** * Returns the attachment object to be published to Facebook. * * @access public * @param string publish_type The type of message to be published. * @param string game_name The name of the game to be published. * @param integer game_id The ID of the game to be published. * @param boolean is_fb_enabled A flag indicating if Facebook stuff is enabled. * @param mixed variable_data The prize won or the new high score achieved. * @param boolean is_high A flag indicating if the score is a high score. * @param boolean autogen A flag indicating if the message was autogenerated. * @param string thumb_url The URL of the image to be used in the post. * @return object A hash representing the attachment object. */ function getScorePublishAttachment(publish_type, game_name, game_id, is_fb_enabled, variable_data, is_high, autogen, thumb_url) { // The ways we end our promo text var on_ww = ' on WorldWinner.com!'; var in_a_tournament = ' in a tournament ' + on_ww; // Decide whether the game name can or can not be shown. if (is_fb_enabled > 0) { var url = 'http://www.worldwinner.com' + '/cgi/welcome/21u9t?game_id=' + game_id + '&utm_source=facebook'; if( publish_type == 'highscore' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} just set a new personal best of ' + variable_data + ' in ' + game_name + on_ww,'href':url + (autogen ? '&utm_medium=autogenhighscorepost' : '&utm_medium=highscorepost') + '&utm_campaign=fbscore' ,'description':'','media':[{'type':'image','src': thumb_url,'href': url + (autogen ? '&utm_medium=autogenhighscorepost' : '&utm_medium=highscorepost') + '&utm_campaign=fbscore' }]}; } else if ( publish_type == 'score' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} just rocked a score of ' + variable_data + ' in ' + game_name + on_ww,'href': url + '&utm_medium=scorepost&utm_campaign=fbscore','description':'','media':[{'type':'image','src':thumb_url,'href': url + '&utm_medium=scorepost&utm_campaign=fbscore'}]}; } else if ( publish_type == 'windropdown' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} just won a ' + (variable_data ? variable_data + ' prize playing ' + game_name: game_name + ' tournament') + on_ww,'href': url + '&utm_medium=windropdownpost&utm_campaign=fbwin','description':'','media':[{'type':'image','src':thumb_url,'href': url + '&utm_medium=windropdownpost&utm_campaign=fbwin'}]}; } else if ( publish_type == 'winstandings' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} just won a ' + (variable_data ? variable_data + ' prize playing ' + game_name: game_name + ' tournament') + on_ww,'href': url + '&utm_medium=winstandingspost&utm_campaign=fbwin','description':'','media':[{'type':'image','src':thumb_url,'href': url + (autogen ? '&utm_medium=autogenwinpost' : '&utm_medium=winstandingspost') + '&utm_campaign=fbwin'}]}; } } else { var url = 'http://www.worldwinner.com' + '/cgi/welcome/21u9t?utm_source=facebook'; if( publish_type == 'highscore' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} just snagged a new high score' + on_ww,'href':url + (autogen ? '&utm_medium=autogenhighscorepost' : '&utm_medium=highscorepost') + '&utm_campaign=fbscore' ,'description':'','media':[{'type':'image','src':thumb_url,'href': url + (autogen ? '&utm_medium=autogenhighscorepost' : '&utm_medium=highscorepost') + '&utm_campaign=fbscore' }]}; } else if ( publish_type == 'score' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} is getting in the game' + on_ww,'href': url + '&utm_medium=scorepost&utm_campaign=fbscore','description':'','media':[{'type':'image','src':thumb_url,'href': url + '&utm_medium=scorepost&utm_campaign=fbscore'}]}; } else if ( publish_type == 'windropdown' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} just ' + (variable_data ? 'won a ' + variable_data + ' prize' : 'beat the competition') + in_a_tournament,'href': url + '&utm_medium=windropdownpost&utm_campaign=fbwin','description':'','media':[{'type':'image','src':thumb_url,'href': url + '&utm_medium=windropdownpost&utm_campaign=fbwin'}]}; } else if ( publish_type == 'winstandings' ) { return {'name':'WorldWinner.com - Play Games, Win Cash Prizes!','caption':'{*actor*} just ' + (variable_data ? 'won a ' + variable_data + ' prize' : 'beat the competition') + in_a_tournament,'href': url + '&utm_medium=winstandingspost&utm_campaign=fbwin','description':'','media':[{'type':'image','src':thumb_url,'href': url + (autogen ? '&utm_medium=autogenwinpost' : '&utm_medium=winstandingspost') + '&utm_campaign=fbwin'}]}; } } } /** * Publishes a message to the user's stream. * * @access public * @param string msg The message to be prefilled for the user. Usually empty. * @param object attachment The attachment object to be used for the post. * @param string action_link The URL that friends will be sent to. * @param string target The Facebook target account. Usually null. * @param string prompt The message prompt * @param string share_type The type of sharing being done. * @return void */ function callScorePublish(msg, attachment, action_link, target, prompt, share_type) { FB.getLoginStatus(function(response) { // Users that are logged in and have a connection with WW have a status of // connected. Users that are logged in and do not haev a connection with WW // have a status of notConnected. Users that are not logged in have a status // of unknown. if (response.status != 'unknown') { publishScore(msg, attachment, action_link, target, prompt, share_type); } else { // Prompt the user to log in. We do this explicitly because if we don't, // Facebook will redirect the user to login and (re-)url encode the url. // This leads to ridiculously long URLs that IE cannot handle. By // explicitly forcing the user to login and then post, we can avoid // crazy URLs. FB.login(function(response) { if (response.session) { // Now that they have logged in, call this again. publishScore(msg, attachment, action_link, target, prompt, share_type); } else { // User cancelled login or would not allow us to publish. handlePublishResults(response, prompt, share_type); } }); } }); return; } /** * Provides the user with an opportunity to publish our message to their Facebook * account. * * @access public * @param string msg The message to be prefilled for the user. Usually empty. * @param object attachment The attachment object to be used for the post. * @param string action_link The URL that friends will be sent to. * @param string target The Facebook target account. Usually null. * @param string prompt The message prompt * @param string share_type The type of sharing being done. * @return void */ function publishScore(msg, attachment, action_link, target, prompt, share_type) { // Publish a message to the user's stream. FB.ui({method: 'stream.publish', message: msg, attachment: attachment, action_links: action_link, user_message_prompt: prompt }, function(response) { handlePublishResults(response, prompt, share_type); }); } /** * Tracks the user's action in our analytics tracker. * * @param object response The response object from a Facebook API call. * @param string prompt The message prompt * @param string share_type The type of sharing being done. * @return void */ function handlePublishResults(response, prompt, share_type) { if (typeof pageTracker != 'undefined') { if (response && response.post_id) { // After we publish, we want to fire a call to GA to track this event. // Checking specifically for post_id indicates that it's a successful // submission. pageTracker._trackEvent('Facebook', share_type); } else { // If there's no post_id, there's no post to facebook. pageTracker._trackEvent('Facebook', 'Submission Cancelled'); } } $j('span#fb_dialog_header').text(prompt); }