Skip to content

Commit

Permalink
Add Bangumi Page
Browse files Browse the repository at this point in the history
新增追番页面,免费提供!同时还有返回页眉、修改背景等新功能,欢迎尝试~
  • Loading branch information
Dreamer-Paul committed Feb 10, 2019
1 parent 8ddf2a4 commit 8af5679
Show file tree
Hide file tree
Showing 11 changed files with 544 additions and 85 deletions.
30 changes: 30 additions & 0 deletions bangumi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* 追番
*
* @package custom
*/

if (!defined('__TYPECHO_ROOT_DIR__')) exit;

$this->need('header.php');

?>
<main>
<div class="wrap min">
<section class="board">
<div class="post-title">
<h2><?php $this->title() ?></h2>
</div>
<article class="post-content exclude-img">
<div class="row">
<?php Fantasy::bangumi($this); ?>
</div>
</article>
</section>
<?php $this->need('comments.php'); ?>
</div>
</main>

<?php $this->need('footer.php'); ?>
4 changes: 2 additions & 2 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
?>

<div class="comment-item<?php echo $commentClass ?>" id="<?php $comments->theId(); ?>">
<?php $comments->gravatar('150', 'wavatar'); ?>
<?php $comments -> gravatar('150', 'wavatar'); ?>
<div class="content">
<div class="comment-meta">
<span class="comment-author"><?php $comments->author(); ?></span>
Expand Down Expand Up @@ -57,7 +57,7 @@
</div>
<?php if ($comments->have()): ?>
<?php $comments->listComments(array('before' => '<div class="comment-list">', 'after' => '</div>')); ?>
<?php $comments->pageNav('', ''); ?>
<?php $comments->pageNav('', '', 3, '...', array('wrapTag' => 'section', 'itemTag' => 'span')); ?>
<?php else: ?>
<p class="no-comment">还没有评论呢!</p>
<?php endif; ?>
Expand Down
91 changes: 91 additions & 0 deletions fantasy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

class Fantasy {
// HTTPS 转换
static function convert_https($url){
return preg_replace("/^http:/", "https:", $url);
}

// 追番
static function bangumi($t){
$uid = Typecho_Widget::widget('Widget_Options') -> bgm_user;
$uid = $uid ? $uid : 433599;
$bgm = file_get_contents("https://api.bgm.tv/user/" . $uid . "/collection?cat=playing");
$bgm = json_decode($bgm);

if($bgm){
foreach($bgm as $item){
$bid = $item -> subject -> id;
$name = $item -> subject -> name_cn ? $item -> subject -> name_cn : $item -> subject -> name;
$seem = $item -> ep_status;
$image = self::convert_https($item -> subject -> images -> large);
$total = property_exists($item -> subject, "eps_count") ? $item -> subject -> eps_count : $seem;
$width = (int)$seem / $total * 100;
?>
<div class="col-6 col-m-4">
<a class="bangumi-item" target="_blank" href="https://bgm.tv/subject/<?php echo $bid ?>">
<div class="bangumi-img" style="background-image: url(<?php echo $image ?>)">
<div class="bangumi-status">
<div class="bangumi-status-bar" style="width: <?php echo $width ?>%"></div>
<p>进度:<?php echo $seem ?> / <?php echo $total ?></p>
</div>
</div>
<h3><?php echo $name ?></h3>
</a>
</div>
<?php
}
}
else{
?>
<div class="col-12">
<p>追番数据获取失败,请检查如下细节:</p>
<ul>
<li>用户 ID 是否正确?</li>
<li>该用户是否在“在看”添加了番剧?</li>
<li>服务器能否正常连接 <code>api.bgm.tv</code> ?</li>
</ul>
</div>
<?php
}

unset($bid, $name, $seem, $total, $img, $width);
}

// 时间转换
static function tran_time($ts){
$dur = time() - $ts;

if($dur < 0){
return $ts;
}
else if($dur < 60){
return $dur . ' 秒前';
}
else if($dur < 3600){
return floor($dur / 60) . ' 分钟前';
}
else if($dur < 86400){
return floor($dur / 3600) . ' 小时前';
}
else if($dur < 604800){ // 七天内
return floor($dur / 86400) . ' 天前';
}
else if($dur < 2592000){ // 一个月内
return floor($dur / 604800) . " 周前";
}

else{
return date("y.m.d", $ts);
}
}

// 上次登录
static function get_last_login(){
$db = Typecho_Db::get();
$query = $db -> select() -> from('table.users');
$logged = $db -> fetchRow($query)["logged"];

return self::tran_time($logged);
}
}
7 changes: 6 additions & 1 deletion footer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<footer>
<div class="wrap mid">
<section class="foot-action">
<div class="to-top"></div>
</section>
<section class="foot-widget">
<div class="row">
<div class="col-m-3">
Expand All @@ -19,7 +22,7 @@
<div class="foot-comments">
<?php $this -> widget('Widget_Comments_Recent', 'pageSize=5') -> to($comments); ?>
<?php while($comments -> next()): ?>
<a href="<?php $comments -> permalink(); ?>" rel="nofollow" target="_blank"><img src="<?php echo Typecho_Common::gravatarUrl($comments -> mail, 32, 'X', 'wavatar') ?>"/><?php $comments -> excerpt(10, '...'); ?></a>
<a href="<?php $comments -> permalink(); ?>" rel="nofollow" target="_blank"><img src="<?php echo Typecho_Common::gravatarUrl($comments -> mail, 32, 'X', 'wavatar', $this -> request -> isSecure()) ?>"/><?php $comments -> author(false); ?><?php $comments -> excerpt(10, '...'); ?></a>
<?php endwhile; ?>
</div>
</div>
Expand All @@ -31,6 +34,8 @@
<li>分类:<?php $stat->categoriesNum() ?> 个</li>
<li>评论:<?php $stat->publishedCommentsNum() ?> 条</li>
<li>页面:<?php $stat->publishedPagesNum() ?> 个</li>
<li>上次更新:<?php echo Fantasy::tran_time($this -> modified) ?></li>
<li>上次登录:<?php echo Fantasy::get_last_login() ?></li>
</ul>
</div>
</div>
Expand Down
12 changes: 11 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

require_once("fantasy.php");

function themeConfig($form) {

// 插件信息与更新检测
Expand All @@ -20,12 +22,16 @@ function paul_update($name, $version){

echo "</div>";
}
paul_update("Fantasy", "1.2");
paul_update("Fantasy", "1.3");

// 自定义站点图标
$favicon = new Typecho_Widget_Helper_Form_Element_Text('favicon', NULL, NULL, _t('站点图标'), _t('在这里填入一张 png 图片地址(<a>192x192px</a>),不填则使用默认图标'));
$form -> addInput($favicon);

// 自定义背景图
$background = new Typecho_Widget_Helper_Form_Element_Text('background', NULL, NULL, _t('站点背景'), _t('在这里填入一张图片地址,不填则显示默认背景'));
$form->addInput($background);

// 自定义社交链接
$home_social = new Typecho_Widget_Helper_Form_Element_Textarea('home_social', NULL, NULL, _t('自定义社交链接'), _t('在这里填入你的自定义社交链接,不填则不输出。(格式请看<a href="https://github.com/Dreamer-Paul/Single/releases/tag/1.1" target="_blank">帮助信息</a>)'));
$form -> addInput($home_social);
Expand All @@ -46,6 +52,10 @@ function paul_update($name, $version){
$verify_num = new Typecho_Widget_Helper_Form_Element_Text('verify_num', NULL, '', _t('备案号'), _t('在这里填入一个备案号,不填则无法输出'));
$form -> addInput($verify_num);

// 追番用户 ID
$bgm_user = new Typecho_Widget_Helper_Form_Element_Text('bgm_user', NULL, '', _t('追番用户 ID'), _t('在这里填入一个 <a>bangumi.tv</a> 的用户 ID,用于追番页面的输出,不填则输出作者的追番记录'));
$form -> addInput($bgm_user);

// 页尾展示内容
$footer_content = new Typecho_Widget_Helper_Form_Element_Checkbox('footer_content',
array(
Expand Down
29 changes: 16 additions & 13 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@
<html lang="zh-cmn-hans">
<head>
<meta charset="UTF-8">
<title><?php $this->archiveTitle(array(
<title><?php $this -> archiveTitle(array(
'category' => _t('%s'),
'search' => _t('含关键词 %s 的文章'),
'tag' => _t('标签 %s 下的文章'),
'author' => _t('%s 发布的文章')
), '', ' - '); $this->options->title(); ?></title>
<?php if ($this->options->favicon): ?>
<link rel="icon" href="<?php $this->options->favicon() ?>" sizes="192x192"/>
), '', ' - '); $this -> options -> title(); ?></title>
<?php if($this -> options -> favicon): ?>
<link rel="icon" href="<?php $this -> options -> favicon() ?>" sizes="192x192"/>
<?php else: ?>
<link rel="icon" href="<?php $this->options->themeUrl('static/img/icon.png'); ?>" sizes="192x192"/>
<link rel="icon" href="<?php $this -> options -> themeUrl('static/img/icon.png'); ?>" sizes="192x192"/>
<?php endif; ?>
<link href="<?php $this->options->themeUrl('static/kico.css'); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php $this->options->themeUrl('static/fantasy.css'); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php $this -> options -> themeUrl('static/kico.css'); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php $this -> options -> themeUrl('static/fantasy.css'); ?>" rel="stylesheet" type="text/css"/>
<link href="https://cdn.jsdelivr.net/gh/FortAwesome/Font-Awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1"/>
<?php $this->header('generator=&template=&pingback=&xmlrpc=&wlw='); ?>
<?php if ($this->options->custom_css): ?>
<style><?php $this->options->custom_css() ?></style>
<?php if($this -> options -> background): ?>
<style>body{ background: url(<?php $this -> options -> background() ?>) center/cover fixed }</style>
<?php endif; ?>
<?php if($this -> options -> custom_css): ?>
<style><?php $this -> options -> custom_css() ?></style>
<?php endif; ?>
</head>
<body>
<aside>
<nav class="side-nav">
<a href="<?php $this->options->siteUrl() ?>">首页</a>
<?php $this->widget('Widget_Contents_Page_List')->parse('<a href="{permalink}">{title}</a>'); ?>
<a href="<?php $this -> options -> siteUrl() ?>">首页</a>
<?php $this -> widget('Widget_Contents_Page_List') -> parse('<a href="{permalink}">{title}</a>'); ?>
<?php if($this -> user -> hasLogin()): ?>
<a href="<?php $this -> options -> adminUrl() ?>" target="_blank">进入后台</a>
<a href="<?php $this -> options -> adminUrl() ?>" target="_blank">进入后台</a>
<?php endif; ?>
</nav>
<nav class="side-action">
Expand All @@ -40,7 +43,7 @@
<input type="text" name="s" placeholder="搜索什么?">
</form>
<div class="side-category color-bar">
<?php $this->widget('Widget_Metas_Category_List')->parse('<a href="{permalink}">{name}</a>'); ?>
<?php $this -> widget('Widget_Metas_Category_List') -> parse('<a href="{permalink}">{name}</a>'); ?>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @package Fantasy Theme
* @author Dreamer-Paul
* @version 1.2
* @version 1.3
* @link https://paugram.com
*/

Expand All @@ -24,7 +24,7 @@
</div>
<?php endwhile; ?>
</section>
<?php $this->pageNav('', ''); ?>
<?php $this->pageNav('', '', 3, '...', array('wrapTag' => 'section', 'itemTag' => 'span')); ?>
</div>
</main>

Expand Down
Loading

0 comments on commit 8af5679

Please sign in to comment.