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
f3eb8d8b
authored
2011-04-11 20:32:39 +0000
by
Chris Boden
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Merging notification changes (cron queue and mail cleaning) into live for CBV
1 parent
56376268
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
25 deletions
com/Notifications/Notifications.php
com/Notifications/Notifications.php
View file @
f3eb8d8
...
...
@@ -188,34 +188,28 @@ function remove_notice($notification_id = -1) {
@trigger = notification unique slug name
*/
function
send_triggered_notification
(
$uid
,
$trigger
=
"NO_TRIGGER"
,
$args
=
array
(),
$send_override
=
false
)
{
global
$wpdb
;
$notification
=
get_notification_by_trigger
(
$trigger
);
if
(
$notification
)
{
// get the notification and notificatio details....
$nid
=
$notification
->
ID
;
$details
=
get_post_meta
(
$nid
,
'details'
,
true
);
$email
=
get_post_meta
(
$nid
,
'email'
,
true
);
$system
=
get_post_meta
(
$nid
,
'system'
,
true
);
$notification
->
trigger
=
$details
[
'trigger'
];
$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_system
=
(
isset
(
$system
[
'message'
])
&&
$system
[
'message'
]
!=
""
)
?
true
:
false
;
// if is_system ==========================================
if
(
$notification
->
is_system
&&
$uid
!=
0
)
{
get_user_notices
(
$uid
);
$notices
=
Vars
::
$notices
;
$insert
=
array
(
'notification_id'
=>
$nid
,
'status'
=>
'unread'
...
...
@@ -234,22 +228,61 @@ function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array(),
update_user_meta
(
$uid
,
'notices'
,
$notices
);
}
// if is_email ===========================================
if
(
$notification
->
is_email
)
{
send_email
(
$uid
,
$email
,
$args
,
true
);
}
$user
=
new
User\Account
(
$uid
);
$email_address_preference
=
get_user_meta
(
$user
->
ID
,
'email_address_preference'
,
true
);
if
(
empty
(
$email_address_preference
))
{
$to_email
=
$user
->
user_email
;
}
else
{
$pp
=
strtolower
(
$email_address_preference
)
.
"_"
;
$to_email
=
get_user_meta
(
$user
->
ID
,
$pp
.
'email'
,
true
);
if
(
empty
(
$to_email
))
{
$to_email
=
$user
->
user_email
;
}
}
$contents
=
$email
;
$from_email
=
get_bloginfo
(
'admin_email'
);
$subject
=
strip_tags
(
$contents
[
'subject'
]);
$html
=
$contents
[
'html'
];
$alttext
=
strip_tags
(
$contents
[
'text'
]);
foreach
(
$args
as
$key
=>
$val
)
{
if
(
(
filter_var
(
$val
,
FILTER_VALIDATE_URL
)
!==
false
)
&&
!
empty
(
$html
))
{
$html
=
str_replace
(
"
{
".$key."
}
"
,
"<a href='"
.
$val
.
"'>"
.
$val
.
"</a>"
,
$html
);
}
else
{
$html
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$html
);
$alttext
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$alttext
);
$subject
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$subject
);
}
}
$attachments
=
array
();
if
(
isset
(
$contents
[
'attachments'
]))
{
$attachments
=
$contents
[
'attachments'
];
}
$att1
=
isset
(
$attachments
[
0
])
?
$attachments
[
0
]
:
''
;
$att2
=
isset
(
$attachments
[
1
])
?
$attachments
[
1
]
:
''
;
$att3
=
isset
(
$attachments
[
2
])
?
$attachments
[
2
]
:
''
;
$wpdb
->
query
(
"INSERT INTO wp_mail_daemon (notification_id,from_email,to_email,subject,text,html,attachment1,attachment2,attachment3,sent,sent_date) VALUES (
$nid
,'
$from_email
','
$to_email
','
$subject
','
$alttext
','
$html
','
$att1
','
$att2
','
$att3
',0,'')"
);
//send_email($uid,$email,$args, true);
}
}
// if the system notification has set current user than get current user otherwise loop through the users needed.
}
function
send_email
(
$uid
=
0
,
$contents
,
$args
,
$override
=
false
)
{
if
(
$uid
==
0
&&
!
isset
(
$args
[
'email'
]))
{
return
;
}
if
(
isset
(
$args
[
'email'
]))
{
$to_email
=
$args
[
'email'
];
}
else
{
...
...
@@ -272,10 +305,9 @@ function send_email($uid = 0, $contents,$args, $override = false) {
$from_address
=
get_bloginfo
(
'admin_email'
);
$subject
=
$contents
[
'subject'
];
$html
=
$contents
[
'html'
];
$alttext
=
$contents
[
'text'
];
$subject
=
strip_tags
(
$contents
[
'subject'
]);
$html
=
$contents
[
'html'
];
$alttext
=
$contents
[
'text'
];
$headers
=
""
;
...
...
@@ -296,11 +328,11 @@ function send_email($uid = 0, $contents,$args, $override = false) {
if
(
(
filter_var
(
$val
,
FILTER_VALIDATE_URL
)
!==
false
)
&&
!
empty
(
$html
))
{
$message
=
str_replace
(
"
{
".$key."
}
"
,
"<a href='"
.
$val
.
"'>"
.
$val
.
"</a>"
,
$message
);
}
else
{
$message
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$message
);
$message
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$message
);
$subject
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$subject
);
}
}
// Additional headers
//$headers .= 'To: '.$to_email.' <'.$to_email.'>' . "\r\n";
$headers
.=
'From: CICBV <'
.
$from_address
.
'>'
.
"
\r\n
"
;
...
...
Please
register
or
sign in
to post a comment