-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail-to-send.php
More file actions
143 lines (125 loc) · 5.11 KB
/
Copy pathmail-to-send.php
File metadata and controls
143 lines (125 loc) · 5.11 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
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
<?php
/*
* Mail to friend wordpress plugins
Copyright (C) 2012 Fazle Elahee
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class SendMailToFriend {
private $to_mail ='';
private $from_mail = 'fe@bondmedia.co.uk';
private $sender_msg = '';
private $sender_name = '';
private $captcha_text = '';
private $send_link = '';
private $captcha_prefix = '';
private $captca_tmp_dir = '';
private $captca_img_url = '';
private $error = array();
private $captcha_instance = null;
public function __construct() {
$upload_dir = wp_upload_dir();
$path = $upload_dir['basedir'].DIRECTORY_SEPARATOR.'wpcf7_captcha';
if(!is_dir($path)){
mkdir($path);
}
if(class_exists ('ReallySimpleCaptcha')) :
$this->captcha_instance = new ReallySimpleCaptcha();
$this->captca_tmp_dir = $path;
$this->captca_img_url = $upload_dir['baseurl'].DIRECTORY_SEPARATOR.'wpcf7_captcha'.DIRECTORY_SEPARATOR;
endif;
}
private function setTo_mail($value){
$email = sanitize_email($value);
if(is_email($email)) {
$this->to_mail = $value;
}
else{
$this->error['email'] = 'Invalid email address!';
}
}
private function setSend_link($value) {
$this->send_link = $url = esc_url($value);
}
private function setFrom_mail($value){
$this->from_mail = $value;
}
private function setSender_msg($value){
$allowed_html = array();
$this->sender_msg = wp_kses(sanitize_text_field($value), $allowed_html);
}
private function setSender_name($value){
$name = sanitize_text_field($value);
if(trim($name) != '') {
$this->sender_name = $value;
}
else {
$this->error['name'] = "Please enter name!";
}
}
private function setCaptcha_text($value){
$this->captcha_text = sanitize_text_field($value);
}
private function setCaptcha_prefix($value){
$this->captcha_prefix = sanitize_text_field($value);
}
private function setCaptca_tmp_dir($value){
$this->captca_tmp_dir($value);
}
public function setProperty($key, $value) {
$func = "set".ucwords($key);
$this->$func($value);
}
public function validate_captcha() {
$this->captcha_instance->tmp_dir = $this->captca_tmp_dir.DIRECTORY_SEPARATOR;
if(!$this->captcha_instance->check( $this->captcha_prefix, $this->captcha_text )) {
$this->error['captcha'] = 'captcha does not matched';
}
$this->captcha_instance->remove( $this->captcha_prefix );
}
public function generate_captcha() {
$word = $this->captcha_instance->generate_random_word();
$this->captcha_instance->tmp_dir = $this->captca_tmp_dir.DIRECTORY_SEPARATOR;
$prefix = mt_rand();
$file_name = $this->captcha_instance->generate_image( $prefix, $word );
$rtn_ARR = array('prefix'=>$prefix, 'img'=>"<img id='_captcha_image_' src='".$this->captca_img_url.$file_name."'>");
return $rtn_ARR;
}
public function process() {
$rtn = array();
$mo = new MtfOption();
$from_replace = array('{sender-name}','{site-url}','{current-site-link}', '{sender-message-to-friend}');
$to_replace = array($this->sender_name,site_url(),$this->send_link,$this->sender_msg);
if(count($this->error) == 0 ) {
$headers = 'From: '.$mo->getProperty('from_name').' <'.$mo->getProperty('from_email').'>'. "\r\n";
$subject = str_replace($from_replace,$to_replace , $mo->getProperty('mail_subject'));
$message = str_replace($from_replace,$to_replace , $mo->getProperty('email_message'));
if($mo->getProperty('html_content') == '1') {
add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
}
wp_mail($this->to_mail,$subject,$message, $headers);
//var_dump($message);
$rtn = array('response'=>'success');
}
else {
;
$rtn = array('response'=>'fail');
$rtn['error'] = implode("<br />",$this->error);
}
if($mo->getProperty('captcha_enabled') == '1'):
$captcha_ARR = $this->generate_captcha();
$rtn['img'] = $captcha_ARR['img'];
$rtn['prefix'] = $captcha_ARR['prefix'];
endif;
return $rtn;
}
}// end of class