You are here

mailchimp_bio.module in Mailchimp 5

Same filename and directory in other branches
  1. 5.2 mailchimp_bio.module

File

mailchimp_bio.module
View source
<?php

// $Id

/**
 * Implementation of hook_nodeapi(). Allows update on bio change
 */
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;
    }
  }
}

/**
 * Implementation of hook_mailchimp_merge_keys
 */
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;
}

/**
 * Implementation of hook_mailchimp_merge_values
 */
function mailchimp_bio_mailchimp_merge_values($user) {
  $out = array();
  $out = (array) $user;
  $out = array_merge($out, _mailchimp_get_bio_fields($user));
  return $out;
}

/**
 * Get the bio.module fields for the given user
 */
function _mailchimp_bio_get_bio_fields($user) {
  $out = array();
  if (function_exists('bio_for_user') && ($nid = bio_for_user($user->uid))) {

    // Load the bio node. Reload from the database because this us called during update.
    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;
}

Functions

Namesort descending Description
mailchimp_bio_mailchimp_merge_keys Implementation of hook_mailchimp_merge_keys
mailchimp_bio_mailchimp_merge_values Implementation of hook_mailchimp_merge_values
mailchimp_bio_nodeapi Implementation of hook_nodeapi(). Allows update on bio change
_mailchimp_bio_get_bio_fields Get the bio.module fields for the given user