diff options
| author | Kengwang <1136772134@qq.com> | 2020-07-12 11:08:42 +0800 |
|---|---|---|
| committer | Kengwang <1136772134@qq.com> | 2020-07-12 11:08:42 +0800 |
| commit | 8c9b74dc342617fa17a5ebeef158541a005bc674 (patch) | |
| tree | c061a4bf53a5cd2d0c7576e50de003974b40c643 /bangumi.php | |
| parent | ddf292c92736e9fa1563a0d41c446e580e90fb7d (diff) | |
改进番剧页面
* 删去不必要的代码和注释
* 增加了报错信息
* 修改了说明文档链接
* 修复了特殊环境下cUrl的一个问题
* 修复了番剧图片不显示问题 (Fixed: #68)
Diffstat (limited to 'bangumi.php')
| -rwxr-xr-x | bangumi.php | 174 |
1 files changed, 92 insertions, 82 deletions
diff --git a/bangumi.php b/bangumi.php index 00b356e..6c900b5 100755 --- a/bangumi.php +++ b/bangumi.php @@ -8,6 +8,9 @@ * @package custom
*/
+//错误提示信息
+$errormsg = '';
+$error = false;
//判断是否为HTTPS
function is_https()
{
@@ -26,48 +29,44 @@ $this->need('includes/head.php'); $this->need('includes/header.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 == !'') {
if (empty($_GET['page']) || $_GET['page'] == 0) $page = 1; else $page = $_GET['page'];
- $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=12&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;
+
+ if (!function_exists('curl_init')) {
+ $errormsg .= '未检测到cUrl函数 ';
+ $error = true;
+ } else {
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//不验证HTTPS链接 (PHP7.1 添加支持)
+ curl_setopt($curl, CURLOPT_URL, 'https://api.bilibili.com/x/space/bangumi/follow/list?type=1&follow_status=0&vmid=' . $this->fields->uid . '&ps=12&pn=' . $page);
+ curl_setopt($curl, CURLOPT_COOKIE, 'SESSDATA=' . $this->fields->sessdata . ';');
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ $callback = curl_exec($curl);
+ if ($callback === false) {
+ $errormsg .= 'cUrl错误: ' . curl_error($curl) . ' (CODE: ' . curl_errno($curl) . ') ';
+ $error = true;
+ }
+ curl_close($curl);
+ $bgmdataraw = json_decode($callback, true);
+ if (!$bgmdataraw) {
+ $error = true;
+ $errormsg .= '番剧数据解析错误 ';
+ }
+ }
+
} else {
$bgmdataraw = array();
$bgmlist = array();
}
-//force https
-$bangumi_cover = str_replace("http://", "https://", $bangumi['cover']);
// Uncomment for debugging
/*
@@ -91,9 +90,14 @@ if ($_GET['dbg'] == 'rawlist') { <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 col-sm-6"><a href="<?php echo 'https:////www.bilibili.com/bangumi/play/ss' . $bangumi['season_id'] . '/'; ?>" target="_blank" class="no-line bangumi-link">
+ $bgmlist = $bgmdataraw['data']['list'];
+ foreach ($bgmlist as $bangumi) :
+ //force https
+ $bangumi_cover = str_replace("http://", "https://", $bangumi['cover']);
+ ?>
+ <div class="bangumi-item col-md-4 col-lg-3 col-sm-6"><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));
@@ -106,76 +110,82 @@ if ($_GET['dbg'] == 'rawlist') { </div>
</div>
<div class="bangumi-content">
- <h3 class="bangumi-title" title="<?php echo $bangumi['title']; ?>"><?php echo $bangumi['title']; ?></h3>
+ <h3 class="bangumi-title"
+ title="<?php echo $bangumi['title']; ?>"><?php echo $bangumi['title']; ?></h3>
<?php
//番剧进度开始
if ($bangumi['both_follow']):
- ?>
- <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'] == '即将开播') {
+ ?>
+ <div class="bangumi-progress" style="width:100%">
+ <div class="bangumi-progress-bar"
+ style="width:<?php
+ //获取总集数
$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']) {
- //没有开始
+ 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;
- } 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>
- <?php
+ 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>
+ <?php
endif;
- //番剧进度结束
- ?>
+ //番剧进度结束
+ ?>
</div>
</a>
</div>
<?php endforeach;
else: ?>
- <div style="margin-top:-30px;text-align:center;width:100%">
- <h2><?php echo '追番数据获取失败'; ?></h2>
- <p><?php echo '请检查追番页面配置,以及是否安装 CURL 拓展,若您不知道如何配置,请查阅'; ?><a href="https://www.notion.so/eltrac/c7c631e21b3345caa2a09bd2fb5dd4b2#f736ad8b1eb44cbfaca424efca3c76f0"><?php echo '说明文档'; ?></a></p>
- </div>
+ <div style="margin-top:-30px;text-align:center;width:100%">
+ <h2><?php echo '追番数据获取失败'; ?></h2>
+ <p><?php echo '请检查追番页面配置,以及是否安装 CURL 拓展,若您不知道如何配置,请查阅'; ?><a
+ href="https://github.com/BigCoke233/miracles/blob/master/docs/wiki.md#%E8%BF%BD%E7%95%AA%E9%A1%B5%E9%9D%A2"><?php echo '说明文档'; ?></a>
+ </p>
+ <?php if ($errormsg != ''): ?>
+ <p>这个报错信息可能会对你有用: <?php echo $errormsg; ?></p>
+ <?php endif; ?>
+ </div>
<?php endif; ?>
</div>
</div>
<br>
</div>
</div>
- <?php if(!$error && $bgmdataraw['data']['total']>12): ?>
- <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 endif;?>
+ <?php if (!$error && $bgmdataraw['data']['total'] > 12): ?>
+ <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 endif; ?>
<?php $this->need('includes/comments.php');
?>
</main>
|
