fix sql error

This commit is contained in:
mashiro 2019-12-03 22:35:15 +08:00
parent 3aa254d017
commit 63fb8372b0
2 changed files with 29 additions and 15 deletions

View File

@ -1723,22 +1723,26 @@ function create_sakura_table(){
$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`)
`mate_key` varchar(50) COLLATE utf8_bin NOT NULL,
`mate_value` text COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`mate_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")
"mate_key" => "manifest_json",
"mate_value" => file_get_contents(get_template_directory()."/manifest/manifest.json")
);
$time = array(
"key" => "json_time",
"value" => date("Y-m-d H:i:s",time())
"mate_key" => "json_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);
}
if ( !$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'json_time'") ){
$wpdb->insert($sakura_table_name,$time);
}
}
add_action( 'after_setup_theme', 'create_sakura_table' );
//code end

View File

@ -338,9 +338,14 @@ EOS;
*/
function cover_gallery() {
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);
$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');
$response = new WP_REST_Response($data);
$response->set_status(302);
@ -354,9 +359,14 @@ function cover_gallery() {
*/
function feature_gallery() {
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);
$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');
$response = new WP_REST_Response($data);
$response->set_status(302);
@ -385,8 +395,8 @@ function update_manifest_json() {
"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->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='manifest_json'");
$wpdb->query("DELETE FROM `wp_sakura` WHERE `mate_key` ='json_time'");
$wpdb->insert($sakura_table_name,$manifest);
$wpdb->insert($sakura_table_name,$time);