forked from solka1/Social-Cafe-Sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
116 lines (95 loc) · 3.79 KB
/
index.php
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
<?php
/**
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
require_once('products.php');
function publishCustomAction($facebook, $product) {
global $app_namespace;
$ret_obj = $facebook->api('/me/'.$app_namespace.':drink', 'post', array(
'beverage' => $product['url'],
));
return $ret_obj['id'];
}
$login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_actions') );
?>
<html>
<head>
<title>Welcome to the Social Cafe</title>
<link rel="shortcut icon" href="img/favicon.ico" />
<link rel=StyleSheet href="css/sc.css" type="text/css" />
</head>
<body>
<script>
function submitForm(index) {
document.forms[0].elements[0].value=index;
document.forms[0].submit();
};
</script>
<div class="header" >
<h1><a href="<?php echo $app_url; ?>"><img src="img/cafe.jpg" width="135px" height="100px" /> Social Cafe</a></h1>
<div class="controls"><a href="<?php echo $login_url; ?>">Login</a> <a href="<?php echo $facebook->getLogoutUrl(); ?>">Logout</a></div>
</div>
<div class="contents">
<div class="top_msg">
<?php
if(!$facebook->getUser()) {
echo '<a href="' . $login_url . '">Login</a>';
} else {
?>
<?php
if($_GET["at"]) {
echo '<p><pre>access token: ' . $facebook->getAccessToken() . '</pre></p>';
}
if(isset($_POST['product'])) {
$idx = $_POST['product'];
try {
echo '<p>You are enjoying a ' . $products[$idx]['name'];
$story_id = publishCustomAction($facebook, $products[$idx]);
$me = $facebook->api("/me",'GET');
echo ' (story id: <a href="https://www.facebook.com/' . $me['username'] . '/activity/' . $story_id . '" target="_blank">' . $story_id . '</a> ).';
} catch (FacebookApiException $e) {
echo '<p>There was a problem with your purchase. Please <a href="' . $login_url . '">Login</a> again.';
if($_REQUEST['debug']) {
echo '<pre>' . $e->getMessage() . '</pre>';
}
}
} else {
echo "<p>You haven't chosen anything yet. </p>";
}
?>
<p>What would you like? </p>
<p style="font-size: 14px">(Choosing a drink will publish a story to your stream)</p>
</div>
<div class="item">
<a href="javascript:submitForm(0);"><img src="img/latte2.gif" width="75px" height= "75px" /> Cafe Latte</a>
</div>
<div class="item">
<a href="javascript:submitForm(1);"><img src="img/kyoto.gif" width="70px" /> Iced Mocha </a>
</div>
<div class="item">
<a href="javascript:submitForm(2);"><img src="img/earlgrey1.gif" width="90px" height= "90px" /> Earl Grey Tea </a>
</div>
<br />
<p style="font-size: 14px">Images are licensed under <a href="http://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a> from flickr users: mattb4rd, kennymatic, jackbrodus.</p>
<?php if($_REQUEST['debug']) { ?>
<form action="index.php?debug=1" method="post" > <input name="product" type="hidden" value="foobar" /></form>
<?php } else { ?>
<form action="index.php" method="post" > <input name="product" type="hidden" value="foobar" /></form>
<?php } ?>
</div>
<?php } //end: if(!$facebook->getUser())
?>
</body>
</html>