ef4a1033 by Marty Penner

Show only unread notices on the dashboard

1 parent e4863550
...@@ -16,7 +16,7 @@ call_user_func( ...@@ -16,7 +16,7 @@ call_user_func(
16 { 16 {
17 Tools\add_actions(__NAMESPACE__.'\Actions'); 17 Tools\add_actions(__NAMESPACE__.'\Actions');
18 Vars::$options = new Tools\WP_Option(OPTION_NAME); 18 Vars::$options = new Tools\WP_Option(OPTION_NAME);
19 Vars::$notices = Array(); 19 Vars::$notices = [];
20 if (is_admin()) { 20 if (is_admin()) {
21 require_once(__DIR__.DIRECTORY_SEPARATOR.'Validation.php'); 21 require_once(__DIR__.DIRECTORY_SEPARATOR.'Validation.php');
22 require_once(__DIR__.DIRECTORY_SEPARATOR.'Admin.php'); 22 require_once(__DIR__.DIRECTORY_SEPARATOR.'Admin.php');
...@@ -44,34 +44,37 @@ function get_user_notices($uid) ...@@ -44,34 +44,37 @@ function get_user_notices($uid)
44 } 44 }
45 } 45 }
46 46
47 function print_user_notices() 47 function print_user_notices($showOnlyUnread = false)
48 { 48 {
49 $user = new User\CurrentAccount(); 49 $user = new User\CurrentAccount();
50 50
51 get_user_notices($user->ID); 51 get_user_notices($user->ID);
52 52
53 $notices = Vars::$notices; 53 $notices = Vars::$notices;
54 $total_rows = count($notices); 54 $rows = '';
55 $rows = ''; 55
56 foreach ($notices as $index => $notice) {
57 if ($showOnlyUnread && $notice['status'] != 'unread') {
58 continue;
59 }
56 60
57 for ($i = 0; $i < $total_rows; $i++) { 61 $system = get_post_meta($notice['notification_id'], 'system', true);
58 $system = get_post_meta($notices[$i]['notification_id'], 'system', true);
59 $content = $system['message']; 62 $content = $system['message'];
60 63
61 if (isset($notices[$i]['args']) && count($notices[$i]['args']) > 0): 64 if (isset($notice['args']) && count($notice['args']) > 0) {
62 foreach ($notices[$i]['args'] as $key => $val) { 65 foreach ($notice['args'] as $key => $val) {
63 if (filter_var($val, FILTER_VALIDATE_URL) !== false) { 66 if (filter_var($val, FILTER_VALIDATE_URL) !== false) {
64 $content = str_replace('{'.$key.'}', "<a href='".$val."'>Click here</a>", $content); 67 $content = str_replace('{'.$key.'}', "<a href='".$val."'>Click here</a>", $content);
65 } else { 68 } else {
66 $content = str_replace('{'.$key.'}', $val, $content); 69 $content = str_replace('{'.$key.'}', $val, $content);
67 } 70 }
68 } 71 }
69 endif; 72 }
70 73
71 $rows .= '<tr class="notice-row" id="'.$i.'">'; 74 $rows .= '<tr class="notice-row" id="'.$index.'">';
72 if ($notices[$i]['status'] == 'unread') { 75 if ($notice['status'] == 'unread') {
73 $rows .= '<td width="12" style="padding:0;padding-left:10px;vertical-align:middle;"><a href="#" class="notice ' 76 $rows .= '<td width="12" style="padding:0;padding-left:10px;vertical-align:middle;"><a href="#" class="notice '
74 .(($notices[$i]['status'] == 'read') ? 'read' : 'unread') 77 .(($notice['status'] == 'read') ? 'read' : 'unread')
75 .'"><img src="assets/images/blank.gif" width="12" height="12" /></a></td>'; 78 .'"><img src="assets/images/blank.gif" width="12" height="12" /></a></td>';
76 } else { 79 } else {
77 $rows .= '<td width="12" style="padding:0;padding-left:10px;vertical-align:middle;"><img src="assets/images/blank.gif" width="12" height="12" /></td>'; 80 $rows .= '<td width="12" style="padding:0;padding-left:10px;vertical-align:middle;"><img src="assets/images/blank.gif" width="12" height="12" /></td>';
...@@ -85,7 +88,7 @@ function print_user_notices() ...@@ -85,7 +88,7 @@ function print_user_notices()
85 .ucfirst(str_replace('_', '&nbsp;', $system['system_message_type'])) 88 .ucfirst(str_replace('_', '&nbsp;', $system['system_message_type']))
86 .'</span></td>'; 89 .'</span></td>';
87 $rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">Sent: ' 90 $rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">Sent: '
88 .date('M j, Y @ h:ia', $notices[$i]['sent_date']).'</span></td>'; 91 .date('M j, Y @ h:ia', $notice['sent_date']).'</span></td>';
89 $rows .= '</tr>'; 92 $rows .= '</tr>';
90 } 93 }
91 94
...@@ -98,12 +101,12 @@ function print_user_notices() ...@@ -98,12 +101,12 @@ function print_user_notices()
98 101
99 function get_notification_by_trigger($trigger) 102 function get_notification_by_trigger($trigger)
100 { 103 {
101 $args = array( 104 $args = [
102 'post_type' => 'notifications', 105 'post_type' => 'notifications',
103 'numberposts' => -1, 106 'numberposts' => -1,
104 'orderby' => 'modified', 107 'orderby' => 'modified',
105 'order' => 'desc' 108 'order' => 'desc'
106 ); 109 ];
107 110
108 $my_notif = false; 111 $my_notif = false;
109 112
...@@ -129,7 +132,7 @@ function get_num_notices() ...@@ -129,7 +132,7 @@ function get_num_notices()
129 132
130 get_user_notices($user->ID); 133 get_user_notices($user->ID);
131 $notices = Vars::$notices; 134 $notices = Vars::$notices;
132 $notifications = array(); 135 $notifications = [];
133 // return $num; 136 // return $num;
134 if (empty($notices)) { 137 if (empty($notices)) {
135 return 0; 138 return 0;
...@@ -162,7 +165,7 @@ function remove_notice($notification_id = -1) ...@@ -162,7 +165,7 @@ function remove_notice($notification_id = -1)
162 Send Notifications 165 Send Notifications
163 @trigger = notification unique slug name 166 @trigger = notification unique slug name
164 */ 167 */
165 function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = array(), $send_override = false) 168 function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = [], $send_override = false)
166 { 169 {
167 global $wpdb; 170 global $wpdb;
168 $notification = get_notification_by_trigger($trigger); 171 $notification = get_notification_by_trigger($trigger);
...@@ -186,14 +189,14 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = ...@@ -186,14 +189,14 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
186 get_user_notices($uid); 189 get_user_notices($uid);
187 $notices = Vars::$notices; 190 $notices = Vars::$notices;
188 191
189 $insert = array( 192 $insert = [
190 'notification_id' => $nid, 193 'notification_id' => $nid,
191 'status' => 'unread', 194 'status' => 'unread',
192 'sent_date' => current_time('timestamp'), 195 'sent_date' => current_time('timestamp'),
193 'args' => $args 196 'args' => $args
194 ); 197 ];
195 if (empty($notices)) { 198 if (empty($notices)) {
196 $notices = array(); 199 $notices = [];
197 } 200 }
198 201
199 $sequence = Sequencer\generate('NTC'); 202 $sequence = Sequencer\generate('NTC');
...@@ -244,7 +247,7 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = ...@@ -244,7 +247,7 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
244 } 247 }
245 } 248 }
246 249
247 $attachments = array(); 250 $attachments = [];
248 if (isset($contents['attachments'])) { 251 if (isset($contents['attachments'])) {
249 $attachments = $contents['attachments']; 252 $attachments = $contents['attachments'];
250 } 253 }
...@@ -356,7 +359,7 @@ function getGroups($grpID = 0) ...@@ -356,7 +359,7 @@ function getGroups($grpID = 0)
356 { 359 {
357 global $userAccessManager; 360 global $userAccessManager;
358 361
359 $groups = array(); 362 $groups = [];
360 if ($grpID > 0) { 363 if ($grpID > 0) {
361 $userGroups = $userAccessManager 364 $userGroups = $userAccessManager
362 ->getAccessHandler() 365 ->getAccessHandler()
...@@ -398,7 +401,7 @@ class Actions ...@@ -398,7 +401,7 @@ class Actions
398 public static function wp_ajax_update_notification_count() 401 public static function wp_ajax_update_notification_count()
399 { 402 {
400 $count = get_num_notices(); 403 $count = get_num_notices();
401 $return = array('count'=> $count); 404 $return = ['count'=> $count];
402 die(json_encode($return)); 405 die(json_encode($return));
403 } 406 }
404 407
...@@ -427,7 +430,7 @@ class Actions ...@@ -427,7 +430,7 @@ class Actions
427 430
428 update_post_meta($id, 'email', $email); 431 update_post_meta($id, 'email', $email);
429 432
430 $return = array('success' => 'true'); 433 $return = ['success' => 'true'];
431 die(json_encode($return)); 434 die(json_encode($return));
432 } 435 }
433 } 436 }
...@@ -436,10 +439,10 @@ class Vars ...@@ -436,10 +439,10 @@ class Vars
436 { 439 {
437 public static $notices; 440 public static $notices;
438 public static $options; 441 public static $options;
439 public static $field_lookup = array( 442 public static $field_lookup = [
440 'allusers' => "All Users", 443 'allusers' => "All Users",
441 'report' => "Report" 444 'report' => "Report"
442 ); 445 ];
443 } 446 }
444 447
445 ?> 448 ?>
...\ No newline at end of file ...\ No newline at end of file
......