Useful script?

Published October 06, 2005
Advertisement
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.

# 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,"");        	for ($i=0; $i<$items; ++$i) {        		$title = get_between_text("","
");
if ($title===false) break;
$link = get_between_text("","");
$description = html_entity_decode(preg_replace("#<(.*?)>#i","",get_between_text("","")),ENT_QUOTES);
$description = preg_replace("#<(.*)#i","...",$description);
fwrite($writer,"

$link\" target=\"_blank\">$title
$description

"
);
}
fclose($writer);
echo "

$saved_page has been updated!

"
;
return;
}
} else {
echo "

Invalid password: sorry!

"
;
unset($_POST['submit']);
}
}

?>
"post">

Please enter your password:
"password"

name="password" />
"submit" value="Go!" name="submit" />




function 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

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!
Advertisement