diff --git a/classement.php b/classement.php index 40c12954b6e167c1a0b200010e2ca725fbbb867d..84f01695fe16f57917d7295f4b57e9f487de5e07 100644 --- a/classement.php +++ b/classement.php @@ -21,6 +21,31 @@ include "header.php"; </tr> </thead> <tbody> + <?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 $result = mysqli_query($link, "SELECT nom_artiste, nb_youtube + nb_instagram as nb, tag_instagram FROM influenceurs WHERE nb_youtube != 0 && nb_instagram != 0 ORDER BY nb DESC LIMIT 10"); $compt = 1; @@ -28,7 +53,7 @@ include "header.php"; <tr onclick="document.location = 'page_globale.php?user=<?= $row['tag_instagram'] ?>';" class="table-click"> <th scope="row"><?= $compt ?></th> <td class="text-right"><?php if ($compt == 1) : ?><i class="fas fa-medal"></i><?php endif;?> <?= $row['nom_artiste'] ?></td> - <td class="text-right"><?= $row['nb'] ?></td> + <td class="text-right"><?= number_format_short($row['nb'] , $precision = 1 )?></td> </tr> <?php $compt = $compt + 1; @@ -54,7 +79,7 @@ include "header.php"; <tr onclick="document.location = 'instagram-profil.php?user=<?= $row['tag_instagram'] ?>';" class="table-click"> <th scope="row"><?= $compt ?></th> <td class="text-right"><?php if ($compt == 1) : ?><i class="fas fa-medal"></i><?php endif;?> <?= $row['nom_artiste'] ?></td> - <td class="text-right"><?= $row['nb'] ?></td> + <td class="text-right"><?= number_format_short($row['nb'] , $precision = 1 ) ?></td> </tr> <?php $compt = $compt + 1; @@ -78,8 +103,8 @@ include "header.php"; while($row = mysqli_fetch_assoc($resultY)) : ?> <tr onclick="document.location = 'youtube.php?user=<?= $row['tag_youtube'] ?>';" class="table-click"> <th scope="row"><?= $compt ?></th> - <td class="text-right"><?php if ($compt == 1) : ?><i class="fas fa-medal"></i><?php endif;?> <?= $row['nom_artiste'] ?></td> - <td class="text-right"><?= $row['nb'] ?></td> + <td class="text-right"><?php if ($compt == 1) : ?><i class="fas fa-medal"></i><?php endif;?> <?= $row['nom_artiste'] ?></td> + <td class="text-right"><?= number_format_short($row['nb'] , $precision = 1 ) ?></td> </tr> <?php $compt = $compt + 1; diff --git a/youtube.php b/youtube.php index 6ff85fcc217dc8cabe7acbd55f337f506a7d93c6..15e9daed434295138e926f0b85a610e046c45dbe 100644 --- a/youtube.php +++ b/youtube.php @@ -16,6 +16,30 @@ $Username = $_GET['user']; $api_key = "AIzaSyARTHdxCjdGqr74cGU1cd0DGwgLnQJ3Xls"; //$api_key = "AIzaSyDHVEM0wpvM5x1q06r12GcXYYjplhBBo4A"; ?> +<?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;} +?> <section class="one profil-info-yt"> <div class="container"> <div class="row"> @@ -44,16 +68,15 @@ $api_key = "AIzaSyARTHdxCjdGqr74cGU1cd0DGwgLnQJ3Xls"; </span> video posts </div> <div class="col-md-4"> - <span class="followers"> + <span id ="nbyt"class="followers"> <?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); - echo $api_info_account_decoded['items'][0]['statistics']['subscriberCount'];?> + // $api_subscribercount_decoded = json_decode($api_subscribercount, true);?> </span> subscribers </div> <div class="col-md-4"> - <span class="views"> + <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); @@ -116,24 +139,21 @@ $api_key = "AIzaSyARTHdxCjdGqr74cGU1cd0DGwgLnQJ3Xls"; <div class="col-md-4"> <!-- likes --> <i class="fas fa-thumbs-up"></i> - <?=$api_video_infos_decoded['items'][0]['statistics']['likeCount'];?> - likes + <?=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 class="col-md-4 text-center"> + <div id="dislikes_youtube" class="col-md-4 text-center"> <!-- DislikeCount --> <i class="fas fa-thumbs-down"></i> - <?=$api_video_infos_decoded['items'][0]['statistics']['dislikeCount'];?> - dislikes + <?=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 class="col-md-4 text-right"> + <div id="views_youtube" class="col-md-4 text-right"> <!-- VideoViewCount --> <i class="fas fa-eye"></i> - <?=$api_video_infos_decoded['items'][0]['statistics']['viewCount'];?> - views + <?=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> @@ -349,7 +369,27 @@ var points = []; }); </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; +} +</script> + + <script type="text/javascript"> + var nbYT = parseInt(<?= $api_info_account_decoded['items'][0]['statistics']['subscriberCount'] ?>); + var viewsYT = parseInt(<?= $api_info_account_decoded['items'][0]['statistics']['viewCount'] ?>); + document.getElementById("nbyt").innerHTML = nFormatter(nbYT); + document.getElementById("viewsyt").innerHTML = nFormatter(viewsYT); + + + </script> <?php