This repository has been archived by the owner on Jan 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
executable file
·329 lines (302 loc) · 17.4 KB
/
settings.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?php
require("load.php");
// Fitbit API call (get activities for specified date)
$apiCall = $baseAPIUrl . "user/-/profile.xml";
// Start session to store the information between calls
if (!isset($_SESSION)) {
session_start();
}
// In state=1 the next request should include an oauth_token.
// If it doesn't go back to 0
if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) $_SESSION['state'] = 0;
try {
// Create OAuth object
$oauth = new OAuth($conskey, $conssec, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
// Enable ouath debug (should be disabled in production)
$oauth->enableDebug();
if ($_SESSION['state'] == 0) {
// Getting request token. Callback URL is the Absolute URL to which the server provder will redirect the User back when the obtaining user authorization step is completed.
$request_token_info = $oauth->getRequestToken($req_url, $callbackUrl);
// Storing key and state in a session.
$_SESSION['secret'] = $request_token_info['oauth_token_secret'];
$_SESSION['state'] = 1;
// Redirect to the authorization.
header('Location: ' . $authurl . '?oauth_token=' . $request_token_info['oauth_token']);
exit;
} else if ($_SESSION['state'] == 1) {
// Authorized. Getting access token and secret
$oauth->setToken($_GET['oauth_token'], $_SESSION['secret']);
$access_token_info = $oauth->getAccessToken($acc_url);
// Storing key and state in a session.
$_SESSION['state'] = 2;
$_SESSION['token'] = $access_token_info['oauth_token'];
$_SESSION['secret'] = $access_token_info['oauth_token_secret'];
}
// Setting asccess token to the OAuth object
$oauth->setToken($_SESSION['token'], $_SESSION['secret']);
// Performing API call
$oauth->fetch($apiCall);
// Getting last response
$response = $oauth->getLastResponse();
// Initializing the simple_xml object using API response
$xml = simplexml_load_string($response);
} catch (OAuthException $E) {
print_r($E);
}
?><!--
# #
# ; #
# ; #
# ; #
# ; ### # ####### L### ,### #
# ; # # # # # # # , #
# ; # # # # # # #
# ; # # # # ###### ## #
# ; ##### # # # # # #
# ; # # # # # # #
# ; # # # # G ; # #
# ##; # ## # # # :### ### #
# #
# #
# iEDWDf #
# ################ #
# #### E### #
# .### G##f #
# ##; ##, #
# ##f .## #
# ## ##; #
# j#t ## #
# ## ## #
## ##
W## ###
t# # # ##
# # # #t
#f # # #
## # # W#
# # # #f
#G # # #
# # # #W
#f # # #
# # # #t
## # # ,#
# # # #
# # # #f
W# # # t#
#: # # #
# # # #
# # # #
# # # #f
# # # ##
;# # # D#
f# ## f#
f# ## f#
t# # # E#
# # # ##
# # # #f
# # # #
# # # #
#. # # #
## # # i#
# # # #L
# # # #
## # # .#
# # # #j
#t # # #
.# # # ##
#f # # #
# # # #L
## # # E#
#; # # #
# # # #L
G# # # ##
### ###
## ##
# ## ## #
# E#, ## #
# ## K#f #
# ##; ## #
# ##. ##f #
# t##G i##W #
# ###E f###; #
# :################t #
# ,D####D; #
# #
# #
# #
# #
# .#### # #
# # # #
# ; # #
# # #### #### ##### #### #
# .#t # # # # # # # #
# ## # : # # # # # #
# # # # # # # ###### #
# # # # # # # # #
# W # : # # # # #
# ## # # # t: # # # # #
# ###t #i :## # # ###: #
-->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Meta, title, CSS, favicons, etc. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings - Fitbit IFTTT</title>
<!-- Bootstrap core CSS -->
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- My CSS -->
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<!-- Load Lato Font -->
<link href="style.css" rel="stylesheet" type="text/css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<a class="sr-only" href="#content">Skip to main content</a>
<!-- Events master nav -->
<?php
echo file_get_contents("http://blog.jamesstone.com.au/JamesMenuAPI/index.php");
?>
<!-- Docs page layout -->
<div class="header" id="content">
<div class="container">
<h1>Fitbit IFTTT Channel</h1>
<p>
A 3rd Party IFTTT Fitbit Channel
</p>
<div id="carbonads-container">
<div class="carbonad">
<div id="azcarbon">
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-9" role="main">
<!-- Details
================================================== -->
<div class="bs-docs-section">
<div class="page-header">
<h1 id="Setup">IFTTT Wordpress Details</h1>
</div>
<p>
<?php
// add user
$checkfitbitid = mysql_query("SELECT * FROM users WHERE FitbitID = '" . $xml->user->encodedId . "'");
if (mysql_num_rows($checkfitbitid) == 1) {
$UsernameQuery = mysql_query("SELECT `IFTTTUsername` FROM `users` WHERE `FitbitID` LIKE '" . $xml->user->encodedId . "'");
$PasswordQuery = mysql_query("SELECT `IFTTTPassword` FROM `users` WHERE `FitbitID` LIKE '" . $xml->user->encodedId . "'");
echo "<h1>Welcome Back " . $xml->user->displayName . "</h1>";
echo "<p>Below are your IFTTT wordpress details:</p>";
echo "<p>Blog URL:<code>" . $iftttBlogUrl . "</code></p>";
echo "<p>Username:<code>" . mysql_result($UsernameQuery, 0) . "</code></p>";
echo "<p>Password:<code>" . mysql_result($PasswordQuery, 0) . "</code></p>";
echo '<p><a href="' . $iftttBlogUrl . '/logout.php">Logout</a></p>';
} else {
$IFTTTPassword = randomPassword();
while (true) {
$IFTTTUsername = randomPassword();
$IFTTTUsernameCheckQuery = mysql_query("SELECT `IFTTTUsername` FROM `users` WHERE `IFTTTUsername` = '" . $IFTTTUsername . "'");
if (mysql_num_rows($IFTTTUsernameCheckQuery) < 1) {
break;
}
}
$registerquery = mysql_query("INSERT INTO users (`FitbitID`, `FitbitName`, `FitbitAvatar`, `IFTTTUsername`, `IFTTTPassword`,`FitBitToken`,`FitBitSecret`) VALUES('" . $xml->user->encodedId . "', '" . $xml->user->displayName . "','" . $xml->user->avatar . "','" . $IFTTTUsername . "','" . $IFTTTPassword . "','" . $_SESSION['token'] . "', '" . $_SESSION['secret'] . "')");
if ($registerquery) {
echo "<h1>Welcome " . $xml->user->displayName . "</h1>";
echo "<p>Your account was successfully created.</p>";
echo "<p>Below are your IFTTT wordpress details:</p>";
echo "<p>Blog URL:<code>" . $iftttBlogUrl . "</code></p>";
echo "<p>Username:<code>" . $IFTTTUsername . "</code></p>";
echo "<p>Password:<code>" . $IFTTTPassword . "</code></p>";
echo '<p><a href="' . $iftttBlogUrl . '/logout.php">Logout</a></p>';
//create table for user activities
mysql_query("CREATE TABLE IF NOT EXISTS `" . $xml->user->encodedId . "Activities` (
`activityId` int(11) NOT NULL,
`calories` int(11) NOT NULL,
`description` varchar(300) NOT NULL,
`distance` int(11) NOT NULL,
`duration` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
PRIMARY KEY (`activityId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
//subscribe to user activities
/**
* Add subscription
*
* @throws FitBitException
*
* @param string $id Subscription Id
* @param string $path Subscription resource path (beginning with slash). Omit to subscribe to all user updates.
*
* @return
*/
//addSubscription($xml->user->encodedId, "/activities", $subscriberId = null);
//echo getSubscriptions();
} else {
echo "<h1>Error 1</h1>";
echo "<p>Current number of beta users maxed out - sorry</p>";
echo "<!--" . mysql_error() . "-->";
}
}
?>
</p>
<p><a href="index.php">Back</a> to documentation </p>
<p> I want to stress if you need <b>any</b> help at all setting this up please <a
href="http://blog.jamesstone.com.au/contact/">contact </a> me </p>
</div>
</div>
<div class="col-md-3">
<!--Side Menu
================================================== -->
<div class="bs-sidebar hidden-print" role="complementary">
<ul class="nav bs-sidenav">
<li><a href="#">Details</a></li>
<li><a href="index.php">Back</a></li>
</ul>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../bootstrap/js/bootstrap.min.js"></script>
<script src="application.js"></script>
<script>
//Filter
$(function () {
function lastfm(event) {
$(".lastfm").animate({
opacity: "toggle",
height: "toggle"
}, 1000, function () {
// Animation complete.
});
$('#lastfmtoggle').parent().toggleClass("on");
return false;
}
$('#lastfmtoggle').click(lastfm);
});
</script>
<script>
$(function () {
$(".meter > span").each(function () {
$(this)
.data("origWidth", $(this).width())
.width(0)
.animate({
width: $(this).data("origWidth")
}, 1200);
});
});
</script>
</body>
</html>