Dilemma with relative or absolute URL and unsubscribe link

Phoca Email (Newsletter) - sending emails and managing newsletters in Joomla! CMS
User avatar
f.gruber
Phoca Member
Phoca Member
Posts: 39
Joined: 12 Sep 2012, 11:47

Dilemma with relative or absolute URL and unsubscribe link

Post by f.gruber »

Hi,
if I insert a link into my newsletter:

Code: Select all

http://joomla_host/subdir
this link appears in the mail message as:

Code: Select all

../subdir

This depends on the tinyMCE option concernig the URL management, it is set to relative URL per default.
Of course this link cannot work inside an e-Mail body on the client.
But the unsubscribe link in the mail message is displayed correct.

After I change the URL option in tinyMCE to absolute URL, the links in my mail-message are working, because they are displayed as absolute URL, but now I get the unsubscribe link with the base part of the URL doubled:

Code: Select all

http://my_joomla_site/http://my_joomla_site/index.php/component/phocaemail/unsubscribe9bc067cca5fa12...
Please help!
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47865
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Dilemma with relative or absolute URL and unsubscribe li

Post by Jan »

Hi, the code which tries to correct the link is here:

administrator\components\com_phocaemail\helpers\phocaemailsendnewsletteremail.php

Code: Select all

public static function getRightPathLink($link) {
So maybe some rule which prevent from changing the unsubscribe link:

FROM:
$pos = strpos($uriS, 'administrator');

if ($pos === false) {

$uriL = str_replace(JURI::root(true), '', $uriS);
$uriL = ltrim($uriL, '/');
$formatLink = JURI::root(false). $uriL;
//$formatLink = $uriS;
} else {
$formatLink = JURI::root(false). str_replace(JURI::root(true).'/administrator/', '', $uri->toString());
}

TO:

Code: Select all

$pos 			= strpos($uriS, 'administrator');
		
		if ($pos === false) {
			
			$pos2 			= strpos($uriS, 'unsubscribe');
			if ($pos === false) {
			
				$uriL = str_replace(JURI::root(true), '', $uriS);
				$uriL = ltrim($uriL, '/');
				$formatLink = JURI::root(false). $uriL;
			} else {
				$formatLink = $uriS;
			}
			
		} else {
			$formatLink = JURI::root(false). str_replace(JURI::root(true).'/administrator/', '', $uri->toString());
		}
Please test and let me know.

Jan
If you find Phoca extensions useful, please support the project
User avatar
f.gruber
Phoca Member
Phoca Member
Posts: 39
Joined: 12 Sep 2012, 11:47

Re: Dilemma with relative or absolute URL and unsubscribe li

Post by f.gruber »

Jan wrote: Please test and let me know. ...
Thank you for trying to change this issue.
Unfortunately it did not help.

But first of all, I think that line 4 of your code snippet should be

Code: Select all

if ($pos2 === false) 
instead of

Code: Select all

if ($pos === false) 

... ?
The dilemma remains:
When tiniMCE is set to absolute URL, then the unsubscribe URL appears damaged - see above.
If I set TinyMCE to relative URL, then the unsubscribe link is ok, but then all other links in the mail body are relative and therefore they cannot work.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47865
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Dilemma with relative or absolute URL and unsubscribe li

Post by Jan »

Hi, yes, sorry for the typo error (corrected in the code)

The modification should prevent from first problem - the unsubscribe URL in wrong format - if you set it to absolute URL, then the if condition will prevent from changing the unsubscribe URL.

Maybe try to print_r all the variables inside this part of code, to know where the wrong formatting is coming ($uriL, $uriS, $formatLink, ...)

:idea:

Jan
If you find Phoca extensions useful, please support the project
User avatar
f.gruber
Phoca Member
Phoca Member
Posts: 39
Joined: 12 Sep 2012, 11:47

Re: Dilemma with relative or absolute URL and unsubscribe li

Post by f.gruber »

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?
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47865
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Dilemma with relative or absolute URL and unsubscribe li

Post by Jan »

Hi, this is what I have tried - to differentiate between absolute and relative. The difference should be, as you have written in links and unsubscribe link - so there is the condition:

$pos2 = strpos($uriS, 'unsubscribe');

which should not change the unsubscribe link but the others too.

I will take a closer look at it for the next version.

Jan
If you find Phoca extensions useful, please support the project
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47865
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Dilemma with relative or absolute URL and unsubscribe link

Post by Jan »

Hi, try to see version 3.0.6.

https://www.phoca.cz/news/981-phoca-ema ... 6-released

Should work Ok there.

Jan
If you find Phoca extensions useful, please support the project
Post Reply