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
b43072e0
authored
2015-02-12 13:56:31 -0500
by
Marty Penner
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Make notifications translatable
1 parent
a1a85c5a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
30 deletions
com/Notifications/Admin.php
com/Notifications/Notifications.php
com/Notifications/views/create.php
com/Notifications/views/form.php
com/Notifications/Admin.php
View file @
b43072e
This diff is collapsed.
Click to expand it.
com/Notifications/Notifications.php
View file @
b43072e
...
...
@@ -79,7 +79,9 @@ function print_user_notices($showOnlyUnread = false)
}
$system
=
get_post_meta
(
$notice
[
'notification_id'
],
'system'
,
true
);
$content
=
$system
[
'message'
];
$content
=
isset
(
$system
[
ICL_LANGUAGE_CODE
.
'_message'
])
?
$system
[
ICL_LANGUAGE_CODE
.
'_message'
]
:
$system
[
'en_message'
];
if
(
isset
(
$notice
[
'args'
])
&&
count
(
$notice
[
'args'
])
>
0
)
{
foreach
(
$notice
[
'args'
]
as
$key
=>
$val
)
{
...
...
@@ -214,6 +216,9 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
/** @var \wpdb $wpdb */
global
$wpdb
;
// LANGTODO: get this from the user's preference. As it stands, if an admin triggers this, the notification will be in whatever language the admin is viewing the page as
$lang
=
ICL_LANGUAGE_CODE
;
/** @var \StdClass $notification */
$notification
=
get_notification_by_trigger
(
$trigger
);
...
...
@@ -228,10 +233,8 @@ 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_system
=
(
isset
(
$system
[
'message'
])
&&
$system
[
'message'
]
!=
''
)
?
true
:
false
;
$notification
->
is_email
=
((
$email
[
$lang
.
'_text'
]
!=
''
||
$email
[
$lang
.
'_html'
]
!=
''
)
&&
$email
[
$lang
.
'_subject'
]
!=
''
);
$notification
->
is_system
=
(
isset
(
$system
[
$lang
.
'_message'
])
&&
$system
[
$lang
.
'_message'
]
!=
''
);
// if is_system ==========================================
if
(
$notification
->
is_system
&&
$uid
!=
0
)
{
...
...
@@ -257,49 +260,56 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
// if is_email ===========================================
if
(
$notification
->
is_email
)
{
if
(
$uid
==
0
&&
!
isset
(
$args
[
'email'
]))
{
return
;
}
elseif
(
$uid
==
0
&&
isset
(
$args
[
'email'
]))
{
$to
_e
mail
=
$args
[
'email'
];
$to
E
mail
=
$args
[
'email'
];
}
else
{
$user
=
new
User\Account
(
$uid
);
$email_address_preference
=
get_user_meta
(
$user
->
ID
,
'email_address_preference'
,
true
);
if
(
empty
(
$email_address_preference
))
{
$to
_e
mail
=
$user
->
user_email
;
$to
E
mail
=
$user
->
user_email
;
}
else
{
$pp
=
strtolower
(
$email_address_preference
)
.
'_'
;
$toEmail
=
get_user_meta
(
$user
->
ID
,
$pp
.
'email'
,
true
);
$pp
=
strtolower
(
$email_address_preference
)
.
"_"
;
$to_email
=
get_user_meta
(
$user
->
ID
,
$pp
.
'email'
,
true
);
if
(
empty
(
$to_email
))
{
$to_email
=
$user
->
user_email
;
if
(
empty
(
$toEmail
))
{
$toEmail
=
$user
->
user_email
;
}
}
}
$contents
=
$email
;
$from_email
=
get_bloginfo
(
'admin_email'
);
$subject
=
strip_tags
(
$contents
[
'subject'
]);
$html
=
@
$contents
[
'html'
];
$alttext
=
strip_tags
(
$contents
[
'text'
]);
$fromEmail
=
get_bloginfo
(
'admin_email'
);
$subject
=
strip_tags
(
isset
(
$contents
[
$lang
.
'_subject'
])
&&
!
empty
(
$contents
[
$lang
.
'_subject'
])
?
$contents
[
$lang
.
'_subject'
]
:
$contents
[
'en_subject'
]
);
$html
=
isset
(
$contents
[
$lang
.
'_html'
])
&&
!
empty
(
$contents
[
$lang
.
'_html'
])
?
$contents
[
$lang
.
'_html'
]
:
@
$contents
[
'en_html'
];
$altText
=
strip_tags
(
isset
(
$contents
[
$lang
.
'_text'
])
&&
!
empty
(
$contents
[
$lang
.
'_text'
])
?
$contents
[
$lang
.
'_text'
]
:
$contents
[
'en_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
);
$html
=
str_replace
(
'{'
.
$key
.
'}'
,
'<a href="'
.
$val
.
'">'
.
$val
.
'</a>'
,
$html
);
}
else
{
$html
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$html
);
$alt
text
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$altt
ext
);
$subject
=
str_replace
(
"
{
".$key."
}
"
,
$val
,
$subject
);
$html
=
str_replace
(
'{'
.
$key
.
'}'
,
$val
,
$html
);
$alt
Text
=
str_replace
(
'{'
.
$key
.
'}'
,
$val
,
$altT
ext
);
$subject
=
str_replace
(
'{'
.
$key
.
'}'
,
$val
,
$subject
);
}
}
$attachments
=
[];
if
(
isset
(
$contents
[
'attachments'
]))
{
$attachments
=
$contents
[
'attachments'
];
}
$attachments
=
isset
(
$contents
[
$lang
.
'_attachments'
])
?
$contents
[
$lang
.
'_attachments'
]
:
$contents
[
'en_attachments'
];
$att1
=
isset
(
$attachments
[
0
])
?
$attachments
[
0
]
:
''
;
$att2
=
isset
(
$attachments
[
1
])
?
$attachments
[
1
]
:
''
;
$att3
=
isset
(
$attachments
[
2
])
?
$attachments
[
2
]
:
''
;
...
...
@@ -313,7 +323,7 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
$sentSuccessfully
=
false
;
if
(
CBV\system_can_send_emails
())
{
$response
=
\wpMandrill
::
mail
(
$to
_email
,
$subject
,
!
empty
(
$html
)
?
$html
:
$altt
ext
,
[],
$attachments
);
$response
=
\wpMandrill
::
mail
(
$to
Email
,
$subject
,
!
empty
(
$html
)
?
$html
:
$altT
ext
,
[],
$attachments
);
if
(
is_array
(
$response
)
&&
isset
(
$response
[
0
][
'status'
])
...
...
@@ -328,10 +338,10 @@ function send_triggered_notification($uid = 0, $trigger = 'NO_TRIGGER', $args =
'wp_mail_daemon'
,
[
'notification_id'
=>
$nid
,
'from_email'
=>
$from
_e
mail
,
'to_email'
=>
$to
_e
mail
,
'from_email'
=>
$from
E
mail
,
'to_email'
=>
$to
E
mail
,
'subject'
=>
$subject
,
'text'
=>
$alt
t
ext
,
'text'
=>
$alt
T
ext
,
'html'
=>
$html
,
'attachment1'
=>
$att1
,
'attachment2'
=>
$att2
,
...
...
com/Notifications/views/create.php
View file @
b43072e
...
...
@@ -9,7 +9,7 @@ use Tz\WordPress\Tools\Notifications\Settings;
<div
class=
"wrap"
>
<h2>
Notifications - Create New
</h2>
<?php
if
(
isset
(
$flash
)
&&
$flash
!=
""
)
:
?>
<?php
if
(
isset
(
$flash
)
&&
$flash
!=
''
)
:
?>
<div
class=
"post-success"
>
<?php
echo
$flash
;
?>
</div>
...
...
com/Notifications/views/form.php
View file @
b43072e
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to post a comment