I have attached a patch to allow themes to override the contents of the notification emails.

Comments

dziemecki’s picture

Could you attach your full module? I'm afraid this module is a moving target, so the lifespan of a patch is somewhat short. It's actually easier for me to run this through a diff editor and merge as required.

Thanks,

dz

mindless’s picture

StatusFileSize
new21.64 KB

I've attached our full file.. it contains the patch discussed here plus a couple other changes.

One marked with:
/* Don't show subscribe-post link on the front page */

The other with subscriptions_settings2 and mailqueue_insert code.

mindless’s picture

Version: 4.5.x-1.x-dev » 4.7.x-1.x-dev
StatusFileSize
new37.74 KB

I've attached my current subscriptions.module code for drupal 4.7.x which includes themable email content and a callout to mailqueue module if available.

mindless’s picture

StatusFileSize
new1.97 KB

And here is the mailqueue.module we use with it..

somebodysysop’s picture

I was just about to post the question "Is it possible to show the content title in Subscriptions Module e-mail notifications", when I came across this thread. This is great!

I assume with this patch it now is possible, but one question: How do I use it? The e-mail is now themable, but what does that mean? Is there documentation available, a sort of step by step how-to?

Thanks so much!

-ron

mindless’s picture

There are now theme_subscriptions_emaildata and theme_subscriptions_email functions. This means in your theme you can define themename_subscriptions_emaildata and _email functions to override the default behavior. Here's what the two functions are for: _emaildata retrieves whatever data will be needed to generate the email contents.. it is called once. _email is called once for each user that receives an email for this change.. it is given the userinfo/recipient and the data generated from the _emaildata call. Take a look at these two functions in subscriptions.module and you'll see how they work. Copy them into your theme, rename them to themename_subscriptions_* and modify to suit your needs.

somebodysysop’s picture

Thank you very much. I understand everything except one (and please forgive my ignorance because I'm very, very new to Drupal):

Where in the theme do you copy the two functions? Let's say I'm using the default Pushbutton theme. In it's directory are several files. Which file in the pushbutton theme directory do I add:

function pushbutton_subscriptions_email($userinfo, $emaildata) {
  $from = $emaildata->from;
  $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
  $subject = t('[%site] %type subscription update for %name : %subject', array('%site' => variable_get('site_name', 'drupal'), '%type' => $emaildata->type, '%name' => $userinfo->name, '%subject' => $emaildata->title));
  $body = t("Greetings, %name.\n\nA %type to which you have subscribed has been updated.\nTo view the thread, navigate to %url \n\n--\nThis is an automatic message from %site.\nTo manage your subscriptions, browse to %manage-url", array('%name' => $userinfo->name, '%type' => $emaildata->type, '%url' => url('node/'. $emaildata->nid, NULL, $emaildata->cid, 1), '%site' => variable_get('site_name', 'drupal'), '%manage-url' => url('subscriptions', NULL, NULL, 1)));
  return array($subject, $body, $headers);
}

Last question. Thanks!

somebodysysop’s picture

OK, for all the other newbies out there, I figured it out.

In the case of standard themes that come with the Drupal download and use phptemplate.engine, all you have to do is create a php file called template.php, put the functions inside of it, change the function name "theme" to the theme name, and put the file into your theme directory.

For example, if your theme is "pushbutton", then create a file called template.php with the following two functions from mindless's subscription_47.module update (note that I have changed the function names, replacing 'theme_' with 'pushbutton_' and also I modified them from the originals):


function pushbutton_subscriptions_emaildata($sid, $ssid, $uid, $stype) {
  $emaildata = new stdClass();
  $emaildata->from = variable_get('site_mail', ini_get('sendmail_from'));
  // if comment insertion, get vars
  if ($stype == 'node') {
    $result = db_query('SELECT title FROM {node} WHERE nid = %d', $sid);
    $emaildata->title = db_result($result);
    $emaildata->type = t('thread');
    $emaildata->nid = $sid;
    $emaildata->cid = "comment-$ssid";
  }
  // if content type, get vars
  else if ($stype == 'type') {
	//
	// I added this 2006-06-10. It gives me the title of the node.
	//
    	$result = db_query('SELECT title FROM {node} WHERE nid = %d', $ssid);
    	$emaildata->title = db_result($result);
	//
	// was:     
	// $emaildata->title = NULL;
	//
	// I also added this 2006-06-10. It give me the content type.
	//
    	$result = db_query('SELECT type FROM {node} WHERE nid = %d', $ssid);
    	$emaildata->type = t('content type (') . db_result($result) . t(')');
 	//
 	// was:
 	// $emaildata->type = t('content type');
	//
    $emaildata->nid = $ssid;
    $emaildata->cid = NULL;
  }
  // if node insert, test if node has a taxonomy else skip
  else if ($stype == 'taxa' && !is_null($sid)) {
    $result = db_query('SELECT name FROM {term_data} WHERE tid = %d', $sid);
    $emaildata->title = db_result($result);
    $emaildata->type = t('category');
    $emaildata->nid = $ssid;
    $emaildata->cid = NULL;
  }
  // if blog insert, get vars
  else if ($stype == 'blog') {
    $result = db_query('SELECT name FROM {users} WHERE uid = %d', $uid);
    $emaildata->title = t('new blog for ') . db_result($result);
    $emaildata->type = t('blog');
    $emaildata->nid = $ssid;
    $emaildata->cid = NULL;
  }
  return $emaildata;
}

function pushbutton_subscriptions_email($userinfo, $emaildata) {
  $from = $emaildata->from;
  $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
  $subject = t('[%site] %type subscription update for %name : %subject', array('%site' => variable_get('site_name', 'drupal'), '%type' => $emaildata->type, '%name' => $userinfo->name, '%subject' => $emaildata->title));
  $body = t("Greetings, %name.\n\nA %type to which you have subscribed has been updated.\nTo view the thread, navigate to %url (%subject)\n\n--\nThis is an automatic message from %site.\nTo manage your subscriptions, browse to %manage-url", array('%name' => $userinfo->name, '%type' => $emaildata->type, '%url' => url('node/'. $emaildata->nid, NULL, $emaildata->cid, 1), '%subject' => $emaildata->title, '%site' => variable_get('site_name', 'drupal'), '%manage-url' => url('subscriptions', NULL, NULL, 1)));

  return array($subject, $body, $headers);
}

Place this file into your themes/pushbutton directory, and you are good to go.

A word about my modifications: When a user subscribes to a content type, the default message he got said nothing about the nature of the content that has been updated:

Greetings, ron.

A content type to which you have subscribed has been updated.
To view the thread, navigate to http://mysite.com/drupal03/?q=node/12

I wanted the message to say what type of content type as well as the title of the node. Hence my modifications to the two functions above that now give me the following:

Greetings, ron.

A content type (event) to which you have subscribed has been updated.
To view the thread, navigate to http://mysite.com/drupal03/?q=node/18 (Ron's Test Event)

Note that I haven't tested this with all content types, so buyer beware! But, I do hope this helps someone who might have been as lost as I was.

-ron

mindless’s picture

StatusFileSize
new43.61 KB

Attached latest file, merged with recent cvs changes.

patchak’s picture

When I install the last file posted here, I can change the email content, but I don't why the subscribe checkboxe disappeards for all members on all created content. They can still subscribe by clicking a link on the content after it is posted, and the autosubscribe seems to work (after they update their account) but the checkboxes are gone on the content form for members who don't have autosubscribe!!!

I guess I would have to download the latest version of this module abd the patch it??
Or as this patch been committed to the module yet??

Thanks

patchak’s picture

oups sorry... It should read I don' know why, but the 'subscribe' checkbox disappears from the content creation form for all members... AUto subscribe works and subscription to content works also as welll... But for a user who does not have the auto subscribe, the checkbox to subscribe is gone.

Should I take the latest module in 4.7 and then patch it, instead of using this one attached here?
Thanks

dziemecki’s picture

You may want to take that up with mindless. I can only support the code I post. Right now, the Drupal repository has what I consider to be the latest and greatest.

patchak’s picture

yes, well since you added the option to display the node title in the mail, I guess I don,t *really* need this patch anymore...

Thanks

__Tango’s picture

dziemecki: Do you plan on incorporating this patch into the default Subscriptions codebase?

I have a need for this exact feature + the ability to send out MIME email. Mindless' patches have been around for a while, so i was wondering if you are going to incorporate the changes or if you expect that this will always be a one-off type scenario.

dziemecki’s picture

Frankly, I haven't really looked that closely at the patch. Right now, I'm focused on bugs. However, I've left this open because I intend to revisit it. Can't make any promises about when, however, but I don't see anything here that is fundamentally at odds with the goals of the module.

mindless’s picture

StatusFileSize
new47.82 KB

Attaching our latest code, up to date with DRUPAL-4-7 branch in CVS.

arthurf’s picture

Hey Mindless- would you mind actually submitting a patch and not the module? I've done a good chunk of changes in the last bit and it would be much easier to get your changes in if I could do the line by line comparison. I would like to get this functionality in place.

thanks!

arthurf’s picture

FYI, I think the hook_mail_alter() should help with this in the 5.0 version, but I'd like to implement the actual themability that you suggest here.

mindless’s picture

I attach the full file here due to the request in comment #1. I think you can get the version from the right date from cvs and diff against the file above. Thanks!

arthurf’s picture

Status: Needs review » Fixed

I've added theming functions for headers, subject and body. This is currently only in the 5.0 branch, and in cvs

mindless’s picture

thanks for incorporating this functionality. i do need a change before this code will work for how we theme the email.. the subject function needs to send more parameters. right now it only sends the variables needed for the default implementation.. but our theme includes the forum and node titles in the subject.. can't do this without more information given to that theme function.

other comments:
- I suggest subscriptions_sendmail have separate $from and $headers parameters to match the 5.x drupal_mail function. right now you're passing $headers to that function and giving that as the drupal_mail $from parameter. probably also the default theme headers function should just return X-Sender: Drupal. giving $from to drupal_mail will add those other things.
- I suggest you use a static $cache in the theme body function for the db query on comments table. otherwise if you have 50 subscribers to a node you'll do that query 50 times. using caching in the default theme function will also help themers realize they should do this too to avoid a performance hit on their site.

thanks!

mindless’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Status: Fixed » Active

hope it's ok, i'm setting this back to active. also changing to 5.x-dev version as that's where i'd like to see this feature. i can provide a patch implementing my suggestions if needed, but it seems you're pretty active in development recently so maybe you'll get to it :-)

arthurf’s picture

Points taken on the static, and on more options on subject, body, etc. I'm going to try do do some fairly significant refactoring of this so that the code is not such a rats nest in this area. I'll try to figure out a better way to pass data so that one can do more theming options with it more easily.

mindless’s picture

Status: Active » Fixed

added more parameters to the theme functions in DRUPAL-5 branch. now there's enough information that my theme can get the details it needs.

Anonymous’s picture

Status: Fixed » Closed (fixed)