1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| <?php
/**
* @author Sébastien Marcil
* @desc Test pour faire une app. Facebook
* @link www.smarcil.com
* @since février 2011
*/
// on charge la librairie facebook
require_once './facebook.php';
//include_once './facebook-platform/php/facebook.php';
// clé publique
define('CLE_PUBLIQUE', '****************');
//clé secrète
define('CLE_SECRETE', '*************************');
// on créé une intance de facebook
$oFacebook = new Facebook(array(
'appId' => CLE_PUBLIQUE,
'secret' => CLE_SECRETE,
'cookie' => true,
));
// on récupère les identifiants du visiteur
$session = $oFacebook->getSession();
// on récupère les informations du visiteur
try {
$aVisiteur = $oFacebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
$friends = $oFacebook->api('/me/friends');
$idFriends = array();
$randFriends = array_rand($friends["data"], 10);
for($i=0; $i < 10; $i++){
$randId = $friends['data'][$randFriends[$i]]['id'];
array_push($idFriends, $randId, $randId);
}
?>
<!DOCTYPE html>
<!-- on va utilisser du fbml ( le html de facebook) -->
<html xmlns='http://www.w3.org/1999/xhtml'
xmlns:fb='http://www.facebook.com/2008/fbml'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<!-- si le client a accepté l'application -->
<?php if ($session) { ?>
<fb:like></fb:like><br>
Salut <?= $aVisiteur['first_name'] ?> ! Trouve les paires de photo<br>
<?php } else { ?> <!-- sinon on propose à l'utilisateur de se connecter à l'application -->
Pour se connecter c'est ici :
<fb:login-button></fb:login-button>
<?php } ?>
<div id='fb-root'></div>
<!-- on charge la librairie javascript de facebook pour la connexion -->
<script src='http://connect.facebook.net/en_US/all.js'></script>
<!-- fonction qui envoie les informations à facebook connect -->
<script>
FB.init({appId: '<?= CLE_PUBLIQUE ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
<script type="text/javascript">
var idFriends = new Array(<?php echo implode(',', $idFriends) ?>);
var randomIdFriends = new Array([],[],[],[],[]);
var randomNum;
var id;
var t;
var jouer = true;
var check = new Array("","");
var cartesTrouvees = new Array();
for(var i=0;i<4;i++)
{
for(var j=0;j<5;j++)
{
randomNum = Math.floor(Math.random()*idFriends.length);
randomIdFriends[i][j] = idFriends.splice(randomNum,1);
document.write("<img src='medias/images/carte.jpg' width='140' height='140' onClick='checkImg("+i+","+j+")' id='"+i+""+j+"' />");
}
document.write("<br/>");
}
function checkImg(pi,pj)
{
if(jouer)
{
for(var i=-1;i<cartesTrouvees.length;i++)
{
id = pi+""+pj;
var idFriend = randomIdFriends[pi][pj];
if(cartesTrouvees+""!=idFriend+"")
{
//alert(id);
document.getElementById(id).src = "https://graph.facebook.com/"+idFriend+"/picture?type=square";
if(check[0]=="")
{
check[0]=idFriend;
check[1]=id;
//alert(check[0]+" ; "+check[1]);
}
else
{
//alert(check[0]+" == "+idFriend);
//alert(check[0]==idFriend);
if(check[0]+""==idFriend+"")
{
//cartesTrouvees.push(check[0]);
//alert("bravo");
}
else
{
jouer = false;
t=setTimeout("updateCarte()",1000);
}
check[0] = "";
}
}
}
}
}
function updateCarte()
{
//alert(check[1]);
//alert(id+" ; "+check[1]);
jouer = true;
document.getElementById(id).src = "medias/images/carte.jpg";
document.getElementById(check[1]).src = "medias/images/carte.jpg";
clearTimeout(t);
}
</script>
</body
></html> |
Partager