Требует RSS Feed 2.2.1
Код: Выделить всё
<?php
/***************************************************************************
* shoutbox_rss.php
* -------------------
* begin : Mon, March 19, 2005
* copyright : (c) 2005, Egor Naklonyaeff
* email : chyduskam@debilarius.ru
*
* $Id: shoutbox_rss.php,v 1.0.0 2005/03/19 01:20: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.
****************************************************************************/
$ProgName='RSS Feed ShoutBox 1.0.0';
$verinfo='V100';
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
// Set the relative path from this file to your phpBB root folder
$phpbb_root_path = './';
//
// BEGIN Includes of phpBB scripts
//
define ('IN_PHPBB', true);
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);
//
// END Includes of phpBB scripts
//
$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;
$needlogin=( (isset($HTTP_GET_VARS['login'])) or (isset($HTTP_GET_VARS['uid']))) ? true : false;
$no_limit=( isset($HTTP_GET_VARS['nolimit']) ) ? true : false;
$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");
}
}
//
// gzip_compression
//
$do_gzip_compress = FALSE;
$useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $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
// BEGIN Session management
//
// Check user
$user_id=($needlogin)? rss_get_user() : ANONYMOUS;
if($user_id==ANONYMOUS && AUTOLOGIN)
{
$userdata = session_pagestart($user_ip, PAGE_SHOUTBOX);
$user_id=$userdata["user_id"];
}
else $userdata=rss_session_begin($user_id, $user_ip, PAGE_SHOUTBOX);
init_userprefs($userdata);
$username=$userdata["username"];
//
// END session management
//
// Create main board url (some code borrowed from functions_post.php)
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
$site = ( $script_name != '' ) ? $script_name . '/shoutbox_max.' . $phpEx : 'shoutbox_max.'. $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']) . '/' : '/';
$site_name = strip_tags($board_config['sitename']);
$site_description = strip_tags($board_config['site_desc']);
$index_site = $server_protocol . $server_name . $server_port . $site;
$index_url = $server_protocol . $server_name . $server_port . (( $script_name != '' )? $script_name . '/':'');
$smilies_path = $board_config['smilies_path'];
$smilies_url = $index_url . $smilies_path;
$smilies_path = preg_replace("/\//", "\/", $smilies_path);
//
// 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());
}
$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_site,
'BOARD_TITLE' => htmlspecialchars(undo_htmlspecialchars($lang['Shoutbox']."::".$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'],
'LANGUAGE'=>FormatLanguage($user_lang),
'L_POST' => $lang['Post'])
);
// Define censored word matches
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
if(($deadline>0) && (!$nolimit))
{
$sql_limit_time="AND s.shout_session_time>$deadline";
$NotErrorFlag=true;
}
else
{
$sql_limit_time="";
$NotErrorFlag=false;
}
$sql = "SELECT s.*, u.user_allowsmile, u.username FROM " . SHOUTBOX_TABLE . " s, ".USERS_TABLE." u
WHERE s.shout_user_id=u.user_id
$sql_limit_time
ORDER BY s.shout_session_time DESC LIMIT $count";
if ( !($result = $db->sql_query($sql)) )
{
ExitWithHeader('500 Internal Server Error','Could not get shoutbox information');
}
$allposts = $db->sql_fetchrowset($result);
$LastPostTime=0;
if ( count($allposts) == 0 )
{
if($NotErrorFlag) ExitWithHeader('304 Not Modified');
}
else
{
foreach ($allposts as $shout_row)
{
if( $shout_row['shout_session_time']>$LastPostTime) $LastPostTime=$shout_row['shout_session_time'];
$user_id = $shout_row['shout_user_id'];
$username = ( $user_id == ANONYMOUS ) ? (( $shout_row['shout_username'] == '' ) ? $lang['Guest'] : $shout_row['shout_username'] ) : $shout_row['username'] ;
$shout = (! $shout_row['shout_active']) ? $shout_row['shout_text'] : $lang['Shout_censor'].(($is_auth['auth_mod']) ? '<br/><hr/><br/>'.$shout_row['shout_text'] : '');
if ( $board_config['allow_smilies'] && $shout_row['user_allowsmile'] && $shout != '' & $shout_row['enable_smilies'])
{
$shout = smilies_pass($shout);
$shout = preg_replace("/$smilies_path/", $smilies_url, $shout);
}
$shout = bbencode_second_pass($shout,$shout_row['shout_bbcode_uid']);
$shout = preg_replace($orig_word, $replacement_word, $shout);
$shout = str_replace("\n", "\n<br />\n", $shout);
$shout = make_clickable($shout);
$template->assign_block_vars('post_item', array(
'POST_URL' => $index_site. '#' . $shout_row['shout_id'],
'FIRST_POST_URL' => $index_site. '#' . $shout_row['shout_id'],
'REPLY_URL'=>$index_site. '#' . $shout_row['shout_id'],
'TOPIC_TITLE' =>create_date($board_config['default_dateformat'], $shout_row['shout_session_time'], $board_config['board_timezone']),
'AUTHOR0' => htmlspecialchars($username),
'AUTHOR' => htmlspecialchars($username),
'POST_TIME' => create_date($board_config['default_dateformat'], $shout_row['shout_session_time'], $board_config['board_timezone']).' (GMT ' . $board_config['board_timezone'] . ')',
'ATOM_TIME'=>gmdate("Y-m-d\TH:i:s", $shout_row['shout_session_time'])."Z",
'ATOM_TIME_M'=>gmdate("Y-m-d\TH:i:s", $shout_row['shout_session_time'])."Z",
'POST_SUBJECT' =>"" ,
'FORUM_NAME' => htmlspecialchars($lang['Shoutbox']),
'UTF_TIME'=>RSSTimeFormat($shout_row['shout_session_time'],$userdata['user_timezone']),
'POST_TEXT' => htmlspecialchars(preg_replace('|[\x00-\x08\x0B\x0C\x0E-\x1f]|','',$shout)),
'USER_SIG' => "",
'TOPIC_REPLIES' => ""
)
);
}
}
// Check for E-Tag
$MyETag='"A'.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 Output XML page
//
$template->pparse('body');
$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;
}
echo ' - '. $gzip_text.' -->';
}
$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;
?>