Mercurial > hg > ywww
comparison facebook/invite.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 session_start(); | |
| 3 | |
| 4 $proceed = true; | |
| 5 if (isset($_SERVER['HTTP_REFERER'])) | |
| 6 { | |
| 7 $pos = strpos($_SERVER['HTTP_REFERER'], "apps.facebook.com"); | |
| 8 if($pos !== false) | |
| 9 { | |
| 10 //we are in facebook canvas so react appropriately | |
| 11 include_once '../facebook.php'; | |
| 12 | |
| 13 $facebook = new Facebook(array( | |
| 14 'appId' => '128245333876633', | |
| 15 'secret' => 'f51afc7e04289db62448edd8b70d83bf', | |
| 16 'cookie' => true, | |
| 17 'domain' => 'yournextread.com' | |
| 18 )); | |
| 19 | |
| 20 $session = $facebook->getSession(); | |
| 21 | |
| 22 if (!$session) { | |
| 23 $proceed = false; | |
| 24 $url = $facebook->getLoginUrl(array( | |
| 25 'canvas' => 1, | |
| 26 'fbconnect' => 0, | |
| 27 'req_perms' => 'email,user_birthday,publish_stream' | |
| 28 )); | |
| 29 | |
| 30 echo "<script type='text/javascript'>top.location.href = '$url';</script>"; | |
| 31 } | |
| 32 else { | |
| 33 //login user | |
| 34 try { | |
| 35 $uid = $facebook->getUser(); | |
| 36 $me = $facebook->api('/me'); | |
| 37 | |
| 38 include "../../private/db.php"; | |
| 39 $Email = $me['email']; | |
| 40 $FirstName = $me['first_name']; | |
| 41 $Surname = $me['last_name']; | |
| 42 //echo $Email; | |
| 43 $sql1="SELECT FirstName, Surname, DisplayName, UserID from user WHERE Email ='$Email'"; | |
| 44 //echo $sql1; | |
| 45 $result1=mysqli_query($link,$sql1); | |
| 46 | |
| 47 // If successfully queried | |
| 48 if($result1){ | |
| 49 $count=mysqli_num_rows($result1); | |
| 50 if($count==0){ | |
| 51 //User doesn't already exist | |
| 52 $add="CALL addNewUser('$Email', 'facebook', '$FirstName', '$Surname', 0, '', 0)"; | |
| 53 //echo $add; | |
| 54 $result2 = mysqli_query($link, $add); | |
| 55 | |
| 56 //reset connection | |
| 57 mysqli_close($link); | |
| 58 include "../../private/db.php"; | |
| 59 | |
| 60 $sql3="SELECT FirstName, Surname, DisplayName, UserID from user WHERE Email ='$User'"; | |
| 61 //echo $sql3; | |
| 62 $resultFull=mysqli_query($link,$sql3); | |
| 63 } | |
| 64 else{ | |
| 65 $resultFull = $result1; | |
| 66 } | |
| 67 if($resultFull){ | |
| 68 //User Exists | |
| 69 //echo "ResultFull!"; | |
| 70 $line=mysqli_fetch_array($resultFull, MYSQLI_ASSOC); | |
| 71 $firstName=$line['FirstName']; | |
| 72 $surname=$line['Surname']; | |
| 73 $displayName=$line['DisplayName']; | |
| 74 $id=$line['UserID']; | |
| 75 | |
| 76 if($displayName == "") | |
| 77 { | |
| 78 if($firstName == "") | |
| 79 $displayName=$Email; | |
| 80 else | |
| 81 $displayName = $firstName; | |
| 82 } | |
| 83 | |
| 84 $_SESSION['displayName']=$displayName; | |
| 85 $_SESSION['email']=$Email; | |
| 86 $_SESSION['surname']=$surname; | |
| 87 $_SESSION['UserID']=$id; | |
| 88 $_SESSION['receiveEmail']=$receiveEmail; | |
| 89 $_SESSION['GRState']=$GRState; | |
| 90 $_SESSION['Loc']=$LocID; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 } catch (FacebookApiException $e) { | |
| 95 error_log($e); | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 } | |
| 100 echo "<!DOCTYPE html><html>"; | |
| 101 if($proceed) | |
| 102 { | |
| 103 echo "<head>"; | |
| 104 echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"; | |
| 105 | |
| 106 echo "<META NAME=\"Description\" CONTENT=\"Find great present ideas at YourNextRead! YourNextRead makes discovery and recommendation simple - all you need to get started is a book you like. Great books, connected by you...\">"; | |
| 107 | |
| 108 echo "<title>Invite your Friends to YourNextRead!</title>"; | |
| 109 | |
| 110 echo "</head>"; | |
| 111 | |
| 112 echo "<body>"; | |
| 113 echo "<div id=\"fb-root\"></div> | |
| 114 <script type=\"text/javascript\" src=\"http://connect.facebook.net/en_US/all.js\"></script> | |
| 115 <script type=\"text/javascript\"> | |
| 116 FB.init({ | |
| 117 appId : '128245333876633', | |
| 118 status : true, // check login status | |
| 119 cookie : true, // enable cookies to allow the server to access the session | |
| 120 xfbml : true // parse XFBML | |
| 121 }); | |
| 122 </script>"; | |
| 123 echo "<script type=\"text/javascript\"> | |
| 124 var obj = new Object; | |
| 125 obj.height=960; | |
| 126 FB.Canvas.setSize(obj); | |
| 127 </script>"; | |
| 128 echo "<fb:serverFbml style=\"width: 755px;\"><script type=\"text/fbml\"> | |
| 129 <fb:fbml> | |
| 130 <fb:request-form | |
| 131 action=\"http://apps.facebook.com/yournextread/\" | |
| 132 invite=\"true\" | |
| 133 method=\"post\" | |
| 134 type=\"YourNextRead\" | |
| 135 content=\"Get book recommendations from YourNextRead!<fb:req-choice label="YourNextRead!" url="http://apps.facebook.com/yournextread/"></fb:req-choice>\"> | |
| 136 <fb:multi-friend-selector actiontext=\"Invite your friends to YourNextRead!\"></fb:multi-friend-selector> | |
| 137 </fb:request-form> | |
| 138 </fb:fbml> | |
| 139 </script> | |
| 140 </fb:serverFbml>" ; | |
| 141 } | |
| 142 ?> | |
| 143 | |
| 144 <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe> | |
| 145 </body> | |
| 146 </html> |
