8 Star 61 Fork 16

Hamm / Svg Badge Tool

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
gitee.php 1.78 KB
Copy Edit Web IDE Raw Blame History
Hamm authored 2020-10-31 14:27 . fix: 修复获取Gitee数据失败的BUG
<?php
require_once('common.php');
if(empty($_GET['user']) || empty($_GET['project']) || empty($_GET['type'])){
header('Location: https://gitee.com/hamm/svg_badge_tool');
die;
}
$user = trim($_GET['user'] ?? 'hamm');
$project = trim($_GET['project'] ?? 'svg_badge_tool');
$type = trim($_GET['type'] ?? 'star');
$key = 'Gitee';
$value = '';
$url = "https://gitee.com/".$user."/".$project;
$html = httpGetFull($url);
$html = str_replace(PHP_EOL,'',$html);
// print_r($html);die;
switch($type){
case 'star':
try{
if(preg_match('/\/stargazers" title="(.*?)"/', $html, $matches)){
$value = $matches[1]." Stars";
}else{
$value = "? Stars";
}
}catch(Exception $e){
$value = "? Stars";
}
break;
case 'fork':
try{
if(preg_match('/\/members" title="(.*?)"/', $html, $matches)){
$value = $matches[1]." Forks";
}else{
$value = "? Forks";
}
}catch(Exception $e){
$value = "? Forks";
}
break;
case 'watch':
try{
if(preg_match('/\/watchers" title="(.*?)"/', $html, $matches)){
$value = $matches[1]." Watches";
}else{
$value = "? Watches";
}
}catch(Exception $e){
$value = "? Watches";
}
break;
case 'commit':
try{
if(preg_match("/<i class='iconfont icon-commit'><\/i>(.*?) 次提交<\/a>/", $html, $matches)){
$value = $matches[1]." Commits";
}else{
$value = "? Commits";
}
}catch(Exception $e){
$value = "? Commits";
}
break;
default:
}
require_once('svg.php');
?>

Comment ( 0 )

Sign in for post a comment

PHP
1
https://gitee.com/hamm/svg_badge_tool.git
git@gitee.com:hamm/svg_badge_tool.git
hamm
svg_badge_tool
Svg Badge Tool
master

Search