Sélectionner une révision Git
visualisation_profil.php
-
Sandra MICHAUT a rédigéSandra MICHAUT a rédigé
page_globale.php 24,81 Kio
<?php
include "./config/database.php";
include "header.php";
?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<?php
$Username = $_GET["user"];
$result= $bdd->query("SELECT id_artiste,nom_artiste,tag_youtube,tag_instagram FROM `influenceurs` WHERE `nom_artiste` LIKE '$Username%' OR `tag_youtube` LIKE '$Username%' OR `tag_instagram` LIKE '$Username%' ORDER BY `nom_artiste`");
$name=$result->fetch();
$user1 =$name['tag_youtube'];
$user2=$name['tag_instagram'];
$id=$name["id_artiste"];
if (isset($_POST["ajout"])){
if ($_POST["ajout"]==1){
$sql="INSERT INTO favoris VALUES (".$id.",".$_SESSION['id'].")";
if ($bdd->query($sql)==TRUE) :?>
<div class="row">
<div class="col-sm-4 ml-auto">
<div class="alert alert-success alert-dismissible fadeIn animated alert-co">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Ajouté(e) aux favoris avec succès
</div>
</div>
</div>
<?php endif;
}
}
if (isset($_POST["retire"])){
if ($_POST["retire"]==1){
$sql="DELETE FROM favoris WHERE id_artiste=".$id." AND id_user=".$_SESSION['id'];
if ($bdd->query($sql)==TRUE) :?>
<div class="row">
<div class="col-sm-4 ml-auto">
<div class="alert alert-success alert-dismissible fadeIn animated alert-co">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Retiré(e) des favoris avec succès
</div>
</div>
</div>
<?php endif;
}
}
$_POST["ajout"]=0;
$_POST["retire"]=0;
$sql2="SELECT * FROM favoris WHERE id_artiste=".$id." AND id_user=".$_SESSION['id'];
$result2=$bdd->query($sql2);
$fav=1;
if ($result2->fetch()==NULL) {$fav=0;};
echo $fav;
?>
<?php
$Username = $user1;
//$api_key = "AIzaSyARTHdxCjdGqr74cGU1cd0DGwgLnQJ3Xls";
$api_key = "AIzaSyDHVEM0wpvM5x1q06r12GcXYYjplhBBo4A";
?>
<div class="text-center fadeInUp animated pt-4">
<h1> Page globale de : <?php echo $name['nom_artiste'];?> </h1>
</div>
</header>
<section class="one profil-global-info ">
<div class="container">
<div class="row">
<div class="col-md-3">
<img src="" class="profile-pic" style="border-radius:50%;position: relative;top:20px; left:25px; ">
</div>
<div class="col-md-9">
<h2 class="name" style="font-size: 30px;position: relative;top:15px; left:-10px;"></h2>
<br/>
<div class="row"style="margin-top:-10px; position: relative;top:15px; left:-10px;">
<div class="col-md-2" >
INSTA :
</div>
<div class="col-md-2" >
<span class="username"></span>
</div>
<div class="col-md-2" >
<span class="number-of-posts"></span> posts
</div>
<div class="col-md-2">
<span class="followers"></span> followers
</div>
<div class="col-md-2">
<span class="following"></span> following
</div>
</div>
<div class="row">
<!-- <h4 class="biography"style="font-size:11px;position: relative;top:15px; left:8px;margin-top:10px;"></h4>
--> </div>
<div class="row"style="margin-top:10px; position: relative;top:15px; left:-10px;">
<div class="col-md-2">
YOUTUBE :
</div>
<div class="col-md-2" >
<span class="username-youtube"></span>
<?php
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {
$n_format = number_format($n / 1000, $precision);
$suffix = 'K';
} else if ($n < 900000000) {
$n_format = number_format($n / 1000000, $precision);
$suffix = 'M';
} else if ($n < 900000000000) {
$n_format = number_format($n / 1000000000, $precision);
$suffix = 'B';
} else {
$n_format = number_format($n / 1000000000000, $precision);
$suffix = 'T';
}
if ( $precision > 0 ) {
$dotzero = '.' . str_repeat( '0', $precision );
$n_format = str_replace( $dotzero, '', $n_format );
}
return $n_format . $suffix;}
?>
<?php
//AccountName
$api_AccountName = file_get_contents('https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername='.$Username.'&fields=items/snippet/title&key='.$api_key);
$api_AccountName_decoded = json_decode($api_AccountName, true);
echo $user1;
?>
</div>
<div class="col-md-2" >
<span class="number-of-posts-youtube">
<?php
$api_info_account = file_get_contents('https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername='.$Username.'&key='.$api_key);
$api_info_account_decoded = json_decode($api_info_account, true);
//VideoCount
echo $api_info_account_decoded['items'][0]['statistics']['videoCount'];
?>
</span> videos
</div>
<div class="col-md-2">
<span id ="nbyt" class="followers-youtube">
<?php
//SubscriberCount
// $api_subscribercount = file_get_contents('https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername='.$Username.'&fields=items/statistics/subscriberCount&key='.$api_key);
// $api_subscribercount_decoded = json_decode($api_subscribercount, true);
$totalfollowersyoutube=$api_info_account_decoded['items'][0]['statistics']['subscriberCount'];
?>
</span> subscribers
</div>
<div class="col-md-2">
<span id ="viewsyt" class="views">
<?php
//ViewCount
// $api_ViewCount = file_get_contents('https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername='.$Username.'&fields=items/statistics/viewCount&key='.$api_key);
// $api_ViewCount_decoded = json_decode($api_ViewCount, true);
$views=$api_info_account_decoded['items'][0]['statistics']['viewCount'];
?>
</span> views
</div>
</div>
<div class="row"style="margin-top:-10px; position: relative;top:15px; left:-10px;">
<div class="col-md-2">
</div>
</div>
<div class="row"style="margin-top:-10px; position: relative;top:15px; left:-10px;">
<!-- <div class="col-md-4">
GLOBAL :
</div>
<div class="col-md-4">
<span class="total-followers">
</span>
</div>
<div class="col-md-2">
<span class="total-posts"> </span>
</div>
</div> -->
</div>
</section>
<section class="one profil-photos">
<div class="container">
<?php if ($_SESSION["authent"]==1) : ?>
<?php if ($fav==0): ?>
<div class="center">
<form class="" action="#" method="post">
<input name="ajout" type="hidden" value =1>
<button type="submit" class="button1"><i class="far fa-heart"></i> Ajouter aux favoris</button>
</div>
<br/><br/><br/>
<?php endif; ?>
<?php if ($fav==1): ?>
<div class="center">
<form class="" action="#" method="post">
<input name="retire" type="hidden" value =1>
<button type="submit" class="button1"><i class="fas fa-heart"></i> Retirer des favoris</button>
</div>
<br/><br/><br/>
<?php endif; ?>
<?php endif; ?>
<div class="row">
<div class="col-md-12">
<h4>POSTS INSTA</h4>
<div class="divider"></div>
<div class="row posts">
</div>
</div>
</div>
</div>
</section>
<script src="ressources/canvasjs/canvasjs.min.js"></script>
<script type="text/javascript">
function nFormatter(num){
if(num >= 1000000){
return (num/1000000).toFixed(1).replace(/\.0$/,'') + 'M';
}
if(num >= 1000){
return (num/1000).toFixed(1).replace(/\.0$/,'') + 'K';
}
return num;
}
var tab= new Array();
var commentaire=new Array();
var nbInsta;
var userInsta = "<?=$_GET['user'];?>";
var follo_insta=new Array();
$.ajax({
url:"https://www.instagram.com/<?php echo $user2;?>?__a=1",
type:'get',
dataType: 'json',
Async : false,
success:function(response){
$(".profile-pic").attr('src',response.graphql.user.profile_pic_url);
$(".name").html(response.graphql.user.full_name);
$(".biography").html(response.graphql.user.biography);
$(".username").html(response.graphql.user.username);
$(".number-of-posts").html(response.graphql.user.edge_owner_to_timeline_media.count);
$(".followers").html(nFormatter(response.graphql.user.edge_followed_by.count));
follo_insta.push(response.graphql.user.edge_followed_by.count);
$(".following").html(nFormatter(response.graphql.user.edge_follow.count));
posts = response.graphql.user.edge_owner_to_timeline_media.edges;
posts_html = '';
for(var i=0;i<6;i++){
url = posts[i].node.display_url;
likes = posts[i].node.edge_liked_by.count;
tab[i]=posts[i].node.edge_liked_by.count;
commentaire[i]=posts[i].node.edge_media_to_comment.count;
comments = posts[i].node.edge_media_to_comment.count;
posts_html += '<div class="col-md-2 equal-height"><a href="'+url+'" target=_blank><img class="insta-photo" src="'+url+'"></a><div class="row like-comment"><div class="col-md-6"><i class="fas fa-heart"></i> '+nFormatter(likes)+' LIKES</div><div class="col-md-6 text-right"><i class="fas fa-comment-dots"></i> '+nFormatter(comments)+' COMMENTS</div></div></div>';
}
$(".posts").html(posts_html);
var points = [];
var chart = new CanvasJS.Chart("chartContainer", {
backgroundColor: "transparent", //Couleur à changer (voir thème de la page)
animationEnabled: true,
theme: "theme2",
title: {
text: "Nombre de likes sur les 6 derniers posts",
fontSize: 24,
fontWeight: "normal",
horizontalAlign: "center",
},
axisY: {
title : "Likes",
includeZero:true,
lineThickness: 2
},
axisX: {
title : "Posts (du plus ancien au plus récent )",
labelAngle: -60,
},
data: [{
type: "spline",
markerType: "circle",
color: "#df4e8e",
dataPoints: points
}
]});
function addPoints(){
points.push({y: tab[5],
label: 'Post 6'});
points.push({y: tab[4],
label: 'Post 5'});
points.push({y: tab[3],
label: 'Post 4'});
points.push({y: tab[2],
label: 'Post 3'});
points.push({y: tab[1],
label: 'Post 2'});
points.push({y: tab[0],
label: 'Post 1'});
chart.options.data[0].dataPoints = points;
chart.render();
}
addPoints();
$.ajax({
type: "POST",
url: "nb_insta.php",
data: {
nbInsta:nbInsta,
userInsta:userInsta,
},
success: function(response)
{
}
});
}
});
</script>
<section class="one yb-videos-global">
<div class="container">
<h4>VIDEOS</h4>
<div class="divider-youtube"></div>
<?php
//ProfilePic
//$api_ProfilePic = file_get_contents('https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername='.$Username.'&fields=items/snippet/thumbnails/default&key='.$api_key);
//$api_ProfilePic_decoded = json_decode($api_ProfilePic, true);
//$img= $api_ProfilePic_decoded['items'][0]['snippet']['thumbnails'];
//echo "<img src='$img'>";
//ChannelID
$api_ChannelID = file_get_contents('https://www.googleapis.com/youtube/v3/channels?key='.$api_key.'&forUsername='.$Username.'&part=id');
$api_ChannelID_decoded = json_decode($api_ChannelID, true);
//Get Last 6 Video Posts
$channelID = $api_ChannelID_decoded['items'][0]['id'];
$maxResults = 6;
$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$api_key.''));
$c = 1;
$tableau_likes = array();
$tableau_dislikes = array();
$tableau_views = array();
foreach($videoList->items as $item){
//Video Post
if(isset($item->id->videoId)){ ?>
<?php if ($c%3 == 1) {
echo "<div class='row'>";
} ?>
<div class="col-md-4">
<div class="Youtube Video">
<div class="row">
<div class="col-sm-12">
<h5 class="yt-videos-title"><?=$item->snippet->title?></h5>
</div>
</div>
<iframe width="100%" height="300" src="https://www.youtube.com/embed/<?=$item->id->videoId?>" frameborder="0" allowfullscreen></iframe>
</div>
<?php
//recuperer les infos de la video
$api_video_infos = file_get_contents('https://www.googleapis.com/youtube/v3/videos?part=snippet%2Cstatistics&id='.$item->id->videoId.'&key='.$api_key.'');
$api_video_infos_decoded = json_decode($api_video_infos, true);
?>
<div class="row like-comment">
<div id="likes_youtube" class="col-md-4">
<!-- likes -->
<i class="fas fa-thumbs-up"></i>
<?=number_format_short( $api_video_infos_decoded['items'][0]['statistics']['likeCount'], $precision = 1 );?>
<?php
array_push($tableau_likes,$api_video_infos_decoded['items'][0]['statistics']['likeCount']);?>
</div>
<div id="dislikes_youtube" class="col-md-4 text-center">
<!-- DislikeCount -->
<i class="fas fa-thumbs-down"></i>
<?=number_format_short( $api_video_infos_decoded['items'][0]['statistics']['dislikeCount'], $precision = 1 );?>
<?php
array_push($tableau_dislikes,$api_video_infos_decoded['items'][0]['statistics']['dislikeCount']);?>
</div>
<div id="views_youtube" class="col-md-4 text-right">
<!-- VideoViewCount -->
<i class="fas fa-eye"></i>
<?=number_format_short( $api_video_infos_decoded['items'][0]['statistics']['viewCount'], $precision = 1 );?>
<?php
array_push($tableau_views,$api_video_infos_decoded['items'][0]['statistics']['viewCount']);?>
</div>
</div>
</div>
<?php if ($c%3 == 0) {
echo "</div>";
}
$c=$c+1;?>
<?php
}
}
?>
</div>
</div>
</div>
</section>
</div>
</div>
</section>
<section class="one graphics" style="background-color:#efefef;">
<div class="container">
<div class="row">
<div class="col-md-12">
<h4>Analyses statistiques INSTAGRAM</h4>
<div class="divider"></div>
<div id="chartContainer" style="height: 400px; width: 100%;"></div>
</div>
</div>
</div>
</section>
<section class="one graphics" style="background-color:white;">
<div class="container">
<div class="row">
<div class="col-md-12">
<h4>Analyses statistiques YOUTUBE
</h4>
<div class="divider-youtube"></div>
<div id="chart1Container" style="height: 400px; width: 100%;"></div>
<div class="divider-youtube"></div>
<div id="chartContainerLike" style="height: 400px; width: 100%;"></div>
<div class="divider-youtube"></div>
<div id="chartContainerViews" style="height: 400px; width: 100%;"></div>
<div class="divider-youtube"></div>
<div id="chartContainerBoth" style="height: 400px; width: 100%;"></div>
</div>
</div>
</div>
</section>
<script src="ressources/canvasjs/canvasjs.min.js"></script>
<script type="text/javascript">
tableau_likes_js = <?php echo json_encode($tableau_likes) ?>;
tableau_dislikes_js = <?php echo json_encode($tableau_dislikes) ?>;
tableau_views_js = <?php echo json_encode($tableau_views) ?>;
var userYT = "<?= $Username ?>";
var nbYT = parseInt(<?= $api_info_account_decoded['items'][0]['statistics']['subscriberCount'] ?>);
var viewsYT = parseInt(<?= $api_info_account_decoded['items'][0]['statistics']['viewCount'] ?>);
/*----------------Graph ratio like/dislike-------------------*/
var points1 = [];
var chart1 = new CanvasJS.Chart("chart1Container", {
backgroundColor: "transparent ", //Couleur à changer (voir thème de la page)
animationEnabled: true,
theme: "theme2",
title: {
text: "Ratio de likes/dislikes sur les 6 dernières vidéos",
fontSize: 24,
fontWeight: "normal",
horizontalAlign: "center",
},
axisY: {
title : "Ratio",
includeZero:true,
lineThickness: 2
},
axisX: {
title : "Videos (de la plus récente à la plus ancienne)",
labelAngle: -60,
},
data: [{
type: "spline",
markerType: "circle",
color: "#df4e8e",
dataPoints: points1,
}
]});
function addPoints1(){
points1.push({y: tableau_likes_js[5]/tableau_dislikes_js[5],
label: 'Video 6'});
points1.push({y: tableau_likes_js[4]/tableau_dislikes_js[4],
label: 'Video 5'});
points1.push({y: tableau_likes_js[3]/tableau_dislikes_js[3],
label: 'Video 4'});
points1.push({y: tableau_likes_js[2]/tableau_dislikes_js[2],
label: 'Video 3'});
points1.push({y: tableau_likes_js[1]/tableau_dislikes_js[1],
label: 'Video 2'});
points1.push({y: tableau_likes_js[0]/tableau_dislikes_js[0],
label: 'Video 1'});
chart1.options.data[0].dataPoints = points1;
chart1.render();
}
addPoints1();
/*---------------Graph like dislike--------------------*/
var chartLike = new CanvasJS.Chart("chartContainerLike", {
backgroundColor: "transparent ", //Couleur à changer (voir thème de la page)
animationEnabled: true,
theme: "theme2",
title: {
text: "Nombre de likes et dislikes sur les 6 dernières vidéos",
fontSize: 24,
fontWeight: "normal",
horizontalAlign: "center",
},
axisY: {
title : "Likes",
titleFontColor: "#4F81BC",
lineColor: "#4F81BC",
labelFontColor: "#4F81BC",
tickColor: "#4F81BC"
},
axisY2: {
title: "Dislikes",
titleFontColor: "#C0504E",
lineColor: "#C0504E",
labelFontColor: "#C0504E",
tickColor: "#C0504E"
},
axisX: {
title : "Videos (de la plus récente à la plus ancienne)",
labelAngle: -60,
},
legend: {
cursor: "pointer",
// itemclick: toggleDataSeries
},
data: [{
type: "column",
color: "#4F81BC",
showInLegend: true,
name: "Likes",
dataPoints: [
{ label: "Video 6", y: parseInt(tableau_likes_js[5]) },
{ label: "Video 5", y: parseInt(tableau_likes_js[4]) },
{ label: "Video 4", y: parseInt(tableau_likes_js[3]) },
{ label: "Video 3", y: parseInt(tableau_likes_js[2]) },
{ label: "Video 2", y: parseInt(tableau_likes_js[1]) },
{ label: "Video 1", y: parseInt(tableau_likes_js[0]) }
],
},
{
type: "column",
name: "Dislikes",
color: "#C0504E" ,
showInLegend: true,
axisYType: "secondary",
dataPoints: [
{ label: "Video 6", y: parseInt(tableau_dislikes_js[5]) },
{ label: "Video 5", y: parseInt(tableau_dislikes_js[4]) },
{ label: "Video 4", y: parseInt(tableau_dislikes_js[3]) },
{ label: "Video 3", y: parseInt(tableau_dislikes_js[2]) },
{ label: "Video 2", y: parseInt(tableau_dislikes_js[1]) },
{ label: "Video 1", y: parseInt(tableau_dislikes_js[0]) }
]
}
]
});
chartLike.render();
/*----------------Graph views-------------------*/
var chartViews = new CanvasJS.Chart("chartContainerViews", {
backgroundColor: "transparent ", //Couleur à changer (voir thème de la page)
animationEnabled: true,
theme: "theme2",
title: {
text: "Nombre de vues sur les 6 dernières vidéos",
fontSize: 24,
fontWeight: "normal",
horizontalAlign: "center",
},
axisY: {
title : "Vues",
includeZero:true,
lineThickness: 2
},
axisX: {
title : "Videos (de la plus récente à la plus ancienne)",
labelAngle: -60,
},
data: [{
type: "spline",
markerType: "circle",
color: "#df4e8e",
dataPoints: [
{ label: "Video 6", y: parseInt(tableau_views_js[5]) },
{ label: "Video 5", y: parseInt(tableau_views_js[4]) },
{ label: "Video 4", y: parseInt(tableau_views_js[3]) },
{ label: "Video 3", y: parseInt(tableau_views_js[2]) },
{ label: "Video 2", y: parseInt(tableau_views_js[1]) },
{ label: "Video 1", y: parseInt(tableau_views_js[0]) }
],
}
]});
chartViews.render();
/*----------------Graph comparaison-------------------*/
var follo_youtube = <?php echo json_encode($totalfollowersyoutube=$api_info_account_decoded['items'][0]['statistics']['subscriberCount']); ?>;
window.onload = function () {
var chartBoth = new CanvasJS.Chart("chartContainerBoth",
{
backgroundColor: "transparent ", //Couleur à changer (voir thème de la page)
animationEnabled: true,
theme: "theme2",
title:{
text: "Followers Instagram/Youtube"
},
legend: {
maxWidth: 350,
itemWidth: 120
},
data: [
{
type: "pie",
showInLegend: true,
legendText: "{indexLabel}",
dataPoints: [
{ y: follo_youtube, indexLabel: "Youtube",color: "#C0504E"},
{ y: follo_insta, indexLabel: "Instagram",color: "#4c68d7"},
]
}
]
});
chartBoth.render();
}
$.ajax({
type: "POST",
url: "nb_youtube.php",
data: {
nbYT:nbYT,
userYT:userYT,
},
success: function(response)
{
}
});
</script>
<script type="text/javascript">
document.getElementById("nbyt").innerHTML = nFormatter(nbYT);
document.getElementById("viewsyt").innerHTML = nFormatter(viewsYT);
</script>
<?php
include "footer.php"
?>