Commit 917ed3c4 authored by aaronwinborn's avatar aaronwinborn

this used to be hub.module, with some minor improvements. still in development.

parents
This diff is collapsed.
; $Id$
name = "Drupal Hub"
description = "Provides API for servers to act as portals to other sites, and/or as xml clients to other portal hubs."
version = "$Name$"
dependencies = content
package = Drupal Hub
\ No newline at end of file
<?php
// $Id$
function drupal_hub_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("
CREATE TABLE {drupal_hub_types} (
type varchar(32) NOT NULL default '',
hub longtext,
PRIMARY KEY (type)
) /*!40100 DEFAULT CHARACTER SET utf8 */;
");
break;
case 'pgsql':
db_query("
CREATE TABLE {drupal_hub_types} (
type varchar(32) NOT NULL default '',
hub text NUT NULL,
PRIMARY KEY (type)
);
");
db_query("CREATE INDEX {drupal_hub_types}_type_idx ON {drupal_hub_types}(type);");
break;
}
}
<?php
// $Id$
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;
}
<?php
// $Id$
function drupal_hub_client_admin_settings() {
$form = array();
// Allow the admin to turn on or off all services offered by various Hub modules on the server.
$form['servers'] = array(
'#type' => 'fieldset',
'#title' => t('Known Drupal Hub Servers'),
'#description' => t('This is a list of known Drupal Hub Servers, and their last known status. You may add or delete a listing with them from here. Once you\'ve added and submitted the form, you may configure a server below.'),
'#collapsible' => true,
'#collapsed' => false,
);
$servers = module_invoke_all('hubapi', 'server defaults');
foreach ($servers as $server => $info) {
$form['servers'][$server] = array(
'#type' => 'checkbox',
'#title' => $info['name'],
'#description' => xmlrpc($info['url_xmlrpc'], 'drupal_hub.server.info'),
'#default_value' => variable_get($server, false),
);
if (variable_get($server, false)) {
$form['config_' . $server] = array(
'#type' => 'fieldset',
'#title' => t('@name Configuration Options', array('@name' => $info['name'])),
'#collapsible' => true,
'#collapsed' => false,
);
$types = xmlrpc($info['url_xmlrpc'], 'drupal_hub.server.register.info');
foreach($types as $type) {
$form['config_' . $server][$server . '_type_' . $type['type']] = array(
'#type' => 'checkbox',
'#title' => $type['name'],
'#description' => $type['description'],
'#default_value' => variable_get($server . '_type_' . $type['type'], false),
);
}
}
}
return system_settings_form($form);
}
<?php
// $Id$
function drupal_hub_server_admin_settings() {
$form = array();
// Allow the admin to turn on or off all services offered by various Hub modules on the server.
$form['cck'] = array(
'#type' => 'fieldset',
'#title' => t('Content Types'),
'#collapsible' => true,
'#collapsed' => false,
);
$form['cck']['current'] = array(
'#type' => 'fieldset',
'#title' => t('Current Hub Listing Types'),
'#description' => t('The following content types have been set to store Hub client listings. You may configure them individually below.'),
'#collapsible' => true,
'#collapsed' => false,
);
$types = drupal_hub_server_type_load();
if (empty($types)) {
$form['cck']['current']['#description'] = t('No content types are currently configured to store Hub client listings. You may select one or more content types from below.');
}
$cck = content_types();
$defaults = array(0 => t('(No Automatic Value)'));
$defaults += module_invoke_all('hubapi', 'field defaults');
foreach ($types as $type) {
$form['cck']['current']['drupal_hub_server_type_' . $type['type']] = array(
'#type' => 'fieldset',
'#title' => $type['name'],
'#description' => $type['description'],
'#collapsible' => true,
'#collapsed' => false,
);
$form['cck']['current']['drupal_hub_server_type_' . $type['type']]['auto'] = array(
'#type' => 'fieldset',
'#title' => t('Automatic Values'),
'#description' => t('Please select the automatic values for each desired field here. When an automatic value has been selected, the client site will automatically enter its corresponding value of the appropriate variable.'),
'#collapsible' => true,
'#collapsed' => true,
);
if ($type['has_title']) {
$form['cck']['current']['drupal_hub_server_type_' . $type['type']]['auto']['drupal_hub_server_' . $type['type'] . '_auto_title'] = array(
'#type' => 'select',
'#title' => $type['title_label'],
'#options' => $defaults,
'#default_value' => variable_get('drupal_hub_server_' . $type['type'] . '_auto_title', 'v:site_name'),
);
}
if ($type['has_body']) {
$form['cck']['current']['drupal_hub_server_type_' . $type['type']]['auto']['drupal_hub_server_' . $type['type'] . '_auto_body'] = array(
'#type' => 'select',
'#title' => $type['body_label'],
'#options' => $defaults,
'#default_value' => variable_get('drupal_hub_server_' . $type['type'] . '_auto_body', 'v:site_mission'),
);
}
foreach($type['fields'] as $field) {
$form['cck']['current']['drupal_hub_server_type_' . $type['type']]['auto']['drupal_hub_server_' . $type['type'] . '_auto_' . $field['field_name']] = array(
'#type' => 'select',
'#title' => $field['widget']['label'],
'#options' => $defaults,
'#default_value' => variable_get('drupal_hub_server_' . $type['type'] . '_auto_' . $field['field_name'], '0'),
);
}
}
$options = array();
foreach ($cck as $type) {
$options[$type['type']] = $type['name'];
}
$form['cck']['drupal_hub_server_cck_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Add Hub Listing Types'),
'#options' => $options,
'#default_value' => variable_get('drupal_hub_server_cck_types', array()),
'#description' => t('To enable a content type as a Hub listing type, check the box for the type and hit submit. You will then be able to modify its specific settings above. Likewise, to remove a type, uncheck the box and submit. It will then be removed from the listings above.'),
);
return system_settings_form($form);
}
function drupal_hub_server_type_load($type_name = NULL) {
static $types = array();
if (empty($types)) {
$drupal_hub_types = variable_get('drupal_hub_server_cck_types', array());
foreach ($drupal_hub_types as $type => $value) {
if ($value) {
$cck_type = content_types($value);
$types[$cck_type['type']] = $cck_type;
}
}
}
if ($type_name) {
return $types[$type_name];
}
return $types;
}
/**
* This is called by a client hub as an xmlrpc to request registration info.
* The server will respond with an xmlrpc message to the client with the appropriate info.
*/
function _drupal_hub_server_test($bool) {
if ($bool) { $output = 'true'; } else { $output = 'false'; }
return $output . t(' testing drupal_hub_server_register_request');
}
/**
* This returns the Hub server's info, in response to a ping from client servers
* wishing to list basic information about why they should register with a particular
* Hub server.
*/
function _drupal_hub_server_info() {
return variable_get('drupal_hub_server_info', variable_get('site_mission', ''));
}
/**
* This xml function will return the descriptions of the cck listing types
*/
function _drupal_hub_server_register_info() {
return drupal_hub_server_type_load();
}
/**
* Implementation of hook_xmlrpc().
* call like:
* $url = 'http://drupalhub.org/xmlrpc.php';
* $xml = xmlrpc($url, 'hub.server.register.request', $arg1, $arg2, ..., $argN);
*/
function _drupal_hub_server_xmlrpc() {
// TODO
$xmlrpc = array();
$xmlrpc[] = array(
'hub.server.test',
'_drupal_hub_server_test',
array('string', 'boolean'), // array($return_value_type, $arg1, $arg2, ..., $argN);
t('Test Hub server'),
);
$xmlrpc[] = array(
'hub.server.info',
'_drupal_hub_server_info',
array('string'),
t('Request Hub server\'s info'),
);
$xmlrpc[] = array(
'hub.server.register.info',
'_drupal_hub_server_register_info',
array('struct'),
t('Request Hub server\'s info'),
);
/* $xmlrpc[] = array(
'drupal.login',
'drupal_login',
array('int', 'string', 'string'),
t('Logging into a Drupal site')
);*/
return $xmlrpc;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment