-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.inc
225 lines (185 loc) · 8.58 KB
/
html.inc
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>My Biggest Follower</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 20px;
padding-bottom: 40px;
}
/* Custom container */
.container-narrow {
margin: 0 auto;
max-width: 700px;
}
.container-narrow > hr {
margin: 30px 0;
}
/* Main marketing message and sign up button */
.jumbotron {
margin: 60px 0;
text-align: center;
}
.jumbotron h1 {
font-size: 72px;
line-height: 1;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
/* Supporting marketing content */
.marketing {
margin: 60px 0;
}
.marketing p + h4 {
margin-top: 28px;
}
</style>
<link href="../assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="../assets/js/html5shiv.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="../assets/ico/favicon.png">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-44052711-1', 'mybiggestfollower-pomart.rhcloud.com');
ga('send', 'pageview');
</script>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<div class="container-narrow">
<div class="masthead">
<ul class="nav nav-pills pull-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="mailto:po.liu.2s@gmail.com">Contact</a></li>
</ul>
<h3><a href="http://ca.linkedin.com/in/poliu2s/">Po Liu</a></h3>
</div>
<hr>
<div class="jumbotron">
<h2>My Biggest</h2>
<img src="flask.jpg" />
<h1>Follower</h1>
<p class="lead">A webapp designed to visualize the magnitude of influence for each of your followers. If you are having issues try <a href='./clearsessions.php'>clearing your session</a>.</p>
<?php print_r($sign_in_button); ?>
</div>
<hr>
<div class="row-fluid marketing" style="margin: 0px">
<?php
// After signing in
if ($sign_in == 0) {
// Check rate limit status
$rate_limit = $connection->get('application/rate_limit_status');
$followers_limit = (array) $rate_limit->resources->followers;
$followers_list_limit = (array) $followers_limit['/followers/list'];
$followers_list_limit_remaining = (array) $followers_list_limit['remaining'];
$num_followers_list_limit_remaining = $followers_list_limit_remaining[0];
// Create a connection with the database
$host = "127.12.191.130";
$username="admin7I4NNiI";
$password="Z6Yt_GAZkX_Q";
$db_name="mybiggestfollower";
$db = new mysqli("$host", "$username", "$password", "$db_name") or die("Database could not connect");
// Update db data if requested
if(isset($_GET['update'])) {
// Throttle the number of times a user can update
if ($num_followers_list_limit_remaining > 10) {
$reset_query = "DELETE FROM bubbles WHERE bubbles.owner='".$screen_name."'";
$reset_response = $db->query($reset_query);
}
}
// Set up database credentials
$user_query = "SELECT *
FROM bubbles
WHERE owner='".$screen_name."'";
$user_response = $db->query($user_query);
$entry = $user_response->fetch_assoc();
// For debugging
//var_dump($entry);
// Check if user already exists in database to reduce Twitter API calls
if (is_null($entry)) {
$cursor = -1;
do {
// Add user's follower information to the database
$response = $connection->get('followers/list', array("cursor" => (string)$cursor));
// Update the cursor if more than 20 followers
$cursor = $response->next_cursor;
for($i = 0; $i < count($response->users); $i++) {
// Store into db
$insert_query = "INSERT INTO bubbles (screen_name, followers, owner)
VALUES (\"".$response->users[$i]->screen_name."\", \"".$response->users[$i]->followers_count."\", \"".$screen_name."\")";
$insert_response = $db->query($insert_query);
}
} while ($cursor != 0);
// Make another query to the db to update num of entries
$user_query = "SELECT *
FROM bubbles
WHERE owner='".$screen_name."'";
$user_response = $db->query($user_query);
$entry = $user_response->fetch_assoc();
}
// Update JSON data file used for graphing
$file = $screen_name.".json";
$handle = fopen($file, 'w');
$json = '{ "name": "analytics","children": [ ';
// Retrieve data from db
for($i = 0; $i < $user_response->num_rows; $i++) {
// Write entry to JSON file
$json = $json.'{ "name": "'.$i.'", "children": [ { "name" : "'.$entry['screen_name'].'", "size": '.$entry['followers'].'}]}';
// Formating everything but the last entry
if($i < $user_response->num_rows - 1) {
$json = $json.',';
}
// Grab a new entry from Twitter server's response
$entry = $user_response->fetch_assoc();
}
$json = $json.']}'; // closing braces in json
fwrite($Handle, $Data);
fwrite($handle, $json);
fclose($handle);
// Display the bubble graph
echo "<h3>".$user_response->num_rows." follower bubbles for user <i>".$screen_name."</i> : </h3>";
echo '<iframe src="graph1.php?screen_name='.$screen_name.'" width=100% height=700px scrolling="no" style="height: auto" frameborder="0" scrolling="no" seamless/></iframe>';
echo '<br><br><p style="text-align: center"><a href="index.php?update=1">Update data</a></p>';
echo '<hr>';
$db->close();
}
?>
<div class="footer">
<p>© PoMart Inc. 2013. Built using PHP/MySQL/D3 with OAuth for Twitter's REST API v1.1 by Abraham Williams.</p>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/bootstrap-transition.js"></script>
<script src="../assets/js/bootstrap-alert.js"></script>
<script src="../assets/js/bootstrap-modal.js"></script>
<script src="../assets/js/bootstrap-dropdown.js"></script>
<script src="../assets/js/bootstrap-scrollspy.js"></script>
<script src="../assets/js/bootstrap-tab.js"></script>
<script src="../assets/js/bootstrap-tooltip.js"></script>
<script src="../assets/js/bootstrap-popover.js"></script>
<script src="../assets/js/bootstrap-button.js"></script>
<script src="../assets/js/bootstrap-collapse.js"></script>
<script src="../assets/js/bootstrap-carousel.js"></script>
<script src="../assets/js/bootstrap-typeahead.js"></script>
</body>
</html>