/
site.php
307 lines (255 loc) · 8.99 KB
/
site.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
<?php
// @author jack krawczyk -- @jackk
// last updated: Nov 28, 2012
// This is the profile page for sites within floathope.
// includes for php
include 'includes.php';
// reroute if not logged in
if(! isset($_COOKIE['EMAIL_floathope']))
{
header("Location: index.php");
}
if(isset($_GET['ind']))
{
$domain = $_GET['ind'];
}
else
{
$domain = null;
}
// parse out userid from userCookie
$userArray = json_decode(htmlspecialchars_decode($_COOKIE['USER_floathope']));
//get name information
$userid = $userArray->{'userid'};
$name = $userArray->{'name'};
$email = $userArray->{'email'};
?>
<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# floathope: http://ogp.me/ns/fb/floathope#">
<title>Float Hope - Indulging <?php if($domain != null) echo "in $domain"; ?></title>
<meta property="fb:app_id" content="254766557960545" />
<meta property="og:type" content="floathope:web_site" />
<meta property="og:url" content="http://dev.floathope.com/site.php?ind=<?php echo $domain; ?>" />
<meta property="og:title" content="Indulging in <?php echo $domain; ?>" />
<meta property="og:image" content="http://dev.floathope.com/dove.png" />
<link rel="shortcut icon" href="dove.png" type="image/x-icon">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<!-- Load Scripts -->
<script src="jquery-1.7.1.js"></script>
<script src="jquery-cookie.js"></script>
<?php getGoogleAnalytics(); ?>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=195408600527486";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.php">float hope</a>
<div class="nav-collapse">
<ul class="nav">
<li><a href="index.php">Home</a></li>
<li class="active"><a href="site.php">Indulgences</a></li>
<li><a href="profile.php">My Profile</a></li>
</ul>
<ul class="nav pull-right">
<li><a href="profile.php">Logged in as <strong><?php echo $name; ?></strong></a></li>
<li class="divider-vertical"></li>
<li><a href="logout.php">Log out</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<?php
// load the account infomation using the userid from the login cookie
//$thisUser = $_COOKIE['USER_floathope'];
//echo "Hello, here is your user info: <br />" . html_entity_decode($thisUser);
// parse out userid from userCookie
$userArray = json_decode(htmlspecialchars_decode($_COOKIE['USER_floathope']));
$userid = $userArray->{'userid'};
?>
</div>
<div class="row">
<div class="span6">
<div class="user-module">
<?php
// Create Conversation Rail
if($domain != null)
{
echo "<h3>Any good finds on this site?</h3><br />
<div class='fb-comments' data-href='http://dev.floathope.com/site.php?ind=$domain' data-num-posts='4' data-width='510'></div>";
}
else
{
// Get monthly user stats
$monthlyStats = getMonthlyStats($userid);
$month = date("F");
echo "<h3>Your Current Indulgences</h3> \n<table class='table table-striped'>
<thead>
<tr>
<th>Indulgence</th>
<th style='text-align:center;'>Total Followers</th>
</tr>
</thead>
<tbody>";
$mySites = $userArray->{"guiltySites"};
foreach($mySites as $mysite)
{
echo "<tr><td><a href='site.php?ind=$mysite'>" . $mysite . "</a></td><td style='text-align:center;'>" . getSiteFollowers($mysite) . "</td></tr>";
}
echo "</tbody></table>";
}
?>
</div></div> <!-- End hero-unit & left column -->
<div class="span6"><div class="user-module"> <!-- Start right column -->
<?php
// show progress bar if specific site
if ($domain != null)
{
// ***** INDULGENCE INFO *****
echo "<h3>Indulging in $domain</h3> \n";
echo "<h4>Total Followers: <span id='num-site-followers'>" . getSiteFollowers($domain) . "</span></h4>";
// check if user follows this site
$sites = $userArray->{'guiltySites'};
$indulgeFlag = false;
foreach($sites as $site)
{
if($site == $domain)
{
$indulgeFlag = true;
}
}
echo "<div id='indulgence-action'>";
if($indulgeFlag)
{
echo "<div id='following'>
<p>You follow this site.</p>
<form action='follow-site.php' method='post' id='removeit'>
<input type='submit' class='btn btn-small' style='width:80px;' value='Remove it' />
</form>
</div>";
}
else
{
echo "<div id='not-following'>
<p>You do not indulge in this site.</p>
<form action='follow-site.php' method='post' id='addit'>
<input type='submit' class='btn btn-primary btn-small' style='width:80px;' value='Add it!' />
</form>
</div>";
}
echo "</div>";
?>
<script>
$(document).ready(function() {
$('#addit').submit(function(event) {
// stop the event handler
event.preventDefault();
var url = $(this).attr('action');
$.post( url, { type: "follow", domain: "<?php echo $_GET['ind']; ?>" },
function(data) {
//alert("Data loaded: " + data );
$('#indulgence-action').html("<p>You now follow this site.</p> <form action='follow-site.php' method='post' id='removeit'> <input type='submit' class='btn btn-small' style='width:80px;' disabled='disabled' value='added!' /> </form>");
// update the number of followers
var numFollowers = $('#num-site-followers').html();
numFollowers++;
$('#num-site-followers').html(numFollowers);
});
});
$('#removeit').submit(function(event) {
// stop the event handler
event.preventDefault();
var url = $(this).attr('action');
$.post( url, { type: "unfollow", domain: "<?php echo $_GET['ind']; ?>" },
function(data) {
//alert("Data loaded: " + data );
$('#indulgence-action').html("<p>You no longer indulge in this site.</p><form action='follow-site.php' method='post' id='addit'> <input type='submit' class='btn btn-small' disabled='disabled' style='width:80px;' value='removed' /> </form>");
// update the number of followers
var numFollowers = $('#num-site-followers').html();
numFollowers = numFollowers - 1;
$('#num-site-followers').html(numFollowers);
});
});
});
</script>
<?php
echo "<hr />";
// Progress Bar
// calculate impact
$chargePerVisit = 0.25;
$siteid = getSiteID($domain);
$siteraised = getMonthlySiteRaised($siteid);
$totalraise = getTotalMonthlyRaised();
// check impact
$impact = $siteraised / $totalraise * 100;
$impactPercent = number_format($impact, 0) . "%";
// print progress bar
echo "<h3>Indulgence Impact</h3>
<div class='progress'> <div class='bar' style='width: $impactPercent'></div> </div>
<p><strong>$domain</strong> has raised <strong>$impactPercent</strong> of all funds this month!</p>";
}
else // not a specific site
{
echo "<h3>Tempted by the Fruit of Another</h3> <br />
<p>Check out the most popular Indulgences:</p>";
echo "<table class='table table-striped'>
<thead>
<tr>
<th>Indulgence</th>
<th style='text-align:center;'>Total Followers</th>
</tr>
</thead>
<tbody>";
$topSites = getTopSites(5);
foreach($topSites as $topSite => $topFollowers)
{
echo "<tr><td><a href='site.php?ind=$topSite'>" . $topSite . "</a></td><td style='text-align:center;'>" . $topFollowers . "</td></tr>";
}
echo "</tbody></table>";
// print search bar
echo '<h3 >Looking for something specific?</h3> <br />
<form class="form-search" action="search-sites.php" method="post" id="search">
<input type="text" class="input-medium search-query" id="query">
<button type="submit" class="btn">Search</button>
</form>';
echo "<div id='query-results'></div>";
echo "<script>$('#search').submit(function(event) {
// stop the event handler
event.preventDefault();
var url = $(this).attr('action');
var queryVal = $('#query').val();
$.post( url, { query: queryVal },
function(data) {
//alert('Data loaded: ' + data );
$('#query-results').html(data);
});
});</script>";
}
?>
</div></div> <!-- End user module & right column -->
</div>
</div>
</body>
</html>