[mod] Live tags hack

3rd party code for phpList

[mod] Live tags hack

Postby shumisha » 5:49pm, Thu 08 Feb, 2007

Hello All,

Here is a small change I have made to suit my purpose. I have not researched the matter so there may be other, more efficient solutions, but here it goes :
I called that live tags : you can already have attributes inserted in your messages. Those are imported in phplist database either by subscription or csv import.
What I needed was some attributes created on the fly, based on other attributes values. In my case I wanted to create a unique password, built as a md5 hash of a combination of user name, email address and more.
So I did the following (PLEASE NOTE this is for v. 2.10.2, but I believe it can work as is for version 2.10.4):

A - Change lists/admin/sendemaillib.php :

1 - insert at line 4, just after the first 'require_once...'
Code: Select all
// shumisha 2007-02-04 : live tags processing
include $GLOBALS["coderoot"] . "plugins/shLiveTags.php";
// end of change


2 - insert around line 330, just before ' if (!$destinationemail) {
$destinationemail = $email;
}' :

Code: Select all
// shumisha 2007-02-04 : live tags added:
  shProcessLiveTags( $userdata, $user_att_values, $htmlmessage, $textmessage);
  // end of change


B - Create the file shLiveTags.php in lists/admin/plugins with the follwoing content :
Code: Select all
<?php
// shumisha 2007-02-06 : live tags in messages : {tagName} replaced by a calculated value

// define  live tags,
$shLiveTagsList = array( 'shPass', // your own live tags
                           'shLiveFullDate', 'shDayOfWeek', 'shMonth', 'shDayOfMonth', 'shYear', 'shTime'); // standard live tags

function shReplaceLiveTags( $userData, $tag, $userAtt) {
  setlocale( LC_ALL, 'fr_FR');
  switch ($tag) {
    // Your own live tags are processed here : add a case/break statement for each of your tags
    case 'shPass':
     $ret = md5( substr( substr($userData['email'], 0, 4)         
             .'mysteryWord'
             .substr($userData['email'], -6)
             );
    break;
    // standard liveTags are processed below
    // today's date
    case 'shLiveFullDate':
      $ret = strftime('%x');
    break;
    case 'shDayOfWeek':
      $ret = strftime('%A');
    break;   
    case 'shMonth':
      $ret = strftime('%B');
    break;
    case 'shDayOfMonth':
      $ret = strftime('%d');
    break;
    case 'shYear':
      $ret = strftime('%Y');
    break;
    case 'shTime':
      $ret= strftime('%X');
    break;   
    default:
      $ret = '';
    break;
  }
  return $ret;
}

function shProcessLiveTags( $userdata, $user_att_values, &$htmlmessage, &$textmessage){
global $shLiveTagsList;

  if (is_array($shLiveTagsList)) {
    foreach ($shLiveTagsList as $shLiveTag) {
      if (eregi("\{".$shLiveTag."\}",$htmlmessage,$regs)) {
         $htmlmessage = eregi_replace("\{".$shLiveTag."\}",shReplaceLiveTags( $userdata, $shLiveTag, $user_att_values),$htmlmessage);
      }
     if (eregi("\{".$shLiveTag."\}",$textmessage,$regs)) {
        $textmessage = eregi_replace("\{".$shLiveTag."\}",shReplaceLiveTags( $userdata, $shLiveTag, $user_att_values),$textmessage);
     }
   }
 }
}

?> 


3 - Usage :

Now you can insert anywhere in your message new tags, surrounded by curly brackets {} instead of square brackets []. As for now, you can use the following tags :

{shPass} : this is my own password, calculated using current user attributes. It can basically anything calculated through php.
{shLiveFullDate}: insert full day of sending, according to setLocale just above in the shReplaceLiveTags function.
{shDayOfWeek} : insert day of week of sending : monday, tuesday,...
{shMonth} : insert current month
{shDayOfMonth} : insert day in month : 20, 21, ...
{shYear} : insert current year (4 digits)
{shTime} : insert current time : hh:mm:ss

This is built for expansion, so yo can easily add your own tags !
shumisha
PL Geek
 
Posts: 82
Joined: 8:06am, Tue 04 Apr, 2006

Postby livingfree » 1:00am, Mon 12 Feb, 2007

hey thanks, I could do with something like this.
livingfree
 

Postby shumisha » 8:07am, Mon 12 Feb, 2007

Well thanks livingfree !
If you add any tags of your own, please post them here so that we can use them as well !!

Regards
shumisha
PL Geek
 
Posts: 82
Joined: 8:06am, Tue 04 Apr, 2006

Postby WinstonN » 1:44pm, Wed 21 Nov, 2007

hi there,
shumisha, first, thank you for this amazing contrib. you have done a very nice work
i have followed your instructions to the letter, however, i my mails just stay in the que now and don't send.

any advice you can give me.

i have version 2.10.4
i would love to use this contrib as it will add a lot of value,
so if you have a moment won't you please look at this post,

thank you once again, you are a star mate!

power day to you!
wins
Winston Nolan
http://www.buyxonline.com
eCommerce and Email Marketing
WinstonN
PL Master
 
Posts: 158
Joined: 3:31pm, Sun 04 Feb, 2007
Location: Cape Town, South Africa

Re: [mod] Live tags hack

Postby drmike » 12:17am, Tue 31 Aug, 2010

A few corrections which I used to get this working:

The statement
$ret = md5( substr( substr($userData['email'], 0, 4)
.'mysteryWord'
.substr($userData['email'], -6)
);
is missing a closing parenthesis. I.e., it should be
$ret = md5( substr( substr($userData['email'], 0, 4)
.'mysteryWord'
.substr($userData['email'], -6)
));

I am not positive the following is absolutely necessary, however, I put the script shLiveTags.php in a sub-directory of admin which I named "hacks" and used
include dirname(__FILE__) . '/hacks/shLiveTags.php';
instead of
include $GLOBALS["coderoot"] . "plugins/shLiveTags.php";

I did this because of what is said about the plugins directory at viewtopic.php?t=10948.

Finally, for phpList 2.10.12 the statement
shProcessLiveTags( $userdata, $user_att_values, $htmlmessage, $textmessage);
needs to go into sendemaillib.php around line 397, not line 330.

I am hoping that this mod/hack will be useful in getting to where we need to be in terms of adding "placeholders" which are at present not available in phpList.
drmike
PL Nut
 
Posts: 19
Joined: 8:40pm, Sat 14 Aug, 2010
Location: Chesterfield, MO, USA

Re: [mod] Live tags hack

Postby drmike » 8:22pm, Mon 18 Oct, 2010

Although I wish to express my appreciation to the author of "Live tags hack," it did not accomplish all that I needed. I have, therefore, created a plugin "Enhanced Placeholders" (http://forums.phplist.com/viewtopic.php?f=7&t=33957),"which does accomplish what I needed. I hope it may also be of use to others.
drmike
PL Nut
 
Posts: 19
Joined: 8:40pm, Sat 14 Aug, 2010
Location: Chesterfield, MO, USA


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

Who is online

Users browsing this forum: No registered users and 0 guests

cron