-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
360 lines (295 loc) · 11 KB
/
profile.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>LeagueLights</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/shop-homepage.css" rel="stylesheet">
<link href="css/leaguelights.css" rel="stylesheet">
<style>
.list-group-item {
color: white;
font-family:cambria;
}
.card-title{
color: white;
font-family:cambria;
}
</style>
</head>
<body>
<?php
//when page is opened via its url, most likely user is not signed in, so redirect to login page
if(!isset($_SESSION['currentId'])){
header("Location:login.php");
exit;
}else{
//currently logged in user's summonerId will be used to retrive user's information
$loggedInAs = $_SESSION["currentId"];
//serverStr needs other ways to set depends on region later on
$serverStr = (isset($_SESSION["currentServer"])) ? $_SESSION['currentServer'] : "na1";
}
$videoSrc = array();
$video = array();
$title = array();
$videoStr = $loggedInAs . "_%";
$numLike = 0;
$numVid = 0;
$apiKey = getenv('RIOT_API');
$version = getenv('CLIENT_VERSION');
//curl request url
$summonerInfo = "https://" . $serverStr;
$summonerRank = $summonerInfo . ".api.riotgames.com/lol/league/v3/positions/by-summoner/".$loggedInAs."?api_key=".$apiKey;
$summonerInfo .= ".api.riotgames.com/lol/summoner/v3/summoners/".$loggedInAs."?api_key=".$apiKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $summonerInfo);
$infoResult = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, $summonerRank);
$rankResult = curl_exec($ch);
/*
curl_setopt($ch, CURLOPT_URL, $currentVersion);
$versionResult = curl_exec($ch);
*/
curl_close($ch);
$summoner = json_decode($infoResult);
$rank = json_decode($rankResult);
if(!empty($rank)){
//if user has rank, display tier, rank, and summonerLevel
$rank = $rank[0]->{'tier'}." ". $rank[0]->{'rank'}."<br>Level ".$summoner->{'summonerLevel'};
}else{
//else just display summonerLevel
$rank = "Level ".$summoner->{'summonerLevel'};
}
//retrive summonerIcon from ddragon.leagueoflegends.com
$profileIcon = $summoner->{'profileIconId'};
$iconLink = "http://ddragon.leagueoflegends.com/cdn/".$version."/img/profileicon/".$profileIcon.".png";
$dbHost = getenv('RDS_HOSTNAME');
$dbUser = getenv('RDS_USERNAME');
$dbPass = getenv('RDS_PASSWORD');
$dbConn = 'mysql:host='.$dbHost.';dbname='.$serverStr.';charset=utf8mb4';
try{
$conn = new \PDO( $dbConn,
$dbUser,
$dbPass,
array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_PERSISTENT => false
)
);
//retrive all the videos uploaded by the user
$srcHandle = $conn->prepare("SELECT Id, Uploader from video where Uploader LIKE ?");
$srcHandle->bindParam(1, $loggedInAs, PDO::PARAM_INT);
$srcHandle->execute();
//retrive total number of likes the user recieved
$likeHandle = $conn->prepare("SELECT * from likes where videoId LIKE ?");
$likeHandle->bindParam(1, $videoStr, PDO::PARAM_STR);
$likeHandle->execute();
$numLike = $likeHandle->rowCount();
//push video src into $src array and count number of videos the user uploaded
foreach ($srcHandle as $value){
$src = "https://s3-ca-central-1.amazonaws.com/".$serverStr."-vid/".$value['Uploader']."/".$value['Id'];
array_push($videoSrc, $src);
array_push($video, $value['Id']);
$numVid++;
}
$srcJson = json_encode($videoSrc);
$videoJson = json_encode($video);
$titleHandle = $conn->prepare("SELECT Title from video where Uploader Like ?");
$titleHandle->bindParam(1, $loggedInAs, PDO::PARAM_INT);
$titleHandle->execute();
//retrive titles of videos in title array
foreach ($titleHandle as $value){
array_push($title, $value['Title']);
}
$titleJson = json_encode($title);
} catch(\PDOException $ex){
print($ex->getMessage());
}
//LeagueLights has its own ranking system to encourage users to try to get as many likes and uploads
$userElo = floor(($numVid*5 + ($numLike-$numVid))/70);
$threshold = 3;
if($userElo < $threshold){
$userRank = "Novice";
}else if($userElo >= $threshold && $userElo < ($threshold*2)){
$userRank = "Advanced Beginner";
}else if($userElo >= $threshold*2 && $userElo < ($threshold*4)){
$userRank = "Competent";
}else if($userElo >= $threshold*4 && $userElo < ($threshold*8)){
$userRank = "Proficient";
}else if($userElo >= $threshold*8){
$userRank = "Expert";
}
?>
<script>
var videos = JSON.parse('<?php echo $srcJson; ?>');
var titles = JSON.parse('<?php echo $titleJson; ?>');
var videoId = JSON.parse('<?php echo $videoJson; ?>');
var counter = videos.length;
var userRank = '<?php echo $userRank;?>';
var imgSrc = "img/" + userRank + ".png";
var pageTitle = '<?php echo $summoner->{'name'}?>';
function addVidElement(vid, vidTitle, videoId){
var dLink = "javascript:window.open('deleteVideo.php?videoId=" + videoId + "','Delete Video','width=1000,height=400')";
var divider = document.createElement("div");
divider.setAttribute("class", "col-lg-4 col-md-6 mb-4");
var cardDiv = document.createElement("div");
cardDiv.setAttribute("class", "card h-100 bg-dark");
var deleteDiv = document.createElement("div");
deleteDiv.setAttribute("class", "row");
var toRight = document.createElement("div");
toRight.setAttribute("class", "col-lg-10");
var deleteBtn = document.createElement("button");
deleteBtn.setAttribute("onclick", dLink);
deleteBtn.innerHTML = "X";
deleteDiv.appendChild(toRight);
deleteDiv.appendChild(deleteBtn);
cardDiv.appendChild(deleteDiv);
var cardBody = document.createElement("div");
cardBody.setAttribute("class", "card-body");
var title = document.createElement("h4");
title.setAttribute("class", "card-title text-center");
title.innerHTML = vidTitle;
//title.onclick = handleVideoSelection;
var video = document.createElement("video");
video.setAttribute("class", "card-img-top video-js vjs-icon-play-circle col-xs-12");
video.setAttribute("preload", "auto");
video.setAttribute("controls", true);
video.src = vid;
cardDiv.appendChild(video);
cardDiv.appendChild(title);
divider.appendChild(cardDiv);
var container = document.getElementById("videoList");
container.appendChild(divider);
}
window.onload = function() {
if(document.title != pageTitle){
document.title = pageTitle + ' | ' + document.title;
}
for(var i=0;i<counter;i++){
addVidElement(videos[i], titles[i], videoId[i]);
}
var totalVid = document.getElementById("numVid");
totalVid.innerHTML = counter;
var rankImg = document.getElementById("rankImg");
rankImg.setAttribute("src", "img/rank.png");
var rank = document.getElementById("leaguelightsRank");
rank.innerHTML = userRank;
}
</script>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="/">LeagueLights</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<div class="navbar-nav ml-auto">
<li id="sign" class="navbar-nav ml-auto">
<a href="javascript:window.open('signOut.php','mywindowtitle','width=1000,height=400')" class="nav-link">Sign out</a>
</li>
</div>
<!--
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
-->
</div>
</div>
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-3">
<h1 class="my-2"><?php echo $summoner->{'name'};?></h1>
<h4><?php echo $rank;?></h4>
<img class="card-img-top" src='<?php echo $iconLink;?>'>
<ul class="list-group my-2">
<a href="javascript:window.open('uploadForm.php','mywindowtitle','width=1000,height=400')" class="list-group-item text-center bg-dark">Upload Video</a>
</ul>
<ul class="list-group my-2">
<a href="javascript:window.open('updatePassword.php','update password','width=1000,height=400')" class="list-group-item text-center bg-dark">Update Password</a>
</ul>
</div>
<!-- /.col-lg-3 -->
<div class="col-lg-9">
<div class="row my-4 py-5">
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100 bg-dark">
<img class="card-img-top" src="img/like.png">
<div class="card-body">
<h4 class="card-title text-center">
Total Likes
</h4>
<h4 class="text-center card-title"><?php echo $numLike;?></h4>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100 bg-dark">
<img class="card-img-top" src="img/video.png">
<div class="card-body">
<h4 class="card-title text-center">
Total Videos
</h4>
<h4 class="text-center card-title" id="numVid"></h4>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100 bg-dark">
<img class="card-img-top" id="rankImg">
<div class="card-body">
<h4 class="card-title text-center">
LeagueLights Rank
</h4>
<h4 class="text-center card-title" id="leaguelightsRank"></h4>
</div>
</div>
</div>
</div>
<div class="row py-2" id="videoList">
</div>
<!-- /.row -->
</div>
<!-- /.col-lg-9 -->
</div>
<!-- /.row -->
</div>
<!-- /.container -->
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">
<p class="m-0 text-center text-white">Copyright © LeagueLights 2018</p>
</div>
<!-- /.container -->
</footer>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/popper/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>