Hi Guys,
I have come up with a solution to the problem of Placeholders not being processed in System Emails (eg subscribe etc - See Issue 3288). I'm just new to phplist, but was disappointed that the first email a user receives after registering weren't able to be personalised...

A bit of a letdown, as personalisation was the reason I went with phplist
This is what I did. First, I created two functions in the file admin/commonlib/lib/userlib.php. The first processes Custom Placeholders (user-defined), the second some System-defined Placeholders:
Before the ending ?>, add:
function RJC_ReplaceCustomPlaceholders($systemmessage = '',$userid = 0) {
/* Function to replace Custom Placeholders with the proper values from the database (See Issue 3288) */
/* PS: Made so that placeholders are replaced in System Messages (eg Subscribe/Unsubscribe emails) */
/* Function works successfully. I guess it needs some sort of check to make sure parameters are supplied???
(to avoid a crash if $systemmessage or $userid are not supplied)
Someone should check for insecurities/inefficiencies as I don't know php well */
$rjc_user_att = getUserAttributeValues('',$userid);
while (list($att_name,$att_value) = each ($rjc_user_att)) {
if (eregi("\[".$att_name."\]",$systemmessage))
$systemmessage = eregi_replace("\[".$att_name."\]",$att_value,$systemmessage);
}
return $systemmessage;
}
function RJC_ReplaceBuiltinPlaceholders($systemmessage = '',$userid = 0) {
/* Function to replace Builtin Placeholders with the proper values from the database
PS: Made so that placeholders are replaced in System Messages (eg Subscribe/Unsubscribe emails)
(See Issue 3288):
*/
$systemmessage = ereg_replace('\[DOMAIN\]', getConfig("domain"), $systemmessage);
$systemmessage = ereg_replace('\[WEBSITE\]', getConfig("website"), $systemmessage);
return $systemmessage;
}
(As an aside, I have shortened the second procedure above to only those ones which successfully work. I show the full one below with all my comments and the placeholders which don't work. Someone eslse may have more success).
Then I modifed the following:
In index.php:
After:
$confirmationmessage = ereg_replace('\[LISTS\]', $lists, getUserConfig("confirmationmessage:$spage",$userdata["id"]));
Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user Confirms their Subscription
$confirmationmessage = RJC_ReplaceCustomPlaceholders($confirmationmessage,$userdata["id"]);
$confirmationmessage = RJC_ReplaceBuiltinPlaceholders($confirmationmessage,$userdata["id"]);
// END RJC ADDED
After:
$unsubscribemessage = ereg_replace("\[LISTS\]", $lists,getUserConfig("unsubscribemessage",$userid));
Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user Unsubscribes
$unsubscribemessage = RJC_ReplaceCustomPlaceholders($unsubscribemessage,$userid);
$unsubscribemessage = RJC_ReplaceBuiltinPlaceholders($unsubscribemessage,$userid);
// END RJC ADDED
In admin/subscribelib2.php:
After:
$subscribemessage = ereg_replace('\[LISTS\]', $lists, getUserConfig("subscribemessage:$id",$userid));
Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user Subscribes
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED
Before:
print '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';
Add:
// RJC MODIFIED - Includes User Placeholders in System Emails when a user updates personal data
$message = RJC_ReplaceCustomPlaceholders($message,$userid);
$message = RJC_ReplaceBuiltinPlaceholders($message,$userid);
// END RJC MODIFIED
In admin/import1.php:
After:
$subscribemessage = ereg_replace('\[LISTS\]', $listoflists, getUserConfig("subscribemessage",$userid));
Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user is added through Import
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED
In admin/import3.php:
After:
$subscribemessage = ereg_replace('\[LISTS\]', $listoflists, getUserConfig("subscribemessage",$userid));
Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user is added through Import
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED
In admin/reconcileusers.php:
Before:
logEvent($GLOBALS['I18N']->get('Resending confirmation request to')." ".$userdata["email"]);
Add:
// RJC ADDED - Includes User Placeholders in System Emails when Reconcile users performed
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED
In admin/commonlib/pages/importcsv.php:
After:
$subscribemessage = ereg_replace('\[LISTS\]', $listoflists, getUserConfig("subscribemessage",$userid));
Add:
// RJC ADDED - Includes User Placeholders in System Emails when users are imported from csv
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED
It seems to process Custom (userdefined) placeholders fine; since I don't know php or sql very well, I wasn't able to get any more of the Globals working (see Full Function below). Maybe someone with a bit more skill can do so...
As I mentioned, I don't know php, so someone really needs to go through it and check the code for insecurities/inefficiencies etc. For now my Custom Placeholders are showing up in (un)subscribe emails, along with system placeholders [DOMAIN] and [WEBSITE], so that's a start until someone else can get the rest of the System placeholders working (or at least those that are meant to according to documentation
http://docs.phplist.com/Placeholders.
I guess the concept could also be extended to not just the message body, but the subject line of (un)subscribe emails too... Another day.
As mentioned above, I list the full Builtin Placeholders function below. I only have a few builtins working (limited by lack of php & sql knowledge).
--- FULL FUNCTION ---
function RJC_ReplaceBuiltinPlaceholders($systemmessage = '',$userid = 0) {
/* Function to replace Builtin Placeholders with the proper values from the database
PS: Made so that placeholders are replaced in System Messages (eg Subscribe/Unsubscribe emails)
(See Issue 3288):
NOTE: Does it cause a clash with specs as listed
http://docs.phplist.com/Placeholders (eg Allowed In)???
Maybe some of these should be removed from this function to avoid any problems??? */
/* The commented lines don't work successfully; someone who's more adept at select tables
should be able to help us out here...
I assume it needs to select tables from database for various user info; don't know php and sql enough
to do it confidently. */
/* I guess the function needs some sort of check to make sure parameters are supplied???
(to avoid a crash if $systemmessage or $userid are not supplied)
Someone should check for insecurities/inefficiencies as I don't know php well */
$systemmessage = ereg_replace('\[DOMAIN\]', getConfig("domain"), $systemmessage);
$systemmessage = ereg_replace('\[WEBSITE\]', getConfig("website"), $systemmessage);
/* The following work, but don't put a UID on the end of the url. The documentation
http://docs.phplist.com/Placeholders
seems to imply that a UID should be on the end... Job for someone

*/
$systemmessage = ereg_replace('\[SUBSCRIBEURL\]', getConfig("subscribeurl"), $systemmessage);
$systemmessage = ereg_replace('\[CONFIRMATIONURL\]', getConfig("confirmationurl"), $systemmessage);
$systemmessage = ereg_replace('\[PREFERENCESURL\]', getConfig("preferencesurl"), $systemmessage);
$systemmessage = ereg_replace('\[UNSUBSCRIBEURL\]', getConfig("unsubscribeurl"), $systemmessage);
$systemmessage = ereg_replace('\[FORWARDURL\]', getConfig("forwardurl"), $systemmessage);
/* These following are meant to have url with uid, in the form of "this link" (ie <a>this link</a> */
// $systemmessage = ereg_replace('\[SUBSCRIBE\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[PREFERENCES\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[UNSUBSCRIBE\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[FORWARD\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[EMAIL\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[FORWARDFORM\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[LISTOWNER\]', /*something goes here*/, $systemmessage);
/* Signature result is blank, needs fixing (I think this is trying to give an html result)*/
// $systemmessage = ereg_replace('\[SIGNATURE\]', preg_replace('/src=".*power-phplist.png"/','src="powerphplist.png"',$PoweredByImage), $systemmessage);
// $systemmessage = ereg_replace('\[USERID\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[USERTRACK\]', /*something goes here*/, $systemmessage);
/* I guess for completeness I should put the lot, even [LISTS] is already processed (eg in index.php).
In theory, if they've already been processed in index.php, then the placeholders won't exist when this function is run, so
no harm done. This needs to be verified */
// $systemmessage = ereg_replace('\[USERDATA\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[LISTS\]', /*something goes here*/, $systemmessage);
return $systemmessage;
}