• [MOD] Facebook Connector V1.0 & V2.0 5 0 5 1
Currently:  

Author Topic: [MOD] Facebook Connector V1.0 & V2.0  (Read 222062 times)

0 Members and 1 Guest are viewing this topic.

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
[MOD] Facebook Connector V1.0 & V2.0
« on: June 13, 2010, 09:38:56 PM »
Facebook Connector VERSION 2.0 CAN BE FOUND HERE...
http://www.4homepages.de/forum/index.php?topic=27396.msg160225#msg160225

[MOD] Facebook Connector V1.0

DO NOT INSTALL VERSION 1 OF THIS MOD!
The Version one instructions are here for users to remove all entries from their galleries before installing version 2.
As of December 13th, facebook no longer supports the code that it is ran under.
I am currently working on version 2.0 of this mod using the new code but still have some testing to do with it first.
I am hoping to have it up and running by the end of January 2012.


This mod will give your users the ability to login to your 4images site using their Facebook account.
YOU MUST be running PHP Version 5 or greater with CURL and JSON running on your server for this mod to work.
check your phpinfo() or your provider to find out. My provider upgraded my account for free to the new PHP.

this mod is based on the facebook php-sdk kit that is available at...
http://github.com/facebook/php-sdk/
the package is new and constantly being updated, I will try to stay on top of it but no guarantee that this mod will work if they make any drastic changes to their code.

I used the folowing tutorials to help me create this mod, (I have to give them the credit, they did most of the hard work)
http://www.barattalo.it/facebook-connect-tutorial/
http://www.pakt.com/pakt/?id=5e17b48f5679ab47&t=How_to_add_Facebook_Connect_to_your_website_using_the_PHP_API
http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/

This mod adds a login button to your userbox on your site.
When a user logs in for the first time with facebook, it will check their e-mail to see if they already have an account on your site and connect the facebook account to that account if found.
If the account is not found, it will auto-create an account on your site using their facebook fullname and adding numbers after it if needed.
it will also transfer their e-mail and website information to 4images database in the process. (facebook now allows this as long as you do not SPAM your visitors, they will disable your app if anyone complains)
It will not e-mail authenticate their account, I figure facebook already did this so it already lets them have full user access when logging in.
After installed and running, it is compatable with most of the facebook social addons if you wish to have them displayed on your site.
Is language friendly, check on the insert in the language/main.php file called $lang['fbl_lang'] for more information.
The Mod will ask your users for their facebook e-mail and website to add to the 4images database.
It will also ask for permission to post any share/like requests to there facebook profiles.

The only issue I have found is that facebook is wanting you to use SSL for comunications between them and your site, so far they have not inforced the issue and I am not sure how to add support for that,
so I modified the facebook.php file to turn the ssl verification off. Everyone on facebook is complaining about it also so hopefully they will not force the SSL issue or I think your entire gallery will have to be
behind a SSL certificate for it to work in the future but for now you should be good.

DEMO...
http://www.budduke.com

Version history...
V1.0 - initial release. (using a modified version 2.0.4 of the php-sdk kit)

You first need to go to Facebooks website and create an app under your account.
http://www.facebook.com/developers/createapp.php
click on the "set up new application" button.
In the set up page you have different fields to enter, but only these are needed (see attached pdf file in zip download to see my settings)
On the Basic tab; "name of the application" and your developer contact.
On the Connect tab; "Connect url", you should enter the root of your gallery, for the example: "http://www.yourwebsite.com/gallery/"
               "Base Domain", you should enter the root of your site, for the example: "www.yourwebsite.com"
Take note of the "application ID", "API key", and the "secret" (write down or be ready to copy this information. (DO NOT SHARE THIS INFO WITH ANYONE!)


Backup your database before adding this mod. It makes changes to your USERS table.
These are the modified files that you will need to backup before modifying.
categories.php
details.php
global.php
index.php
lightbox.php
login.php
member.php
postcards.php
register.php
rss.php
search.php
top.php
includes\page_header.php
includes\sessions.php
lang\english\main.php
your template\details.html
your template\header.html
your template\member_editprofile.html
your template\user_loginform.html
your template\user_logininfo.html

Lets get started...

Download and unzip the file attached and place the facebook folder with it's content in the root of your gallery.
Place the facebook_install.php file in the root of your gallery and run it to add the fields to your user table. (DELETE THIS FILE AFTER YOU RUN IT!)
Protect the facebook folder anyway you can, I placed an index.php file in it that will reroute anyone directory browsing to your homepage (replace with your website path in the index.php file)
or delete it if you are using another method to keep people out.

Copy the "application ID", "API key", "secret", and "base domain" information into the top of the FBMAIN.PHP file.

Now, onto modifying your current files...

in the categories.php, lightbox.php, member.php, register.php, rss.php, top.php, index.php, postcards.php, search.php, and details.php files...
find
Code: [Select]
$user_access = get_permission();insert after
Code: [Select]
include_once(ROOT_PATH.'facebook/fbstatus.php');//MOD facebook connect
in the login.php file...
find
Code: [Select]
if ($site_sess->login($user_name, $user_password, $auto_login)) {insert after
Code: [Select]
//MOD facebook connect
if ($fbme){
$fb_userinfo=$site_sess->return_user_info();
if ($fb_userinfo['user_email'] !== $fbme['email']){
redirect($facebook->getLogoutUrl(array('next' => dirname(curPageURL()).'/'.$url)));
}
}
//END MOD facebook connect

Also in the details.php file...
find
Code: [Select]
"prepend_head_title"        => $image_name . " - ",insert after
Code: [Select]
"facebook_title"        => $image_name,
in the global.php file...
find
Code: [Select]
if (!defined('ROOT_PATH')) {
  die("Security violation");
}
insert after
Code: [Select]
if (!defined("IN_CP")) include_once(ROOT_PATH.'facebook/fbmain.php'); //MOD facebook connect

find
Code: [Select]
?>insert before
Code: [Select]
//MOD facebook connect
$fb_status=0;
//END MOD facebook connect

in the lang/english/main.php file...
find
Code: [Select]
?>insert before
Code: [Select]
//-----------------------------------------------------
//--- Facebook connect -------------------------------------
//-----------------------------------------------------
$lang['fbl_confirm'] = "\"To logout of Facebook also Select 'OK'\"";
$lang['fbl_lang'] = "en_US";// please see http://www.facebook.com/translations/FacebookLocales.xml
$lang['fbl_change_password'] = "Attention Facebook Users!";
$lang['fbl_passmessage'] = "If your account was created when you signed in with your Facebook account, then your password was randomly created.<br> You will need to <b>logout</b> of this site and click on <b>'forgot password'</b> to have a new one sent to you.";
$lang['fbl_sharing'] = "Facebook Sharing";

in the includes\page_header.php file...
find
Code: [Select]
$site_template->register_vars($array);insert after
Code: [Select]
//MOD facebook connect
if (strstr($site_sess->url($script_url."/".$self_url),'?')){
$fbstatus="&fb_status=1";
}else{
$fbstatus="?fb_status=1";
}
$site_template->register_vars(array("fb_status"=>$fbstatus));
//END MOD facebook connect

find
Code: [Select]
//-----------------------------------------------------
//--- User Box ----------------------------------------
//-----------------------------------------------------
insert before
Code: [Select]
//MOD facebook connect
$fbl_loggedin = ($fbme)?1:0;
$fb_url = $site_sess->url($script_url."/".$self_url);
if (strpos($fb_url,"&")){
$fb_url=substr($fb_url,0,strpos($fb_url,"&"));
}
$site_template->register_vars(array(
    "fb_appid" => FBAPPID,
"fbl_loggedin" => $fbl_loggedin,
"fbl_confirm" => $lang['fbl_confirm'],
"fbl_lang" => $lang['fbl_lang'],
"fbl_passmessage" => $lang['fbl_passmessage'],
"fbl_sharing" => $lang['fbl_sharing'],
"fb_url" => $fb_url)
);
unset($fbl_loggedin,$fb_url);
//END MOD facebook connect

in the includes\sessions.php file...
find
Code: [Select]
"user_icq" => "user_icq"replace with
Code: [Select]
"user_icq" => "user_icq",
  "fb_userid" => "fb_userid"
 
find
Code: [Select]
function logout($user_id) {insert before
Code: [Select]
//MOD facebook connect
  function fb_login($user_name = "", $user_password = "", $auto_login = 0, $set_auto_login = 1) {
    global $site_db, $user_table_fields;

    if (empty($user_name) || empty($user_password)) {
      return false;
    }
    $sql = "SELECT ".get_user_table_field("", "user_id").get_user_table_field(", ", "user_password")."
            FROM ".USERS_TABLE."
            WHERE ".get_user_table_field("", "user_name")." = '$user_name' AND ".get_user_table_field("", "user_level")." <> ".USER_AWAITING;
    $row = $site_db->query_firstrow($sql);

    $user_id = (isset($row[$user_table_fields['user_id']])) ? $row[$user_table_fields['user_id']] : GUEST;
    if ($user_id != GUEST) {
      if ($row[$user_table_fields['user_password']] == $user_password) {
        $sql = "UPDATE ".SESSIONS_TABLE."
                SET session_user_id = $user_id
                WHERE session_id = '".addslashes($this->session_id)."'";
        $site_db->query($sql);
        if ($set_auto_login) {
          $this->set_cookie_data("userpass", ($auto_login) ? $user_password : "");
        }
        $this->start_session($user_id, 1);
        return true;
      }
    }
    return false;
  }
//END MOD facebook connect

The following modifications are using the default template as a model...
yours may be different...


in the your_template_folder\header.html file...
find
Code: [Select]
<html dir="{direction}">insert after
Code: [Select]
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

find
Code: [Select]
{if has_rss}insert before
Code: [Select]
<script language="JavaScript">
<!--
function fb_confirm_entry()
{
FB.getLoginStatus(function(response){
if (response.session){
input_box=confirm({fbl_confirm});
if (input_box==true){FB.logout(function(response){});}}});
}
-->
</script>

find
Code: [Select]
<body bgcolor="#FFFFFF" text="#0F5475" link="#0F5475" vlink="#0F5475" alink="#0F5475">
<br />
insert after
Code: [Select]
   <div id="fb-root"></div>
        <script type="text/javascript">
            window.fbAsyncInit = function() {
                FB.init({appId: '{fb_appid}', status: true, cookie: true, xfbml: true});

                /* All the events registered */
                FB.Event.subscribe('auth.login', function(response) {
                    // do something with response
                    login();
                });
                FB.Event.subscribe('auth.logout', function(response) {
                    // do something with response
                    logout();
                });
            };
            (function() {
                var e = document.createElement('script');
                e.type = 'text/javascript';
                e.src = document.location.protocol +
                    '//connect.facebook.net/{fbl_lang}/all.js';
                e.async = true;
                document.getElementById('fb-root').appendChild(e);
            }());

            function login(){
                document.location.href = '{self_full}{fb_status}';
            }
            function logout(){
                document.location.href = '{self_full}{fb_status}';
            }
</script>

in the your_template_folder\member_editprofile.html file...
at the end of the document or after the change password form insert this code
Code: [Select]
{if fbl_loggedin}
<br />
  <table width="100%" border="0" cellspacing="0" cellpadding="1">
    <tr>
      <td valign="top" class="head1">
        <table width="100%" border="0" cellpadding="4" cellspacing="0">
          <tr>
            <td colspan="2" valign="top" class="head1">{fbl_change_password}</td>
          </tr>
          <tr>
            <td class="row1">{fbl_passmessage}</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
{endif fbl_loggedin}

in the your_template_folder\user_loginform.html file...
find
Code: [Select]
<a href="{url_register}">{lang_register}</a><br>&nbsp;</td>insert after
Code: [Select]
 </tr><tr><td valign="top" align="center">
{if fbl_loggedin}
<table width="100%" border="0"><tr><td align="right">
<fb:profile-pic uid='loggedinuser' facebook-logo='false'></fb:profile-pic></td><td valign="center" align="left"> Welcome,<BR> <fb:name uid='loggedinuser' useyou='false'></fb:name>
</td></tr></table>
{endif fbl_loggedin}
 <fb:login-button size="small" length="long" autologoutlink="true" perms="email,user_website,publish_stream"></fb:login-button>
</td>

in the your_template_folder\user_logininfo.html file...
find
Code: [Select]
<a href="{url_logout}">{lang_logout}</a><br>&nbsp;</td>replace with
Code: [Select]
<a href="{url_logout}" onclick="fb_confirm_entry()">{lang_logout}</a></td>
 </tr><tr><td valign="top" align="center">
{if fbl_loggedin}
<table width="100%" border="0"><tr><td align="right">
<fb:profile-pic uid='loggedinuser' facebook-logo='false'></fb:profile-pic></td><td valign="center" align="left"> Welcome,<BR> <fb:name uid='loggedinuser' useyou='false'></fb:name>
</td></tr></table>
{endif fbl_loggedin}
 <fb:login-button size="small" length="long" autologoutlink="true" perms="email,user_website,publish_stream"></fb:login-button>
 </td>
     
You can now integrate the social plugins that Facebook offers for your 4images site...
they can be found here... http://developers.facebook.com/plugins

I added the "Like and the Share" buttons to my details pages of my site with the following code...
in the your_template_folder\details.html file...
find
Code: [Select]
<tr>
                            <td valign="top" class="row2"><b>{lang_keywords}</b></td>
                            <td valign="top" class="row2">{image_keywords}</td>
                          </tr>
insert before
Code: [Select]
 <tr>
                            <td valign="top" class="row1" width="33%">
<b>{fbl_sharing}</b><br><br><center><fb:share-button  type="button_count" href="{fb_url}">
<meta name="title" content="{facebook_title}"/>
<meta name="description" content="{image_description}"/>
<link rel="image_src" href="{facebook_image}" />
</fb:share-button></center></td>
                            <td valign="top" class="row1">
<fb:like width="66%" href="{fb_url}">
<meta name="title" content="{facebook_title}"/>
</fb:like>
</td>
                          </tr>

The
Code: [Select]
<meta name="title" content="{facebook_title}"/> is using the imagename for its title.
If you are using a better dynamic title on your detail pages I would suggest replacing the {facebook_title} with the variable for that mod for a better title for your image.

There are allot of issues with the like/share buttons as of creating this mod,
sometimes they show thumbnails, sometimes not. sometimes adds correctly, sometimes not.
The issues are with facebook and not with anything I have done. (Do not ask me to fix anything regarding those issues unless you can prove it is in my code causing the problem!)

There are some unusual things that happen from time to time, and if anyone can look my coding over and see if it is secure I would appriciate it.
I also would have like putting the include statements in the global.php file instead of all the others but it never worked when I did that so if anyone can help there it would make future changes easier.


« Last Edit: January 22, 2012, 09:22:04 PM by budduke »
Buddy Duke
www.budduke.com

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Facebook Connector V1.0
« Reply #1 on: June 14, 2010, 12:16:43 AM »
Thanks for sharing this mod.

The fist step could be simplified by adding this into global.php instead of all main files:
if (!defined("IN_CP")) include_once(ROOT_PATH.'facebook/fbmain.php'); //MOD facebook connect
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Facebook Connector V1.0
« Reply #2 on: June 14, 2010, 01:10:55 AM »
Thanks for sharing this mod.

The fist step could be simplified by adding this into global.php instead of all main files:
if (!defined("IN_CP")) include_once(ROOT_PATH.'facebook/fbmain.php'); //MOD facebook connect


Thanks V@no!
I have changed my original post...
Hopefully nobody already started on it. If they did they will need to remove the
Code: [Select]
include_once(ROOT_PATH.'facebook/fbmain.php'); //MOD facebook connectfrom all the files above except the global.php file...
Buddy Duke
www.budduke.com

Offline webvision

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [MOD] Facebook Connector V1.0
« Reply #3 on: June 14, 2010, 01:52:27 AM »
I have one thing to say excellent!

Offline GaYan

  • Sr. Member
  • ****
  • Posts: 301
  • ♫ | G2 | ♫
    • View Profile
    • Ziramagic
Re: [MOD] Facebook Connector V1.0
« Reply #4 on: June 14, 2010, 05:03:50 AM »
 :D Sir, normally you keep silent for a bit , and when you return.. Boom  :mrgreen: .. you share he best modes for the 4images,, you are aming the best of best sir ! Keep it up! Great Mod !  :wink:
I'm Back :)

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Facebook Connector V1.0
« Reply #5 on: June 14, 2010, 09:05:40 AM »
This looks very promising... but I have a question:

What would happened when you signup with facebook account and your username is already taken?

I have also noticed that there is error with logout link. When you want to logout from gallery some FB code show up.

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Facebook Connector V1.0
« Reply #6 on: June 14, 2010, 12:09:12 PM »
This looks very promising... but I have a question:

What would happened when you signup with facebook account and your username is already taken?

I have also noticed that there is error with logout link. When you want to logout from gallery some FB code show up.
first question: It will add numbers to the end of the name until it gets a username that does not already exist.

second one: do you have php warnings being suppressed? I do know it makes a call to facebook to see if you are attached or not but I rechecked the code to make sure I removed that array that you say is showing up. Can you provide me with a link to see if it is the same thing?
Buddy Duke
www.budduke.com

Offline Sumale.my

  • Addicted member
  • ******
  • Posts: 1.790
  • I ♥ 4I
    • View Profile
Beste Gre
Sumale.my

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [MOD] Facebook Connector V1.0
« Reply #8 on: June 17, 2010, 12:35:05 PM »
This looks very promising... but I have a question:

What would happened when you signup with facebook account and your username is already taken?

I have also noticed that there is error with logout link. When you want to logout from gallery some FB code show up.
first question: It will add numbers to the end of the name until it gets a username that does not already exist.

second one: do you have php warnings being suppressed? I do know it makes a call to facebook to see if you are attached or not but I rechecked the code to make sure I removed that array that you say is showing up. Can you provide me with a link to see if it is the same thing?

Thx for you answers, here is attached screenshot of that error that i was talking about...

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Facebook Connector V1.0
« Reply #9 on: June 17, 2010, 05:51:38 PM »
@ Lucifix,
Interesting, You are using firefox.
I tested a bunch of combinations of logins/out on ie8 without any issues.
I do not have firefox on my work computer, will have to look at it this weekend. I tested firefox a few time while creating it but never saw that error.
Can you give me any step by step how you logged in/out? Was it strait facebook login/out both ways?

I did find one bug, I opened another browser window and logged into facebook and then logged into my site in another browser window under a different username then the facebook one, it gave me a blank page. Will be looking into that also this weekend...

Update: I have tested it here at home...
IE8, chrome, comodo dragon, and opera all seem to work fine (chrome locked up once when I was logging in, not sure why)
firefox, you are correct, when you login using facebook and then I logged out from my site the normal way and saying "Yes, I want to log out of facebook" I get the error you attached. Will have to do some digging, not sure why only firefox is doing that  :?:

UPDATE #2:
The version of files that I had on my site was one version behind the ones I posted. The files in the zip file in the post are the correct ones. I changed the files on my site to the same ones I posted and firefox is working correctly now...
The only issue I still see the the one bug I mentioned above, will look into that this weekend
« Last Edit: June 18, 2010, 12:21:48 AM by budduke »
Buddy Duke
www.budduke.com

Offline relu

  • Newbie
  • *
  • Posts: 44
    • View Profile
    • Pulsarmedia
Re: [MOD] Facebook Connector V1.0
« Reply #10 on: July 03, 2010, 10:43:40 AM »
When running facebook_install.php i get Installation status

       1. Error:

          ALTER TABLE `4images_users` ADD `fb_userid` VARCHAR(255) NOT NULL, ADD `fl_facebook` ENUM(\'new\',\'normal\',\'registered\') NOT NULL DEFAULT \'registered\'

What i should check?

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Facebook Connector V1.0
« Reply #11 on: July 03, 2010, 03:15:49 PM »
@ relu,

I would go into your phpadmin and see if the fields "fb_userid" and "fl_facebook" have been added...

I have never had an issue with that installer file unless your sql version does not support something...
Buddy Duke
www.budduke.com

Offline jonnyo

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: [MOD] Facebook Connector V1.0
« Reply #12 on: July 05, 2010, 10:03:30 PM »
When running facebook_install.php i get Installation status

       1. Error:

          ALTER TABLE `4images_users` ADD `fb_userid` VARCHAR(255) NOT NULL, ADD `fl_facebook` ENUM(\'new\',\'normal\',\'registered\') NOT NULL DEFAULT \'registered\'

What i should check?

Ive goten this aswell, and in phpadmin no tables have been created under 4images_users..

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: [MOD] Facebook Connector V1.0
« Reply #13 on: July 05, 2010, 10:12:18 PM »
@ jonnyo and relu,
What version of PHP are your running?
phpinfo() in the admin panel will give you the answer.
Buddy Duke
www.budduke.com

Offline jonnyo

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: [MOD] Facebook Connector V1.0
« Reply #14 on: July 05, 2010, 10:17:32 PM »
it says: PHP Version 5.2.13
ended up adding the tables manualy,not sure if right tho..

but still getting:
Code: [Select]
Parse error: syntax error, unexpected T_CONST in /home/jonnyo/public_html/CSSS/facebook/fbmain.php on line 5
took lines 5 to  8 out and loads ok. but cant connect due to no keys..

 

Post your comments here