Index: campaignmonitor.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/campaignmonitor/campaignmonitor.install,v retrieving revision 1.1.2.1 diff -u -r1.1.2.1 campaignmonitor.install --- campaignmonitor.install 9 Oct 2008 11:17:45 -0000 1.1.2.1 +++ campaignmonitor.install 27 Mar 2009 17:08:36 -0000 @@ -10,6 +10,10 @@ variable_del('campaignmonitor_api_key'); variable_del('campaignmonitor_pastcampaignurl'); variable_del('campaignmonitor_connection_timeout'); + variable_del('campaignmonitor_block_show_name'); + variable_del('campaignmonitor_block_show_mail'); + variable_del('campaignmonitor_block_show_unsub'); + variable_del('campaignmonitor_block_show_alink'); cache_clear_all('*', 'cache', TRUE); cache_clear_all('*', 'cache_filter', TRUE); Index: campaignmonitor.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/campaignmonitor/campaignmonitor.module,v retrieving revision 1.3.2.3.2.1 diff -u -r1.3.2.3.2.1 campaignmonitor.module --- campaignmonitor.module 20 Dec 2008 06:01:03 -0000 1.3.2.3.2.1 +++ campaignmonitor.module 1 Apr 2009 14:17:54 -0000 @@ -90,22 +90,70 @@ return $blocks; } else if ($op == 'configure' && $delta == 0) { + $form = array(); /* $form['items'] = array( '#type' => 'select', '#title' => t('Number of items'), '#default_value' => variable_get('XXX_block_items', 0), '#options' => array('1', '2', '3'), - ); - return $form;*/ + ); /* */ + + $form['campaignmonitor'] = array( + '#type' => 'fieldset', + '#title' => t('Campaign Monitor'), + '#description' => t('Select which fields should be visible in the block.'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + + $form['campaignmonitor']['show_name'] = array( + '#type' => 'checkbox', + '#title' => t('Name'), + '#default_value' => variable_get('campaignmonitor_block_show_name', TRUE), + '#description' => t('If the user is logged in, show their name.'), + ); + + $form['campaignmonitor']['show_mail'] = array( + '#type' => 'checkbox', + '#title' => t('Email address'), + '#default_value' => variable_get('campaignmonitor_block_show_mail', TRUE), + '#description' => t('If the user is logged in, show their email address.'), + ); + + $form['campaignmonitor']['show_unsub'] = array( + '#type' => 'checkbox', + '#title' => t('Unsubscribe box'), + '#default_value' => variable_get('campaignmonitor_block_show_unsub', TRUE), + '#description' => t('Show a check box to unsubscribe. This shows regardless of the sign in status.'), + ); + + $form['campaignmonitor']['show_alink'] = array( + '#type' => 'checkbox', + '#title' => t('Archive link'), + '#default_value' => variable_get('campaignmonitor_block_show_alink', TRUE), + '#description' => t('If you enable the menu entry, you might want to disable this. This shows regardless of the sign in status.'), + ); + + return $form; } else if ($op == 'save' && $delta == 0) { - /* variable_set('XXX_block_items', $edit['items']);*/ + variable_set('campaignmonitor_block_show_name', $edit['show_name']); + variable_set('campaignmonitor_block_show_mail', $edit['show_mail']); + variable_set('campaignmonitor_block_show_unsub', $edit['show_unsub']); + variable_set('campaignmonitor_block_show_alink', $edit['show_alink']); } + else if ($op == 'view') { switch ($delta) { case 0: - $block = array('subject' => t('Join Newsletter'), - 'content' => campaignmonitor_signup_block()); + $show = variable_get('campaignmonitor_block_show_name', TRUE) + || variable_get('campaignmonitor_block_show_mail', TRUE) + || variable_get('campaignmonitor_block_show_unsub', TRUE) + || variable_get('campaignmonitor_block_show_alink', TRUE); + if ($show) { + $block = array('subject' => t('Join Newsletter'), + 'content' => campaignmonitor_signup_block()); + } break; /* case 1: $block = array('subject' => t('Title of block #2'), @@ -206,9 +254,8 @@ function campaignmonitor_signup_block() { global $user; - $content = ''; - $content .= drupal_get_form('campaignmonitor_general_form'); - if (user_access('access archive')) { + $content = drupal_get_form('campaignmonitor_general_form'); + if (user_access('access archive') && variable_get('campaignmonitor_block_show_alink', TRUE)) { $content .= l('Newsletter Archive', 'newsletter_archive'); } return $content; @@ -261,7 +308,7 @@ global $user; // Check if the profile module is installed. If it is, use the name element of the profile if (module_exists("profile")) { - profile_load_profile($user->uid); + profile_load_profile($user); $profile_name = $user->profile_name; } // Replace api_key and list_id with your own details @@ -282,16 +329,32 @@ } } +function mollom_data_campaignmonitor_general_form($form_values) { + global $user; + return array( + 'post_title' => $form_values['name'], +// 'post_body' => $form_values['email'], + 'post_body' => 'I would like to join your newsletter, please. My name is '. $form_values['name'] .'.', + 'author_name' => $form_values['name'] ? $form_values['name'] : $user->name, + 'author_mail' => $form_values['email'] ? $form_values['email'] : $user->mail, + 'author_id' => $user->uid > 0 ? $user->uid : NULL, + 'author_ip' => _mollom_ip_address(), + ); +} + function campaignmonitor_general_form() { global $user; + $form = array(); $name = ''; $email = ''; $default = false; - + $show_name = variable_get('campaignmonitor_block_show_name', TRUE) || $user->uid == 0; + $show_mail = variable_get('campaignmonitor_block_show_mail', TRUE) || $user->uid == 0; + $show_unsub = variable_get('campaignmonitor_block_show_unsub', TRUE); + // Check if the profile module is installed. If it is, use the name element of the profile if (module_exists("profile")) { - profile_load_profile($user->uid); - $name = $user->profile_name; + profile_load_profile($user); } if ($user->uid != 0) { $email = $user->mail; @@ -305,34 +368,54 @@ } else { $default = false; - } - + } + } + if ($show_name) { + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#size' => 20, + '#maxlength' => 50, + '#required' => TRUE, + '#default_value' => $name, + ); + } + else { + $form['name'] = array( + '#type' => 'value', + '#value' => $name, + ); + } + + if ($show_mail) { + $form['email'] = array( + '#type' => 'textfield', + '#title' => t('Email'), + '#size' => 20, + '#maxlength' => 100, + '#required' => TRUE, + '#default_value' => $email, + ); + } + else { + $form['email'] = array( + '#type' => 'value', + '#value' => $email, + ); + } + + if ($show_unsub) { + $form['unsubscribe_newsletter'] = array( + '#type' => 'checkbox', + '#title' => t('Unsubscribe'), + '#default_value' => $default, + ); + } + + if ($show_name || $show_mail || $show_unsub) { + $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); } - - $form['name'] = array( - '#type' => 'textfield', - '#title' => t('Name'), - '#size' => 20, - '#maxlength' => 50, - '#required' => TRUE, - '#default_value' => $name, - ); - $form['email'] = array( - '#type' => 'textfield', - '#title' => t('Email'), - '#size' => 20, - '#maxlength' => 100, - '#required' => TRUE, - '#default_value' => $email, - ); - - $form['unsubscribe_newsletter'] = array( - '#type' => 'checkbox', - '#title' => t('Unsubscribe'), - '#default_value' => $default, - ); - $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); return $form; }