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]
|
//With Thumbnail: !{alt}(url)[th_url]
|
||||||
if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) {
|
if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) {
|
||||||
$i = 0;
|
for ($i = 0; $i < sizeof($matches); $i++) {
|
||||||
if ($i < sizeof($matches)) {
|
|
||||||
$content = str_replace($matches[$i], preg_replace(
|
$content = str_replace($matches[$i], preg_replace(
|
||||||
'/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i',
|
'/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i',
|
||||||
'<a data-fancybox="gallery"
|
'<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>',
|
title="$1"><img src="$7" target="_blank" rel="nofollow" class="fancybox"></a>',
|
||||||
$matches[$i]),
|
$matches[$i]),
|
||||||
$content);
|
$content);
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1671,14 +1669,12 @@ function html_tag_parser($content)
|
||||||
//Fancybox
|
//Fancybox
|
||||||
$url_regex = '((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))';
|
$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)) {
|
if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) {
|
||||||
$i = 0;
|
for ($i = 0; $i < sizeof($matches); $i++) {
|
||||||
if ($i < sizeof($matches)) {
|
|
||||||
$content = str_replace(
|
$content = str_replace(
|
||||||
$matches[$i],
|
$matches[$i],
|
||||||
preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i', '<a href="$2"><img src="$7" alt="$1" title="$1"></a>', $matches[$i]),
|
preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i', '<a href="$2"><img src="$7" alt="$1" title="$1"></a>', $matches[$i]),
|
||||||
$content
|
$content
|
||||||
);
|
);
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$content = preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)/i', '<a href="$2"><img src="$2" alt="$1" title="$1"></a>', $content);
|
$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'")) {
|
if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'manifest_json'")) {
|
||||||
$manifest = array(
|
$manifest = array(
|
||||||
"mate_key" => "manifest_json",
|
"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);
|
$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
|
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/cover
|
||||||
*/
|
*/
|
||||||
function cover_gallery() {
|
function cover_gallery() {
|
||||||
global $wpdb,$sakura_image_array;
|
if(akina_option('cover_cdn_options')=="type_2"){
|
||||||
$img_array = json_decode($sakura_image_array, true);
|
$img_array = glob(get_template_directory() . "/manifest/gallary/*.{gif,jpg,png}",GLOB_BRACE);
|
||||||
$img = array_rand($img_array);
|
$img = array_rand($img_array);
|
||||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
|
$imgurl = trim($img_array[$img]);
|
||||||
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
|
$imgurl = str_replace(get_template_directory(), get_template_directory_uri(), $imgurl);
|
||||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][0];
|
}elseif(akina_option('cover_cdn_options')=="type_3"){
|
||||||
} else {
|
$imgurl = akina_option('cover_cdn');
|
||||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][0];
|
}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');
|
$data = array('cover image');
|
||||||
$response = new WP_REST_Response($data);
|
$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
|
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/feature
|
||||||
*/
|
*/
|
||||||
function feature_gallery() {
|
function feature_gallery() {
|
||||||
global $wpdb,$sakura_image_array;
|
if(akina_option('cover_cdn_options')=="type_2"){
|
||||||
$img_array = json_decode($sakura_image_array, true);
|
$img_array = glob(get_template_directory() . "/manifest/gallery/*.{gif,jpg,png}",GLOB_BRACE);
|
||||||
$img = array_rand($img_array);
|
$img = array_rand($img_array);
|
||||||
$img_domain = akina_option('cover_cdn') ? akina_option('cover_cdn') : get_template_directory_uri();
|
$imgurl = trim($img_array[$img]);
|
||||||
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
|
$imgurl = str_replace(get_template_directory(), get_template_directory_uri(), $imgurl);
|
||||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][0];
|
}elseif(akina_option('cover_cdn_options')=="type_3"){
|
||||||
} else {
|
$imgurl = akina_option('cover_cdn');
|
||||||
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][0];
|
}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');
|
$data = array('cover image');
|
||||||
$response = new WP_REST_Response($data);
|
$response = new WP_REST_Response($data);
|
||||||
|
@ -369,7 +387,7 @@ function feature_gallery() {
|
||||||
function update_database() {
|
function update_database() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$sakura_table_name = $wpdb->base_prefix.'sakura';
|
$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");
|
$manifest = file_get_contents($img_domain . "/manifest/manifest.json");
|
||||||
if($manifest) {
|
if($manifest) {
|
||||||
$manifest = array(
|
$manifest = array(
|
||||||
|
@ -387,7 +405,7 @@ function update_database() {
|
||||||
$wpdb->insert($sakura_table_name,$time);
|
$wpdb->insert($sakura_table_name,$time);
|
||||||
$output = "manifest.json has been stored into database.";
|
$output = "manifest.json has been stored into database.";
|
||||||
}else{
|
}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);
|
$result = new WP_REST_Response($output, 200);
|
||||||
return $result;
|
return $result;
|
||||||
|
|
17
options.php
17
options.php
|
@ -374,8 +374,21 @@ function optionsframework_options()
|
||||||
));
|
));
|
||||||
|
|
||||||
$options[] = array(
|
$options[] = array(
|
||||||
'name' => __('Cover manifest', 'sakura'), /*封面图片库*/
|
'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>*/
|
'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',
|
'id' => 'cover_cdn',
|
||||||
'std' => 'https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3',
|
'std' => 'https://cdn.jsdelivr.net/gh/mashirozx/sakura@3.3.3',
|
||||||
'type' => 'text');
|
'type' => 'text');
|
||||||
|
|
Loading…
Reference in New Issue