drupal_hub.module 6.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
<?php

if (variable_get('drupal_hub_is_client', false)) {
  include_once(drupal_get_path('module', 'hub') .'/inc/drupal_hub_client.inc');
}
if (variable_get('drupal_hub_is_server', false)) {
  include_once(drupal_get_path('module', 'hub') .'/inc/drupal_hub_server.inc');
}

/**
 *  implement hook_menu
 */
function drupal_hub_menu($may_cache) {
  $items = array();

  if ($may_cache) {
    $admin_access = user_access('administer hub');
    $items[] = array(
      'path' => 'admin/hub',
      'title' => t('Hub configuration'),
      'description' => t('Adjust Hub portal configuration options.'),
      'position' => 'right',
      'weight' => -5,
      'callback' => 'system_admin_menu_block_page',
      'access' => $admin_access,
    );
    $items[] = array(
      'path' => 'admin/hub/global',
      'title' => t('Global Hub configuration'),
      'description' => t('Global Hub settings.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => 'drupal_hub_admin_settings',
      'access' => $admin_access,
    );
    if (variable_get('drupal_hub_is_client', false)) {
      $items[] = array(
        'path' => 'admin/hub/client',
        'title' => t('Hub client configuration'),
        'description' => t('Client Hub settings.'),
        'callback' => 'drupal_get_form',
        'callback arguments' => 'drupal_hub_client_admin_settings',
        'access' => $admin_access,
      );
    }
    if (variable_get('drupal_hub_is_server', false)) {
      $items[] = array(
        'path' => 'admin/hub/server',
        'title' => t('Hub server configuration'),
        'description' => t('Server Hub settings.'),
        'callback' => 'drupal_get_form',
        'callback arguments' => 'drupal_hub_server_admin_settings',
        'access' => $admin_access,
      );
    }
  }

  return $items;
}

/**
 *  Display global Hub admin settings
 */
function drupal_hub_admin_settings() {
  // we have to rebuild the menu, because certain menu items are built or removed accordingly
  menu_rebuild();

  $form = array();

  // Allow the admin to turn on or off all services offered by various Hub modules on the server.
  $form['services'] = array(
    '#type' => 'fieldset',
    '#title' => t('Active Services'),
    '#description' => t('Check the box for each Hub portal service you wish to activate for this host.'),
    '#collapsible' => true,
    '#collapsed' => false,
  );
  $services = module_invoke_all('hubapi', 'list services');
  $service_descriptions = module_invoke_all('hubapi', 'describe services');
  foreach ($services as $service => $title) {
    $form['services'][$service] = array(
      '#type' => 'checkbox',
      '#title' => $title,
      '#description' => $service_descriptions[$service],
      '#default_value' => variable_get($service, false),
    );
  }

  return system_settings_form($form);
}

/**
 *  Implements hook_hubapi:
 *  $op
 *    'list services': This will return an array of the hub services offered by this module.
 *      This is used by the Hub server when associating node types to the server, so when a
 *      client requests the listing options offered, they will also see which modules & services
 *      are required to be included in that server's listings.
 *    'describe services': This is a brief description of the services offered.
 *    'field defaults': This returns an array of variables offered as defaults for listings.
 *      Each field has a prefix that determines the type of variable passed:
 *      v: signifies a variable stored as variable_get('variable', ...);
 *      $: signifies a variable stored as a global $variable;
 *      c: signifies a variable stored as a CONSTANT variable;
 *      f: signifies a variable that will be returned by a function call;
 *      s: signifies special handling for the variable, which must be determined by the calling module.
 *      Note that anything other than v: must be handled by the calling module; the prefixes are for the
 *      benefit of human programmers.
 *    'server defaults': A Hub module may define one or more default servers to list for
 *      clients. This will return an array of $key => array('name' => $name, 'xmlrpc' => $xmlrpc),
 *      where $key is a unique code, $name is the name of the server, and $xmlrpc is the
 *      address for the server's xmlrpc calls. This server should be configured as a
 *      Hub server.
 *
 *  return values for $op:
 *    'list services': This should return an array of strings of the services offered by
 *      the module, keyed by the variable for whether that service has been activated by the
 *      client module. For instance, the Hub module allows two services, 'client' and 'server'.
 *      The client service is activated with variable_get('drupal_hub_is_client', false), so the
 *      resulting array is array('drupal_hub_is_client' => t('Hub client service'), 'drupal_hub_is_server'
 *      => t('Hub server service')).
 *    'describe services': This returns a keyed array of strings for the descriptions offered
 *      by the module, keyed by the same service variables as for 'list services'.
 */
function drupal_hub_hubapi($op) {
  switch ($op) {
    case 'list services':
      return array(
        'drupal_hub_is_client' => t('Hub: Client service'),
        'drupal_hub_is_server' => t('Hub: Server service')
      );
    case 'describe services':
      return array(
        'drupal_hub_is_client' => t('Hub Clients may be listed on Hub Servers they have registered with through admin screens on the client. Once registered, the Hub servers will periodically update their listing information.'),
        'drupal_hub_is_server' => t('A Hub Server may list clients who have registered with their server, associating the clients with configurable nodes, so the nodes may be displayed through various views and blocks.'),
      );
    case 'field defaults':
      return array(
        'v:site_name' => t('Site Name'),
        '$:base_url' => t('Site URL'),
        'v:site_mission' => t('Site Mission'),
        'v:site_slogan' => t('Site Slogan'),
        'v:site_mail' => t('Site Mail'),
        'c:VERSION' => t('Version'),
      );
    case 'server defaults':
      return array(
        'drupal_hub_default_server_drupal_hub' => array(
          'name' => t('Drupal Hub'),
          'url_xmlrpc' => 'http://drupalhub.org/xmlrpc.php',
        ),
      );
  }
}

/**
 * Implementation of hook_xmlrpc().
 */
function drupal_hub_xmlrpc() {
  // TODO
  $xmlrpc = array();
  if (variable_get('drupal_hub_is_server', false)) {
    $xmlrpc += _drupal_hub_server_xmlrpc();
/*    $xmlrpc[] = array(
      'drupal_hub.client.ping',
      'drupal_hub_client_ping',
      array('array', 'array', 'array'),
      t('Handling ping request')
    );
*/
  }
  return $xmlrpc;
// TODO:
  if (variable_get('drupal_hub_is_client', false)) {
    $xmlrpc = _drupal_hub_client_xmlrpc();
/*    $xmlrpc[] = array(
      'drupal.login',
      'drupal_login',
      array('int', 'string', 'string'),
      t('Logging into a Drupal site')
    );*/
  }
  return $xmlrpc;
}