2021-01-21 10:41:21 +00:00
< ? php
2021-01-22 10:37:16 +00:00
2021-03-16 13:23:04 +00:00
/* 获取文章列表 已测试 √ */
2021-01-21 10:41:21 +00:00
function _getPost ( $self )
{
2021-05-20 01:27:35 +00:00
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-03-16 13:23:04 +00:00
2021-08-28 14:30:39 +00:00
$page = Typecho_Request :: getInstance () -> page ;
$pageSize = Typecho_Request :: getInstance () -> pageSize ;
$type = Typecho_Request :: getInstance () -> type ;
2021-03-16 13:23:04 +00:00
/* sql注入校验 */
if ( ! preg_match ( '/^\d+$/' , $page )) {
2021-08-28 14:30:39 +00:00
return Typecho_Response :: getInstance () -> throwJson ( array ( " data " => " 非法请求!已屏蔽! " ));
2021-03-16 13:23:04 +00:00
}
if ( ! preg_match ( '/^\d+$/' , $pageSize )) {
2021-08-28 14:30:39 +00:00
return Typecho_Response :: getInstance () -> throwJson ( array ( " data " => " 非法请求!已屏蔽! " ));
2021-03-16 13:23:04 +00:00
}
if ( ! preg_match ( '/^[created|views|commentsNum|agree]+$/' , $type )) {
2021-08-28 14:30:39 +00:00
return Typecho_Response :: getInstance () -> throwJson ( array ( " data " => " 非法请求!已屏蔽! " ));
2021-03-16 13:23:04 +00:00
}
/* 如果传入0, 强制赋值1 */
if ( $page == 0 ) $page = 1 ;
2021-01-21 10:41:21 +00:00
$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 ) {
2021-05-10 02:48:42 +00:00
$self -> widget ( 'Widget_Contents_Post@' . $cid , 'cid=' . $cid ) -> to ( $item );
2021-03-19 04:26:48 +00:00
if ( $item -> next ()) {
$result [] = array (
" mode " => $item -> fields -> mode ? $item -> fields -> mode : 'default' ,
" image " => _getThumbnails ( $item ),
" 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-27 11:01:49 +00:00
}
}
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 (
2021-02-11 04:46:01 +00:00
" mode " => $item -> fields -> mode ? $item -> fields -> mode : 'default' ,
" image " => _getThumbnails ( $item ),
2021-01-21 10:41:21 +00:00
" 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-04-02 02:07:39 +00:00
" views " => number_format ( $item -> views ),
2021-01-21 10:41:21 +00:00
" commentsNum " => number_format ( $item -> commentsNum ),
2021-04-02 02:07:39 +00:00
" agree " => number_format ( $item -> agree ),
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
);
};
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array ( " data " => $result ));
2021-01-21 10:41:21 +00:00
}
2021-01-22 10:37:16 +00:00
2021-03-16 13:23:04 +00:00
/* 增加浏览量 已测试 √ */
2021-01-23 08:15:02 +00:00
function _handleViews ( $self )
{
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-08-28 14:30:39 +00:00
$cid = Typecho_Request :: getInstance () -> cid ;
2021-03-16 13:23:04 +00:00
/* sql注入校验 */
if ( ! preg_match ( '/^\d+$/' , $cid )) {
2021-08-28 14:30:39 +00:00
return Typecho_Response :: getInstance () -> throwJson ( array ( " code " => 0 , " data " => " 非法请求!已屏蔽! " ));
2021-03-16 13:23:04 +00:00
}
2021-01-23 08:15:02 +00:00
$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 ));
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array (
2021-01-23 08:15:02 +00:00
" code " => 1 ,
2021-04-02 02:07:39 +00:00
" data " => array ( 'views' => number_format ( $db -> fetchRow ( $db -> select ( 'views' ) -> from ( 'table.contents' ) -> where ( 'cid = ?' , $cid ))[ 'views' ]))
2021-01-23 08:15:02 +00:00
));
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array ( " code " => 0 , " data " => null ));
2021-01-23 08:15:02 +00:00
}
}
2021-03-16 13:23:04 +00:00
/* 点赞和取消点赞 已测试 √ */
2021-01-23 08:15:02 +00:00
function _handleAgree ( $self )
{
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-08-28 14:30:39 +00:00
$cid = Typecho_Request :: getInstance () -> cid ;
$type = Typecho_Request :: getInstance () -> type ;
2021-03-16 13:23:04 +00:00
/* sql注入校验 */
if ( ! preg_match ( '/^\d+$/' , $cid )) {
2021-08-28 14:30:39 +00:00
return Typecho_Response :: getInstance () -> throwJson ( array ( " code " => 0 , " data " => " 非法请求!已屏蔽! " ));
2021-03-16 13:23:04 +00:00
}
/* sql注入校验 */
if ( ! preg_match ( '/^[agree|disagree]+$/' , $type )) {
2021-08-28 14:30:39 +00:00
return Typecho_Response :: getInstance () -> throwJson ( array ( " code " => 0 , " data " => " 非法请求!已屏蔽! " ));
2021-03-16 13:23:04 +00:00
}
2021-01-23 08:15:02 +00:00
$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 ));
}
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array (
2021-01-23 08:15:02 +00:00
" code " => 1 ,
2021-04-02 02:07:39 +00:00
" data " => array ( 'agree' => number_format ( $db -> fetchRow ( $db -> select ( 'agree' ) -> from ( 'table.contents' ) -> where ( 'cid = ?' , $cid ))[ 'agree' ]))
2021-01-23 08:15:02 +00:00
));
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array ( " code " => 0 , " data " => null ));
2021-01-23 08:15:02 +00:00
}
}
2021-03-16 13:23:04 +00:00
/* 查询是否收录 已测试 √ */
2021-01-22 10:37:16 +00:00
function _getRecord ( $self )
{
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-08-28 14:30:39 +00:00
$site = Typecho_Request :: getInstance () -> site ;
2021-01-22 10:37:16 +00:00
$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 );
2021-04-15 01:47:16 +00:00
curl_setopt ( $ch , CURLOPT_REFERER , " https://www.baidu.com/s?ie=UTF-8&wd= { $site } " );
2021-01-22 10:37:16 +00:00
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 , " 抱歉没有找到 " )) {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array ( " data " => " 未收录 " ));
2021-01-22 10:37:16 +00:00
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array ( " data " => " 已收录 " ));
2021-01-22 10:37:16 +00:00
}
2021-01-26 13:41:01 +00:00
}
2021-03-16 13:23:04 +00:00
/* 主动推送到百度收录 已测试 √ */
2021-01-26 13:41:01 +00:00
function _pushRecord ( $self )
{
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-04-30 09:50:30 +00:00
$token = Helper :: options () -> JBaiduToken ;
2021-08-28 14:30:39 +00:00
$domain = Typecho_Request :: getInstance () -> domain ;
$url = Typecho_Request :: getInstance () -> url ;
2021-01-26 13:41:01 +00:00
$urls = explode ( " , " , $url );
2021-04-30 09:50:30 +00:00
$api = " http://data.zz.baidu.com/urls?site= { $domain } &token= { $token } " ;
2021-01-26 13:41:01 +00:00
$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 );
2021-04-30 09:50:30 +00:00
curl_close ( $ch );
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array (
2021-04-30 09:50:30 +00:00
'domain' => $domain ,
'url' => $url ,
'data' => json_decode ( $result , TRUE )
));
2021-01-26 13:41:01 +00:00
}
2021-01-28 11:30:39 +00:00
2021-03-16 13:23:04 +00:00
/* 获取壁纸分类 已测试 √ */
2021-01-28 11:30:39 +00:00
function _getWallpaperType ( $self )
{
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
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 ) {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-01-28 11:30:39 +00:00
" code " => 1 ,
" data " => $res [ 'data' ]
]);
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-01-28 11:30:39 +00:00
" code " => 0 ,
" data " => null
]);
}
}
2021-03-16 13:23:04 +00:00
/* 获取壁纸列表 已测试 √ */
2021-01-28 11:30:39 +00:00
function _getWallpaperList ( $self )
{
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-08-28 14:30:39 +00:00
$cid = Typecho_Request :: getInstance () -> cid ;
$start = Typecho_Request :: getInstance () -> start ;
$count = Typecho_Request :: getInstance () -> 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 ) {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-01-28 11:30:39 +00:00
" code " => 1 ,
" data " => $res [ 'data' ],
" total " => $res [ 'total' ]
]);
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-01-28 11:30:39 +00:00
" code " => 0 ,
" data " => null
]);
}
}
2021-01-29 10:54:33 +00:00
2021-03-16 13:23:04 +00:00
/* 抓取苹果CMS视频分类 已测试 √ */
2021-01-29 10:54:33 +00:00
function _getMaccmsList ( $self )
{
2021-02-20 05:03:44 +00:00
header ( " HTTP/1.1 200 OK " );
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-01-29 10:54:33 +00:00
header ( " HTTP/1.1 200 OK " );
$cms_api = Helper :: options () -> JMaccmsAPI ;
2021-08-28 14:30:39 +00:00
$ac = Typecho_Request :: getInstance () -> ac ? Typecho_Request :: getInstance () -> ac : '' ;
$ids = Typecho_Request :: getInstance () -> ids ? Typecho_Request :: getInstance () -> ids : '' ;
$t = Typecho_Request :: getInstance () -> t ? Typecho_Request :: getInstance () -> t : '' ;
$pg = Typecho_Request :: getInstance () -> pg ? Typecho_Request :: getInstance () -> pg : '' ;
$wd = Typecho_Request :: getInstance () -> wd ? Typecho_Request :: getInstance () -> wd : '' ;
2021-01-29 10:54:33 +00:00
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-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-01-29 10:54:33 +00:00
" code " => 1 ,
" data " => $res ,
]);
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-01-29 10:54:33 +00:00
" code " => 0 ,
" data " => " 抓取失败!请联系作者! "
]);
}
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-01-29 10:54:33 +00:00
" code " => 0 ,
" data " => " 后台苹果CMS API未填写! "
]);
}
}
2021-02-02 10:25:32 +00:00
2021-03-16 13:23:04 +00:00
/* 获取虎牙视频列表 已测试 √ */
2021-02-02 10:25:32 +00:00
function _getHuyaList ( $self )
{
header ( " HTTP/1.1 200 OK " );
2021-02-20 05:03:44 +00:00
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-08-28 14:30:39 +00:00
$gameId = Typecho_Request :: getInstance () -> gameId ;
$page = Typecho_Request :: getInstance () -> page ;
2021-02-02 10:25:32 +00:00
$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 ) {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-02-02 10:25:32 +00:00
" code " => 1 ,
" data " => $res [ 'data' ],
]);
} else {
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-02-02 10:25:32 +00:00
" code " => 0 ,
" data " => " 抓取失败!请联系作者! "
]);
}
}
2021-05-20 01:27:35 +00:00
2021-05-21 09:27:27 +00:00
/* 获取服务器状态 */
2021-05-20 01:27:35 +00:00
function _getServerStatus ( $self )
{
header ( " HTTP/1.1 200 OK " );
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
$api_panel = Helper :: options () -> JBTPanel ;
$api_sk = Helper :: options () -> JBTKey ;
2021-08-28 14:30:39 +00:00
if ( ! $api_panel ) return Typecho_Response :: getInstance () -> throwJson ([
2021-05-20 01:27:35 +00:00
" code " => 0 ,
" data " => " 宝塔面板地址未填写! "
]);
2021-08-28 14:30:39 +00:00
if ( ! $api_sk ) return Typecho_Response :: getInstance () -> throwJson ([
2021-05-20 01:27:35 +00:00
" code " => 0 ,
" data " => " 宝塔接口密钥未填写! "
]);
$request_time = time ();
$request_token = md5 ( $request_time . '' . md5 ( $api_sk ));
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $api_panel . '/system?action=GetNetWork' );
2021-05-20 03:31:50 +00:00
curl_setopt ( $ch , CURLOPT_NOSIGNAL , 1 );
2021-05-20 10:39:18 +00:00
curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT_MS , 3000 );
curl_setopt ( $ch , CURLOPT_TIMEOUT_MS , 3000 );
2021-05-20 01:27:35 +00:00
curl_setopt ( $ch , CURLOPT_POST , 1 );
curl_setopt ( $ch , CURLOPT_POSTFIELDS , array ( " request_time " => $request_time , " request_token " => $request_token ));
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_HEADER , 0 );
curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST , false );
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , false );
$response = json_decode ( curl_exec ( $ch ), true );
curl_close ( $ch );
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( array (
2021-05-21 09:27:27 +00:00
/* 状态 */
" status " => $response ? true : false ,
2021-05-22 02:30:07 +00:00
/* 信息提示 */
2021-05-22 10:10:06 +00:00
" message " => $response [ 'msg' ],
2021-05-20 01:27:35 +00:00
/* 上行流量KB */
2021-05-20 10:39:18 +00:00
" up " => $response [ " up " ] ? $response [ " up " ] : 0 ,
2021-05-20 01:27:35 +00:00
/* 下行流量KB */
2021-05-20 10:39:18 +00:00
" down " => $response [ " down " ] ? $response [ " down " ] : 0 ,
2021-05-20 01:27:35 +00:00
/* 总发送(字节数) */
2021-05-20 10:39:18 +00:00
" upTotal " => $response [ " upTotal " ] ? $response [ " upTotal " ] : 0 ,
2021-05-20 01:27:35 +00:00
/* 总接收(字节数) */
2021-05-20 10:39:18 +00:00
" downTotal " => $response [ " downTotal " ] ? $response [ " downTotal " ] : 0 ,
2021-05-20 01:27:35 +00:00
/* 内存占用 */
2021-05-20 10:39:18 +00:00
" memory " => $response [ " mem " ] ? $response [ " mem " ] : [ " memBuffers " => 0 , " memCached " => 0 , " memFree " => 0 , " memRealUsed " => 0 , " memTotal " => 0 ],
2021-05-20 01:27:35 +00:00
/* CPU */
2021-05-20 10:39:18 +00:00
" cpu " => $response [ " cpu " ] ? $response [ " cpu " ] : [ 0 , 0 , [ 0 ], 0 , 0 , 0 ],
2021-05-20 01:27:35 +00:00
/* 系统负载 */
2021-05-20 10:39:18 +00:00
" load " => $response [ " load " ] ? $response [ " load " ] : [ " fifteen " => 0 , " five " => 0 , " limit " => 0 , " max " => 0 , " one " => 0 , " safe " => 0 ],
2021-05-20 01:27:35 +00:00
));
}
2021-05-20 10:39:18 +00:00
2021-05-21 09:27:27 +00:00
/* 获取最近评论 */
2021-05-20 10:39:18 +00:00
function _getCommentLately ( $self )
{
header ( " HTTP/1.1 200 OK " );
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
$time = time ();
$num = 7 ;
$categories = [];
$series = [];
$db = Typecho_Db :: get ();
$prefix = $db -> getPrefix ();
2021-05-21 01:05:45 +00:00
for ( $i = ( $num - 1 ); $i >= 0 ; $i -- ) {
$date = date ( " Y/m/d " , $time - ( $i * 24 * 60 * 60 ));
2021-05-20 10:39:18 +00:00
$sql = " SELECT coid FROM ` { $prefix } comments` WHERE FROM_UNIXTIME(created, '%Y/%m/%d') = ' { $date } ' limit 100 " ;
$count = count ( $db -> fetchAll ( $sql ));
$categories [] = $date ;
$series [] = $count ;
}
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ([
2021-05-20 10:39:18 +00:00
" categories " => $categories ,
2021-05-21 01:05:45 +00:00
" series " => $series ,
2021-05-20 10:39:18 +00:00
]);
}
2021-05-21 02:14:21 +00:00
2021-05-22 02:30:07 +00:00
/* 获取文章归档 */
2021-05-21 02:14:21 +00:00
function _getArticleFiling ( $self )
{
2021-05-21 09:27:27 +00:00
header ( " HTTP/1.1 200 OK " );
header ( 'Access-Control-Allow-Origin:*' );
header ( " Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept " );
2021-08-28 14:30:39 +00:00
$page = Typecho_Request :: getInstance () -> page ;
2021-05-21 09:27:27 +00:00
$pageSize = 8 ;
2021-08-28 14:30:39 +00:00
if ( ! preg_match ( '/^\d+$/' , $page )) return Typecho_Response :: getInstance () -> throwJson ( array ( " data " => " 非法请求!已屏蔽! " ));
2021-05-21 09:27:27 +00:00
if ( $page == 0 ) $page = 1 ;
$offset = $pageSize * ( $page - 1 );
$time = time ();
$db = Typecho_Db :: get ();
$prefix = $db -> getPrefix ();
$result = [];
$sql = " SELECT FROM_UNIXTIME(created, '%Y 年 %m 月') as date FROM ` { $prefix } contents` WHERE created < { $time } AND (password is NULL or password = '') AND status = 'publish' AND type = 'post' GROUP BY FROM_UNIXTIME(created, '%Y 年 %m 月') DESC LIMIT { $pageSize } OFFSET { $offset } " ;
$temp = $db -> fetchAll ( $sql );
$options = Typecho_Widget :: widget ( 'Widget_Options' );
foreach ( $temp as $item ) {
$date = $item [ 'date' ];
$list = [];
2021-05-22 02:30:07 +00:00
$sql = " SELECT * FROM ` { $prefix } contents` WHERE created < { $time } AND (password is NULL or password = '') AND status = 'publish' AND type = 'post' AND FROM_UNIXTIME(created, '%Y 年 %m 月') = ' { $date } ' ORDER BY created DESC LIMIT 100 " ;
2021-05-21 09:27:27 +00:00
$_list = $db -> fetchAll ( $sql );
foreach ( $_list as $_item ) {
$type = $_item [ 'type' ];
2021-08-28 14:30:39 +00:00
$_item [ 'categories' ] = $db -> fetchAll ( $db -> select () -> from ( 'table.metas' )
-> join ( 'table.relationships' , 'table.relationships.mid = table.metas.mid' )
-> where ( 'table.relationships.cid = ?' , $_item [ 'cid' ])
-> where ( 'table.metas.type = ?' , 'category' )
-> order ( 'table.metas.order' , Typecho_Db :: SORT_ASC ));
$_item [ 'category' ] = urlencode ( current ( Typecho_Common :: arrayFlatten ( $_item [ 'categories' ], 'slug' )));
$_item [ 'slug' ] = urlencode ( $_item [ 'slug' ]);
$_item [ 'date' ] = new Typecho_Date ( $_item [ 'created' ]);
$_item [ 'year' ] = $_item [ 'date' ] -> year ;
$_item [ 'month' ] = $_item [ 'date' ] -> month ;
$_item [ 'day' ] = $_item [ 'date' ] -> day ;
2021-05-21 09:27:27 +00:00
$routeExists = ( NULL != Typecho_Router :: get ( $type ));
$_item [ 'pathinfo' ] = $routeExists ? Typecho_Router :: url ( $type , $_item ) : '#' ;
$_item [ 'permalink' ] = Typecho_Common :: url ( $_item [ 'pathinfo' ], $options -> index );
$list [] = array (
" title " => date ( 'm/d' , $_item [ 'created' ]) . ': ' . $_item [ 'title' ],
" permalink " => $_item [ 'permalink' ],
);
}
$result [] = array ( " date " => $date , " list " => $list );
}
2021-08-28 14:30:39 +00:00
Typecho_Response :: getInstance () -> throwJson ( $result );
}