-
Notifications
You must be signed in to change notification settings - Fork 6
/
class.quericy_notice_mail.php
163 lines (154 loc) · 5.62 KB
/
class.quericy_notice_mail.php
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}
class quericy_notice_mail
{
private $conf_arr = array();
private $KMMailer_obj = null;
/**
* Get system config
* @return bool
*/
public function get_config()
{
if (!empty($this->conf_arr)) {
return true;
}
$conf_arr['mail_name'] = option::get('quericy_sign_mail_name');
$conf_arr['nick_name'] = option::get('quericy_sign_nick_name');
$conf_arr['mail_host'] = option::get('quericy_sign_mail_host');
$conf_arr['mail_port'] = option::get('quericy_sign_mail_port');
$conf_arr['mail_secure'] = option::get('quericy_sign_mail_secure');
$conf_arr['mail_user_name'] = option::get('quericy_sign_mail_user_name');
$conf_arr['mail_user_password'] = option::get('quericy_sign_mail_user_password');
$conf_arr['mail_time_zone'] = option::get('quericy_sign_mail_time_zone');
$conf_arr['mail_title'] = option::get('quericy_sign_mail_title');
$conf_arr['mail_content'] = option::get('quericy_sign_mail_content');
//check config
if (empty($conf_arr['mail_name']) || empty($conf_arr['mail_host']) || empty($conf_arr['mail_port'])) {
return false;
}
if (empty($conf_arr['mail_title']) || empty($conf_arr['mail_content'])) {
return false;
}
//deal config
$conf_arr['nick_name'] = empty($conf_arr['nick_name']) ? '贴吧云签到' : $conf_arr['nick_name'];
$conf_arr['mail_secure'] = empty($conf_arr['mail_secure']) ? 'none' : $conf_arr['mail_secure'];
$conf_arr['mail_user_name'] = empty($conf_arr['mail_user_name']) ? null : $conf_arr['mail_user_name'];
$conf_arr['mail_user_password'] = empty($conf_arr['mail_user_password']) ? null : $conf_arr['mail_user_password'];
$conf_arr['mail_time_zone'] = empty($conf_arr['mail_time_zone']) ? '+0800' : $conf_arr['mail_time_zone'];
$conf_arr['mail_title'] = $this->deal_public_template($conf_arr['mail_title']);
$conf_arr['mail_content'] = $this->deal_public_template($conf_arr['mail_content']);
$this->conf_arr = $conf_arr;
return true;
}
/**
* Connect to SMTP server
* @return bool
*/
public function connect_notice_server()
{
if (empty($this->conf_arr)) {
return false;
}
if (!empty($this->KMMailer_obj)) {
return true;
}
require 'KMMailer.php';
$KMMailer_obj = new KMMailer($this->conf_arr['mail_host'], $this->conf_arr['mail_port'], $this->conf_arr['mail_user_name'], $this->conf_arr['mail_user_password'], $this->conf_arr['mail_secure']);
$KMMailer_obj->charset = "\"UTF-8\"";
$KMMailer_obj->contentType = "multipart/mixed";
$KMMailer_obj->transferEncodeing = "quoted-printable";
$this->KMMailer_obj = $KMMailer_obj;
return true;
}
/**
* Send sign notice mail
* @param string $mail_to email
* @param string $mail_title email title
* @param string $mail_content email content
* @return bool
*/
public function send_notice_mail($mail_to, $mail_title, $mail_content)
{
if (empty($this->conf_arr)) {
return false;
}
if (empty($this->KMMailer_obj)) {
return false;
}
return $this->KMMailer_obj->send($this->conf_arr['mail_name'], $mail_to, $mail_title, $mail_content, null, $this->conf_arr['nick_name'], $this->conf_arr['mail_time_zone']);
}
/**
* Set the link of the sign notice page
* @param string $user_name user name
* @param int $user_id user id
* @param string|null $date
* @return string
*/
public function get_notice_url($user_name, $user_id, $date = null)
{
$date = empty($date) ? date('Y-m-d') : $date;
return SYSTEM_URL . 'index.php?pub_plugin=quericy_sign_mail&username=' . $user_name . '&token=' . md5(md5($user_name . $user_id . $date) . md5($user_id));
}
/**
* Get the title of the mail template
* @return bool|mixed
*/
public function get_template_title()
{
if (empty($this->conf_arr)) {
return false;
}
return $this->conf_arr['mail_title'];
}
/**
* Get the content of the mail template
* @return bool|mixed
*/
public function get_template_content()
{
if (empty($this->conf_arr)) {
return false;
}
return $this->conf_arr['mail_content'];
}
/**
* Deal the template,replace the user variable
* @param string $template_str
* @param string $user_name
* @param string $notice_url link of the sign notice page
* @return mixed
*/
public function deal_user_template($template_str, $user_name, $notice_url)
{
$user_pattern_arr = array(
'/\[link\]/',
'/\[name\]/',
);
$user_replacement_arr = array(
$notice_url,
$user_name,
);
return preg_replace($user_pattern_arr, $user_replacement_arr, $template_str);
}
/**
* Deal the template,replace the public variable
* @param string $template_str
* @return mixed
*/
private function deal_public_template($template_str)
{
$public_pattern_arr = array(
'/\[date\]/',
'/\[SYSTEM_URL\]/',
'/\[SYSTEM_NAME\]/',
);
$public_replacement_arr = array(
date('Y-m-d'),
SYSTEM_URL,
SYSTEM_NAME,
);
return preg_replace($public_pattern_arr, $public_replacement_arr, $template_str);
}
}