drupal/modules/headline.module

315 lines
10 KiB
Plaintext

<?php
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><?php echo path_uri(); ?>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=\"3\">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=edit&id=$backend->id\">edit</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_edit($id) {
$result = db_query("SELECT * FROM channel WHERE id='$id' ORDER BY id");
if ($channel = db_fetch_object($result)) {
$output .= " <FORM ACTION=\"admin.php?mod=headline\" METHOD=\"post\">\n";
$output .= " <INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
$output .= " <P>\n";
$output .= " <B>Site name:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"site\" SIZE=\"50\" VALUE=\"$channel->site\">\n";
$output .= " </P>\n";
$output .= " <P>\n";
$output .= " <B>URL:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"url\" SIZE=\"50\" VALUE=\"$channel->url\">\n";
$output .= " </P>\n";
$output .= " <P>\n";
$output .= " <B>Backend file:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"backend\" SIZE=\"50\" VALUE=\"$channel->file\">\n";
$output .= " </P>\n";
$output .= " <P>\n";
$output .= " <B>Contact information:</B><BR>\n";
$output .= " <INPUT TYPE=\"text\" NAME=\"contact\" SIZE=\"50\" VALUE=\"$channel->contact\">\n";
$output .= " </P>\n";
$output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save backend\">\n";
$output .= " </FORM>\n";
} else {
$output .= "Invalid Channel ID.\n";
}
print $output;
}
function headline_admin_rehash() {
module_rehash_blocks("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 "edit":
headline_admin_edit(check_input($id));
break;
case "delete":
$channel = new backend($id);
$channel->delete();
headline_admin_rehash();
headline_admin_display();
break;
case "help":
headline_help();
break;
case "refresh":
$channel = new backend($id);
$channel->refresh();
headline_admin_display();
break;
case "Add backend":
$channel = new backend(check_input($id), check_input($site), check_input($url), check_input($backend), check_input($contact));
$channel->add();
headline_admin_rehash();
headline_admin_display();
break;
case "Save backend":
$channel = new backend(check_input($id));
$channel->site = $site;
$channel->url = $url;
$channel->file = $backend;
$channel->contact = $contact;
$channel->save();
headline_admin_rehash();
// fall through:
default:
headline_admin_display();
}
}
function headline_export_rdf() {
global $status;
$uri = substr(path_uri(), 0, strlen(path_uri()) - strlen("export/"));
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>". variable_get(site_name, "drupal") ."</title>\n";
print " <link>". $uri ."</link>\n";
print " <description>". variable_get(site_name, "drupal") ."</description>\n";
print "</channel>\n";
$result = db_query("SELECT * FROM node WHERE promote = '1' 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>". $uri ."node.php?id=$node->nid</link>\n";
print "</item>\n";
}
print "</rdf:RDF>\n";
}
function headline_export_rss() {
global $status;
$uri = substr(path_uri(), 0, strlen(path_uri()) - strlen("export/"));
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://purl.org/rss/1.0/\">\n\n";
print "<channel rdf:about=\"". $uri ."export/headlinesRSS10.rdf\">\n";
print " <title>". variable_get(site_name, "drupal") ."</title>\n";
print " <link>". $uri ."</link>\n";
print " <description>". variable_get(site_name, "drupal") ."</description>\n";
print " <items>\n";
print " <rdf:Seq>\n";
$result = db_query("SELECT * FROM node WHERE promote = '1' AND status = '$status[posted]' ORDER BY timestamp DESC LIMIT 10");
while ($node = db_fetch_object($result)) {
print " <rdf:li resource=\"". $uri ."node.php?id=$node->nid\" />\n";
}
print " </rdf:Seq>\n";
print " </items>\n";
print "</channel>\n\n";
$result = db_query("SELECT * FROM node WHERE promote = '1' AND status = '$status[posted]' ORDER BY timestamp DESC LIMIT 10");
while ($node = db_fetch_object($result)) {
print "<item rdf:about=\"". $uri ."node.php?id=$node->nid\">\n";
print " <title>". check_export($node->title) ."</title>\n";
print " <link>". $uri ."node.php?id=$node->nid</link>\n";
if ($node->abstract) print " <description>". check_output($node->abstract, 1) ."</description>\n";
if ($node->body) print " <description>". check_output($node->body, 1) ."</description>\n";
print "</item>\n";
}
print "</rdf:RDF>\n";
}
function headline_export($uri) {
switch ($uri[2]) {
case "headlines.rss":
headline_export_rss();
break;
case "headlines.rdf":
case "default":
headline_export_rdf();
}
}
?>