fix sql error
This commit is contained in:
parent
3aa254d017
commit
63fb8372b0
|
@ -1723,21 +1723,25 @@ function create_sakura_table(){
|
||||||
$sakura_table_name = $wpdb->base_prefix.'sakura';
|
$sakura_table_name = $wpdb->base_prefix.'sakura';
|
||||||
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
|
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
|
||||||
dbDelta("CREATE TABLE IF NOT EXISTS `" . $sakura_table_name . "` (
|
dbDelta("CREATE TABLE IF NOT EXISTS `" . $sakura_table_name . "` (
|
||||||
`key` varchar(50) COLLATE utf8_bin NOT NULL,
|
`mate_key` varchar(50) COLLATE utf8_bin NOT NULL,
|
||||||
`value` text COLLATE utf8_bin NOT NULL,
|
`mate_value` text COLLATE utf8_bin NOT NULL,
|
||||||
PRIMARY KEY (`key`)
|
PRIMARY KEY (`mate_key`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;");
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;");
|
||||||
//default data
|
//default data
|
||||||
$manifest = array(
|
$manifest = array(
|
||||||
"key" => "manifest_json",
|
"mate_key" => "manifest_json",
|
||||||
"value" => file_get_contents(get_template_directory()."/manifest/manifest.json")
|
"mate_value" => file_get_contents(get_template_directory()."/manifest/manifest.json")
|
||||||
);
|
);
|
||||||
$time = array(
|
$time = array(
|
||||||
"key" => "json_time",
|
"mate_key" => "json_time",
|
||||||
"value" => date("Y-m-d H:i:s",time())
|
"mate_value" => date("Y-m-d H:i:s",time())
|
||||||
);
|
);
|
||||||
|
if ( !$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'manifest_json'") ){
|
||||||
$wpdb->insert($sakura_table_name,$manifest);
|
$wpdb->insert($sakura_table_name,$manifest);
|
||||||
|
}
|
||||||
|
if ( !$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'json_time'") ){
|
||||||
$wpdb->insert($sakura_table_name,$time);
|
$wpdb->insert($sakura_table_name,$time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
add_action( 'after_setup_theme', 'create_sakura_table' );
|
add_action( 'after_setup_theme', 'create_sakura_table' );
|
||||||
|
|
||||||
|
|
22
inc/api.php
22
inc/api.php
|
@ -338,9 +338,14 @@ EOS;
|
||||||
*/
|
*/
|
||||||
function cover_gallery() {
|
function cover_gallery() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$img_array = json_decode($wpdb->get_var("SELECT `value` FROM `wp_sakura` WHERE `key`='manifest_json'"), true);
|
$img_array = json_decode($wpdb->get_var("SELECT `mate_value` FROM `wp_sakura` WHERE `mate_key`='manifest_json'"), true);
|
||||||
$img = array_rand($img_array);
|
$img = array_rand($img_array);
|
||||||
$imgurl = akina_option('jsdelivr_cdn') . "/manifest/" . $img_array[$img]["webp"][0];
|
$img_domain = akina_option('jsdelivr_cdn') ? akina_option('jsdelivr_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);
|
||||||
$response->set_status(302);
|
$response->set_status(302);
|
||||||
|
@ -354,9 +359,14 @@ function cover_gallery() {
|
||||||
*/
|
*/
|
||||||
function feature_gallery() {
|
function feature_gallery() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$img_array = json_decode($wpdb->get_var("SELECT `value` FROM `wp_sakura` WHERE `key`='manifest_json'"), true);
|
$img_array = json_decode($wpdb->get_var("SELECT `mate_value` FROM `wp_sakura` WHERE `mate_key`='manifest_json'"), true);
|
||||||
$img = array_rand($img_array);
|
$img = array_rand($img_array);
|
||||||
$imgurl = akina_option('jsdelivr_cdn') . "/manifest/" . $img_array[$img]["webp"][1];
|
$img_domain = akina_option('jsdelivr_cdn') ? akina_option('jsdelivr_cdn') : get_template_directory_uri();
|
||||||
|
if(strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')) {
|
||||||
|
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["webp"][1];
|
||||||
|
} else {
|
||||||
|
$imgurl = $img_domain . "/manifest/" . $img_array[$img]["jpeg"][1];
|
||||||
|
}
|
||||||
$data = array('cover image');
|
$data = array('cover image');
|
||||||
$response = new WP_REST_Response($data);
|
$response = new WP_REST_Response($data);
|
||||||
$response->set_status(302);
|
$response->set_status(302);
|
||||||
|
@ -385,8 +395,8 @@ function update_manifest_json() {
|
||||||
"value" => date("Y-m-d H:i:s",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 `mate_key` ='manifest_json'");
|
||||||
$wpdb->query("DELETE FROM `wp_sakura` WHERE `key` ='json_time'");
|
$wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='json_time'");
|
||||||
$wpdb->insert($sakura_table_name,$manifest);
|
$wpdb->insert($sakura_table_name,$manifest);
|
||||||
$wpdb->insert($sakura_table_name,$time);
|
$wpdb->insert($sakura_table_name,$time);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue