Jony/core/route.php

265 lines
9.6 KiB
PHP
Raw Normal View History

2021-01-21 10:41:21 +00:00
<?php
2021-01-22 10:37:16 +00:00
2021-01-26 13:41:01 +00:00
/* 侧边栏热门排行榜 */
2021-01-21 10:41:21 +00:00
function _getRanking($self)
{
header("HTTP/1.1 200 OK");
$ranking_txt = Helper::options()->JAside_Ranking;
$ranking_arr = explode("$", $ranking_txt);
2021-02-07 03:32:41 +00:00
$json = _curl("https://rank.the.top/v1/{$ranking_arr[1]}/1/9");
2021-01-21 10:41:21 +00:00
$res = json_decode($json, TRUE);
if ($res['code'] === 0) {
$self->response->throwJson([
"code" => 1,
"title" => $ranking_arr[0],
"data" => $res["data"]
]);
} else {
$self->response->throwJson([
"code" => 0,
"title" => $ranking_arr[0],
"data" => null
]);
}
}
2021-01-26 13:41:01 +00:00
/* 获取文章列表 */
2021-01-21 10:41:21 +00:00
function _getPost($self)
{
header("HTTP/1.1 200 OK");
$page = $self->request->page;
$pageSize = $self->request->pageSize;
$type = $self->request->type;
$result = [];
2021-01-27 11:01:49 +00:00
/* 增加置顶文章功能通过JS判断如果你想添加其他标签的话请先看置顶如何实现的 */
$sticky_text = Helper::options()->JIndexSticky;
if ($sticky_text && $page == 1) {
$sticky_arr = explode("||", $sticky_text);
foreach ($sticky_arr as $cid) {
$self->widget('Widget_Archive@' . $cid, 'pageSize=1&type=post', 'cid=' . $cid)->to($item);
$result[] = array(
"image" => _getThumbnail($item, false),
"time" => date('Y-m-d', $item->created),
"created" => date('Y年m月d日', $item->created),
"title" => $item->title,
"abstract" => _getAbstract($item, false),
"category" => $item->categories,
"views" => _getViews($item, false),
"commentsNum" => number_format($item->commentsNum),
"agree" => _getAgree($item, false),
"permalink" => $item->permalink,
"lazyload" => _getLazyload(false),
"type" => "sticky"
);
}
}
2021-01-21 10:41:21 +00:00
$self->widget('Widget_Contents_Sort', 'page=' . $page . '&pageSize=' . $pageSize . '&type=' . $type)->to($item);
while ($item->next()) {
$result[] = array(
"image" => _getThumbnail($item, false),
"time" => date('Y-m-d', $item->created),
"created" => date('Y年m月d日', $item->created),
2021-01-26 13:41:01 +00:00
"title" => $item->title,
2021-01-21 10:41:21 +00:00
"abstract" => _getAbstract($item, false),
"category" => $item->categories,
2021-01-23 08:15:02 +00:00
"views" => _getViews($item, false),
2021-01-21 10:41:21 +00:00
"commentsNum" => number_format($item->commentsNum),
2021-01-23 08:15:02 +00:00
"agree" => _getAgree($item, false),
2021-01-21 10:41:21 +00:00
"permalink" => $item->permalink,
2021-01-27 11:01:49 +00:00
"lazyload" => _getLazyload(false),
"type" => "normal"
2021-01-21 10:41:21 +00:00
);
};
$self->response->throwJson(array("data" => $result));
}
2021-01-22 10:37:16 +00:00
2021-01-26 13:41:01 +00:00
/* 增加浏览量 */
2021-01-23 08:15:02 +00:00
function _handleViews($self)
{
header("HTTP/1.1 200 OK");
$cid = $self->request->cid;
$db = Typecho_Db::get();
$row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid));
if (sizeof($row) > 0) {
$db->query($db->update('table.contents')->rows(array('views' => (int)$row['views'] + 1))->where('cid = ?', $cid));
$self->response->throwJson(array(
"code" => 1,
"data" => $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid))
));
} else {
$self->response->throwJson(array("code" => 0, "data" => null));
}
}
2021-01-26 13:41:01 +00:00
/* 点赞和取消点赞 */
2021-01-23 08:15:02 +00:00
function _handleAgree($self)
{
header("HTTP/1.1 200 OK");
$cid = $self->request->cid;
$type = $self->request->type;
$db = Typecho_Db::get();
$row = $db->fetchRow($db->select('agree')->from('table.contents')->where('cid = ?', $cid));
if (sizeof($row) > 0) {
if ($type === "agree") {
$db->query($db->update('table.contents')->rows(array('agree' => (int)$row['agree'] + 1))->where('cid = ?', $cid));
} else {
$db->query($db->update('table.contents')->rows(array('agree' => (int)$row['agree'] - 1))->where('cid = ?', $cid));
}
$self->response->throwJson(array(
"code" => 1,
"data" => $db->fetchRow($db->select('agree')->from('table.contents')->where('cid = ?', $cid))
));
} else {
$self->response->throwJson(array("code" => 0, "data" => null));
}
}
2021-01-26 13:41:01 +00:00
/* 查询是否收录 */
2021-01-22 10:37:16 +00:00
function _getRecord($self)
{
header("HTTP/1.1 200 OK");
$site = $self->request->site;
$encryption = md5(mt_rand(1655, 100860065) . time());
$baiduSite = "https://www.baidu.com/s?ie=utf-8&newi=1&mod=1&isid={$encryption}&wd={$site}&rsv_spt=1&rsv_iqid={$encryption}&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=0&rsv_dl=ib&rsv_sug3=2&rsv_sug1=1&rsv_sug7=001&rsv_n=2&rsv_btype=i&inputT=3083&rsv_sug4=3220&rsv_sug=9&rsv_sid=32818_1460_33042_33060_31660_33099_33101_32961_26350_22159&_ss=1&clist=&hsug=&f4s=1&csor=38&_cr1=32951";
2021-01-25 15:03:09 +00:00
$ip = mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255) . '.' . mt_rand(0, 255);
2021-01-22 10:37:16 +00:00
$header[] = "accept-encoding: gzip, deflate";
$header[] = "accept-language: en-US,en;q=0.8";
$header[] = "CLIENT-IP:" . $ip;
$header[] = "X-FORWARDED-FOR:" . $ip;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baiduSite);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_REFERER, "https://www.baidu.com/s?ie=UTF-8&wd={$url}");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$output = curl_exec($ch);
curl_close($ch);
$res = str_replace([' ', "\n", "\r"], '', $output);
if (strpos($res, "抱歉,没有找到与") || strpos($res, "找到相关结果约0个") || strpos($res, "没有找到该URL") || strpos($res, "抱歉没有找到")) {
$self->response->throwJson(array("data" => "未收录"));
} else {
$self->response->throwJson(array("data" => "已收录"));
}
2021-01-26 13:41:01 +00:00
}
/* 主动推送到百度收录 */
function _pushRecord($self)
{
header("HTTP/1.1 200 OK");
$domain = $self->request->domain;
$url = $self->request->url;
$token = Helper::options()->JBaiduToken;
$urls = explode(",", $url);
$api = 'http://data.zz.baidu.com/urls?site=' . $domain . '&token=' . $token;
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$self->response->throwJson(json_decode($result));
}
2021-01-28 11:30:39 +00:00
/* 获取壁纸分类 */
function _getWallpaperType($self)
{
header("HTTP/1.1 200 OK");
2021-02-01 10:11:49 +00:00
$json = _curl("http://cdn.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome");
2021-01-28 11:30:39 +00:00
$res = json_decode($json, TRUE);
if ($res['errno'] == 0) {
$self->response->throwJson([
"code" => 1,
"data" => $res['data']
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => null
]);
}
}
/* 获取壁纸列表 */
function _getWallpaperList($self)
{
header("HTTP/1.1 200 OK");
$cid = $self->request->cid;
$start = $self->request->start;
$count = $self->request->count;
2021-02-01 10:11:49 +00:00
$json = _curl("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid={$cid}&start={$start}&count={$count}&from=360chrome");
2021-01-28 11:30:39 +00:00
$res = json_decode($json, TRUE);
if ($res['errno'] == 0) {
$self->response->throwJson([
"code" => 1,
"data" => $res['data'],
"total" => $res['total']
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => null
]);
}
}
2021-01-29 10:54:33 +00:00
/* 抓取苹果CMS视频分类 */
function _getMaccmsList($self)
{
header("HTTP/1.1 200 OK");
$cms_api = Helper::options()->JMaccmsAPI;
$ac = $self->request->ac ? $self->request->ac : '';
$ids = $self->request->ids ? $self->request->ids : '';
$t = $self->request->t ? $self->request->t : '';
$pg = $self->request->pg ? $self->request->pg : '';
$wd = $self->request->wd ? $self->request->wd : '';
if ($cms_api) {
2021-02-01 10:11:49 +00:00
$json = _curl("{$cms_api}?ac={$ac}&ids={$ids}&t={$t}&pg={$pg}&wd={$wd}");
2021-01-29 10:54:33 +00:00
$res = json_decode($json, TRUE);
2021-01-30 07:04:20 +00:00
if ($res['code'] === 1) {
2021-01-29 10:54:33 +00:00
$self->response->throwJson([
"code" => 1,
"data" => $res,
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => "抓取失败!请联系作者!"
]);
}
} else {
$self->response->throwJson([
"code" => 0,
"data" => "后台苹果CMS API未填写"
]);
}
}
2021-02-02 10:25:32 +00:00
/* 获取虎牙视频列表 */
function _getHuyaList($self)
{
header("HTTP/1.1 200 OK");
$gameId = $self->request->gameId;
$page = $self->request->page;
$json = _curl("https://www.huya.com/cache.php?m=LiveList&do=getLiveListByPage&gameId={$gameId}&tagAll=0&page={$page}");
$res = json_decode($json, TRUE);
if ($res['status'] === 200) {
$self->response->throwJson([
"code" => 1,
"data" => $res['data'],
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => "抓取失败!请联系作者!"
]);
}
}