I got a simple solution.
I removed your new code snippet with your original code and only changed the last line that returns the function result:
Code: Select all
// return $formatLink;
return $link;
This is now all the code of that function
Code: Select all
public static function getRightPathLink($link) {
$app = JApplication::getInstance('site');
$router = $app->getRouter();
$uri = $router->build($link);
$uriS = $uri->toString();
$pos = strpos($uriS, 'administrator');
if ($pos === false) {
$uriL = str_replace(JURI::root(true), '', $uriS);
$uriL = ltrim($uriL, '/');
$formatLink = JURI::root(false). $uriL;
} else {
$formatLink = JURI::root(false). str_replace(JURI::root(true).'/administrator/', '', $uri->toString());
}
// return $formatLink;
return $link;
}
But it only works, if in tinyMCE the URL formatting is set to
absolute.
If in tinyMCE the URL formatting is set to
relative, than the link is not complete (the host part gets lost).
That's how I understand the problem, but I cannot solve it:
If relative URL, than your code works, because before the unsubscribe link nothing appears in the Mail.
If absolute URL, than your function has to remove the host part of the link.
Because your link is only appended to the existing URL in the mail message, the host part must be removed, if there is already an absolute URL present.
Your scipt must differentiate whether there is an absolute URL set before your link or not.
Can you find a way to solve this?