diff -u -r mailchimp.org/mailchimp.admin.inc mailchimp/mailchimp.admin.inc --- mailchimp.org/mailchimp.admin.inc 2012-08-20 14:09:29.036030681 +1000 +++ mailchimp/mailchimp.admin.inc 2012-08-20 14:26:10.475998607 +1000 @@ -125,6 +125,22 @@ } } } + if (module_exists('domain')) { + $domain_options = array(); + foreach (domain_domains() as $domain) { + ($domain['domain_id'] == 0) ? $key = -1 : $key = $domain['domain_id']; + if ($domain['valid']) { + $domain_options[$key] = $domain['sitename']; + } + } + $form['mailchimp_lists']['mailchimp_list_'. $list['id']]['domains'] = array( + '#type' => 'checkboxes', + '#title' => t('Domains'), + '#default_value' => (isset($saved_list->domains)) ? $saved_list->domains : array(), + '#options' => $domain_options, + '#description' => t('New subscribers will be sent a link with an email they must follow to confirm their subscription.'), + ); + } } $form['mailchimp_messages'] = array( @@ -266,10 +282,11 @@ */ function mailchimp_admin_settings_submit($form, &$form_state) { // no lists selected or first time here + if(empty($form_state['values']['mailchimp_lists'])){ return; } - + $required = FALSE; $lists = array(); foreach ($form_state['values']['mailchimp_lists'] as $form_list) { @@ -282,8 +299,10 @@ $list->listtype = $form_list['listtype']; $list->doublein = $form_list['doublein']; $list->mergevars = $form_list['mergevars']; + if (module_exists('domain')) { + $list->domains = $form_list['domains']; + } $lists[$form_list['list_id']] = $list; - $required = ($form_list['listtype'] == MAILCHIMP_LISTTYPE_REQUIRED && $form_state['values']['mailchimp_cron']); } diff -u -r mailchimp.org/mailchimp.module mailchimp/mailchimp.module --- mailchimp.org/mailchimp.module 2012-08-17 14:12:59.060325575 +1000 +++ mailchimp/mailchimp.module 2012-08-21 11:21:38.281586017 +1000 @@ -323,7 +323,15 @@ function mailchimp_cron() { if (variable_get('mailchimp_cron', FALSE) && $q = _mailchimp_get_api_object()) { // grab UIDs for active users who are pending - $sql = "SELECT mu.uid FROM {mailchimp_user} mu LEFT OUTER JOIN {users} u ON mu.uid = u.uid WHERE mu.status = '%s' AND u.status = 1"; + + $domain_access = module_exists('domain') ? TRUE : FALSE; + + /* Domain access enabled implementations need extra information */ + if ($domain_access) { + $sql = 'SELECT mu.uid,GROUP_CONCAT(de.domain_id) AS domain_ids FROM {mailchimp_user} mu LEFT OUTER JOIN {users} u ON mu.uid = u.uid INNER JOIN {domain_editor} AS de ON u.uid=de.uid WHERE mu.status = \'%s\' AND u.status = 1 GROUP BY uid'; + } else { + $sql = "SELECT mu.uid FROM {mailchimp_user} mu LEFT OUTER JOIN {users} u ON mu.uid = u.uid WHERE mu.status = '%s' AND u.status = 1"; + } $result = db_query_range($sql, array(MAILCHIMP_USERSTATUS_PENDING), 0, variable_get('mailchimp_batch_limit', 100)); if ($result) { @@ -334,10 +342,23 @@ $lists[$key]->unsubscribe = array(); } while ($row = db_fetch_object($result)) { + if ($domain_access) { + $row->domain_ids = explode(',',$row->domain_ids); + foreach ($row->domain_ids as $dindex => $dvalue) { + if ($dvalue == 0) { // This is to get around the 0/null problem with checkboxes on the admin screen + $row->domain_ids[$dindex] = -1; + } + } + } if ($account = user_load(array('uid' => $row->uid))) { db_query('UPDATE {mailchimp_user} SET status = \'%s\' WHERE uid = %d', MAILCHIMP_USERSTATUS_CURRENT, $account->uid); foreach ((array)$lists as $key => $list) { + $valid_domains = array_intersect($row->domain_ids,$list->domains); + if (empty($valid_domains)) { + $lists[$key]->unsubscribe[] = $account->mail; // We may have removed them from this domain + continue; + } $is_allowed = FALSE; foreach ((array)$account->roles as $rid => $info) { if ($list->roles[$rid]) {