style: format api.php

pull/212/head
Spirit 2020-04-02 11:59:52 +08:00
parent f1981117b5
commit f5c53f2224
7 changed files with 54 additions and 46 deletions

View File

@ -278,45 +278,68 @@ function cache_search_json()
/<\/?[a-zA-Z]+("[^"]*"|'[^']*'|[^'">])*>|begin[\S\s]*\/begin|hermit[\S\s]*\/hermit|img[\S\s]*\/img|{{.*?}}|:.*?:/m
EOS;
$more = 1;
$output = array();
$posts = new WP_Query('posts_per_page=-1&post_status=publish&post_type=post');
while ($posts->have_posts()): $posts->the_post();
$output .= '{"type":"post","link":"' . get_permalink() . '","title":' . json_encode(get_the_title()) . ',"comments":"' . get_comments_number('0', '1', '%') . '","text":' . json_encode(str_replace($vowels, " ", preg_replace($regex, ' ', apply_filters( 'the_content', get_the_content())))) . '},';
$output[] = array(
"type" => "post",
"link" => get_permalink(),
"title" => get_the_title(),
"comments" => get_comments_number('0', '1', '%'),
"text" => str_replace($vowels, " ", preg_replace($regex, ' ', apply_filters( 'the_content', get_the_content())))
);
endwhile;
wp_reset_postdata();
$pages = new WP_Query('posts_per_page=-1&post_status=publish&post_type=page');
while ($pages->have_posts()): $pages->the_post();
$output .= '{"type":"page","link":"' . get_permalink() . '","title":' . json_encode(get_the_title()) . ',"comments":"' . get_comments_number('0', '1', '%') . '","text":' . json_encode(str_replace($vowels, " ", preg_replace($regex, ' ', apply_filters( 'the_content', get_the_content())))) . '},';
$output[] = array(
"type" => "page",
"link" => get_permalink(),
"title" => get_the_title(),
"comments" => get_comments_number('0', '1', '%'),
"text" => str_replace($vowels, " ", preg_replace($regex, ' ', apply_filters( 'the_content', get_the_content())))
);
endwhile;
wp_reset_postdata();
$tags = get_tags();
foreach ($tags as $tag) {
$output .= '{"type":"tag","link":"' . get_term_link($tag) . '","title":' . json_encode($tag->name) . ',"comments":"","text":""},';
$output[] = array(
"type" => "tag",
"link" => get_term_link($tag),
"title" => $tag->name,
"comments" => "",
"text" => ""
);
}
$categories = get_categories();
foreach ($categories as $category) {
$output .= '{"type":"category","link":"' . get_term_link($category) . '","title":' . json_encode($category->name) . ',"comments":"","text":""},';
$output[] = array(
"type" => "category",
"link" => get_term_link($category),
"title" => $category->name,
"comments" => "",
"text" => ""
);
}
if (akina_option('live_search_comment')) {
$comments = get_comments();
foreach ($comments as $comment) {
$is_private = get_comment_meta($comment->comment_ID, '_private', true);
if ($is_private) {
$output .= '{"type":"comment","link":"' . get_comment_link($comment) . '","title":' . json_encode(get_the_title($comment->comment_post_ID)) . ',"comments":"","text":' . json_encode($comment->comment_author . "" . __("The comment is private", "sakura") /*该评论为私密评论*/) . '},';
continue;
} else {
$output .= '{"type":"comment","link":"' . get_comment_link($comment) . '","title":' . json_encode(get_the_title($comment->comment_post_ID)) . ',"comments":"","text":' . json_encode(str_replace($vowels, " ", preg_replace($regex, " ", $comment->comment_author . "" . $comment->comment_content))) . '},';
}
$output[] = array(
"type" => "comment",
"link" => get_comment_link($comment),
"title" => get_the_title($comment->comment_post_ID),
"comments" => "",
"text" => $is_private ? ($comment->comment_author . ": " . __('The comment is private', 'sakura')) : str_replace($vowels, ' ', preg_replace($regex, ' ', $comment->comment_author . "" . $comment->comment_content))
);
}
}
$output = substr($output, 0, strlen($output) - 1);
$data = '[' . $output . ']';
$result = new WP_REST_Response(json_decode($data), 200);
$result = new WP_REST_Response($output, 200);
$result->set_headers(
array(
'Content-Type' => 'application/json',
@ -415,9 +438,13 @@ function get_qq_avatar(){
$imgurl='https://q2.qlogo.cn/headimg_dl?dst_uin='.$matches[0].'&spec=100';
if(akina_option('qq_avatar_link')=='type_2'){
$imgdata = file_get_contents($imgurl);
header("Content-type: image/jpeg");
header("Cache-Control: max-age=86400");
$response = new WP_REST_Response();
$response->set_headers(array(
'Content-Type' => 'image/jpeg',
'Cache-Control' => 'max-age=86400'
));
echo $imgdata;
return $response;
}else{
$response = new WP_REST_Response();
$response->set_status(301);

View File

@ -931,27 +931,6 @@ function getqqinfo() {
}
});
}
// $.ajax({
// type: 'get',
// url: mashiro_option.qq_avatar_api_url + '?type=getqqavatar&qq=' + qq,
// dataType: 'jsonp',
// jsonp: 'callback',
// jsonpCallback: 'qqavatarCallBack',
// success: function (data) {
// $('div.comment-user-avatar img').attr('src', data[qq]);
// setCookie('user_avatar', data[qq], 30);
// },
// error: function () {
// cached.filter('#qq,#email,#url').val('');
// if (!cached.filter('#qq').val()) {
// $('.qq-check').css('display', 'none');
// $('.gravatar-check').css('display', 'block');
// setCookie('user_qq', '', 30);
// $('div.comment-user-avatar img').attr('src', get_gravatar(cached.filter('#email').val(), 80));
// setCookie('user_avatar', get_gravatar(cached.filter('#email').val(), 80), 30);
// }
// }
// });
});
if (getCookie('user_avatar') && getCookie('user_email') && getCookie('is_user_qq') == 'no' && !getCookie('user_qq_email')) {
$('div.comment-user-avatar img').attr('src', getCookie('user_avatar'));
@ -1024,6 +1003,8 @@ function load_bangumi() {
var html = JSON.parse(xhr.responseText);
$("#bangumi-pagination").remove();
$(".row").append(html);
}else{
$("#bangumi-pagination a").removeClass("loading").html('<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> ERROR ');
}
};
xhr.send();
@ -1615,7 +1596,7 @@ var home = location.href,
var tempScrollTop = $(window).scrollTop();
$(window).scrollTop(tempScrollTop);
$body.animate({
scrollTop: tempScrollTop + 300
scrollTop: tempScrollTop + 100
}, 666)
} else {
$("#pagination").html("<span>很高兴你翻到这里,但是真的没有了...</span>");

Binary file not shown.

View File

@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: Sakura\n"
"POT-Creation-Date: 2020-04-01 17:10+0800\n"
"PO-Revision-Date: 2020-04-01 17:10+0800\n"
"POT-Creation-Date: 2020-04-02 11:56+0800\n"
"PO-Revision-Date: 2020-04-02 11:56+0800\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en_US\n"
@ -222,7 +222,7 @@ msgstr ""
msgid "page %s "
msgstr ""
#: inc/api.php:308 inc/theme_plus.php:727
#: inc/api.php:337 inc/theme_plus.php:727
msgid "The comment is private"
msgstr ""

View File

@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"Project-Id-Version: Sakura\n"
"POT-Creation-Date: 2020-04-01 17:10+0800\n"
"POT-Creation-Date: 2020-04-02 11:56+0800\n"
"PO-Revision-Date: 2019-11-01 14:27+0800\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -220,7 +220,7 @@ msgstr ""
msgid "page %s "
msgstr ""
#: inc/api.php:308 inc/theme_plus.php:727
#: inc/api.php:337 inc/theme_plus.php:727
msgid "The comment is private"
msgstr ""

Binary file not shown.

View File

@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: Sakura\n"
"POT-Creation-Date: 2020-04-01 17:11+0800\n"
"PO-Revision-Date: 2020-04-01 17:13+0800\n"
"POT-Creation-Date: 2020-04-02 11:56+0800\n"
"PO-Revision-Date: 2020-04-02 11:56+0800\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: zh_CN\n"
@ -227,7 +227,7 @@ msgstr ""
msgid "page %s "
msgstr "第 %s 页 "
#: inc/api.php:308 inc/theme_plus.php:727
#: inc/api.php:337 inc/theme_plus.php:727
msgid "The comment is private"
msgstr "该评论为私密评论"