Skip to content

Commit

Permalink
Merge pull request #38 from kengwang/master
Browse files Browse the repository at this point in the history
⛓  Fixed: 修复追番页面
  • Loading branch information
BigCoke233 authored Mar 23, 2020
2 parents 7269b8b + 0d9ebf4 commit d116fc4
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 285 deletions.
218 changes: 144 additions & 74 deletions bangumi.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,74 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 追番页面
*
*
* @author Kengwang
* @for BigCoke233/miracles
*
* @package custom
*/
//判断是否为HTPS
function is_https() {
if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {

//判断是否为HTTPS
function is_https()
{
if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
return true;
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
return true;
} elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
} elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
return true;
}
return false;
}
define('IS_HTTPS',is_https());

define('IS_HTTPS', is_https());
$this->need('includes/head.php');
$this->need('includes/header.php');
$this->need('libs/Bangumi.php');


function curl($url, $cookie)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
//地址
//curl_setopt ($curl, CURLOPT_COOKIEJAR, $cookiefile);//文件式
//curl_setopt ($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$str = curl_exec($curl);
curl_close($curl);
return $str;
}

function getSubstr($str, $leftStr, $rightStr)
{
$left = strpos($str, $leftStr);
//echo '左边:'.$left;
$right = strpos($str, $rightStr, $left);
//echo '<br>右边:'.$right;
if ($left < 0 or $right < $left) return '';
return substr($str, $left + strlen($leftStr), $right - $left - strlen($leftStr));
}

if ($this->fields->uid == !'' && $this->fields->sessdata == !'') {
bilibili::setUserInfo($this->fields->uid, $this->fields->sessdata);
if (empty($_GET['page']) || $_GET['page'] == 0) $page = 1; else $page = $_GET['page'];
$bgmdataraw = bilibili::getFollowingListRaw($page,16);
$bgmlist = bilibili::getFormatList($bgmdataraw['data']['list']);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.bilibili.com/x/space/bangumi/follow/list?type=1&follow_status=0&vmid=' . $this->fields->uid . '&ps=16&pn=' . $page);
curl_setopt($curl, CURLOPT_COOKIE, 'SESSDATA=' . $this->fields->sessdata . ';');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$str = curl_exec($curl);
curl_close($curl);
$bgmdataraw = json_decode($str, true);
$error = false;
if (!$bgmdataraw) $error = true;
} else {
$bgmdataraw = array();
$bgmlist = array();
}

// Uncomment for debugging
/*
if ($_GET['dbg'] == 'fuck') {
if ($_GET['dbg'] == 'format') {
echo "<pre>";
print_r($bgmlist);
echo "</pre>";
Expand All @@ -48,70 +82,106 @@ function is_https() {

?>
<main class="main-container container">
<div class="post-body"><div class="post-content">
<?php
//番组链接 $bgm['link'];
//番组名字 $bgm['name'];
//番组封面 $bgm['img'];
//番组介绍 $bgm['des'];
//观看进度 $bgm['watched'] . "/" . $bgm['all']
//更新至 $bgm['new']['title'];
//观看状态 if ($bgm['basket'] == 0) echo '想看';
// if ($bgm['basket'] == 1) echo '在看';
// if ($bgm['basket'] == 2) echo '看完';
/**
开始循环
<?php
if ($bgmdataraw['data']['total'] != 0):
foreach ($bgmlist as $bgm) : ?>
//content
<?php endforeach;
else: ?>
//if nothing
<?php endif; ?>
**/
?>
<div class="container-fluid"><div class="row">
<div class="post-body">
<div class="post-content">
<?php
if ($bgmdataraw['data']['total'] != 0): //没有东西
foreach ($bgmlist as $bgm) : ?>

<div class="bangumi-item col-md-4 col-lg-3"><a href="<?php echo $bgm['link']; ?>" target="_blank" class="no-line bangumi-link">
<div class="bangumi-banner">
<?php $db=Typecho_Db::get();
$load_image = $db->fetchAll($db->select('value')->from('table.options')->where('name = %s', "theme:Miracles")->limit(1));
$load_image = explode("\";",explode("\"",explode("\"loading_image\";",$load_image[0]["value"],2)[1],2)[1],2)[0]; ?>
<img src="<?php if(IS_HTTPS):?>/usr/themes/Miracles/images/loading/<?php echo $load_image;?>.gif" data-original="<?php echo $bgm['img']; else: echo $bgm['img']; endif;?>" referrerpolicy="no-referrer">
<div class="bangumi-des">
<p><?php echo $bgm['des']; ?></p>
</div>
</div>
<div class="bangumi-content">
<h3 class="bangumi-title" title="<?php echo $bgm['name'];?>"><?php echo $bgm['name'];?></h3>
<div class="bangumi-progress" style="width:100%">
<div class="bangumi-progress-bar" style="width:<?php echo round(($bgm['watched']/$bgm['all'])*100); ?>%"></div>
</div>
<div class="bangumi-progress-num">进度:<?php echo $bgm['watched']; echo ' / '; echo $bgm['all'];?></div>
</div></a>
</div>

<?php endforeach;
else: ?>
<h1 class="about-name"><?php echo '啥也没有呐 !!!∑(゚Д゚ノ)ノ';?></h1>
<?php endif; ?>
</div></div>
//番组链接 $bgm['link'];
//番组名字 $bgm['name'];
//番组封面 $bgm['img'];
//番组介绍 $bgm['des'];
//观看进度 $bgm['watched'] . "/" . $bgm['all']
//更新至 $bgm['new']['title'];
//观看状态 if ($bgm['basket'] == 0) echo '想看';
// if ($bgm['basket'] == 1) echo '在看';
// if ($bgm['basket'] == 2) echo '看完';
/**
* 开始循环
* <?php
* if ($bgmdataraw['data']['total'] != 0):
* foreach ($bgmlist as $bgm) : ?>
* //content
* <?php endforeach;
* else: ?>
* //if nothing
* <?php endif; ?>
**/
?>
<div class="container-fluid">
<div class="row">
<?php
if (!$error && $bgmdataraw['data']['total'] != 0): //没有东西
$bgmlist=$bgmdataraw['data']['list'];
foreach ($bgmlist as $bangumi) : ?>
<div class="bangumi-item col-md-4 col-lg-3"><a href="<?php echo 'https:////www.bilibili.com/bangumi/play/ss' . $bangumi['season_id'] . '/'; ?>" target="_blank" class="no-line bangumi-link">
<div class="bangumi-banner">
<?php $db = Typecho_Db::get();
$load_image = $db->fetchAll($db->select('value')->from('table.options')->where('name = %s', "theme:Miracles")->limit(1));
$load_image = explode("\";", explode("\"", explode("\"loading_image\";", $load_image[0]["value"], 2)[1], 2)[1], 2)[0]; ?>
<img src="<?php if (IS_HTTPS): ?>/usr/themes/Miracles/images/loading/<?php echo $load_image; ?>.gif"
data-original="<?php echo $bangumi['cover']; else: echo $bangumi['cover'];
endif; ?>" referrerpolicy="no-referrer">
<div class="bangumi-des">
<p><?php echo isset($bangumi['evaluate']) && $bangumi['evaluate'] != '' ? $bangumi['evaluate'] : '暂无简介'; ?></p>
</div>
</div>
<div class="bangumi-content">
<h3 class="bangumi-title" title="<?php echo $bangumi['title']; ?>"><?php echo $bangumi['title']; ?></h3>
<div class="bangumi-progress" style="width:100%">
<div class="bangumi-progress-bar"
style="width:<?php
//获取总集数
$total = 0;
if ($bangumi['is_finish']) {
$total = $bangumi['total_count'];
//total_count是预计总集数
} elseif (!$bangumi['is_started'] || $bangumi['new_ep']['index_show'] == '即将开播') {
$total = 0;
} else {
$total = $bangumi['new_ep']['title'];
if (!is_numeric($total)) $total = $bangumi['total_count'];
//有些最后是Extra,默认识别为最后一集
}
if ($total < 0) $total = 0;
$ep = 0;
if (!$bangumi['is_started']) {
//没有开始
$ep = 0;
} elseif (strpos($bangumi['progress'], '已看完')) {
$ep = $total;
} elseif (isset($bangumi['progress']) && !strpos($bangumi['progress'], 'PV')) {
$ep = getSubstr($bangumi['progress'], '', '');
if (!is_numeric($ep)) $ep = $total;
//匹配左右取中间数字
} else {
$ep = 0;
}
echo round(($ep / $total) * 100); ?>%"></div>
</div>
<div class="bangumi-progress-num">进度:<?php echo $ep;
echo ' / ';
echo $total; ?></div>
</div>
</a>
</div>

<?php endforeach;
else: ?>
<h1 class="about-name"><?php echo '啥也没有呐 !!!∑(゚Д゚ノ)ノ'; ?></h1>
<?php endif; ?>
</div>
</div>
<br>
</div>
</div>
<div class="post-pagenav">
<?php if ($page != 1): ?><a class="post-pagenav-left" href="?page=<?php echo $page - 1; ?>"><i
class="iconfont icon-chevron-left"></i></a> <?php endif; ?>
<?php if ($bgmdataraw['data']['pn'] * $bgmdataraw['data']['ps'] < $bgmdataraw['data']['total']): ?>
<a class="post-pagenav-right" href="?page=<?php echo $page + 1; ?>"><i
class="iconfont icon-chevron-right"></i></a>
<?php endif; ?>
</div>
<br>
</div>
</div>
<div class="post-pagenav">
<?php if ($page != 1): ?><a class="post-pagenav-left" href="?page=<?php echo $page - 1; ?>"><i
class="iconfont icon-chevron-left"></i></a> <?php endif; ?>
<?php if ($bgmdataraw['data']['pn'] * $bgmdataraw['data']['ps'] < $bgmdataraw['data']['total']): ?>
<a class="post-pagenav-right" href="?page=<?php echo $page + 1; ?>"><i
class="iconfont icon-chevron-right"></i></a>
<?php endif; ?>
</div>
<br>
<?php $this->need('includes/comments.php');
?>
</main>
Expand Down
Loading

0 comments on commit d116fc4

Please sign in to comment.