1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-18 05:09:05 +01:00

start of function/class rewrite

This commit is contained in:
CaMer0n 2009-11-11 12:25:13 +00:00
parent f1ecf52e90
commit 9c75f4766f
3 changed files with 222 additions and 141 deletions

View File

@ -1,158 +1,140 @@
<?php
//error_reporting(E_ALL);
include_once (e_PLUGIN.'facebook/facebook_function.php');
e107::getEvent()->register('logout',array('e_facebook','fb_logout'),e_PLUGIN.'facebook/facebook_function.php');
if (function_exists('prevent_cache_headers'))
{
prevent_cache_headers();
}
$fb = e107::getSingleton('e_facebook',e_PLUGIN.'facebook/facebook_function.php');
/**
* just define facebook XMLNS
*
*/
define(XMLNS, "xmlns:fb='http://www.facebook.com/2008/fbml'");
/**
* Ensure "Make entering an email address optional" is setted to "ON";
*
*/
global $pref;
if ($pref['disable_emailcheck'] == 0)
if (USER_AREA)
{
$pref['disable_emailcheck'] = 1;
include_once (e_PLUGIN.'facebook/facebook_function.php');
save_prefs();
if (function_exists('prevent_cache_headers'))
{
prevent_cache_headers();
}
}
/**
* when clicked it insert a new User
*
*/
if (e_QUERY == 'facebook')
{
define(XMLNS, "xmlns:fb='http://www.facebook.com/2008/fbml'");
Fb_Connect_Me();
global $pref;
if ($pref['disable_emailcheck'] == 0) // Ensure "Make entering an email address optional" is setted to "ON";
{
$pref['disable_emailcheck'] = 1;
save_prefs();
}
if (e_QUERY == 'facebook') // when clicked it inserts a new User in e107.
{
Fb_Connect_Me();
}
if (e_QUERY == 'login') // simple Re-Login after logged out from e107
{
Fb_LogIn();
}
if (e_QUERY == 'logout') // simulate Facebook logOut when logged out from e107
{
// Fb_LogOut();
}
if (e_QUERY == 'facebook_switch')
{
Switch_Facebook_User();
}
if (USERID && (e_QUERY == 'facebook_link'))
{
Add_Facebook_Connect_User('', USERID);
}
if (e_QUERY == 'facebook_delete')
{
Delete_Duplicate_Facebook_User();
}
}
/**
* simple Re-Login after logged out from e107
*
*/
if (e_QUERY == 'login')
{
Fb_LogIn();
}
/**
* simulate Facebook logOut when logged out from e107
*
*/
if (e_QUERY == 'logout')
{
Fb_LogOut();
}
if (e_QUERY == 'facebook_switch')
{
Switch_Facebook_User();
}
if (USERID && (e_QUERY == 'facebook_link'))
{
Add_Facebook_Connect_User('', USERID);
}
if (e_QUERY == 'facebook_delete')
{
Delete_Duplicate_Facebook_User();
}
function theme_foot()
{
function theme_foot()
{
/**
* the init js needs to be at the bottom of the document, within the </body> tag
* this is so that any xfbml elements are already rendered by the time the xfbml
* rendering takes over. otherwise, it might miss some elements in the doc.
*
*/
global $onload_js;
$text .= render_facebook_init_js(is_fb());
// Print out all onload function calls
if ($onload_js)
{
$text .= '<script type="text/javascript">'.'window.onload = function() { '.$onload_js.' };'.'</script>';
}
return $text;
}
/**
* the init js needs to be at the bottom of the document, within the </body> tag
* this is so that any xfbml elements are already rendered by the time the xfbml
* rendering takes over. otherwise, it might miss some elements in the doc.
*
* Facebook Deprecated get Feed Story trough Template Bundle 2009
*
function getTemplateData() {
$template_data = array(
'post_title' => $_POST[ 'subject' ],
'body' => $_POST[ 'comment' ],
'body_short' => $_POST[ 'comment' ],
'post_permalink' => e_SELF,
'blogname' => SITENAME,
'blogdesc' => SITEDESCRIPTION,
'siteurl' => SITEURLBASE);
return $template_data;
}
*/
/**
* get Feed Story infos to send to Facebook
*
* the new way FB.Connect.streamPublish();
*
*/
function getStreamToPublish()
{
//global $pref;
//$stream = facebook_client()->api_client->stream_get('','','','','',''.$pref[ 'Facebook_App-Bundle' ].'','');
// $stream = facebook_client()->api_client->stream_publish($_POST[ 'comment' ]);
return $_POST['comment'];
}
/**
* if comment is submitted and "publish_to_facebook" is checked send a copy to Facebook
*
*/
global $onload_js;
$text .= render_facebook_init_js(is_fb());
// Print out all onload function calls
if ($onload_js)
if (isset($_POST['commentsubmit']) && ($_POST['publish_to_facebook'] == true))
{
$text .= '<script type="text/javascript">'.'window.onload = function() { '.$onload_js.' };'.'</script>';
register_feed_form_js();
}
return $text;
}
/**
*
* Facebook Deprecated get Feed Story trough Template Bundle 2009
*
function getTemplateData() {
$template_data = array(
'post_title' => $_POST[ 'subject' ],
'body' => $_POST[ 'comment' ],
'body_short' => $_POST[ 'comment' ],
'post_permalink' => e_SELF,
'blogname' => SITENAME,
'blogdesc' => SITEDESCRIPTION,
'siteurl' => SITEURLBASE);
return $template_data;
}
*/
/**
* get Feed Story infos to send to Facebook
*
* the new way FB.Connect.streamPublish();
*
*/
function getStreamToPublish()
{
//global $pref;
//$stream = facebook_client()->api_client->stream_get('','','','','',''.$pref[ 'Facebook_App-Bundle' ].'','');
// $stream = facebook_client()->api_client->stream_publish($_POST[ 'comment' ]);
return $_POST['comment'];
}
/**
* if comment is submitted and "publish_to_facebook" is checked send a copy to Facebook
*
*/
if (isset($_POST['commentsubmit']) && ($_POST['publish_to_facebook'] == true))
{
register_feed_form_js();
}
?>
?>

View File

@ -10,8 +10,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/facebook/facebook_function.php,v $
| $Revision: 1.6 $
| $Date: 2009-11-10 15:25:50 $
| $Revision: 1.7 $
| $Date: 2009-11-11 12:25:13 $
| $Author: e107coders $
+----------------------------------------------------------------------------+
*/
@ -284,8 +284,8 @@ function Fb_Connect_Me()
Add_Facebook_Connect_User('', $nid);
require_once(e_HANDLER.'login.php');
$usr = new userlogin($row['user_loginname'], md5($row['user_name'].$row['user_password'].$row['user_join']), 'signup', '');
// require_once(e_HANDLER.'login.php');
// $usr = new userlogin($row['user_loginname'], md5($row['user_name'].$row['user_password'].$row['user_join']), 'signup', '');
set_cookies($nid, md5($password));
// fb_redirect(e_SELF);
@ -787,7 +787,7 @@ function register_feed_forms()
function username_exists($user)
{
$sql = e107::getDb();
$sql = e107::getDb('sql2');
$sql2 = e107::getDb('sql2');
if ($sql->db_Select("user", "user_loginname", "user_loginname = '$user' "))
{
$count = $sql2->db_Count("user", "(*)", "WHERE $name LIKE '$user%' ");
@ -892,7 +892,106 @@ function fb_redirect($loc)
class e_facebook
{
public $fb_uid;
public $e107_userid;
function __construct()
{
$this->fb_uid = $this->getFacebookId();
$this->e107_userid = $this->getUserId($this->fb_uid);
// echo "UID=".$this->fb_uid;
// echo "<br />e107=".$this->e107_userid;
}
function getUserId($uid)
{
$sql = e107::getDb();
if($sql->db_Select("facebook", "facebook_user_id", "facebook_uid = ".$this->fb_uid))
{
$row = $sql->db_Fetch();
return $row['facebook_user_id'];
}
else
{
return FALSE;
}
}
function getFacebookId()
{
try
{
$fbclient = &facebook_client();
if ($fbclient)
{
return $fbclient->get_loggedin_user();
}
}
catch (FacebookRestClientException $e)
{
//echo "Facebook connect error:".$e->getCode();
}
return null;
}
function addFacebookUser()
{
$sql = e107::getDb();
if (!$sql->db_Select("facebook", "*", "facebook_uid = '".$this->fb_uid."' "))
{
$nickname = username_exists(Get_Facebook_Info('first_name'));
$password = md5(is_fb());
$username = "FacebookUser_".is_fb();
$nid = $sql->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')));
Add_Facebook_Connect_User('', $nid);
// require_once(e_HANDLER.'login.php');
// $usr = new userlogin($row['user_loginname'], md5($row['user_name'].$row['user_password'].$row['user_join']), 'signup', '');
set_cookies($nid, md5($password));
// fb_redirect(e_SELF);
}
}
function fb_login()
{
$sql = e107::getDb();
if ($sql->db_Update("facebook", "facebook_connected = '1' WHERE facebook_uid = '".is_fb()."' "))
{
Log_In_Registered_User(); // log in to e107.
}
else
{
$this->addFacebookUser(); // not found, so create a new facebook user.
}
fb_redirect(e_SELF);
}
function fb_logout()
{
if(!varset($this->fb_uid))
{
// echo "UID not Found";
}
$sql = e107::getDb();
$sql->db_Update("facebook", "facebook_connected = '0' WHERE facebook_uid = ".$this->fb_uid." ");
}
function fb_connect()
{
global $pref;

View File

@ -14,7 +14,7 @@ if (isset($_POST['fb_sig_in_canvas']))
}
$fb = e107::getSingleton('e_facebook',e_PLUGIN.'facebook/facebook_function.php');
$html = $fb->fb_login();
$html = $fb->fb_connect();
$caption = 'Facebook';
// $text = $tp->parseTemplate($html, true, $facebook_shortcodes);