update api
This commit is contained in:
parent
c8349d33e9
commit
19a337ed17
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 |
|
@ -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 |
|
@ -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
|
|
@ -1631,12 +1631,7 @@ function change_avatar($avatar){
|
|||
|
||||
// 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 'https://api.mashiro.top/feature/?'.rand(1,1000);
|
||||
} else {
|
||||
return akina_option('default_feature_image').'?'.rand(1,1000);
|
||||
}
|
||||
}
|
||||
|
||||
//防止设置置顶文章造成的图片同侧bug
|
||||
|
@ -1719,4 +1714,31 @@ function allow_more_tag_in_comment() {
|
|||
$allowedtags['span'] = array('class'=>array());
|
||||
}
|
||||
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
|
||||
|
|
61
inc/api.php
61
inc/api.php
|
@ -20,6 +20,10 @@ add_action('rest_api_init', function () {
|
|||
'methods' => 'GET',
|
||||
'callback' => 'feature_gallery',
|
||||
));
|
||||
register_rest_route('sakura/v1', '/image/json', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => 'update_manifest_json',
|
||||
));
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -276,9 +280,10 @@ EOS;
|
|||
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/cover
|
||||
*/
|
||||
function cover_gallery() {
|
||||
$img_array = file(get_wp_root_path(). "/themes/Sakura/cover/img.txt");
|
||||
$img = mt_rand(0, count($img_array) - 1);
|
||||
$imgurl = trim($img_array[$img]);
|
||||
global $wpdb;
|
||||
$img_array = json_decode($wpdb->get_var("SELECT `value` FROM `wp_sakura` WHERE `key`='manifest_json'"), true);
|
||||
$img = array_rand($img_array);
|
||||
$imgurl = akina_option('jsdelivr_cdn') . "/manifest/" . $img_array[$img]["webp"][0];
|
||||
$data = array('cover image');
|
||||
$response = new WP_REST_Response($data);
|
||||
$response->set_status(302);
|
||||
|
@ -291,12 +296,54 @@ function cover_gallery() {
|
|||
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/feature
|
||||
*/
|
||||
function feature_gallery() {
|
||||
$img_array = file(get_wp_root_path(). "/themes/Sakura/feature/img.txt");
|
||||
$img = mt_rand(0, count($img_array) - 1);
|
||||
$imgurl = trim($img_array[$img]);
|
||||
$data = array( 'feature image' );
|
||||
global $wpdb;
|
||||
$img_array = json_decode($wpdb->get_var("SELECT `value` FROM `wp_sakura` WHERE `key`='manifest_json'"), true);
|
||||
$img = array_rand($img_array);
|
||||
$imgurl = akina_option('jsdelivr_cdn') . "/manifest/" . $img_array[$img]["webp"][1];
|
||||
$data = array('cover image');
|
||||
$response = new WP_REST_Response($data);
|
||||
$response->set_status(302);
|
||||
$response->header('Location', $imgurl);
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -78,15 +78,7 @@ if ( akina_option('toggle-menu') == 'no') { ?>
|
|||
.comments .comments-hidden {display:none !important;}
|
||||
<?php } // comments ?>
|
||||
<?php
|
||||
|
||||
if (akina_option('cover_img')) {
|
||||
$imgurl = akina_option('cover_img');
|
||||
} else {
|
||||
$imgurl = rest_url('sakura/v1/image/cover');
|
||||
}
|
||||
|
||||
|
||||
$image_api = 'background-image: url("'.$imgurl.'");';
|
||||
$image_api = 'background-image: url("'.rest_url('sakura/v1/image/cover').'");';
|
||||
$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;}
|
||||
|
|
|
@ -71,13 +71,7 @@ mashiro_option.jsdelivr_css_src = "https://cdn.jsdelivr.net/gh/mashirozx/Sakura@
|
|||
mashiro_option.float_player_on = true;
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
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; ?>";
|
||||
mashiro_option.cover_api = "<?php echo rest_url('sakura/v1/image/cover'); ?>";
|
||||
|
||||
/*End of Initial Variables*/
|
||||
</script>
|
||||
|
|
|
@ -43,11 +43,7 @@ function get_avatar_profile_url(){
|
|||
* 随机图
|
||||
*/
|
||||
function get_random_bg_url(){
|
||||
if ( empty( akina_option('default_feature_image' )) ) {
|
||||
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(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> ', $comment_text);
|
||||
else $comment_text = '<a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a> ' . $comment_text;
|
||||
else
|
||||
$comment_text = '<a href="#comment-' . $comment->comment_parent . '" class="comment-at">@'.get_comment_author( $comment->comment_parent ) . '</a> ' . $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
21
options.php
21
options.php
|
@ -263,13 +263,6 @@ function optionsframework_options() {
|
|||
'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(
|
||||
'name' => __('Comment shrink', 'sakura'),/*评论收缩*/
|
||||
'id' => 'toggle-menu',
|
||||
|
@ -418,13 +411,6 @@ function optionsframework_options() {
|
|||
'std' => '',
|
||||
'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(
|
||||
'name' => __('Background image filter', 'sakura'),/*背景图滤镜*/
|
||||
'id' => 'focus_img_filter',
|
||||
|
@ -889,6 +875,13 @@ function optionsframework_options() {
|
|||
'std' => '',
|
||||
'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(
|
||||
'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,不建议启用*/
|
||||
|
|
Loading…
Reference in New Issue