CD Feed

I was looking through the php script found in the nrg.chaosnet.org repository and was trying to figure out how to access the thread id value so that i could create a link to that specific thread using the url chiefdelphi.com/forums/showthread.php?t=[the desired thread #]. Is this possible? or is there some other way of doing it?

You would have to use an RSS parser I think…

I have one made up that’s going on our new site…if anyone would like, I can post it in the White Papers.

It’s really just a modded version of what Brandon had up here before i beileve…I’d have to look again.

You want the threadid via the XML? … or you want to get it just by browsing?

Here’s some new code that links to the correct CD thread.

Unfortunately, the external.xml that CD provides only gives the thread’s author, not the post’s author. I hope this changed soon :wink:

You can see the following code in action at: http://nrg.chaosnet.org/resource/programming/cdfeed/cdfeed.php

The code is also stored in the repository, as usual…


<?php 
// If you want to use this PHP code, provide credit to 
$cdfeed = "[http://www.chiefdelphi.com/forums/external.php?type=XML](http://www.chiefdelphi.com/forums/external.php?type=XML)"; 
$fp = fopen($cdfeed, "r") or die("<b>Unable read ChiefDelphi feed!</b>
"); 
while(!feof($fp)) 
	{ 
	$xmld = $xmld.fgets($fp, 1024); 
	} 
$open_stack = array(); 
$atts_stack = array(); 
$parser = xml_parser_create(); 
xml_set_element_handler($parser, "start_handler", "end_handler"); 
xml_set_character_data_handler($parser, "character_handler"); 
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING,0); 
xml_parse($parser, $xmld); 
xml_parser_free($parser); 
function start_handler($p, $name, $atts) 
	{ 
	global $open_stack; 
		global $atts_stack; 
	global $cdthreads;
	$open_stack] = array($name,"",$atts); 
		if ($name == "thread"){ 
			   $cdthreads]=array("id"=>$atts'id'],"title"=>"","auth"=>"","time"=>0,"date"=>0);
			   $id=$atts'id'];
			   print "<a href=\"<A href="http://www.chiefdelphi.com/forums/showthread.php?t=$id\">n">http://www.chiefdelphi.com/forums/showthread.php?t=$id\">
"; 
		} 
	} 
function character_handler($p, $txt) 
	{ 
	global $open_stack; 
	$cur_index = count($open_stack)-1; 
	$open_stack$cur_index][1].=$txt; 
	} 
function end_handler($p, $name) 
	{ 
	global $open_stack; 
	$el = array_pop($open_stack); 
		if ($name == "thread"){ 
			   print "</a>
"; 
		} 
	if ($name == "title") 
		{ 
		echo "<b>$el[1]</b><br>"; 
		 $cdthreads[count($cdthreads)-1]'title']=$el[1];
		} 
	if ($name == "author") 
		{ 
		echo "By <i>$el[1]</i>"; 
		 $cdthreads[count($cdthreads)-1]'auth']=$el[1];
		} 
	if ($name == "date") 
		{ 
		echo "On $el[1],"; 
		 $cdthreads[count($cdthreads)-1]'date']=$el[1];
		} 
	if ($name == "time") 
		{ 
		echo " at $el[1]<p>"; 
		 $cdthreads[count($cdthreads)-1]'time']=$el[1];
		} 

	} 
// At this point, all the threads have been printed out if PRINTOUT equaled one
// Also all the threads are stored in $cdthreads associative array.

?> 

Thank you, this is pretty much what I was looking for.