mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-19 22:53:03 +05:30
(feat): added hoverable project info tooltip card
This commit is contained in:
32
htdocs/core/github_api_functions.php
Normal file
32
htdocs/core/github_api_functions.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// function to fetch star and fork count of the given github repo
|
||||
function fetch_repo_stats($repoName) {
|
||||
$url = "https://api.github.com/repos/" . $repoName;
|
||||
$token = $_ENV['GITHUB_ACCESS_TOKEN'];
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP script');
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"Authorization: token $token"
|
||||
));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if ($response === false) {
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
echo "Error fetching data for repo '$repoName': $error";
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
$repoData = json_decode($response, true);
|
||||
|
||||
$stargazersCount = isset($repoData['stargazers_count']) ? $repoData['stargazers_count'] : null;
|
||||
$forksCount = isset($repoData['forks_count']) ? $repoData['forks_count'] : null;
|
||||
|
||||
return [$stargazersCount, $forksCount];
|
||||
}
|
||||
?>
|
||||
14
htdocs/core/utility_functions.php
Normal file
14
htdocs/core/utility_functions.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// function to format given number in youtube views style
|
||||
function format_number_in_yt_style($num) {
|
||||
if ($num >= 1000000000) {
|
||||
return number_format($num / 1000000000, 1) . 'B';
|
||||
} elseif ($num >= 1000000) {
|
||||
return number_format($num / 1000000, 1) . 'M';
|
||||
} elseif ($num >= 1000) {
|
||||
return number_format($num / 1000, 1) . 'K';
|
||||
} else {
|
||||
return $num;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user