Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
ef4a1033
authored
2014-10-16 11:15:57 -0400
by
Marty Penner
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Show only unread notices on the dashboard
1 parent
e4863550
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
25 deletions
com/Notifications/Notifications.php
com/Notifications/Notifications.php
View file @
ef4a103
...
...
@@ -16,7 +16,7 @@ call_user_func(
{
Tools\add_actions
(
__NAMESPACE__
.
'\Actions'
);
Vars
::
$options
=
new
Tools\WP_Option
(
OPTION_NAME
);
Vars
::
$notices
=
Array
()
;
Vars
::
$notices
=
[]
;
if
(
is_admin
())
{
require_once
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'Validation.php'
);
require_once
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'Admin.php'
);
...
...
@@ -44,34 +44,37 @@ function get_user_notices($uid)
}
}
function
print_user_notices
()
function
print_user_notices
(
$showOnlyUnread
=
false
)
{
$user
=
new
User\CurrentAccount
();
get_user_notices
(
$user
->
ID
);
$notices
=
Vars
::
$notices
;
$total_rows
=
count
(
$notices
);
$rows
=
''
;
for
(
$i
=
0
;
$i
<
$total_rows
;
$i
++
)
{
$system
=
get_post_meta
(
$notices
[
$i
][
'notification_id'
],
'system'
,
true
);
foreach
(
$notices
as
$index
=>
$notice
)
{
if
(
$showOnlyUnread
&&
$notice
[
'status'
]
!=
'unread'
)
{
continue
;
}
$system
=
get_post_meta
(
$notice
[
'notification_id'
],
'system'
,
true
);
$content
=
$system
[
'message'
];
if
(
isset
(
$notice
s
[
$i
][
'args'
])
&&
count
(
$notices
[
$i
][
'args'
])
>
0
)
:
foreach
(
$notice
s
[
$i
]
[
'args'
]
as
$key
=>
$val
)
{
if
(
isset
(
$notice
[
'args'
])
&&
count
(
$notice
[
'args'
])
>
0
)
{
foreach
(
$notice
[
'args'
]
as
$key
=>
$val
)
{
if
(
filter_var
(
$val
,
FILTER_VALIDATE_URL
)
!==
false
)
{
$content
=
str_replace
(
'{'
.
$key
.
'}'
,
"<a href='"
.
$val
.
"'>Click here</a>"
,
$content
);
}
else
{
$content
=
str_replace
(
'{'
.
$key
.
'}'
,
$val
,
$content
);
}
}
endif
;
}
$rows
.=
'<tr class="notice-row" id="'
.
$i
.
'">'
;
if
(
$notice
s
[
$i
]
[
'status'
]
==
'unread'
)
{
$rows
.=
'<tr class="notice-row" id="'
.
$i
ndex
.
'">'
;
if
(
$notice
[
'status'
]
==
'unread'
)
{
$rows
.=
'<td width="12" style="padding:0;padding-left:10px;vertical-align:middle;"><a href="#" class="notice '
.
((
$notice
s
[
$i
]
[
'status'
]
==
'read'
)
?
'read'
:
'unread'
)
.
((
$notice
[
'status'
]
==
'read'
)
?
'read'
:
'unread'
)
.
'"><img src="assets/images/blank.gif" width="12" height="12" /></a></td>'
;
}
else
{
$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()
.
ucfirst
(
str_replace
(
'_'
,
' '
,
$system
[
'system_message_type'
]))
.
'</span></td>'
;
$rows
.=
'<td style="vertical-align:middle;">'
.
nl2br
(
$content
)
.
'<br /><span class="legal">Sent: '
.
date
(
'M j, Y @ h:ia'
,
$notice
s
[
$i
]
[
'sent_date'
])
.
'</span></td>'
;
.
date
(
'M j, Y @ h:ia'
,
$notice
[
'sent_date'
])
.
'</span></td>'
;
$rows
.=
'</tr>'
;
}
...
...
@@ -98,12 +101,12 @@ function print_user_notices()
function
get_notification_by_trigger
(
$trigger
)
{
$args
=
array
(
$args
=
[
'post_type'
=>
'notifications'
,
'numberposts'
=>
-
1
,
'orderby'
=>
'modified'
,
'order'
=>
'desc'
)
;
]
;
$my_notif
=
false
;
...
...
@@ -129,7 +132,7 @@ function get_num_notices()
get_user_notices
(
$user
->
ID
);
$notices
=
Vars
::
$notices
;
$notifications
=
array
()
;
$notifications
=
[]
;
// return $num;
if
(
empty
(
$notices
))
{
return
0
;
...
...
@@ -162,7 +165,7 @@ function remove_notice($notification_id = -1)
Send Notifications
@trigger = notification unique slug name
*/
function
send_triggered_notification
(
$uid
=
0
,
$trigger
=
"NO_TRIGGER"
,
$args
=
array
()
,
$send_override
=
false
)
function
send_triggered_notification
(
$uid
=
0
,
$trigger
=
"NO_TRIGGER"
,
$args
=
[]
,
$send_override
=
false
)
{
global
$wpdb
;
$notification
=
get_notification_by_trigger
(
$trigger
);
...
...
@@ -186,14 +189,14 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
get_user_notices
(
$uid
);
$notices
=
Vars
::
$notices
;
$insert
=
array
(
$insert
=
[
'notification_id'
=>
$nid
,
'status'
=>
'unread'
,
'sent_date'
=>
current_time
(
'timestamp'
),
'args'
=>
$args
)
;
]
;
if
(
empty
(
$notices
))
{
$notices
=
array
()
;
$notices
=
[]
;
}
$sequence
=
Sequencer\generate
(
'NTC'
);
...
...
@@ -244,7 +247,7 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
}
}
$attachments
=
array
()
;
$attachments
=
[]
;
if
(
isset
(
$contents
[
'attachments'
]))
{
$attachments
=
$contents
[
'attachments'
];
}
...
...
@@ -356,7 +359,7 @@ function getGroups($grpID = 0)
{
global
$userAccessManager
;
$groups
=
array
()
;
$groups
=
[]
;
if
(
$grpID
>
0
)
{
$userGroups
=
$userAccessManager
->
getAccessHandler
()
...
...
@@ -398,7 +401,7 @@ class Actions
public
static
function
wp_ajax_update_notification_count
()
{
$count
=
get_num_notices
();
$return
=
array
(
'count'
=>
$count
)
;
$return
=
[
'count'
=>
$count
]
;
die
(
json_encode
(
$return
));
}
...
...
@@ -427,7 +430,7 @@ class Actions
update_post_meta
(
$id
,
'email'
,
$email
);
$return
=
array
(
'success'
=>
'true'
)
;
$return
=
[
'success'
=>
'true'
]
;
die
(
json_encode
(
$return
));
}
}
...
...
@@ -436,10 +439,10 @@ class Vars
{
public
static
$notices
;
public
static
$options
;
public
static
$field_lookup
=
array
(
public
static
$field_lookup
=
[
'allusers'
=>
"All Users"
,
'report'
=>
"Report"
)
;
]
;
}
?>
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment