comparison user/getFBSession.php @ 6:077b0a0a3e6d

remaining originals according to dependency walk
author Robert Boland <robert@markup.co.uk>
date Thu, 16 Feb 2017 22:29:02 +0000
parents
children 385ddd7c4b55 a67bf725e87b
comparison
equal deleted inserted replaced
5:55445b456ad0 6:077b0a0a3e6d
1 <?php
2
3 //we are in facebook canvas so react appropriately
4 include_once '../facebook.php';
5
6 $facebook = new Facebook(array(
7 'appId' => '128245333876633',
8 'secret' => 'f51afc7e04289db62448edd8b70d83bf',
9 'cookie' => true,
10 'domain' => 'yournextread.com'
11 ));
12
13 $session = $facebook->getSession();
14
15 if ($session) {
16 //login user
17 try {
18 $uid = $facebook->getUser();
19 $me = $facebook->api('/me');
20
21 include "../../private/db.php";
22 $Email = $me['email'];
23 $FirstName = $me['first_name'];
24 $Surname = $me['last_name'];
25 //echo $Email;
26 $sql1="SELECT FirstName, Surname, DisplayName, u.UserID, ReceiveEmail, GoodreadsState, LocID
27 from user u, userpref p
28 WHERE Email ='$Email'
29 and u.UserID = p.UserID";
30 //echo $sql1;
31 $result1=mysqli_query($link,$sql1);
32
33 // If successfully queried
34 if($result1){
35 $count=mysqli_num_rows($result1);
36 if($count==0){
37 //User doesn't already exist
38 $add="CALL addNewUser('$Email', 'facebook', '$FirstName', '$Surname', 0, '', 0)";
39 //echo $add;
40 $result2 = mysqli_query($link, $add);
41
42 //reset connection
43 mysqli_close($link);
44 include "../../private/db.php";
45
46 $sql3="SELECT FirstName, Surname, DisplayName, u.UserID, ReceiveEmail, GoodreadsState, LocID
47 from user u, userpref p
48 WHERE Email ='$Email'
49 and u.UserID = p.UserID";
50 //echo $sql3;
51 $resultFull=mysqli_query($link,$sql3);
52 }
53 else{
54 $resultFull = $result1;
55 }
56 if($resultFull){
57 //User Exists
58 $line=mysqli_fetch_array($resultFull, MYSQLI_ASSOC);
59 $firstName=$line['FirstName'];
60 $surname=$line['Surname'];
61 $displayName=$line['DisplayName'];
62 $id=$line['UserID'];
63 $receiveEmail = trim($line['ReceiveEmail']);
64 $GRState=trim($line['GoodreadsState']);
65 $LocID=trim($line['LocID']);
66
67 if($displayName == "")
68 {
69 if($firstName == "")
70 $displayName=$Email;
71 else
72 $displayName = $firstName;
73 }
74
75 //session_start();
76 $_SESSION['displayName']=$displayName;
77 $_SESSION['email']=$Email;
78 $_SESSION['surname']=$surname;
79 $_SESSION['UserID']=$id;
80 $_SESSION['receiveEmail']=$receiveEmail;
81 $_SESSION['GRState']=$GRState;
82 $_SESSION['Loc']=$LocID;
83 echo session_id();
84 echo ":::" . $displayName . ":::" . $surname . ":::" . $receiveEmail . ":::" . $GRState . ":::" . $LocID . ":::" . $Email . ":::" . $id;
85 }
86 }
87
88 $postMsgRoulette = rand(0,4);
89
90 if($postMsgRoulette == 0)
91 {
92 //post message saying they are looking for Presents on YourNextPresent
93 $api_call = array(// use this instead? FQL or fb_sig_ext_perms http://forum.developers.facebook.net/viewtopic.php?id=58565
94 'method' => 'users.hasAppPermission',
95 'uid' => $uid,
96 'ext_perm' => 'publish_stream'
97 );
98 $can_post = $facebook->api($api_call);
99 if($can_post){
100 $facebook->api('/'.$uid.'/feed', 'post', array('message' => "$firstName is looking for books at YourNextRead",
101 'name' => 'YourNextRead',
102 'description' => 'All you need to get started is a book you already like...',
103 'caption' => 'Find great books ideas!',
104 'picture' => 'http://www.yournextread.com/images/YNR_icon.png',
105 'link' => 'http://apps.facebook.com/yournextread/'
106 ));
107 //echo 'Posted!';
108 }
109 }
110
111 } catch (FacebookApiException $e) {
112 error_log($e);
113 }
114 }
115 ?>