PluginProbe ʕ •ᴥ•ʔ
Download Manager / trunk
Download Manager vtrunk
3.3.62 3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / __ / Email.php
download-manager / src / __ Last commit date
HTML 1 year ago views 5 months ago Apply.php 6 months ago Cron.php 1 year ago CronJob.php 7 months ago CronJobs.php 2 months ago Crypt.php 1 month ago DownloadStats.php 5 months ago Email.php 4 days ago EmailCron.php 1 year ago FileSystem.php 1 year ago Installer.php 2 hours ago Messages.php 1 year ago Query.php 4 months ago Session.php 2 hours ago Settings.php 4 years ago SimpleMath.php 4 years ago TempStorage.php 2 hours ago Template.php 5 months ago UI.php 6 months ago Updater.php 4 years ago UserAgent.php 2 years ago __.php 1 month ago __MailUI.php 3 years ago
Email.php
572 lines
1 <?php
2 /**
3 * Email Handler Class for WordPress Download Manager Pro
4 * Since: v4.6.0
5 * Author: Shahjada
6 * Version: 2.0.2
7 */
8 namespace WPDM\__;
9
10 class Email {
11
12 public $_to;
13 public $cc;
14 public $bcc;
15 public $_from;
16 public $fromName;
17 public $_subject;
18 public $_message;
19 public $_template;
20 public $_attachments;
21 public $_params = [];
22
23 var $email_hooks = [
24 'wpdm_before_email_download_link' => [
25 'title' => 'Before email download link',
26 'params' => 2
27 ],
28 'wpdm_onstart_download' => [
29 'title' => 'Just before download starts',
30 'params' => 1
31 ],
32 'create_package_frontend' => [
33 'title' => 'Create new package from front-end',
34 'params' => 2
35 ],
36 'edit_package_frontend' => [
37 'title' => 'Update a package from frontend',
38 'params' => 2
39 ],
40 'wpdm_after_checkout' => [
41 'title' => 'After a successful checkout',
42 'params' => 2
43 ],
44 ];
45
46 public $templateDir;
47
48 function __construct() {
49 $this->templateDir = __DIR__.'/views/email-templates/';
50 }
51
52 function to($to, $cc = '', $bcc = '')
53 {
54 $this->_to = $to;
55 $this->_params['to_email'] = $to;
56 $this->cc = $cc;
57 $this->_params['cc'] = $cc;
58 $this->bcc = $bcc;
59 $this->_params['bcc'] = $bcc;
60 return $this;
61 }
62
63 function from($email, $name = '')
64 {
65 $this->_from = $email;
66 $this->_params['from_email'] = $email;
67 $this->fromName = $name;
68 $this->_params['from_name'] = $name;
69 return $this;
70 }
71
72 function subject($subject)
73 {
74 $this->_subject = $subject;
75 $this->_params['subject'] = $subject;
76 return $this;
77 }
78 function message($message)
79 {
80 $this->_message = $message;
81 $this->_params['message'] = $message;
82 return $this;
83 }
84 function attachments($attachments)
85 {
86 $this->_attachments = $attachments;
87 return $this;
88 }
89
90 function template($template)
91 {
92 $this->_template = $template;
93 return $this;
94 }
95
96 function params($params)
97 {
98 foreach ($params as $key => $val) {
99 $this->_params[$key] = $val;
100 }
101 return $this;
102 }
103
104 function getStatus($id = '') {
105 $status = get_option("_fm_email_template_status");
106 if(!is_array($status)) {
107 $templates = self::templates();
108 $templates = array_keys($templates);
109 $status = array_combine($templates, array_pad([], count($templates), 1));
110 }
111
112 return $id ? ( isset($status[$id]) ? (int)$status[$id] : 1 ) : $status;
113 }
114
115 public static function templates() {
116 $admin_email = get_option( 'admin_email' );
117 $sitename = get_option( "blogname" );
118 $templates = array(
119 'default' => array(
120 'label' => __( "General Email Template" , "download-manager" ),
121 'for' => 'varies',
122 'default' => array( 'subject' => '{{subject}}',
123 'from_name' => get_option('blogname'),
124 'from_email' => $admin_email,
125 'message' => '{{message}}</b><br/><br/>Best Regards,<br/>Support Team<br/><b><a href="{{homeurl}}">{{sitename}}</a></b>'
126 )
127 ),
128 'user-signup' => array(
129 'label' => __( "User Signup Notification" , "download-manager" ),
130 'for' => 'customer',
131 'default' => array(
132 'subject' => sprintf( __( "Welcome to %s" , "download-manager" ), $sitename ),
133 'from_name' => get_option( 'blogname' ),
134 'from_email' => $admin_email,
135 'message' => '<h3>Welcome to {{sitename}}</h3>Hello {{first_name}},<br/>Thanks for registering to {{sitename}}. For the record, here is your login info again:<br/>Username: {{username}}<br/>Password: {{password}}<br/><b>Login URL: <a href="{{loginurl}}">{{loginurl}}</a></b><br/><br/>Best Regards,<br/>Support Team<br/><b><a href="{{homeurl}}">{{sitename}}</a></b>'
136 )
137 ),
138 'user-signup-admin' => array(
139 'label' => __( "User Signup Notification" , "download-manager" ),
140 'for' => 'admin',
141 'default' => array(
142 'subject' => sprintf( __( "[ %s ] New User Registration" , "download-manager" ), $sitename ),
143 'from_name' => get_option( 'blogname' ),
144 'from_email' => $admin_email,
145 'to_email' => $admin_email,
146 'message' => __( "New user registration on your site WordPress Download Manager:" , "download-manager" ).'<hr/>Username: {{username}}<br/>Email: {{email}}<br/>IP: {{user_ip}}<hr/>{{edit_user_btn}}<br/><br/>Best Regards,<br/>Support Team<br/><b><a href="{{homeurl}}">{{sitename}}</a></b>'
147 )
148 ),
149 'user-signup-approved' => array(
150 'label' => __( "User Signup Approved" , "download-manager" ),
151 'for' => 'customer',
152 'default' => array(
153 'subject' => __( "Congratulation! Your signup request is approved" , "download-manager" ),
154 'from_name' => get_option( 'blogname' ),
155 'from_email' => $admin_email,
156 'message' => '<h3>Welcome to {{sitename}}</h3>Hello {{first_name}},<br/>Congratulation!! Your signup request is approved! <br/>Login URL: <a href="{{loginurl}}">{{loginurl}}</a></b><br/><br/>Best Regards,<br/>Support Team<br/><b><a href="{{homeurl}}">{{sitename}}</a></b>'
157 )
158 ),
159 'user-signup-declined' => array(
160 'label' => __( "User Signup Declined" , "download-manager" ),
161 'for' => 'customer',
162 'default' => array(
163 'subject' => __( "Your signup request is declined" , "download-manager" ),
164 'from_name' => get_option( 'blogname' ),
165 'from_email' => $admin_email,
166 'message' => '<h3>Signup Request Declined</h3>Hello {{first_name}},<br/>Unfortunately we are unable to approve your signup for the following reason:<hr/>{{reason}}<hr/><br/><br/>Best Regards,<br/>Support Team<br/><b><a href="{{homeurl}}">{{sitename}}</a></b>'
167 )
168 ),
169 'user-signup-suspended' => array(
170 'label' => __( "User Account Suspended" , "download-manager" ),
171 'for' => 'customer',
172 'default' => array(
173 'subject' => __( "Your account has been suspended" , "download-manager" ),
174 'from_name' => get_option( 'blogname' ),
175 'from_email' => $admin_email,
176 'message' => '<h3>Account Suspended</h3>Hello {{first_name}},<br/>Unfortunately your account has been suspended for the following reason:<hr/>{{reason}}<hr/><br/><br/>Best Regards,<br/>Support Team<br/><b><a href="{{homeurl}}">{{sitename}}</a></b>'
177 )
178 ),
179 'password-reset' => array(
180 'label' => __( "Password Reset Notification" , "download-manager" ),
181 'for' => 'customer',
182 'default' => array(
183 'subject' => sprintf( __( "Request to reset your %s password" , "download-manager" ), $sitename ),
184 'from_name' => get_option( 'blogname' ),
185 'from_email' => $admin_email,
186 'message' => 'You have requested for your password to be reset.<br/>Please confirm by clicking the button below: <a href="{{reset_password}}">{{reset_password}}</a><br/>No action required if you did not request it.</b><br/><br/>Best Regards,<br/>Support Team<br/><b><a href="{{homeurl}}">{{sitename}}</a></b>'
187 )
188 ),
189 'email-lock' => array(
190 'label' => __( "Email Lock Notification" , "download-manager" ),
191 'for' => 'customer',
192 'default' => array(
193 'subject' => __( "Download {{package_name}}" , "download-manager" ),
194 'from_name' => get_option( 'blogname' ),
195 'from_email' => $admin_email,
196 'message' => 'Thanks for Subscribing to {{sitename}}<br/>Please click on following link to start download:<br/><b><a style="display: block;text-align: center" class="button" href="{{download_url}}">Download</a></b><br/><br/><br/>Best Regards,<br/>Support Team<br/><b>{{sitename}}</b>'
197 )
198 ),
199 'new-package-frontend' => array(
200 'label' => __( "New Package Notification" , "download-manager" ),
201 'for' => 'admin',
202 'default' => array(
203 'subject' => __( "New Package is Added By {{name}}" , "download-manager" ),
204 'from_name' => get_option( 'blogname' ),
205 'from_email' => $admin_email,
206 'to_email' => $admin_email,
207 'message' => 'A new package is added<br/><br/><table style="width: 100%" cellpadding="10px"><tr><td width="120px">Package Name:</td><td>{{package_name}}</td></tr><tr><td width="120px">Added By:</td><td>{{author}}</td></tr><tr><td width="120px"></td><td><div style="padding-top: 10px;"><a class="btn" href="{{edit_url}}">Review The Package</a></div></td></tr></table>'
208 )
209 ),
210 'package-approved' => array(
211 'label' => __( "Package Approval Notification" , "download-manager" ),
212 'for' => 'seller',
213 'default' => array(
214 'subject' => __( "Congratulation! {{package_name}} has been approved" , "download-manager" ),
215 'from_name' => get_option( 'blogname' ),
216 'from_email' => $admin_email,
217 'message' => 'Your package has been approved<br/><br/><table style="width: 100%" cellpadding="10px"><tr><td width="120px">Package Name:</td><td>{{package_name}}</td></tr><tr><td width="120px"></td><td><div style="padding-top: 10px;"><a class="btn" href="{{package_url}}">View Package</a></div></td></tr></table>'
218 )
219 ),
220 );
221
222 $templates = apply_filters( 'wpdm_email_templates', $templates );
223
224 return $templates;
225
226 }
227
228 public static function info( $id ) {
229 $templates = self::templates();
230 return isset($templates[ $id ]) ? $templates[ $id ] : null;
231 }
232
233 public static function tags() {
234 $tags = array(
235 "{{SERVER_...key...}}" => ['value' => '', 'desc' => 'Server variables, replace <code>...key...</code> with proper key, for example, to show referer, use <code>{{SERVER_HTTP_REFERER}}</code>'],
236 "{{REQUEST_...key...}}" => ['value' => '', 'desc' => 'Request variables, replace <code>...key...</code> with proper key'],
237 "{{support_email}}" => array( 'value' => get_option( 'admin_email' ), 'desc' => 'Support Email' ),
238 "{{img_logo}}" => array( 'value' => '', 'desc' => 'Site Logo' ),
239 "{{banner}}" => array( 'value' => '', 'desc' => 'Banner/Background Image URL' ),
240 "{{site_url}}" => array( 'value' => home_url( '/' ), 'desc' => 'Home URL of your website' ),
241 "{{homeurl}}" => array( 'value' => home_url( '/' ), 'desc' => 'Home URL of your website' ),
242 "{{sitename}}" => array(
243 'value' => get_option( 'blogname' ),
244 'desc' => 'The name/title of your website'
245 ),
246 "{{site_tagline}}" => array(
247 'value' => get_bloginfo( 'description' ),
248 'desc' => 'The name/title of your website'
249 ),
250 "{{loginurl}}" => array( 'value' => wp_login_url(), 'desc' => 'Login page URL' ),
251 "{{name}}" => array( 'value' => '', 'desc' => 'Members First Name' ),
252 "{{username}}" => array( 'value' => '', 'desc' => 'Username' ),
253 "{{password}}" => array( 'value' => '', 'desc' => 'Members account password' ),
254 "{{date}}" => array(
255 'value' => date_i18n( get_option( 'date_format' ), time() + wpdm_tzoffset() ),
256 'desc' => 'Current Date'
257 ),
258 "{{package_name}}" => array( 'value' => '', 'desc' => 'Package Name' ),
259 "{{author}}" => array( 'value' => '', 'desc' => 'Package author profile' ),
260 "{{package_url}}" => array( 'value' => '', 'desc' => 'Package URL' ),
261 "{{edit_url}}" => array( 'value' => '', 'desc' => 'Package Edit URL' )
262 );
263
264 $tags["{{client_ip}}"] = ['value' => wpdm_get_client_ip(), 'desc' => 'User IP'];
265
266 if(is_user_logged_in()) {
267 global $current_user;
268 $tags["{{user_login}}"] = ['value' => $current_user->user_login, 'desc' => 'User login'];
269 $tags["{{user_email}}"] = ['value' => $current_user->user_email, 'desc' => 'User email'];
270 $tags["{{user_first_name}}"] = ['value' => $current_user->user_firstname, 'desc' => 'User first name'];
271 $tags["{{user_last_name}}"] = ['value' => $current_user->user_lastname, 'desc' => 'User last name'];
272 $tags["{{user_display_name}}"] = ['value' => $current_user->display_name, 'desc' => 'User display name'];
273 $tags["{{user_description}}"] = ['value' => get_user_meta($current_user->ID, 'description', true), 'desc' => 'User display name'];
274 $tags["{{um_...metakey...}}"] = ['value' => '', 'desc' => 'User meta data, replace <code>...metakey...</code> with user meta key'];
275 }
276 return apply_filters( "wpdm_email_template_tags", $tags );
277 }
278
279 public static function defaultTemplate( $id ) {
280 $templates = self::templates();
281
282 return isset($templates[ $id ], $templates[ $id ]['default']) ? $templates[ $id ]['default'] : null;
283 }
284
285 public static function getTemplate( $id ) {
286 $template = maybe_unserialize( get_option( "__wpdm_etpl_" . $id, false ) );
287 //print_r($template);die();
288 $default = self::defaultTemplate( $id );
289 if ( ! $template ) {
290 $template = $default;
291 }
292 $template['message'] = ! isset( $template['message'] ) || trim( strip_tags( $template['message'] ) ) == '' ? $default['message'] : $template['message'];
293
294 return $template;
295 }
296
297 public static function prepare( $id, $params ) {
298 $template = self::getTemplate( $id );
299
300 $params = apply_filters( "wpdm_email_params_" . $id, $params );
301 $template = apply_filters( "wpdm_email_template_" . $id, $template );
302 if(!is_array($params)) $params = [];
303 $__wpdm_email_setting = maybe_unserialize( get_option( '__wpdm_email_setting', array() ) );
304 if(!is_array($__wpdm_email_setting)) $__wpdm_email_setting = [];
305 $params = $params + $__wpdm_email_setting;
306 $logo = isset($params['logo']) ? esc_url($params['logo']) : '';
307 $banner = isset($params['banner']) ? esc_url($params['banner']) : '';
308 $logo_wh = isset( $params['logo_w'] ) ? "width:{$params['logo_w']};" : "";
309 $logo_wh .= isset($params['logo_h']) ? "height:{$params['logo_h']};" : "";
310 $params['img_logo'] = isset( $params['logo'] ) && $params['logo'] != '' ? "<img style='max-width: 70%;{$logo_wh}' src='{$logo}' alt='".esc_attr(get_option('blogname'))."' />" : get_bloginfo('name');
311 $params['banner'] = isset( $params['banner'] ) && $params['banner'] != '' ? esc_url($params['banner']) : "";
312 $params['banner_img'] = isset( $params['banner'] ) && $params['banner'] != '' ? "<img style='max-width: 100%;' src='{$banner}' alt='Banner Image' />" : "";
313 $params['images_dir'] = WPDM_BASE_URL.'src/__/views/email-templates/images/';
314 $template_file = get_option( "__wpdm_email_template", "default.html" );
315 $emltpl = null;
316 if ( isset( $params['template_file'] ) ) {
317 $template_file = $params['template_file'];
318 $emltpl = Template::locate( "email-templates/".sanitize_file_name($template_file), __DIR__ . '/views' );
319 }
320 if(!$emltpl)
321 $emltpl = Template::locate( "email-templates/".sanitize_file_name($template_file), __DIR__ . '/views' );
322 if($emltpl)
323 $emltpl = realpath($emltpl);
324
325 if($template_file === '' || !$emltpl)
326 $emltpl = Template::locate( "email-templates/default.html", __DIR__ . '/views' );
327
328 if(file_exists($emltpl))
329 $template_data = file_get_contents( $emltpl );
330
331 $template['message'] = str_replace( "{{message}}", stripslashes( wpautop( $template['message'] ) ), $template_data );
332 $tags = self::tags();
333
334 // Drop any link whose href placeholder resolves to a blank value (e.g. a
335 // social profile URL the admin left empty) so the email never renders a
336 // dead/blank icon. Done before token replacement, keyed on the
337 // placeholder name, so it is immune to how an empty value renders.
338 $resolved_hrefs = $params;
339 foreach ( $tags as $tag_name => $tag_info ) {
340 $bare_tag = trim( $tag_name, '{}' );
341 if ( ! isset( $resolved_hrefs[ $bare_tag ] ) || $resolved_hrefs[ $bare_tag ] === '' ) {
342 $resolved_hrefs[ $bare_tag ] = $tag_info['value'];
343 }
344 }
345 if ( preg_match_all( '/href\s*=\s*([\'"])\{\{([a-z0-9_]+)\}\}\1/i', $template['message'], $href_matches ) ) {
346 foreach ( array_unique( $href_matches[2] ) as $href_key ) {
347 $href_value = isset( $resolved_hrefs[ $href_key ] ) && is_scalar( $resolved_hrefs[ $href_key ] )
348 ? trim( (string) $resolved_hrefs[ $href_key ] )
349 : '';
350 if ( $href_value === '' ) {
351 $template['message'] = self::removeEmptyLink( $template['message'], $href_key );
352 }
353 }
354 }
355
356 $new_pasrams = array();
357 foreach ( $params as $key => $val ) {
358 $new_pasrams["{{{$key}}}"] = stripslashes($val);
359 $new_pasrams["[#{$key}#]"] = stripslashes($val);
360 }
361 $params = $new_pasrams;
362 foreach ( $tags as $key => $info ) {
363 if ( ! isset( $params[$key] )) {
364 $params[$key] = $info['value'];
365 }
366 }
367
368 $template['subject'] = isset($params['subject']) ? $params['subject'] : str_replace( array_keys( $params ), array_values( $params ), $template['subject'] );
369 if(isset($template['to_email']))
370 $template['to_email'] = str_replace( array_keys( $params ), array_values( $params ), $template['to_email'] );
371 $template['message'] = str_replace( array_keys( $params ), array_values( $params ), $template['message'] );
372 $template['message'] = self::compile($template['message']);
373 $template['message'] = self::compile($template['message'], "/\{\{([^\}]+)\}\}/");
374 return $template;
375 }
376
377 public static function send( $id, $params ) {
378
379 if(!$id || !WPDM()->email->getStatus($id)) return false;
380
381 $email = self::info( $id );
382 $template = self::prepare( $id, $params );
383 $headers[] = "From: " . $template['from_name'] . " <" . $template['from_email'] . ">";
384 $headers[] = "Content-type: text/html";
385 if(!isset($template['to_email'])) {
386 $template['to_email'] = get_option('admin_email');
387 }
388 //$to = $email['for'] !== 'admin' && !isset($params['to_seller']) && isset($params['to_email']) ? $params['to_email'] : $template['to_email'];
389 if(!isset($template['to_email'])) $template['to_email'] = get_option('admin_email');
390 $to = isset($params['to_email']) ? $params['to_email'] : $template['to_email'];
391 $headers = apply_filters( "wpdm_email_headers_" . str_replace("-", "_", $id), $headers );
392 if(isset($params['cc'])){
393 $headers[] = "CC: {$params['cc']}";
394 unset($params['cc']);
395 }
396 if(isset($params['bcc'])){
397 $headers[] = "Bcc: {$params['bcc']}";
398 unset($params['bcc']);
399 }
400
401 $attachments = apply_filters( "wpdm_email_attachments_" . str_replace("-", "_", $id), array(), $params );
402
403 return wp_mail( $to, esc_attr($template['subject']), $template['message'], $headers, $attachments );
404 }
405
406 function sendMail()
407 {
408 $params = $this->_params;
409
410 $email = self::info( $this->_template );
411 $template = self::prepare( $this->_template, $this->_params );
412 $headers[] = "From: " . $template['from_name'] . " <" . $template['from_email'] . ">";
413 $headers[] = "Content-type: text/html";
414 if(!isset($template['to_email'])) {
415 $template['to_email'] = get_option('admin_email');
416 }
417 //$to = $email['for'] !== 'admin' && !isset($params['to_seller']) && isset($params['to_email']) ? $params['to_email'] : $template['to_email'];
418 if(!isset($template['to_email'])) $template['to_email'] = get_option('admin_email');
419 $to = isset($params['to_email']) ? $params['to_email'] : $template['to_email'];
420 $headers = apply_filters( "wpdm_email_headers_" . str_replace("-", "_", $this->_template), $headers );
421 if(isset($params['cc'])){
422 $headers[] = "CC: {$params['cc']}";
423 unset($params['cc']);
424 }
425 if(isset($params['bcc'])){
426 $headers[] = "Bcc: {$params['bcc']}";
427 unset($params['bcc']);
428 }
429
430 $attachments = apply_filters( "wpdm_email_attachments_" . str_replace("-", "_", $this->_template), array(), $params );
431
432 return wp_mail( $to, esc_attr($template['subject']), $template['message'], $headers, $attachments );
433 }
434
435
436 public function preview() {
437 global $current_user;
438
439
440 if ( ! isset( $_REQUEST['action'] ) || $_REQUEST['action'] != 'email_template_preview' ) {
441 return;
442 }
443
444 __::isAuthentic("__empnonce", WPDM_PRI_NONCE, WPDM_MENU_ACCESS_CAP, false);
445
446
447 $id = wpdm_query_var('id');
448 $email = self::info( $id );
449 $params = array(
450 "name" => $current_user->display_name,
451 "username" => $current_user->user_login,
452 "password" => "**************",
453 "package_name" => __( "Sample Package Name" , "download-manager" ),
454 "author" => $current_user->display_name,
455 "package_url" => "#",
456 "edit_url" => "#"
457 );
458
459 if ( isset( $_REQUEST['etmpl'] ) ) {
460 $params['template_file'] = wpdm_query_var('etmpl');
461 }
462 $template = self::prepare( $id, $params );
463 echo $template['message'];
464 die();
465
466 }
467
468 static public function fetch($template, $message) {
469 global $current_user;
470 if ( ! current_user_can( WPDM_MENU_ACCESS_CAP ) ) {
471 die( 'Error' );
472 }
473
474 $params['template_file'] = $template;
475
476 $template = self::prepare( 'default', $params );
477 return $template['message'];
478 }
479
480 static function compile($template, $rule = "/\[\#([^\#]+)\#\]/")
481 {
482 $compiled = preg_replace_callback($rule, [new self, '_var'], $template);
483 return $compiled;
484 }
485
486 static function _var($matched)
487 {
488 if(substr_count($matched[1], "acfx_user_meta_") && file_exists('get_field')){
489 $meta_name = str_replace("acfx_user_meta_", "", $matched[1]);
490 $meta_value = get_field($meta_name, 'user_'.get_current_user_id());
491 return $meta_value;
492 }
493 if(substr_count($matched[1], "acf_user_meta_")){
494 $meta_name = str_replace("acf_user_meta_", "", $matched[1]);
495 $data = maybe_unserialize(get_user_meta(get_current_user_id(), 'wpdm_cregf', true));
496 $value = wpdm_valueof($data, $meta_name);
497 if(is_array($value)) $value = implode(", ", $value);
498 return $value;
499 }
500 if(substr_count($matched[1], "user_meta_")){
501 $meta_name = str_replace("user_meta_", "", $matched[1]);
502 if(substr_count($meta_name, '/')){
503 $meta_name = explode("/", $meta_name);
504 $meta_value = get_user_meta(get_current_user_id(), $meta_name[0], true);
505 array_shift($meta_name);
506 $meta_value = wpdm_valueof($meta_value, implode("/", $meta_name));
507 return $meta_value;
508 }
509 return get_user_meta(get_current_user_id(), $meta_name, true);
510 }
511 if(substr_count($matched[1], "um_")){
512 $meta_name = str_replace("um_", "", $matched[1]);
513 if(substr_count($meta_name, '/')){
514 $meta_name = explode("/", $meta_name);
515 $meta_value = get_user_meta(get_current_user_id(), $meta_name[0], true);
516 array_shift($meta_name);
517 $meta_value = wpdm_valueof($meta_value, implode("/", $meta_name));
518 return $meta_value;
519 }
520 return get_user_meta(get_current_user_id(), $meta_name, true);
521 }
522 if(substr_count($matched[1], "SERVER_")){
523 $meta_name = str_replace("SERVER_", "", $matched[1]);
524 $meta_value = wpdm_valueof($_SERVER, $meta_name);
525 return $meta_value;
526 }
527 if(substr_count($matched[1], "REQUEST_")){
528 $meta_name = str_replace("REQUEST_", "", $matched[1]);
529 $meta_value = wpdm_valueof($_REQUEST, $meta_name);
530 if(is_array($meta_value)) $meta_value = implode(", ", $meta_value);
531 return $meta_value;
532 }
533 return $matched[1];
534 }
535
536 /**
537 * Remove an anchor whose href is the given (empty) placeholder, together with
538 * its sole-content table cell and any adjacent separator cell, so an unset
539 * social/link URL leaves no blank icon or stray divider in the email.
540 *
541 * @param string $html The email markup, still containing {{tokens}}.
542 * @param string $key The placeholder name, e.g. "facebook".
543 * @return string
544 */
545 protected static function removeEmptyLink( $html, $key ) {
546 if ( ! is_string( $html ) || $html === '' ) return $html;
547
548 $ph = '\{\{' . preg_quote( $key, '~' ) . '\}\}';
549 $separator = '(?:<td\b[^>]*>(?:\s|&[a-z0-9#]+;|\|)*</td>\s*)?';
550
551 // 1) Anchor alone in its own <td> (icon tiles or text links), plus a
552 // trailing separator cell when present, so no empty gap or stray
553 // divider is left behind.
554 $html = preg_replace(
555 '~<td\b[^>]*>\s*<a\b[^>]*\bhref\s*=\s*([\'"])' . $ph . '\1[^>]*>.*?</a>\s*</td>\s*' . $separator . '~is',
556 '',
557 $html
558 );
559
560 // 2) Fallback: any remaining bare anchor pointing at the empty placeholder.
561 $html = preg_replace(
562 '~<a\b[^>]*\bhref\s*=\s*([\'"])' . $ph . '\1[^>]*>.*?</a>~is',
563 '',
564 $html
565 );
566
567 return $html;
568 }
569
570
571 }
572