235 lines
10 KiB
Plaintext
235 lines
10 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Lets users log in using a Drupal ID and can notify a central server about your site.
|
|
*/
|
|
|
|
/**
|
|
* Implementation of hook_help().
|
|
*/
|
|
function drupal_help($section) {
|
|
switch ($section) {
|
|
case 'admin/help#drupal':
|
|
$output = '<p>'. t('The Drupal module uses the XML-RPC network communication protocol to connect your site with a directory server that maintains a directory of sites. Community leaders who have common interests may wish to be part of a larger community and showing sites in a common directory is a good way to do this.') .'</p>';
|
|
$output .= t('<p>Enabling the drupal module will:</p>
|
|
<ul>
|
|
<li>list your site in a site directory.</li>
|
|
<li>allow members on all sites using the Drupal module to login to your site without registering using their distributed identification and vice versa.</li>
|
|
<li>allow members to login to any other site which uses the Drupal module, using a login name which looks much like an email address for your site: <em>username@example.com</em></li>
|
|
</ul>
|
|
');
|
|
$output .= '<p>'. t('The Drupal module administration page allows you to set the xml-rpc server page. The listing of your site in a site directory will occur shortly after your sites next cron run.') .'</p>';
|
|
$output .= t('<p>You can</p>
|
|
<ul>
|
|
<li>run your cron job at your sites <a href="%file-cron">cron page</a>.</li>
|
|
<li>browse to the <a href="%external-http-www-drupal-org-xmlrpc-php">XML-RPC site directory</a>.</li>
|
|
<li>view your <a href="%file-xmlrpc">XML-RPC page</a>.</li>
|
|
<li>administer Drupal <a href="%admin-settings-drupal">administer >> settings >> drupal</a>.</li>
|
|
</ul>
|
|
', array('%file-cron' => 'cron.php', '%external-http-www-drupal-org-xmlrpc-php' => 'http://www.drupal.org/xmlrpc.php', '%file-xmlrpc' => 'xmlrpc.php', '%admin-settings-drupal' => url('admin/settings/drupal')));
|
|
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%drupal">Drupal page</a>.', array('%drupal' => 'http://www.drupal.org/handbook/modules/drupal/')) .'</p>';
|
|
return $output;
|
|
case 'admin/modules#description':
|
|
return t('Lets users log in using a Drupal ID and can notify a central server about your site.');
|
|
case 'admin/settings/drupal':
|
|
return t('<p>Using this your site can "call home" and add itself to the Drupal directory. If you want it to add itself to a different directory server you can change the <a href="%xml-rpc-setting">Drupal XML-RPC server</a> setting -- but the directory server has to be able to handle Drupal XML. To get all your site information listed, go to the <a href="%site-settings">settings page</a> and set the site name, the e-mail address, the slogan, and the mission statement.</p>', array('%xml-rpc-setting' => url('admin/settings/drupal'), '%site-settings' => url('admin/settings')));
|
|
case 'user/help#drupal':
|
|
return t("<p><a href=\"%Drupal\">Drupal</a> is the name of the software which powers %this-site. There are Drupal web sites all over the world, and many of them share their registration databases so that users may freely login to any Drupal site using a single <strong>Drupal ID</strong>.</p>
|
|
<p>So please feel free to login to your account here at %this-site with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <strong>username</strong>@<em>server</em>. An example of a valid Drupal ID is <strong>mwlily</strong>@<em>www.drupal.org</em>.</p>", array('%Drupal' => 'http://www.drupal.org', '%this-site' => '<em>'. variable_get('site_name', 'this web site') .'</em>'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_settings().
|
|
*/
|
|
function drupal_settings() {
|
|
// Check if all required fields are present for the Drupal directory
|
|
if ((variable_get('site_name', 'drupal') == 'drupal') || (variable_get('site_name', 'drupal') == '')) {
|
|
form_set_error('drupal_directory', t('You must set the name of your site on the <a href="%url">administer » settings</a> page.', array('%url' => url('admin/settings'))));
|
|
}
|
|
else if (variable_get('site_mail', ini_get('sendmail_from')) == '') {
|
|
form_set_error('drupal_directory', t('You must set an e-mail address for your site on the <a href="%url">administer » settings</a> page.', array('%url' => url('admin/settings'))));
|
|
}
|
|
else if (variable_get('site_slogan', '') == '') {
|
|
form_set_error('drupal_directory', t('You must set your site slogan on the <a href="%url">administer » settings</a> page.', array('%url' => url('admin/settings'))));
|
|
}
|
|
else if (variable_get('site_mission', '') == '') {
|
|
form_set_error('drupal_directory', t('You must set your site mission on the <a href="%url">administer » settings</a> page.' , array('%url' => url('admin/settings'))));
|
|
}
|
|
|
|
$form['drupal_server'] = array('#type' => 'textfield', '#title' => t('Drupal XML-RPC server'), '#default_value' => variable_get('drupal_server', 'http://www.drupal.org/xmlrpc.php'), '#description' => t('The URL of your root Drupal XML-RPC server.'));
|
|
|
|
$form['drupal_directory'] = array(
|
|
'#type' => 'radios', '#title' => t('Drupal directory'), '#default_value' => variable_get('drupal_directory', 0),
|
|
'#options' => array(t('Disabled'), t('Enabled')),
|
|
'#description' => t("If enabled, your Drupal site will make itself known to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you must set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"%drupal-xml-rpc\", your web site will get listed on the <a href=\"%drupal-sites\">Drupal sites</a> page. Requires the cron feature to be enabled.", array("%drupal-xml-rpc" => "http://www.drupal.org/xmlrpc.php", "%drupal-sites" => "http://www.drupal.org/drupal-sites/"))
|
|
);
|
|
|
|
return $form;
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_cron(); handles pings to and from the site.
|
|
*/
|
|
function drupal_cron() {
|
|
if (time() - variable_get('drupal_cron_last', 0) > 21600) {
|
|
variable_set('drupal_cron_last', time());
|
|
|
|
// If this site acts as a Drupal XML-RPC server, delete the sites that
|
|
// stopped sending "ping" messages.
|
|
db_query("DELETE FROM {directory} WHERE timestamp < '". (time() - 259200) ."'");
|
|
|
|
// If this site acts as a Drupal XML-RPC client, send a message to the
|
|
// Drupal XML-RPC server.
|
|
if (variable_get('drupal_directory', 0) && variable_get('drupal_server', 0)) {
|
|
drupal_notify(variable_get('drupal_server', ''));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Callback function from drupal_xmlrpc() called when another site pings this one.
|
|
*/
|
|
function drupal_directory_ping($link, $name, $mail, $slogan, $mission) {
|
|
|
|
/*
|
|
** Parse our parameters:
|
|
*/
|
|
|
|
foreach (array('link', 'name', 'mail', 'slogan', 'mission') as $key) {
|
|
$$key = strip_tags($$key);
|
|
}
|
|
|
|
/*
|
|
** Update the data in our database and send back a reply:
|
|
*/
|
|
|
|
if ($link && $name && $mail && $slogan && $mission) {
|
|
db_query("DELETE FROM {directory} WHERE link = '%s' OR mail = '%s'", $link, $mail);
|
|
db_query("INSERT INTO {directory} (link, name, mail, slogan, mission, timestamp) VALUES ('%s', '%s', '%s', '%s', '%s', %d)", $link, $name, $mail, $slogan, $mission, time());
|
|
|
|
watchdog('directory ping', t('Ping from %name (%link).', array('%name' => theme('placeholder', $name), '%link' => theme('placeholder', $link))), WATCHDOG_NOTICE, '<a href="'. check_url($link) .'">view</a>');
|
|
|
|
return 1;
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Formats a list of all sites indexed in the directory.
|
|
*
|
|
* This function may be called from a custom page on sites that are
|
|
* Drupal directory servers.
|
|
*/
|
|
function drupal_directory_page($sort = 'name') {
|
|
$result = db_query('SELECT * FROM {directory} ORDER BY '. $sort);
|
|
|
|
// Note: All fields except the mission are treated as plain-text.
|
|
// The mission is stripped of any HTML tags to keep the output simple and consistent.
|
|
while ($site = db_fetch_object($result)) {
|
|
$output .= '<a href="'. check_url($site->link) .'">'. check_plain($site->name) .'</a> - '. check_plain($site->slogan) .'<div style="padding-left: 20px;">'. strip_tags($site->mission) .'</div><br />';
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_xmlrpc().
|
|
*/
|
|
function drupal_xmlrpc() {
|
|
return array(
|
|
array(
|
|
'drupal.site.ping',
|
|
'drupal_directory_ping',
|
|
array('boolean', 'string', 'string', 'string', 'string', 'string'),
|
|
t('Handling ping request')),
|
|
array(
|
|
'drupal.login',
|
|
'drupal_login',
|
|
array('int', 'string', 'string'),
|
|
t('Logging into a drupal site')));
|
|
}
|
|
|
|
/**
|
|
* Sends a ping to the Drupal directory server.
|
|
*/
|
|
function drupal_notify($server) {
|
|
global $base_url;
|
|
|
|
$result = xmlrpc($server, 'drupal.site.ping', $base_url, variable_get('site_name', ''), variable_get('site_mail', ''), variable_get('site_slogan', ''), variable_get('site_mission', ''));
|
|
|
|
if ($result === FALSE) {
|
|
watchdog('directory ping', t('Failed to notify %server, error code: %errno, error message: %error_msg.', array('%server' => theme('placeholder', $server), '%errno' => theme('placeholder', xmlrpc_errno()), '%error_msg' => theme('placeholder', xmlrpc_error_msg()))), WATCHDOG_WARNING);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_info().
|
|
*/
|
|
function drupal_info($field = 0) {
|
|
$info['name'] = 'Drupal';
|
|
$info['protocol'] = 'XML-RPC';
|
|
|
|
if ($field) {
|
|
return $info[$field];
|
|
}
|
|
else {
|
|
return $info;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_auth().
|
|
*/
|
|
function drupal_auth($username, $password, $server) {
|
|
$result = xmlrpc('http://'. $server .'/xmlrpc.php', 'drupal.login', $username, $password);
|
|
if ($result === FALSE) {
|
|
drupal_set_message(t('Error %code : %message', array('%code' => theme('placeholder', xmlrpc_errno()), '%message' => theme('placeholder', xmlrpc_error_msg()))), 'error');
|
|
}
|
|
else {
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implementation of hook_menu().
|
|
*/
|
|
function drupal_menu($may_cache) {
|
|
$items = array();
|
|
if ($may_cache) {
|
|
$items[] = array('path' => 'drupal', 'title' => t('Drupal'),
|
|
'callback' => 'drupal_page_help', 'access' => TRUE,
|
|
'type' => MENU_SUGGESTED_ITEM);
|
|
}
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Menu callback; print Drupal-authentication-specific information from user/help.
|
|
*/
|
|
function drupal_page_help() {
|
|
return drupal_help('user/help#drupal');
|
|
}
|
|
|
|
/**
|
|
* Callback function from drupal_xmlrpc() for authenticating remote clients.
|
|
*
|
|
* Remote clients are usually other Drupal instances.
|
|
*/
|
|
function drupal_login($username, $password) {
|
|
if ($user = user_load(array('name' => $username, 'pass' => $password, 'status' => 1))) {
|
|
return $user->uid;
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|