-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
128 lines (93 loc) · 3.12 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
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
require_once 'inc/config.inc.php';
// Catches the Instagram realtime Pubsubhubub challenge flow
if (isset($_GET['hub_challenge'])) {
echo $_GET['hub_challenge'];
exit;
}
// Catches realtime updates from Instagram
if ($_SERVER['REQUEST_METHOD']==='POST') {
// Instantiates Pusher PHP API
require 'lib/Pusher.php';
// Retrieves the POST data from Instagram
$update = file_get_contents('php://input');
$photos = json_decode($update);
// If one or more photos has been posted, notify all clients
if (is_array($photos) && ($length=count($photos))>0) {
$pusher = new Pusher($pusher_key, $pusher_secret, $pusher_app_id);
$pusher->trigger(
'photos',
'new-photo',
array(
'newcount' => $length,
)
);
}
}
// Retrieves the access token from the query string
$token = isset($_GET['access_token']) ? $_GET['access_token'] : NULL;
// Generates the login URL to authorize the app
$login_url = 'https://api.instagram.com/oauth/authorize/'
. '?client_id=' . $ig_client_id
. '&redirect_uri=' . $ig_login_uri
. '&response_type=code';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/master.css" />
<title>Realtime Workshop by Jason Lengstorf — Future Insights Live</title>
</head>
<body>
<?php if ($token===NULL): ?>
<header>
<h1>Log in to start playing with realtime!</h1>
</header>
<article>
<a href="<?=$login_url?>"
class="login button">Login →</a>
</article>
<?php else: ?>
<header>
<h1>Photos tagged with #<?=$tag?></h1>
</header>
<article>
<div id="count-bar" class="message hidden">
<p>
<strong id="count">0 new photos posted.</strong>
<a href="<?=$page_url?>"
class="button"
id="image-loader">↻ Load the new images </a>
</p>
</div>
<ul id="photos">
<li class="loading">Loading…</li>
</ul><!--/#photos-->
</article>
<?php endif; ?>
<footer>
<p>
This demo was created by
<a href="http://www.lengstorf.com/">Jason Lengstorf</a> for use in the
realtime workshop at Future Insights Live 2013. All photos belong to
their respective owners.
</p>
</footer>
<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
<script src="http://js.pusher.com/2.0/pusher.min.js"></script>
<script>
// Enables pusher logging - don't include this in production
Pusher.log = function(message) {
if (window.console && window.console.log) window.console.log(message);
};
// Flash fallback logging - don't include this in production
WEB_SOCKET_DEBUG = true;
// Initializes Pusher (done inline to use PHP for config variables)
var pusher = new Pusher('<?=$pusher_key?>'),
channel = pusher.subscribe('photos'),
tag = '<?=$tag?>'; // For PHP-powered tag selection
</script>
<script src="js/main.js"></script>
</body>
</html>