[mod] NL_Date - Automatically insert date in messages

3rd party code for phpList

[mod] NL_Date - Automatically insert date in messages

Postby H2B2 » 4:06pm, Mon 18 Feb, 2008

The forum thread for this mod was deleted. Fortunately I could recover the contents from google cache. Here it goes:

darkknight Posted: 5:01am, Fri 30 Sep, 2005
phplist newbie
Joined: 29 Sep 2005
Posts: 3


I have been working with phpLists for a few days. Most of my issues have been resolved through searches of the forum. In a few places, questions were asked about 'attributes' and how to use them. I wanted to send out newsletters that were personalized with the users first name and to automate the dating of the newsletter as follows:

XXX Company Newletter for September 30, 2005

Hello George


Getting the Fist Name (George) was quite simple. I just added several attributes including FIRST NAME and SECOND NAME. In the newsletter template, I included the following:

Hello [FIRST NAME]<br />[CONTENT]

phpList obligingly recovers each users first name from the tables and substitutes it for the placeholder [FIRST NAME].

Getting it to do the automatic dating was marginally more difficult. Here there is no attribute for the date. So I created one [NL_DATE]. This placeholder also appears in the template as follows:

XXX Company Newletter for [NL_DATE]

Then I opened admin/sendmaillib.php. At line 181 is the following code:

Code: Select all
if ($cached[$messageid]["template"])
# template used
$htmlmessage = eregi_replace("\[CONTENT\]",$htmlcontent,$cached[$messageid]["template"]);
else {
# no template used
$htmlmessage = $htmlcontent;
$adddefaultstyle = 1;
}


I modified this code as follows:
Code: Select all
if ($cached[$messageid]["template"]){
# template used
$htmlmessage = eregi_replace("\[CONTENT\]",$htmlcontent,$cached[$messageid]["template"]);
// gkd [NL_DATE] Mod
$nl_date = date("l F dS, Y");
$htmlmessage = eregi_replace("\[NL_DATE\]",$nl_date,$htmlmessage);
// end mod
}else {
# no template used
$htmlmessage = $htmlcontent;
$adddefaultstyle = 1;
}

(note the addition of curly brackets at the beginning of the 'if' clause)

And with that simple modification, the date of mailing the newsletter replaces the [NL_DATE] placeholder.

While these are minor examples of the use of attributes/placeholders, I offer them so that they may sheld a little light on how the system works for those needing more elaborate placeholder replacements.

_________________
2 + 2 = 5 for really large values of 2


weblite Posted: 10:25pm, Wed 05 Oct, 2005
phplist newbie
Joined: 05 Oct 2005
Posts: 3

Since you are experienced - where do I find the [CONTENT] text so I can change it?

AS well how do I make more [CONTENT 1] [CONTENT 2] placeholders so I can set up a template for a friend and then they just login and fill in the new images and text?

Thanks
weblite


jotazzu Posted: 12:00am, Thu 06 Oct, 2005
PL Master
Joined: 13 Jul 2005
Posts: 183
Location: Hamburg, Germany

Hi darkknight,
nice patch, I've added it to my installation immediately. I have shifted this patch 6 lines below after line 189

Code: Select all
  $textmessage = $textcontent;

and added three lines
Code: Select all
  $nl_date = date("l F dS, Y");
  $htmlmessage = eregi_replace("\[NL_DATE\]",$nl_date,$htmlmessage);
  $textmessage = eregi_replace("\[NL_DATE\]",$nl_date,$textmessage);

Now it is available for templates as well as for HTML messages and text messages. (Changed in file admin/sendemaillib.php.)


darkknight Posted: 4:59pm, Thu 06 Oct, 2005
phplist newbie
Joined: 29 Sep 2005
Posts: 3

Hi Weblite

I must be missing something as I do not fully grasp what you want to do.

The template you create defines the appearance of the html email and contains all the elements that you want to appear in each email - logo, frequently used links, etc. The actual content for each individual email is created in the Admin section under 'send a message'. In both places you can create just about anything you want.

As for your second question, if you want your friends to send out their own emails, give them access by making them a 'user' and assign appropriate 'user attributes'. Create a template for each of these users for their own emails and let them added to content as above using thier own template.

However, if you want them all to contribute to a single email using [CONTENT1], [CONTENT2], ..., you have a problem. phpLists is not designed for multiple users sending single emails in this fashion. It is possible but would take a major restructuring of the code. There is an old phrase - 'sometimes you eat the bear and sometimes the bear eats you'. In this case, the bear would be dining.

_________________
2 + 2 = 5 for really large values of 2


carterco Posted: 12:47am, Thu 13 Oct, 2005
PL Geek
Joined: 12 Oct 2005
Posts: 76
Location: Pasadena, California, USA

I'm guessing here, but I think what weblite is asking is for multiple content buckets that can be plugged into different areas of a single email template.

I happen to have a similar need, though I've just started trying to solve it:

I have within my template some layout areas for three different items:

a main chunk of content

a side bar, pull-quote or image

a footer area with a reminder ablut upcoming stuff

Given how fragile the table layout is -- to be compatible with as many mail clients as possible it is table driven -- I'd like to be able to create a message and enter my Content1, Content2, and Content3 values, then have the template smart enough to shove this into the appropriate places scattered around the page.

to do it on an email by email case is possible but:

1. it's likely I'll eventually break it;
2. for the text subscribers ... not sure what i'd do since there'd be so much tble bark up

Seems like an invasive mod to the phplist codej, perhaps a wish list item.


carterco Posted: 5:05pm, Fri 14 Oct, 2005
PL Geek
Joined: 12 Oct 2005
Posts: 76
Location: Pasadena, California, USA

Due to the interest in this “Hack” (and some much appreciated encouragement from Karl Hedner) I’ve re-written my original solution for the multi-content challenge as a plug-in called PBTS_XTRA.

The files have been moved to the following post under "Contributions and Mods". Get the latest version of this plugin from there (and leave your ideas/comments as well): http://www.phplist.com/forums/viewtopic.php?t=4059

Overview
This plugin extends phpList's Template functionality by allowing you to define multiple Content Regions within your Templates.

You are also able to include or exclude sections of your Template based on whether one of these Content Regions is empty or not.

Finally, the plug-in automatically creates an editor for your Content Regions based on settings you provide.

Sample
As a teaser, here is what you would put into your Template:
Code: Select all
[PBTS_XTRA name="MyNewColumn"]

That is all of that’s required. If you do choose to include some of the extra parameters you’ll be rewarded with a better Editor. These parameters are basically what you use for HTML form elements;
Code: Select all
[PBTS_XTRA name="MyNewColumn" displayname="Joke of the Day" type="textarea" rows="6" cols="45"]

Oh, you still retain the option of using “normal” templates:
I've modified sendmaillib.php where it generates the text and HTML versions of the email (where it does the CONTENT substitution into your template). If the template contains at least one PBTS custom tags it parses the message's CONTENT and stuffs it into the appropriate places within the template otherwise it uses phpList’s normal replacement.


Splen Posted: 4:19pm, Thu 01 Dec, 2005
phplist newbie
Joined: 01 Dec 2005
Posts: 2

I have added the PBST plugin and I am also trying to add the date:

Is this correct?:
Code: Select all
  if ($cached[$messageid]["template"]){
    # template used
    if (!preg_match("/\[PBTS_/is", $cached[$messageid]["template"]))
      $htmlmessage = eregi_replace("\[CONTENT\]", $htmlcontent, $cached[$messageid]["template"]);
      $nl_date = date("l F dS, Y");
      $htmlmessage = eregi_replace("\[NL_DATE\]",$nl_date,$htmlmessage);
    else
      $htmlmessage = pbts_replace_content( $htmlcontent, $cached[$messageid]["template"] );
      $nl_date = date("l F dS, Y");
      $htmlmessage = eregi_replace("\[NL_DATE\]",$nl_date,$htmlmessage);
  } else {
    # no template used
    $htmlmessage = $htmlcontent;
    $adddefaultstyle = 1;
  }
  $textmessage = $textcontent;
  $nl_date = date("l F dS, Y");
  $htmlmessage = eregi_replace("\[NL_DATE\]",$nl_date,$htmlmessage);
  $textmessage = eregi_replace("\[NL_DATE\]",$nl_date,$textmessage);


OR Should it be:
Code: Select all
  if ($cached[$messageid]["template"]){
    # template used
    if (!preg_match("/\[PBTS_/is", $cached[$messageid]["template"]))
      $htmlmessage = eregi_replace("\[CONTENT\]", $htmlcontent, $cached[$messageid]["template"]);
    else
      $htmlmessage = pbts_replace_content( $htmlcontent, $cached[$messageid]["template"] );
  } else {
    # no template used
    $htmlmessage = $htmlcontent;
    $adddefaultstyle = 1;
  }
  $textmessage = $textcontent;
  $nl_date = date("l F dS, Y");
  $htmlmessage = eregi_replace("\[NL_DATE\]",$nl_date,$htmlmessage);
  $textmessage = eregi_replace("\[NL_DATE\]",$nl_date,$textmessage);


Or does it matter?


carterco Posted: 5:05pm, Thu 01 Dec, 2005
PL Geek
Joined: 12 Oct 2005
Posts: 76
Location: Pasadena, California, USA

It looks as though you always want to perform this replacement, no? that is, whether it's pbts-enabled or not, right?

Code: Select all
$htmlmessage = eregi_replace("\[NL_DATE\]",$nl_date,$htmlmessage);


(and, unless I'm really sloppy in my read, the first code snippet is inefficient: you always perform the substitution regardless)

so, use the second one.

This date thing -- that's a great idea, by the way... think this just might need to find it's way into pbts_xtra at some point, as something like:
Code: Select all
[pbts_date format="l F dS, Y"]


Perhaps even some mechanism such as value="now" that would allow you to choose ... hmmm, scheduled send time should be now... well, there might be others, i dunno, but the date would be easy, especially since you've already written the code for us ;-p


jayq Posted: 12:11pm, Fri 09 Dec, 2005
phplister
Joined: 04 Dec 2005
Posts: 11
Location: UK

Hi darkknight,

I've set-up two attributes First Name and Last Name and then set-up the configure page messages to include the placeholder [FIRST NAME] in a few select spots. (i.e. confirm subscription page) but when the automated email goes out, the email contains the placeholder rather than the name submitted. The details entered (first name, last name, email address) are all in the list ok.

I'm not familiar with the coding of PHPlist and where to check this but any help on sorting this placeholder problem out would be appreciated.

On a related note, the placeholder [WEBSITE] is also showing up instead of the URL entered in the config page (http://www.digitalfilerecovery.com) but the [DOMAIN] URL merges fine (digitalfilerecovery.com).

Any ideas from anyone very much appreciated.

Thanks,
-Jason


T0PS3O Posted: 6:07pm, Fri 09 Dec, 2005
PL Geek
Joined: 07 Nov 2005
Posts: 53


Perhaps this problem (I don't have it) is due to FCKeditor changing all special characters, including [ and ], to the HTML equivalent. Then by the time the PHP script looks for an [ it's already converted to &whatever; so it won't match.

Try it with FCK off (config.php) and see how you go.

_________________
a.k.a. TOPS


jayq Posted: 11:01am, Mon 12 Dec, 2005
phplister
Joined: 04 Dec 2005
Posts: 11
Location: UK

Found out how to solve both my issues:

1) Emails not showing the correct From & server values. This was due to me setting the system messages to noreply@ without creating the email address. My host won't allow this so as to minimise spammers. (Not a bad policy.) Fixed by simply ensuring all email addresses set-up in PHPlist were actual email addresses in my domain.
2) Placeholders [WEBSITE] and [First Name] not working. This actually does work with bulk emails (i.e. newsletters) sent out. Most, but not all, placeholders just don't seem work with the subscription messages - i.e. Confirm your Subscription, Thank you for your Subscription, etc.

Hope this helps any other newbie.

-Jason


demonangel Posted: 7:41pm, Thu 17 Aug, 2006
phplist newbie
Joined: 17 Aug 2006
Posts: 2

First off,
I love the Mods you guys have been so great in devleoping & Supporting.

I'm running phpList 2.10.2 and have the Personalized Attributes and the NL_Date add-ons running (they're like standard equipment now).

I've been tinckering to no avail about getting the [NL_DATE] atrribute to work in the Subject. It works just fine in the message body, but I would like to have the capabilities of getting it to work in the subject...

Any Ideas?

H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

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

Who is online

Users browsing this forum: No registered users and 3 guests