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
66546631
authored
2014-10-20 11:07:22 -0400
by
Marty Penner
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Always show a notice icon in notification rows
1 parent
fd76b669
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
40 deletions
com/Notifications/Notifications.php
com/Notifications/Notifications.php
View file @
6654663
...
...
@@ -2,18 +2,18 @@
namespace
Tz\WordPress\Tools\Notifications
;
use
Tz\Common
;
use
Tz\WordPress\Tools
;
use
Tz\WordPress\Tools\Sequencer
;
use
Tz\WordPress\CBV
;
use
Tz\WordPress\CBV\User
;
use
Tz\WordPress\Tools
;
use
Tz\WordPress\Tools\Sequencer
;
use
WP_User
;
use
Exception
,
StdClass
;
const
OPTION_NAME
=
"notif_options"
;
const
OPTION_NAME
=
'notif_options'
;
const
NOTIFICATION_STATUS_READ
=
'read'
;
const
NOTIFICATION_STATUS_UNREAD
=
'unread'
;
call_user_func
(
function
()
{
function
()
{
Tools\add_actions
(
__NAMESPACE__
.
'\Actions'
);
Vars
::
$options
=
new
Tools\WP_Option
(
OPTION_NAME
);
Vars
::
$notices
=
[];
...
...
@@ -21,17 +21,19 @@ call_user_func(
require_once
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'Validation.php'
);
require_once
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'Admin.php'
);
}
});
}
);
function
subval_sort
(
$a
,
$subkey
,
$sort
)
{
foreach
(
$a
as
$k
=>
$v
)
{
foreach
(
$a
as
$k
=>
$v
)
{
$b
[
$k
]
=
strtolower
(
$v
[
$subkey
]);
}
$sort
(
$b
);
foreach
(
$b
as
$key
=>
$val
)
{
foreach
(
$b
as
$key
=>
$val
)
{
$c
[]
=
$a
[
$key
];
}
return
$c
;
}
...
...
@@ -58,8 +60,8 @@ function print_user_notices($showOnlyUnread = false)
continue
;
}
$system
=
get_post_meta
(
$notice
[
'notification_id'
],
'system'
,
true
);
$content
=
$system
[
'message'
];
$system
=
get_post_meta
(
$notice
[
'notification_id'
],
'system'
,
true
);
$content
=
$system
[
'message'
];
if
(
isset
(
$notice
[
'args'
])
&&
count
(
$notice
[
'args'
])
>
0
)
{
foreach
(
$notice
[
'args'
]
as
$key
=>
$val
)
{
...
...
@@ -72,13 +74,9 @@ function print_user_notices($showOnlyUnread = false)
}
$rows
.=
'<tr class="notice-row" id="'
.
$index
.
'">'
;
if
(
$notice
[
'status'
]
==
'unread'
)
{
$rows
.=
'<td width="12" style="padding:0;padding-left:10px;vertical-align:middle;"><a href="#" class="notice '
.
((
$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>'
;
}
$rows
.=
'<td width="12" style="padding:0;padding-left:10px;vertical-align:middle;"><a href="#" class="notice '
.
((
$notice
[
'status'
]
==
'read'
)
?
'read'
:
'unread'
)
.
'"><img src="assets/images/blank.gif" width="12" height="12"></a></td>'
;
if
(
$system
[
'system_message_type'
]
==
'none'
)
{
$system
[
'system_message_type'
]
=
'notice'
;
...
...
@@ -102,17 +100,17 @@ function print_user_notices($showOnlyUnread = false)
function
get_notification_by_trigger
(
$trigger
)
{
$args
=
[
'post_type'
=>
'notifications'
,
'numberposts'
=>
-
1
,
'orderby'
=>
'modified'
,
'order'
=>
'desc'
'post_type'
=>
'notifications'
,
'numberposts'
=>
-
1
,
'orderby'
=>
'modified'
,
'order'
=>
'desc'
];
$my_notif
=
false
;
foreach
(
get_posts
(
$args
)
as
$entry
)
{
$details
=
get_post_meta
(
$entry
->
ID
,
'details'
,
true
);
if
(
$details
[
'type'
]
==
"triggered"
&&
$details
[
'trigger'
]
==
$trigger
)
{
if
(
$details
[
'type'
]
==
'triggered'
&&
$details
[
'trigger'
]
==
$trigger
)
{
$my_notif
=
$entry
;
break
;
}
...
...
@@ -123,7 +121,7 @@ function get_notification_by_trigger($trigger)
/**
* GET NUMBER OF NEW NOTICES
@returns (Int)
*
@returns (Int)
*/
function
get_num_notices
()
{
...
...
@@ -143,27 +141,33 @@ function get_num_notices()
}
}
}
return
count
(
$notifications
);
}
function
remove_notice
(
$notification_id
=
-
1
)
/**
* @param int $notification_id
* @param string $status
*/
function
markNotice
(
$notification_id
=
-
1
,
$status
=
NOTIFICATION_STATUS_READ
)
{
get_user_notices
(
Tools\getCurrentUser
()
->
ID
);
$notices
=
Vars
::
$notices
;
if
(
!
empty
(
$notices
))
{
foreach
(
$notices
as
$id
=>
$notice
)
{
if
(
$id
==
$notification_id
)
{
$notices
[
$id
][
'status'
]
=
"read"
;
$notices
[
$id
][
'status'
]
=
$status
;
break
;
}
}
}
update_user_meta
(
Tools\getCurrentUser
()
->
ID
,
'notices'
,
$notices
);
}
/**
Send Notifications
@trigger = notification unique slug name
*
Send Notifications
*
@trigger = notification unique slug name
*/
function
send_triggered_notification
(
$uid
=
0
,
$trigger
=
"NO_TRIGGER"
,
$args
=
[],
$send_override
=
false
)
{
...
...
@@ -181,7 +185,9 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
$notification
->
status
=
isset
(
$details
[
'status'
])
?
$details
[
'status'
]
:
"active"
;
$notification
->
type
=
$details
[
'type'
];
$notification
->
sendto
=
@
$details
[
'sendto'
];
$notification
->
is_email
=
((
$email
[
'text'
]
!=
""
||
$email
[
'html'
]
!=
""
)
&&
$email
[
'subject'
]
!=
""
)
?
true
:
false
;
$notification
->
is_email
=
((
$email
[
'text'
]
!=
""
||
$email
[
'html'
]
!=
""
)
&&
$email
[
'subject'
]
!=
""
)
?
true
:
false
;
$notification
->
is_system
=
(
isset
(
$system
[
'message'
])
&&
$system
[
'message'
]
!=
""
)
?
true
:
false
;
// if is_system ==========================================
...
...
@@ -190,10 +196,10 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
$notices
=
Vars
::
$notices
;
$insert
=
[
'notification_id'
=>
$nid
,
'status'
=>
'unread'
,
'sent_date'
=>
current_time
(
'timestamp'
),
'args'
=>
$args
'notification_id'
=>
$nid
,
'status'
=>
'unread'
,
'sent_date'
=>
current_time
(
'timestamp'
),
'args'
=>
$args
];
if
(
empty
(
$notices
))
{
$notices
=
[];
...
...
@@ -285,7 +291,6 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
'%s'
]
);
//send_email($uid,$email,$args, true);
}
}
...
...
@@ -364,6 +369,7 @@ function getGroups($grpID = 0)
$userGroups
=
$userAccessManager
->
getAccessHandler
()
->
getUserGroups
(
$grpID
);
return
$userGroups
->
getGroupName
();
}
else
{
$userGroups
=
$userAccessManager
...
...
@@ -373,6 +379,7 @@ function getGroups($grpID = 0)
foreach
(
$userGroups
as
$group
)
{
$groups
[
$group
->
getId
()]
=
$group
->
getGroupName
();
}
return
$groups
;
}
...
...
@@ -393,6 +400,7 @@ function current_url()
}
else
{
$pageURL
.=
$_SERVER
[
"SERVER_NAME"
]
.
$_SERVER
[
"REQUEST_URI"
];
}
return
$pageURL
;
}
...
...
@@ -401,13 +409,18 @@ class Actions
public
static
function
wp_ajax_update_notification_count
()
{
$count
=
get_num_notices
();
$return
=
[
'count'
=>
$count
];
$return
=
[
'count'
=>
$count
];
die
(
json_encode
(
$return
));
}
public
static
function
wp_ajax_mark_read
()
{
remove_notice
(
$_POST
[
'index'
]);
markNotice
(
$_POST
[
'index'
],
NOTIFICATION_STATUS_READ
);
}
public
static
function
wp_ajax_mark_unread
()
{
markNotice
(
$_POST
[
'index'
],
NOTIFICATION_STATUS_UNREAD
);
}
public
static
function
wp_ajax_print_user_notices
()
...
...
@@ -440,9 +453,7 @@ class Vars
public
static
$notices
;
public
static
$options
;
public
static
$field_lookup
=
[
'allusers'
=>
"All Users"
,
'report'
=>
"Report"
'allusers'
=>
'All Users'
,
'report'
=>
'Report'
];
}
?>
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment