function mailchimp_block in Mailchimp 6.2
implementation of hook_block Provides a block for each available list for a given user
File
- ./
mailchimp.module, line 1076 - Mailchimp module.
Code
function mailchimp_block($op = 'list', $delta = 0) {
if ($op == "list") {
$blocks = array();
$all_lists = variable_get('mailchimp_lists', array());
if (!empty($all_lists)) {
foreach ($all_lists as $key => $list) {
// exclude required lists
if ($list->listtype !== MAILCHIMP_LISTTYPE_REQUIRED) {
$blocks[$list->id] = array(
'info' => t('Mailchimp Subscription Form: @name', array(
'@name' => $list->name,
)),
'cache' => BLOCK_CACHE_PER_USER,
);
}
}
}
return $blocks;
}
else {
if ($op == 'view' && arg(2) != 'mailchimp' && arg(0) != 'mailchimp') {
$block = array();
global $user;
$lists = _mailchimp_get_available_lists($user);
if (!empty($lists)) {
if (!empty($lists[$delta]) && ($q = _mailchimp_get_api_object())) {
$list = $lists[$delta];
$block['subject'] = t('Subscribe to @title', array(
'@title' => $list->name,
));
if ($user->uid) {
$block['content'] = drupal_get_form('mailchimp_subscribe_auth_form_' . $list->id, $user, 1, $list);
}
else {
$block['content'] = drupal_get_form('mailchimp_subscribe_anon_form_' . $list->id, $list, $q);
}
}
}
return $block;
}
}
}