/* * The facebook_onload statement is printed out in the PHP. If the user's logged in * status has changed since the last page load, then refresh the page to pick up * the change. * * This helps enforce the concept of "single sign on", so that if a user is signed into * Facebook when they visit your site, they will be automatically logged in - * without any need to click the login button. * * @param already_logged_into_facebook reports whether the server thinks the user * is logged in, based on their cookies * */ var page_url = 'http://www.nurbamberg.de'; var communityname = 'nur!bamberg'; var cityname = 'Bamberg'; function facebook_onload() { // user state is either: has a session, or does not. // if the state has changed, detect that and reload. logging("facebook_onload aufgerufen."); FB.ensureInit(function() { FB.Facebook.get_sessionState().waitUntilReady(function(session) { var is_now_logged_into_facebook = session ? true : false; // if the new state is the same as the old (i.e., nothing changed) // then do nothing if (is_now_logged_into_facebook) { update_user_box(); setup_form(); fb_reparse(); return; } // otherwise, refresh to pick up the state change // refresh_page(); }); }); } function invoke_cancel_function() { logging('invoke_cancel_function()'); var myAjax = new Ajax.Request( 'modules/facebook/ajax.php', { parameters: 'cmd=skip_asking_for_fbc', onComplete: function() { } }); } function save_fb_user_id() { FB.ensureInit(function() { logging("FB.ensureInit aufgerufen"); FB.Facebook.get_sessionState().waitUntilReady(function(session) { if(session) { var fb_id = FB.Facebook.apiClient.get_session().uid; var myAjax = new Ajax.Request( 'modules/facebook/ajax.php', { parameters: 'fb_id='+fb_id+'&cmd=store_fb_user_id', onComplete: function() { } }); } }); }); } function setup_form() { logging('setup_form()'); if(document.getElementById('addcommentbutton')) { logging('addcommentbutton'); if(fbc_comments_activated) { var addcomment_button = ge("addcommentbutton"); addcomment_button.href="javascript: submit_comment(); void(0);"; } } } /* * Our specifies this function in its onlogin attribute, * which is triggered after the user authenticates the app in the Connect * dialog and the Facebook session has been set in the cookies. */ function facebook_onlogin_ready() { // In this app, we redirect the user back to index.php. The server will read // the cookie and see that the user is logged in, and will deliver a new page // with content appropriate for a logged-in user. // // However, a more complex app could use this function to do AJAX calls // and/or in-place replacement of page contents to avoid a full page refresh. refresh_page(); } /* * Umlaute ersetzen */ function replaceUmlaute(curText) { var result = curText; result=result.replace(/\u00fc/g, "ue"); result=result.replace(/\u00f6/g, "oe"); result=result.replace(/\u00e4/g, "ae"); result=result.replace(/\u00dc/g, "Ue"); result=result.replace(/\u00d6/g, "Oe"); result=result.replace(/\u00c4/g, "Ae"); result=result.replace(/\u00df/g, "sz"); result=result.replace(/ü/g, "ue"); result=result.replace(/ö/g, "oe"); result=result.replace(/ä/g, "ae"); result=result.replace(/Ü/g, "Ue"); result=result.replace(/Ö/g, "Oe"); result=result.replace(/Ä/g, "Ae"); result=result.replace(/ß/g, "sz"); return result; } /* * Leerzeichen entfernen */ function replaceSpace(curText) { var result = curText; result=result.replace(/\ /, ""); return result; } /* * Userdaten auslesen */ function get_fb_id() { FB.ensureInit(function() { FB.Facebook.get_sessionState().waitUntilReady(function(session) { if(session) { var uid = FB.Facebook.apiClient.get_session().uid; var fql = 'SELECT uid FROM user WHERE uid='+uid; FB.Facebook.apiClient.fql_query(fql, function(result) { if(document.getElementById('fb_id')) $('fb_id').value = result[0].uid; logging(result[0].uid); }); } }); }); } function get_main_user_data() { FB.ensureInit(function() { logging("FB.ensureInit aufgerufen"); FB.Facebook.get_sessionState().waitUntilReady(function(session) { if(session) { logging("eingeloggt"); var uid = FB.Facebook.apiClient.get_session().uid; var fql = 'SELECT first_name, last_name, uid, meeting_for, pic_big, name, pic_square_with_logo, profile_url, sex, birthday_date, meeting_sex, relationship_status, activities, interests, is_app_user, music, tv, movies, books, about_me, hs_info, education_history, work_history, profile_blurb FROM user WHERE uid='+uid; FB.Facebook.apiClient.fql_query(fql, function(result) { //var fbc_login_state = ge('fbc_login_state'); //removeChildren(fbc_login_state); var name_value = result[0].name; var name_array = name_value.split(' '); name_value = replaceSpace(replaceUmlaute(name_array[0]))+replaceUmlaute(name_array[1].substr(0,1)); name_value = name_value.toLowerCase(); if($('username')) $('username').value = name_value; if($('fb_id')) $('fb_id').value = result[0].uid; if($('sex')) $('sex').value = result[0].sex; if(result[0].birthday_date != undefined && result[0].birthday_date.length > 9) { if(document.getElementById('birthday_date')) $('birthday_date').value = result[0].birthday_date; } else { if ($('registerForm')) { if(result[0].birthday_date != undefined) { // read out the day and month array = new Array(); array = result[0].birthday_date.split('/'); $('tag').selectedIndex = array[1]; $('monat').selectedIndex = array[0]; } document.getElementById("registerForm").removeChild(document.getElementById("birthday_date")); Element.show('birthday_check'); } } if($('meeting_sex')) $('meeting_sex').value = result[0].meeting_sex; if($('meeting_for')) $('meeting_for').value = result[0].meeting_for; if($('relationship_status')) $('relationship_status').value = result[0].relationship_status; if($('activities')) $('activities').value = result[0].activities; if($('interests')) $('interests').value = result[0].interests; if($('music')) $('music').value = result[0].music; if($('tv')) $('tv').value = result[0].tv; if($('movies')) $('movies').value = result[0].movies; if($('books')) $('books').value = result[0].books; if($('about_me')) $('about_me').value = result[0].about_me; if($('first_name')) $('first_name').value = result[0].first_name; if($('last_name')) $('last_name').value = result[0].last_name; /* $('hs_info').value = Object.toJSON(result[0].hs_info); $('education_history').value = Object.toJSON(result[0].education_history); $('work_history').value = Object.toJSON(result[0].work_history); */ if($('profile_blurb')) $('profile_blurb').value = result[0].profile_blurb; if($('pic_big')) $('pic_big').value = result[0].pic_big; if($('username')) check_username(); /* var pic_value = result[0].pic_square_with_logo; var name_value = result[0].name; var userlink_value = result[0].profile_url; var p1 = document.createElement('p'); var signout_link = document.createElement('a'); var p2 = document.createElement('p'); fbc_login_state.innerHTML = ''; p1.innerHTML = 'Welcome, '+name_value+'. You are signed in with your Facebook account.'; signout_link.innerHTML = 'Click here to sign out.'; signout_link.href= 'javascript:FBConnect.logout()'; signout_link.id = 'fbc_signout_link'; signout_link.className = 'link'; appendNode(p1,fbc_login_state); appendNode(signout_link,p2); appendNode(p2,fbc_login_state); */ }); } else { logging("nicht eingeloggt"); FB.Connect.requireSession(function() { //alert("Du musst bei Facebook eingeloggt sein."); }); } //if(typeof(fb_onload_script) == "string") // eval(fb_onload_script); //FB.XFBML.Host.parseDomTree(); }); }); } /* * Do a page refresh after login state changes. * This is the easiest but not the only way to pick up changes. * If you have a small amount of Facebook-specific content on a large page, * then you could change it in Javascript without refresh. */ function refresh_page() { //window.location = 'index.php'; location.reload(true); } /* * Prompts the user to grant a permission to the application. */ function facebook_prompt_permission(permission) { FB.ensureInit(function() { FB.Connect.showPermissionDialog(permission); }); } /* * Welcome-Post publishen */ function publish_new_member() { var fbc_template_start_text = 'ist jetzt Mitglied bei'; var fbc_template_end_text = ''; var fbc_home_url = page_url; var fbc_blog_name = communityname; var fbc_post_image_url = page_url+'/grafiken/Icons/nur_icon.png'; var fbc_template_bundle_id = 84847920255; var fbc_article_title = ''+communityname+'.'; var fbc_post_url = page_url; var fbc_to_link = 'zu '+communityname; var fbc_to_link_url = page_url; FB.ensureInit(function() { FB.Connect.get_status().waitUntilReady(function(status) { if (status == FB.ConnectState.userNotLoggedIn) { // If the user is currently logged into Facebook, but has not // authorized the app, then go ahead and show them the feed dialog + upsell logging("userNotLoggedIn"); FB.Connect.requireSession(function() { publish_new_member(); }); } else if(status == FB.ConnectState.appNotAuthorized) { logging("appNotAuthorized"); FB.Connect.requireSession(function() { publish_new_member(); }); } else if(status == FB.ConnectState.connected) { logging("connected"); var template_data = { 'template-start-text': fbc_template_start_text, 'template-end-text': fbc_template_end_text, 'post-title': fbc_article_title, 'post-url': fbc_post_url, 'images': [{'src':fbc_post_image_url, 'href':fbc_post_url}], 'to-link': fbc_to_link, 'to-link-url': fbc_to_link_url }; var body_general = ''+communityname+' ist die Community für deine Stadt: Locations, Partys, Freunde & mehr. Melde dich jetzt kostenlos an!'; FB.Connect.showFeedDialog(fbc_template_bundle_id, template_data, null, body_general, null, FB.RequireConnect.require, function() { if(window.location.pathname != '/register.php') refresh_page(); }); return void(0); } }); }); /* FB.ensureInit(function() { logging("FB.ensureInit aufgerufen"); FB.Facebook.get_sessionState().waitUntilReady(function(session) { if(session) { var template_data = { 'template-start-text': fbc_template_start_text, 'template-end-text': fbc_template_end_text, 'post-title': fbc_article_title, 'post-url': fbc_post_url, 'images': [{'src':fbc_post_image_url, 'href':fbc_post_url}], 'to-link': fbc_to_link, 'to-link-url': fbc_to_link_url }; FB.Connect.showFeedDialog(fbc_template_bundle_id, template_data, null, // template_ids null, // body_general null, // story_size FB.RequireConnect.require, // require_connect function() { //ge('commentForm').submit(); }); //FB.RequireConnect.promptConnect, return void(0); } else { logging("nicht eingeloggt"); FB.Connect.requireSession(function() {}); } }); }); */ } /* * Kommentare publishen */ function publish_js_comment(form_bundle_id, post_title, post_url) { document.getElementsByName("fbconnect_js_submit")[0].disabled="disabled"; comment_text = document.getElementsByName("comment")[0].value; var template_data = { "post-title":post_title, "post-url":post_url, "post":comment_text }; try { facebook_publish_feed_story(form_bundle_id, template_data); } catch(err) { document.getElementsByName("comment")[0].value = ""; document.getElementById("fbconnect_result").innerHTML = "Error publishing story: " + err.description; } document.getElementsByName("comment")[0].value = ""; document.getElementById("fbconnect_result").innerHTML = "Published story via Javascript to your profile feed!"; document.getElementsByName("fbconnect_js_submit")[0].disabled=""; } /* * Kommentare verkürzen */ function make_body_general(comment) { var words = comment.split(' '); if (words.length > 50) { words = words.slice(0, 50); words.push('...'); } var comment_clip = words.join(' '); return "\"" + comment_clip + "\""; } function fb_reparse() { FB.ensureInit(function() { FB.XFBML.Host.parseDomTree(); }); } /* * Show the feed form. This would be typically called in response to the * onclick handler of a "Publish" button, or in the onload event after * the user submits a form with info that should be published. * */ function facebook_publish_feed_story(form_bundle_id, template_data) { // Load the feed form FB.ensureInit(function() { FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, null, FB.RequireConnect.promptConnect, null); //FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, FB.FeedStorySize.shortStory, FB.RequireConnect.promptConnect); /* e.g. FB.Connect.showFeedDialog(FBConnect.template_bundle_id, template_data, null, // template_ids body_general, null, // story_size FB.RequireConnect.promptConnect, // require_connect function() { ge('commentform').submit(); }); */ }); } /* * If a user is not connected, then the checkbox that says "Publish To Facebook" * is hidden in the "add run" form. * * This function detects whether the user is logged into facebook but just * not connected, and shows the checkbox if that's true. */ function facebook_show_feed_checkbox() { FB.ensureInit(function() { FB.Connect.get_status().waitUntilReady(function(status) { if (status != FB.ConnectState.userNotLoggedIn) { // If the user is currently logged into Facebook, but has not // authorized the app, then go ahead and show them the feed dialog + upsell checkbox = document.getElementById('publish_fb_checkbox'); if (checkbox) { Element.show('publish_fb_checkbox'); } } }); }); } function facebook_show_status_checkbox() { FB.ensureInit(function() { FB.Connect.get_status().waitUntilReady(function(status) { if (status != FB.ConnectState.userNotLoggedIn) { // If the user is currently logged into Facebook, but has not // authorized the app, then go ahead and show them the feed dialog + upsell checkbox = document.getElementById('publish_fb_status'); if (checkbox) { Element.toggle('publish_fb_status'); } } }); }); } function submit_comment() { var template_data = { 'template-start-text': fbc_template_start_text, 'template-end-text': fbc_template_end_text, 'post-title': fbc_article_title, 'post-url': fbc_post_url, 'images': [{'src':fbc_post_image_url, 'href':fbc_post_url}], 'to-link': fbc_to_link, 'to-link-url': fbc_to_link_url }; var body_general; if(document.getElementById('comment')) body_general = $('comment').value; FB.Connect.showFeedDialog(fbc_template_bundle_id, template_data, null, // template_ids '"'+body_general+'"', // body_general null, // story_size FB.RequireConnect.require, // require_connect function() { ge('commentForm').submit(); }); //FB.RequireConnect.promptConnect, return void(0); } function submit_status_success() { FB.Facebook.apiClient.users_setStatus($('last_message').innerHTML,false,true,function(re,ex){ if(null != re){ //console.log('setStatus: success.'); }else{ //console.log('setStatus: fail.' + ex); } }); } function submit_status() { if($('publish_fb_checkbox').checked == true) { FB.Facebook.apiClient.users_hasAppPermission('status_update',function(re,ex){ if(re != 0){ submit_status_success(); }else{ FB.Connect.showPermissionDialog('status_update', function(accepted) { submit_status_success(); } ); } }); } Element.hide('publish_fb_status'); } // SHOWS DIALOG FOR USER TO ACCEPT PUBLISH STREAMS OR NOT function fbc_show_publish_streams_permission_dialog() { FB.Connect.showPermissionDialog('publish_stream', function(accepted) { window.location.reload(); } ); } // SHOWS DIALOG FOR USER TO ACCEPT EXTENDED PERMISSION OR NOT function fbc_show_status_update_permission_dialog() { FB.Connect.showPermissionDialog('status_update', function(accepted) { window.location.reload(); } ); } // SHOWS DIALOG FOR USER TO ACCEPT EXTENDED PERMISSION OR NOT function fbc_show_offline_access_permission_dialog() { FB.Connect.showPermissionDialog('offline_access', function(accepted) { window.location.reload(); } ); } function fbc_remove(e) { if(e) e.parentNode.removeChild(e); } function fbc_remove_parent(e) { if(e) fbc_remove(e.parentNode); } function ge(elem) { return document.getElementById(elem); } function make_body_general(comment) { var words = comment.split(' '); if (words.length > 50) { words = words.slice(0, 50); words.push('...'); } var comment_clip = words.join(' '); return "\"" + comment_clip + "\""; } function handleOnFacebookLogoutCallback() { window.location='/logout'; } function facebook_onlogin() { facebook_redirect_url = "http://"+window.location.hostname+"/register.php?step=fb_step_new&cat_1=1"; window.location = facebook_redirect_url; } function handleOnFacebookSessionReadyCallback() { if(typeof afterFacebookAuthentication=='function') { afterFacebookAuthentication(); } } function requireFacebookSession() { if(typeof beforeFacebookAuthentication=='function') { beforeFacebookAuthentication(); } FB.Connect.requireSession(handleOnFacebookSessionReadyCallback); } function afterFacebookAuthentication() { // ajax-call if registered or not logging("afterFacebookAuthentication"); facebook_redirect_url = "http://"+window.location.hostname+"/register.php?step=fb_step_new&cat_1=1"; window.location = facebook_redirect_url; } function publish_fb_checkbox() { var value = document.getElementById('publish_fb_checkbox').checked; if (value) { setCookie('publish_fb_checkbox', 'true', soon, false, false, false); } else{ setCookie('publish_fb_checkbox', 'false', soon, false, false, false); } } function publish_fb_comment() { if (document.getElementById('publish_fb_comment').checked == true) { setCookie('publish_fb_comment', 'true', soon, false, false, false); } else { setCookie('publish_fb_comment', 'false', soon, false, false, false); } } function update_user_box() { if(document.getElementById('user_logged_in')) { $('user_logged_in').innerHTML = 'facebook'; } if(document.getElementById('publish_fb_checkbox')) { var publish_fb_checkbox = document.getElementById('publish_fb_checkbox'); var publish_fb_checkbox_cookie = getCookie('publish_fb_checkbox'); if( publish_fb_checkbox_cookie == true || publish_fb_checkbox_cookie == 'true' || publish_fb_checkbox_cookie == null ) { publish_fb_checkbox.checked = 'true'; } } if(document.getElementById('publish_fb_comment')) { var publish_fb_comment = document.getElementById('publish_fb_comment'); var publish_fb_comment_cookie = getCookie('publish_fb_comment'); if( publish_fb_comment_cookie == true || publish_fb_comment_cookie == 'true' || publish_fb_comment_cookie == null ) { publish_fb_comment.checked = 'true'; } } if(document.getElementById('logout_button')) { $('logout_button').href = 'javascript:FB.Connect.logoutAndRedirect("/actions.php?action=logout");'; } /* user_box.innerHTML = "" + "" + "Welcome, " + ""; FB.XFBML.Host.parseDomTree(); */ }