drupal/modules/headline.module

224 lines
7.1 KiB
Plaintext

<?php
$module = array("page" => "headline_page",
"cron" => "headline_cron",
"help" => "headline_help",
"block" => "headline_block",
"admin" => "headline_admin",
"export" => "headline_export");
include_once "includes/common.inc";
include_once "modules/backend.class";
function headline_blocks() {
global $theme;
// Get channel info:
$result = db_query("SELECT * FROM channel ORDER BY id");
$theme->header();
print "<TABLE BORDER=\"0\">\n";
while ($channel = db_fetch_object($result)) {
if ($state % 3 == 0) print " <TR>\n";
print " <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">\n";
// Load backend from database:
$backend = new backend($channel->id);
if ($backend->headlines) {
unset($content);
foreach ($backend->headlines as $headline) $content .= "<LI>$headline</LI>\n";
}
else {
$content = "no headlines available\n";
}
// Print backend box to screen:
$theme->box($backend->site, $content);
print " </TD>\n";
if ($state % 3 == 2) print " </TR>\n";
$state += 1;
}
print "</TABLE>\n";
$theme->footer();
}
function headline_page() {
global $type;
switch($type) {
case "rdf":
headline_rdf();
break;
default:
headline_blocks();
}
}
function headline_cron() {
$result = db_query("SELECT * FROM channel");
while ($channel = db_fetch_object($result)) {
$backend = new Backend($channel->id);
}
}
function headline_help() {
?>
<P>Drupal's headline module both imports and exports RDF/RSS headlines.</P>
<P>A lot of news-oriented websites are now publishing news (headlines) and making their content available through XML, RSS and RDF backend files. They syndicate free content and allow retrieval and further transmission, aggregation, and online publication. In its current state, drupal's headline module supports RDF and RSS backends.</P>
<P>RSS was originally developed by Netscape to allow adding news channels to "My Netscape" sites, but it has since become adopted as the <I>de facto</I> net standard for distributing headlines and brief dynamic texts.</P>
<P>The headline module goes out to a list of configured news sites once an hour or so (driven by cron), downloads new RSS/RDF data and makes it available to your visitors. In addition, your headlines are exported as well and can be retrieved by other sites from <CODE>http://yourdomain.com/export/headlines.rdf</CODE>.</P>
<?php
}
function headline_block() {
$result = db_query("SELECT * FROM channel");
while ($channel = db_fetch_object($result)) {
$backend = new Backend($channel->id);
if ($backend->headlines) {
unset($content);
foreach ($backend->headlines as $headline) {
$content .= "<LI>$headline</LI>\n";
}
}
else {
$content = "no headlines available";
}
$blocks[$channel->id]["subject"] = $backend->site;
$blocks[$channel->id]["content"] = $content;
$blocks[$channel->id]["info"] = "$backend->site headlines";
$blocks[$channel->id]["link"] = $backend->url;
}
return $blocks;
}
function headline_admin_display() {
global $theme;
// Get channel info:
$result = db_query("SELECT * FROM channel ORDER BY id");
$output .= "<TABLE BORDER=\"1\" CELLSPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TH>site</TH><TH>contact</TH><TH>last update</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";
while ($channel = db_fetch_object($result)) {
// Load backend from database:
$backend = new backend($channel->id);
$output .= "<TR>\n";
$output .= " <TD>". format_url($backend->url, $backend->site) ."</TD>\n";
$output .= " <TD>". format_email($backend->contact) ."</TD>\n";
$output .= " <TD ALIGN=\"center\">". ($backend->timestamp == 1 ? "failed" : format_interval(time() - $backend->timestamp) ." ago") ."</TD>\n";
$output .= " <TD ALIGN=\"center\"><A HREF=\"admin.php?mod=headline&op=refresh&id=$backend->id\">refresh</A></TD>\n";
$output .= " <TD ALIGN=\"center\"><A HREF=\"admin.php?mod=headline&op=delete&id=$backend->id\">delete</A></TD>\n";
$output .= "</TR>\n";
}
$output .= "</TABLE>\n";
print $output;
}
function headline_admin_add() {
$output .= " <FORM ACTION=\"admin.php?mod=headline\" METHOD=\"post\">\n";
$output .= " <P>\n";
$output .= " <B>Site name:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"site\" SIZE=\"50\">\n";
$output .= " </P>\n";
$output .= " <P>\n";
$output .= " <B>URL:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"url\" SIZE=\"50\">\n";
$output .= " </P>\n";
$output .= " <P>\n";
$output .= " <B>Backend file:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"backend\" SIZE=\"50\">\n";
$output .= " </P>\n";
$output .= " <P>\n";
$output .= " <B>Contact information:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"contact\" SIZE=\"50\">\n";
$output .= " </P>\n";
$output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Add backend\">\n";
$output .= " </FORM>\n";
print $output;
}
function headline_admin_rehash() {
global $repository;
module_rehash_blocks("headline", $repository["headline"]);
}
function headline_admin() {
global $op, $id, $site, $url, $backend, $contact;
print "<SMALL><A HREF=\"admin.php?mod=headline&op=add\">add new channel</A> | <A HREF=\"admin.php?mod=headline\">overview</A> | <A HREF=\"admin.php?mod=headline&op=help\">help</A></SMALL><HR>";
switch($op) {
case "add":
headline_admin_add();
break;
case "delete":
$backend = new backend($id);
$backend->delete();
headline_admin_rehash();
headline_admin_display();
break;
case "help":
headline_help();
break;
case "refresh":
$backend = new backend($id);
$backend->refresh();
headline_admin_display();
break;
case "Add backend":
$backend = new backend($id, $site, $url, $backend, $contact);
$backend->add();
headline_admin_rehash();
// fall through:
default:
headline_admin_display();
}
}
function headline_export($uri) {
global $site_name, $site_url, $status, $HTTP_REFERER, $HTTP_USER_AGENT;
if ($uri[1] == "headlines.rdf") {
watchdog("message", "grabbed 'headlines.rdf' - referring url: $HTTP_REFERER - user agent: $HTTP_USER_AGENT");
header("Content-Type: text/plain");
print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
print "<rdf:RDF\n";
print " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
print " xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">\n";
print "<channel>\n";
print " <title>$site_name</title>\n";
print " <link>$site_url</link>\n";
print " <description>$site_name</description>\n";
print "</channel>\n";
$result = db_query("SELECT * FROM node WHERE type = 'story' AND status = '$status[posted]' ORDER BY timestamp DESC LIMIT 10");
while ($node = db_fetch_object($result)) {
print "<item>\n";
print " <title>". check_export($node->title) ."</title>\n";
print " <link>". $site_url ."node.php?id=$node->nid</link>\n";
print "</item>\n";
}
print "</rdf:RDF>\n";
}
}
?>