function generate_rss_feeds($clear='') {
global $config, $ubbt_lang, $dbh, $html, $smarty;
$now = time();
$clear_clause = "";
if ($clear) $clear_clause = "or 1";
// Lock everything that needs to be rebuilt
$query = "
update {$config['TABLE_PREFIX']}RSS_FEEDS
set FEED_LOCK = '$now'
where FEED_IS_ACTIVE = 1 AND
(($now - FEED_LAST_BUILD > FEED_CACHE_TIME) AND
(FEED_LOCK = '0' OR (FEED_LOCK > 0 AND ($now - FEED_LOCK > 120)))
$clear_clause)
";
$dbh->do_query($query,__LINE__,__FILE__);
// Grab the feeds that need to be rebuilt
// anything with a lock time of now or that has been locked for over
// 2 minutes
$query = "
select FEED_ID,FEED_FORUM,FEED_FORUM_ARRAY,FEED_NAME,FEED_TYPE,FEED_INCLUDE_BODY,FEED_ITEMS,FEED_LAST_BUILD,FEED_IS_MULTI
from {$config['TABLE_PREFIX']}RSS_FEEDS
where FEED_IS_ACTIVE = 1
and (($now - FEED_LAST_BUILD > FEED_CACHE_TIME
and (FEED_LOCK = '$now' or (FEED_LOCK > 0 and ($now - FEED_LOCK > 120))))
$clear_clause)
order by FEED_ID
";
$sth_islands = $dbh->do_query($query,__LINE__,__FILE__);
while(list($feed_id,$feed_forum,$forum_array,$feed_name,$feed_type,$feed_include_body,$feed_items,$feed_last_build,$multi) = $dbh->fetch_array($sth_islands)) {
// Querying 1 or multiple forums?
$feed_xml_file = "rss$feed_forum.xml";
// LISA ADDITION - WANT TO SAVE OUT AS A TABLE
$lisa_ci_file = "ci$feed_forum.js";
$clause = "";
$t1clause = "";
if ($multi) {
$feed_xml_file = "global_rss$feed_id.xml";
$sources = unserialize($forum_array);
$inlist = "";
foreach($sources as $k => $v) {
if ($v == "allforums") {
$inlist = "";
continue;
} else {
$inlist .= "'$v',";
} // end if
}
if ($inlist) {
$inlist = preg_replace("/,$/","",$inlist);
$t1clause = "AND t1.FORUM_ID in ($inlist)";
}
} else {
$t1clause = "AND t1.FORUM_ID = '$feed_forum'";
} // end if
// Topics or Posts?
if ($feed_type == "topics") {
$order = "TOPIC_CREATED_TIME desc";
} else {
$order = "TOPIC_LAST_REPLY_TIME desc";
} // end if
if (!$feed_include_body) {
$query = "
select t1.TOPIC_ID,t1.POST_ID,t1.TOPIC_SUBJECT,t1.TOPIC_CREATED_TIME,t1.TOPIC_LAST_REPLY_TIME,t1.TOPIC_LAST_POST_ID,t1.TOPIC_LAST_POSTER_ID,t1.TOPIC_LAST_POSTER_NAME,t2.USER_DISPLAY_NAME
from {$config['TABLE_PREFIX']}TOPICS as t1,
{$config['TABLE_PREFIX']}USERS as t2
where t1.TOPIC_IS_APPROVED = '1'
and t1.USER_ID = t2.USER_ID
$t1clause
ORDER BY t1.$order
limit $feed_items
";
} else {
$query = "
select t1.TOPIC_ID,t1.POST_ID,t1.TOPIC_SUBJECT,t1.TOPIC_CREATED_TIME,t1.TOPIC_LAST_REPLY_TIME,t1.TOPIC_LAST_POST_ID,t1.TOPIC_LAST_POSTER_ID,t1.TOPIC_LAST_POSTER_NAME,t2.POST_DEFAULT_BODY,t3.USER_DISPLAY_NAME
from {$config['TABLE_PREFIX']}TOPICS as t1,
{$config['TABLE_PREFIX']}POSTS as t2,
{$config['TABLE_PREFIX']}USERS as t3
where t1.TOPIC_LAST_POST_ID = t2.POST_ID
and t2.USER_ID = t3.USER_ID
$t1clause
and t2.POST_IS_APPROVED = '1'
ORDER BY t1.$order
limit $feed_items
";
}
$sth = $dbh->do_query($query,__LINE__,__FILE__);
$items = array();
$latest = 0;
while($posts = $dbh->fetch_array($sth)) {
if ($posts['TOPIC_LAST_REPLY_TIME'] > $latest) {
$latest = $posts['TOPIC_LAST_REPLY_TIME'];
}
$posts['TOPIC_SUBJECT'] = htmlspecialchars($posts['TOPIC_SUBJECT']);
if (isset($posts['POST_DEFAULT_BODY'])) {
$posts['POST_DEFAULT_BODY'] = htmlspecialchars(substr(strip_tags($posts['POST_DEFAULT_BODY']),0,$feed_include_body));
if ($feed_type == "posts") {
$posts['TOPIC_SUBJECT'] = "Re: {$posts['TOPIC_SUBJECT']}";
} // end if
} // end if
if ($feed_type == "topics") {
$posts['TOPIC_LAST_REPLY_TIME'] = $posts['TOPIC_CREATED_TIME'];
$posts['TOPIC_LAST_POSTER_NAME'] = $posts['USER_DISPLAY_NAME'];
$posts['TOPIC_LAST_POST_ID'] = $posts['POST_ID'];
} // end if
$posts['TOPIC_LAST_REPLY_TIME'] = $html->convert_time($posts['TOPIC_LAST_REPLY_TIME'],0,"rss",1,0);
$items[] = $posts;
} // end while
if ($latest <= ($feed_last_build + ($config['SERVER_TIME_OFFSET'] * 3600)) && !$clear) {
continue;
} // end if
$smarty->assign_by_ref("items",$items);
$smarty->assign("generated_on",$html->convert_time($now,0,"rss",1,0));
$smarty->assign("feed_name",htmlspecialchars($feed_name));
$rss_data = $smarty->fetch("rss_xml.tpl");
//LISA ADDITION - GET MY CUSTOM TEMPLATE
$lisa_data = $smarty->fetch("lisa_contisl.tpl");
lock_and_write("{$config['FULL_PATH']}/cache/$feed_xml_file",$rss_data);
//LISA ADDITION - WRITE OUT CONTENT ISLAND FILE
lock_and_write("{$config['FULL_PATH']}/cache/$lisa_ci_file",$lisa_data);
} // end while
// Unlock everything
$query = "
update {$config['TABLE_PREFIX']}RSS_FEEDS
set FEED_LAST_BUILD = '$now',
FEED_LOCK = '0'
where FEED_IS_ACTIVE = '1'
and (FEED_LOCK = '$now' or (FEED_LOCK > 0 and ($now - FEED_LOCK > 120)))
$clear_clause
";
$dbh->do_query($query,__LINE__,__FILE__);
} // end function generate_rss_feeds