dd
Showing
1 changed file
with
82 additions
and
97 deletions
| 1 | <?php | 1 | <?php |
| 2 | namespace Tz\WordPress\Tools\Notifications; | 2 | namespace Tz\WordPress\Tools\Notifications; |
| 3 | 3 | ||
| 4 | use Tz\Common; | ||
| 5 | use Tz\WordPress\CBV; | 4 | use Tz\WordPress\CBV; |
| 6 | use Tz\WordPress\CBV\User; | 5 | use Tz\WordPress\CBV\User; |
| 7 | use Tz\WordPress\Tools; | 6 | use Tz\WordPress\Tools; |
| ... | @@ -13,13 +12,13 @@ const NOTIFICATION_STATUS_UNREAD = 'unread'; | ... | @@ -13,13 +12,13 @@ const NOTIFICATION_STATUS_UNREAD = 'unread'; |
| 13 | 12 | ||
| 14 | call_user_func( | 13 | call_user_func( |
| 15 | function () { | 14 | function () { |
| 16 | Tools\add_actions(__NAMESPACE__.'\Actions'); | 15 | Tools\add_actions(__NAMESPACE__ . '\Actions'); |
| 17 | Vars::$options = new Tools\WP_Option(OPTION_NAME); | 16 | Vars::$options = new Tools\WP_Option(OPTION_NAME); |
| 18 | Vars::$notices = []; | 17 | Vars::$notices = []; |
| 19 | 18 | ||
| 20 | if (is_admin()) { | 19 | if (is_admin()) { |
| 21 | require_once(__DIR__.'/Validation.php'); | 20 | require_once (__DIR__ . '/Validation.php'); |
| 22 | require_once(__DIR__.'/Admin.php'); | 21 | require_once (__DIR__ . '/Admin.php'); |
| 23 | } | 22 | } |
| 24 | } | 23 | } |
| 25 | ); | 24 | ); |
| ... | @@ -82,12 +81,12 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -82,12 +81,12 @@ function print_user_notices($showOnlyUnread = false) |
| 82 | 81 | ||
| 83 | $enableTriggers = [ | 82 | $enableTriggers = [ |
| 84 | 'MEMBERSHIP_FEES_DUE', | 83 | 'MEMBERSHIP_FEES_DUE', |
| 85 | 'STUDENT_FEES_DUE' | 84 | 'STUDENT_FEES_DUE', |
| 86 | ]; | 85 | ]; |
| 87 | 86 | ||
| 88 | $system = get_post_meta($notice['notification_id'], 'system', true); | 87 | $system = get_post_meta($notice['notification_id'], 'system', true); |
| 89 | $content = ''; | 88 | $content = ''; |
| 90 | if(!isset($notice['message']) && in_array($triggered, $enableTriggers)){ | 89 | if (!isset($notice['message']) && in_array($triggered, $enableTriggers)) { |
| 91 | $emailAddressPreference = get_user_meta($user->ID, 'email_address_preference', true); | 90 | $emailAddressPreference = get_user_meta($user->ID, 'email_address_preference', true); |
| 92 | if (empty($emailAddressPreference)) { | 91 | if (empty($emailAddressPreference)) { |
| 93 | $userData = get_userdata($user->ID); | 92 | $userData = get_userdata($user->ID); |
| ... | @@ -131,49 +130,47 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -131,49 +130,47 @@ function print_user_notices($showOnlyUnread = false) |
| 131 | 130 | ||
| 132 | } | 131 | } |
| 133 | } else { | 132 | } else { |
| 134 | if(isset($notice['message'])) { | 133 | if (isset($notice['message'])) { |
| 135 | $content = $notice['message']; | 134 | $content = $notice['message']; |
| 136 | } else { | 135 | } else { |
| 137 | $content = isset($system[ICL_LANGUAGE_CODE.'_message']) | 136 | $content = isset($system[ICL_LANGUAGE_CODE . '_message']) |
| 138 | ? $system[ICL_LANGUAGE_CODE.'_message'] | 137 | ? $system[ICL_LANGUAGE_CODE . '_message'] |
| 139 | : $system['en_message']; | 138 | : $system['en_message']; |
| 140 | } | 139 | } |
| 141 | } | 140 | } |
| 142 | 141 | ||
| 143 | |||
| 144 | if (isset($notice['args']) && count($notice['args']) > 0) { | 142 | if (isset($notice['args']) && count($notice['args']) > 0) { |
| 145 | foreach ($notice['args'] as $key => $val) { | 143 | foreach ($notice['args'] as $key => $val) { |
| 146 | if (filter_var($val, FILTER_VALIDATE_URL) !== false) { | 144 | if (filter_var($val, FILTER_VALIDATE_URL) !== false) { |
| 147 | $content = str_replace( | 145 | $content = str_replace( |
| 148 | '{'.$key.'}', | 146 | '{' . $key . '}', |
| 149 | "<a href='" | 147 | "<a href='" |
| 150 | .$val | 148 | . $val |
| 151 | ."'>" | 149 | . "'>" |
| 152 | .__('Click here', 'CBV_DOMAIN') | 150 | . __('Click here', 'CBV_DOMAIN') |
| 153 | .'</a>', | 151 | . '</a>', |
| 154 | $content | 152 | $content |
| 155 | ); | 153 | ); |
| 156 | } else { | 154 | } else { |
| 157 | $content = str_replace('{'.$key.'}', $val, $content); | 155 | $content = str_replace('{' . $key . '}', $val, $content); |
| 158 | } | 156 | } |
| 159 | } | 157 | } |
| 160 | } | 158 | } |
| 161 | 159 | ||
| 162 | $rows .= '<tr class="notice-row" id="'.$index.'">'; | 160 | $rows .= '<tr style="margin-bottom:10px;" class="notice-row" id="' . $index . '">'; |
| 163 | $rows .= '<td width="12" style="padding: 0 0 0 10px; vertical-align: middle;"><a href="javascript:;" class="notice ' | 161 | $rows .= '<td style="padding: 0px 0 px 20px; vertical-align: top; width:5%;"><a href="javascript:;" class="notice ' |
| 164 | .(($notice['status'] == 'read') ? 'read' : 'unread') | 162 | . '"><img src="/wp-content/themes/cbv/assets/images/new/Icon_Archive.svg" style="width: 25px; height: 25px;"></a></td>'; |
| 165 | .'"><img src="/wp-content/themes/cbv/assets/images/blank.gif" style="width: 12px; height: 12px;"></a></td>'; | ||
| 166 | 163 | ||
| 167 | if ($system['system_message_type'] == 'none') { | 164 | if ($system['system_message_type'] == 'none') { |
| 168 | $system['system_message_type'] = 'notice'; | 165 | $system['system_message_type'] = 'notice'; |
| 169 | } | 166 | } |
| 170 | 167 | ||
| 171 | $rows .= '<td width="80" style="vertical-align: middle;"><span>' | 168 | $rows .= '<td style="vertical-align: middle; width:55%;">' . nl2br($content) . '</td><td style="vertical-align: middle; width:26%;">' |
| 172 | .ucfirst(str_replace('_', ' ', $system['system_message_type'])) | 169 | |
| 173 | .'</span></td>'; | 170 | . CBV\tz_display('notice_sent_date', $notice['sent_date']) . '</span></td>'; |
| 174 | $rows .= '<td style="vertical-align: middle;">'.nl2br($content).'<br /><span class="legal">' | 171 | $rows .= '<td style="vertical-align: middle; width:10%;padding: 5px 0px 5px 0px;" style="vertical-align: middle;"><span>' |
| 175 | .__('Sent:', 'CBV_DOMAIN') | 172 | . ucfirst(str_replace('_', ' ', $system['system_message_type'])) |
| 176 | .CBV\tz_display('notice_sent_date', $notice['sent_date']).'</span></td>'; | 173 | . '</span></td>'; |
| 177 | $rows .= '</tr>'; | 174 | $rows .= '</tr>'; |
| 178 | } | 175 | } |
| 179 | 176 | ||
| ... | @@ -195,7 +192,7 @@ function get_notification_by_trigger($trigger) | ... | @@ -195,7 +192,7 @@ function get_notification_by_trigger($trigger) |
| 195 | 'post_type' => 'notifications', | 192 | 'post_type' => 'notifications', |
| 196 | 'numberposts' => -1, | 193 | 'numberposts' => -1, |
| 197 | 'orderby' => 'modified', | 194 | 'orderby' => 'modified', |
| 198 | 'order' => 'desc' | 195 | 'order' => 'desc', |
| 199 | ]; | 196 | ]; |
| 200 | 197 | ||
| 201 | $my_notif = false; | 198 | $my_notif = false; |
| ... | @@ -291,9 +288,9 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -291,9 +288,9 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 291 | $notification->status = isset($details['status']) ? $details['status'] : 'active'; | 288 | $notification->status = isset($details['status']) ? $details['status'] : 'active'; |
| 292 | $notification->type = $details['type']; | 289 | $notification->type = $details['type']; |
| 293 | $notification->sendto = @$details['sendto']; | 290 | $notification->sendto = @$details['sendto']; |
| 294 | $notification->is_email = (($email[$lang.'_text'] != '' || $email[$lang.'_html'] != '') && $email[$lang.'_subject'] != ''); | 291 | $notification->is_email = (($email[$lang . '_text'] != '' || $email[$lang . '_html'] != '') && $email[$lang . '_subject'] != ''); |
| 295 | $notification->is_system = (isset($system[$lang.'_message']) && $system[$lang.'_message'] != ''); | 292 | $notification->is_system = (isset($system[$lang . '_message']) && $system[$lang . '_message'] != ''); |
| 296 | $notification->is_push = (isset($push[$lang.'_message']) && $push[$lang.'_message'] != ''); | 293 | $notification->is_push = (isset($push[$lang . '_message']) && $push[$lang . '_message'] != ''); |
| 297 | // if is_system ========================================== | 294 | // if is_system ========================================== |
| 298 | if ($notification->is_system && $uid != 0) { | 295 | if ($notification->is_system && $uid != 0) { |
| 299 | get_user_notices($uid); | 296 | get_user_notices($uid); |
| ... | @@ -304,8 +301,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -304,8 +301,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 304 | 'notification_id' => $nid, | 301 | 'notification_id' => $nid, |
| 305 | 'status' => 'unread', | 302 | 'status' => 'unread', |
| 306 | 'sent_date' => current_time('timestamp'), | 303 | 'sent_date' => current_time('timestamp'), |
| 307 | 'message' => $system[$lang.'_message'], | 304 | 'message' => $system[$lang . '_message'], |
| 308 | 'args' => $args | 305 | 'args' => $args, |
| 309 | ]; | 306 | ]; |
| 310 | 307 | ||
| 311 | // Convert the args to actual message | 308 | // Convert the args to actual message |
| ... | @@ -314,16 +311,16 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -314,16 +311,16 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 314 | foreach ($insert['args'] as $key => $val) { | 311 | foreach ($insert['args'] as $key => $val) { |
| 315 | if (filter_var($val, FILTER_VALIDATE_URL) !== false) { | 312 | if (filter_var($val, FILTER_VALIDATE_URL) !== false) { |
| 316 | $content = str_replace( | 313 | $content = str_replace( |
| 317 | '{'.$key.'}', | 314 | '{' . $key . '}', |
| 318 | "<a href='" | 315 | "<a href='" |
| 319 | .$val | 316 | . $val |
| 320 | ."'>" | 317 | . "'>" |
| 321 | .__('Click here', 'CBV_DOMAIN') | 318 | . __('Click here', 'CBV_DOMAIN') |
| 322 | .'</a>', | 319 | . '</a>', |
| 323 | $content | 320 | $content |
| 324 | ); | 321 | ); |
| 325 | } else { | 322 | } else { |
| 326 | $content = str_replace('{'.$key.'}', $val, $content); | 323 | $content = str_replace('{' . $key . '}', $val, $content); |
| 327 | } | 324 | } |
| 328 | } | 325 | } |
| 329 | $insert['message'] = $content; | 326 | $insert['message'] = $content; |
| ... | @@ -342,7 +339,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -342,7 +339,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 342 | if ($notification->is_push) { | 339 | if ($notification->is_push) { |
| 343 | 340 | ||
| 344 | $preferred_language = get_user_meta($uid, 'preferred_language', true); | 341 | $preferred_language = get_user_meta($uid, 'preferred_language', true); |
| 345 | if(empty($preferred_language)) { | 342 | if (empty($preferred_language)) { |
| 346 | $preferred_language = 'en'; | 343 | $preferred_language = 'en'; |
| 347 | } | 344 | } |
| 348 | 345 | ||
| ... | @@ -353,13 +350,11 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -353,13 +350,11 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 353 | $status = $push[$preferred_language . '_status']; | 350 | $status = $push[$preferred_language . '_status']; |
| 354 | foreach ($args as $key => $val) { | 351 | foreach ($args as $key => $val) { |
| 355 | 352 | ||
| 356 | $title = str_replace('{'.$key.'}', $val, $title); | 353 | $title = str_replace('{' . $key . '}', $val, $title); |
| 357 | $message = str_replace('{'.$key.'}', $val, $message); | 354 | $message = str_replace('{' . $key . '}', $val, $message); |
| 358 | |||
| 359 | 355 | ||
| 360 | } | 356 | } |
| 361 | 357 | ||
| 362 | |||
| 363 | // Do argument template again | 358 | // Do argument template again |
| 364 | // Set arguments for email template | 359 | // Set arguments for email template |
| 365 | $user_data = [ | 360 | $user_data = [ |
| ... | @@ -399,22 +394,20 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -399,22 +394,20 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 399 | 'preferred_email', | 394 | 'preferred_email', |
| 400 | 'member_id', | 395 | 'member_id', |
| 401 | 'user_id', | 396 | 'user_id', |
| 402 | 'course_note_listing' | 397 | 'course_note_listing', |
| 403 | ]; | 398 | ]; |
| 404 | 399 | ||
| 405 | $user_data = array_flip($user_data); | 400 | $user_data = array_flip($user_data); |
| 406 | 401 | ||
| 407 | |||
| 408 | foreach ($user_data as $field => $value) { | 402 | foreach ($user_data as $field => $value) { |
| 409 | $user_data[$field] = User\clean_string(get_user_meta($uid, $field, true)); | 403 | $user_data[$field] = User\clean_string(get_user_meta($uid, $field, true)); |
| 410 | } | 404 | } |
| 411 | 405 | ||
| 412 | foreach ($user_data as $key => $val) { | 406 | foreach ($user_data as $key => $val) { |
| 413 | $title = str_replace('{'.$key.'}', $val, $title ); | 407 | $title = str_replace('{' . $key . '}', $val, $title); |
| 414 | $message = str_replace('{'.$key.'}', $val, $message); | 408 | $message = str_replace('{' . $key . '}', $val, $message); |
| 415 | } | 409 | } |
| 416 | 410 | ||
| 417 | |||
| 418 | $wpdb->query( | 411 | $wpdb->query( |
| 419 | "INSERT INTO wp_push_daemon (post_id,user_id,time,title,message,link,status) VALUES (0, $uid,'$time','$title','$message','$link','$status')" | 412 | "INSERT INTO wp_push_daemon (post_id,user_id,time,title,message,link,status) VALUES (0, $uid,'$time','$title','$message','$link','$status')" |
| 420 | ); | 413 | ); |
| ... | @@ -432,8 +425,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -432,8 +425,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 432 | if (empty($emailAddressPreference)) { | 425 | if (empty($emailAddressPreference)) { |
| 433 | $toEmail = $user->user_email; | 426 | $toEmail = $user->user_email; |
| 434 | } else { | 427 | } else { |
| 435 | $pp = strtolower($emailAddressPreference).'_'; | 428 | $pp = strtolower($emailAddressPreference) . '_'; |
| 436 | $toEmail = get_user_meta($user->ID, $pp.'email', true); | 429 | $toEmail = get_user_meta($user->ID, $pp . 'email', true); |
| 437 | 430 | ||
| 438 | if (empty($toEmail)) { | 431 | if (empty($toEmail)) { |
| 439 | $toEmail = $user->user_email; | 432 | $toEmail = $user->user_email; |
| ... | @@ -445,26 +438,26 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -445,26 +438,26 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 445 | 438 | ||
| 446 | $fromEmail = get_bloginfo('admin_email'); | 439 | $fromEmail = get_bloginfo('admin_email'); |
| 447 | $subject = strip_tags( | 440 | $subject = strip_tags( |
| 448 | isset($contents[$lang.'_subject']) && !empty($contents[$lang.'_subject']) | 441 | isset($contents[$lang . '_subject']) && !empty($contents[$lang . '_subject']) |
| 449 | ? $contents[$lang.'_subject'] | 442 | ? $contents[$lang . '_subject'] |
| 450 | : $contents['en_subject'] | 443 | : $contents['en_subject'] |
| 451 | ); | 444 | ); |
| 452 | $html = isset($contents[$lang.'_html']) && !empty($contents[$lang.'_html']) | 445 | $html = isset($contents[$lang . '_html']) && !empty($contents[$lang . '_html']) |
| 453 | ? $contents[$lang.'_html'] | 446 | ? $contents[$lang . '_html'] |
| 454 | : @$contents['en_html']; | 447 | : @$contents['en_html']; |
| 455 | $altText = strip_tags( | 448 | $altText = strip_tags( |
| 456 | isset($contents[$lang.'_text']) && !empty($contents[$lang.'_text']) | 449 | isset($contents[$lang . '_text']) && !empty($contents[$lang . '_text']) |
| 457 | ? $contents[$lang.'_text'] | 450 | ? $contents[$lang . '_text'] |
| 458 | : $contents['en_text'] | 451 | : $contents['en_text'] |
| 459 | ); | 452 | ); |
| 460 | 453 | ||
| 461 | foreach ($args as $key => $val) { | 454 | foreach ($args as $key => $val) { |
| 462 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | 455 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { |
| 463 | $html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html); | 456 | $html = str_replace('{' . $key . '}', '<a href="' . $val . '">' . $val . '</a>', $html); |
| 464 | } else { | 457 | } else { |
| 465 | $html = str_replace('{'.$key.'}', $val, $html); | 458 | $html = str_replace('{' . $key . '}', $val, $html); |
| 466 | $altText = str_replace('{'.$key.'}', $val, $altText); | 459 | $altText = str_replace('{' . $key . '}', $val, $altText); |
| 467 | $subject = str_replace('{'.$key.'}', $val, $subject); | 460 | $subject = str_replace('{' . $key . '}', $val, $subject); |
| 468 | } | 461 | } |
| 469 | } | 462 | } |
| 470 | 463 | ||
| ... | @@ -507,7 +500,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -507,7 +500,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 507 | 'preferred_email', | 500 | 'preferred_email', |
| 508 | 'member_id', | 501 | 'member_id', |
| 509 | 'user_id', | 502 | 'user_id', |
| 510 | 'course_note_listing' | 503 | 'course_note_listing', |
| 511 | ]; | 504 | ]; |
| 512 | 505 | ||
| 513 | $user_data = array_flip($user_data); | 506 | $user_data = array_flip($user_data); |
| ... | @@ -516,28 +509,28 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -516,28 +509,28 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 516 | $user_data[$field] = User\clean_string(get_user_meta($uid, $field, true)); | 509 | $user_data[$field] = User\clean_string(get_user_meta($uid, $field, true)); |
| 517 | 510 | ||
| 518 | // Choose user's preferred email address | 511 | // Choose user's preferred email address |
| 519 | if($field == 'preferred_email') { | 512 | if ($field == 'preferred_email') { |
| 520 | $user_data['preferred_email'] = $user_data['email_address_preference'] == 'Home' ? $user_data['home_email'] : $user_data['work_email']; | 513 | $user_data['preferred_email'] = $user_data['email_address_preference'] == 'Home' ? $user_data['home_email'] : $user_data['work_email']; |
| 521 | } | 514 | } |
| 522 | 515 | ||
| 523 | // Set course note listing page | 516 | // Set course note listing page |
| 524 | if($field == 'course_note_listing' && empty($args['course_note_listing'])) { | 517 | if ($field == 'course_note_listing' && empty($args['course_note_listing'])) { |
| 525 | $user_data['course_note_listing'] = '<a href="' . get_bloginfo('url') . CBV\PAGE_COURSENOTES . '">Course Note Listing page</a>'; | 518 | $user_data['course_note_listing'] = '<a href="' . get_bloginfo('url') . CBV\PAGE_COURSENOTES . '">Course Note Listing page</a>'; |
| 526 | } | 519 | } |
| 527 | } | 520 | } |
| 528 | 521 | ||
| 529 | foreach ($user_data as $key => $val) { | 522 | foreach ($user_data as $key => $val) { |
| 530 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | 523 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { |
| 531 | $html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html); | 524 | $html = str_replace('{' . $key . '}', '<a href="' . $val . '">' . $val . '</a>', $html); |
| 532 | } else { | 525 | } else { |
| 533 | $html = str_replace('{'.$key.'}', $val, $html); | 526 | $html = str_replace('{' . $key . '}', $val, $html); |
| 534 | $altText = str_replace('{'.$key.'}', $val, $altText); | 527 | $altText = str_replace('{' . $key . '}', $val, $altText); |
| 535 | $subject = str_replace('{'.$key.'}', $val, $subject); | 528 | $subject = str_replace('{' . $key . '}', $val, $subject); |
| 536 | } | 529 | } |
| 537 | } | 530 | } |
| 538 | 531 | ||
| 539 | $attachments = isset($contents[$lang.'_attachments']) | 532 | $attachments = isset($contents[$lang . '_attachments']) |
| 540 | ? $contents[$lang.'_attachments'] | 533 | ? $contents[$lang . '_attachments'] |
| 541 | : $contents['en_attachments']; | 534 | : $contents['en_attachments']; |
| 542 | $att1 = isset($attachments[0]) ? $attachments[0] : ''; | 535 | $att1 = isset($attachments[0]) ? $attachments[0] : ''; |
| 543 | $att2 = isset($attachments[1]) ? $attachments[1] : ''; | 536 | $att2 = isset($attachments[1]) ? $attachments[1] : ''; |
| ... | @@ -545,7 +538,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -545,7 +538,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 545 | 538 | ||
| 546 | $attachments = array_map( | 539 | $attachments = array_map( |
| 547 | function ($attachmentPath) { | 540 | function ($attachmentPath) { |
| 548 | return realpath(__DIR__.'/../../../uploads/notifications/'.$attachmentPath); | 541 | return realpath(__DIR__ . '/../../../uploads/notifications/' . $attachmentPath); |
| 549 | }, | 542 | }, |
| 550 | $attachments | 543 | $attachments |
| 551 | ); | 544 | ); |
| ... | @@ -575,8 +568,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -575,8 +568,8 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 575 | 'attachment1' => $att1, | 568 | 'attachment1' => $att1, |
| 576 | 'attachment2' => $att2, | 569 | 'attachment2' => $att2, |
| 577 | 'attachment3' => $att3, | 570 | 'attachment3' => $att3, |
| 578 | 'sent' => (int)$sentSuccessfully, | 571 | 'sent' => (int) $sentSuccessfully, |
| 579 | 'sent_date' => CBV\tz_date('Y-m-d H:i:s') | 572 | 'sent_date' => CBV\tz_date('Y-m-d H:i:s'), |
| 580 | ], | 573 | ], |
| 581 | [ | 574 | [ |
| 582 | '%d', | 575 | '%d', |
| ... | @@ -589,7 +582,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -589,7 +582,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 589 | '%s', | 582 | '%s', |
| 590 | '%s', | 583 | '%s', |
| 591 | '%d', | 584 | '%d', |
| 592 | '%s' | 585 | '%s', |
| 593 | ] | 586 | ] |
| 594 | ); | 587 | ); |
| 595 | } | 588 | } |
| ... | @@ -615,8 +608,8 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a | ... | @@ -615,8 +608,8 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a |
| 615 | $notification->status = isset($details['status']) ? $details['status'] : 'active'; | 608 | $notification->status = isset($details['status']) ? $details['status'] : 'active'; |
| 616 | $notification->type = $details['type']; | 609 | $notification->type = $details['type']; |
| 617 | $notification->sendto = @$details['sendto']; | 610 | $notification->sendto = @$details['sendto']; |
| 618 | $notification->is_email = (($email[$lang.'_text'] != '' || $email[$lang.'_html'] != '') && $email[$lang.'_subject'] != ''); | 611 | $notification->is_email = (($email[$lang . '_text'] != '' || $email[$lang . '_html'] != '') && $email[$lang . '_subject'] != ''); |
| 619 | $notification->is_system = (isset($system[$lang.'_message']) && $system[$lang.'_message'] != ''); | 612 | $notification->is_system = (isset($system[$lang . '_message']) && $system[$lang . '_message'] != ''); |
| 620 | 613 | ||
| 621 | // if is_system ========================================== | 614 | // if is_system ========================================== |
| 622 | if ($notification->is_system && $uid != 0) { | 615 | if ($notification->is_system && $uid != 0) { |
| ... | @@ -628,47 +621,40 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a | ... | @@ -628,47 +621,40 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a |
| 628 | 'notification_id' => $nid, | 621 | 'notification_id' => $nid, |
| 629 | 'status' => 'unread', | 622 | 'status' => 'unread', |
| 630 | 'sent_date' => current_time('timestamp'), | 623 | 'sent_date' => current_time('timestamp'), |
| 631 | 'message' => $system[$lang.'_message'], | 624 | 'message' => $system[$lang . '_message'], |
| 632 | 'args' => $args | 625 | 'args' => $args, |
| 633 | ]; | 626 | ]; |
| 634 | } | 627 | } |
| 635 | 628 | ||
| 636 | |||
| 637 | } | 629 | } |
| 638 | 630 | ||
| 639 | $contents = $email; | 631 | $contents = $email; |
| 640 | 632 | ||
| 641 | $fromEmail = get_bloginfo('admin_email'); | 633 | $fromEmail = get_bloginfo('admin_email'); |
| 642 | $subject = strip_tags( | 634 | $subject = strip_tags( |
| 643 | isset($contents[$lang.'_subject']) && !empty($contents[$lang.'_subject']) | 635 | isset($contents[$lang . '_subject']) && !empty($contents[$lang . '_subject']) |
| 644 | ? $contents[$lang.'_subject'] | 636 | ? $contents[$lang . '_subject'] |
| 645 | : $contents['en_subject'] | 637 | : $contents['en_subject'] |
| 646 | ); | 638 | ); |
| 647 | $html = isset($contents[$lang.'_html']) && !empty($contents[$lang.'_html']) | 639 | $html = isset($contents[$lang . '_html']) && !empty($contents[$lang . '_html']) |
| 648 | ? $contents[$lang.'_html'] | 640 | ? $contents[$lang . '_html'] |
| 649 | : @$contents['en_html']; | 641 | : @$contents['en_html']; |
| 650 | $altText = strip_tags( | 642 | $altText = strip_tags( |
| 651 | isset($contents[$lang.'_text']) && !empty($contents[$lang.'_text']) | 643 | isset($contents[$lang . '_text']) && !empty($contents[$lang . '_text']) |
| 652 | ? $contents[$lang.'_text'] | 644 | ? $contents[$lang . '_text'] |
| 653 | : $contents['en_text'] | 645 | : $contents['en_text'] |
| 654 | ); | 646 | ); |
| 655 | 647 | ||
| 656 | foreach ($args as $key => $val) { | 648 | foreach ($args as $key => $val) { |
| 657 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | 649 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { |
| 658 | $html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html); | 650 | $html = str_replace('{' . $key . '}', '<a href="' . $val . '">' . $val . '</a>', $html); |
| 659 | } else { | 651 | } else { |
| 660 | $html = str_replace('{'.$key.'}', $val, $html); | 652 | $html = str_replace('{' . $key . '}', $val, $html); |
| 661 | $altText = str_replace('{'.$key.'}', $val, $altText); | 653 | $altText = str_replace('{' . $key . '}', $val, $altText); |
| 662 | $subject = str_replace('{'.$key.'}', $val, $subject); | 654 | $subject = str_replace('{' . $key . '}', $val, $subject); |
| 663 | } | 655 | } |
| 664 | } | 656 | } |
| 665 | 657 | ||
| 666 | |||
| 667 | |||
| 668 | |||
| 669 | |||
| 670 | |||
| 671 | |||
| 672 | $sentSuccessfully = false; | 658 | $sentSuccessfully = false; |
| 673 | if (CBV\system_can_send_emails_using_wpdb()) { | 659 | if (CBV\system_can_send_emails_using_wpdb()) { |
| 674 | $response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments); | 660 | $response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments); |
| ... | @@ -682,7 +668,6 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a | ... | @@ -682,7 +668,6 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a |
| 682 | } | 668 | } |
| 683 | } | 669 | } |
| 684 | 670 | ||
| 685 | |||
| 686 | } | 671 | } |
| 687 | 672 | ||
| 688 | /** | 673 | /** |
| ... | @@ -737,9 +722,9 @@ function current_url() | ... | @@ -737,9 +722,9 @@ function current_url() |
| 737 | } | 722 | } |
| 738 | $pageURL .= '://'; | 723 | $pageURL .= '://'; |
| 739 | if ($_SERVER['SERVER_PORT'] != '80') { | 724 | if ($_SERVER['SERVER_PORT'] != '80') { |
| 740 | $pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; | 725 | $pageURL .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; |
| 741 | } else { | 726 | } else { |
| 742 | $pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; | 727 | $pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; |
| 743 | } | 728 | } |
| 744 | 729 | ||
| 745 | return $pageURL; | 730 | return $pageURL; | ... | ... |
-
Please register or sign in to post a comment