Page 1 of 1

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

Posted: Wed Sep 03, 2008 3:23 pm
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!

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

Posted: Wed Sep 03, 2008 6:20 pm
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;

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

Posted: Tue Dec 08, 2009 10:11 pm
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.

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

Posted: Thu Dec 17, 2009 1:05 pm
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>