update to notifications
Showing
1 changed file
with
51 additions
and
6 deletions
| 1 | <?php | 1 | <?php |
| 2 | namespace Tz\WordPress\Tools\Notifications; | 2 | namespace Tz\WordPress\Tools\Notifications; |
| 3 | 3 | ||
| 4 | use Tz\WordPress\Tools; | ||
| 5 | use Tz\Common; | 4 | use Tz\Common; |
| 5 | use Tz\WordPress\Tools; | ||
| 6 | use WP_User; | ||
| 7 | use Exception, StdClass; | ||
| 6 | 8 | ||
| 7 | 9 | ||
| 8 | const OPTION_NAME = "notif_options"; | 10 | const OPTION_NAME = "notif_options"; |
| ... | @@ -77,15 +79,15 @@ function remove_notice($notification_id = -1) { | ... | @@ -77,15 +79,15 @@ function remove_notice($notification_id = -1) { |
| 77 | Send Notifications | 79 | Send Notifications |
| 78 | @trigger = notification unique slug name | 80 | @trigger = notification unique slug name |
| 79 | */ | 81 | */ |
| 80 | function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) { | 82 | function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(),$send_override = false) { |
| 81 | $notification = get_notification_by_trigger($trigger); | 83 | $notification = get_notification_by_trigger($trigger); |
| 82 | if($notification) { | 84 | if($notification) { |
| 83 | 85 | ||
| 84 | // get the user and user details.... | 86 | // get the user and user details.... |
| 85 | $user = Tools\getCurrentUser(); | 87 | $user = new WP_User($uid);//Tools\getCurrentUser(); |
| 86 | $notify_me = get_user_meta($user->ID,'notify_me',true); | 88 | $notify_me = get_user_meta($user->ID,'notify_me',true); |
| 87 | $notify_format = get_user_meta($user->ID,'notify_format',true); | 89 | $notify_format = get_user_meta($user->ID,'notify_format',true); |
| 88 | $email = get_user_meta($user->ID,'email_address_preference',true); | 90 | $email_preference = get_user_meta($user->ID,'email_address_preference',true); |
| 89 | $cell = get_user_meta($user->ID,'home_mobile',true); | 91 | $cell = get_user_meta($user->ID,'home_mobile',true); |
| 90 | 92 | ||
| 91 | // get the notification and notificatio details.... | 93 | // get the notification and notificatio details.... |
| ... | @@ -101,7 +103,7 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) | ... | @@ -101,7 +103,7 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) |
| 101 | $notification->type = $details['type']; | 103 | $notification->type = $details['type']; |
| 102 | $notification->sendto = $details['sendto']; | 104 | $notification->sendto = $details['sendto']; |
| 103 | 105 | ||
| 104 | $notification->is_email = (($email['text'] != "" || $email['html'] != "")) ? true : false; | 106 | $notification->is_email = (($email['text'] != "" || $email['html'] != "") && $email['subject'] != "") ? true : false; |
| 105 | $notification->is_system = (isset($system['message']) && $system['message'] != "") ? true : false; | 107 | $notification->is_system = (isset($system['message']) && $system['message'] != "") ? true : false; |
| 106 | $notification->is_sms = (isset($sms['message']) && $sms['message'] != "") ? true : false; | 108 | $notification->is_sms = (isset($sms['message']) && $sms['message'] != "") ? true : false; |
| 107 | 109 | ||
| ... | @@ -132,7 +134,8 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) | ... | @@ -132,7 +134,8 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) |
| 132 | 134 | ||
| 133 | 135 | ||
| 134 | // if is_email =========================================== | 136 | // if is_email =========================================== |
| 135 | if ($notification->is_email && $notify_me) { | 137 | if ($notification->is_email && ($notify_me || $send_override)) { |
| 138 | send_email($user->ID,$email,$args,$send_override); | ||
| 136 | } | 139 | } |
| 137 | 140 | ||
| 138 | 141 | ||
| ... | @@ -144,6 +147,48 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) | ... | @@ -144,6 +147,48 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) |
| 144 | // if the system notification has set current user than get current user otherwise loop through the users needed. | 147 | // if the system notification has set current user than get current user otherwise loop through the users needed. |
| 145 | } | 148 | } |
| 146 | 149 | ||
| 150 | function send_email($uid, $contents,$args) { | ||
| 151 | $from_address = get_bloginfo('admin_email'); | ||
| 152 | $user = new WP_User($uid); | ||
| 153 | |||
| 154 | $to_email = $user->user_email; | ||
| 155 | $subject = $contents['subject']; | ||
| 156 | $html = $contents['html']; | ||
| 157 | $alttext = $contents['text']; | ||
| 158 | |||
| 159 | $headers = ""; | ||
| 160 | |||
| 161 | if (empty($html)) { | ||
| 162 | $message = $alttext; | ||
| 163 | $message = strip_tags($message); | ||
| 164 | // it's text based only... no need to check format preference. | ||
| 165 | } else { | ||
| 166 | $message = $html; | ||
| 167 | $headers .= 'MIME-Version: 1.0' . "\r\n"; | ||
| 168 | $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; | ||
| 169 | |||
| 170 | // it's HTML formatted. | ||
| 171 | // Check user preference if they want Text ONly?? | ||
| 172 | } | ||
| 173 | |||
| 174 | foreach($args as $key => $val) { | ||
| 175 | if ( (filter_var($val, FILTER_VALIDATE_URL) !== false) && !empty($html)) { | ||
| 176 | $message = str_replace("{".$key."}","<a href='".$val."'>".$val."</a>",$message); | ||
| 177 | } else { | ||
| 178 | $message = str_replace("{".$key."}",$val,$message); | ||
| 179 | } | ||
| 180 | |||
| 181 | } | ||
| 182 | |||
| 183 | // Additional headers | ||
| 184 | //$headers .= 'To: '.$to_email.' <'.$to_email.'>' . "\r\n"; | ||
| 185 | $headers .= 'From: CICBV <'.$from_address.'>' . "\r\n"; | ||
| 186 | |||
| 187 | mail($to_email, $subject, $message, $headers); | ||
| 188 | |||
| 189 | |||
| 190 | } | ||
| 191 | |||
| 147 | function getGroups($grpID=0) { | 192 | function getGroups($grpID=0) { |
| 148 | global $userAccessManager; | 193 | global $userAccessManager; |
| 149 | 194 | ... | ... |
-
Please register or sign in to post a comment