7) [OPTIONAL] A script that can push the latest forum threads.
forum_news.php?datestamp=%NOW%&limit=%LIMIT%Your script has to output the latest N forum threads newer or equal to a datestamp.
The datestamp has to be in the format YYYYmmddhhiiss.
Your query has to be ordered by thread_lastpostdate DESC.
Your output has to print the result in reverse order.
You have to escape : with \: and \n with \\n.
The columns are: threadid::datestamp::boardid::url::nickname::threadname
Click here for an example on the server side<?php
# Validate Args
if (!isset($_GET['datestamp']) || !isset($_GET['limit'])) {
die('Error: Missing arg datestamp or limit.');
}
$limit = (int) $_GET['limit'];
if ($limit > 10 || $limit < 1) {
die('Error: Limit has to be between 1 and 10.');
}
$date = $_GET['datestamp'];
$date = mysql_real_escape_string($date);
if (strlen($date) !== 14) {
die('Error: datestamp has to be 14 chars long.');
}
# Query the threads.
# You might need to convert datestamp into unix timestamp.
#$time = strtotime(sprintf('%s-%s-%s %s:%s:%s', $y, $m, $d, $h, $i, $s));
$query = "SELECT * FROM threads WHERE thread_lastpostdate >= '$date' ORDER BY thread_lastpostdate DESC";
if (false === ($result = mysql_query($query))) {
die('Database error 1');
}
# Fetch all rows
$threads = array();
while (false !== ($row = mysql_fetch_assoc($result)))
{
$threads[] = $row;
}
mysql_free_result($result);
# Reverse the order
$threads = array_reverse($threads);
# Output the data
# Format: threadid::datestamp::groupid::url::nickname::threadname
foreach ($threads as $row)
{
$censor = $row['groupid'] > 0;
echo $row['threadid'];
echo '::';
echo $row['datestamp'];
echo '::';
echo $row['boardid'];
echo '::';
echo escape_csv_like(forum_push_get_url($row, $censor)); # Get url and censor, if desired.
echo '::';
echo escape_csv_like(forum_push_nickname($row, $censor)); # Get nickname and censor if desired.
echo '::';
echo escape_csv_like(forum_push_threadname($row, $censor)); # Print thread title, censored if desired.
echo "\n";
}
function escape_csv_like($string)
{
return str_replace(array(':', "\n"), array('\\:', "\\\n"), $string);
}
Click here for an example on the client side<?php
/**
* This file is part of the Lamb2 IRC Bot.
* @author gizmore
*/
# Date we want to query
$date = GWF_Settings::getSetting('WC_FORUM_DATE', date('YmdH0000'));
# We already know these threads for the current data stored
$known = GWF_Settings::getSetting('WC_FORUM_LAST', ',');
# Set output channel
$server instanceof Lamb_Server;
$channels = $server->getChannels();
$channel = array_shift($channels);
$channel = $channel->getVar('chan_name');
# Query URL
$url = sprintf('http://www.wechall.net/nimda_forum.php?datestamp=%s&limit=5', $date);
if (false === ($content = GWF_HTTP::getFromURL($url))) {
return;
}
# Nothing happened
if ($content === '') {
return '';
}
$latest_date = $date;
$new_known = $known;
$lines = explode("\n", $content);
foreach ($lines as $line)
{
if ('' === ($line = trim($line))) {
continue;
}
# Fetch line
list($threadid, $lastdate, $lock, $url, $username, $title) = explode('::', $line);
# Duplicate output?
if ( ($lastdate === $date) && (strpos($known, ','.$threadid.',') !== false) ) {
continue;
}
# Is it private?
$lock = $lock === '0' ? '' : ' locked';
# does the date change?
if ($latest_date !== $lastdate) {
$latest_date = $lastdate;
$new_known = ',';
}
# Mark this thread as known for this datestamp
$new_known .= $threadid.',';
# Output message
if ($lock === ' locked') {
$server->sendPrivmsg($channel, sprintf('[WeChall-Forum] New%s post: %s', $lock, $url));
} else {
$server->sendPrivmsg($channel, sprintf('[WeChall-Forum] New post by %s in %s: %s', $username, $title, $url));
}
}
# Save state
GWF_Settings::setSetting('WC_FORUM_DATE', $lastdate);
GWF_Settings::setSetting('WC_FORUM_LAST', $new_known);
?>
If you like to, I can implement this script for you, in case you use some known forum software, like phpbb.Meanwhile there are scripts for a very few well known forum softwares available.You can take a look at them in the
gwf3 code repository.