mailchimp_bio.module in Mailchimp 5
File
mailchimp_bio.module
View source
<?php
function mailchimp_bio_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if (function_exists('bio_get_type') && $node->type == bio_get_type()) {
switch ($op) {
case 'insert':
case 'update':
if (($q = _mailchimp_get_api_object()) && ($account = user_load(array(
'uid' => $node->uid,
)))) {
foreach ((array) $q
->lists() as $key => $list) {
if (_mailchimp_is_subscribed($list['id'], $account->mail, $q)) {
$merge_vars = _mailchimp_load_user_list_mergevars($account->uid, $list['id'], $q
->listMergeVars($list['id']));
_mailchimp_update_user($list, $account->mail, $merge_vars, $q);
}
}
}
break;
}
}
}
function mailchimp_bio_mailchimp_merge_keys() {
$out = array(
0 => '<none>',
);
if (function_exists('_bio_get_fields')) {
$bio_fields = _bio_get_fields();
foreach ($bio_fields as $field) {
$out['bio_' . $field['field_name']] = t('Bio: !field', array(
'!field' => $field['widget']['label'],
));
}
}
return $out;
}
function mailchimp_bio_mailchimp_merge_values($user) {
$out = array();
$out = (array) $user;
$out = array_merge($out, _mailchimp_get_bio_fields($user));
return $out;
}
function _mailchimp_bio_get_bio_fields($user) {
$out = array();
if (function_exists('bio_for_user') && ($nid = bio_for_user($user->uid))) {
if ($node = node_load($nid, NULL, true)) {
$bio_fields = _bio_get_fields();
$node = node_build_content($node, false, true);
foreach ($bio_fields as $key => $field) {
$out['bio_' . $key] = $node->{$key}[0]['view'];
}
}
}
return $out;
}