davide101 |
04-06-2006 08:39 PM |
I inspired by Cloud Warrior, I decided it was time to get the latest blog entries on the rest of my site. After an hour of playing around, I have some working code. This code is NOT COMPLETE! You need to manually put in the RDF header information in the code. Please don't try to use it if you aren't comfortable playing with PHP code. If someone wants to fix it up and repost it with an explanation that a noobie could follow, by all means go ahead. My brain is about to quit for the day so I'm not quite up to it.
Added the following section of code to the journal.php file causes journal.php?do=rss will pull the latest entries in RDF format.
Code:
// RSS SUPPORT
if($_REQUEST['do']=='rss')
{
$vbulletin->input->clean_array_gpc('r', array(
'type' => TYPE_STR,
));
// ATTN Compatibility Code
$type =& $vbulletin->GPC['type'];
// ATTN Compatibility Code
require_once(DIR . '/includes/functions_file.php');
// $journalinfo= $db->query_first("SELECT journalist,journalist_id,journalname,journaldesc FROM " . TABLE_PREFIX . "journals");
$getentries= $db->query("SELECT " . TABLE_PREFIX . "journal_entries.entrytitle, " . TABLE_PREFIX . "journal_entries.entrytext, " . TABLE_PREFIX . "journal_entries.entrydate,
" . TABLE_PREFIX . "journal_entries.private, " . TABLE_PREFIX . "journal_entries.entry_id, " . TABLE_PREFIX . "journal_entries.allowedusers, " . TABLE_PREFIX . "journals.journalist FROM
" . TABLE_PREFIX . "journal_entries, " . TABLE_PREFIX . "journals WHERE " . TABLE_PREFIX . "journal_entries.entry_active=1 AND
" . TABLE_PREFIX . "journal_entries.journal_id = " . TABLE_PREFIX . "journals.journal_id ORDER BY entrydate DESC");
require_once('./includes/class_bbcode.php');
$rss1_header .= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n\r\n";
$rss1_header .= "<rdf:RDF\r\n";
$rss1_header .= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\r\n";
$rss1_header .= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\r\n";
$rss1_header .= " xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"\r\n";
$rss1_header .= " xmlns=\"http://purl.org/rss/1.0/\"\r\n";
$rss1_header .= ">\r\n\r\n";
$rss1_header .= "<channel rdf:about=\"".$vbulletin->options['bburl']."/journal.php?do=downloadjournal&j=".$j."&type=rss1\">\r\n";
if ($journalinfo['journalname'] == "") { $journalinfo['journalname'] = $journalinfo['journalist'] . "'s Blog"; }
$rss1_header .= "<title>Diabetes Daily Member Blogs: Recently Updated</title>\r\n";
$rss1_header .= "<link>".$vbulletin->options['bburl']."/journal.php?do=showjournal&j=".$j."</link>\r\n";
if (empty($journalinfo['journaldesc'])) { $journalinfo['journaldesc'] = $journalinfo['journalist']."'s Blog at ".$vbulletin->options['bbtitle']; }
$rss1_header .= "<description>".htmlspecialchars($journalinfo['journaldesc'])."</description>\r\n\r\n";
$rss1_header .= "<items>\r\n";
$rss1_header .= "\t<rdf:Seq>\r\n";
$totalentries = 0;
$previousentry = 0;
while($entry= $db->fetch_array($getentries))
{
if($entry['private']!=1 AND $previousentry != $entry['entry_id'])
{
$totalentries++;
$parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$entry['entrytext'] = $parser->do_parse($entry['entrytext']);
$entry['entrytext']= unhtmlspecialchars(stripslashes($entry['entrytext']));
$entry['entrytext']= ereg_replace("{smilies}", $vbulletin->options['bburl']."/images/smilies", $entry['entrytext']);
$entry_short= substr ( $entry['entrytext'], 0, 200);
$entry['entrytitle']= stripslashes($entry['entrytitle']);
$rss1_header .= "\t\t<rdf:li rdf:resource=\"".$vbulletin->options['bburl']."/journal.php?do=showentry&e=".$entry['entry_id']."\" />\r\n";
$rss1_body .= "\t<item rdf:about=\"".$vbulletin->options['bburl']."/journal.php?do=showentry&e=".$entry['entry_id']."\">\r\n";
$rss1_body .= "\t\t<author>".htmlspecialchars($entry['journalist'])."</author>\r\n";
$rss1_body .= "\t\t<title>".htmlspecialchars($entry['entrytitle'])."</title>\r\n";
$W3CDTFdate = preg_replace("/(\+|\-)([0-9]{2})([0-9]{2})/","$1$2:$3", date("O",$entry['entrydate']));
$rss1_body .= "\t\t<dc:date>".date("Y-m-d",$entry['entrydate'])."T".date("H:i:s",$entry['entrydate']).$W3CDTFdate."</dc:date>\r\n";
$rss1_body .= "\t\t<link>".$vbulletin->options['bburl']."/journal.php?do=showentry&e=".$entry['entry_id']."</link>\r\n";
$rss1_body .= "\t\t<content:encoded><![CDATA[".$entry_short."]]></content:encoded>\r\n";
$rss1_body .= "\t\t<description>".htmlspecialchars(strip_tags($entry_short))."</description>\r\n";
$rss1_body .= "\t</item>\r\n\r\n";
}
$previousentry = $entry['entry_id'];
if($totalentries=="15") { break; }
}
$rss1_header .= "\t</rdf:Seq>\r\n";
$rss1_header .= "</items>\r\n\r\n";
$rss1_header .= "</channel>\r\n\r\n";
$rss1_body .= "</rdf:RDF>";
$filestring = utf8_encode($rss1_header.$rss1_body);
$filename = "$journalinfo[journalist]_blog_".vbdate($vbulletin->options['dateformat'], TIMENOW).'.rdf';
header("Content-Type: application/rdf+xml; charset=utf-8");
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: ' . strlen($filestring));
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo $filestring;
// RSS 1.0 Ends
}
The more I play with this hack, the more I love it!
|