Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
civicrm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plugins
civicrm
Commits
9dbf1e53
Verified
Commit
9dbf1e53
authored
5 years ago
by
Andrei Mondoc
Committed by
Kevin Cristiano
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add suport for 'civicrm_alterExternUrl' hook
Signed-off-by:
Kevin Cristiano
<
kcristiano@kcristiano.com
>
parent
e03acce4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wp-rest/Civi/Mailing-Hooks.php
+64
-3
64 additions, 3 deletions
wp-rest/Civi/Mailing-Hooks.php
with
64 additions
and
3 deletions
wp-rest/Civi/Mailing-Hooks.php
+
64
−
3
View file @
9dbf1e53
...
...
@@ -25,6 +25,14 @@ class Mailing_Hooks {
*/
public
$open_endpoint
;
/**
* The parsed WordPress REST url.
*
* @since 1.0
* @var array
*/
public
$parsed_rest_url
;
/**
* Constructor.
*
...
...
@@ -36,6 +44,8 @@ class Mailing_Hooks {
$this
->
open_endpoint
=
rest_url
(
'civicrm/v3/open'
);
$this
->
parsed_rest_url
=
parse_url
(
rest_url
()
);
}
/**
...
...
@@ -47,6 +57,38 @@ class Mailing_Hooks {
add_filter
(
'civicrm_alterMailParams'
,
[
$this
,
'do_mailing_urls'
],
10
,
2
);
add_filter
(
'civicrm_alterExternUrl'
,
[
$this
,
'alter_mailing_extern_urls'
],
10
,
6
);
}
/**
* Replaces the open, and click
* tracking URLs for a mailing (CiviMail)
* with thier REST counterparts.
*
* @uses 'civicrm_alterExternUrl' filter
*
* @param \GuzzleHttp\Psr7\Uri $url
* @param string|null $path
* @param string|null $query
* @param string|null $fragment
* @param bool|null $absolute
* @param bool|null $isSSL
*/
public
function
alter_mailing_extern_urls
(
&
$url
,
$path
,
$query
,
$fragment
,
$absolute
,
$isSSL
)
{
if
(
$path
==
'extern/url'
)
{
$url
=
$url
->
withHost
(
$this
->
parsed_rest_url
[
'host'
]
)
->
withPath
(
"
{
$this
->
parsed_rest_url
[
'path'
]
}
civicrm/v3/url"
);
}
if
(
$path
==
'extern/open'
)
{
$url
=
$url
->
withHost
(
$this
->
parsed_rest_url
[
'host'
]
)
->
withPath
(
"
{
$this
->
parsed_rest_url
[
'path'
]
}
civicrm/v3/open"
);
}
}
/**
...
...
@@ -62,11 +104,15 @@ class Mailing_Hooks {
*/
public
function
do_mailing_urls
(
&
$params
,
$context
)
{
if
(
$context
==
'civimail'
)
{
if
(
in_array
(
$context
,
[
'civimail'
,
'flexmailer'
]
)
)
{
$params
[
'html'
]
=
$this
->
replace_html_mailing_tracking_urls
(
$params
[
'html'
]
);
$params
[
'html'
]
=
$this
->
is_mail_tracking_url_alterable
(
$params
[
'html'
]
)
?
$this
->
replace_html_mailing_tracking_urls
(
$params
[
'html'
]
)
:
$params
[
'html'
];
$params
[
'text'
]
=
$this
->
replace_text_mailing_tracking_urls
(
$params
[
'text'
]
);
$params
[
'text'
]
=
$this
->
is_mail_tracking_url_alterable
(
$params
[
'text'
]
)
?
$this
->
replace_text_mailing_tracking_urls
(
$params
[
'text'
]
)
:
$params
[
'text'
];
}
...
...
@@ -133,4 +179,19 @@ class Mailing_Hooks {
}
/**
* Checks whether for a given mail
* content (text or html) the tracking URLs
* are alterable/need to be altered.
*
* @since 0.1
* @param string $content The mail content (text or html)
* @return bool $is_alterable
*/
public
function
is_mail_tracking_url_alterable
(
string
$content
)
{
return
strpos
(
$content
,
'civicrm/extern/url.php'
)
||
strpos
(
$content
,
'civicrm/extern/open.php'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment