diff --git a/functions.php b/functions.php index dfab6c8..8b3a693 100644 --- a/functions.php +++ b/functions.php @@ -1565,29 +1565,15 @@ function html_tag_parser($content) { if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content,$matches)){ $i=0; if ($i', - $matches[$i]), - $content); + $content=str_replace( + $matches[$i], + preg_replace('/!\{([^\{\}]+)*\}\('.$url_regex.'\)\['.$url_regex.'\]/i','$1',$matches[$i]), + $content + ); $i++; } } - $content=preg_replace( - '/!\{([^\{\}]+)*\}\('.$url_regex.'\)/i', - '', - $content - ); + $content=preg_replace('/!\{([^\{\}]+)*\}\('.$url_regex.'\)/i','$1',$content); //Github cards $content=preg_replace( @@ -1646,7 +1632,7 @@ function change_avatar($avatar){ // default feature image function DEFAULT_FEATURE_IMAGE() { if ( empty( akina_option('default_feature_image' )) ) { - return get_template_directory_uri().'/feature/index.php?'.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); diff --git a/inc/api.php b/inc/api.php index 9cb0ca8..a175108 100644 --- a/inc/api.php +++ b/inc/api.php @@ -12,6 +12,14 @@ add_action('rest_api_init', function () { 'methods' => 'GET', 'callback' => 'cache_search_json', )); + register_rest_route('sakura/v1', '/image/cover', array( + 'methods' => 'GET', + 'callback' => 'cover_gallery', + )); + register_rest_route('sakura/v1', '/image/feature', array( + 'methods' => 'GET', + 'callback' => 'feature_gallery', + )); }); /** @@ -262,3 +270,31 @@ EOS; return $result; } + +/* + * 随机封面图 rest api + * @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/cover + */ +function cover_gallery() { + $img_array = glob(get_wp_root_path(). "/themes/Sakura/cover/gallery/*.{gif,jpg,png}",GLOB_BRACE); + $img = array_rand($img_array); + $imgurl = $img_array[$img]; + $mimetype = end(getimagesize($imgurl)); + $imgdata = file_get_contents($imgurl); + header("Content-type: ".$mimetype); + echo $imgdata; +} + +/* + * 随机文章特色图 rest api + * @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/feature + */ +function feature_gallery() { + $img_array = glob(get_wp_root_path(). "/themes/Sakura/feature/gallery/*.{gif,jpg,png}",GLOB_BRACE); + $img = array_rand($img_array); + $imgurl = $img_array[$img]; + $mimetype = end(getimagesize($imgurl)); + $imgdata = file_get_contents($imgurl); + header("Content-type: ".$mimetype); + echo $imgdata; +} \ No newline at end of file diff --git a/inc/decorate.php b/inc/decorate.php index 6389b26..538293f 100644 --- a/inc/decorate.php +++ b/inc/decorate.php @@ -82,7 +82,7 @@ if ( akina_option('toggle-menu') == 'no') { ?> if (akina_option('cover_img')) { $imgurl = akina_option('cover_img'); } else { - $imgurl = get_site_url()."/wp-content/themes/Sakura/cover/index.php"; + $imgurl = rest_url('sakura/v1/image/cover'); } diff --git a/inc/swicher.php b/inc/swicher.php index f2ec4d0..258eb3f 100644 --- a/inc/swicher.php +++ b/inc/swicher.php @@ -75,7 +75,7 @@ mashiro_option.float_player_on = true; if (akina_option('cover_img')) { $imgurl = akina_option('cover_img'); } else { - $imgurl = get_site_url()."/wp-content/themes/Sakura/cover/index.php"; + $imgurl = rest_url('sakura/v1/image/cover'); } ?> mashiro_option.cover_api = ""; diff --git a/inc/theme_plus.php b/inc/theme_plus.php index c554094..115b200 100644 --- a/inc/theme_plus.php +++ b/inc/theme_plus.php @@ -44,7 +44,7 @@ function get_avatar_profile_url(){ */ function get_random_bg_url(){ if ( empty( akina_option('default_feature_image' )) ) { - return get_template_directory_uri().'/feature/index.php?'.rand(1,1000); + return rest_url('sakura/v1/image/feature').'?'.rand(1,1000); } else { return akina_option('default_feature_image').'?'.rand(1,1000); }