init.php
3.3 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
<?php
if (!defined('ABSPATH')) {
exit('Direct\'s not allowed');
}
add_action('admin_menu', 'easyiit_cf7_admin_add_init');
function easyiit_cf7_admin_add_init() {
add_menu_page('询盘添加', '询盘添加', 7, 'cf7_admin_add');
add_submenu_page('cf7_admin_add', '询盘添加', '询盘添加', 7, 'cf7_admin_add', 'cf7_admin_add');
}
function cf7_admin_add() {
global $wpdb;
if(isset($_POST['dosubmit'])){
$cf7_id = 19;
$time = date('Y-m-d H:i:s');
$_POST['data']['submit_time'] = $time;
$posted_data = $_POST['data'];
$wpdb->query($wpdb->prepare('INSERT INTO '.$wpdb->prefix.'cf7_data(`created`) VALUES (%s)', $time));
$data_id = $wpdb->insert_id;
foreach ($posted_data as $k => $v) {
$wpdb->query($wpdb->prepare('INSERT INTO '.$wpdb->prefix.'cf7_data_entry(`cf7_id`, `data_id`, `name`, `value`) VALUES (%d,%d,%s,%s)', $cf7_id, $data_id, $k, $v));
}
$wpdb->query($wpdb->prepare('INSERT INTO '.$wpdb->prefix.'cf7_data_entry(`cf7_id`, `data_id`, `name`, `value`) VALUES (%d,%d,%s,%s)', $cf7_id, $data_id, "readed", 0));
$ip=$posted_data['submit_ip'];
$ip_area = file_get_contents("http://ip.globalso.com/?ip=".$ip);
$siteurl = get_option('siteurl',true);
file_get_contents($siteurl."/smsapi?country=".$ip_area);
$wpcf7 = wpcf7_contact_form(19);
$to = $wpcf7->mail['recipient'];
$subject = str_replace("[Name]",$posted_data['Name'],$wpcf7->mail['subject']);
$message = str_replace("[Name]",$posted_data['Name'],$wpcf7->mail['body']);
$message = str_replace("[Email]",$posted_data['Email'],$message);
$message = str_replace("[Phone]",$posted_data['Phone'],$message);
$message = str_replace("[Message]",str_replace("<br />","\n",$posted_data['Message']),$message);
$message = str_replace("[_url]",$posted_data['refer'],$message);
$message = str_replace("[_remote_ip] ",$ip,$message);
$message = str_replace("[_remote_ip_area]",$ip_area,$message);
ob_start();
$result = wp_mail($to,$subject,$message);
$smtp_debug = ob_get_clean();
echo '<script language="javascript">alert("添加成功。")</script>';
}
?>
<div class="wrap">
<form id="posts-filter" method="post">
<h2 class="title">询盘添加</h2>
<table class="form-table permalink-structure">
<tbody>
<tr>
<th>
<label>姓名:</label>
</th>
<td>
<input type="text" name="data[Name]" value="" placeholder="* Your Name..."/>
</td>
</tr>
<tr>
<th>
<label>邮箱:</label>
</th>
<td>
<input type="text" name="data[Email]" value="" placeholder="* Your Email..."/>
</td>
</tr>
<tr>
<th>
<label>电话:</label>
</th>
<td><input type="text" name="data[Phone]" value="" placeholder="* Your Phone..."/></td>
</tr>
<tr>
<th>
<label>内容:</label>
</th>
<td>
<textarea name="data[Message]" placeholder="* Your Message" style="width:400px;height:100px"></textarea>
</td>
</tr>
<tr>
<th>
<label>发送页面:</label>
</th>
<td>
<input type="text" name="data[refer]" value=""/>
</td>
</tr>
<tr>
<th>
<label>IP:</label>
</th>
<td>
<input type="text" name="data[submit_ip]" value=""/>
</td>
</tr>
</tbody>
</table>
<p class="submit"><input type="submit" name="dosubmit" id="submit" class="button button-primary" value="添加"></p>
</form>
</div>
<div class="clear"></div>
<?php
}