Useful script?

Published October 06, 2005
If you have a website of your own, you might want to have your journal on it. (I do [wink]).
This script can be used to generate a simple HTML document (such as this one!) containing a brief description of your recent entries, a title and a link to the item itself.

<?php# UPDATE_JOURNAL.PHP# Ben Ryves 2005.# CONFIG:$journal_id = 273102;           # ID number of your journal.$items      = 8;                # How many recent journal entries do you want?$saved_page = 'journal.htm';    # Which page do you want to save the journal to?$password   = 'password';       # What's the password required to fire off an update?if (isset($_POST['submit'])) {    if ($_POST['password']==$password) {        # Run the update script:        $url='http://www.gamedev.net/community/forums/lib/rss.asp?mode=journal&jn='.$journal_id;        $handle = fopen($url,'r');        $writer = fopen($saved_page,'w');        if (!$handle) {        	echo "The RSS feed is not available at the moment - sorry.";        } else {        	global $cur_pos, $buffer;        	$buffer = '';        	while (!feof ($handle)) {        		$buffer .= fgets($handle, 4096);        	}        	fclose($handle);        	$cur_pos = strpos($buffer,"<item>");        	for ($i=0; $i<$items; ++$i) {        		$title = get_between_text("<title>","</title>");        		if ($title===false) break;        		$link = get_between_text("<link>","</link>");        		$description = html_entity_decode(preg_replace("#<(.*?)>#i","",get_between_text("<description>","</description>")),ENT_QUOTES);        		$description = preg_replace("#<(.*)#i","...",$description);        		fwrite($writer,"$link\" target=\"_blank\">$title<small>$description</small>");        	}        	fclose($writer);        	echo "$saved_page has been updated!";        	return;        }    } else {        echo "Invalid password: sorry!";        unset($_POST['submit']);    }}?><form method="post">Please enter your password:<input type="password" name="password" /><input type="submit" value="Go!" name="submit" /></form><?phpfunction get_between_text($before, $after) {   global $buffer, $cur_pos;   $cur_pos = strpos($buffer, $before, $cur_pos);   if ($cur_pos===false) {      return false;   } else {      $cur_pos+=strlen($before);      $e = strpos($buffer, $after, $cur_pos);      return substr($buffer, $cur_pos, $e-$cur_pos);   }}?>

You need to set a password just to stop people from running the script (it's a pretty basic system). You'll also need to set the correct ID number. It's a very quick-and-dirty script, so if you have any problems with it give me a shout!
0 likes 1 comments

Comments

Comments are shown oldest first so the discussion reads top to bottom.
Rob Loach
Brilliant! I didn't think of using the GameDev RSS as a method of publishing data on an the site... Good one benny.
October 06, 2005 01:56 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!