dd
Showing
1 changed file
with
182 additions
and
197 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; |
| 8 | use Tz\WordPress\Tools\Sequencer; | 7 | use Tz\WordPress\Tools\Sequencer; |
| 9 | 8 | ||
| 10 | const OPTION_NAME = 'notif_options'; | 9 | const OPTION_NAME = 'notif_options'; |
| 11 | const NOTIFICATION_STATUS_READ = 'read'; | 10 | const NOTIFICATION_STATUS_READ = 'read'; |
| 12 | const NOTIFICATION_STATUS_UNREAD = 'unread'; | 11 | 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 | ); |
| 26 | 25 | ||
| 27 | /** | 26 | /** |
| 28 | * @param $a | 27 | * @param $a |
| 29 | * @param $subkey | 28 | * @param $subkey |
| ... | @@ -56,7 +55,7 @@ function get_user_notices($uid) | ... | @@ -56,7 +55,7 @@ function get_user_notices($uid) |
| 56 | { | 55 | { |
| 57 | $notices = get_user_meta($uid, 'notices', true); | 56 | $notices = get_user_meta($uid, 'notices', true); |
| 58 | if (!empty($notices)) { | 57 | if (!empty($notices)) { |
| 59 | $notices = subval_sort($notices, 'sent_date', 'arsort'); | 58 | $notices = subval_sort($notices, 'sent_date', 'arsort'); |
| 60 | Vars::$notices = $notices; | 59 | Vars::$notices = $notices; |
| 61 | } | 60 | } |
| 62 | } | 61 | } |
| ... | @@ -72,33 +71,33 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -72,33 +71,33 @@ function print_user_notices($showOnlyUnread = false) |
| 72 | get_user_notices($user->ID); | 71 | get_user_notices($user->ID); |
| 73 | 72 | ||
| 74 | $notices = Vars::$notices; | 73 | $notices = Vars::$notices; |
| 75 | $rows = ''; | 74 | $rows = ''; |
| 76 | foreach ($notices as $index => $notice) { | 75 | foreach ($notices as $index => $notice) { |
| 77 | if ($showOnlyUnread && $notice['status'] != 'unread') { | 76 | if ($showOnlyUnread && $notice['status'] != 'unread') { |
| 78 | continue; | 77 | continue; |
| 79 | } | 78 | } |
| 80 | 79 | ||
| 81 | $triggered = get_post_meta($notice['notification_id'], 'trigger', true); | 80 | $triggered = get_post_meta($notice['notification_id'], 'trigger', true); |
| 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); |
| 94 | $toEmail = $userData->user_email; | 93 | $toEmail = $userData->user_email; |
| 95 | } else { | 94 | } else { |
| 96 | $pp = strtolower($emailAddressPreference) . '_'; | 95 | $pp = strtolower($emailAddressPreference) . '_'; |
| 97 | $toEmail = get_user_meta($user->ID, $pp . 'email', true); | 96 | $toEmail = get_user_meta($user->ID, $pp . 'email', true); |
| 98 | 97 | ||
| 99 | if (empty($toEmail)) { | 98 | if (empty($toEmail)) { |
| 100 | $userData = get_userdata($user->ID); | 99 | $userData = get_userdata($user->ID); |
| 101 | $toEmail = $userData->user_email; | 100 | $toEmail = $userData->user_email; |
| 102 | } | 101 | } |
| 103 | } | 102 | } |
| 104 | 103 | ||
| ... | @@ -119,7 +118,7 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -119,7 +118,7 @@ function print_user_notices($showOnlyUnread = false) |
| 119 | foreach ($results as $result) { | 118 | foreach ($results as $result) { |
| 120 | if ($toEmail == $result->to_email) { | 119 | if ($toEmail == $result->to_email) { |
| 121 | $stringArray = (preg_split("/\r\n|\n|\r/", $result->text, -1, PREG_SPLIT_NO_EMPTY)); | 120 | $stringArray = (preg_split("/\r\n|\n|\r/", $result->text, -1, PREG_SPLIT_NO_EMPTY)); |
| 122 | $message = implode("\n", [$stringArray[0], $stringArray[1]]); | 121 | $message = implode("\n", [$stringArray[0], $stringArray[1]]); |
| 123 | break; | 122 | break; |
| 124 | } | 123 | } |
| 125 | } | 124 | } |
| ... | @@ -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 | ||
| ... | @@ -192,10 +189,10 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -192,10 +189,10 @@ function print_user_notices($showOnlyUnread = false) |
| 192 | function get_notification_by_trigger($trigger) | 189 | function get_notification_by_trigger($trigger) |
| 193 | { | 190 | { |
| 194 | $args = [ | 191 | $args = [ |
| 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; |
| ... | @@ -222,7 +219,7 @@ function get_num_notices() | ... | @@ -222,7 +219,7 @@ function get_num_notices() |
| 222 | $user = new User\CurrentAccount(); | 219 | $user = new User\CurrentAccount(); |
| 223 | 220 | ||
| 224 | get_user_notices($user->ID); | 221 | get_user_notices($user->ID); |
| 225 | $notices = Vars::$notices; | 222 | $notices = Vars::$notices; |
| 226 | $notifications = []; | 223 | $notifications = []; |
| 227 | // return $num; | 224 | // return $num; |
| 228 | if (empty($notices)) { | 225 | if (empty($notices)) { |
| ... | @@ -282,18 +279,18 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -282,18 +279,18 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 282 | 279 | ||
| 283 | if ($notification) { | 280 | if ($notification) { |
| 284 | // get the notification and notificatio details.... | 281 | // get the notification and notificatio details.... |
| 285 | $nid = $notification->ID; | 282 | $nid = $notification->ID; |
| 286 | $details = get_post_meta($nid, 'details', true); | 283 | $details = get_post_meta($nid, 'details', true); |
| 287 | $email = get_post_meta($nid, 'email', true); | 284 | $email = get_post_meta($nid, 'email', true); |
| 288 | $system = get_post_meta($nid, 'system', true); | 285 | $system = get_post_meta($nid, 'system', true); |
| 289 | $push = get_post_meta($nid, 'push', true); | 286 | $push = get_post_meta($nid, 'push', true); |
| 290 | $notification->trigger = $details['trigger']; | 287 | $notification->trigger = $details['trigger']; |
| 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); |
| ... | @@ -302,10 +299,10 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -302,10 +299,10 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 302 | // Add a system message into the usermeta as well to track the system notification. | 299 | // Add a system message into the usermeta as well to track the system notification. |
| 303 | $insert = [ | 300 | $insert = [ |
| 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; |
| ... | @@ -341,24 +338,22 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -341,24 +338,22 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 341 | } | 338 | } |
| 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 | ||
| 349 | $time = time(); | 346 | $time = time(); |
| 350 | $title = $push[$preferred_language . '_title']; | 347 | $title = $push[$preferred_language . '_title']; |
| 351 | $message = $push[$preferred_language . '_message']; | 348 | $message = $push[$preferred_language . '_message']; |
| 352 | $link = $push[$preferred_language . '_link']; | 349 | $link = $push[$preferred_language . '_link']; |
| 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 | |||
| 360 | } | ||
| 361 | 355 | ||
| 356 | } | ||
| 362 | 357 | ||
| 363 | // Do argument template again | 358 | // Do argument template again |
| 364 | // Set arguments for email template | 359 | // Set arguments for email template |
| ... | @@ -399,25 +394,23 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -399,25 +394,23 @@ 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 | 411 | $wpdb->query( | |
| 418 | $wpdb->query( | 412 | "INSERT INTO wp_push_daemon (post_id,user_id,time,title,message,link,status) VALUES (0, $uid,'$time','$title','$message','$link','$status')" |
| 419 | "INSERT INTO wp_push_daemon (post_id,user_id,time,title,message,link,status) VALUES (0, $uid,'$time','$title','$message','$link','$status')" | 413 | ); |
| 420 | ); | ||
| 421 | 414 | ||
| 422 | } | 415 | } |
| 423 | 416 | ||
| ... | @@ -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; |
| ... | @@ -444,27 +437,27 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -444,27 +437,27 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 444 | $contents = $email; | 437 | $contents = $email; |
| 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,36 +509,36 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -516,36 +509,36 @@ 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] : ''; |
| 544 | $att3 = isset($attachments[2]) ? $attachments[2] : ''; | 537 | $att3 = isset($attachments[2]) ? $attachments[2] : ''; |
| 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 | ); |
| ... | @@ -567,16 +560,16 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -567,16 +560,16 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 567 | 'wp_mail_daemon', | 560 | 'wp_mail_daemon', |
| 568 | [ | 561 | [ |
| 569 | 'notification_id' => $nid, | 562 | 'notification_id' => $nid, |
| 570 | 'from_email' => $fromEmail, | 563 | 'from_email' => $fromEmail, |
| 571 | 'to_email' => $toEmail, | 564 | 'to_email' => $toEmail, |
| 572 | 'subject' => $subject, | 565 | 'subject' => $subject, |
| 573 | 'text' => $altText, | 566 | 'text' => $altText, |
| 574 | 'html' => $html, | 567 | 'html' => $html, |
| 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 | } |
| ... | @@ -598,7 +591,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = | ... | @@ -598,7 +591,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args = |
| 598 | 591 | ||
| 599 | function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $args = []) | 592 | function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $args = []) |
| 600 | { | 593 | { |
| 601 | 594 | ||
| 602 | $lang = 'en'; | 595 | $lang = 'en'; |
| 603 | 596 | ||
| 604 | /** @var \StdClass $notification */ | 597 | /** @var \StdClass $notification */ |
| ... | @@ -606,17 +599,17 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a | ... | @@ -606,17 +599,17 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a |
| 606 | 599 | ||
| 607 | if ($notification) { | 600 | if ($notification) { |
| 608 | // get the notification and notificatio details.... | 601 | // get the notification and notificatio details.... |
| 609 | $nid = $notification->ID; | 602 | $nid = $notification->ID; |
| 610 | $details = get_post_meta($nid, 'details', true); | 603 | $details = get_post_meta($nid, 'details', true); |
| 611 | $email = get_post_meta($nid, 'email', true); | 604 | $email = get_post_meta($nid, 'email', true); |
| 612 | $system = get_post_meta($nid, 'system', true); | 605 | $system = get_post_meta($nid, 'system', true); |
| 613 | 606 | ||
| 614 | $notification->trigger = $details['trigger']; | 607 | $notification->trigger = $details['trigger']; |
| 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) { |
| ... | @@ -626,65 +619,57 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a | ... | @@ -626,65 +619,57 @@ function send_admin_triggered_notification($toEmail, $trigger = 'NO_TRIGGER', $a |
| 626 | // Add a system message into the usermeta as well to track the system notification. | 619 | // Add a system message into the usermeta as well to track the system notification. |
| 627 | $insert = [ | 620 | $insert = [ |
| 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 | |||
| 636 | |||
| 637 | } | ||
| 638 | |||
| 639 | $contents = $email; | ||
| 640 | |||
| 641 | $fromEmail = get_bloginfo('admin_email'); | ||
| 642 | $subject = strip_tags( | ||
| 643 | isset($contents[$lang.'_subject']) && !empty($contents[$lang.'_subject']) | ||
| 644 | ? $contents[$lang.'_subject'] | ||
| 645 | : $contents['en_subject'] | ||
| 646 | ); | ||
| 647 | $html = isset($contents[$lang.'_html']) && !empty($contents[$lang.'_html']) | ||
| 648 | ? $contents[$lang.'_html'] | ||
| 649 | : @$contents['en_html']; | ||
| 650 | $altText = strip_tags( | ||
| 651 | isset($contents[$lang.'_text']) && !empty($contents[$lang.'_text']) | ||
| 652 | ? $contents[$lang.'_text'] | ||
| 653 | : $contents['en_text'] | ||
| 654 | ); | ||
| 655 | |||
| 656 | foreach ($args as $key => $val) { | ||
| 657 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | ||
| 658 | $html = str_replace('{'.$key.'}', '<a href="'.$val.'">'.$val.'</a>', $html); | ||
| 659 | } else { | ||
| 660 | $html = str_replace('{'.$key.'}', $val, $html); | ||
| 661 | $altText = str_replace('{'.$key.'}', $val, $altText); | ||
| 662 | $subject = str_replace('{'.$key.'}', $val, $subject); | ||
| 663 | } | ||
| 664 | } | ||
| 665 | |||
| 666 | |||
| 667 | |||
| 668 | |||
| 669 | |||
| 670 | 628 | ||
| 629 | } | ||
| 671 | 630 | ||
| 672 | $sentSuccessfully = false; | 631 | $contents = $email; |
| 673 | if (CBV\system_can_send_emails_using_wpdb()) { | 632 | |
| 674 | $response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments); | 633 | $fromEmail = get_bloginfo('admin_email'); |
| 675 | if ( | 634 | $subject = strip_tags( |
| 676 | is_array($response) | 635 | isset($contents[$lang . '_subject']) && !empty($contents[$lang . '_subject']) |
| 677 | && isset($response[0]['status']) | 636 | ? $contents[$lang . '_subject'] |
| 678 | && isset($response[0]['status']) | 637 | : $contents['en_subject'] |
| 679 | && !in_array($response['status'], ['rejected', 'invalid']) | 638 | ); |
| 680 | ) { | 639 | $html = isset($contents[$lang . '_html']) && !empty($contents[$lang . '_html']) |
| 681 | $sentSuccessfully = true; | 640 | ? $contents[$lang . '_html'] |
| 682 | } | 641 | : @$contents['en_html']; |
| 683 | } | 642 | $altText = strip_tags( |
| 643 | isset($contents[$lang . '_text']) && !empty($contents[$lang . '_text']) | ||
| 644 | ? $contents[$lang . '_text'] | ||
| 645 | : $contents['en_text'] | ||
| 646 | ); | ||
| 647 | |||
| 648 | foreach ($args as $key => $val) { | ||
| 649 | if ((filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | ||
| 650 | $html = str_replace('{' . $key . '}', '<a href="' . $val . '">' . $val . '</a>', $html); | ||
| 651 | } else { | ||
| 652 | $html = str_replace('{' . $key . '}', $val, $html); | ||
| 653 | $altText = str_replace('{' . $key . '}', $val, $altText); | ||
| 654 | $subject = str_replace('{' . $key . '}', $val, $subject); | ||
| 655 | } | ||
| 656 | } | ||
| 684 | 657 | ||
| 658 | $sentSuccessfully = false; | ||
| 659 | if (CBV\system_can_send_emails_using_wpdb()) { | ||
| 660 | $response = \wpMandrill::mail($toEmail, $subject, !empty($html) ? $html : $altText, [], $attachments); | ||
| 661 | if ( | ||
| 662 | is_array($response) | ||
| 663 | && isset($response[0]['status']) | ||
| 664 | && isset($response[0]['status']) | ||
| 665 | && !in_array($response['status'], ['rejected', 'invalid']) | ||
| 666 | ) { | ||
| 667 | $sentSuccessfully = true; | ||
| 668 | } | ||
| 669 | } | ||
| 685 | 670 | ||
| 686 | } | 671 | } |
| 687 | 672 | ||
| 688 | /** | 673 | /** |
| 689 | * @param int $grpID | 674 | * @param int $grpID |
| 690 | * | 675 | * |
| ... | @@ -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