Для устновки требуется RSS Feed 2.2 или старше
Установка: Заменить фаил weblog_rss.php прилагаемым кодом.
Код: Выделить всё
<?php
/***************************************************************************
* weblog_rss.php
* --------------------
* begin : Monday, September 5, 2004
* copyright : (C) 2005 Hyperion, (c) Egor Naklonyaeff
*
* $Id: weblog_rss.php,v 1.0.0 2004/09/05, 13:17:43 Hyperion 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 Blog Feed 1.0.1';
$verinfo='V101';
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
define('IN_PHPBB', true);
$phpbb_root_path = './';
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);
$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;
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");
}
}
//
// Start session management
//
//
// 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_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
//
include($phpbb_root_path . 'includes/weblogs_common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_weblog.'.$phpEx);
//
// Start initial var setup
//
if( isset($HTTP_GET_VARS[POST_WEBLOG_URL]) || isset($HTTP_POST_VARS[POST_WEBLOG_URL]) )
{
$weblog_id = ( isset($HTTP_GET_VARS[POST_WEBLOG_URL]) ) ? intval($HTTP_GET_VARS[POST_WEBLOG_URL]) : intval($HTTP_POST_VARS[POST_WEBLOG_URL]);
$weblog_id = intval($weblog_id);
}
//
// Check if the user has actually sent a forum ID with his/her request
// If not give them a nice error page.
//
if( !empty($weblog_id) )
{
$sql = "SELECT w.*, u.user_id
FROM " . WEBLOGS_TABLE . " w, " . USERS_TABLE . " u
WHERE w.weblog_id = $weblog_id
AND u.user_weblog = w.weblog_id";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain weblogs information.", "", __LINE__, __FILE__, $sql);
}
}
else
{
message_die(GENERAL_MESSAGE, $lang['Weblog_not_exist']);
}
//
// If the query doesn't return any rows this isn't a valid forum. Inform
// the user.
//
if( !($weblog_data = $db->sql_fetchrow($result)) )
{
message_die(GENERAL_MESSAGE, $lang['Weblog_not_exist']);
}
if ( $weblog_data['deleted'] )
{
message_die(GENERAL_ERROR, sprintf($lang['Weblog_deactivated'], $weblog_data['weblog_name']));
}
// Get the user's clearence levels
$auth_level = get_auth_level ( $weblog_data, $friends_data, $blocked_data, $weblog_data['user_id'] );
// See if user can see this weblog
if ( $weblog_data['weblog_auth'] > $auth_level )
{
message_die(GENERAL_ERROR, $lang['Weblog_noaccess']);
}
//
// Get the owner's data
//
$sql = "SELECT * FROM " . USERS_TABLE . "
WHERE user_weblog = " . $weblog_data['weblog_id'];
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't get weblog owner information.", "", __LINE__, __FILE__, $sql);
}
$owner_data = array();
if ( $row = $db->sql_fetchrow($result) )
{
$owner_data = $row;
}
$NotErrorFlag=false;
$sql_limit_time="";
if (!$no_limit and isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])) {
$NotErrorFlag=true;
$NotModifiedSince=strtotime($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']);
if($NotModifiedSince>0){
$sql_limit_time="AND entry_time > ".$NotModifiedSince;
}
}
//
// Fetch Entries
//
$sql = "SELECT * FROM " . WEBLOG_ENTRIES_TABLE . "
WHERE weblog_id = " . $weblog_data['weblog_id'] . "
AND entry_access <= $auth_level
AND entry_deleted = 0
$sql_limit_time
ORDER BY entry_time DESC
LIMIT $count";
if(!($result = $db->sql_query($sql)))
{
ExitWithHeader("500 Internal Server Error","Could not query weblog entry information");
}
$entry_data = $db->sql_fetchrowset($picrow);
if ( count($entry_data) == 0 )
{
if($NotErrorFlag) ExitWithHeader("304 Not Modified");
else ExitWithHeader("404 Not Found","No records find");
}
//
// Start output of RSS
//
$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']) . '/' : '';
$script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
$basedir = $server_protocol . $server_name . '/' . $server_port . $script_name . '/';
$smilies_path = $board_config['smilies_path'];
$smilies_url = $basedir . $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=($board_config['default_lang']=='russian')?'ru':(($board_config['default_lang']=='english')?'en':'');
$user_lang=(($user_lang!='')?"\n<language>".$user_lang."</language>":"");
$template->assign_vars(array(
'S_CONTENT_ENCODING' => $lang['ENCODING'],
'BOARD_URL' => $basedir . "weblog.$phpEx?" . POST_WEBLOG_URL . "=$weblog_id",
'BOARD_TITLE' => htmlspecialchars($weblog_data['weblog_name']),
'PROGRAM' => $ProgName,
'BOARD_DESCRIPTION' => htmlspecialchars($weblog_data['weblog_desc']),
'BOARD_MANAGING_EDITOR' => $owner_data['user_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'=>$user_lang,
'L_POST' => $lang['Post'])
);
//
// Get the moods data
//
$sql = "SELECT *
FROM " . WEBLOG_MOODS_TABLE . "
ORDER BY mood_text";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain mood data from database", "", __LINE__, __FILE__, $sql);
}
$mood_data = $db->sql_fetchrowset($result);
//
// Get the actions data
//
$sql = "SELECT *
FROM " . WEBLOG_ACTIONS_TABLE . "
ORDER BY action_text";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Couldn't obtain action data from database", "", __LINE__, __FILE__, $sql);
}
$action_data = $db->sql_fetchrowset($result);
$LastPostTime=0;
for ($i = 0; $i < count($entry_data); $i++)
{
//
// Prepare every entry
//
If($entry_data[$i]['entry_time']>$LastPostTime) $LastPostTime=$entry_data[$i]['entry_time'];
// $entry_data[$i]['entry_text'] = htmlspecialchars($entry_data[$i]['entry_text']);
// BBCode
if ( $entry_data[$i]['enable_bbcode'] )
{
$entry_data[$i]['entry_text'] = bbencode_second_pass($entry_data[$i]['entry_text'], $entry_data[$i]['bbcode_uid']);
}
// Smilies
if ( $entry_data[$i]['enable_smilies'] )
{
$entry_data[$i]['entry_text'] = smilies_pass($entry_data[$i]['entry_text']);
$entry_data[$i]['entry_text'] =preg_replace("/$smilies_path/", $smilies_url, $entry_data[$i]['entry_text']);
}
$entry_data[$i]['entry_text'] = make_clickable($entry_data[$i]['entry_text']);
if ( !$weblog_config['censor_weblog'] )
{
// Define censored word matches
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
// Censor text and title
if (count($orig_word))
{
$entry_data[$i]['entry_subject'] = preg_replace($orig_word, $replacement_word, $entry_data[$i]['entry_subject']);
$entry_data[$i]['entry_text'] = preg_replace($orig_word, $replacement_word, $entry_data[$i]['entry_text']);
}
}
$entry_data[$i]['entry_text'] = nl2br($entry_data[$i]['entry_text']);
// Mood Icons
$mood = array();
$mood = find_mood($entry_data[$i]['entry_mood']);
if ( $mood >= 0 )
{
$mood = '<strong>[</strong> ' . sprintf($lang['Mood:'], '<img src="'.$basedir.'images/weblogs/' . $mood['mood_url'] . '" alt="' . $mood['mood_text'] . '" style="vertical-align: middle" border="0" />', $mood['mood_text']) . ' <strong>]</strong>
';
}
else
{
$mood = '';
}
// Currently Icons
$currently = array();
$currently = find_action($entry_data[$i]['entry_currently']);
if ( $currently > 0 )
{
$action = '<strong>[</strong> ' . sprintf($lang['Currently:'], '<img src="'.$basedir.'images/weblogs/' . $currently['action_url'] . '" alt="' . $currently['action_text'] . ' ' . $entry_data[$i]['currently_text'] . '" style="vertical-align: middle" border="0" />', $currently['action_text'] . ' ' . $entry_data[$i]['currently_text']) . ' <strong>]</strong>
';
}
else if ( $entry_data[$i]['currently_text'] && $currently == -2 )
{
$action = '<strong>[</strong>' . sprintf($lang['Currently:'], '', $entry_data[$i]['currently_text']) . ' <strong>]</strong>
';
}
else
{
$action = '';
}
$entry_data[$i]['entry_text'] = $mood . $action . $entry_data[$i]['entry_text'];
$entry_data[$i]['entry_text'] = trim ($entry_data[$i]['entry_text']);
// if (strlen($entry_data[$i]['entry_text']) > 1000)
// {
// $entry_data[$i]['entry_text'] = substr($entry_data[$i]['entry_text'], 0, 957) . '...';
// }
// Variable reassignment and reformatting for author
$entry_author = $owner_data['username'] . ' ' . $owner_data['user_email'];
$entry_link = $basedir . "weblog_entry.$phpEx?" . POST_ENTRY_URL . "=" . $entry_data[$i]['entry_id'];
$entry_time = $entry_data[$i]['topic_time'];
$template->assign_block_vars('post_item', array(
'POST_URL' => $entry_link ,
'FIRST_POST_URL' => $entry_link ,
'REPLY_URL'=>$entry_link,
'TOPIC_TITLE' =>$entry_data[$i]['entry_subject'],
'AUTHOR0' => $owner_data['username'],
'AUTHOR' => $owner_data['username'],
'POST_TIME' => create_date($board_config['default_dateformat'], $entry_data[$i]['entry_time'], $board_config['board_timezone']).' (GMT ' . $board_config['board_timezone'] . ')',
'ATOM_TIME'=>gmdate("Y-m-d\TH:i:s", $entry_data[$i]['entry_time'])."Z",
'ATOM_TIME_M'=>gmdate("Y-m-d\TH:i:s", $entry_data[$i]['entry_time'])."Z",
'POST_SUBJECT' => "",
'FORUM_NAME' => htmlspecialchars($weblog_data['weblog_name']),
'UTF_TIME'=>gmdate('D, d M Y H:i:s O', $entry_data[$i]['entry_time']),
'POST_TEXT' => htmlspecialchars($entry_data[$i]['entry_text']),
'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;
?>
Добавлено спустя 18 минут 20 секунд:
Как выяснилось, в первоисточнике еще и ссылки формировались как относительные, что непозволительно в RSS.
Исправил.