It would be nice if there was an optional setting to expose the "enable" Check box during user registration.

CommentFileSizeAuthor
#4 admin.png13.57 KBonionweb
#3 notify.module_1.patch6.56 KBonionweb

Comments

onionweb’s picture

Version: » 4.6.x-1.x-dev

I added an opt-in during registration checkbox to notify. Just a single checkbox that flips the master switch and content options to enabled.

The way I did it was to add the hook user function to notify, which puts serialized data in the user table: "notify_status"

Then I wrote another function which does a left join on the users and the notify tables, grabs all the uids that are not already present in the notify table, checks them in users for "notify_status" and, if the status is present, adds their records to the notify table. This function is triggered by notify_cron.

function _notify_optin(){
$result = db_query('SELECT DISTINCT(users.uid) FROM users LEFT JOIN notify on users.uid = notify.uid WHERE notify.uid IS NULL');
while ($uid = db_fetch_object($result)) {
$account = user_load(array('uid' => $uid->uid, 'status' => 1));
if ($account->notify_status) {

db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $account->uid,1,1,0,0);
   }
 }
}

function notify_user($type, $edit, &$user, $category = NULL) {
  switch ($type) {
    case 'register':
      return array(array('title' => t('Notification settings'), 'data' => form_checkbox(t('Email notification'), 'notify_status', 1, $edit['notify_status'], t('Receive daily email notifications of new content posted to this site.')), 'weight' => 3));
  }
}

function notify_cron() {
   _notify_optin();
...

So, when cron runs, anybody who opted in during registration gets added to notify. If they've already changed their notify settings before cron runs, they are ignored. Maybe there's a better way to do this. Any suggestions?

Also, I couldn't figure out how to remove the notify switch from the user table after it has been checked, although that really doesn't affect the functionality.

onionweb’s picture

Maybe there's a better way to do this with far less code:


function notify_user($type, $edit, &$user, $category = NULL) {
  switch ($type) {
    case 'register':
      return array(array('title' => t('Notification settings'), 'data' => form_checkbox(t('Content emailing'), 'notify_status', 1, $edit['notify_status'], t('Receive daily email notifications of new content posted to this site.')), 'weight' => 3));
    case 'insert':
      if ($edit['notify_status']) {
          db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $user->uid,1,1,0,0);
      }
   }
}
onionweb’s picture

Status: Active » Needs review
StatusFileSize
new6.56 KB

This patch does several things. Some of the code was inspired by this: http://drupal.org/node/28040

1. admin interface:

a. limit notifications by node type;
b. Allow simple opt-in checkbox in user registration form;
1. If simple checkbox is enabled, set the default values for notifications enabled via user registration checkbox. Users can always change them later.

2. user interface
a. checkbox visible in user registration form.

This is a patch against 4.6.

onionweb’s picture

StatusFileSize
new13.57 KB

here's screenshot of admin/notify

kweisblatt’s picture

This is great! Thanks for your work!

I am trying to allow users to be notified when a certain field in cck matched theirs. For example, I have cck fields: street address, city, state, zip. If they live in NY, it would be useful if they could be notified everytime someone in NY creates a page. (I have tried subsciptions, but that only uses categories.)

beginner’s picture

Version: 4.6.x-1.x-dev » 5.x-1.x-dev
Status: Needs review » Needs work

patch is old.

nevmoor’s picture

What about for sites that add the notify module AFTER there are current members? Is there a way to add an administrative setting to turn this on at install? I just don't want to have to do it for every member by hand......

mdowsett’s picture

any idea if this patch works for v5?

nevmoor (#7) - if you are using v5, see here (http://drupal.org/node/36163) for getting existing users' notifications turned on....it worked for me.

gisle’s picture

Status: Needs work » Closed (won't fix)

Version 4 and 5 is no longer supported, and since nobody has worked on this in 5.5 years, it is not likely to happen now. In Drupal 6 and Drupal 7, there is a tab that lets users opt in during registration. If you want this, please upgrade to Drupal 6 or Drupal 7.