├── Action.php
├── Plugin.php
├── README.md
├── css
└── css.css
└── js
└── js.js
/Action.php:
--------------------------------------------------------------------------------
1 | userName = $_userName;
51 | $this->passWord = $_passWord;
52 | //登陆api
53 | $this->loginApi = BangumiAPI::$apiUrl . "/auth?source=" . BangumiAPI::$appName;
54 | //用户id为空或auth为空
55 | if ($this->userID == "" || $this->authEncode == ""){
56 | //登陆post字符串
57 | $postData = array('username' => $this->userName , 'password' => $this->passWord);
58 | //获取登陆返回json
59 | $userContent = BangumiAPI::curl_post_contents($this->loginApi,$postData);
60 | //json to object
61 | $userData = json_decode($userContent);
62 | //存在error属性
63 | if (property_exists($userData, "error")) {
64 | //输出错误信息
65 | echo "登陆错误:" . $userData->error;
66 | //程序返回
67 | return;
68 | }
69 | //初始化
70 | $this->userID = $userData->id;
71 | $this->auth = $userData ->auth;
72 | $this->authEncode = $userData ->auth_encode;
73 | }
74 | //初始化收藏字符串
75 | $this->collectionApi = BangumiAPI::$apiUrl . "/user/" . $this->userID ."/collection?cat=playing";
76 | }
77 | //获取收藏json
78 | public function GetCollection()
79 | {
80 | if ($this->userID == "" || $this->collectionApi == "") {
81 | return null;
82 | }
83 | return BangumiAPI::curl_get_contents($this->collectionApi);
84 | }
85 | //格式化收藏
86 | public function ParseCollection()
87 | {
88 | $content = $this->GetCollection();
89 | if ($content == null || $content == "") {
90 | echo "获取失败";
91 | return;
92 | }
93 | //返回不是json
94 | if (strpos($content, "[{") != false && $content != "") {
95 | echo "用户不存在!";
96 | return;
97 | }
98 | $collData = json_decode($content);
99 | if (sizeof($collData) == 0 || $collData == null) {
100 | //echo "还没有记录哦~";
101 | return;
102 | }
103 | $index = 0;
104 | foreach ($collData as $value) {
105 | $name = $value->name;
106 | $name_cn = $value->subject->name_cn;
107 | $theurl = $value->subject->url;
108 | $img_grid =$value->subject->images->grid;
109 | $this->myCollection[$index++] = $value;
110 | }
111 | }
112 | //获取详细进度
113 | public function GetProgress($_subjectID)
114 | {
115 | if ($this->authEncode == "" || $this->userID == "") {
116 | return null;
117 | }
118 | $progressApi = BangumiAPI::$apiUrl . "/user/" . $this->userID . "/progress?subject_id=". $_subjectID . "&source=" . self::$appName . "&auth=" . authEncode;
119 | $content = BangumiAPI::curl_get_contents($progressApi);
120 | //print_r($content);
121 | return $content;
122 | }
123 | public function ParseProgress($_subjectID)
124 | {
125 | $content = $this->GetProgress($_subjectID);
126 | //不在收藏或没看过
127 | if ($content == "null") {
128 | return 0;
129 | }
130 | //在收藏中,没看过
131 | if ($content == "") {
132 | return 0;
133 | }
134 | $progressValue = json_decode($content);
135 | //返回剧集观看详细进度
136 | return $progressValue;
137 | }
138 | //打印收藏
139 | public function PrintCollecion($flag = true)
140 | {
141 | if ($this->myCollection == null) {
142 | $this->ParseCollection();
143 | }
144 | switch ($flag) {
145 | case true:
146 | if (sizeof($this->myCollection) == 0 || $this->myCollection == null) {
147 | echo "还没有记录哦~";
148 | return;
149 | }
150 | echo "
151 |
224 | ";
225 | foreach ($this->myCollection as $value) {
226 | //print_r($value);
227 | //$id = $value->subject->id;
228 | $epsNum = '未知';
229 | if(@$value->subject->eps){
230 | $epsNum = $value->subject->eps;
231 | }
232 | $progressNum = $value->ep_status;
233 | $myProgress = $progressNum . "/" . $epsNum;
234 | $name = $value->name;
235 | $name_cn = $value->subject->name_cn;
236 | if(@!$name_cn){
237 | $name_cn = $name;
238 | }
239 | $air_date = $value->subject->air_date;
240 | $theurl = $value->subject->url;
241 | $img_grid =str_replace("http://", "https://", $value->subject->images->common);
242 | $progressWidth = 0;
243 | if($epsNum=='未知'){
244 | $progressWidth = 100;
245 | }else{
246 | $progressWidth = $progressNum / $epsNum * 100;
247 | if($progressWidth>100){
248 | $progressWidth = 100;
249 | }
250 | }
251 | echo "
252 |
253 |
254 |
255 | $name
256 | 首播日期:$air_date
257 |
";
278 | $myCurl = curl_init($_url);
279 | //不验证证书
280 | curl_setopt($myCurl, CURLOPT_SSL_VERIFYPEER, false);
281 | curl_setopt($myCurl, CURLOPT_SSL_VERIFYHOST, false);
282 | curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, true);
283 | curl_setopt($myCurl, CURLOPT_HEADER, false);
284 | //获取
285 | $content = curl_exec($myCurl);
286 | //关闭
287 | curl_close($myCurl);
288 | return $content;
289 | }
290 | //post获取内容
291 | private static function curl_post_contents($_url,$_postdata)
292 | {
293 | //echo "The POST Url You Request is " . $_url . "
";
294 | $myCurl = curl_init($_url);
295 | //不验证证书
296 | curl_setopt($myCurl, CURLOPT_SSL_VERIFYPEER, false);
297 | curl_setopt($myCurl, CURLOPT_SSL_VERIFYHOST, false);
298 | curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, true);
299 | curl_setopt($myCurl, CURLOPT_POST, 1);
300 | curl_setopt($myCurl, CURLOPT_POSTFIELDS, $_postdata);
301 | $output = curl_exec($myCurl);
302 | curl_close($myCurl);
303 | return $output;
304 | }
305 | }
306 |
307 | class WikimoeBangumi_Action extends Widget_Abstract_Contents implements Widget_Interface_Do
308 | {
309 |
310 | public function action()
311 | {
312 | $options = Helper::options();
313 | $userID = $options->plugin('WikimoeBangumi')->userID;
314 | $password = $options->plugin('WikimoeBangumi')->password;
315 |
316 | $bangum = BangumiAPI::GetInstance();
317 | $bangum->init($userID,$password);
318 | $bangum->ParseCollection();
319 | $bangum->PrintCollecion(true);
320 | }
321 | }
--------------------------------------------------------------------------------
/Plugin.php:
--------------------------------------------------------------------------------
1 | header = array('WikimoeBangumi_Plugin', 'header');
22 | //Typecho_Plugin::factory('Widget_Archive')->footer = array('WikimoeBangumi_Plugin', 'footer');
23 | Helper::addRoute("route_WikimoeBangumi","/WikimoeBangumi","WikimoeBangumi_Action",'action');
24 | //Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('WikimoeBangumi_Plugin', 'setak');
25 | //Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('WikimoeBangumi_Plugin', 'setak');
26 | }
27 |
28 | /**
29 | * 禁用插件方法,如果禁用失败,直接抛出异常
30 | *
31 | * @static
32 | * @access public
33 | * @return void
34 | * @throws Typecho_Plugin_Exception
35 | */
36 | public static function deactivate(){
37 | Helper::removeRoute("route_WikimoeBangumi");
38 | }
39 |
40 | /**
41 | * 获取插件配置面板
42 | *
43 | * @access public
44 | * @param Typecho_Widget_Helper_Form $form 配置面板
45 | * @return void
46 | */
47 | public static function config(Typecho_Widget_Helper_Form $form)
48 | {
49 | /**表单设置 */
50 | $userID = new Typecho_Widget_Helper_Form_Element_Text('userID', NULL, NULL, _t('输入Bangumi账号'));
51 | $form->addInput($userID);
52 | $password = new Typecho_Widget_Helper_Form_Element_Password('password', NULL, NULL, _t('输入Bangumi密码(推荐设置成不是常用的密码)'));
53 | $form->addInput($password);
54 | }
55 |
56 | /**
57 | * 个人用户的配置面板
58 | *
59 | * @access public
60 | * @param Typecho_Widget_Helper_Form $form
61 | * @return void
62 | */
63 |
64 | /**
65 | * 页头输出CSS
66 | *
67 | * @access public
68 | * @param unknown header
69 | * @return unknown
70 | */
71 | public static function header() {
72 | $Path = Helper::options()->pluginUrl . '/WikimoeBangumi/';
73 | echo '';
74 | }
75 |
76 | public static function footer() {
77 | $Path = Helper::options()->pluginUrl . '/WikimoeBangumi/';
78 | echo '';
79 | }
80 |
81 | public static function personalConfig(Typecho_Widget_Helper_Form $form){}
82 |
83 | public static function output()
84 | {
85 | $Path = Helper::options()->pluginUrl . '/WikimoeBangumi/';
86 | echo '';
87 | echo '