I looked for a solution to have a "view in browser" function for PHPLIST and fell over the mod from xanonite, which I figured a good approach. But why store every sent message in the database? PHPLIST already has a function ("sendEmail") which creates a user specific HTML message by fetching a message, it's template and the user specific data from the database. Why not use this code to build a message on the fly and display it online?
There where some obstacles to deal with:
- - the admin/sendemaillib.php has some SQL_Query code at it's end, which will be called every time you try to include this file.
- the admin/sendemaillib.php calls admin/accesscheck.php, which (I assume) blocks access, if you are not logged in as a user. This wouldn't be useful for a "view online in browser" function
- the sendEmail function in admin/sendemaillib.php returns only 0 or 1. But we need the HTML message to display it online.
The admin/sendemaillib.php was useless to me as it is. What I did:
- - I created a function require_once_custom in admin/lib.php, which tries to fetch a custom file, if existent, instead of the original file (admin/sendemaillib_custom.php instead of admin/sendemaillib.php)
- Code: Select all
[VIEWONLINEBLOCK]
<p align="center">
<a href="[VIEWMESSAGEURL]">View this mail in your favourite browser</a>
</p>
[/VIEWONLINEBLOCK]
- I replaced the code to include admin/sendemaillib.php in
- -- index.php
-- admin/send_core.php
-- and admin/processqueue.php
- I split the code in admin/sendemaillib.php into two parts. One part to process the message data and one part to process the mail.
- I moved the code to process the message data into a new lib called admin/preparemessagelib.php.
- I moved the mail processing part into a new file called admin/sendemaillib_custom.php
- admin/sendemaillib_custom.php uses the functions in admin/preparemessagelib.php to process messages.
- I added the code part from xanonite to replace [VIEWMESSAGEURL] by the specific URL to view the message in the browser.
- I added code to handle some code block in the message containing the online URL:
you can add something alike to your messages (or templates):
- -- if the function prepare_message is called from sendEmail: the tags [VIEWONLINEBLOCK] and [/VIEWONLINEBLOCK] will be removed from the message and the tag [VIEWMESSAGEURL] will be replaced by the browser URL.
-- if the function prepare_message is called from view_online: everything between [VIEWONLINEBLOCK] and [/VIEWONLINEBLOCK] will be removed entirely from the message - including the tags.
- I created the file view_online.php from a copy of xanonites "vm.php"
- view_online.php also uses the functions in admin/preparemessagelib.php to create a HTML message on the fly with parameters of the request URL.
What is this good for?
Now, if PHPLIST sends a mail to a user, the message contains a link to the online HTML version of her message (considered the message or the template includes some code like the one above).
If the user clicks on the link in the mail to view the mail via browser, PHPLIST will display her user specific online version of the message.But generated on the fly by using the PHPLIST code which is also used to generate HTML messages for mailings.
Advantages / Disadvantages
- - compared to the solution of xanonite, this solution doesn't store messages in the database and therefore needs no database changes
- on the other way it needs a lot of code rewriting. That's why I provided a patch.
- if you change or delete templates or messages after you used them in mailings, a user who clicks on the "view in browser" link will see the changed version of the template/message in her browser (not the version sent by mail)
The patch
I also did a lot of comments in the code ( only the part I altered

This message is also part of the patch.
download patch here (Tried to upload the file to the forum but this forum tells me allways: "The extension ... is not allowed". Unfortunately it doesn't tell me what extensions are allowed. Tired of trial and error - get the file from my site

(this patch worked for me with PHPLIST version 2.10.12 and 2.10.13)
apply patch:
Attention!! Do not apply this patch to your favourite PHPLIST production application. This is not tested by other users yet. And if you do so and brake something, even I warned you - don't blame me

copy phplist-2.10.12-13_view_online_patch to your phplist directory e.g. /var/www/phplist-2.10.12
change into your phplist directory
run
- Code: Select all
patch -p1 < phplist-2.10.12-13_view_online_patch
(there are no database modifications necessary)
remove patch:
change into your phplist directory e.g. /var/www/phplist-2.10.12
run
- Code: Select all
patch -R -p1 < phplist-2.10.12-13_view_online_patch
(there are no database modifications necessary)
Let me hear, what you think of it. Any suggestions, questions?
cheers
Tom