[MOD] Facebook Connector V2.0This 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/DEMO...http://www.budduke.comVersion History...2.0 - upgrade from old model (using facebook php-sdk kit version 3.1.1)
Version 2 of this mod now support the Auth 2.0 that Facebook has moved over to.
NOTE: If you have Version 1 of this Mod installed, You will need to remove all the code you placed in Version 1.0 before you proceed. You can leave the database entries but all the code inserts must be removed.
The old version mod steps can be found here.http://www.4homepages.de/forum/index.php?topic=27396.0New facebook users will now have to "agree to terms" and "create a password" before gaining entry into your site.Facebook users that are already created from version 1 of this mod will not have to do the above steps.
This mod is in conjunction with my other mod
http://www.4homepages.de/forum/index.php?topic=29422.0The like/send/share button so some of the steps may be the same as you are going through them.
Backup your database before continuing. This will make changes to your settings and user databases.You will need to unzip the attached file to the root of your 4images gallery and run the facebook_install.php file to place the entries into your database. Delete this file after you have ran it once.
You will also have a facebook folder with the correct files in it after you expand the zip file.
The following files will be modified...admin\settings.php
includes\db_field_definitions.php
includes\page_header.php
includes\sessions.php
lang\english\admin.php
lang\english\main.php
logout.php
register.php
templates\your template\header.html
templates\your template\register_form.html
templates\your template\user_loginform.html
templates\your template\user_logininfo.html
STEP 1.a (this insert is the same as my like/share/send MOD V3.1 Step 5.a)
in your
admin/settings.php file
search for
// end of functions
Insert
Before//[MOD] Facebook
function show_fb_language_options($setting_name, $setting_value) {
global $fb_language_optionlist;
echo "<select name=\"setting_item[".$setting_name."]\">";
foreach ($fb_language_optionlist as $key => $val) {
echo "<option value=\"$key\"";
if ($setting_value == $key) {
echo " selected=\"selected\"";
}
echo ">".$val."</option>";
}
echo "</select>";
}
//END [MOD] Facebook
Step 1.b (this insert is the same as my like/share/send MOD V3.1 Step 5.b)
Search for
show_form_footer($lang['save_changes'], "", 2);
Insert
Before// [MOD] Facebook
show_table_separator($setting_group["facebook"], 2, "setting_group_facebook");
show_setting_row("fb_appid");
if ($fb_mod_select==1 || $fb_mod_select==3){
show_setting_row("fb_appsec");
}
if ($fb_mod_select>1){
show_setting_row("fb_admins");
show_setting_row("fb_title");
show_setting_row("fb_main_url");
show_setting_row("fb_image");
show_setting_row("fb_description","textarea");
}
show_setting_row("fb_language","show_fb_language_options");
// END[MOD] Facebook
Step 2in your
includes\db_field_definitions.php file
Search for
?>
Insert
Before//MOD facebook
$additional_user_fields['fb_userid'] = array($lang['fb_userid'], "text",0);
$additional_user_fields['fb_name'] = array($lang['fb_name'], "text",0);
$additional_user_fields['fb_pic_small'] = array($lang['fb_pic_small'], "text",0);
//end MOD facebook
Step 3in your
includes\page_header.php file
search for
//-----------------------------------------------------
//--- User Box ----------------------------------------
//-----------------------------------------------------
insert
Before//MOD facebook
include_once (ROOT_PATH.'facebook/fbmain.php');
if (($user_info['user_level'] >= USER)&&($fb_flag==3)) {
$site_sess->set_session_var("fb_flag", 0);
$fb_flag=0;
}
if ((!$fb_flag) && ($file!="register")) {
fb_checkstatus();
}
$fb['hide1']=$fb_flag>1?1:0;
$fb['hide2']=$fb_flag==3?1:0;
$fb['loggedin'] = $fb_session>0?1:0;
$site_template->register_vars(array(
"fb_appid" => $config['fb_appid'],
"fb_language" => isset($lang['fb_language']) ? $lang['fb_language'] : $config['fb_language'],
"fb_hide1" => $fb['hide1'],
"fb_hide2" => $fb['hide2'],
"fb_message" => $lang['fb_message'],
"fb_loggedin" => $fb['loggedin'],
"fb_pic_small" =>$user_info['fb_pic_small'],
"fb_userid"=>$user_info['fb_userid'],
"fb_name"=>$user_info['fb_name'],
"fb_logout_url"=>(ROOT_PATH=="./") ? "logout.php" : $site_sess->url($script_url."/".substr(ROOT_PATH,2)."logout.php"),
));
unset ($fb);
//end MOD facebook
Step 4in your
includes\sessions.php file
search for
function logout($user_id)
insert
Before//MOD facebook
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
Step 5 (this insert is the same as my like/share/send MOD V3.1 Step 6)
Note: first line $fb_mod_select=1 (change to 3 if using both mods)in your
lang\english\admin.php file
search for
?>
insert
Before//[MOD] Facebook
$fb_mod_select=1; // 1="login button Mod", 2="like/share/send button Mod", 3="both Mods installed"
/*-- Setting-Group Facebook --*/
$setting_group["facebook"]="Facebook settings";
$setting['fb_appid'] = "Application ID";
$setting['fb_appsec'] = "Application Secret";
$setting['fb_admins'] = "List of facebook IDs as admins<br><span class=\"smalltext\">IDs seperated by commas</span>";
$setting['fb_main_url'] = "Full HTML path to your website<br><span class=\"smalltext\">What you placed in the connect URL on facebook</span>";
$setting['fb_image'] = "Full HTML path to your logo/image for your website";
$setting['fb_title'] = "What you would like the Main Title to say for your website";
$setting['fb_description'] = "Description displayed for your website<br><span class=\"smalltext\">HTML code will be removed</span>";
$setting['fb_language'] = "Default language to use for Facebook";
$fb_language_optionlist = array(
'ca_ES' => 'Catalan',
'cs_CZ' => 'Czech',
'cy_GB' => 'Welsh',
'da_DK' => 'Danish',
'de_DE' => 'German',
'eu_ES' => 'Basque',
'en_PI' => 'English (Pirate)',
'en_UD' => 'English (Upside Down)',
'ck_US' => 'Cherokee',
'en_US' => 'English (US)',
'es_LA' => 'Spanish',
'es_CL' => 'Spanish (Chile)',
'es_CO' => 'Spanish (Colombia)',
'es_ES' => 'Spanish (Spain)',
'es_MX' => 'Spanish (Mexico)',
'es_VE' => 'Spanish (Venezuela)',
'fb_FI' => 'Finnish (test)',
'fi_FI' => 'Finnish',
'fr_FR' => 'French (France)',
'gl_ES' => 'Galician',
'hu_HU' => 'Hungarian',
'it_IT' => 'Italian',
'ja_JP' => 'Japanese',
'ko_KR' => 'Korean',
'nb_NO' => 'Norwegian (bokmal)',
'nn_NO' => 'Norwegian (nynorsk)',
'nl_NL' => 'Dutch',
'pl_PL' => 'Polish',
'pt_BR' => 'Portuguese (Brazil)',
'pt_PT' => 'Portuguese (Portugal)',
'ro_RO' => 'Romanian',
'ru_RU' => 'Russian',
'sk_SK' => 'Slovak',
'sl_SI' => 'Slovenian',
'sv_SE' => 'Swedish',
'th_TH' => 'Thai',
'tr_TR' => 'Turkish',
'ku_TR' => 'Kurdish',
'zh_CN' => 'Simplified Chinese (China)',
'zh_HK' => 'Traditional Chinese (Hong Kong)',
'zh_TW' => 'Traditional Chinese (Taiwan)',
'fb_LT' => 'Leet Speak',
'af_ZA' => 'Afrikaans',
'sq_AL' => 'Albanian',
'hy_AM' => 'Armenian',
'az_AZ' => 'Azeri',
'be_BY' => 'Belarusian',
'bn_IN' => 'Bengali',
'bs_BA' => 'Bosnian',
'bg_BG' => 'Bulgarian',
'hr_HR' => 'Croatian',
'nl_BE' => 'Dutch (België)',
'en_GB' => 'English (UK)',
'eo_EO' => 'Esperanto',
'et_EE' => 'Estonian',
'fo_FO' => 'Faroese',
'fr_CA' => 'French (Canada)',
'ka_GE' => 'Georgian',
'el_GR' => 'Greek',
'gu_IN' => 'Gujarati',
'hi_IN' => 'Hindi',
'is_IS' => 'Icelandic',
'id_ID' => 'Indonesian',
'ga_IE' => 'Irish',
'jv_ID' => 'Javanese',
'kn_IN' => 'Kannada',
'kk_KZ' => 'Kazakh',
'la_VA' => 'Latin',
'lv_LV' => 'Latvian',
'li_NL' => 'Limburgish',
'lt_LT' => 'Lithuanian',
'mk_MK' => 'Macedonian',
'mg_MG' => 'Malagasy',
'ms_MY' => 'Malay',
'mt_MT' => 'Maltese',
'mr_IN' => 'Marathi',
'mn_MN' => 'Mongolian',
'ne_NP' => 'Nepali',
'pa_IN' => 'Punjabi',
'rm_CH' => 'Romansh',
'sa_IN' => 'Sanskrit',
'sr_RS' => 'Serbian',
'so_SO' => 'Somali',
'sw_KE' => 'Swahili',
'tl_PH' => 'Filipino',
'ta_IN' => 'Tamil',
'tt_RU' => 'Tatar',
'te_IN' => 'Telugu',
'ml_IN' => 'Malayalam',
'uk_UA' => 'Ukrainian',
'uz_UZ' => 'Uzbek',
'vi_VN' => 'Vietnamese',
'xh_ZA' => 'Xhosa',
'zu_ZA' => 'Zulu',
'km_KH' => 'Khmer',
'tg_TJ' => 'Tajik',
'ar_AR' => 'Arabic',
'he_IL' => 'Hebrew',
'ur_PK' => 'Urdu',
'fa_IR' => 'Persian',
'sy_SY' => 'Syriac',
'yi_DE' => 'Yiddish',
'gn_PY' => 'Guaraní',
'qu_PE' => 'Quechua',
'ay_BO' => 'Aymara',
'se_NO' => 'Northern Sámi',
'ps_AF' => 'Pashto',
'tl_ST' => 'Klingon'
);
//END [MOD] Facebook
Step 6in your
lang/english/main.php file
search for
?>
insert
Before//MOD facebook
$lang['fb_userid'] = "Facebook User ID";
$lang['fb_name'] = "Facebook User Name";
$lang['fb_pic_small'] = "Facebook Picture link";
$lang['fb_message'] = "Your account has not been activated yet.";
$lang['fb_password'] = "Password to be used<br>for access to this site:";
$lang['fb_register_success'] = "You are now registered.";
//END MOD facebook
Step 7in your
logout.php file
search for
require(ROOT_PATH.'includes/sessions.php');
insert
After//MOD facebook
$site_sess->set_session_var("fb_flag", 0);
$fb_flag=0;
include_once (ROOT_PATH.'facebook/fbmain.php');
fb_checkstatus();
//END MOD facebook
Step 8.aNote: read insert line that begins with $captcha_enable_registration=0;in your
register.php file
search for
//-----------------------------------------------------
//--- Add New User ------------------------------------
//-----------------------------------------------------
insert
Before//MOD facebook
if ($action == "register" && $fb_flag == 2){
if (!$HTTP_POST_VARS['user_name']){
$tempuser = $fb_info[0]['name'];
$tempuser = preg_replace("/ /","_",$fb_info[0]['name']);
$found=false;
$i=0;
while (!$found){
$user=$tempuser.($i==0?"":$i);
$sql="SELECT count(*) from ".USERS_TABLE." where user_name='".$user."'";
$row = $site_db->query_firstrow($sql);
if ($row[0]!=0) $i++; else $found=true;
}
$HTTP_POST_VARS['user_name']=$user;
}
$captcha_enable_registration=0;// change to 1 if you want New facebook users to enter captcha
}
if ($fb_flag == 2){
$HTTP_POST_VARS['user_email'] = $fb_info[0]['email'];
$site_template->register_vars(array(
"fb_password" => $lang['fb_password'],
));
}
//END MOD facebook
Step 8.bsearch for
$msg = $lang['register_success']
insert
After //MOD facebook
$site_sess->set_session_var("fb_flag", 3);
$fb_flag=3;
//END MOD facebook
Step 8.csearch for
$msg = $lang['register_success_none'];
insert
After //MOD facebook
if ($fb_flag>1){ $msg=$lang['fb_register_success'];}
$site_sess->set_session_var("fb_flag", 0);
$fb_flag=0;
//END MOD facebok
Step 8.dsearch for
$msg = $lang['activation_success'];
insert
After //MOD facebook
$site_sess->set_session_var("fb_flag", 0);
$fb_flag=0;
//END MOD facebok
Step 9.a(this insert is the same as my like/share/send mod V3.1 step 2.a)
in your
templates/your template/header.html file
search for
<html dir="{direction}">
Replace with
<html dir="{direction}" xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
Step 9.b(this insert is the same as my like/share/send mod V3.1 step 2.c)
At the end of the page insert
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '{fb_appid}',
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.logout', function(response) {
window.location = '{fb_logout_url}';
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/{fb_language}/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
Step 10.ain your
templates/your template/user_loginform.html file
search for
<form action="{url_login}" method="post">
insert
Before{ifnot fb_hide1}
Step 10.bsearch for
» <a href="{url_lost_password}">{lang_lost_password}</a><br />
insert
After {endifnot fb_hide1}
{ifnot fb_hide2}
Step 10.csearch for
» <a href="{url_register}">{lang_register}</a><br> </td>
insert
After {endifnot fb_hide2}
{if fb_hide2}
{fb_message}
{endif fb_hide2}
Step 10.dsearch for
</table>
insert
Before <tr><td valign="top" align="center">
{if fb_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 fb_loggedin}
<fb:login-button size="small" length="long" autologoutlink="true" scope="email,user_website,publish_stream" ></fb:login-button>
</td></tr>
Step 11.ain your
templates/your template/user_logininfo.html file
search for
<a href="{url_control_panel}">{lang_control_panel}</a><br />
insert
After {ifnot fb_loggedin}
Step 11.bsearch for
<a href="{url_logout}">{lang_logout}</a><br> </td>
insert
After {endifnot fb_loggedin}
Step 11.csearch for
</table>
insert
Before <tr><td valign="top" align="center">
{if fb_loggedin}
<table width="100%" border="0"><tr><td align="right">
<img src="{fb_pic_small}"></img></td><td valign="center" align="left"> Welcome,<BR> <a href="http://www.facebook.com/profile.php?id={fb_userid}">{fb_name}</a>
</td></tr></table>
{endif fb_loggedin}
<fb:login-button size="small" length="long" autologoutlink="true" scope="email,user_website,publish_stream" ></fb:login-button>
</td></tr>
Step 12in your
templates/your template/register_form.html file
search for
{lang_password}
Replace with
{if fb_password}{fb_password}{endif fb_password}{ifnot fb_password}{lang_password}{endifnot fb_password}
after you are finished going through the steps, you will find in the admin control panel, under settings,
you will see facebook settings, this is where you will put the info for your facebook application to make this mod work.
How do you make a facebook application? this link will give you the steps. they are a little outdated but should still get you on the right track until I have a chance to redo them.
http://www.4homepages.de/forum/index.php?topic=29422.msg157086#msg157086