update api

This commit is contained in:
spirit 2019-11-28 23:21:24 +08:00
parent c8349d33e9
commit 19a337ed17
18 changed files with 942 additions and 901 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

View File

@ -1,3 +0,0 @@
https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.3.2/cover/gallery/pixar_up_movie_balloons_desktop_1920x1080_hd-wallpaper-507967.jpg
https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.3.2/cover/gallery/beyond_by_auroralion-dan5njb.jpg
https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.3.2/cover/gallery/海の空(56993195)_by_夏T.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 486 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 KiB

View File

@ -1,2 +0,0 @@
https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.3.2/feature/gallery/1.jpg
https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.3.2/feature/gallery/2.jpg

View File

@ -1631,12 +1631,7 @@ function change_avatar($avatar){
// default feature image // default feature image
function DEFAULT_FEATURE_IMAGE() { function DEFAULT_FEATURE_IMAGE() {
if ( empty( akina_option('default_feature_image' )) ) { return rest_url('sakura/v1/image/feature').'?'.rand(1,1000);
return rest_url('sakura/v1/image/feature').'?'.rand(1,1000);
//return 'https://api.mashiro.top/feature/?'.rand(1,1000);
} else {
return akina_option('default_feature_image').'?'.rand(1,1000);
}
} }
//防止设置置顶文章造成的图片同侧bug //防止设置置顶文章造成的图片同侧bug
@ -1719,4 +1714,31 @@ function allow_more_tag_in_comment() {
$allowedtags['span'] = array('class'=>array()); $allowedtags['span'] = array('class'=>array());
} }
add_action('pre_comment_on_post', 'allow_more_tag_in_comment'); add_action('pre_comment_on_post', 'allow_more_tag_in_comment');
/*
* 随机图
*/
function create_sakura_table(){
global $wpdb;
$sakura_table_name = $wpdb->base_prefix.'sakura';
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
dbDelta("CREATE TABLE IF NOT EXISTS `" . $sakura_table_name . "` (
`key` varchar(50) COLLATE utf8_bin NOT NULL,
`value` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;");
//default data
$manifest = array(
"key" => "manifest_json",
"value" => file_get_contents(get_template_directory()."/manifest/manifest.json")
);
$time = array(
"key" => "json_time",
"value" => date("Y-m-d H:i:s",time())
);
$wpdb->insert($sakura_table_name,$manifest);
$wpdb->insert($sakura_table_name,$time);
}
add_action( 'after_setup_theme', 'create_sakura_table' );
//code end //code end

View File

@ -20,6 +20,10 @@ add_action('rest_api_init', function () {
'methods' => 'GET', 'methods' => 'GET',
'callback' => 'feature_gallery', 'callback' => 'feature_gallery',
)); ));
register_rest_route('sakura/v1', '/image/json', array(
'methods' => 'POST',
'callback' => 'update_manifest_json',
));
}); });
/** /**
@ -276,13 +280,14 @@ EOS;
* @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/image/cover * @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/image/cover
*/ */
function cover_gallery() { function cover_gallery() {
$img_array = file(get_wp_root_path(). "/themes/Sakura/cover/img.txt"); global $wpdb;
$img = mt_rand(0, count($img_array) - 1); $img_array = json_decode($wpdb->get_var("SELECT `value` FROM `wp_sakura` WHERE `key`='manifest_json'"), true);
$imgurl = trim($img_array[$img]); $img = array_rand($img_array);
$data = array( 'cover image' ); $imgurl = akina_option('jsdelivr_cdn') . "/manifest/" . $img_array[$img]["webp"][0];
$data = array('cover image');
$response = new WP_REST_Response($data); $response = new WP_REST_Response($data);
$response->set_status( 302 ); $response->set_status(302);
$response->header( 'Location', $imgurl); $response->header('Location', $imgurl);
return $response; return $response;
} }
@ -291,12 +296,54 @@ function cover_gallery() {
* @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/image/feature * @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/image/feature
*/ */
function feature_gallery() { function feature_gallery() {
$img_array = file(get_wp_root_path(). "/themes/Sakura/feature/img.txt"); global $wpdb;
$img = mt_rand(0, count($img_array) - 1); $img_array = json_decode($wpdb->get_var("SELECT `value` FROM `wp_sakura` WHERE `key`='manifest_json'"), true);
$imgurl = trim($img_array[$img]); $img = array_rand($img_array);
$data = array( 'feature image' ); $imgurl = akina_option('jsdelivr_cdn') . "/manifest/" . $img_array[$img]["webp"][1];
$data = array('cover image');
$response = new WP_REST_Response($data); $response = new WP_REST_Response($data);
$response->set_status( 302 ); $response->set_status(302);
$response->header( 'Location', $imgurl); $response->header('Location', $imgurl);
return $response; return $response;
} }
/*
* update manifest.json rest api
* @rest api接口路径https://sakura.2heng.xin/wp-json/sakura/v1/image/json
*/
function update_manifest_json(WP_REST_Request $request) {
if (is_admin()) {
$sakura_table_name = $wpdb->base_prefix.'sakura';
$manifest = array(
"key" => "manifest_json",
"value" => file_get_contents($_FILES["manifest_json"]["tmp_name"])
);
$time = array(
"key" => "json_time",
"value" => date("Y-m-d H:i:s",time())
);
$wpdb->query("DELETE FROM `wp_sakura` WHERE `key`='manifest_json'");
$wpdb->query("DELETE FROM `wp_sakura` WHERE `key`='json_time'");
$wpdb->insert($sakura_table_name,$manifest);
$wpdb->insert($sakura_table_name,$time);
$output = array(
'status' => 200,
'success' => true,
'message' => 'manifest.json has been stored into database'
);
$result = new WP_REST_Response($output, 200);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
} else {
$output = array(
'status' => 401,
'success' => false,
'message' => 'Not Authorized.'
);
$result = new WP_REST_Response($output, 401);
$result->set_headers(array('Content-Type' => 'application/json'));
return $result;
}
}

View File

@ -78,15 +78,7 @@ if ( akina_option('toggle-menu') == 'no') { ?>
.comments .comments-hidden {display:none !important;} .comments .comments-hidden {display:none !important;}
<?php } // comments ?> <?php } // comments ?>
<?php <?php
$image_api = 'background-image: url("'.rest_url('sakura/v1/image/cover').'");';
if (akina_option('cover_img')) {
$imgurl = akina_option('cover_img');
} else {
$imgurl = rest_url('sakura/v1/image/cover');
}
$image_api = 'background-image: url("'.$imgurl.'");';
$bg_style = akina_option('focus_height') ? 'background-position: center center;background-attachment: inherit;' : ''; $bg_style = akina_option('focus_height') ? 'background-position: center center;background-attachment: inherit;' : '';
?> ?>
.centerbg{<?php echo $image_api.$bg_style ?>background-position: center center;background-attachment: inherit;} .centerbg{<?php echo $image_api.$bg_style ?>background-position: center center;background-attachment: inherit;}

View File

@ -71,13 +71,7 @@ mashiro_option.jsdelivr_css_src = "https://cdn.jsdelivr.net/gh/mashirozx/Sakura@
mashiro_option.float_player_on = true; mashiro_option.float_player_on = true;
<?php endif; ?> <?php endif; ?>
<?php mashiro_option.cover_api = "<?php echo rest_url('sakura/v1/image/cover'); ?>";
if (akina_option('cover_img')) {
$imgurl = akina_option('cover_img');
} else {
$imgurl = rest_url('sakura/v1/image/cover');
} ?>
mashiro_option.cover_api = "<?php echo $imgurl; ?>";
/*End of Initial Variables*/ /*End of Initial Variables*/
</script> </script>

View File

@ -43,11 +43,7 @@ function get_avatar_profile_url(){
* 随机图 * 随机图
*/ */
function get_random_bg_url(){ function get_random_bg_url(){
if ( empty( akina_option('default_feature_image' )) ) { return rest_url('sakura/v1/image/feature').'?'.rand(1,1000);
return rest_url('sakura/v1/image/feature').'?'.rand(1,1000);
} else {
return akina_option('default_feature_image').'?'.rand(1,1000);
}
} }
@ -120,7 +116,8 @@ function comment_add_at( $comment_text, $comment = '') {
if( $comment->comment_parent > 0) { if( $comment->comment_parent > 0) {
if(substr($comment_text, 0, 3) === "<p>") if(substr($comment_text, 0, 3) === "<p>")
$comment_text = str_replace(substr($comment_text, 0, 3), '<p><a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a>&nbsp;', $comment_text); $comment_text = str_replace(substr($comment_text, 0, 3), '<p><a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a>&nbsp;', $comment_text);
else $comment_text = '<a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a>&nbsp;' . $comment_text; else
$comment_text = '<a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a>&nbsp;' . $comment_text;
} }
return $comment_text; return $comment_text;
} }

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -263,13 +263,6 @@ function optionsframework_options() {
'alternate' => __('Alternate', 'sakura')/*左右交替*/ 'alternate' => __('Alternate', 'sakura')/*左右交替*/
)); ));
$options[] = array(
'name' => __('Default article feature image', 'sakura'),/*默认文章特色图*/
'desc' => __('The default image to be displayed without the feature map of the article. Leave blank here to use the built-in API (write the URL of the image to be displayed randomly to the /feature/img.txt file)', 'sakura'),/*在未设置文章特色图的情况下展示的默认图像此处留空则使用内置API将需要随机展示的图片url写入 /feature/img.txt 文件)*/
'id' => 'default_feature_image',
'std' => 'https://api.mashiro.top/feature/',
'type' => 'text');
$options[] = array( $options[] = array(
'name' => __('Comment shrink', 'sakura'),/*评论收缩*/ 'name' => __('Comment shrink', 'sakura'),/*评论收缩*/
'id' => 'toggle-menu', 'id' => 'toggle-menu',
@ -418,13 +411,6 @@ function optionsframework_options() {
'std' => '', 'std' => '',
'type' => 'text'); 'type' => 'text');
$options[] = array(
'name' => __('Cover image', 'sakura'),/*封面图*/
'desc' => __('Leave blank here to use the built-in API (write the URL of the image that needs to be displayed randomly to the /cover/img.txt file))', 'sakura'),/*此处留空则使用内置API将需要随机展示的图片url写入 /cover/img.txt 文件)*/
'id' => 'cover_img',
'std' => '',
'type' => 'text');
$options[] = array( $options[] = array(
'name' => __('Background image filter', 'sakura'),/*背景图滤镜*/ 'name' => __('Background image filter', 'sakura'),/*背景图滤镜*/
'id' => 'focus_img_filter', 'id' => 'focus_img_filter',
@ -889,6 +875,13 @@ function optionsframework_options() {
'std' => '', 'std' => '',
'type' => 'text'); 'type' => 'text');
$options[] = array(
'name' => __('Jsdelivr CDN', 'sakura'),/*图片库*/
'desc' => __('Fill in the cdn path for random picture display, without adding a slash at the end, for example: https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3, please refer to <a href = "https: //github.com/mashirozx/Sakura/wiki/options">Wiki </a>', 'sakura'),/*填写 cdn 路径用于随机图片展示最后不用加斜杠https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3 ,更多信息请参考<a href="https://github.com/mashirozx/Sakura/wiki/options">Wiki</a>*/
'id' => 'jsdelivr_cdn',
'std' => 'https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3',
'type' => 'text');
$options[] = array( $options[] = array(
'name' => __('Use the front-end library locally (lib.js、lib.css)', 'sakura'),/*本地调用前端库lib.js、lib.css*/ 'name' => __('Use the front-end library locally (lib.js、lib.css)', 'sakura'),/*本地调用前端库lib.js、lib.css*/
'desc' => __('The front-end library don\'t load from jsDelivr, not recommand', 'sakura'),/*前端库不走 jsDelivr不建议启用*/ 'desc' => __('The front-end library don\'t load from jsDelivr, not recommand', 'sakura'),/*前端库不走 jsDelivr不建议启用*/