[mod] View HTML Email in Browser

3rd party code for phpList

Re: [mod] View HTML Email in Browser

Postby mrmckoy » 9:45am, Sat 11 Sep, 2010

Can anyone view the message in HTML or do they HAVE to be phplist users?
mrmckoy
PL Master
 
Posts: 169
Joined: 7:10am, Sat 24 Nov, 2007
Location: Atlanta, GA

Re: [mod] View HTML Email in Browser

Postby xannonite » 5:06pm, Sat 11 Sep, 2010

mrmckoy wrote:Can anyone view the message in HTML or do they HAVE to be phplist users?


Anyone should be able to view a message using the link in the e-mail.
xannonite
PL Nut
 
Posts: 36
Joined: 4:50pm, Tue 24 Feb, 2009

Re: [mod] View HTML Email in Browser

Postby trucmuche2005 » 10:05am, Sun 26 Dec, 2010

Hello !

I tried your mod and It seems to works properly ! Great ! Thank you for your good job !! :-)

When the static version is saved in the DB, it is saved WITH the link to the online version, and so the link is still displayed when we view the online version. Would it be possible to get this link off the online static version ??

Thank you very much for your help !!

Trucmuche
trucmuche2005
PL Nut
 
Posts: 18
Joined: 11:04am, Thu 25 Nov, 2010

Re: [mod] View HTML Email in Browser

Postby xannonite » 9:37pm, Sun 26 Dec, 2010

trucmuche2005 wrote:Would it be possible to get this link off the online static version ??


The proper way to do it would be to give the link an ID, then use DOM to find the link and remove it. However, that would require anyone using the mod to have PHP5 or later compiled with libxml. The alternative is to use a regex replace, but considering that not all of the links will be formatted the same way, it would be difficult to construct an expression that would work for everyone.

What I suggest, if you really want to get rid of the link when viewing, is to add a little JavaScript that hides the link. Most e-mail programs block JavaScript, so it would theoretically only hide the link when viewed in a browser. Of course, it still wouldn't work for NoScript users:

Code: Select all
  <a id="browser_link" href="{VIEWMESSAGEURL}">Click here to view in your browser</a>
  <script type="text/javascript">document.getElementById('browser_link').style.display='none';</script>


In case an e-mail program does allow JavaScript, you could go even further and detect the user agent:

http://www.javascriptkit.com/javatutors/navigator.shtml
xannonite
PL Nut
 
Posts: 36
Joined: 4:50pm, Tue 24 Feb, 2009

Re: [mod] View HTML Email in Browser

Postby trucmuche2005 » 10:42am, Mon 27 Dec, 2010

Hello !

I thought about this problem... Why wouldn't it be possible to modify the version stored in the database to get off the link where the [VIEWMESSAGEURL] is used ?

I imagine using this regexp
Code: Select all
preg_replace('/<a href\=[\"]\[VIEWMESSAGEURL\][\"]\>(.*?)<\/a>/si','',$text);

to get off the '<a href="[VIEWMESSAGEURL]"> ... </a>' links. I tried it and it seems to be ok...

So, simply replacing the original code of the MOD in sendemaillib.php
Code: Select all
      if(preg_match('/(<html>)|(<head[^>]*>)|(<body[^>]*>)/i', $mail->Body)) {
        Sql_Query(sprintf('update %s set data = "%s" where messageid = %d and uniqid = "%s"',
        $GLOBALS["tables"]["messageview"],addslashes($htmlmessage),$messageid,$hash));
        if(!Sql_Affected_Rows())
        Sql_Query(sprintf('insert into %s (messageid,uniqid,data) values(%d,"%s","%s")',
        $GLOBALS["tables"]["messageview"],$messageid,$hash,addslashes($htmlmessage)));
      }

by this modified code
Code: Select all
     
$htmlmessage_withoutVIEWMESSAGEURL = preg_replace('/<a href\=[\"]\[VIEWMESSAGEURL\][\"]\>(.*?)<\/a>/si','',$htmlmessage);
if(preg_match('/(<html>)|(<head[^>]*>)|(<body[^>]*>)/i', $mail->Body)) {
        Sql_Query(sprintf('update %s set data = "%s" where messageid = %d and uniqid = "%s"',
        $GLOBALS["tables"]["messageview"],addslashes($htmlmessage_withoutVIEWMESSAGEURL),$messageid,$hash));
        if(!Sql_Affected_Rows())
        Sql_Query(sprintf('insert into %s (messageid,uniqid,data) values(%d,"%s","%s")',
        $GLOBALS["tables"]["messageview"],$messageid,$hash,addslashes($htmlmessage_withoutVIEWMESSAGEURL)));
      }

would do the trick, or not ?

I didn't tried yet... I prefer to ask you before :-)

Thanks for your advices !

Trucmuche
trucmuche2005
PL Nut
 
Posts: 18
Joined: 11:04am, Thu 25 Nov, 2010

Re: [mod] View HTML Email in Browser

Postby xannonite » 8:52pm, Mon 27 Dec, 2010

As I said, using regex to remove the link is an option. However, the expression you are using will only work for a link formatted as you've specified. The solution may work perfectly for you, but not everyone will write their code the same way. Also, [VIEWMESSAGEURL] should have already been replaced by the time the message is written to the database, so searching for that tag shouldn't work. You would need to copy the contents of the $htmlmessage variable before the custom tag is replaced.

Personally I feel that using regex to modify HTML is too messy. If I were to integrate a solution into the mod, I would rather use something cleaner that will work for everyone. In this case I think it is better for users to work out their own methods.
xannonite
PL Nut
 
Posts: 36
Joined: 4:50pm, Tue 24 Feb, 2009

Re: [mod] View HTML Email in Browser

Postby trucmuche2005 » 11:09am, Mon 10 Jan, 2011

Of course I agree with you, xannonite ! I would also prefer a solution that works for everyone ! But... Which one ?
I'm not PHP programmer, I only know some basic techniques... I would like to help...

Someone told me about this : http://api.jquery.com/remove/
It seems to be perfectly suited to this... Would it be possible to use it in PHPList to remove the link ??

I understand in your message that the line in sendemaillib.php I suggested to modify is not the correct one because the [VIEWMESSAGEURL] tag has already been replaced.
Where does this substitution is made in the php code ? I didn't found out the instruction which causes the tag is substituted. Could you tell me ?
Maybe if I know this I could imagine a solution...

Thanks for your help !

Best wishes for 2011 ! :-)

Trucmuche
trucmuche2005
PL Nut
 
Posts: 18
Joined: 11:04am, Thu 25 Nov, 2010

Re: [mod] View HTML Email in Browser

Postby xannonite » 8:18pm, Mon 10 Jan, 2011

jQuery uses JavaScript, and anything involving JavaScript should be implemented by the user in the HTML itself. That `remove` function essentially provides a short-hand way of doing what I already described using an ID or class in your HTML. However, you would need to add an additional <script> element to include the necessary jQuery framework, which seems rather unnecessary for a simple e-mail.

If you open your modded sendemaillib.php and search for VIEWMESSAGEURL, you will see a whole section where various tags are replaced using preg_replace() and eregi_replace(). That is where the link is inserted. If you want the link to be removed while still maintaining all the other tag replacements, then you will need to make a copy of $htmlmessage before all those tags are replaced, then duplicate all of those preg_replace/eregi_replace lines minus the VIEWMESSAGEURL lines. Alternatively you could clean it up by using an array for the tags and a loop. Either way the script is going to be doing twice the work just to remove the link, and it would have to be updated every time the list of tags was changed - including changes from other mods. All-in-all it's not a good solution.
xannonite
PL Nut
 
Posts: 36
Joined: 4:50pm, Tue 24 Feb, 2009

Re: [mod] View HTML Email in Browser

Postby trucmuche2005 » 6:06pm, Tue 25 Jan, 2011

I have a problem. The tag [VIEWMESSAGEURL] is replaced by an URL of the type
Code: Select all
http://www.mydomain.com/newsletter/vm.php?m=51&u=e2998f7775555555d8fffe3b13c0734b

But it seems that this URL is valid only for people to who I sent the newsletter : if someone who did not receive the newsletter wants to see the static version of the newsletter by accessing this link, a blank page appears...

I would like to copy a link to static version to facebook, for instance, but if the page shown is entirely blank, it's not really interesting... :D

How can I do ? Is PHPList configured to restrict access to static versions ?

Many thanks in advance for your help !!

Trucmuche
trucmuche2005
PL Nut
 
Posts: 18
Joined: 11:04am, Thu 25 Nov, 2010

Re: [mod] View HTML Email in Browser

Postby xannonite » 12:46am, Wed 26 Jan, 2011

It should not matter who views the message. When a user clicks the link in their e-mail, it is the same as someone clicking the link in Facebook or anywhere else. If a blank page is displayed, then you should check your PHP log for errors. It could be that you didn't copy/paste the link properly. You might also need to delete your cookies.

p.s. Keep in mind that if you post a link for others to click on, the contents of the message will be personalized for the person who originally received the link. You might want to create a separate e-mail account specifically for public links so that you don't inadvertently expose a list member's name or other info.
xannonite
PL Nut
 
Posts: 36
Joined: 4:50pm, Tue 24 Feb, 2009

Re: [mod] View HTML Email in Browser

Postby locomot1f » 9:35pm, Thu 24 Feb, 2011

I'm having trouble with this script. I've downloaded the lastest - 1.2.2 version.

My problem is with the unique ID column. and possibly the messageid column

On first attempts, my messageid starts with 142 for the first entry.

the uniqueid column does not get populated. i've looked at other entries involving this, but nothing seems to point me in the correct direction.

I have tried plugging in the [USERID] placeholder in my message, and it does show up. I know that you stated that something is removing this before it gets to your script... but I have no idea what it could be... any advice would be greatly appreciated!

i'm using PHPList v.2.10.12

thanks in advance
locomot1f
phpLister
 
Posts: 7
Joined: 9:32pm, Thu 11 Mar, 2010

Re: [mod] View HTML Email in Browser

Postby xannonite » 12:04am, Fri 25 Feb, 2011

locomot1f wrote:I'm having trouble with this script. I've downloaded the lastest - 1.2.2 version.

My problem is with the unique ID column. and possibly the messageid column

On first attempts, my messageid starts with 142 for the first entry.

the uniqueid column does not get populated. i've looked at other entries involving this, but nothing seems to point me in the correct direction.

I have tried plugging in the [USERID] placeholder in my message, and it does show up. I know that you stated that something is removing this before it gets to your script... but I have no idea what it could be... any advice would be greatly appreciated!

i'm using PHPList v.2.10.12

thanks in advance


Did you setup the database table using phplist's built-in utility, or did you use the .sql file included with the mod? What version of MySQL are you using? If you can, enable error display in your PHP configuration. It sounds to me like there is a problem saving the message to the database, but it will be difficult to troubleshoot without an error message.
xannonite
PL Nut
 
Posts: 36
Joined: 4:50pm, Tue 24 Feb, 2009

Re: [mod] View HTML Email in Browser

Postby bhup18 » 3:11pm, Fri 25 Feb, 2011

using latest mod 1.2.2

Bug?

If you use [VIEWMESSAGEURL] tag more than once in the message, the link may not be replaced correctly or just with "http://" .

Discovered this by accident.
bhup18
phpLister
 
Posts: 11
Joined: 8:26pm, Wed 15 Dec, 2010

Re: [mod] View HTML Email in Browser

Postby locomot1f » 7:38pm, Fri 25 Feb, 2011

1) I used the SQL script provided by the mod UTF8 version. I have also tried the Latin one. I'm sure I should be using the UTF8 though.

2)MySQL Server version: 5.1.55 Source distribution

3) I've tried to enable the error display in my .htaccess file by adding
Code: Select all
php_flag display_errors on
to the file. I also enabled through my php.ini file

It's not showing any errors. I'm starting to guess that there is some confusion on how the uniqueid is referenced. could there be a further setting in the config of the PHP List that could do this? Is it the structure.php file that actually populates the fields? or some other process? I have noticed that this script runs when a message is sent. I'm still not understanding the reason for needing the uniqueid column....?

Naturally I can plug in the [USERID] in the row, refresh the page, and it comes up. but yeah, for some reason, that's the ONLY field that does not get populated -- no errors to report.

Again, Using PHPList 2.10.12
locomot1f
phpLister
 
Posts: 7
Joined: 9:32pm, Thu 11 Mar, 2010

Re: [mod] View HTML Email in Browser

Postby xannonite » 8:27pm, Fri 25 Feb, 2011

locomot1f wrote:1) I used the SQL script provided by the mod UTF8 version. I have also tried the Latin one. I'm sure I should be using the UTF8 though.

2)MySQL Server version: 5.1.55 Source distribution

3) I've tried to enable the error display in my .htaccess file by adding
Code: Select all
php_flag display_errors on
to the file. I also enabled through my php.ini file

It's not showing any errors. I'm starting to guess that there is some confusion on how the uniqueid is referenced. could there be a further setting in the config of the PHP List that could do this? Is it the structure.php file that actually populates the fields? or some other process? I have noticed that this script runs when a message is sent. I'm still not understanding the reason for needing the uniqueid column....?

Naturally I can plug in the [USERID] in the row, refresh the page, and it comes up. but yeah, for some reason, that's the ONLY field that does not get populated -- no errors to report.

Again, Using PHPList 2.10.12


Try deleting the table and recreating it using phplist's built-in utility. If that doesn't work, try deleting the table's primary key. The uniqid is the same as the [USERID]. It is required for message personalization to be preserved. structure.php handles database table creation using phplists's built-in utility. The mod runs each time an HTML message is sent, saving each copy to each user to the database.

bhup18 wrote:using latest mod 1.2.2

Bug?

If you use [VIEWMESSAGEURL] tag more than once in the message, the link may not be replaced correctly or just with "http://" .

Discovered this by accident.


Do you also have this problem with other tags that insert URLs? This mod uses the same functions that phplist uses (namely preg_replace and eregi_replace.) If there is a bug, it should affect other tags as well. If you are checking the source in the e-mail after you receive it, try checking the source in the database instead.
xannonite
PL Nut
 
Posts: 36
Joined: 4:50pm, Tue 24 Feb, 2009

PreviousNext

Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 2 guests