| 1 |
<?php |
<?php |
| 2 |
// $Id: atom.module,v 1.10 2004/06/28 05:08:50 dries Exp $ |
// $Id: atom.module,v 1.11 2004/12/05 14:06:12 ax Exp $ |
| 3 |
|
|
| 4 |
function atom_help($section) { |
function atom_help($section) { |
| 5 |
$output = ""; |
$output = ''; |
| 6 |
|
|
| 7 |
switch ($section) { |
switch ($section) { |
| 8 |
case "admin/modules#description": |
case 'admin/modules#description': |
| 9 |
$output = t("Provides an Atom 0.3 feed"); |
$output = t('Provides an Atom 0.3 feed'); |
| 10 |
break; |
break; |
| 11 |
} |
} |
| 12 |
return $output; |
return $output; |
| 14 |
|
|
| 15 |
function atom_menu() { |
function atom_menu() { |
| 16 |
$items = array(); |
$items = array(); |
| 17 |
drupal_set_html_head("<link rel=\"alternate\" type=\"application/atom+xml\" title=\"Atom\" href=\"". url("atom/feed") ."\" />"); |
drupal_set_html_head('<link rel="alternate" type="application/atom+xml" title="Atom" href="'. url('atom/feed', NULL, NULL, TRUE) .'" />'); |
| 18 |
$items[] = array('path' => 'atom/feed', 'title' => t('atom feed'), |
$items[] = array('path' => 'atom/feed', 'title' => t('atom feed'), |
| 19 |
'callback' => 'atom_feed', |
'callback' => 'atom_feed', |
| 20 |
'access' => user_access('access content'), |
'access' => user_access('access content'), |
| 24 |
|
|
| 25 |
function atom_feed() { |
function atom_feed() { |
| 26 |
global $base_url; |
global $base_url; |
| 27 |
$output = ""; |
$output = ''; |
| 28 |
$last_mod = 0; |
$last_mod = 0; |
| 29 |
$nodes = db_query_range("SELECT n.nid, u.uid, u.name FROM {node} n, {users} u WHERE n.uid = u.uid AND n.promote = '1' AND n.status = '1' ORDER BY n.created DESC", 0, 15); |
$nodes = db_query_range("SELECT n.nid, u.uid, u.name FROM {node} n, {users} u WHERE n.uid = u.uid AND n.promote = '1' AND n.status = '1' ORDER BY n.created DESC", 0, 15); |
| 30 |
|
|
| 31 |
while ($node = db_fetch_object($nodes)) { |
while ($node = db_fetch_object($nodes)) { |
| 32 |
$item = node_load(array("nid" => $node->nid)); |
$item = node_load(array('nid' => $node->nid)); |
| 33 |
$link = url("node/$node->nid", NULL, NULL, true); |
$link = url("node/$node->nid", NULL, NULL, true); |
| 34 |
$output .= " <entry>\n"; |
$output .= " <entry>\n"; |
| 35 |
$output .= " <title>". $item->title ."</title>\n"; |
$output .= ' <title>'. $item->title ."</title>\n"; |
| 36 |
$output .= " <link rel=\"alternate\" type=\"text/html\" href=\"". $link ."\" />\n"; |
$output .= ' <link rel="alternate" type="text/html" href="'. $link ."\" />\n"; |
| 37 |
$output .= " <id>$link</id>\n"; |
$output .= " <id>$link</id>\n"; |
| 38 |
$output .= " <issued>". _atom_timestamp2w3dtf($item->created) ."</issued>\n"; |
$output .= ' <issued>'. _atom_timestamp2w3dtf($item->created) ."</issued>\n"; |
| 39 |
$output .= " <modified>". _atom_timestamp2w3dtf($item->changed) ."</modified>\n"; |
$output .= ' <modified>'. _atom_timestamp2w3dtf($item->changed) ."</modified>\n"; |
| 40 |
$last_mod = $item->changed; |
$last_mod = $item->changed; |
| 41 |
$output .= " <author>\n"; |
$output .= " <author>\n"; |
| 42 |
if ($node->name) { |
if ($node->name) { |
| 43 |
$output .= " <name>". $node->name ."</name>\n"; |
$output .= ' <name>'. $node->name ."</name>\n"; |
| 44 |
} |
} |
| 45 |
else { |
else { |
| 46 |
$output .= " <name>". variable_get('anonymous', 'Anonymous') ."</name>\n"; |
$output .= ' <name>'. variable_get('anonymous', 'Anonymous') ."</name>\n"; |
| 47 |
} |
} |
| 48 |
$output .= " </author>\n"; |
$output .= " </author>\n"; |
| 49 |
$output .= " </entry>\n"; |
$output .= " </entry>\n"; |
| 50 |
} |
} |
| 51 |
|
|
| 52 |
header("Content-Type: application/xml"); |
header('Content-Type: application/xml'); |
| 53 |
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
| 54 |
print "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\">\n"; |
print "<feed version=\"0.3\" xmlns=\"http://purl.org/atom/ns#\">\n"; |
| 55 |
print " <title>". variable_get("site_name", "drupal") ." - ". variable_get("site_slogan", "") ."</title>\n"; |
print ' <title>'. variable_get('site_name', 'drupal') .' - '. variable_get('site_slogan', '') ."</title>\n"; |
| 56 |
print " <link rel=\"alternate\" type=\"text/html\" href=\"". $base_url. "\"/>\n"; |
print " <link rel=\"alternate\" type=\"text/html\" href=\"". $base_url. "\"/>\n"; |
| 57 |
print " <modified>". _atom_timestamp2w3dtf($last_mod) ."</modified>\n"; |
print ' <modified>'. _atom_timestamp2w3dtf($last_mod) ."</modified>\n"; |
| 58 |
print $output; |
print $output; |
| 59 |
print "</feed>\n"; |
print "</feed>\n"; |
| 60 |
} |
} |
| 61 |
|
|
| 62 |
function _atom_timestamp2w3dtf($timestamp) { |
function _atom_timestamp2w3dtf($timestamp) { |
| 63 |
$tz = date("O", $timestamp); |
$tz = date('O', $timestamp); |
| 64 |
return date("Y-m-d", $timestamp) ."T". date("H:i:s", $timestamp) . substr($tz, 0, 3) . ":" . substr($tz, 3, 2); |
return date('Y-m-d', $timestamp) .'T'. date('H:i:s', $timestamp) . substr($tz, 0, 3) . ':' . substr($tz, 3, 2); |
| 65 |
} |
} |
| 66 |
|
|
| 67 |
?> |
?> |