/var/www/(Del)hsihk.com/wp-content/plugins/contact-form-7/includes/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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php

class WPCF7_Mail {

    private static 
$current null;

    private 
$name '';
    private 
$template = array();

    public static function 
send$template$name '' ) {
        
$instance = new self;
        
$instance->name trim$name );
        
$instance->setup_template$template );

        
self::$current $instance;

        return 
$instance->compose();
    }

    private function 
__construct() {}

    public static function 
get_current() {
        return 
self::$current;
    }

    private function 
setup_template$template ) {
        
$defaults = array(
            
'subject' => '''sender' => '''body' => '',
            
'recipient' => '''additional_headers' => '',
            
'attachments' => '''use_html' => false,
            
'exclude_blank' => false );

        
$this->template wp_parse_args$template$defaults );
    }

    private function 
compose$send true ) {
        
$template $this->template;
        
$use_html = (bool) $template['use_html'];

        
$subject $this->replace_tags$template['subject'] );
        
$sender $this->replace_tags$template['sender'] );
        
$recipient $this->replace_tags$template['recipient'] );
        
$additional_headers $this->replace_tags$template['additional_headers'] );

        if ( 
$use_html ) {
            
$body $this->replace_tags$template['body'], true );
            
$body wpautop$body );
        } else {
            
$body $this->replace_tags$template['body'] );
        }

        
$attachments $this->attachments$template['attachments'] );

        
$components compact'subject''sender''body',
            
'recipient''additional_headers''attachments' );

        
$components apply_filters'wpcf7_mail_components',
            
$componentswpcf7_get_current_contact_form() );

        
$subject wpcf7_strip_newline$components['subject'] );
        
$sender wpcf7_strip_newline$components['sender'] );
        
$recipient wpcf7_strip_newline$components['recipient'] );
        
$body $components['body'];
        
$additional_headers trim$components['additional_headers'] );
        
$attachments $components['attachments'];

        
$headers "From: $sender\n";

        if ( 
$use_html ) {
            
$headers .= "Content-Type: text/html\n";
        }

        if ( 
$additional_headers ) {
            
$headers .= $additional_headers "\n";
        }

        if ( 
$send ) {
            return 
wp_mail$recipient$subject$body$headers$attachments );
        }

        
$components compact'subject''sender''body',
            
'recipient''headers''attachments' );

        return 
$components;
    }

    public function 
replace_tags$content$html false ) {
        
$args = array(
            
'html' => $html,
            
'exclude_blank' => $this->template['exclude_blank'] );

        return 
wpcf7_mail_replace_tags$content$args );
    }

    private function 
attachments$template ) {
        
$attachments = array();

        if ( 
$submission WPCF7_Submission::get_instance() ) {
            
$uploaded_files $submission->uploaded_files();

            foreach ( (array) 
$uploaded_files as $name => $path ) {
                if ( 
false !== strpos$template"[${name}]" )
                && ! empty( 
$path ) ) {
                    
$attachments[] = $path;
                }
            }
        }

        foreach ( 
explode"\n"$template ) as $line ) {
            
$line trim$line );

            if ( 
'[' == substr$line0) ) {
                continue;
            }

            
$path path_joinWP_CONTENT_DIR$line );

            if ( @
is_readable$path ) && @is_file$path ) ) {
                
$attachments[] = $path;
            }
        }

        return 
$attachments;
    }
}

function 
wpcf7_mail_replace_tags$content$args '' ) {
    
$args wp_parse_args$args, array(
        
'html' => false,
        
'exclude_blank' => false ) );

    if ( 
is_array$content ) ) {
        foreach ( 
$content as $key => $value ) {
            
$content[$key] = wpcf7_mail_replace_tags$value$args );
        }

        return 
$content;
    }

    
$content explode"\n"$content );

    foreach ( 
$content as $num => $line ) {
        
$line = new WPCF7_MailTaggedText$line$args );
        
$replaced $line->replace_tags();

        if ( 
$args['exclude_blank'] ) {
            
$replaced_tags $line->get_replaced_tags();

            if ( empty( 
$replaced_tags ) || array_filter$replaced_tags ) ) {
                
$content[$num] = $replaced;
            } else {
                unset( 
$content[$num] ); // Remove a line.
            
}
        } else {
            
$content[$num] = $replaced;
        }
    }

    
$content implode"\n"$content );

    return 
$content;
}

class 
WPCF7_MailTaggedText {

    private 
$html false;
    private 
$content '';
    private 
$replaced_tags = array();

    public function 
__construct$content$args '' ) {
        
$args wp_parse_args$args, array( 'html' => false ) );

        
$this->html = (bool) $args['html'];
        
$this->content $content;
    }

    public function 
get_replaced_tags() {
        return 
$this->replaced_tags;
    }

    public function 
replace_tags() {
        
$regex '/(\[?)\[[\t ]*'
            
'([a-zA-Z_][0-9a-zA-Z:._-]*)' // [2] = name
            
'((?:[\t ]+"[^"]*"|[\t ]+\'[^\']*\')*)' // [3] = values
            
'[\t ]*\](\]?)/';

        if ( 
$this->html ) {
            
$callback = array( $this'replace_tags_callback_html' );
        } else {
            
$callback = array( $this'replace_tags_callback' );
        }

        return 
preg_replace_callback$regex$callback$this->content );
    }

    private function 
replace_tags_callback_html$matches ) {
        return 
$this->replace_tags_callback$matchestrue );
    }

    private function 
replace_tags_callback$matches$html false ) {
        
// allow [[foo]] syntax for escaping a tag
        
if ( $matches[1] == '[' && $matches[4] == ']' ) {
            return 
substr$matches[0], 1, -);
        }

        
$tag $matches[0];
        
$tagname $matches[2];
        
$values $matches[3];

        if ( ! empty( 
$values ) ) {
            
preg_match_all'/"[^"]*"|\'[^\']*\'/'$values$matches );
            
$values wpcf7_strip_quote_deep$matches[0] );
        }

        
$do_not_heat false;

        if ( 
preg_match'/^_raw_(.+)$/'$tagname$matches ) ) {
            
$tagname trim$matches[1] );
            
$do_not_heat true;
        }

        
$format '';

        if ( 
preg_match'/^_format_(.+)$/'$tagname$matches ) ) {
            
$tagname trim$matches[1] );
            
$format $values[0];
        }

        
$submission WPCF7_Submission::get_instance();
        
$submitted $submission $submission->get_posted_data$tagname ) : null;

        if ( 
null !== $submitted ) {

            if ( 
$do_not_heat ) {
                
$submitted = isset( $_POST[$tagname] ) ? $_POST[$tagname] : '';
            }

            
$replaced $submitted;

            if ( ! empty( 
$format ) ) {
                
$replaced $this->format$replaced$format );
            }

            
$replaced wpcf7_flat_join$replaced );

            if ( 
$html ) {
                
$replaced esc_html$replaced );
                
$replaced wptexturize$replaced );
            }

            
$replaced apply_filters'wpcf7_mail_tag_replaced',
                
$replaced$submitted$html );

            
$replaced wp_unslashtrim$replaced ) );

            
$this->replaced_tags[$tag] = $replaced;
            return 
$replaced;
        }

        
$special apply_filters'wpcf7_special_mail_tags'''$tagname$html );

        if ( ! empty( 
$special ) ) {
            
$this->replaced_tags[$tag] = $special;
            return 
$special;
        }

        return 
$tag;
    }

    public function 
format$original$format ) {
        
$original = (array) $original;

        foreach ( 
$original as $key => $value ) {
            if ( 
preg_match'/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/'$value ) ) {
                
$original[$key] = mysql2date$format$value );
            }
        }

        return 
$original;
    }
}

/* Special Mail Tags */

add_filter'wpcf7_special_mail_tags''wpcf7_special_mail_tag'10);

function 
wpcf7_special_mail_tag$output$name$html ) {
    
$name preg_replace'/^wpcf7\./''_'$name ); // for back-compat

    
$submission WPCF7_Submission::get_instance();

    if ( ! 
$submission ) {
        return 
$output;
    }

    if ( 
'_remote_ip' == $name ) {
        if ( 
$remote_ip $submission->get_meta'remote_ip' ) ) {
            return 
$remote_ip;
        } else {
            return 
'';
        }
    }

    if ( 
'_user_agent' == $name ) {
        if ( 
$user_agent $submission->get_meta'user_agent' ) ) {
            return 
$html esc_html$user_agent ) : $user_agent;
        } else {
            return 
'';
        }
    }

    if ( 
'_url' == $name ) {
        if ( 
$url $submission->get_meta'url' ) ) {
            return 
esc_url$url );
        } else {
            return 
'';
        }
    }

    if ( 
'_date' == $name || '_time' == $name ) {
        if ( 
$timestamp $submission->get_meta'timestamp' ) ) {
            if ( 
'_date' == $name ) {
                return 
date_i18nget_option'date_format' ), $timestamp );
            }

            if ( 
'_time' == $name ) {
                return 
date_i18nget_option'time_format' ), $timestamp );
            }
        }

        return 
'';
    }

    if ( 
'_post_' == substr$name0) ) {
        
$unit_tag $submission->get_meta'unit_tag' );

        if ( 
$unit_tag
        
&& preg_match'/^wpcf7-f(\d+)-p(\d+)-o(\d+)$/'$unit_tag$matches ) ) {
            
$post_id absint$matches[2] );

            if ( 
$post get_post$post_id ) ) {
                if ( 
'_post_id' == $name ) {
                    return (string) 
$post->ID;
                }

                if ( 
'_post_name' == $name ) {
                    return 
$post->post_name;
                }

                if ( 
'_post_title' == $name ) {
                    return 
$html esc_html$post->post_title ) : $post->post_title;
                }

                if ( 
'_post_url' == $name ) {
                    return 
get_permalink$post->ID );
                }

                
$user = new WP_User$post->post_author );

                if ( 
'_post_author' == $name ) {
                    return 
$user->display_name;
                }

                if ( 
'_post_author_email' == $name ) {
                    return 
$user->user_email;
                }
            }
        }

        return 
'';
    }

    return 
$output;
}

?>