[Solved] NMS - strip all html except between the body tags

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
sn3p
Forum Members
Forum Members
Posts: 169
Joined: Mon Oct 15, 2007 2:27 pm

[Solved] NMS - strip all html except between the body tags

Post by sn3p »

When I click a message in the archive list of the NMS (Newsletter Made Simple) module it displays the whole message.
This message is a HTML formatted e-mail including doctype, html, head and body tags. All these tags are included withing the code of my page aswell, which is obviously not what I want.

What I'm looking for is a wat to replace/remove these tags, so only the code between the body tags remain.
Can anyone tell me how to do this?


The message is included with this line:

Code: Select all

{nms_getmessage msg=$messageinfo->messageid}
A way to modify this could be making an UDT (nms_strip) which assigns the stipped message as a smarty variable ($stipped_msg):

Code: Select all

{nms_strip msg=$messageinfo->messageid}
{nms_getmessage msg=$stipped_msg}
But I don't have a clue how to code this UDT..

Thanks in advance!
Last edited by sn3p on Wed Sep 03, 2008 6:21 pm, edited 1 time in total.
sn3p
Forum Members
Forum Members
Posts: 169
Joined: Mon Oct 15, 2007 2:27 pm

Re: NMS - srtip all html except between the body tags

Post by sn3p »

Got it working.
In my template I capture the message and push it in an UDT like this:

Code: Select all

{capture name=msg}{nms_getmessage msg=$messageinfo->messageid}{/capture}
{nms_strip msg=$smarty.capture.msg}
In the UDT (nms_strip) the html I don't want will be removed:

Code: Select all

if (isset($params['msg'])) {
  $msg = $params['msg'];
} else {
  return;
}

$stripped = ereg_replace("<!DOCTYPE(.*)</__body>","",$msg);
$stripped = ereg_replace("<__body>(.*)</__html>","",$stripped);

echo $stripped;
bryan

Re: [Solved] NMS - strip all html except between the body tags

Post by bryan »

sn3p,
I know you found a solution a while back, but as an alternative you could use strip and regex_replace on the $thismessage variable to remove unwanted tags directly in the archive template:

Code: Select all

{$thismessage|strip|regex_replace:"[(<__html>)|(</__body\b[^>]*>)|(<style\b[^>]*>(.*?)</style>)|(<__body>)|(</__html>)]":""}
This way you don't need to create a UDT.
User avatar
tinhat
Forum Members
Forum Members
Posts: 65
Joined: Fri May 23, 2008 6:33 am

Re: [Solved] NMS - strip all html except between the body tags

Post by tinhat »

You could edit your Archive Summary template to something like:

Code: Select all

<ul>
{section name=mysec loop=$archived_messages}
   {* modified mark 081207 - make newsletter link open in new window *}
   <li><a href="{$archived_messages[mysec].href}&showtemplate=false" onClick="window.open('{$archived_messages[mysec].href}&showtemplate=false', 'eml_newsletter', 'width=800, height=800, resizable=yes, scrollbars=yes, toolbar=no, location=no, menubar=yes, copyhistory=yes, status=no'); return false;">{$archived_messages[mysec].subject}</a></li>
{/section}
</ul>
Post Reply

Return to “Modules/Add-Ons”