Support Token module

pixelcort - October 13, 2007 - 00:27
Project:Simplenews
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

It would be nice to include in a newsletter something like:

Hello, {profile_firstname}!

This would then pull from the proflie of each user their firstname and put it in for each personalized newsletter sent out.

#1

Sutharsan - January 2, 2009 - 08:42
Title:Support Profile Mail Merge Tokens» Support Token module
Version:5.x-1.1» 6.x-1.x-dev

This could be achieved with an integration of Token module with simplenews. Patches are welcome.

#2

Sutharsan - January 26, 2009 - 20:07

Duplicate request: #364408: Token integration

#3

Sutharsan - January 26, 2009 - 20:14

I had this half finished simplenews.token.inc module in my sandbox. Perhaps someone wants to take if further. Using the recently added function simplenews_mail_tokens() it should not be too hard.

AttachmentSize
simplenews.token_.inc_.zip 1001 bytes

#4

TBarregren - January 31, 2009 - 12:33

I would also suggest that the Token module is used instead of the SImlenews specific tokens %site, %uri, %uri_brief, %mymail, %date, %login_uri.

#5

Sutharsan - January 31, 2009 - 14:45

I couldn't agree with you more.

#6

Sutharsan - March 13, 2009 - 23:06

Duplicated by: #400936: Utilize Tokens

#7

Sutharsan - March 16, 2009 - 14:04
Version:6.x-1.x-dev» HEAD

Changing version to HEAD. That's were the action is ;)

#8

Sutharsan - March 16, 2009 - 14:28
Status:active» needs work

Duplicated by #87071: Personalizing newsletters. Contains D5 patches.

#9

jpfle - March 16, 2009 - 15:08

subscribing

#10

kenorb - March 25, 2009 - 11:15

If somebody want quick custom variables, you can add your own function in:

<?php
function simplenews_mail_tokens($subscription, $context, $language) {
...
  if (
function_exists('my_module_get_mail_tokens') ) {
   
$vars = array_merge($vars,my_module_get_mail_tokens());
  }
      
  return
$vars;
}
?>

Then you can use your own function:

<?php
function my_module_get_mail_tokens() {
  global
$user;   
   
 
$tokens = array(
   
'!user_name' => $user->name,
   
'!something' => 'bla bla bla',
  );
   
  return
$tokens;
?>

#11

haus - March 27, 2009 - 09:53

I am very interested in your solution for personalization of newsletters.
Could you tell where to put your functions and how to use them with simplenews, please.
Thanks

#12

Pboenisch - March 31, 2009 - 13:54
Assigned to:Anonymous» Pboenisch

Im new on Drupal.org but i am interested in changing the simplenews_mail_tokens into tokens from the token module like Sutharsan wrote in his third post.
In the next days i write how the development is going on.

#14

Eikaa - April 20, 2009 - 14:35

Applying this patch allows you to use !recipient_name in your mail or template.

If the mail is sent out to an anonymous subscriber the email is inserted instead.

AttachmentSize
simplenews.module.personalization.patch 2.27 KB

#15

Sutharsan - April 20, 2009 - 19:52

@Pboenisch: any progress on your development?

@Eikaa: this is perhaps a nice intermediate solution, but implementing Token module is not about adding an individual place holder. Token gives much, much more options that just recipent name.

#16

Pboenisch - April 21, 2009 - 10:23

@Sutharsan: It is in work. I am still making the last tests with the tokens. At the moment it looks well and i think i can upload it in a few days

#17

kenorb - April 21, 2009 - 11:41

You can use mail_alter hook for define some custom tokens:

Example:

<?php
/**
* Implementation of hook_mail_alter
*/
function mymodule_mail_alter(&$data)  {
    if (isset(
$data['params']))    {
       
$var = array ('!my_custom_variable' => 'my variable data');
       
$data['body']['body'] = strtr($data['body']['body'], $var);
    }
}
?>

#18

IWasBornToWin - June 29, 2009 - 04:20

@Pboenisch I would love to test your new token code when you're finished.

#19

kenorb - June 29, 2009 - 12:30

Simpler solution:

<?php
/**
* Implementation of hook_mail_alter().
*
*/
function hook_mail_alter(&$message) {
 
/* detect mail body format */
 
if (is_array($message['body'])) {
     
$body = &$message['body']['body'];
  } else {
     
$body = &$message['body'];
  }
 
$body = token_replace_multiple($body); /* replace all available tokens */
}
?>

Define this hook to replace all tokens available in body mail.
Eventually you can add some condition if Token module is enabled.

#20

jackinloadup - July 13, 2009 - 21:10

subscribing

#21

Pboenisch - August 17, 2009 - 13:12

Hi there

i'm sorry that you must wait so long for this patch. I didn't had the time for this because i wrote my bachelor thesis.

Here is my patch for the simplenews 6.x-1.0-rc6. I removed the simplenews_mail_tokens function and added the well-known token_list and token_values functions.

Please test it and give me feedback.

AttachmentSize
simplenews_token.patch 19.2 KB

#22

johngriffin - August 22, 2009 - 23:51

I would love to test this out but it fails against current HEAD, can you re-roll please?

In the meantime I'll apply it to an earlier revision and check it out.

Thanks,
John

#23

johngriffin - August 23, 2009 - 02:11

Patched the failed hunks manually and it all seems to be working. I'm also adding my own tokens to insert a content listing view based upon the user's profile preferences. Fantastic, thanks for this!

#24

Sutharsan - August 23, 2009 - 11:01
Status:needs work» needs review

This is a patch for current HEAD for those who also want to test and report their results.

AttachmentSize
simplenews.183120.patch 11.69 KB

#25

Sutharsan - September 9, 2009 - 13:16

I had a better look at Phoebisch's patch. It failed and I had to completely overhaul the code. A new patch (for HEAD) for review is attached.

AttachmentSize
simplenews.183120_1.patch 19.29 KB

#26

kwinters - September 10, 2009 - 21:15

+dependencies[] = token

This is probably not needed... It should be fine to make it an "optional dependency" just like with mailmime.

I can't tell if it would work with this patch or not, but I'm definitely going to need access to $user->profile_company, etc. (ability to pull in user profile fields and map them to a token usable in the send, even if it requires a hook in a custom module).

Nothing else jumps out at me, I'll have to see how it works in practice.

#27

Sutharsan - September 10, 2009 - 22:37
Assigned to:Pboenisch» Anonymous

Tokens are also used for the confirmation emails. This makes token a requirement. To use this part without tokens would mean that simplenews requires two systems of token replacement. Token is used in 50% of the drupal 6 installations and is the third most used module. I don't see a real problem in making simplenews dependent on token.

#28

miro_dietiker - September 14, 2009 - 03:23

I've checked the patch and found two issues:
1. All tokens where displayed in admin for mail replacement. Added token_help specifier. I home this is correct behaviour.
2. Footer .tpl.php tokenized update was missing.
3. Removed unused obsolete email_token_help in .admin

Everything else unchanged.

In general i think it works pretty well, although i've found a bunch of small errors to fix outside of the scope of this issue.

AttachmentSize
simplenews.x.patch 21.78 KB

#29

Sutharsan - September 14, 2009 - 10:39

Thanks for your review. I leave the issue open for a little longer to get another review but for me the last patch is already RTBC worthy.

#30

miro_dietiker - September 18, 2009 - 16:57
Status:needs review» reviewed & tested by the community

Setting to RTBC. Checked another couple of minutes and reproducing code and especially checking static caching not to cache things that shouldn't be cached...

Seems perfectly right. Cool patch, Sutharsan!

Next step in evolution is:
#581500: Conditional personalisation and dynamic (uncacheable) filters

#31

miro_dietiker - September 22, 2009 - 08:51

We need a note for users who upgrade to make clear they need to rewrite their mailings.
If not they will result having broken obsolete replacement patterns inside mails.

#32

Sutharsan - September 30, 2009 - 14:08
Status:reviewed & tested by the community» fixed

I've added a replace function for the confirmation messages and a user message.

Attached patch is committed to HEAD. Thanks to all for encouragement, code and test.

AttachmentSize
simplenews.183120_2.patch 23.63 KB

#33

miro_dietiker - October 1, 2009 - 20:41

Very nice! Thanks a lot.

#34

System Message - October 15, 2009 - 20:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#35

gantenx - October 26, 2009 - 09:05

Hi, I have created simplenews_token module to integrate simplenews and token module. I developed it for drupal 6. What do you think?

AttachmentSize
simplenews_token-6.x-1.x-dev.tar_.gz 1.33 KB

#36

Sutharsan - October 26, 2009 - 12:52

I'd rather combine efforts for this function. Please check-out simplenews HEAD, review and supply patches for it.

#37

chinaKat - October 26, 2009 - 23:12

Hi -- thanks for the module. Call me a newbie loser but I haven't quite nailed patch installation, so I was struggling with this. Having a module was great, I could use it right away. But, I don't know if it does what I need.

Problem: I used the global tokens listed at /admin/store/help/tokens in my newsletter, and they mostly worked great. However, the [user-name] token gives the name of the currently logged in user, which is no help to me in a newsletter because all the newsletters wind up being addressed to "admin" or "bob" or whoever creates the newsletter.

Is there a token available to get the user name of the user receiving the email?

Thanks!

ETA --

aha, I see that there is a drop down menu in the newsletter edit screen titled "replacement patterns" with the user tokens. [user] works perfectly.

Thank you for making this available, I appreciate it!

 
 

Drupal is a registered trademark of Dries Buytaert.