1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

pref fixes and some cleanup

This commit is contained in:
CaMer0n
2009-11-10 02:18:04 +00:00
parent 31d3d6b1be
commit e55393412d
2 changed files with 706 additions and 697 deletions

View File

@@ -14,26 +14,102 @@ if (!getperms("P"))
exit();
}*/
class facebook_admin extends e_admin_dispatcher
{
protected $modes = array(
'main' => array(
'controller' => 'facebook_main_ui',
'path' => null,
'ui' => 'facebook_admin_form_ui',
'uipath' => null
)
);
protected $adminMenu = array(
'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => '0'),
'main/custom' => array('caption'=> 'Instructions', 'perm' => '0')
);
protected $menuTitle = 'Facebook';
}
class facebook_main_ui extends e_admin_ui
{
protected $pluginTitle = 'Facebook Connect';
protected $pluginName = 'facebook';
protected $prefs = array(
'Facebook_App-Bundle' => array('title'=> 'Facebook Application ID', 'type'=>'text'),
'Facebook_Api-Key' => array('title'=> 'Facebook API Key', 'type'=>'text'),
'Facebook_Secret-Key' => array('title'=> 'Facebook Secret Key', 'type'=>'text')
);
function customPage()
{
global $ns,$pref;
$text = '
<h2><img class="left" src="'.e_PLUGIN.'facebook/images/facebooklogo.gif" alt="" /> Setting Up Your Application and Getting an API Key</h2>
<div style="padding:20px">
<table style="'.ADMIN_WIDTH.'">
<tr>
<td>
<p>If you don\'t already have a Facebook Platform API key for your site, create an application with the <a href="http://www.facebook.com/developers" class="external text" title="http://www.facebook.com/developers" rel="nofollow">Facebook Developer application</a>.
</p><p><b>Note:</b> Even if you have created an application and received an API key, you should review steps 1.4 through 1.7 and make sure your application settings are appropriate.
</p>
<ol><li>1. Go to <a href="http://www.facebook.com/developers/createapp.php" class="external free" title="http://www.facebook.com/developers/createapp.php" rel="nofollow">http://www.facebook.com/developers/createapp.php</a> to create a new application.
</li><li>2. Enter a name for your application in the <b>Application Name</b> field.
</li><li>3. Accept the <a href="http://developers.facebook.com/terms.php" class="external text" title="http://developers.facebook.com/terms.php" rel="nofollow">Developer Terms of Service</a>, then click <b>Save Changes</b>.
</li><li>4. On the <b>Basic</b> tab, keep all of the defaults.
</li><li>5. Take note of the <b>API Key</b>, you\'ll need this shortly.<br/>
</li><li>6. Click the <b>Connect</b> tab. Set <b>Connect URL</b> to the top-level directory of the site where you plan to implement Facebook Connect (this is usually your domain, like <a href="http://www.example.com" class="external free" title="http://www.example.com" rel="nofollow">http://www.example.com</a>, but could also be a subdirectory).
</li><li>7. You should include a logo that appears on the Facebook Connect dialog. Next to <b>Facebook Connect Logo</b>, click <b>Change your Facebook Connect logo</b> and browse to an image file. The logo can be up to 99 pixels wide by 22 pixels tall, and must be in JPG, GIF, or PNG format.
</li><li>8. If you plan to implement Facebook Connect across a number of subdomains of your site (for example, foo.example.com and bar.example.com), you need to enter a <b><a href="/index.php/Base_Domain" title="Base Domain">Base Domain</a></b> (which would be example.com in this case). Specifying a base domain allows you to make calls using the <a href="/index.php/PHP" title="PHP">PHP</a> and <a href="/index.php/JavaScript_Client_Library" title="JavaScript Client Library">JavaScript</a> client libraries as well as get and store session information for any subdomain of the base domain. For more information about subdomains, see <a href="/index.php/Supporting_Subdomains_In_Facebook_Connect" title="Supporting Subdomains In Facebook Connect">Supporting Subdomains In Facebook Connect</a>.
</li><li>9. Click <b>Save Changes</b>.
</li></ol>
</td>
</tr>
</table>
</div>
';
return $text;
}
}
class facebook_admin_form_ui extends e_admin_form_ui
{
function init()
{
}
}
new facebook_admin();
require_once(e_ADMIN."auth.php");
$fb = new facebook_admin;
if (isset($_POST['save-settings']))
{
$fb->save_settings();
$fb->message = "<div style='text-align:center;padding:20px'>Preferences Updated!</div>";
}
$fb->pref_form();
e107::getAdminUI()->runPage();
require_once(e_ADMIN."footer.php");
exit;
class facebook_admin
class facebook_aasdadmin
{
var $message;
@@ -106,37 +182,7 @@ class facebook_admin
function display_help()
{
global $ns,$pref;
$text = '
<div style="padding:20px">
<h2>Setting Up Your Application and Getting an API Key</h2>
<table style="'.ADMIN_WIDTH.'">
<tr>
<td>
<p>If you don\'t already have a Facebook Platform API key for your site, create an application with the <a href="http://www.facebook.com/developers" class="external text" title="http://www.facebook.com/developers" rel="nofollow">Facebook Developer application</a>.
</p><p><b>Note:</b> Even if you have created an application and received an API key, you should review steps 1.4 through 1.7 and make sure your application settings are appropriate.
</p>
<ol><li>1. Go to <a href="http://www.facebook.com/developers/createapp.php" class="external free" title="http://www.facebook.com/developers/createapp.php" rel="nofollow">http://www.facebook.com/developers/createapp.php</a> to create a new application.
</li><li>2. Enter a name for your application in the <b>Application Name</b> field.
</li><li>3. Accept the <a href="http://developers.facebook.com/terms.php" class="external text" title="http://developers.facebook.com/terms.php" rel="nofollow">Developer Terms of Service</a>, then click <b>Save Changes</b>.
</li><li>4. On the <b>Basic</b> tab, keep all of the defaults.
</li><li>5. Take note of the <b>API Key</b>, you\'ll need this shortly.<br/>
</li><li>6. Click the <b>Connect</b> tab. Set <b>Connect URL</b> to the top-level directory of the site where you plan to implement Facebook Connect (this is usually your domain, like <a href="http://www.example.com" class="external free" title="http://www.example.com" rel="nofollow">http://www.example.com</a>, but could also be a subdirectory).
</li><li>7. You should include a logo that appears on the Facebook Connect dialog. Next to <b>Facebook Connect Logo</b>, click <b>Change your Facebook Connect logo</b> and browse to an image file. The logo can be up to 99 pixels wide by 22 pixels tall, and must be in JPG, GIF, or PNG format.
</li><li>8. If you plan to implement Facebook Connect across a number of subdomains of your site (for example, foo.example.com and bar.example.com), you need to enter a <b><a href="/index.php/Base_Domain" title="Base Domain">Base Domain</a></b> (which would be example.com in this case). Specifying a base domain allows you to make calls using the <a href="/index.php/PHP" title="PHP">PHP</a> and <a href="/index.php/JavaScript_Client_Library" title="JavaScript Client Library">JavaScript</a> client libraries as well as get and store session information for any subdomain of the base domain. For more information about subdomains, see <a href="/index.php/Supporting_Subdomains_In_Facebook_Connect" title="Supporting Subdomains In Facebook Connect">Supporting Subdomains In Facebook Connect</a>.
</li><li>9. Click <b>Save Changes</b>.
</li></ol>
</td>
</tr>
</table>
</div>';
return $text;
}
}

View File

@@ -1,25 +1,27 @@
<?php
//error_reporting(E_ALL);
if ( !defined ( 'e107_INIT' ) ) {
if (!defined('e107_INIT'))
{
exit;
}
require_once (e_PLUGIN.'facebook/facebook-client/facebook.php');
/**
* simple get the Facebook User ID one is logged in!
*
*/
function is_fb() {
try{
function is_fb()
{
try
{
$fbclient = &facebook_client();
if ($fbclient)
return $fbclient->get_loggedin_user();
}catch (FacebookRestClientException $e) {
}
catch (FacebookRestClientException $e)
{
//echo "Facebook connect error:".$e->getCode();
}
return null;
@@ -33,9 +35,8 @@ function is_fb() {
*
*/
function Add_Facebook_Connect_User ( $info = '', $user_id ) {
function Add_Facebook_Connect_User($info = '', $user_id)
{
/* $full = array (
'facebook_about_me' => Get_Facebook_Info ( 'about_me' ) ,
@@ -74,28 +75,16 @@ function Add_Facebook_Connect_User ( $info = '', $user_id ) {
'facebook_work_history' => Get_Facebook_Info ( 'work_history' )
) ; */
$standard = array (
'facebook_connected' => '1',
'facebook_uid' => is_fb() ,
'facebook_user_id' => $user_id,
'facebook_last_name' => Get_Facebook_Info ( 'last_name' ) ,
'facebook_username' => Get_Facebook_Info ( 'username' ) ,
'facebook_name' => Get_Facebook_Info ( 'name' ) ,
$standard = array('facebook_connected'=>'1', 'facebook_uid'=>is_fb(), 'facebook_user_id'=>$user_id, 'facebook_last_name'=>Get_Facebook_Info('last_name'), 'facebook_username'=>Get_Facebook_Info('username'), 'facebook_name'=>Get_Facebook_Info('name'),
//'facebook_affiliations' => Get_Facebook_Info ( 'affiliations' ) ,
'facebook_sex' => Get_Facebook_Info ( 'sex' ) ,
'facebook_timezone' => Get_Facebook_Info ( 'timezone' ) ,
'facebook_birthday' => Get_Facebook_Info ( 'birthday' ) ,
'facebook_profile_url' => Get_Facebook_Info ( 'profile_url' ) ,
'facebook_sex'=>Get_Facebook_Info('sex'), 'facebook_timezone'=>Get_Facebook_Info('timezone'), 'facebook_birthday'=>Get_Facebook_Info('birthday'), 'facebook_profile_url'=>Get_Facebook_Info('profile_url'),
//'facebook_proxied_email' => Get_Facebook_Info ( 'proxied_emai' ) ,
'facebook_email_hashes' => Get_Facebook_Info ( 'email_hashes' ) ,
'facebook_first_name' => Get_Facebook_Info ( 'first_name' ) ,
'facebook_current_location' => Get_Facebook_Info ( 'current_location' ) ,
'facebook_locale' => Get_Facebook_Info ( 'locale' )
) ;
'facebook_email_hashes'=>Get_Facebook_Info('email_hashes'), 'facebook_first_name'=>Get_Facebook_Info('first_name'), 'facebook_current_location'=>Get_Facebook_Info('current_location'), 'facebook_locale'=>Get_Facebook_Info('locale'));
$query = $standard;
if ( trim ( $info ) == 'full' ) {
if (trim($info) == 'full')
{
$query = array_push($standard, $full);
@@ -111,8 +100,10 @@ function Add_Facebook_Connect_User ( $info = '', $user_id ) {
*
*/
function Render_Facebook_Profile() {
if ( is_fb() ) {
function Render_Facebook_Profile()
{
if (is_fb())
{
$html .= '<div class="welcome_msg">';
$html .= 'Welcome, '.Get_Facebook_Info('name');
@@ -123,10 +114,10 @@ function Render_Facebook_Profile() {
$html .= '</span>';
$html .= '</div>';
//check for User Permission
if ( Has_App_Permission( 'publish_stream' ) == 0 ) {
if (Has_App_Permission('publish_stream') == 0)
{
$html .= '<div class="facebook_notice">';
$html .= '<fb:prompt-permission perms="read_stream,publish_stream">';
@@ -139,11 +130,8 @@ function Render_Facebook_Profile() {
/*
if ( ADMIN )
{
$html .= '<a href="' . e_ADMIN . 'admin.php">&rarr; Admin Area</a><br />';
}
$html .= '<br /><a href="' . e_BASE . 'usersettings.php">&rarr; Settings</a><br />';
$html .= '<a href="' . e_BASE . 'user.php?id . ' . USERID . '">&rarr; Profile</a><br />';
@@ -166,15 +154,20 @@ function Render_Facebook_Profile() {
*
*/
function facebook_client() {
function facebook_client()
{
global $pref;
$pref = e107::getPlugConfig()->getPref();
static $facebook = null;
if ( $facebook === null ) {
if ($facebook === null)
{
$facebook = new Facebook($pref['Facebook_Api-Key'], $pref['Facebook_Secret-Key']);
if ( !$facebook ) {
if (!$facebook)
{
// Could not create facebook client!
}
@@ -182,7 +175,6 @@ function facebook_client() {
return $facebook;
}
/**
* since 2009 User Permission Required for Post Stream
*
@@ -192,11 +184,11 @@ function facebook_client() {
*
* return 0 OR 1
*/
function Has_App_Permission($ext_perm)
{
function Has_App_Permission( $ext_perm ) {
if ( is_fb() ) {
if (is_fb())
{
$HasAppPermission = facebook_client()->api_client->users_hasAppPermission($ext_perm, is_fb());
@@ -206,37 +198,36 @@ $HasAppPermission = facebook_client()->api_client->users_hasAppPermission ( $ext
}
/**
* Function for retrieve Facebook info by using his API
*
* more info: http://wiki.developers.facebook.com/index.php/User_ ( FQL )
*
*/
function Get_Facebook_Info($info, $friend = '')
{
function Get_Facebook_Info ( $info , $friend = '' ) {
if ( is_fb() ) {
if (is_fb())
{
$uid = is_fb();
if ( $friend != '' ) {
if ($friend != '')
{
$uid = $friend;
}
$info_data = facebook_client()->api_client->users_getInfo($uid, $info);
if ( ! empty ( $info_data ) ) {
if (! empty($info_data))
{
$data[$info] = $info_data[0][$info];
if ( is_array ( $data[ $info ] ) ) {
if (is_array($data[$info]))
{
$data[$info] = implode(',', $info_data[0][$info]);
@@ -249,7 +240,6 @@ function Get_Facebook_Info ( $info , $friend = '' ) {
return $text;
}
}
/**
@@ -257,11 +247,13 @@ function Get_Facebook_Info ( $info , $friend = '' ) {
*
*/
function Fb_Connect_Me() {
function Fb_Connect_Me()
{
global $sql;
$sql4 = new db;
if ( !$sql4->db_select("user_extended","*","user_facebookID = '".is_fb()."' ") ) {
if (!$sql4->db_select("user_extended", "*", "user_facebookID = '".is_fb()."' "))
{
$nickname = username_exists(Get_Facebook_Info('first_name'));
$password = md5(is_fb());
@@ -269,22 +261,9 @@ if ( !$sql4->db_select("user_extended","*","user_facebookID = '".is_fb()."' ")
$sql2 = new db;
$sql2->db_Insert ( 'user',
array (
'user_name' => $nickname,
'user_loginname' => $username,
'user_password' => $password,
'user_login' => Get_Facebook_Info ( 'name' ) ,
'user_image' => Get_Facebook_Info ( 'pic' )
)
) ;
$sql2->db_Insert('user', array('user_name'=>$nickname, 'user_loginname'=>$username, 'user_password'=>$password, 'user_login'=>Get_Facebook_Info('name'), 'user_image'=>Get_Facebook_Info('pic')));
$sql3 = new db;
$sql3->db_Insert ( 'user_extended',
array (
'user_extended_id' => last_user() ,
'user_facebookID' => is_fb()
)
) ;
$sql3->db_Insert('user_extended', array('user_extended_id'=>last_user(), 'user_facebookID'=>is_fb()));
Add_Facebook_Connect_User('', last_user());
@@ -294,7 +273,8 @@ $sql3 = new db;
}
}
function UEID () {
function UEID()
{
global $sql;
@@ -310,12 +290,14 @@ function UEID () {
*
*/
function Fb_LogOut() {
function Fb_LogOut()
{
//$uid = UEID() ? UEID() : is_fb();
global $sql;
if ( $sql->db_Select ( "facebook", "*", "facebook_connected = '1' AND facebook_user_id = '".USERID."' " ) ) {
if ($sql->db_Select("facebook", "*", "facebook_connected = '1' AND facebook_user_id = '".USERID."' "))
{
$row = $sql->db_Fetch();
extract($row);
@@ -329,15 +311,18 @@ function Fb_LogOut() {
* Re-Login in e107 without request new Facebook session!
*
*/
function Fb_LogIn() {
function Fb_LogIn()
{
$sql = new db;
$sql2 = new db;
if ( $sql->db_Update ( "facebook", "facebook_connected = '1' WHERE facebook_uid = '".is_fb() ."' " ) ) {
if ($sql->db_Update("facebook", "facebook_connected = '1' WHERE facebook_uid = '".is_fb()."' "))
{
Log_In_Registered_User();
} else if ( $sql2->db_Select ( "user_extended", "*", "user_facebookID = '".is_fb() ."' " ) ) {
}
else if ($sql2->db_Select("user_extended", "*", "user_facebookID = '".is_fb()."' "))
{
$row2 = $sql2->db_Fetch();
extract($row2);
@@ -345,7 +330,9 @@ function Fb_LogIn() {
Log_In_Registered_User();
} else {
}
else
{
Fb_Connect_Me();
@@ -354,35 +341,33 @@ function Fb_LogIn() {
header('Location: '.e_SELF);
}
/**
* check for e107 connection status: 1 = logged In , 0 = logged Out
*
*/
function your_facebook_is() {
function your_facebook_is()
{
$uid = is_fb();
return ( $uid ) ?
'your facebook id is: <b>'. $uid .'</b>'
:'';
return ($uid) ? 'your facebook id is: <b>'.$uid.'</b>' : '';
}
function Get_Connection_Status() {
function Get_Connection_Status()
{
$sql = new db;
$sql2 = new db;
if (($sql->db_Select("facebook", "*", "facebook_uid = '".is_fb()."' ")) ||
($sql2->db_Select("user_extended", "*", "user_facebookID = '".is_fb()."' "))
) {
)
{
$row = $sql->db_Fetch();
return $row['facebook_connected'] ? $row['facebook_connected'] : '0';
} else {
}
else
{
return '';
@@ -393,30 +378,30 @@ function Get_Connection_Status() {
* Ensure e107 and Facebook Are well linked!
*
*/
function Facebook_User_Is_Connected() {
function Facebook_User_Is_Connected()
{
global $sql;
if ( $sql->db_select("user_extended", "*", "user_extended_id = '".get_id_from_uid ( is_fb() )."' AND user_facebookID = '".is_fb()."' ") ) {
if ($sql->db_select("user_extended", "*", "user_extended_id = '".get_id_from_uid(is_fb())."' AND user_facebookID = '".is_fb()."' "))
{
return true;
} else {
return false;
}
else
{
return false;
}
}
/**
* Log out from Facebook by JS
*
*/
function Facebook_LogOut()
{
function Facebook_LogOut() {
if ( is_fb () ) {
if (is_fb())
{
onloadRegister('facebook_log_out(); ');
Fb_LogOut();
@@ -424,39 +409,31 @@ function Facebook_User_Is_Connected() {
}
/**
*
*
*
*
*/
function Delete_Duplicate_Facebook_User() {
function Delete_Duplicate_Facebook_User()
{
$sql = e107::getDb();
$id = get_id_from_uid(is_fb());
$sql1->db_Delete("user_extended", "user_extended_id='".$id."'");
$sql2->db_Delete("facebook", "facebook_uid='".is_fb()."'");
$sql3->db_Delete("user", "user_loginname='FacebookUser_".is_fb()."'");
$sql->db_Delete("user_extended", "user_extended_id='".$id."'");
$sql->db_Delete("facebook", "facebook_uid='".is_fb()."'");
$sql->db_Delete("user", "user_loginname='FacebookUser_".is_fb()."'");
}
function Switch_Facebook_User() {
function Switch_Facebook_User()
{
$sql1 = new db;
$sql2 = new db;
$sql3 = new db;
$sql4 = new db;
if ( !$sql1->db_Insert ( 'user_extended',
array (
'user_extended_id' => USERID ,
'user_facebookID' => is_fb()
))) {
if (!$sql1->db_Insert('user_extended', array('user_extended_id'=>USERID, 'user_facebookID'=>is_fb())))
{
$sql2->db_Update("user_extended", "user_facebookID = '".is_fb()."' WHERE user_extended_id = '".USERID."' ");
@@ -468,28 +445,21 @@ function Facebook_User_Is_Connected() {
$sql4->db_Update("facebook", "facebook_user_id = '".USERID."' WHERE facebook_uid = '".is_fb()."' ");
}
/**
* check for Facebook presence and validation
*
*/
function single_uid()
{
$sql = e107::getDb();
function single_uid(){
$sql = new db;
$count = $sql->db_Count("user_extended", "(*)",
"WHERE user_facebookID = '".is_fb()."'");
$count = $sql->db_Count("user_extended", "(*)", "WHERE user_facebookID = '".is_fb()."'");
return $count;
}
function uid_check() {
function uid_check()
{
$sql = e107::getDb();
$sql = new db;
$sql2 = new db;
$sql3 = new db;
@@ -499,26 +469,29 @@ function uid_check() {
$msg = "";
if ( $sql->db_select ( "user_extended", "*","user_facebookID = '".is_fb()."' AND user_extended_id !='".USERID."'" ) ) {
if ($sql->db_select("user_extended", "*", "user_facebookID = '".is_fb()."' AND user_extended_id !='".USERID."'"))
{
// header ( 'Location: ' . e_SELF ) ;
$msg .= "<div class='facebook_notice'><a href='".e_SELF."?facebook_switch' title='switch user'>would you like to use facebook with this account? press this link!</a></div>";
$msg .= "<div class='facebook_notice'><a href='".e_SELF."?facebook_delete' title='delete user'>would you like to delete this facebook account? press this link!</a></div>";
} else if ( $sql->db_select ( "user_extended", "*", "user_facebookID != '".is_fb()."' ") ) {
}
else if ($sql->db_select("user_extended", "*", "user_facebookID != '".is_fb()."' "))
{
$msg = "<div class='facebook_notice'> <a href='usersettings.php' title='click here'>The provided Facebook ID is wrong!</a> </div> <div class='fb_green'>".your_facebook_is()."</div>";
} else if ( $sql->db_select ( "user_extended", "*", "user_facebookID = '' ") ) {
}
else if ($sql->db_select("user_extended", "*", "user_facebookID = '' "))
{
$msg = "<div class='facebook_notice'><a href='usersettings.php' title='click here'>Specify your Facebook ID in the Profile Settings! </a></div><div class='fb_green'>".your_facebook_is()."</div>";
} else {
}
else
{
$msg = '<a href="#" onclick="facebook_onlogin_ready();">
<img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif" alt="Connect" />
@@ -529,22 +502,19 @@ function uid_check() {
return $msg;
}
function uid_exists() {
global $sql;
if( $sql->db_select ( "user_extended", "*","user_extended_id = '".USERID."' AND user_facebookID = '".is_fb()."'") ) {
function uid_exists()
{
$sql = e107::getDb();
if ($sql->db_select("user_extended", "*", "user_extended_id = '".USERID."' AND user_facebookID = '".is_fb()."'"))
{
$row = $sql->db_Fetch();
return $row['user_extended_id'];
} else {
return null;
}
else
{
return null;
}
}
/**
@@ -552,30 +522,29 @@ function uid_exists() {
*
*/
function fb_icon() {
function fb_icon()
{
return " <img src=\"".e_PLUGIN."facebook/images/icon_16.png\" alt=\"\" /> ";
}
/**
* get profile picture by requesting it to Facebook; but we can use also the infos stored in facebook table!
*
*/
function getProfilePic ( $uid, $show_logo = false ) {
return ( $uid ) ? ( '<fb:profile-pic uid="' . $uid . '" size="square" ' . ( $show_logo?' facebook-logo="true"':'' ) . '></fb:profile-pic>' )
:'<img src="http://static.ak.fbcdn.net/pics/q_default.gif" />';
function getProfilePic($uid, $show_logo = false)
{
return ($uid) ? ('<fb:profile-pic uid="'.$uid.'" size="square" '.($show_logo ? ' facebook-logo="true"' : '').'></fb:profile-pic>') : '<img src="http://static.ak.fbcdn.net/pics/q_default.gif" />';
}
/**
* get USERID by knowing his Facebook ID
*
*/
function get_id_from_uid ( $uid ) {
global $sql;
function get_id_from_uid($uid)
{
$sql = e107::getDb();
$sql->db_Select("facebook", "*", "facebook_uid = '$uid' ");
@@ -585,13 +554,13 @@ function get_id_from_uid ( $uid ) {
}
function render_facebook_init_js($uid)
{
function render_facebook_init_js ( $uid ) {
$sql = e107::getDb();
$pref = e107::getPlugConfig()->getPref();
global $pref, $sql;
$text .=
'<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
$text .= '<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
FB_RequireFeatures ( [ "XFBML" ], function() {
FB.init ( "'.$pref['Facebook_Api-Key'].'", "'.e_PLUGIN.'facebook/xd_receiver.php" ) ;
@@ -604,11 +573,7 @@ function render_facebook_init_js ( $uid ) {
return $text;
}
/*
/**
* Render a custom button to log in via Facebook.
* When the button is clicked, the Facebook JS library pops up a Connect dialog
* to authenticate the user.
@@ -618,41 +583,37 @@ function render_facebook_init_js ( $uid ) {
* @param $size size of the button. one of ( 'small', 'medium', 'large' )
* http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif
*/
function Render_Facebook_Connect_Button ( $size = 'medium' ) {
if ( !is_fb() ) {
function Render_Facebook_Connect_Button($size = 'medium')
{
if (!is_fb())
{
/* return '<a href="#" onclick="FB.Connect.requireSession(); return false;" ><img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif" alt="Connect"/></a>';*/
return '<fb:login-button ' .
'size="' . $size . '" background="light" length="long" ' .
'onlogin="facebook_onlogin_ready();"></fb:login-button>';
return '<fb:login-button '.'size="'.$size.'" background="light" length="long" '.'onlogin="facebook_onlogin_ready();"></fb:login-button>';
}
}
/**
* Render pseudo Facebook button when USER logOut from e107
*
*/
function Render_Fcuk_Facebook_Connect_Button() {
function Render_Fcuk_Facebook_Connect_Button()
{
return '
<div class="welcome_msg">Welcome '.Get_Facebook_Info('name').' !<br /> Click below to Login</div> <br />
<a href="'.e_SELF.'?login">
<img id="fb_login_image" src="'.e_PLUGIN.'facebook/images/facebooklogin.gif" alt="Click to Login"/></a>
<img id="fb_login_image" src="'.e_PLUGIN_ABS.'facebook/images/facebooklogin.gif" alt="Click to Login"/></a>
';
}
function register_feed_form_js() {
function register_feed_form_js()
{
onloadRegister("facebook_publish_feed_story('".getStreamToPublish()."');");
}
/*
@@ -660,7 +621,8 @@ function register_feed_form_js() {
* it wants to actually refresh it, so we want to prevent the browser from
* caching them.
*/
function prevent_cache_headers() {
function prevent_cache_headers()
{
header('Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
}
@@ -670,25 +632,29 @@ function prevent_cache_headers() {
*
* This is printed in render_footer() , so make sure to include that on all pages.
*/
function onloadRegister ( $js ) {
function onloadRegister($js)
{
global $onload_js;
$onload_js .= $js;
}
/**
* expire Facebook session = logOut
* not used yet!
*/
function fb_expire_session() {
try {
function fb_expire_session()
{
try
{
$fbclient = &facebook_client();
if ( $fbclient && $fbclient->get_loggedin_user() != "" ) {
if ($fbclient && $fbclient->get_loggedin_user() != "")
{
$fbclient->expire_session();
}
} catch ( Exception $e )
}
catch (Exception $e)
{
//nothing, probably an expired session
}
@@ -699,10 +665,9 @@ function fb_expire_session() {
*
*/
function Get_Fecebook_Status ( $uid ) {
return ( $uid ) ?
'<fb:user-status uid="' . $uid . '" ></fb:user-status>'
:'';
function Get_Fecebook_Status($uid)
{
return ($uid) ? '<fb:user-status uid="'.$uid.'" ></fb:user-status>' : '';
}
/**
@@ -710,61 +675,55 @@ function Get_Fecebook_Status ( $uid ) {
*
*/
function Render_Invite_Friends_Link() {
return ' <a href="javascript;" onclick="FB.Connect.inviteConnectUsers();' .
' return false;">&rarr; Invite them to Connect.</a> ';
function Render_Invite_Friends_Link()
{
return ' <a href="javascript;" onclick="FB.Connect.inviteConnectUsers();'.' return false;">&rarr; Invite them to Connect.</a> ';
}
function Render_Fun_Box ( $stream , $connections , $width ) {
global $pref;
function Render_Fun_Box($stream, $connections, $width)
{
$pref = e107::getPlugConfig()->getPref();
return '<fb:fan profile_id="'.$pref['Facebook_App-Bundle'].'" stream="'.$stream.'" connections="'.$connections.'" width="'.$width.'"></fb:fan><div style="font-size:8px; padding-left:10px"><a href="'.e_PLUGIN.'facebook">e107fbconnect</a> on Facebook</div>';
}
/**
* Render all Facebook User Friends
*
*/
function Render_Facebook_Friends_Table() {
function Render_Facebook_Friends_Table()
{
$friends = facebook_client()->api_client->friends_get();
$n = (count($friends) * 60 / 2);
if ( $n > 300 ) {
if ($n > 300)
{
$n = 300;
}
if ( is_array ( $friends ) && !empty ( $friends ) ) {
if (is_array($friends) && ! empty($friends))
{
$html .= '<div style="width:200px;height:'.$n.'px;overflow:auto" >';
foreach ( $friends as $friend ) {
if ( $friend ) {
foreach ($friends as $friend)
{
if ($friend)
{
$html .= '<div style="margin:0;width:50px;height:50px;padding-top:10px;padding-right:5px;float:left">'.getProfilePic($friend).'</div>';
}
}
$html .= '</div>';
return $html;
} else {
}
else
{
return '';
}
}
@@ -774,14 +733,15 @@ function Render_Facebook_Friends_Table() {
*
*/
function Render_Connect_Invite_Friends() {
function Render_Connect_Invite_Friends()
{
//$friends = facebook_client()->api_client->friends_get() ;
//$has_existing_friends = count ( $friends ) ;
//$more = $has_existing_friends?' more':'';
$num = '<fb:unconnected-friends-count></fb:unconnected-friends-count>';
if ( $num > 0 ) {
if ($num > 0)
{
//$one_friend_text = 'You have one' . $more . ' Facebook friend that also join on ' . SITENAME;
//$multiple_friends_text = 'You have ' . $num.$more . ' Facebook friends that also join on ' . SITENAME;
//$invite_link = '<a onclick="FB.Connect.inviteConnectUsers() ; return false;">Invite them to Connect.</a>';
@@ -798,13 +758,13 @@ function Render_Connect_Invite_Friends() {
}
}
/*
* Make the API call to register the feed forms. This is a setup call that only
* needs to be made once.
*
*/
function register_feed_forms() {
function register_feed_forms()
{
$one_line_stories = $short_stories = $full_stories = array();
$one_line_stories[] = '{*actor*} went for a {*distance*} run at {*location*} . ';
@@ -818,40 +778,43 @@ function register_feed_forms() {
*
*/
function username_exists ( $user ) {
$sql = new db;
if ( $sql->db_Select ( "user", "user_loginname", "user_loginname = '$user' " ) ) {
$sql2 = new db;
$count = $sql2->db_Count ( "user", "(*)",
"WHERE $name LIKE '$user%' " ) ;
function username_exists($user)
{
$sql = e107::getDb();
$sql = e107::getDb('sql2');
if ($sql->db_Select("user", "user_loginname", "user_loginname = '$user' "))
{
$count = $sql2->db_Count("user", "(*)", "WHERE $name LIKE '$user%' ");
$num = $count + 1;
return username_exists($user.$num);
} else {
}
else
{
return $user;
}
}
/**
* Set Login cookies
*
*/
function set_cookies ( $id, $pwd ) {
function set_cookies($id, $pwd)
{
global $pref;
$cockiename = $pref['cookie_name'] ? $pref['cookie_name'] : 'e107cookie';
$cookieval = $id.".".$pwd;
if ( $pref[ 'user_tracking' ] == 'session' ) {
if ($pref['user_tracking'] == 'session')
{
$_SESSION[$cockiename] = $cookieval;
} else {
}
else
{
cookie($cockiename, $cookieval, (time() + 3600 * 24 * 30));
}
return $_SESSION[$cockiename];
@@ -862,27 +825,26 @@ function set_cookies ( $id, $pwd ) {
* not used yet!
*/
function get_info ( $info , $uid ) {
$sql = new db;
if ( $sql->db_select ( "user", "*", "user_id = '$uid'" ) ) {
function get_info($info, $uid)
{
$sql = e107::getDb();
if ($sql->db_select("user", "*", "user_id = '$uid'"))
{
$row = $sql->db_Fetch();
extract($row);
return $row[$info];
} else {
}
else
{
return false;
}
}
function Log_In_Registered_User(){
if ( !USER ) {
function Log_In_Registered_User()
{
if (!USER)
{
$uid = get_id_from_uid(is_fb());
@@ -898,7 +860,8 @@ if ( !USER ) {
*
*/
function last_user() {
function last_user()
{
$sql = new db;
$qry = "SELECT
user_id