mirror of
https://github.com/mashirozx/sakura.git
synced 2024-11-22 06:48:12 +08:00
feat: add cover images api options
This commit is contained in:
parent
b419dcc8ca
commit
742f5680e3
@ -1626,8 +1626,7 @@ function html_tag_parser($content)
|
||||
|
||||
//With Thumbnail: !{alt}(url)[th_url]
|
||||
if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) {
|
||||
$i = 0;
|
||||
if ($i < sizeof($matches)) {
|
||||
for ($i = 0; $i < sizeof($matches); $i++) {
|
||||
$content = str_replace($matches[$i], preg_replace(
|
||||
'/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i',
|
||||
'<a data-fancybox="gallery"
|
||||
@ -1638,7 +1637,6 @@ function html_tag_parser($content)
|
||||
title="$1"><img src="$7" target="_blank" rel="nofollow" class="fancybox"></a>',
|
||||
$matches[$i]),
|
||||
$content);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1671,14 +1669,12 @@ function html_tag_parser($content)
|
||||
//Fancybox
|
||||
$url_regex = '((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))';
|
||||
if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) {
|
||||
$i = 0;
|
||||
if ($i < sizeof($matches)) {
|
||||
for ($i = 0; $i < sizeof($matches); $i++) {
|
||||
$content = str_replace(
|
||||
$matches[$i],
|
||||
preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i', '<a href="$2"><img src="$7" alt="$1" title="$1"></a>', $matches[$i]),
|
||||
$content
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$content = preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)/i', '<a href="$2"><img src="$2" alt="$1" title="$1"></a>', $content);
|
||||
@ -1864,7 +1860,7 @@ function create_sakura_table()
|
||||
if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'manifest_json'")) {
|
||||
$manifest = array(
|
||||
"mate_key" => "manifest_json",
|
||||
"mate_value" => file_get_contents(get_template_directory() . "/manifest/manifest.json"),
|
||||
"mate_value" => file_get_contents(get_stylesheet_directory() . "/manifest/manifest.json"),
|
||||
);
|
||||
$wpdb->insert($sakura_table_name, $manifest);
|
||||
}
|
||||
|
54
inc/api.php
54
inc/api.php
@ -325,14 +325,23 @@ EOS;
|
||||
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/cover
|
||||
*/
|
||||
function cover_gallery() {
|
||||
global $wpdb,$sakura_image_array;
|
||||
$img_array = json_decode($sakura_image_array, true);
|
||||
$img = array_rand($img_array);
|
||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
|
||||
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][0];
|
||||
} else {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][0];
|
||||
if(akina_option('cover_cdn_options')=="type_2"){
|
||||
$img_array = glob(get_template_directory() . "/manifest/gallary/*.{gif,jpg,png}",GLOB_BRACE);
|
||||
$img = array_rand($img_array);
|
||||
$imgurl = trim($img_array[$img]);
|
||||
$imgurl = str_replace(get_template_directory(), get_template_directory_uri(), $imgurl);
|
||||
}elseif(akina_option('cover_cdn_options')=="type_3"){
|
||||
$imgurl = akina_option('cover_cdn');
|
||||
}else{
|
||||
global $sakura_image_array;
|
||||
$img_array = json_decode($sakura_image_array, true);
|
||||
$img = array_rand($img_array);
|
||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
|
||||
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][0];
|
||||
} else {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][0];
|
||||
}
|
||||
}
|
||||
$data = array('cover image');
|
||||
$response = new WP_REST_Response($data);
|
||||
@ -346,14 +355,23 @@ function cover_gallery() {
|
||||
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/feature
|
||||
*/
|
||||
function feature_gallery() {
|
||||
global $wpdb,$sakura_image_array;
|
||||
$img_array = json_decode($sakura_image_array, true);
|
||||
$img = array_rand($img_array);
|
||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
|
||||
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][0];
|
||||
} else {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][0];
|
||||
if(akina_option('cover_cdn_options')=="type_2"){
|
||||
$img_array = glob(get_template_directory() . "/manifest/gallery/*.{gif,jpg,png}",GLOB_BRACE);
|
||||
$img = array_rand($img_array);
|
||||
$imgurl = trim($img_array[$img]);
|
||||
$imgurl = str_replace(get_template_directory(), get_template_directory_uri(), $imgurl);
|
||||
}elseif(akina_option('cover_cdn_options')=="type_3"){
|
||||
$imgurl = akina_option('cover_cdn');
|
||||
}else{
|
||||
global $sakura_image_array;
|
||||
$img_array = json_decode($sakura_image_array, true);
|
||||
$img = array_rand($img_array);
|
||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
|
||||
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][0];
|
||||
} else {
|
||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][0];
|
||||
}
|
||||
}
|
||||
$data = array('cover image');
|
||||
$response = new WP_REST_Response($data);
|
||||
@ -369,7 +387,7 @@ function feature_gallery() {
|
||||
function update_database() {
|
||||
global $wpdb;
|
||||
$sakura_table_name = $wpdb->base_prefix.'sakura';
|
||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
|
||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory();
|
||||
$manifest = file_get_contents($img_domain . "/manifest/manifest.json");
|
||||
if($manifest) {
|
||||
$manifest = array(
|
||||
@ -387,7 +405,7 @@ function update_database() {
|
||||
$wpdb->insert($sakura_table_name,$time);
|
||||
$output = "manifest.json has been stored into database.";
|
||||
}else{
|
||||
$output = "manifest.json not found, please ensure your url is corrent.";
|
||||
$output = "manifest.json not found, please ensure your url ($img_domain) is corrent.";
|
||||
}
|
||||
$result = new WP_REST_Response($output, 200);
|
||||
return $result;
|
||||
|
17
options.php
17
options.php
@ -374,8 +374,21 @@ function optionsframework_options()
|
||||
));
|
||||
|
||||
$options[] = array(
|
||||
'name' => __('Cover manifest', 'sakura'), /*封面图片库*/
|
||||
'desc' => sprintf(__('Fill in the manifest 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>. Click <a href = "%s">here</a> to update manifest', 'sakura'), rest_url('sakura/v1/database/update')), /*填写 manifest 路径 ,用于随机图片展示,最后不用加斜杠,例:https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3 ,更多信息请参考<a href="https://github.com/mashirozx/Sakura/wiki/options">Wiki</a>*/
|
||||
'name' => __('Cover manifest', 'sakura'), /*封面图片库选项*/
|
||||
'desc' => __('Select how to call the cover random image', 'sakura'), /*选择封面随机图的调用方式*/
|
||||
'id' => 'cover_cdn_options',
|
||||
'std' => "type_1",
|
||||
'type' => "select",
|
||||
'options' => array(
|
||||
'type_1' => __('webp images (optimization)', 'sakura'), /*webp优化随机图*/
|
||||
'type_2' => __('built-in api (easiest)', 'sakura'), /*内置原图随机图*/
|
||||
'type_3' => __('custom api (advanced)', 'sakura'), /*外部随机图API*/
|
||||
)
|
||||
);
|
||||
|
||||
$options[] = array(
|
||||
'name' => __('Cover images url', 'sakura'), /*图片库url*/
|
||||
'desc' => sprintf(__('Fill in the manifest path for random picture display, please refer to <a href = "https: //github.com/mashirozx/Sakura/wiki/options">Wiki </a>. If you select webp images above, click <a href = "%s">here</a> to update manifest', 'sakura'), rest_url('sakura/v1/database/update')), /*填写 manifest 路径,更多信息请参考<a href="https://github.com/mashirozx/Sakura/wiki/options">Wiki</a>,,如果你在上面选择了webp优化,点击<a href = "%s">这里</a>更新 manifest*/
|
||||
'id' => 'cover_cdn',
|
||||
'std' => 'https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3',
|
||||
'type' => 'text');
|
||||
|
Loading…
Reference in New Issue
Block a user