If you would, I'm requesting that you insert the following code just under line number 199 in the subscriptions_mail.module.

$mailvars['!bodiecount'] = count($user_mails['bodies']);

It is rather harmless otherwise, but this code enables the mail templates to have an additional !bodiecount token containing the number of digest items in each email. One can use this number to modify the templates to show a column of ads to the right of the content roughly equal in height to the amount of content on the left, in a 2 column email template.
( I manually modify the subscriptions_mail.templates.inc file to suit my template needs)

Comments

gregarios’s picture

I somewhat take back my request... I thought I could read the number stored in the token and derive a token "if/then" kind of setup for displaying one, two, or three ads depending on the number of teasers in the digest content of each email. I can't seem to get this to happen, as it seems you can only check for the existence of the token content in this situation? Anyone who has any pointers, I'd love some help figuring this out.

salvis’s picture

Adding that variable is certainly possible. However, you can only compare using == and !=, and I don't think you can nest the conditionals. (If at all, the chances are better in the 'else' part.)

If/then with one, two, or three should certainly work, but I don't see a good way to get 'four or more'...

Maybe a hook_subscriptions_digest(&$user_mails) and a convention that we'd merge $user_mails['mailvars'] into $mailvars would be a more flexible solution? That would allow you to define whatever variables you like.

gregarios’s picture

StatusFileSize
new10.73 KB

Maybe a hook_subscriptions_digest(&$user_mails) and a convention that we'd merge $user_mails['mailvars'] into $mailvars would be a more flexible solution? That would allow you to define whatever variables you like.

I believe, yes. I must admit I'm in a bit over my head with this... However, having a variable that I can use in the subscriptions_mail.templates.inc file would be the best, since that is the only file from Subscriptions which I've modified. (I'd like to keep it that way.)

Attached is my heavily modified file. If you could see fit, would you take a peek, and maybe tell me how I can incorporate a conditional variable that would allow me to define the 'ADS' case containing 1, 2, or 3 ads depending on that variable?

gregarios’s picture

Title: Digest Item Count Token Request » Digest Item Count Variable Request
salvis’s picture

You'd have to do a bit of PHP programming to take advantage of such a hook.

Essentially, you'd write a Drupal module with a function that receives the $user_mails array, you'd count the bodies (or whatever) and you'd set $user_mails['mail_vars']['!number_of_ads'] to whatever you want. Then you could use that variable in your digest template.

gregarios’s picture

Title: Digest Item Count Variable Request » Digest Item Count Token Code Request

Ok... I just made some headway. My original request stands. The token I can use, albeit a round-about way of doing it, its the only way I understand it at this point. If you could add it, it may not be useful to anyone else, but it SURE would help me with this.

salvis’s picture

Category: feature » task

We'll do a hook and I'll help you with it...

But it'll take a while. Please nag me in three weeks if I haven't done it by then.

salvis’s picture

StatusFileSize
new3.82 KB

Be sure to try this on a test system — it's completely untested.

Apply the attached patch to the -dev version.

Then create a mysite module for your site:

Create mysite.info

; $Id$
name = Mysite
description = Contains the site-specific customizations.
package = Other
core = 6.x

and mysite.module

<?php
// $Id$

/**
 * @file
 * Customizations for the mysite website.
 */

/**
 * Implementation of hook_subscriptions_digest_alter().
 */
function mysite_subscriptions_digest_alter(&$digest_data) {
  $digest_data['mailvars']['!digest_count'] = count($digest_data['bodies']);
}

Put the files with the other contrib modules (usually sites/all/modules/mysite) and enable the module. Then you should get a new !digest_count variable.

Gook luck!

gregarios’s picture

StatusFileSize
new12.22 KB

The patch causes no errors from what I can see, and emails do still go out.

I did the instructions you gave, then I took my subscriptions_mail.templates.inc_.txt file and modified it as the attached file, but it doesn't seem to show the 2nd, 3rd, etc ads inline like it does if I do the Line199 code addition. Maybe I'm not using this variable correctly, as I seem to be using it like a token still... but... I'm not sure how to get this right. Please forgive my ignorance in this matter, as I've had no formal PHP training.

If I insert the !digest_count variable directly into the template, I only get the actual "!digest_count" text in the email.

gregarios’s picture

Egads... I just realized that you are already using the !digest_count variable in another part of the module to count digest emails, not digest bodies...

Update: changing the variable name in my custom module and the template made no difference.

salvis’s picture

Egads... I just realized that you are already using the !digest_count variable in another part of the module to count digest emails, not digest bodies...

That's completely unrelated and does not interfere.

I did the instructions you gave, then I took my subscriptions_mail.templates.inc_.txt file

There should not be any underscore after ".inc"!

Did you create and activate the Mysite module? If you changed "Mysite", then did you change it wherever it occurs?

Do you by chance have the Devel module installed? Then you can change

function mysite_subscriptions_digest_alter(&$digest_data) {
  $digest_data['mailvars']['!digest_count'] = count($digest_data['bodies']);
}

to

function mysite_subscriptions_digest_alter(&$digest_data) {
  dpm($digest_data['mailvars']);
  $digest_data['mailvars']['!digest_count'] = count($digest_data['bodies']);
  dpm($digest_data['mailvars']);
}

Now, when you run cron manually, you should see the mailvars array twice, with the !digest_count variable inserted the second time.

gregarios’s picture

Ah... I'd missed renaming the "mysite" in the function name... retesting now...

Update: THAT works! :-)

2 Questions:

1) How does your way of doing this add more functionality for me?

2) Should I start a different 'feature request' to ask if there is a way we can externalize the subscriptions_mail.templates.inc file functionality so I don't have to hack anything in the Subscriptions module to get my custom template to work? The reason I resorted to hacking the default template was the Mail Editor module was not working.

THANK YOU for so much work! This has been invaluable for me, and I've learned quite a bit as well.

gregarios’s picture

Title: Digest Item Count Token Code Request » Digest Item Count Variable/Token Hook Code Request
Status: Active » Reviewed & tested by the community
gregarios’s picture

Looks like this person is having the same issues I was with Mail Editor not working right: http://drupal.org/node/651304

salvis’s picture

1) How does your way of doing this add more functionality for me?

It's a general mechanism that lets you or anyone else add (or change!) any number of !variables programmatically without hacking. It's an opportunity for customizing Subscriptions by adding just the minimum amount of code required. It's the preferred mechanism throughout all of Drupal to do such customizations — THE Drupal Way.

This hook is for digests and I intend to add similar hooks for non-digest notifications and comments.

2) Should I start a different 'feature request' to ask if there is a way we can externalize the subscriptions_mail.templates.inc file functionality

Yes, please.

THANK YOU for so much work! This has been invaluable for me, and I've learned quite a bit as well.

You're welcome. Are you ready to jump into PHP programming yet?

gregarios’s picture

Are you ready to jump into PHP programming yet?

Oh... I already dove in. It just takes a while to learn. Perl seemed a lot easier to me in many ways. :-)

salvis’s picture

Great! :-)

What do you find difficult in PHP over Perl?

gregarios’s picture

What do you find difficult in PHP over Perl?

Well, that's where the lines are fuzzy for me. Sometimes I'm not sure what items are PHP specific and which are Drupal specific... Perl is Perl, even in apps. But, because I'm learning PHP while learning Drupal, it is confusing... Also, Perl has a definite barrier between it and the HTML, where as PHP can be mixed in with the HTML a lot more.

PS: Any idea when this will be rolled into another release version?

salvis’s picture

Perl has a definite barrier between it and the HTML, where as PHP can be mixed in with the HTML a lot more.

At the theming level yes, but at the module level there's no HTML. There's a strict separation between those two levels.

BTW, Devel is your friend, and especially the dpm() function; it's easy to quickly insert anywhere and shows you what data you're dealing with. For heavy lifting, a debugger that let's you break on any given line and inspect variables is indispensable.

Any idea when this will be rolled into another release version?

Probably by the end of the year.

gregarios’s picture

Any idea when this might get out in a real release? :-) I've been using my custom module with the dev version for awhile now and it works wonderfully. :-)

salvis’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for the feedback, that's nice to hear.

I've committed it to the -dev version. Give it up to 12h to be repackaged.

Please check it out and let us know if it still works. Then we can release 1.2.

(If you wish to keep a backup of the old version, be sure to move it OUT FROM BELOW the Drupal directory tree!!!)

gregarios’s picture

Version: 6.x-1.1 » 6.x-1.x-dev

The Feb 3rd 6.x-1.x-dev release works great! :-) Thanks Salvis.

Status: Fixed » Closed (fixed)

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