drupal/modules/drupal.module

195 lines
8.1 KiB
Plaintext
Raw Normal View History

<?php
2002-11-07 18:25:01 +00:00
// $Id$
function drupal_help_directory() {
?>
<p>The "drupal" module features a capability whereby other drupal sites may <i>call home</i> to report their existence. In turn, this enables a pod of Drupal sites to find, cooperate and advertise each other.</p>
2003-01-06 19:51:01 +00:00
<p>Currently, the main application of this feature is the <a href="http://www.drupal.org/node/view/3">Drupal sites page</a>. By default, fresh Drupal installations can use <a href="http://www.drupal.org/">drupal.org</a> as their <i>directory server</i> and report their existence. This reporting occurs via scheduled <a href="http://www.xmlrpc.com/">XML-RPC</a> pings.</p>
<p>Drupal administrators should simply enable this feature to get listed on the <a href="http://www.drupal.org/node/view/3">Drupal sites page</a>; just set your site's name, e-mail address, slogan and mission statement. Then make sure that the field called <i>Drupal XML-RPC server</i> on the <i>site settings</i> tab of the <i>site configuration</i> page is set to http://www.drupal.org/xmlrpc.php. Also, make sure you enable this feature using the checkbox directly below.</p>
<p>The listing of your site will occur shortly after your site's next ". l("cron run", "admin/system/help") .". Note that cron.php should be called using the domain name which you want to have listed at <a href="http://www.drupal.org/">drupal.org</a>. For example, don't kick off cron by requesting http://127.0.0.1/cron.php. Instead, use a publicly accessible domain name such as http:// www.mydomain.org/cron.php.</p>
<p>Also note that your installation need not use drupal.org as its directory server. For example, this feature is perfectly capable of aggregating pings from all of your departmental drupal installations sites within an enterprise.</p>
<?php
}
function drupal_help() {
drupal_help_directory();
}
function drupal_system($field) {
$system["description"] = t("Lets users log in using a Drupal ID and can notify drupal.org about your site.");
return $system[$field];
}
function drupal_settings() {
2002-06-08 10:09:03 +00:00
$output .= form_textfield("Drupal XML-RPC server", "drupal_server", variable_get("drupal_server", "http://www.drupal.org/xmlrpc.php"), 55, 128, "The URL of your root Drupal XML-RPC server.");
$output .= form_select("Drupal directory", "drupal_directory", variable_get("drupal_directory", 0), array("Disabled", "Enabled"), "If enabled, your Drupal site will make itself know to the Drupal directory at the specified Drupal XML-RPC server. For this to work properly, you have to set your site's name, e-mail address, slogan and mission statement. When the \"Drupal XML-RPC server\" field is set to \"http://www.drupal.org/xmlrpc.php\", your website will get listed on <a href=\"http://www.drupal.org/\">http://www.drupal.org/</a>. Requires crontab.");
return $output;
}
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", ""));
}
}
}
function drupal_directory_ping($arguments) {
/*
** Parse our parameters:
*/
$argument = $arguments->getparam(0);
$link = strip_tags($argument->scalarval());
$argument = $arguments->getparam(1);
$name = strip_tags($argument->scalarval());
$argument = $arguments->getparam(2);
$mail = strip_tags($argument->scalarval());
$argument = $arguments->getparam(3);
$slogan = strip_tags($argument->scalarval());
$argument = $arguments->getparam(4);
$mission = strip_tags($argument->scalarval());
/*
** 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', '%s')", $link, $name, $mail, $slogan, $mission, time());
watchdog("message", "directory: ping from '$name' ($link)");
return new xmlrpcresp(new xmlrpcval(1, "int"));
}
else {
return new xmlrpcresp(new xmlrpcval(0, "int"));
}
}
function drupal_directory_page() {
$result = db_query("SELECT * FROM directory ORDER BY name");
while ($site = db_fetch_object($result)) {
$output .= "<a href=\"$site->link\">$site->name</a> - $site->slogan<div style=\"padding-left: 20px;\">$site->mission</div><br />";
}
return $output;
}
function drupal_xmlrpc() {
return array("drupal.site.ping" => array("function" => "drupal_directory_ping"), "drupal.login" => array("function" => "drupal_login"));
}
function drupal_notify($server) {
$url = parse_url($server);
$client = new xmlrpc_client($url["path"], $url["host"], 80);
$message = new xmlrpcmsg("drupal.site.ping", array(new xmlrpcval(path_uri(), "string"), new xmlrpcval(variable_get("site_name", ""), "string"), new xmlrpcval(variable_get("site_mail", ""), "string"), new xmlrpcval(variable_get("site_slogan", ""), "string"), new xmlrpcval(variable_get("site_mission", ""), "string")));
$result = $client->send($message, 5);
if (!$result || $result->faultCode()) {
watchdog("error", "failed to notify '". $url["host"] ."' at '". $url["path"] ."': ". $result->faultString());
}
}
function drupal_info($field = 0) {
$info["name"] = "Drupal";
$info["protocol"] = "XML-RPC";
if ($field) {
return $info[$field];
}
else {
return $info;
}
}
function drupal_auth($username, $password, $server) {
$message = new xmlrpcmsg("drupal.login", array(new xmlrpcval($username, "string"), new xmlrpcval($password, "string")));
// TODO remove hard coded Port 80
// TODO manage server/path such that HTTP_HOST/xml.rpc.php is not assumed
$client = new xmlrpc_client("/xmlrpc.php", $server, 80);
$result = $client->send($message, 5);
if ($result && !$result->faultCode()) {
$value = $result->value();
$login = $value->scalarval();
}
return $login;
}
function drupal_page() {
global $theme;
$theme->header();
$theme->box("Drupal", drupal_auth_help());
$theme->footer();
}
function drupal_login($arguments) {
// an XML-RPC method called by external clients (usually other Drupal instances)
$argument = $arguments->getparam(0);
$username = $argument->scalarval();
$argument = $arguments->getparam(1);
$password = $argument->scalarval();
if ($user = user_load(array(name => "$username", "pass" => $password, "status" => 1))) {
return new xmlrpcresp(new xmlrpcval($user->uid, "int"));
}
else {
return new xmlrpcresp(new xmlrpcval(0, "int"));
}
}
function drupal_auth_help() {
$site = variable_get("site_name", "this web site");
$output = "<p><a href=\"http://www.drupal.org\">Drupal</a> is the name of the software which powers %s. There are Drupal websites 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 <b>Drupal ID</b>.</p>\n";
$output .= "<p>So please feel free to login to your account here at %s with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <b>username</b>@<i>server</i>. An example of valid Drupal ID is <b>mwlily</b><i>@www.drupal.org</i>.</p>";
return t($output, array("%s" => "<i>$site</i>"));
}
function drupal_user($type, $edit, $user) {
global $HTTP_HOST;
$module = "drupal";
$name = module_invoke($module, "info", "name");
switch ($type) {
case "view_private":
$result = user_get_authname($user, $module);
if ($result) {
$output .= form_item(t("$name ID"), $result);
}
else {
// TODO: use a variation of path_uri() instead of $HTTP_HOST below
$output .= form_item(t("$name ID"), "$user->name@$HTTP_HOST");
}
return $output;
}
}
?>