The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.
Font size: +
4 minutes reading time (795 words)

Tweaking the JMailAlerts Latest News plug-in to send out JEvents Latest Events

Sometime around mid July, i got an email from one of our J!MailAlerts users - Scout Master Mike Lyman. He was looking for a Jevents plugin for J!MailAlerts & during our conversations, he came up with a really innovative way of sending JEvents Events via J!MailAlerts. I suggested he do a guest blog post for us about it, and he kindly complied. Thanks a lot Mike !

This method is a classic workaround using which you could practically display content from any Module in a J!MailAlerts Digest.. Over to Mike for the blog !


P.S. If you have built any custom J!MailAlerts plugins or done any awesome tweaks to it, do share them with us & we'll be happy to do Guest Blog posts about  them !

Tweaking the JMailAlerts Latest News plug-in to send out JEvents Latest Events

While upgrading a Boy Scout troop website from Joomla 1.5.26 to 3.1.1, I had to replace a newsletter component that had never been upgraded to the newer versions of Joomla. It had to send out the stories we wanted sent out weekly and send out the events from our JEvents calendar for the next several months which our old newsletter component did via the JEvents Latest Events module.

TechJoomla’s JMailAlerts was almost the perfect replacement. It was only almost because it had no plug-in for JEvents or a way to pull content from a module like our previous newsletter component did. With a few tweaks to the JMailAlerts Latest News plug-in and leveraging some Joomla features it would become more than the perfect replacement and reduce the weekly touch labor to nothing more than managing stories.


The first tweak I needed was newsletter formatting that the built in features didn’t do and that was pretty straight forward tweaks to the files in the Latest News plug-in. Next I needed to get the calendar to go out.

Joomla includes a Content - Load Modules plug-in that uses a "loadposition MyPosition" ( in curly braces) tag to load the content of whatever modules are in the position into a story. (Subject to the normal module permissions and menu assignment conditions.) I used that to create a story where the contents of the JEvents Latest Events module were loaded into the story. While that works well on the website, the stock JMailAlerts Latest News plug-in only includes the "loadposition MyPosition" tag itself in the newsletter, not the content of the modules in that position. The solution to that was not difficult.

In the Latest News plug-in, the jma_latestnews_js.php file uses the line:

$lists[$i]->intro = substr( strip_tags($row->intro) , 0, $introtext_count )." ...";

to load the story intro content from the database query into the array of data used in the newsletter/alert. (It does so in two different places and comments in the code explain why.) I had already tweaked that to give me the message format I wanted so I took it a step further to also trigger the Content – Load Modules plug-in. The new lines are:

$lists[$i]->intro = $row->intro;
$lists[$i]->intro = JHtml::_('content.prepare', $lists[$i]->intro);

This stopped limiting the intro text that went out in the newsletter and somewhat maintained the article formatting by no longer stripping out html tags. (I’m a security guy and know those risks and found them acceptable for this site’s newsletter.) The second line ran it through Joomla’s content preparing routines that triggered the Content - Load Module plug-in and put the upcoming events calendar into the story and now into weekly the newsletter.
This was almost the solution. The links in the content are relative links and have a few more issues and some quick string replacements got me what I wanted. Full change was to replace:

            $lists[$i]->intro = substr( strip_tags($row->intro) , 0, $introtext_count )." ...";


    $lists[$i]->intro = $row->intro; // substr( strip_tags($row->intro) , 0, $introtext_count )." ...";
    $lists[$i]->intro = JHtml::_('content.prepare', $lists[$i]->intro);
    // JEvents specific fixes
    $lists[$i]->intro = str_replace("a href=\"/calendar","a href=\"".JURI::base()."calendar", $lists[$i]->intro);
    $lists[$i]->intro = str_replace("?tmpl=component","", $lists[$i]->intro);
    // make images work in stories
    $lists[$i]->intro = str_replace("src=\"images","src=\"".JURI::base()."/images", $lists[$i]->intro);
    // fix other relative urls
    $lists[$i]->intro = str_replace("a href=\"index.php","a href=\"".JURI::base()."index.php", $lists[$i]->intro);

in the two places necessary.
With those minor tweaks to the JMailAlerts Latest News plug-in, JMailAlerts has become a better newsletter component for us than the one it replaced. The stories and upcoming events from our JEvents calendar can go out automatically and all we have to do is maintain the stories in the proper categories. The story containing the calendar does not have to be touched.

Using the same technique, I should be able to send out the content from any component that uses modules with only some potential additional string replacement tweaks.

Guest Blog By Mike Lyman


Mike Lyman is a Software Assurance Engineer, CISSP, CSSLP

Huntsville, Alabama AreaComputer & Network Security

Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Invitex 2.7.3 is available
How to Copy Zoo Items programmatically