Display your last BoxedThought on your website

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
If you don't already know what BoxedThoughts is, check out http://www.boxedthoughts.com. There is a complete explanation under the FAQ on that site, so I won't go into it here.

If you use the site, you may have noticed the XML Metadata feature and wondered what it's for.... Basically, its so web developers can post information about their ThoughtStream on their personal websites. Check out this forum post for more information about the different features of the XML Metadata. http://www.boxedthoughts.com/newspeak/viewtopic.php?t=141

Ok, to the reason for this post... here is a bit of code I wrote a while back that lets you use the XML Metadata and display BoxedThoughts stuff on your site.

PHP:
<?
   // (c) The_Magistrate 2006
   // Usage : bt.php?u=<<YOUR BT USERNUMBER HERE>>
   // or
   // Usage : bt.php?u=<<USERNUMBER>>&i=1
   // This script will retrieve the XHTML version of the last thought of the user specified by 
   // the variable u.
   // If i == 1 then information about the user will be displayed with the thought
  
   $filename = "http://www.boxedthoughts.com/users/".$_GET['u']."/meta/last/xhtml";
   $data = implode("", file($filename));   //  Store the information from the site in an array
   $parser = xml_parser_create();  //  Create a new XML parser to extract the information
   xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
   xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
   xml_parse_into_struct($parser, $data, $values, $tags);
   xml_parser_free($parser);

   $remain = $values[5][value];   // Time remaining in seconds until next post is allowed
   $hours = floor($remain / 3600);  // Change the time remaining into useful hours
   $mins = floor(($remain % 3600) / 60);  // and seconds remaining.

   $username = $values[2][value];  // The username of the BT user
   $URL = $values[3][value];  //  URL to that user's thoughtstream
   $numposts = $values[9][value];  // Number of thoughts by the user

   $title = $values[12][value];  // Title of the last thought
   $class = $values[13][value];  // CSS Class of the last thought
   $style = $values[14][value];  // Border style of the last thought
   $content = $values[15][value];  // Actual thought content
               
   if($_GET['i'] == 1)  // If i is set in the URL, display the information about the user
   {
      echo "<strong>Username</strong> : $username<br />\n"
          ."<strong>Num Posts</strong> : $numposts<br />\n"
          ."<strong>Timeleft</strong> : ".$hours."h ".$mins."m<br /><br />\n";
   }

   // Display the thought
   echo "<div title=\"$title\" id=\"preview\" class=\"$class\" style=\"$style\" onclick=\"javascript:document.location='http://www.boxedthoughts.com/users/".$_GET['u']."'\">$content</div><br />";
?>

This script will only display the last thought of a user in XHTML, I'm pretty sure it'll work for the standard HTML version of the XML Metadata too. As for displaying the entire ThoughtStream, that would require some looping, but shouldn't be too hard. If anyone would like me to take a stab at it, I can hack out a full stream script.
 

lambada

New Member
Messages
2,444
Reaction score
0
Points
0
I'd quite like you to have a stab at doing the looped version.

Although this is very good as it is

Well done. :)
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Nice script, I must say.

Also I like seeing other's code that is clean, efficient, and nicely commented. I like it so much because I always see scripts or snippets of code that are horribly coded, that people show others and try to teach them with. Blahh.. You probably know what I mean. ;)

Just wanted to say that. :)
 
Top