Facebook Connector VERSION 2.0 CAN BE FOUND HERE...
http://www.4homepages.de/forum/index.php?topic=27396.msg160225#msg160225[MOD] Facebook Connector V1.0DO 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_APIhttp://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.comVersion 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.phpclick 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$user_access = get_permission();
insert
afterinclude_once(ROOT_PATH.'facebook/fbstatus.php');//MOD facebook connect
in the
login.php file...
findif ($site_sess->login($user_name, $user_password, $auto_login)) {
insert
after//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"prepend_head_title" => $image_name . " - ",
insert
after"facebook_title" => $image_name,
in the
global.php file...
findif (!defined('ROOT_PATH')) {
die("Security violation");
}
insert
afterif (!defined("IN_CP")) include_once(ROOT_PATH.'facebook/fbmain.php'); //MOD facebook connect
find?>
insert
before//MOD facebook connect
$fb_status=0;
//END MOD facebook connect
in the
lang/english/main.php file...
find?>
insert
before//-----------------------------------------------------
//--- 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$site_template->register_vars($array);
insert
after//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//-----------------------------------------------------
//--- User Box ----------------------------------------
//-----------------------------------------------------
insert
before//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"user_icq" => "user_icq"
replace with
"user_icq" => "user_icq",
"fb_userid" => "fb_userid"
findfunction logout($user_id) {
insert
before//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<html dir="{direction}">
insert
after<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
find{if has_rss}
insert
before<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<body bgcolor="#FFFFFF" text="#0F5475" link="#0F5475" vlink="#0F5475" alink="#0F5475">
<br />
insert
after <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
{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» <a href="{url_register}">{lang_register}</a><br> </td>
insert
after </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» <a href="{url_logout}">{lang_logout}</a><br> </td>
replace with
» <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/pluginsI 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<tr>
<td valign="top" class="row2"><b>{lang_keywords}</b></td>
<td valign="top" class="row2">{image_keywords}</td>
</tr>
insert
before <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
<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.