Welcome to all phpBB2 Refugees!This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area. |
|
Author |
Message |
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Tue Jun 02, 2009 3:39 pm Post subject: Problems with RSS Mod for PHPBB2 |
|
|
We had for a long time the RSS Mod 2.2.4
http://www.phpbb.com/community/viewtopic.php?t=254606
installed on our site. As our site grew we found that the load that this mod was putting on our site was too much and have since temporaily disabled it. There are two main problems that we have determined were causing this.
1. The caching of this mod (it is supposed to put a cache file in the cache directory) never worked. The directory permissions are set correctly (we use it with Extreme Styles)
2. The main query takes entirely too long even when setting very low limits on the amount of posts to fetch. Since our site is at the 20,000,000 (million) post mark, this query obviously is the main problem
This is the code from RSS.php which is where all the "magic" is supposed to happen
Code: |
<?php
/***************************************************************************
* rss.php
* -------------------
* begin : Sat, October 23, 2004
* copyright : (c) 2004-2005, Egor Naklonyaeff
* email : chyduskam@naklon.info
* more info : http://naklon.info/rss/about.htm
*
* $Id: rss.php,v 2.2.4 2005/11/23 21:15:00 chyduskam Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
****************************************************************************/
define ('IN_PHPBB', true);
$phpbb_root_path = './';
$ProgName='RSS Feed 2.2.4';
$verinfo='V224';
//
// BEGIN Includes of phpBB scripts
//
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
include($phpbb_root_path . 'includes/rss_config.'.$phpEx);
include($phpbb_root_path . 'includes/rss_functions.'.$phpEx);
if(!SMARTOR_STATS) {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
}
//
// END Includes of phpBB scripts
//
if(!defined('PAGE_RSS')) define('PAGE_RSS', PAGE_INDEX);
$deadline=0;
if(isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']))
{
$deadline=strtotime($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']);
if(CACHE_TIME>0) if((time()-$deadline)<CACHE_TIME)
{
ExitWithHeader("304 Not Modified");
}
}
$sql= "SELECT MAX(post_time) as pt FROM ". POSTS_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
ExitWithHeader("500 Internal Server Error","Error in obtaining post data");
}
if( $row = $db->sql_fetchrow($result) )
{
if($row['pt']<=$deadline) ExitWithHeader("304 Not Modified");
$deadline=$row['pt'];
}
// BEGIN Cache Mod
$use_cached=false;
$cache_file ='';
if(CACHE_TO_FILE and CACHE_TIME>0) {
$cache_file =$phpbb_root_path.$cache_root.$cache_filename;
if($cache_root!='' and empty($HTTP_GET_VARS))
{
$cachefiletime=@filemtime($cache_file);
$timedif = ($deadline - $cachefiletime);
if ($timedif < CACHE_TIME and filesize($cache_file)>0) $use_cached=true;
}
}
// END Cache Mod
//
// gzip_compression
//
$do_gzip_compress = FALSE;
$useragent = (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) ? $HTTP_SERVER_VARS['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT');
if($use_cached && AUTOSTYLED and strpos($useragent,'MSIE'))$use_cached=false;
if ( $board_config['gzip_compress'] )
{
$phpver = phpversion();
if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
{
if ( extension_loaded('zlib') )
{
ob_start('ob_gzhandler');
}
}
else if ( $phpver > '4.0' )
{
if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
{
if ( extension_loaded('zlib') )
{
$do_gzip_compress = TRUE;
ob_start();
ob_implicit_flush(0);
header('Content-Encoding: gzip');
}
}
}
}
// end gzip block
// How many posts do you want to returnd (count)? Specified in the URL with "c=". Defaults to 25, upper limit of 50.
$count = ( isset($HTTP_GET_VARS['c']) ) ? intval($HTTP_GET_VARS['c']) : DEFAULT_ITEMS;
$count = ( $count == 0 ) ? DEFAULT_ITEMS : $count;
$count = ( $count > MAX_ITEMS ) ? MAX_ITEMS : $count;
// Which forum do you want posts from (forum_id)? specified in the url with "f=". Defaults to all (public) forums.
$forum_id = ( isset($HTTP_GET_VARS['f']) ) ? intval($HTTP_GET_VARS['f']) : '';
$forum_id = ( $forum_id == 0 ) ? 9 : $forum_id;
$no_limit=( isset($HTTP_GET_VARS['nolimit']) ) ? true : false;
$needlogin=( isset($HTTP_GET_VARS['login']) or isset($HTTP_GET_VARS['uid'])) ? true : false;
$sql_forum_where = ( !empty($forum_id) ) ? ' AND f.forum_id = ' . $forum_id : ' ';
// Return topics only, or all posts? Specified in the URL with "t=". Defaults to all posts (0).
$topics_only = (isset($HTTP_GET_VARS['t']) ) ? intval($HTTP_GET_VARS['t']) : 0;
$topics_view = (isset($HTTP_GET_VARS['topic']) ) ? intval($HTTP_GET_VARS['topic']) : 0;
$sql_topics_only_where = '';
if ( $topics_only == 1 )
{
$sql_topics_only_where = 'AND p.post_id = t.topic_first_post_id';
}
if($topics_view != 0)
{
$sql_topic_view = 'AND t.topic_id ='.$topics_view;
}
//
// BEGIN Session management
//
// Check user
$user_id=($needlogin)? rss_get_user() : ANONYMOUS;
if($user_id==ANONYMOUS && AUTOLOGIN)
{
$userdata = session_pagestart($user_ip, PAGE_RSS);
$user_id=$userdata["user_id"];
}
else $userdata=rss_session_begin($user_id, $user_ip, PAGE_RSS);
init_userprefs($userdata);
$username=$userdata["username"];
//
// END session management
//
// BEGIN Cache Mod
if($user_id==ANONYMOUS && $use_cached) {
$MyETag='"RSS'.gmdate("YmdHis", $cachefiletime).$verinfo.'"';
$MyGMTtime=gmdate("D, d M Y H:i:s", $cachefiletime)." GMT";
if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
{
header ('Cache-Control: no-cache, pre-check=0, post-check=0, max-age=0');
}
else
{
header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
}
header("Last-Modified: ".$MyGMTtime);
header("Etag: ".$MyETag);
header("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");
header ('Content-Type: text/xml; charset='.$lang['ENCODING']);
readfile($cache_file);
}
else
{
// END Cache Mod
//-----------------------------------------------------
//
// BEGIN Create main board information (some code borrowed from functions_post.php)
//
// Build URL components
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
$viewpost = ( $script_name != '' ) ? $script_name . '/viewtopic.' . $phpEx : 'viewtopic.'. $phpEx;
$replypost = ( $script_name != '' ) ? $script_name . '/jlaposting.' . $phpEx.'?mode=quote' : 'jlaposting.'. $phpEx.'?mode=quote';
$index = ( $script_name != '' ) ? $script_name . '/index.' . $phpEx : 'index.'. $phpEx;
$server_name = trim($board_config['server_name']);
$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
$server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
// Assemble URL components
$index_url = $server_protocol . $server_name . $server_port . (( $script_name != '' )? $script_name . '/':'');
$viewpost_url = $server_protocol . $server_name . $server_port . $viewpost;
$replypost_url =$server_protocol . $server_name . $server_port . $replypost;
// Reformat site name and description
$site_name = strip_tags($board_config['sitename']);
$site_description = strip_tags($board_config['site_desc']);
// Set the fully qualified url to your smilies folder
$smilies_path = $board_config['smilies_path'];
$smilies_url = $index_url . $smilies_path;
$smilies_path = preg_replace("/\//", "\/", $smilies_path);
//
// END Create main board information
//
// Auth check
$sql_forum_where="";
if($userdata['user_level']<>ADMIN)
{
$is_auth = array();
$is_auth = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
if($forum_id=='') {
while ( list($forumId, $auth_mode) = each($is_auth) )
{
if ( !$auth_mode['auth_read'] )
{
$unauthed .= ',' . $forumId;
}
}
$sql_forum_where="AND f.forum_id NOT IN (" . $unauthed . ")";
}
else
{
if((!$is_auth[$forum_id]['auth_read']) or (strpos(",$unauthed," , ",$forum_id,")))
{
if($needlogin) ExitWithHeader("404 Not Found","This forum does not exists");
else
{
header('Location: ' .$index_url.'rss.'.$phpEx.'?f='.$forum_id.(($no_limit)?'&nolimit':'').(isset($HTTP_GET_VARS['atom'])?'&atom':'').(isset($HTTP_GET_VARS['c'])?'&c='.$count:'').(isset($HTTP_GET_VARS['t'])?'&t='.$topics_only:'').(isset($HTTP_GET_VARS['styled'])?'&styled':'').'&login');
ExitWithHeader('301 Moved Permanently');
}
}
else $sql_forum_where = 'AND f.forum_id = ' . $forum_id;
}
unset($is_auth);
}
elseif($forum_id!='')
{
$sql_forum_where = 'AND f.forum_id = ' . $forum_id;
}
//
// BEGIN Initialise template
//
if(isset($HTTP_GET_VARS['atom']))
{
$template->set_filenames(array("body" => "atom_body.tpl"));
$verinfo.="A";
}
else
{
$template->set_filenames(array("body" => "rss_body.tpl"));
$verinfo.="R";
}
//
// END Initialise template
//
if(isset($HTTP_GET_VARS['styled']) or (AUTOSTYLED and strpos($useragent,'MSIE')))
{
$template->assign_block_vars('switch_enable_xslt', array());
}
//
// BEGIN SQL statement to fetch active posts of allowed forums
//
$sql_limit_by_http='';
$MaxRecordAge=time()-MAX_WEEKS_AGO*604800;
$sql_limit_time=(MAX_WEEKS_AGO>0)?"p.post_time >".$MaxRecordAge:"1";
if (!$no_limit){
if(isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])) {
$NotErrorFlag=true;
$NotModifiedSince=strtotime($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']);
if(SEE_MODIFYED) $sql_limit_by_http = "AND (p.post_time > ".$NotModifiedSince." OR p.post_edit_time >".$NotModifiedSince." )";
else if($NotModifiedSince>$MaxRecordAge) $sql_limit_time="p.post_time > ".$NotModifiedSince;
}
}
$getdesc=($forum_id<>'')?'f.forum_desc,':'';
$sql = "SELECT f.forum_name,".$getdesc." t.topic_id, t.topic_title, u.user_id,
u.username, u.user_sig, u.user_sig_bbcode_uid,u.user_allowsmile, p.post_time,p.post_username, p.post_edit_time,
p.enable_sig,p.enable_smilies,p.enable_bbcode,p.enable_html,pt.*, t.topic_replies, t.topic_first_post_id
FROM " . FORUMS_TABLE . " AS f, " . TOPICS_TABLE . " AS t, " . USERS_TABLE . " AS u, " . POSTS_TABLE . " AS p, " . POSTS_TEXT_TABLE . " as pt
WHERE
$sql_limit_time
$sql_forum_where
$sql_limit_by_http
AND pt.post_id = p.post_id
AND t.forum_id = f.forum_id
AND p.poster_id = u.user_id
AND p.topic_id = t.topic_id
$sql_topics_only_where
$sql_topic_view
ORDER BY p.post_time DESC LIMIT $count";
$posts_query = $db->sql_query($sql);
//
// END SQL statement to fetch active posts of public forums
//
//
// BEGIN Query failure check
//
if ( !$posts_query )
{
ExitWithHeader("500 Internal Server Error","Could not query list of active posts");
}
$allposts = $db->sql_fetchrowset($posts_query);
if(($forum_id<>'')&&(count($allposts) != 0)) {
$site_name=strip_tags($allposts[0]["forum_name"]);
$site_description=$allposts[0]["forum_desc"];
}
//
// BEGIN Assign static variables to template
//
// Variable reassignment for Topic Replies
$l_topic_replies = $lang['Topic'] . ' ' . $lang['Replies'];
$user_lang=$userdata['user_lang'];
if(empty($user_lang))$user_lang=$board_config['default_lang'];
$template->assign_vars(array(
'S_CONTENT_ENCODING' => $lang['ENCODING'],
'BOARD_URL' => $index_url,
'BOARD_TITLE' => htmlspecialchars(undo_htmlspecialchars($site_name)),
'PROGRAM' => $ProgName,
'BOARD_DESCRIPTION' => htmlspecialchars(undo_htmlspecialchars($site_description)),
'BOARD_MANAGING_EDITOR' => $board_config['board_email'],
'BOARD_WEBMASTER' => $board_config['board_email'],
'BUILD_DATE' => gmdate('D, d M Y H:i:s').' GMT',
'ATOM_BUILD_DATE'=>gmdate("Y-m-d\TH:i:s")."Z",
'READER' => $username,
'L_AUTHOR' => $lang['Author'],
'L_POSTED' => $lang['Posted'],
'L_TOPIC_REPLIES' => $l_topic_replies,
'LANGUAGE'=>FormatLanguage($user_lang),
'L_POST' => $lang['Post'])
);
//
// END Assign static variabless to template
//
$LastPostTime=0;
if ( count($allposts) == 0 )
{
if($NotErrorFlag) ExitWithHeader("304 Not Modified");
}
else
{
//
// BEGIN "item" loop
//
$PostCount=0;
$SeenTopics=array();
foreach ($allposts as $post)
{
if( $post['post_time']>$LastPostTime) $LastPostTime=$post['post_time'];
if( $post['post_edit_time']>$LastPostTime) $LastPostTime=$post['post_edit_time'];
$topic_id=$post['topic_id'];
$PostCount++;
$SeenTopics["$topic_id"]++;
// Variable reassignment and reformatting for post text
$post_id=$post['post_id'];
$post_subject = ( $post['post_subject'] != '' ) ? $post['post_subject'] : '';
$message = $post['post_text'];
$words = explode(" ",$message,20); //get first 15 words
$message = "";
for ($i = 0; $i < (count($words) - 1); $i++)
{
$message .= $words[$i] . " "; //add words back to $message
}
$message .= ' ...'; //append ... to indicate more text available
$bbcode_uid = $post['bbcode_uid'];
$user_sig = ( $post['enable_sig'] && $post['user_sig'] != '' && $board_config['allow_sig'] ) ? $post['user_sig'] : '';
$user_sig_bbcode_uid = $post['user_sig_bbcode_uid'];
//
// If the board has HTML off but the post has HTML
// on then we process it, else leave it alone
//
if ( !$board_config['allow_html']||!$userdata['user_allowhtml'])
{
if ( $user_sig != '')
{
$user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig);
}
if ( $post['enable_html'] )
{
$message = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $message);
}
}
//
// Parse message and/or sig for BBCode if reqd
//
if ( $board_config['allow_bbcode'] )
{
if ( $user_sig != '' && $user_sig_bbcode_uid != '' )
{
$user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
}
if ( $bbcode_uid != '' )
{
$message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
}
}
if ( $user_sig != '' )
{
$user_sig = make_clickable($user_sig);
}
$message = make_clickable($message);
//
// Parse smilies
//
if ( $board_config['allow_smilies'] )
{
if ( $post['user_allowsmile'] && $user_sig != '' )
{
$user_sig = smilies_pass($user_sig);
$user_sig = preg_replace("/$smilies_path/", $smilies_url, $user_sig);
}
if ( $post['enable_smilies'] )
{
$message = smilies_pass($message);
$message = preg_replace("/$smilies_path/", $smilies_url, $message);
}
}
//
// Replace newlines (we use this rather than nl2br because
// till recently it wasn't XHTML compliant)
//
if ( $user_sig != '' )
{
$user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
}
$message = str_replace("\n", "\n<br />\n", $message);
if ( $post_subject != '' )
{
$post_subject = htmlspecialchars($lang['Subject'].': '.$post_subject.'<br />');
}
// Variable reassignment for topic title, and show whether it is the start of topic, or a reply
$topic_title = $post['topic_title'];
if ( $post['post_id'] != $post['topic_first_post_id'] )
{
$topic_title = 'RE: ' . $topic_title;
}
// Variable reassignment and reformatting for author
$author = $post['username'];
$author0 =$author;
if ( $post['user_id'] != -1 )
{
$author = '<a href="' . $index_url . 'profile.' . $phpEx . '?mode=viewprofile&u=' . $post['user_id'] . '" target="_blank">'
. $author . '</a>';
}
else
{
// Uncomment next string if you want or $author0=='Anonymus'.
// $author0= $post['post_username'];
$author= $post['post_username'];
}
$author = make_clickable($author);
// Assign "item" variables to template
$template->assign_block_vars('post_item', array(
'POST_URL' => $viewpost_url . '?' . POST_POST_URL . '=' . $post['post_id'] . '#' . $post['post_id'],
'FIRST_POST_URL' => $viewpost_url . '?' . POST_POST_URL . '=' . $post['topic_first_post_id'] . '#' . $post['topic_first_post_id'],
'REPLY_URL'=>$replypost_url."&".POST_POST_URL."=".$post['post_id'],
'TOPIC_TITLE' =>htmlspecialchars(undo_htmlspecialchars($topic_title)),
'AUTHOR0' => htmlspecialchars($author0),
'AUTHOR' => htmlspecialchars($author),
'POST_TIME' => create_date($board_config['default_dateformat'], $post['post_time'], $board_config['board_timezone']).' (GMT ' . $board_config['board_timezone'] . ')',
'ATOM_TIME'=>gmdate("Y-m-d\TH:i:s", $post['post_time'])."Z",
'ATOM_TIME_M'=>($post['post_edit_time']<>"" ? gmdate("Y-m-d\TH:i:s", $post['post_edit_time'])."Z": gmdate("Y-m-d\TH:i:s", $post['post_time'])."Z"),
'POST_SUBJECT' => $post_subject,
'FORUM_NAME' => htmlspecialchars($post['forum_name']),
'UTF_TIME'=>RSSTimeFormat($post['post_time'],$userdata['user_timezone']),
'POST_TEXT' => htmlspecialchars(preg_replace('|[\x00-\x08\x0B\x0C\x0E-\x1f]|','',$message)),
'USER_SIG' => htmlspecialchars($user_sig),
'TOPIC_REPLIES' => $post['topic_replies']
)
);
}
//
// END "item" loop
//
if($user_id!=ANONYMOUS && UPDATE_VIEW_COUNT)
{
$updlist='';
foreach ($SeenTopics as $topic_id=>$tcount)
{
$updlist.=(empty($updlist))? $topic_id : ",".$topic_id;
if(defined('TOPIC_VIEW_TABLE') and AUTO_WVT_MOD)
{
$sql='UPDATE '.TOPIC_VIEW_TABLE.' SET topic_id="'.$topic_id.'", view_time="'.time().'", view_count=view_count+1 WHERE topic_id='.$topic_id.' AND user_id='.$user_id;
if ( !$db->sql_query($sql) || !$db->sql_affectedrows() )
{
$sql = 'INSERT IGNORE INTO '.TOPIC_VIEW_TABLE.' (topic_id, user_id, view_time,view_count)
VALUES ('.$topic_id.', "'.$user_id.'", "'.time().'","1")';
if ( !($db->sql_query($sql)) )
{
ExitWithHeader("500 Internal Server Error",'Error create user view topic information');
}
}
}
// End add - Who viewed a topic MOD
}
if($updlist!='')
{
//
// Update the topic view counter
//
$sql = "UPDATE " . TOPICS_TABLE . "
SET topic_views = topic_views + 1
WHERE topic_id IN ($updlist)";
if ( !$db->sql_query($sql) )
{
ExitWithHeader("500 Internal Server Error","Could not update topic views");
}
}
}
// LAstvisit MOD
if(LV_MOD_INSTALLED and $user_id!=ANONYMOUS){
$sql = "UPDATE " . USERS_TABLE . "
SET user_totalpages=user_totalpages+$PostCount
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
ExitWithHeader("500 Internal Server Error",'Error updating user totalpages ');
}}
}
// Check for E-Tag
if($LastPostTime==0) $LastPostTime=$deadline;
$MyETag='"RSS'.gmdate("YmdHis", $LastPostTime).$verinfo.'"';
$MyGMTtime=gmdate("D, d M Y H:i:s", $LastPostTime)." GMT";
if(isset($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH'])&& ($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']== $MyETag)) ExitWithHeader("304 Not Modified");
if(isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']) && ($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'] == $MyGMTtime)) ExitWithHeader("304 Not Modified");
//
// BEGIN XML and nocaching headers (copied from page_header.php)
//
if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
{
header ('Cache-Control: no-cache, pre-check=0, post-check=0, max-age=0');
}
else
{
header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
}
header("Last-Modified: ".$MyGMTtime);
header("Etag: ".$MyETag);
header("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");
header ('Content-Type: text/xml; charset='.$lang['ENCODING']);
//
// End XML and nocaching headers
//
//
// BEGIN Output XML page
//
// BEGIN Cache Mod
if(($user_id==ANONYMOUS) and CACHE_TO_FILE and ($cache_root!='') and empty($HTTP_GET_VARS) and !isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']) and !(AUTOSTYLED and strpos($useragent,'MSIE')))
{
ob_start();
$template->pparse('body');
$out=ob_get_contents();
ob_end_flush();
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $out,strlen($out));
fclose($f);
}
}
else {
$template->pparse('body');
}
}// END Cache Mod
// And remove temporary session from database
if(defined(TEMP_SESSION)) rss_session_end;
$gzip_text = ($board_config['gzip_compress']) ? 'GZIP enabled' : 'GZIP disabled';
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$gentime = round(($endtime - $starttime), 4);
if($show_time) {
echo '<!-- Page generation time: '.$gentime .'s ';
if(SMARTOR_STATS) {
$sql_time = round($db->sql_time, 4);
$sql_part = round($sql_time / $gentime * 100);
$excuted_queries = $db->num_queries;
$php_part = 100 - $sql_part;
echo '(PHP: '. $php_part .'% - SQL: '. $sql_part .'%) - SQL queries: '. $excuted_queries;
}
if (function_exists('memory_get_usage') && ($mem = @memory_get_usage())) echo ' - Memory Usage: '.(number_format(($mem/(1024*1024)),3)).' Mb ';
echo ' - '. $gzip_text.' -->';
}
//
// END Output XML page
//
$db->sql_close();
//
// Compress buffered output if required and send to browser
//
if ( $do_gzip_compress )
{
//
// Borrowed from php.net!
//
$gzip_contents = ob_get_contents();
ob_end_clean();
$gzip_size = strlen($gzip_contents);
$gzip_crc = crc32($gzip_contents);
$gzip_contents = gzcompress($gzip_contents, 9);
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip_contents;
echo pack('V', $gzip_crc);
echo pack('V', $gzip_size);
}
exit;
?>
|
Any ideas on what might be done to correct these issues?
Thanks in advance. _________________ http://www.jlaforums.com |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Tue Jul 21, 2009 3:07 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Anyone have any idea why the caching does not function correctly? _________________ http://www.jlaforums.com |
|
Back to top |
|
|
Ptirhiik Board Member
Joined: 19 Nov 2008
Posts: 114
|
Posted: Tue Jul 21, 2009 7:27 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Probably because it relies on $HTTP_SERVER_VARS, which may be not populated depending the server settings (at least for the HTTP_IF_MODIFIED_SINCE entry). Anyway, I don't think you are beating the right horse: prefer focus on the query, that can be greatly improved here. The multiplication of all rows on so much large tables is quite catastrophic. Drop the "edit revive" function, and select first only the topic id you need, then select posts from this topic ids list, with the users and the texts -by my side, I would isolate the user_ids too). The idea behind this is to collect first the forum ids (very few), then the topic ids (max 50), then only the posts, working on keys, avoiding large table index builds. The lower number of table links you will have, the better the script will run, making the cache pretty useless. |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Mon Aug 10, 2009 5:51 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Ptirhiik wrote: | Probably because it relies on $HTTP_SERVER_VARS, which may be not populated depending the server settings (at least for the HTTP_IF_MODIFIED_SINCE entry). Anyway, I don't think you are beating the right horse: prefer focus on the query, that can be greatly improved here. The multiplication of all rows on so much large tables is quite catastrophic. Drop the "edit revive" function, and select first only the topic id you need, then select posts from this topic ids list, with the users and the texts -by my side, I would isolate the user_ids too). The idea behind this is to collect first the forum ids (very few), then the topic ids (max 50), then only the posts, working on keys, avoiding large table index builds. The lower number of table links you will have, the better the script will run, making the cache pretty useless. |
Do you think you can provided a modified version of the previous code to implement this?
Thanks _________________ http://www.jlaforums.com |
|
Back to top |
|
|
drathbun Board Member
Joined: 24 Jul 2008
Posts: 729 Location: Texas
|
Posted: Fri Aug 28, 2009 11:47 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Which queries have you found that are causing the problem? I'll have a look at them. _________________ phpBBDoctor Blog |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Mon Aug 31, 2009 9:57 am Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
drathbun wrote: | Which queries have you found that are causing the problem? I'll have a look at them. |
Code: |
$getdesc=($forum_id<>'')?'f.forum_desc,':'';
$sql = "SELECT f.forum_name,".$getdesc." t.topic_id, t.topic_title, u.user_id,
u.username, u.user_sig, u.user_sig_bbcode_uid,u.user_allowsmile, p.post_time,p.post_username, p.post_edit_time,
p.enable_sig,p.enable_smilies,p.enable_bbcode,p.enable_html,pt.*, t.topic_replies, t.topic_first_post_id
FROM " . FORUMS_TABLE . " AS f, " . TOPICS_TABLE . " AS t, " . USERS_TABLE . " AS u, " . POSTS_TABLE . " AS p, " . POSTS_TEXT_TABLE . " as pt
WHERE
$sql_limit_time
$sql_forum_where
$sql_limit_by_http
AND pt.post_id = p.post_id
AND t.forum_id = f.forum_id
AND p.poster_id = u.user_id
AND p.topic_id = t.topic_id
$sql_topics_only_where
$sql_topic_view
ORDER BY p.post_time DESC LIMIT $count";
$posts_query = $db->sql_query($sql);
//
// END SQL statement to fetch active posts of public forums
//
/
|
Thank You! _________________ http://www.jlaforums.com |
|
Back to top |
|
|
drathbun Board Member
Joined: 24 Jul 2008
Posts: 729 Location: Texas
|
Posted: Mon Aug 31, 2009 10:04 am Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
How are the variables $sql_limit_time and $sql_forum_where and $sql_limit_by_http typically filled in? I don't mean the process (I assume that's in the code) I mean the values. I need to know all of the typical where clause information to tune the query.
If they're typically left blank, that's fine. But if they generally have some sort of additional query restriction that would be important to know. _________________ phpBBDoctor Blog |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Mon Aug 31, 2009 10:18 am Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Here is the entire code
Code: |
<?php
/***************************************************************************
* rss.php
* -------------------
* begin : Sat, October 23, 2004
* copyright : (c) 2004-2005, Egor Naklonyaeff
* email : chyduskam@naklon.info
* more info : http://naklon.info/rss/about.htm
*
* $Id: rss.php,v 2.2.4 2005/11/23 21:15:00 chyduskam Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
****************************************************************************/
define ('IN_PHPBB', true);
$phpbb_root_path = './';
$ProgName='RSS Feed 2.2.4';
$verinfo='V224';
//
// BEGIN Includes of phpBB scripts
//
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
include($phpbb_root_path . 'includes/rss_config.'.$phpEx);
include($phpbb_root_path . 'includes/rss_functions.'.$phpEx);
if(!SMARTOR_STATS) {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
}
//
// END Includes of phpBB scripts
//
if(!defined('PAGE_RSS')) define('PAGE_RSS', PAGE_INDEX);
$deadline=0;
if(isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']))
{
$deadline=strtotime($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']);
if(CACHE_TIME>0) if((time()-$deadline)<CACHE_TIME)
{
ExitWithHeader("304 Not Modified");
}
}
$sql= "SELECT MAX(post_time) as pt FROM ". POSTS_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
ExitWithHeader("500 Internal Server Error","Error in obtaining post data");
}
if( $row = $db->sql_fetchrow($result) )
{
if($row['pt']<=$deadline) ExitWithHeader("304 Not Modified");
$deadline=$row['pt'];
}
// BEGIN Cache Mod
$use_cached=false;
$cache_file ='';
if(CACHE_TO_FILE and CACHE_TIME > 0) {
$cache_file =$phpbb_root_path.$cache_root.$cache_filename;
if($cache_root!='' and empty($HTTP_GET_VARS))
{
$cachefiletime=@filemtime($cache_file);
$timedif = ($deadline - $cachefiletime);
if ($timedif < CACHE_TIME and filesize($cache_file)>0) $use_cached=true;
}
}
// END Cache Mod
//
// gzip_compression
//
$do_gzip_compress = FALSE;
$useragent = (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) ? $HTTP_SERVER_VARS['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT');
if($use_cached && AUTOSTYLED and strpos($useragent,'MSIE'))$use_cached=false;
if ( $board_config['gzip_compress'] )
{
$phpver = phpversion();
if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
{
if ( extension_loaded('zlib') )
{
ob_start('ob_gzhandler');
}
}
else if ( $phpver > '4.0' )
{
if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
{
if ( extension_loaded('zlib') )
{
$do_gzip_compress = TRUE;
ob_start();
ob_implicit_flush(0);
header('Content-Encoding: gzip');
}
}
}
}
// end gzip block
// How many posts do you want to returnd (count)? Specified in the URL with "c=". Defaults to 25, upper limit of 50.
$count = ( isset($HTTP_GET_VARS['c']) ) ? intval($HTTP_GET_VARS['c']) : DEFAULT_ITEMS;
$count = ( $count == 0 ) ? DEFAULT_ITEMS : $count;
$count = ( $count > MAX_ITEMS ) ? MAX_ITEMS : $count;
// Which forum do you want posts from (forum_id)? specified in the url with "f=". Defaults to all (public) forums.
$forum_id = ( isset($HTTP_GET_VARS['f']) ) ? intval($HTTP_GET_VARS['f']) : '';
$forum_id = ( $forum_id == 0 ) ? 9 : $forum_id;
$no_limit=( isset($HTTP_GET_VARS['nolimit']) ) ? true : false;
$needlogin=( isset($HTTP_GET_VARS['login']) or isset($HTTP_GET_VARS['uid'])) ? true : false;
$sql_forum_where = ( !empty($forum_id) ) ? ' AND f.forum_id = ' . $forum_id : ' ';
// Return topics only, or all posts? Specified in the URL with "t=". Defaults to all posts (0).
$topics_only = (isset($HTTP_GET_VARS['t']) ) ? intval($HTTP_GET_VARS['t']) : 0;
$topics_view = (isset($HTTP_GET_VARS['topic']) ) ? intval($HTTP_GET_VARS['topic']) : 0;
$sql_topics_only_where = '';
if ( $topics_only == 1 )
{
$sql_topics_only_where = 'AND p.post_id = t.topic_first_post_id';
}
if($topics_view != 0)
{
$sql_topic_view = 'AND t.topic_id ='.$topics_view;
}
//
// BEGIN Session management
//
// Check user
$user_id=($needlogin)? rss_get_user() : ANONYMOUS;
if($user_id==ANONYMOUS && AUTOLOGIN)
{
$userdata = session_pagestart($user_ip, PAGE_RSS);
$user_id=$userdata["user_id"];
}
else $userdata=rss_session_begin($user_id, $user_ip, PAGE_RSS);
init_userprefs($userdata);
$username=$userdata["username"];
//
// END session management
//
// BEGIN Cache Mod
if($user_id==ANONYMOUS && $use_cached) {
$MyETag='"RSS'.gmdate("YmdHis", $cachefiletime).$verinfo.'"';
$MyGMTtime=gmdate("D, d M Y H:i:s", $cachefiletime)." GMT";
if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
{
header ('Cache-Control: no-cache, pre-check=0, post-check=0, max-age=0');
}
else
{
header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
}
header("Last-Modified: ".$MyGMTtime);
header("Etag: ".$MyETag);
header("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");
header ('Content-Type: text/xml; charset='.$lang['ENCODING']);
readfile($cache_file);
}
else
{
// END Cache Mod
//-----------------------------------------------------
//
// BEGIN Create main board information (some code borrowed from functions_post.php)
//
// Build URL components
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
$viewpost = ( $script_name != '' ) ? $script_name . '/viewtopic.' . $phpEx : 'viewtopic.'. $phpEx;
$replypost = ( $script_name != '' ) ? $script_name . '/jlaposting.' . $phpEx.'?mode=quote' : 'jlaposting.'. $phpEx.'?mode=quote';
$index = ( $script_name != '' ) ? $script_name . '/index.' . $phpEx : 'index.'. $phpEx;
$server_name = trim($board_config['server_name']);
$server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
$server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';
// Assemble URL components
$index_url = $server_protocol . $server_name . $server_port . (( $script_name != '' )? $script_name . '/':'');
$viewpost_url = $server_protocol . $server_name . $server_port . $viewpost;
$replypost_url =$server_protocol . $server_name . $server_port . $replypost;
// Reformat site name and description
$site_name = strip_tags($board_config['sitename']);
$site_description = strip_tags($board_config['site_desc']);
// Set the fully qualified url to your smilies folder
$smilies_path = $board_config['smilies_path'];
$smilies_url = $index_url . $smilies_path;
$smilies_path = preg_replace("/\//", "\/", $smilies_path);
//
// END Create main board information
//
// Auth check
$sql_forum_where="";
if($userdata['user_level']<>ADMIN)
{
$is_auth = array();
$is_auth = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
if($forum_id=='') {
while ( list($forumId, $auth_mode) = each($is_auth) )
{
if ( !$auth_mode['auth_read'] )
{
$unauthed .= ',' . $forumId;
}
}
$sql_forum_where="AND f.forum_id NOT IN (" . $unauthed . ")";
}
else
{
if((!$is_auth[$forum_id]['auth_read']) or (strpos(",$unauthed," , ",$forum_id,")))
{
if($needlogin) ExitWithHeader("404 Not Found","This forum does not exists");
else
{
header('Location: ' .$index_url.'rss.'.$phpEx.'?f='.$forum_id.(($no_limit)?'&nolimit':'').(isset($HTTP_GET_VARS['atom'])?'&atom':'').(isset($HTTP_GET_VARS['c'])?'&c='.$count:'').(isset($HTTP_GET_VARS['t'])?'&t='.$topics_only:'').(isset($HTTP_GET_VARS['styled'])?'&styled':'').'&login');
ExitWithHeader('301 Moved Permanently');
}
}
else $sql_forum_where = 'AND f.forum_id = ' . $forum_id;
}
unset($is_auth);
}
elseif($forum_id!='')
{
$sql_forum_where = 'AND f.forum_id = ' . $forum_id;
}
//
// BEGIN Initialise template
//
if(isset($HTTP_GET_VARS['atom']))
{
$template->set_filenames(array("body" => "atom_body.tpl"));
$verinfo.="A";
}
else
{
$template->set_filenames(array("body" => "rss_body.tpl"));
$verinfo.="R";
}
//
// END Initialise template
//
if(isset($HTTP_GET_VARS['styled']) or (AUTOSTYLED and strpos($useragent,'MSIE')))
{
$template->assign_block_vars('switch_enable_xslt', array());
}
//
// BEGIN SQL statement to fetch active posts of allowed forums
//
$sql_limit_by_http='';
$MaxRecordAge=time()-MAX_WEEKS_AGO*604800;
$sql_limit_time=(MAX_WEEKS_AGO>0)?"p.post_time >".$MaxRecordAge:"1";
if (!$no_limit){
if(isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])) {
$NotErrorFlag=true;
$NotModifiedSince=strtotime($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']);
if(SEE_MODIFYED) $sql_limit_by_http = "AND (p.post_time > ".$NotModifiedSince." OR p.post_edit_time >".$NotModifiedSince." )";
else if($NotModifiedSince>$MaxRecordAge) $sql_limit_time="p.post_time > ".$NotModifiedSince;
}
}
$getdesc=($forum_id<>'')?'f.forum_desc,':'';
$sql = "SELECT f.forum_name,".$getdesc." t.topic_id, t.topic_title, u.user_id,
u.username, u.user_sig, u.user_sig_bbcode_uid,u.user_allowsmile, p.post_time,p.post_username, p.post_edit_time,
p.enable_sig,p.enable_smilies,p.enable_bbcode,p.enable_html,pt.*, t.topic_replies, t.topic_first_post_id
FROM " . FORUMS_TABLE . " AS f, " . TOPICS_TABLE . " AS t, " . USERS_TABLE . " AS u, " . POSTS_TABLE . " AS p, " . POSTS_TEXT_TABLE . " as pt
WHERE
$sql_limit_time
$sql_forum_where
$sql_limit_by_http
AND pt.post_id = p.post_id
AND t.forum_id = f.forum_id
AND p.poster_id = u.user_id
AND p.topic_id = t.topic_id
$sql_topics_only_where
$sql_topic_view
ORDER BY p.post_time DESC LIMIT $count";
$posts_query = $db->sql_query($sql);
//
// END SQL statement to fetch active posts of public forums
//
//
// BEGIN Query failure check
//
if ( !$posts_query )
{
ExitWithHeader("500 Internal Server Error","Could not query list of active posts");
}
$allposts = $db->sql_fetchrowset($posts_query);
if(($forum_id<>'')&&(count($allposts) != 0)) {
$site_name=strip_tags($allposts[0]["forum_name"]);
$site_description=$allposts[0]["forum_desc"];
}
//
// BEGIN Assign static variables to template
//
// Variable reassignment for Topic Replies
$l_topic_replies = $lang['Topic'] . ' ' . $lang['Replies'];
$user_lang=$userdata['user_lang'];
if(empty($user_lang))$user_lang=$board_config['default_lang'];
$template->assign_vars(array(
'S_CONTENT_ENCODING' => $lang['ENCODING'],
'BOARD_URL' => $index_url,
'BOARD_TITLE' => htmlspecialchars(undo_htmlspecialchars($site_name)),
'PROGRAM' => $ProgName,
'BOARD_DESCRIPTION' => htmlspecialchars(undo_htmlspecialchars($site_description)),
'BOARD_MANAGING_EDITOR' => $board_config['board_email'],
'BOARD_WEBMASTER' => $board_config['board_email'],
'BUILD_DATE' => gmdate('D, d M Y H:i:s').' GMT',
'ATOM_BUILD_DATE'=>gmdate("Y-m-d\TH:i:s")."Z",
'READER' => $username,
'L_AUTHOR' => $lang['Author'],
'L_POSTED' => $lang['Posted'],
'L_TOPIC_REPLIES' => $l_topic_replies,
'LANGUAGE'=>FormatLanguage($user_lang),
'L_POST' => $lang['Post'])
);
//
// END Assign static variabless to template
//
$LastPostTime=0;
if ( count($allposts) == 0 )
{
if($NotErrorFlag) ExitWithHeader("304 Not Modified");
}
else
{
//
// BEGIN "item" loop
//
$PostCount=0;
$SeenTopics=array();
foreach ($allposts as $post)
{
if( $post['post_time']>$LastPostTime) $LastPostTime=$post['post_time'];
if( $post['post_edit_time']>$LastPostTime) $LastPostTime=$post['post_edit_time'];
$topic_id=$post['topic_id'];
$PostCount++;
$SeenTopics["$topic_id"]++;
// Variable reassignment and reformatting for post text
$post_id=$post['post_id'];
$post_subject = ( $post['post_subject'] != '' ) ? $post['post_subject'] : '';
$message = $post['post_text'];
$words = explode(" ",$message,20); //get first 15 words
$message = "";
for ($i = 0; $i < (count($words) - 1); $i++)
{
$message .= $words[$i] . " "; //add words back to $message
}
$message .= ' ...'; //append ... to indicate more text available
$bbcode_uid = $post['bbcode_uid'];
$user_sig = ( $post['enable_sig'] && $post['user_sig'] != '' && $board_config['allow_sig'] ) ? $post['user_sig'] : '';
$user_sig_bbcode_uid = $post['user_sig_bbcode_uid'];
//
// If the board has HTML off but the post has HTML
// on then we process it, else leave it alone
//
if ( !$board_config['allow_html']||!$userdata['user_allowhtml'])
{
if ( $user_sig != '')
{
$user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig);
}
if ( $post['enable_html'] )
{
$message = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $message);
}
}
//
// Parse message and/or sig for BBCode if reqd
//
if ( $board_config['allow_bbcode'] )
{
if ( $user_sig != '' && $user_sig_bbcode_uid != '' )
{
$user_sig = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $user_sig);
}
if ( $bbcode_uid != '' )
{
$message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
}
}
if ( $user_sig != '' )
{
$user_sig = make_clickable($user_sig);
}
$message = make_clickable($message);
//
// Parse smilies
//
if ( $board_config['allow_smilies'] )
{
if ( $post['user_allowsmile'] && $user_sig != '' )
{
$user_sig = smilies_pass($user_sig);
$user_sig = preg_replace("/$smilies_path/", $smilies_url, $user_sig);
}
if ( $post['enable_smilies'] )
{
$message = smilies_pass($message);
$message = preg_replace("/$smilies_path/", $smilies_url, $message);
}
}
//
// Replace newlines (we use this rather than nl2br because
// till recently it wasn't XHTML compliant)
//
if ( $user_sig != '' )
{
$user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig);
}
$message = str_replace("\n", "\n<br />\n", $message);
if ( $post_subject != '' )
{
$post_subject = htmlspecialchars($lang['Subject'].': '.$post_subject.'<br />');
}
// Variable reassignment for topic title, and show whether it is the start of topic, or a reply
$topic_title = $post['topic_title'];
if ( $post['post_id'] != $post['topic_first_post_id'] )
{
$topic_title = 'RE: ' . $topic_title;
}
// Variable reassignment and reformatting for author
$author = $post['username'];
$author0 =$author;
if ( $post['user_id'] != -1 )
{
$author = '<a href="' . $index_url . 'profile.' . $phpEx . '?mode=viewprofile&u=' . $post['user_id'] . '" target="_blank">'
. $author . '</a>';
}
else
{
// Uncomment next string if you want or $author0=='Anonymus'.
// $author0= $post['post_username'];
$author= $post['post_username'];
}
$author = make_clickable($author);
// Assign "item" variables to template
$template->assign_block_vars('post_item', array(
'POST_URL' => $viewpost_url . '?' . POST_POST_URL . '=' . $post['post_id'] . '#' . $post['post_id'],
'FIRST_POST_URL' => $viewpost_url . '?' . POST_POST_URL . '=' . $post['topic_first_post_id'] . '#' . $post['topic_first_post_id'],
'REPLY_URL'=>$replypost_url."&".POST_POST_URL."=".$post['post_id'],
'TOPIC_TITLE' =>htmlspecialchars(undo_htmlspecialchars($topic_title)),
'AUTHOR0' => htmlspecialchars($author0),
'AUTHOR' => htmlspecialchars($author),
'POST_TIME' => create_date($board_config['default_dateformat'], $post['post_time'], $board_config['board_timezone']).' (GMT ' . $board_config['board_timezone'] . ')',
'ATOM_TIME'=>gmdate("Y-m-d\TH:i:s", $post['post_time'])."Z",
'ATOM_TIME_M'=>($post['post_edit_time']<>"" ? gmdate("Y-m-d\TH:i:s", $post['post_edit_time'])."Z": gmdate("Y-m-d\TH:i:s", $post['post_time'])."Z"),
'POST_SUBJECT' => $post_subject,
'FORUM_NAME' => htmlspecialchars($post['forum_name']),
'UTF_TIME'=>RSSTimeFormat($post['post_time'],$userdata['user_timezone']),
'POST_TEXT' => htmlspecialchars(preg_replace('|[\x00-\x08\x0B\x0C\x0E-\x1f]|','',$message)),
'USER_SIG' => htmlspecialchars($user_sig),
'TOPIC_REPLIES' => $post['topic_replies']
)
);
}
//
// END "item" loop
//
if($user_id!=ANONYMOUS && UPDATE_VIEW_COUNT)
{
$updlist='';
foreach ($SeenTopics as $topic_id=>$tcount)
{
$updlist.=(empty($updlist))? $topic_id : ",".$topic_id;
if(defined('TOPIC_VIEW_TABLE') and AUTO_WVT_MOD)
{
$sql='UPDATE '.TOPIC_VIEW_TABLE.' SET topic_id="'.$topic_id.'", view_time="'.time().'", view_count=view_count+1 WHERE topic_id='.$topic_id.' AND user_id='.$user_id;
if ( !$db->sql_query($sql) || !$db->sql_affectedrows() )
{
$sql = 'INSERT IGNORE INTO '.TOPIC_VIEW_TABLE.' (topic_id, user_id, view_time,view_count)
VALUES ('.$topic_id.', "'.$user_id.'", "'.time().'","1")';
if ( !($db->sql_query($sql)) )
{
ExitWithHeader("500 Internal Server Error",'Error create user view topic information');
}
}
}
// End add - Who viewed a topic MOD
}
if($updlist!='')
{
//
// Update the topic view counter
//
$sql = "UPDATE " . TOPICS_TABLE . "
SET topic_views = topic_views + 1
WHERE topic_id IN ($updlist)";
if ( !$db->sql_query($sql) )
{
ExitWithHeader("500 Internal Server Error","Could not update topic views");
}
}
}
// LAstvisit MOD
if(LV_MOD_INSTALLED and $user_id!=ANONYMOUS){
$sql = "UPDATE " . USERS_TABLE . "
SET user_totalpages=user_totalpages+$PostCount
WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
ExitWithHeader("500 Internal Server Error",'Error updating user totalpages ');
}}
}
// Check for E-Tag
if($LastPostTime==0) $LastPostTime=$deadline;
$MyETag='"RSS'.gmdate("YmdHis", $LastPostTime).$verinfo.'"';
$MyGMTtime=gmdate("D, d M Y H:i:s", $LastPostTime)." GMT";
if(isset($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH'])&& ($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']== $MyETag)) ExitWithHeader("304 Not Modified");
if(isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']) && ($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'] == $MyGMTtime)) ExitWithHeader("304 Not Modified");
//
// BEGIN XML and nocaching headers (copied from page_header.php)
//
if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
{
header ('Cache-Control: no-cache, pre-check=0, post-check=0, max-age=0');
}
else
{
header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
}
header("Last-Modified: ".$MyGMTtime);
header("Etag: ".$MyETag);
header("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");
header ('Content-Type: text/xml; charset='.$lang['ENCODING']);
//
// End XML and nocaching headers
//
//
// BEGIN Output XML page
//
// BEGIN Cache Mod
if(($user_id==ANONYMOUS) and CACHE_TO_FILE and ($cache_root!='') and empty($HTTP_GET_VARS) and !isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']) and !(AUTOSTYLED and strpos($useragent,'MSIE')))
{
ob_start();
$template->pparse('body');
$out=ob_get_contents();
ob_end_flush();
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $out,strlen($out));
fclose($f);
}
}
else {
$template->pparse('body');
}
}// END Cache Mod
// And remove temporary session from database
if(defined(TEMP_SESSION)) rss_session_end;
$gzip_text = ($board_config['gzip_compress']) ? 'GZIP enabled' : 'GZIP disabled';
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$gentime = round(($endtime - $starttime), 4);
if($show_time) {
echo '<!-- Page generation time: '.$gentime .'s ';
if(SMARTOR_STATS) {
$sql_time = round($db->sql_time, 4);
$sql_part = round($sql_time / $gentime * 100);
$excuted_queries = $db->num_queries;
$php_part = 100 - $sql_part;
echo '(PHP: '. $php_part .'% - SQL: '. $sql_part .'%) - SQL queries: '. $excuted_queries;
}
if (function_exists('memory_get_usage') && ($mem = @memory_get_usage())) echo ' - Memory Usage: '.(number_format(($mem/(1024*1024)),3)).' Mb ';
echo ' - '. $gzip_text.' -->';
}
//
// END Output XML page
//
$db->sql_close();
//
// Compress buffered output if required and send to browser
//
if ( $do_gzip_compress )
{
//
// Borrowed from php.net!
//
$gzip_contents = ob_get_contents();
ob_end_clean();
$gzip_size = strlen($gzip_contents);
$gzip_crc = crc32($gzip_contents);
$gzip_contents = gzcompress($gzip_contents, 9);
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip_contents;
echo pack('V', $gzip_crc);
echo pack('V', $gzip_size);
}
exit;
?>
|
Code: |
<?php
// rss_funtions.php
// Part of RSS Feed MOD
// Edit: 2005-11-23
// Copyright (c) 2004-2005, Egor Naklonyaeff
function FormatLanguage($lng)
{
// You can add you ISO 639 coutry code here or remove unused codes
$iso639=array("albanian"=>"sq","arabic"=>"ar","azerbaijani"=>"az",
"bulgarian"=>"bg","chinese"=>"zh","chinese_simplified"=>"zh",
"chinese_traditional"=>"zh","croatian"=>"hr","czech"=>"cs",
"danish"=>"da","dutch"=>"nl","english"=>"en",
"esperanto"=>"eo","estonian"=>"et","finnish"=>"fi",
"french"=>"fr","japanese"=>"ja","galego"=>"gl",
"german"=>"de","greek"=>"el","hungarian"=>"hu",
"hebrew"=>"he","icelandic"=>"is","indonesian"=>"id",
"italian"=>"it","korean"=>"ko","kurdish"=>"ku",
"macedonian"=>"mk","moldavian"=>"mo","mongolian"=>"mn",
"norwegian"=>"no","polish"=>"pl","portuguese"=>"pt",
"romanian"=>"ro","russian"=>"ru","russian_tu"=>"ru",
"serbian"=>"sr","slovak"=>"sk","slovenian"=>"sl",
"spanish"=>"es","swedish"=>"sv","thai"=>"th",
"turkish"=>"tr","uigur"=>"ug","ukrainian"=>"uk",
"vietnamese"=>"vi","welsh"=>"cy");
$user_lang=(isset($iso639[$lng]))? $iso639[$lng]:'';
return(($user_lang!='')?"\n<language>$user_lang</language>":'');
}
function RSSTimeFormat($utime,$uoffset=0)
{
global $HTTP_GET_VARS,$user_id,$useragent;
if(CACHE_TO_FILE && ($user_id==ANONYMOUS) && empty($HTTP_GET_VARS))$uoffset=0;
if((isset($HTTP_GET_VARS['time']) && $HTTP_GET_VARS['time']=='local')|| (strpos($useragent,'Abilon')!==false)|| (strpos($useragent,'ActiveRefresh')!==false))
{
$uoffset=intval($uoffset);
}
else $uoffset=0;
$result=gmdate("D, d M Y H:i:s", $utime + (3600 * $uoffset));
$uoffset=intval($uoffset*100);
$result.=' '.(($uoffset>0)?'+':'').(($uoffset==0)? 'GMT': sprintf((($uoffset<0)?"%05d":"%04d"),$uoffset));
return $result;
}
function GetHTTPPasswd()
{
header('WWW-Authenticate: Basic realm="For registred users only"');
ExitWithHeader('401 Unauthorized','For registred users only');
}
function ExitWithHeader($output,$message='')
{
global $db, $HTTP_SERVER_VARS;
$db->sql_close();
if(function_exists("getallheaders")) header("HTTP/1.1 $output");
else header('Status: '.$output);
$code=intval(substr($output,0,3));
if(($code==200)||($code==304))
{
if(isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])) header("Last-Modified: ".$HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']);
if(isset($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH'])) header("Etag: ".$HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']);
}
if(!empty($message)) {
header ('Content-Type: text/plain');
echo $message;
}
exit;
}
function rss_session_begin($user_id, $user_ip, $page_id)
{
global $db, $board_config,$HTTP_SERVER_VARS;
$page_id = (int) $page_id;
$user_id= (int) $user_id;
$password=md5($HTTP_SERVER_VARS['PHP_AUTH_PW']);
$last_visit = 0;
$current_time = time();
$expiry_time = $current_time - $board_config['session_length'];
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE user_id = $user_id";
if ( !($result = $db->sql_query($sql)) )
{
ExitWithHeader('500 Internal Server Error','Could not obtain lastvisit data from user table');
}
$userdata = $db->sql_fetchrow($result);
if(($user_id!=ANONYMOUS) && (!$userdata || ($password != $userdata['user_password'])))
{
ExitWithHeader('500 Internal Server Error','Error while create session');
}
$login=( $user_id != ANONYMOUS )?1:0;
//
// Initial ban check against user id, IP and email address
//
preg_match('/(..)(..)(..)(..)/', $user_ip, $user_ip_parts);
$sql = "SELECT ban_ip, ban_userid, ban_email
FROM " . BANLIST_TABLE . "
WHERE ban_ip IN ('" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . $user_ip_parts[4] . "', '" . $user_ip_parts[1] . $user_ip_parts[2] . $user_ip_parts[3] . "ff', '" . $user_ip_parts[1] . $user_ip_parts[2] . "ffff', '" . $user_ip_parts[1] . "ffffff')
OR ban_userid = $user_id";
if ( $user_id != ANONYMOUS )
{
$sql .= " OR ban_email LIKE '" . str_replace("\'", "''", $userdata['user_email']) . "'
OR ban_email LIKE '" . substr(str_replace("\'", "''", $userdata['user_email']), strpos(str_replace("\'", "''", $userdata['user_email']), "@")) . "'";
}
if ( !($result = $db->sql_query($sql)) )
{
ExitWithHeader("500 Internal Server Error","Could not obtain ban information");
}
if ( $ban_info = $db->sql_fetchrow($result) )
{
if ( $ban_info['ban_ip'] || $ban_info['ban_userid'] || $ban_info['ban_email'] )
{
ExitWithHeader("403 Forbidden","You been banned");
}
}
list($sec, $usec) = explode(' ', microtime());
mt_srand((float) $sec + ((float) $usec * 100000));
$session_id = md5(uniqid(mt_rand(), true));
$sql = "INSERT INTO " . SESSIONS_TABLE . "
(session_id, session_user_id, session_start, session_time, session_ip, session_page, session_logged_in, session_admin)
VALUES ('$session_id', $user_id, $current_time, $current_time, '$user_ip', $page_id, $login, 0)";
if ( !$db->sql_query($sql) )
{
ExitWithHeader("500 Internal Server Error","Error creating new session");
}
$last_visit = ( $userdata['user_session_time'] > 0 ) ? $userdata['user_session_time'] : $current_time;
$sql = "UPDATE " . USERS_TABLE . " SET user_session_time = $current_time, user_session_page = $page_id, user_lastvisit = $last_visit ";
if(LV_MOD_INSTALLED) $sql.= ",user_lastlogon=$current_time, user_totallogon=user_totallogon+1";
$sql .=" WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
ExitWithHeader("500 Internal Server Error",'Error updating last visit time');
}
$userdata['user_lastvisit'] = $last_visit;
$userdata['session_id'] = $session_id;
$userdata['session_ip'] = $user_ip;
$userdata['session_user_id'] = $user_id;
$userdata['session_logged_in'] = $login;
$userdata['session_page'] = $page_id;
$userdata['session_start'] = $current_time;
$userdata['session_time'] = $current_time;
$userdata['session_admin'] = 0;
$userdata['session_key']='';
$SID = 'sid=' . $session_id;
define('TEMP_SESSION',true);
return $userdata;
}
function rss_session_end()
{
global $db, $userdata;
$session_id=$userdata['session_id'];
$user_id=$userdata['user_id'];
$sql = 'DELETE FROM ' . SESSIONS_TABLE . "
WHERE session_id = '$session_id'
AND session_user_id = $user_id";
if ( !$db->sql_query($sql) )
{
ExitWithHeader("500 Internal Server Error","Error delete session");
}
}
function rss_get_user()
{
global $db, $HTTP_SERVER_VARS, $HTTP_GET_VARS;
if((!isset($HTTP_SERVER_VARS['PHP_AUTH_USER']) || !isset($HTTP_SERVER_VARS['PHP_AUTH_PW']))
&& isset($HTTP_SERVER_VARS['REMOTE_USER']) && preg_match('/Basic\s+(.*)$/i', $HTTP_SERVER_VARS['REMOTE_USER'], $matches)) {
list($name, $password) = explode(':', base64_decode($matches[1]), 2);
$HTTP_SERVER_VARS['PHP_AUTH_USER'] = strip_tags($name);
$HTTP_SERVER_VARS['PHP_AUTH_PW'] = strip_tags($password);
}
if (isset($HTTP_SERVER_VARS['PHP_AUTH_USER']) && isset($HTTP_SERVER_VARS['PHP_AUTH_PW'])) {
$username=phpbb_clean_username($HTTP_SERVER_VARS['PHP_AUTH_USER']);
$password=md5($HTTP_SERVER_VARS['PHP_AUTH_PW']);
if(isset($HTTP_GET_VARS['uid'])){
$uid=intval($HTTP_GET_VARS['uid']);
$sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = $uid";
}
else
$sql = "SELECT user_id, username, user_password, user_active, user_level
FROM " . USERS_TABLE . "
WHERE username = '" . str_replace("\\'", "''", $username) . "'";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
}
if( $row = $db->sql_fetchrow($result) )
{
if( $password == $row['user_password'] && $row['user_active'] )
{
// Yes!!! It's good user
return $row['user_id'];
}
else GetHTTPPasswd();
}
}
else GetHTTPPasswd();
return ANONYMOUS;
}
?>
|
Code: |
<?php
// rss_config.php
// RSS Feed configuration file - part of RSS Feed MOD ver. 2.2.2+
// Copyright (c) 2004-2005, Egor Naklonyaeff
if ( !defined('IN_PHPBB') )
{
die("Hacking attempt");
}
define('CACHE_TIME',300); // Cache time for RSS feed in sec, 5 min by default
// Set to zero to disable cache (Not recomendated).
define('AUTOSTYLED',true); // Use XSLT transformation in MSIE by default
define('CACHE_TO_FILE', true); // Use cache dir for caching default page. You MUST set 777 to that dir first
define('UPDATE_VIEW_COUNT',true); // Update count of viewed topics for non-Anonymous user
// If set to false disable Who viewed a topic update too
define('AUTO_WVT_MOD', true); // Who viewed a topic [2.0.6/EM]
define('LV_MOD_INSTALLED',false); // Last visit [2.0.10/EM] http://mods.db9.dk/
define('DEFAULT_ITEMS',10); // How many items parsed in feed by default
define('MAX_ITEMS',10); // Max number of parsed items
define('AUTOLOGIN',true); // Try to autologin using cookie if user not set 'login' or 'uid' key
define('SEE_MODIFYED',true); // Include in feed modified from last visit record in addition to new records
define('MAX_WEEKS_AGO',1); // Limit RSS feed by time. Most important in large forums (!)
// Set to zero if you don't want use this futures
$show_time=true; // Show total script time in RSS comments.
$unauthed='0'; // Comma separated list of unauthed forums. For ex.: '0,1,11';
$cache_root = 'cache/'; // Cache dir
$cache_filename="rss.xml";
// Config Page generation method
define('SMARTOR_STATS',true); // Set to true if you use page generation time mod
?>
|
_________________ http://www.jlaforums.com |
|
Back to top |
|
|
drathbun Board Member
Joined: 24 Jul 2008
Posts: 729 Location: Texas
|
Posted: Wed Sep 02, 2009 11:32 am Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
The parameters from the query come only from the config file? Or do you customize them with a URL in some way? _________________ phpBBDoctor Blog |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
|
Back to top |
|
|
drathbun Board Member
Joined: 24 Jul 2008
Posts: 729 Location: Texas
|
Posted: Wed Sep 02, 2009 1:37 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Yes.
The conditions on a query can sometimes alter (for better or worse) the query plan, which can have an impact on the performance. _________________ phpBBDoctor Blog |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Wed Sep 02, 2009 3:35 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
drathbun wrote: | Yes.
The conditions on a query can sometimes alter (for better or worse) the query plan, which can have an impact on the performance. |
Well this is these are the only conditions we would need to use
Being
F=(whichever forum the rss is being called for)
T=(I think it is only calling new topics and not topic replies)
Thanks _________________ http://www.jlaforums.com |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Thu Oct 01, 2009 11:15 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Any further ideas on this?
Thanks! _________________ http://www.jlaforums.com |
|
Back to top |
|
|
drathbun Board Member
Joined: 24 Jul 2008
Posts: 729 Location: Texas
|
Posted: Sat Oct 10, 2009 5:41 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
Hi, JLA, thanks for being patient. My new job has been occupying a lot of my time and I am preparing for two different conferences over the next two weeks. Lots going on in other words, and not much time for fun stuff. _________________ phpBBDoctor Blog |
|
Back to top |
|
|
JLA Board Member
Joined: 30 Apr 2009
Posts: 451 Location: U.S.A
|
Posted: Thu Feb 04, 2010 7:41 pm Post subject: Re: Problems with RSS Mod for PHPBB2 |
|
|
By chance might you or anyone else have some time to assist with this one?
Thanks _________________ http://www.jlaforums.com |
|
Back to top |
|
|
|
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.1344 seconds using 16 queries. (SQL 0.0240 Parse 0.0015 Other 0.1089) |
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com
|
|