inquiry-api.php
4.6 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
require_once( dirname(__FILE__) . '/wp-load.php' );
if(isset($_GET['code']) && $_GET['code'] == 'qqs'){
$show_type = 0;
if(isset($_GET['type']) && $_GET['type'] == 1){
$show_type = 1;
}
global $wpdb;
$start_date = date("Y-m-d 00:00:00",time()-86400);
$end_date = date("Y-m-d 00:00:00");
if($show_type == 0){
$comments = $wpdb->get_results("select comment_post_ID,comment_author,comment_content,comment_date from wp_comments where comment_date>='".$start_date."' and comment_date<'".$end_date."' order by comment_ID desc",ARRAY_A);
}else{
$comments = $wpdb->get_results("select comment_post_ID,comment_author,comment_content,comment_date from wp_comments order by comment_ID desc",ARRAY_A);
}
$pattern = "/([a-z0-9\-_\.]+@[a-z0-9]+\.[a-z0-9\-_\.]+)/";
$regexp= "/(\\+\\d{2}-)?0\\d{2,3}-\\d{7,12}/";
if($comments){
foreach($comments as $k=>$v){
$comments[$k]['comment_content'] = ($v['comment_content']);
$post = get_post($v['comment_post_ID']);
$comments[$k]['product_name'] = $post->post_title;
preg_match_all($pattern,strtolower($v['comment_content']),$emailArr);
$comments[$k]['email'] = '';
$comments[$k]['phone'] = '';
if($emailArr[1]){
$comments[$k]['email'] = $emailArr[1][0];
}
preg_match_all($regexp,$v['comment_content'],$phoneArr);
if($phoneArr[0]){
$comments[$k]['phone'] = $phoneArr[0][0];
}
unset($comments[$k]['comment_post_ID']);
}
}
$weburl = home_url();
$inquirys = $comments;
$xunpan = [];
if($show_type == 0){
$query = sprintf("SELECT * FROM `wp_cf7_data_entry` WHERE `cf7_id` = 19 AND data_id IN(SELECT * FROM (SELECT data_id FROM `wp_cf7_data_entry` WHERE 1=1 GROUP BY `data_id` ORDER BY `data_id` desc LIMIT 0,50) temp_table) ORDER BY `data_id` desc");
$data1 = $wpdb->get_results($query);
$data_sorted = cf7d_sortdata($data1);
$data_sorted = array_unset_tt($data_sorted,'Name');
if($data_sorted){
foreach($data_sorted as $v){
if($v['submit_time'] >= $start_date && $v['submit_time']<$end_date){
$tmp['name'] = isset($v['Name']) ? $v['Name'] : '';
$tmp['email'] = isset($v['Email']) ? $v['Email'] : '';
$tmp['phone'] = isset($v['Phone']) ? $v['Phone'] : '';
$tmp['message'] = isset($v['Message']) ? ($v['Message']) : '';
$tmp['ip'] = isset($v['submit_ip']) ? $v['submit_ip'] : '';
$tmp['date'] = isset($v['submit_time']) ? $v['submit_time'] : '';
$tmp['refer'] = isset($v['refer']) ? $v['refer'] : '';
$xunpan[] = $tmp;
}
}
}
}else{
$data1 = cf7d_get_entrys(19, '', 'data_id desc');
$data_sorted = cf7d_sortdata($data1);
$data_sorted = array_unset_tt($data_sorted,'Name');
if($data_sorted){
foreach($data_sorted as $v){
$tmp['name'] = isset($v['Name']) ? $v['Name'] : '';
$tmp['email'] = isset($v['Email']) ? $v['Email'] : '';
$tmp['phone'] = isset($v['Phone']) ? $v['Phone'] : '';
$tmp['message'] = isset($v['Message']) ? ($v['Message']) : '';
$tmp['ip'] = isset($v['submit_ip']) ? $v['submit_ip'] : '';
$tmp['date'] = isset($v['submit_time']) ? $v['submit_time'] : '';
$tmp['refer'] = isset($v['refer']) ? $v['refer'] : '';
$xunpan[] = $tmp;
}
}
}
$email = '';
$email_info = get_post_meta(19,'_mail');
if(!$email_info){
$email_info_ar = $wpdb->get_results("select ID from wp_posts where post_type='wpcf7_contact_form' and post_status='publish'",ARRAY_A);
$email_info = get_post_meta($email_info_ar[0]['ID'],'_mail');
$email = $email_info[0]['recipient'];
}else{
$email = $email_info[0]['recipient'];
}
$phone_t = get_option('sms_phone_num',true);
$phone = '';
if(preg_match("/^1[345789]{1}\d{9}$/",$phone_t)){
$phone = $phone_t;
}
$data['comments'] = $comments;
$data['weburl'] = $weburl;
$data['xunpan'] = $xunpan;
$data['email'] = $email;
$data['phone'] = $phone;
print_r(json_encode($data));exit;
}else{
echo ' - -!!! Error!!!';exit;
}
//去重
function array_unset_tt($arr,$key){
$res = array();
foreach ($arr as $value) {
if(isset($res[$value[$key]])){
unset($value[$key]);
}else{
$res[$value[$key]] = $value;
}
}
return $res;
}
?>