diff --git a/API_Twitter/userSuggestions.php b/API_Twitter/userSuggestions.php index be6e35ec725e6d6633fcfb7a8cd42284abeddff0..c05941f49b69d2e1a765e62d1f1e214993c36169 100644 --- a/API_Twitter/userSuggestions.php +++ b/API_Twitter/userSuggestions.php @@ -7,7 +7,7 @@ $res = []; for ($i=0; $i<5; $i++){ $res[$i]['username'] = $results[$i]->screen_name; $res[$i]['profile_image'] = $results[$i]->profile_image_url; - + $res[$i]['id'] = $results[$i]->id; } echo json_encode($res); diff --git a/js/recherche.js b/js/recherche.js index eace6c168c7fe386671dd7ea1785e368d5831ccb..ffab9dacec95e838b9e3aade1bd6bbe9b51d2a7c 100644 --- a/js/recherche.js +++ b/js/recherche.js @@ -9,6 +9,14 @@ document.getElementById('usernames').innerHTML = ""; return; } + var socialNetwork = "Twitter"; + if (document.getElementById("radio_3").checked == true) { + socialNetwork = "Twitter"; + } + else if (document.getElementById("radio_2").checked == true) { + socialNetwork = "Youtube"; + + } xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) {// 4 = request finished and response is ready, 200 = "OK" @@ -18,7 +26,7 @@ var options = ""; for(var i = 0; i < tab.length; i++) { - options += '<button id="userSuggesBtn" class="suggestionButton" onclick="window.location.href=\'../page_profile/profil.php?username='+tab[i].username+'\'"><img src="'+ + options += '<button id="userSuggesBtn" class="suggestionButton" onclick="window.location.href=\'../page_profile/profil.php?id='+tab[i].id+'&sn='+socialNetwork+'\'"><img src="'+ tab[i].profile_image + '" alt="icone" style="vertical-align:middle; position:relative; width:50px; height: 50px;" /><span style="margin-left:10px;">'+ tab[i].username + @@ -34,7 +42,7 @@ API = "API_Twitter"; } else if (document.getElementById("radio_2").checked == true) { - API = "youtube-api" + API = "youtube-api"; } else { document.getElementById("erreur").innerHTML = "Please select a social network."; diff --git a/page_profile/profil.php b/page_profile/profil.php index 590c5fa72df9f31ab8e6b29e15d61ce86901aa80..1439acb5e65210849fa0ff807c245e08403562ee 100644 --- a/page_profile/profil.php +++ b/page_profile/profil.php @@ -1,5 +1,6 @@ <?php require_once('../API_Twitter/userInfosFunctions.php'); +require_once('../youtube-api/userInfos.php'); require_once('../facto.php'); session_start(); @@ -12,6 +13,22 @@ elseif (isset($_POST['id'])) { elseif (isset($_GET['username'])) { $id = getUserId($_GET['username']); } +elseif (isset($_GET['id'])) { + $id = $_GET['id']; +} +else { + echo('ERREUR'); +} + +if (isset($_POST['sn'])) { + $socialNetwork = $_POST['sn']; +} +elseif (isset($_POST['sn'])) { + $socialNetwork = $_POST['sn']; +} +elseif (isset($_GET['sn'])) { + $socialNetwork = $_GET['sn']; +} else { echo('ERREUR'); } @@ -38,14 +55,40 @@ else { --> <div id="photoprofil"> - <img src='<?php echo getUserProfileImage($id) ?>' alt='profile_image' style="width:100px;height:100px;"/> + <img src='<?php + if ($socialNetwork === "Twitter") { + echo getUserProfileImage($id); + } + elseif ($socialNetwork === "Youtube") { + echo getChannelProfileImage($id); + } + ?>' alt='profile_image' style="width:100px;height:100px;"/> </div> <br/><br/> <div class='flexspace' style="padding:30px 40px 0px;border-left:1px solid;width:100%;background-image: linear-gradient(to bottom right, #919df9, #93eeff);border-radius:50px"> - <div>Twitter Username <br/> <h5><?php echo getUserScreenName($id) ?></h5><br/></div> - <div>Twitter Followers <br/> <h5><?php echo number_format (getUserNbFollowers($id), 0, ".", " ")?></h5><br/></div> - <div>Ville ?<br/> <h5></h5> </div> - <div>autre ?<br/> <h5></h5></div> + <div><?php echo $socialNetwork; ?> Username <br/> <h5><?php + if ($socialNetwork === "Twitter") { + echo getUserScreenName($id); + } + elseif ($socialNetwork === "Youtube") { + echo getChannelUsername($id); + } + ?> + + </h5><br/></div> + <div> + <?php + if ($socialNetwork === "Twitter") { + echo "Twitter Followers <br/> <h5>".number_format(getUserNbFollowers($id), 0, ".", " "); + } + elseif ($socialNetwork === "Youtube") { + echo "Youtube Subscribers <br/> <h5>".number_format(getChannelNbFollowers($id), 0, ".", " "); + } + ?> + </h5><br/> + </div> + <div> <br/> <h5></h5> </div> + <div> <br/> <h5></h5></div> </div> </div> diff --git a/youtube-api/userInfos.php b/youtube-api/userInfos.php index 402a9070cc0532f7fbd9bebb13209b6832b02ff3..ae19651b88eb1767ab0df0695b7f59cbf402ea16 100644 --- a/youtube-api/userInfos.php +++ b/youtube-api/userInfos.php @@ -26,6 +26,13 @@ function getChannelId($id){ return $res; } +function getChannelUsername($id){ + global $setting; + $youtube = new Madcoda\Youtube\Youtube($setting); + $res= $youtube->getChannelById($id); + return $res->snippet->title; +} + function getChannelNbFollowers($id) { global $setting; $youtube = new Madcoda\Youtube\Youtube($setting); @@ -37,7 +44,7 @@ function getChannelProfileImage($id) { global $setting; $youtube = new Madcoda\Youtube\Youtube($setting); $res= $youtube->getChannelById($id); - $url = $res->thumbnails->medium->url; + $url = $res->snippet->thumbnails->high->url; return $url; } @@ -53,4 +60,5 @@ function getChannelViewCount($id) { $youtube = new Madcoda\Youtube\Youtube($setting); $res= $youtube->getChannelById($id); return intval($res->statistics->viewCount); -} \ No newline at end of file +} + diff --git a/youtube-api/userSuggestions.php b/youtube-api/userSuggestions.php index e38473c7b4e7044a14c79b71d28384a0676cb2b0..c2a40ac0a31098f8faeb0decd52fef6a33c2b236 100644 --- a/youtube-api/userSuggestions.php +++ b/youtube-api/userSuggestions.php @@ -1,15 +1,14 @@ <?php require './userInfos.php'; - $results = searchByKey($_GET['w']); - $res=array(); for ($i=0; $i<5; $i++){ $res[$i]['username'] = $results[$i]->snippet->channelTitle; $res[$i]['profile_image'] = $results[$i]->snippet->thumbnails->default->url; + $res[$i]['id'] = $results[$i]->snippet->channelId; } echo json_encode($res);