forked from hybridauth/hybridauth
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 2 examples Sign-in/Sign-up users and Basic Facebook in
- Loading branch information
hybridauth
committed
Nov 22, 2011
1 parent
ad23b4d
commit f6975d6
Showing
25 changed files
with
970 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
session_start(); | ||
|
||
$config = dirname(__FILE__) . '/../../hybridauth/config.php'; | ||
require_once( "../../hybridauth/Hybrid/Auth.php" ); | ||
|
||
if( isset( $_GET["login"] ) ){ | ||
try{ | ||
// hybridauth EP | ||
$hybridauth = new Hybrid_Auth( $config ); | ||
|
||
$adapter = $hybridauth->authenticate( "facebook" ); | ||
|
||
$user_profile = $adapter->getUserProfile(); | ||
} | ||
catch( Exception $e ){ | ||
die( "<b>got an error!</b> " . $e->getMessage() ); | ||
} | ||
} | ||
|
||
if( ! isset( $user_profile ) ){ | ||
?> | ||
<p> | ||
A basic example which show how to integrate Facebook Dialogs and stuff on your website side by side whith HybridAuth. Click the Signin link to start. | ||
</p> | ||
|
||
<h2><a href ="index.php?login=1">Signin with facebook</a></h2> | ||
|
||
<img src="../fb.gif" style="border:1px solid #ccc;padding:4px;" /> | ||
<?php | ||
} | ||
else{ | ||
?> | ||
<h3>Hi <?php echo $user_profile->displayName; ?> </h3> | ||
|
||
<input value="Want to share this page on facebook?" style="height:30px;" type="submit" onclick="share_link()" /> | ||
<input value="Want to publish a random story your facebook wall?" style="height:30px;" type="submit" onclick="post_to_wall()" /> | ||
<input value="Want to invite some friends ?" style="height:30px;" type="submit" onclick="invite_friends()" /> | ||
|
||
<p> | ||
<hr /> | ||
The invite friends <b>may require some advanced</b> facebook application configuration your side. To know more about FB.ui visit https://developers.facebook.com/docs/reference/javascript/FB.ui/ | ||
</p> | ||
|
||
<div id="fb-root"></div> | ||
<script src="http://connect.facebook.net/en_US/all.js"></script> | ||
<script> | ||
FB.init({ | ||
appId:'<?php echo $adapter->config["keys"]["id"]; ?>', // or simply set your appid hard coded | ||
cookie:true, | ||
status : true, | ||
xfbml:true | ||
}); | ||
|
||
// https://developers.facebook.com/docs/reference/dialogs/send/ | ||
function share_link() { | ||
FB.ui({ | ||
method: 'send', | ||
name: 'HybridAuth, open source social sign on php library', | ||
link: 'http://hybridauth.sourceforge.net/', | ||
}); | ||
} | ||
|
||
// https://developers.facebook.com/docs/reference/dialogs/requests/ | ||
function invite_friends() { | ||
FB.ui({ | ||
method: 'apprequests', message: '<?php echo $user_profile->displayName; ?> want you to join him at mywebsite.com.' | ||
}); | ||
} | ||
|
||
// https://developers.facebook.com/docs/reference/dialogs/feed/ | ||
function post_to_wall() { | ||
var obj = { | ||
method: 'feed', | ||
link: 'http://hybridauth.sourceforge.net/', | ||
picture: 'http://fbrell.com/f8.jpg', | ||
name: 'HybridAuth', | ||
caption: 'HybridAuth, open source social sign on php library', | ||
description: 'HybridAuth, open source social sign on php library.' | ||
}; | ||
|
||
function callback(response) { | ||
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id']; | ||
} | ||
|
||
FB.ui(obj, callback); | ||
} | ||
</script> | ||
<?php | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
// load hybridauth base file, change the following paths if necessary | ||
// note: in your application you probaly you have to include these only when required.. | ||
$hybridauth_config = dirname(__FILE__) . '/../../hybridauth/config.php'; | ||
require_once( "../../hybridauth/Hybrid/Auth.php" ); | ||
|
||
// database config | ||
$database_host = "localhost"; | ||
$database_user = "root"; | ||
$database_pass = ""; | ||
$database_name = "hybridauth_test"; | ||
|
||
$database_link = @ mysql_connect( $database_host, $database_user, $database_pass ); | ||
|
||
if ( ! $database_link ) { | ||
die( "This sample require a mysql database. Please edit the configuration file: <b>application.config.php</b>. <hr><b>Mysql error</b>: " . mysql_error() ); | ||
} | ||
|
||
$db_selected = mysql_select_db( $database_name ); | ||
|
||
if ( ! $db_selected ) { | ||
die( "This sample require a mysql database. Please edit the configuration file: <b>application.config.php</b>. <hr><b>Mysql error</b>: " . mysql_error() ); | ||
} | ||
|
||
function mysql_query_excute( $sql ){ | ||
$result = mysql_query($sql); | ||
|
||
if (!$result) { | ||
$message = 'Invalid query: ' . mysql_error() . "\n"; | ||
$message .= 'Whole query: ' . $sql; | ||
die($message); | ||
} | ||
|
||
return $result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
// almost nothing to see here... just basic mvc stuff | ||
class application | ||
{ | ||
public $uri; | ||
|
||
function __construct( $uri = null ) | ||
{ | ||
$this->uri = $uri; | ||
|
||
$this->loadController( $uri['controller'] ); | ||
} | ||
|
||
function loadController( $class ) | ||
{ | ||
$file = "application/controllers/".$this->uri['controller'].".php"; | ||
|
||
if(!file_exists($file)) die( "controller not found at $file" ); | ||
|
||
require_once($file); | ||
|
||
$controller = new $class(); | ||
|
||
if( method_exists( $controller, $this->uri['method'] ) ){ | ||
$controller->{$this->uri['method']}( $this->uri['var'] ); | ||
} | ||
else { | ||
$controller->index(); | ||
} | ||
} | ||
} | ||
|
||
class model | ||
{ | ||
function __construct(){} | ||
} | ||
|
||
class controller | ||
{ | ||
function loadModel( $model ) | ||
{ | ||
require_once( 'application/models/'. $model .'.php' ); | ||
return new $model; | ||
} | ||
|
||
function loadView( $view, $vars="" ) | ||
{ | ||
if(is_array($vars) && count($vars) > 0) extract($vars, EXTR_PREFIX_SAME, "wddx"); | ||
require_once( 'application/views/'.$view.'.html' ); | ||
} | ||
|
||
function redirect( $uri ) | ||
{ | ||
header( "Location: index.php?route=$uri" ); | ||
|
||
die(); | ||
} | ||
} |
Oops, something went wrong.