insert-keywords.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
header("Content-type:text/html;charset=utf-8");
ignore_user_abort(TRUE);
set_time_limit(0);
define( 'DOING_AJAX', true );
define( 'WP_ADMIN', true );
/** Load WordPress Bootstrap */
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
/** Load WordPress Administration APIs */
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
global $wpdb;
$res=@file_get_contents('php://input');
//$wpdb->query($wpdb->prepare("INSERT INTO wp_test (test) VALUES (%d)",$res));
if(!$res){
die();
}
$data=json_decode($res,true);
if(!isset($data['term_id'])||!isset($data['api_key'])||!isset($data['title'])){
die();
}
if($data['api_key']!=sha1(md5('dst').$data['term_id'])){
die();
}
$is_exist_term_id=$wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM wp_term_flag WHERE term_id = %d", $data['term_id'] ) );
if(!$is_exist_term_id){
die();
}
$add_res='';
$time=date('Y-m-d H:i:s');
foreach ($data['title'] as $title){
$add_res = $wpdb->query($wpdb->prepare("INSERT INTO wp_term_news (term_id,title,adtime,sorts) VALUES (%d,%s,%s,%d)",$data['term_id'],$title,$time,1));
}
if($add_res){
$wpdb->query($wpdb->prepare("UPDATE wp_term_flag SET tflag=2 WHERE term_id = %d",$data['term_id']));
}
die();