Index: phplist.module =================================================================== RCS file: /cvs/drupal/contributions/modules/phplist/phplist.module,v retrieving revision 1.12.2.19 diff -u -r1.12.2.19 phplist.module --- phplist.module 26 Mar 2009 13:59:44 -0000 1.12.2.19 +++ phplist.module 30 Apr 2009 08:17:47 -0000 @@ -22,11 +22,11 @@ case 'admin/help#phplist': $output = t('

The phpList interface module allows you to send newsletters to your Drupal users using a separate phpList installation. You can allow your Drupal users to (un)subscribe to newsletters via the Drupal site, but all creating, sending and processing of newsletters/bounces etc. is done directly in phpList.

The phpList pre-requisites are minimal: -

+

User accounts are synchronised from Drupal to phpList - if a user changes their email, or their account is deleted, this change is replicated to phpList. An attribute is added to enable you to easily identify users which are not "native" to phpList - take care @@ -231,6 +231,27 @@ '#default_value' => variable_get('phplist_pllastname', 'Last Name') ); } + if (module_exists('locale')) { + $languages = locale_language_list(); + if (count($languages) > 1) { + $count = 1; + $form['mapping']['phplist_lang'] = array( + '#type' => 'textfield', + '#title' => t('Language mapping'), + '#default_value' => variable_get('phplist_lang', ''), + '#description' => t('Language attribute in phplist, leave blank to disable language mapping.'), + ); + foreach ($languages as $key => $value) { + $form['mapping']["phplist_lang_$key"] = array( + '#type' => 'textfield', + '#title' => $value, + '#default_value' => variable_get("phplist_lang_$key", (string)$count), + '#description' => t('phplist attribute table value for !lang', array('!lang' => $value)), + ); + $count++; + } + } + } $form['user'] = array( '#title' => 'My Account - My Newsletters options', '#type' => 'fieldset' @@ -270,7 +291,7 @@ $form['sync'] = array( '#title' => 'Synchronise users to phpList', '#type' => 'fieldset' - ); + ); $form['sync']['phplist_sync'] = array( '#type' => 'item', @@ -438,7 +459,7 @@ break; case 'update': - // Account has been modified - object $user still has original email, array $edit has modified (if changed) + // Account has been modified - object $user still has original email, array $edit has modified (if changed) $phplistid = _phplist_lookup_phplistid($user->mail); break; @@ -447,17 +468,17 @@ break; case 'delete': - // User is being deleted - update phpList too + // User is being deleted - update phpList too $phplistid = _phplist_lookup_phplistid($user->mail); if (true) { - // Just remove the Drupal flag from the phpList account + // Just remove the Drupal flag from the phpList account _phplist_update_attribute('Drupal', 'checkbox', 'off', $phplistid); } else { db_set_active('phplist'); - // Completely remove this user from PHPlist - could be enabled using another system variable + // Completely remove this user from PHPlist - could be enabled using another system variable db_query("DELETE FROM $strprefix%s WHERE userid = %d", $prefix['prefix']."listuser", $phplistid); db_query("DELETE FROM %s WHERE userid = %d", $prefix['user']."attribute", $phplistid); db_query("DELETE FROM $strprefix%s WHERE userid = %d", $prefix['prefix']."usermessage", $phplistid); @@ -472,10 +493,10 @@ case 'form': if ($category == 'phplist' && user_perm('access lists')) { - // Lookup the list of mails lists + // Lookup the list of mails lists $form = phplist_lists($user); - // Show the pre-amble text + // Show the pre-amble text $form['preamble'] = array( '#value' => variable_get('phplist_preamble', ''), '#weight' => -10 @@ -638,7 +659,7 @@ if (empty($rows)) { if ($subonly) { - // We're in the user account area - change the wording slightly + // We're in the user account area - change the wording slightly $rows[] = array(array('data' => t('No subscriptions. You can subscribe to mailing lists here.'), 'colspan' => '2')); } else { @@ -757,15 +778,27 @@ $attrmap = array(); if (($profile_firstname = variable_get('phplist_profilefirstname', '')) != 'profile_') { - // Map first name to phpList attribute + // Map first name to phpList attribute $attrmap[] = array($profile_firstname, variable_get('phplist_plfirstname', '')); } if (($profilelastname = variable_get('phplist_profilelastname', '')) != 'profile_') { - // Map last name to phpList attribute + // Map last name to phpList attribute $attrmap[] = array($profilelastname, variable_get('phplist_pllastname', '')); } + if ((($langattr = variable_get('phplist_lang', '')) != '') && module_exists('locale')) { + // Map languages to array + $languages = locale_language_list(); + $count = 0; + $langmap = array(); + $langmap[$langattr] = array(); + foreach ($languages as $key => $value) { + $langmap[$langattr][$key] = variable_get("phplist_lang_$key", (string)$count); + $count++; + } + } + if ($phplistid != '') { db_set_active('phplist'); $result = db_query("UPDATE {$prefix['user']}user SET email='%s', modified=NOW(), htmlemail=%d, confirmed=1 WHERE id=%d", ($user->mail == '' ? $user->init : $user->mail), ($user->phplist_html == 0 || $user->phplist_html == '' ? 1 : 0), $phplistid); @@ -791,7 +824,7 @@ _phplist_update_attribute('Drupal role - '. $role, 'checkbox', 'on', $phplistid); } elseif ($role == 'authenticated user') { - // Always add this role to tag the phpList user as originating from Drupal + // Always add this role to tag the phpList user as originating from Drupal _phplist_update_attribute('Drupal', 'checkbox', 'on', $phplistid); if (!$booroles) break; } @@ -799,7 +832,7 @@ // Synchronise other profile fields to phpList attributes if (module_exists('profile')) { - // Store other attributes/profile settings + // Store other attributes/profile settings foreach ($attrmap as $attr) { if (isset($user->{$attr[0]})) { if (PHPLIST_DEBUG) drupal_set_message('Synchronised attribute '. $attr[1] .' : '. $user->{$attr[0]}); @@ -808,6 +841,21 @@ } } + // Synchronise language + if (module_exists('locale')) { + if (isset($user->language)) { + $lang = $user->language; + } + else { + global $language; + $lang = $language->language; + } + foreach ($langmap as $langattr => $langs) { + if (PHPLIST_DEBUG) drupal_set_message('Synchronised language '. $lang .' : '. $langs[$lang]); + _phplist_update_attribute($langattr, 'radio', $langs[$lang], $phplistid); + } + } + db_set_active('default'); } @@ -822,7 +870,7 @@ $drupalid = db_result(db_query("SELECT id FROM {$prefix['user']}attribute WHERE name='$attr_name'")); if ($drupalid == '') { - // Attribute has not been created + // Attribute has not been created db_query("INSERT INTO {$prefix['user']}attribute(name, type, listorder, default_value, required, tablename) VALUES('$attr_name', '$attr_type', 0, '', 0, '$attr_name')"); $drupalid = db_result(db_query("SELECT id FROM {$prefix['user']}attribute WHERE name='$attr_name'")); if (PHPLIST_DEBUG) drupal_set_message("Added PHPlist attribute"); @@ -1240,6 +1288,19 @@ 'subscribe' => 'Subscribe', ); + if (module_exists('locale') && variable_get('phplist_lang', '') != '') { + global $language; + $lang = $language->language; + $attr_name = variable_get('phplist_lang', ''); + $prefix = _phplist_dbconn(); + db_set_active('phplist'); + $attrid = db_result(db_query("SELECT id FROM {$prefix['user']}attribute WHERE name='$attr_name'")); + if ($attrid) { + $data["attribute$attrid"] = variable_get("phplist_lang_$lang", '1'); + drupal_set_message($lang); + } + } + $lists = _phplist_get_public_lists($user); foreach ($lists as $l) { @@ -1300,7 +1361,7 @@ // If we are still here, this is a non-Druapl person unsubscribing $form['mail'] = array( '#title' => t('Email address'), - '#type' => 'textfield', + '#type' => 'textfield', '#required' => TRUE, '#default_value' => $email, ); @@ -1377,8 +1438,8 @@ '#type' => 'item', '#title' => t('Problem with confirmation'), '#value' => t('Sorry, your request for confirmation was not recognised. - Please make sure to use the full web address as mentioned in the email that you received. - Sometimes this web address wraps onto multiple lines.'), + Please make sure to use the full web address as mentioned in the email that you received. + Sometimes this web address wraps onto multiple lines.'), ); } elseif (strpos($result->data, 'Thank you for confirming ') > 0) {