You are here

account_sync.module in Account Sync 6

Same filename and directory in other branches
  1. 7.2 account_sync.module

File

account_sync.module
View source
<?php

/**
 * Implementation of hook_menu().
 */
function account_sync_menu() {
  $items = array();
  $items['admin/user/account_sync'] = array(
    'title' => 'Account sync',
    'description' => 'Setup accounts to sync across multiple drupal sites.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'account_sync_settings',
    ),
    'access arguments' => array(
      'administer account sync',
    ),
    'file' => 'account_sync.admin.inc',
    'type' => NORMAL_MENU_ITEM,
  );
  $items['admin/user/account_sync/global'] = array(
    'title' => 'Global settings',
    'description' => 'Setup accounts to sync across multiple drupal sites.',
    'access arguments' => array(
      'administer account sync',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  $items['admin/user/account_sync/sender'] = array(
    'title' => 'Sender settings',
    'description' => 'Settings for sending the account data to a remote server',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'account_sync_sender_settings',
    ),
    'access arguments' => array(
      'administer account sync',
    ),
    'file' => 'account_sync.admin.inc',
    'weight' => 1,
    'type' => MENU_LOCAL_TASK,
  );
  $items['admin/user/account_sync/receiver'] = array(
    'title' => 'Receiver settings',
    'description' => 'Settings for receiving the account data from a remote server',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'account_sync_receiver_settings',
    ),
    'access arguments' => array(
      'administer account sync',
    ),
    'file' => 'account_sync.admin.inc',
    'weight' => 2,
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/**
 * Implementation of hook_perm().
 */
function account_sync_perm() {
  return array(
    'administer account sync',
    'sync account',
  );
}

/**
 * Implementation of hook_xmlrpc().
 */
function account_sync_xmlrpc() {
  module_load_include('inc', 'account_sync', 'account_sync.receiver');
  return array(
    array(
      'account_sync.updateUser',
      'account_sync_update_user',
      array(
        'struct',
        'string',
        'string',
        'struct',
        'struct',
        'string',
        'struct',
      ),
      t('Update the given user account'),
    ),
  );
}

/**
 * Implementation of hook_user().
 */
function account_sync_user($op, &$edit, &$account, $category = NULL) {
  module_load_include('inc', 'account_sync', 'account_sync.sender');
  return account_sync_send_update($op, &$edit, &$account, $category);
}

/**
 * Allow modules to hook into hook_account_sync_servers($url, $account).
 *
 * It passes the server url and the given account for each server available
 * for syncing. If any of the hooks return FALSE for a given server url or
 * account then the account data will not be sent to that server.
 */
function account_sync_servers($account) {
  $servers = array();
  $all_servers = explode("\n", variable_get('account_sync_servers', ''));

  // Strip out blank lines
  $all_servers = array_filter($all_servers);
  foreach ($all_servers as $server) {
    $results = module_invoke_all('account_sync_servers', $server, $account);
    if (!in_array(FALSE, $results)) {
      $servers[] = $server;
    }
  }
  return $servers;
}

/**
 * Figure out which roles have the account sync permissions.
 *
 * Return all roles that have the 'sync account' permission.
 * If no roles have the sync account permission then returns FALSE.
 */
function account_sync_allowed_roles() {
  $result = db_query("SELECT r.name, p.perm FROM {permission} p LEFT JOIN {role} r ON r.rid = p.rid AND r.rid <> %d", DRUPAL_ANONYMOUS_RID);
  $roles = array();
  while ($row = db_fetch_object($result)) {
    $perms = explode(', ', $row->perm);
    if (in_array('sync account', $perms)) {
      $roles[$row->rid] = $row->name;
    }
  }
  return empty($roles) ? FALSE : $roles;
}

/**
 * Simple helper function to return a list of profile categories.
 */
function _account_sync_get_profile_categories() {
  $categories = array();
  if (module_exists('profile')) {
    $result = db_query("SELECT DISTINCT(category) FROM {profile_fields}");
    while ($category = db_fetch_object($result)) {
      $categories[$category->category] = $category->category;
    }
  }
  return $categories;
}

Functions

Namesort descending Description
account_sync_allowed_roles Figure out which roles have the account sync permissions.
account_sync_menu Implementation of hook_menu().
account_sync_perm Implementation of hook_perm().
account_sync_servers Allow modules to hook into hook_account_sync_servers($url, $account).
account_sync_user Implementation of hook_user().
account_sync_xmlrpc Implementation of hook_xmlrpc().
_account_sync_get_profile_categories Simple helper function to return a list of profile categories.