| 1 |
<?php
|
| 2 |
// vim:filetype=php expandtab tabstop=2 softtabstop=2 shiftwidth=2 autoindent smartindent
|
| 3 |
// $Id: tribune.backend.inc,v 1.7 2008/11/28 10:22:53 seeschloss Exp $
|
| 4 |
|
| 5 |
|
| 6 |
/**
|
| 7 |
* Print the XML backend
|
| 8 |
*/
|
| 9 |
function tribune_backend($node, $format) {
|
| 10 |
switch ($format) {
|
| 11 |
case 'xml':
|
| 12 |
header("Content-Type: text/xml");
|
| 13 |
$posts = tribune_get_last_posts($node, $node->tribune_settings['xml_size']);
|
| 14 |
print theme("tribune_xml", $posts, $node);
|
| 15 |
break;
|
| 16 |
case 'rss':
|
| 17 |
header("Content-Type: application/rss+xml");
|
| 18 |
$posts = tribune_get_last_posts($node, $node->tribune_settings['rss_size']);
|
| 19 |
print theme("tribune_rss", $posts, $node);
|
| 20 |
break;
|
| 21 |
}
|
| 22 |
exit();
|
| 23 |
}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Returns the $nb last posts, in XML format
|
| 27 |
* @param nb Number of posts to return (tribune_history_size by default)
|
| 28 |
* @return String containing the posts in an HTML unordered list
|
| 29 |
*/
|
| 30 |
function theme_tribune_xml($posts, $node) {
|
| 31 |
$contents = "<?xml version=\"1.0\" encoding=\"UTF-8\""."?".">\n";
|
| 32 |
$contents .= "<!DOCTYPE board PUBLIC \"C01N C01N !\" \"http://phplop.org/dtd/tribune-1.0.dtd\">\n";
|
| 33 |
|
| 34 |
$timezone = variable_get('date_default_timezone', 0);
|
| 35 |
$tz = "UTC". ($timezone < 0 ? "-" : "+") . round($timezone/3600);
|
| 36 |
$contents .= "<board site=\"". url('node/'. $node->nid, array('absolute' => TRUE)) ."\" timezone=\"". $tz ."\">\n";
|
| 37 |
|
| 38 |
$posts = array_reverse($posts);
|
| 39 |
|
| 40 |
foreach ($posts as $id => $post) {
|
| 41 |
if ($post['moderated'] == 0) {
|
| 42 |
$contents .= theme("tribune_post_xml", $post, $node);
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
$contents .= "</board>\n";
|
| 47 |
|
| 48 |
return $contents;
|
| 49 |
}
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Returns the $nb last posts, in RSS format
|
| 53 |
* @param nb Number of posts to return (tribune_history_size by default)
|
| 54 |
* @return String containing the posts in an HTML unordered list
|
| 55 |
*/
|
| 56 |
function theme_tribune_rss($posts, $node) {
|
| 57 |
$contents = "<?xml version=\"1.0\"?>\n";
|
| 58 |
$contents .= "<rss version=\"2.0\">\n";
|
| 59 |
$contents .= "\t<channel>\n";
|
| 60 |
$contents .= "\t\t<title>".variable_get("site_name", "")."</title>\n";
|
| 61 |
$contents .= "\t\t<link>".url('node'. $node->nid, array('absolute' => TRUE))."</link>\n";
|
| 62 |
$contents .= "\t\t<description>".variable_get("site_slogan", "")."</description>\n";
|
| 63 |
|
| 64 |
$posts = array_reverse($posts, TRUE);
|
| 65 |
|
| 66 |
foreach ($posts as $id => $post) {
|
| 67 |
if ($post['moderated'] == 0) {
|
| 68 |
$contents .= theme("tribune_post_rss", $post, $node);
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
| 72 |
$contents .= "\t</channel>\n";
|
| 73 |
$contents .= "</rss>\n";
|
| 74 |
|
| 75 |
return $contents;
|
| 76 |
}
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Returns a single post, in XML format
|
| 80 |
* @param post Array with the following keys : id, clock, login, info, message
|
| 81 |
*/
|
| 82 |
function theme_tribune_post_xml($post, $node) {
|
| 83 |
$contents = " <post time=\"". $post['clock'] ."\" id=\"". $post['tribune_post_id'] ."\">\n";
|
| 84 |
$contents .= " <info>" . $post['info'] ."</info>\n";
|
| 85 |
$contents .= " <message>". tribune_xml_slip($post['message'], $node) ."</message>\n";
|
| 86 |
$contents .= " <login>" . $post['login'] ."</login>\n";
|
| 87 |
$contents .= " </post>\n";
|
| 88 |
|
| 89 |
return $contents;
|
| 90 |
}
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Returns a single post, in RSS format
|
| 94 |
* @param post Array with the following keys : id, clock, login, info, message
|
| 95 |
*/
|
| 96 |
function theme_tribune_post_rss($post, $node) {
|
| 97 |
$contents = "\t\t<item>\n";
|
| 98 |
$contents .= "\t\t\t<description>". tribune_rss_slip($post['message'], $node) ."</description>\n";
|
| 99 |
$contents .= "\t\t\t<pubDate>". date('r', tribune_date_to_timestamp($post['post_time'])) ."</pubDate>\n";
|
| 100 |
$contents .= "\t\t\t<author>". tribune_rss_slip($post['login'], $node) ." <". tribune_rss_slip($post['login'], $node) ."@null></author>\n";
|
| 101 |
$contents .= "\t\t</item>\n";
|
| 102 |
|
| 103 |
return $contents;
|
| 104 |
}
|
| 105 |
|
| 106 |
function tribune_rss_slip($string, $node) {
|
| 107 |
require_once "tribune.sleep.inc";
|
| 108 |
|
| 109 |
$string = tribune_sleep($string, $node->tribune_settings['max_message_size']);
|
| 110 |
$string = preg_replace('#((https?|ftp|gopher|file|mms|rtsp|rtmp)://.*?)((,|\.|\)|\])?(<| | |"|$))#', '<a href="\1">[url]</a>\3', $string);
|
| 111 |
|
| 112 |
return $string;
|
| 113 |
}
|