Файл я переименовал в topics_any.php.
Из него выкинуты фрагменты, которые отвечали за генерацию JavaScripta, который затем надо размещать на странице, где будут выводиться последние поднятые темы форума.
Также все текстовые переменные не загружаются из lang_main, а прописываются непосредственно в самой програмке.
Кроме того сократил и оптимизировал тут ещё разные вещи, но от времени уже позабыл что конкретно.
После всех этих манипуляций работать стало существенно быстрее. Отмечается даже на глаз.
<?php
// topics_anywhere.php,v 1.8.0 2003/06/20
$full_url = 'http://путь к Вашему форуму';
$date_formats = array('d/m/y', 'd/m/Y', 'd/m/Y H:i:s', 'D d-M-y', 'D d-M-Y', 'D d-M-Y H:i:s', 'l d F Y', 'l d F Y H:i:s');
$bullets = array('<span class="nav1">»</span>', '<span class="nav1">»</span>', '<span class="nav1">»</span>', '<span class="nav1">»</span>', '<span class="nav1">»</span>', '<span class="nav1">»</span>', '<span class="nav1">»</span>');
$topics_anywhere_authlevel = 1;
$hide_forums = array();
define('IN_PHPBB', true);
$phpbb_root_path = './';
// Там, где многоточия введите данные из Вашего config.php
$dbname = '...';
$dbuser = '...';
$dbpasswd = '...';
$table_prefix = '...';
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
if(!$db->db_connect_id) {
message_die(CRITICAL_ERROR, "Could not connect to the database");
}
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
define('TA_SCRIPT_NAME', 'topics_anywhere');
function output_die($msg) {
$error = true;
$msg = '<font color="red"><b>' . $msg . '<br>Use the Topics Anywhere link builder again - browse to topics_anywhere.</b><br><br></font>';
exit("document.writeln('$msg');\n");
}
if ($HTTP_GET_VARS['mode'] == "show")
{
if ($board_config['board_disable'])
{
$msg = 'Извините, форум временно отключен.';
exit("document.writeln('$msg');\n");
}
$error = false;
$errorstring = '';
if (!isset($HTTP_GET_VARS['f']) || $HTTP_GET_VARS['f'] == '') {
$error = true;
$errorstring .= 'Error: Missing argument (forum_id)<br>';
}
else {
if (is_numeric($HTTP_GET_VARS['f']))
{
if (sizeof($hide_forums)) {
if (in_array(intval($HTTP_GET_VARS['f']), $hide_forums)) {
$error = true;
$errorstring .= 'Error: Not allowed to show topics from this forum<br>';
}
else {
$forum_id = intval($HTTP_GET_VARS['f']);
$forum_sql = "AND t.forum_id = $forum_id";
}
}
else {
$forum_id = intval($HTTP_GET_VARS['f']);
$forum_sql = "AND t.forum_id = $forum_id";
}
}
else {
if ($HTTP_GET_VARS['f'] == 'a') {
if (sizeof($hide_forums)) {
$hidelist = "(" . implode(",", $hide_forums) . ")";
$forum_sql = 'AND t.forum_id NOT IN ' . $hidelist;
}
else {
$forum_sql = '';
}
}
else
{
if (substr($HTTP_GET_VARS['f'], 0, 1) == 'b') {
$forumlist = base64_decode(substr($HTTP_GET_VARS['f'], 1));
$forum_sql = "AND t.forum_id in $forumlist";
}
else {
$error = true;
$errorstring .= 'Error: Wrong argument (forum_id)<br>';
}
}
}
}
if (!isset($HTTP_GET_VARS['n']) || $HTTP_GET_VARS['n'] == '') {
$error = true;
$errorstring .= 'Error: Missing argument (limit)<br>';
}
else {
if (is_numeric($HTTP_GET_VARS['n'])) {
$limit = intval($HTTP_GET_VARS['n']);
}
else {
$error = true;
$errorstring .= 'Error: Wrong argument (limit)<br>';
}
}
if (!$error)
{
$outputarray = array();
$target_link = ' target="_self"';
if (isset($HTTP_GET_VARS['t'])) {
if ($HTTP_GET_VARS['t'] != '') {
$target_link = ' target="' . $HTTP_GET_VARS['t'] . '"';
}
else {
$error = true;
output_die('Error: No value for argument (target_link)<br>');
}
}
if (isset($HTTP_GET_VARS['so']) && $HTTP_GET_VARS['so'] == 'd') {
if (isset($HTTP_GET_VARS['a'])) {
if ($HTTP_GET_VARS['a'] == 'y') {
$announce_sql = '';
}
else {
$error = true;
output_die('Error: Wrong value for argument (announcement)<br>');
}
}
else {
$announce_sql = 'AND t.topic_type <> ' . POST_ANNOUNCE;
}
if (isset($HTTP_GET_VARS['s'])) {
if ($HTTP_GET_VARS['s'] == 'y') {
$sticky_sql = '';
}
else {
$error = true;
output_die('Error: Wrong value for argument (sticky)<br>');
}
}
else {
$sticky_sql = "AND t.topic_type <> " . POST_STICKY;
}
if (isset($HTTP_GET_VARS['l'])) {
if ($HTTP_GET_VARS['l'] == 'y') {
$locked_sql = '';
}
else {
$error = true;
output_die('Error: Wrong value for argument (locked)<br>');
}
}
else {
$locked_sql = "AND t.topic_status <> " . TOPIC_LOCKED;
}
if (isset($HTTP_GET_VARS['m'])) {
if ($HTTP_GET_VARS['m'] == 'y') {
$locked_sql = '';
}
else {
$error = true;
output_die('Error: Wrong value for argument (moved)<br>');
}
}
else {
$moved_sql = "AND t.topic_status <> " . TOPIC_MOVED;
}
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time, f.forum_name
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2, " . FORUMS_TABLE . " f
WHERE t.topic_poster = u.user_id
$forum_sql
AND p.post_id = t.topic_first_post_id
AND p2.post_id = t.topic_last_post_id
AND t.forum_id = f.forum_id
AND u2.user_id = p2.poster_id
$announce_sql
$sticky_sql
$locked_sql
$moved_sql
ORDER BY t.topic_last_post_id DESC
LIMIT $limit";
if ( !($result = $db->sql_query($sql)) ) {
$error = true;
output_die('General Error: Could not obtain topic information (topics sql)<br>');
}
$total_topics = 0;
while( $row = $db->sql_fetchrow($result) ) {
$topic_rowset[] = $row;
$total_topics++;
}
$db->sql_freeresult($result);
}
else {
if (isset($HTTP_GET_VARS['a'])) {
if ($HTTP_GET_VARS['a'] == 'y') {
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username, f.forum_name
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2, " . FORUMS_TABLE . " f
WHERE t.topic_poster = u.user_id
$forum_sql
AND p.post_id = t.topic_last_post_id
AND p.poster_id = u2.user_id
AND t.forum_id = f.forum_id
AND t.topic_type = " . POST_ANNOUNCE . "
ORDER BY t.topic_last_post_id DESC
LIMIT $limit";
if ( !($result = $db->sql_query($sql)) ) {
$error = true;
output_die('General Error: Could not obtain topic information (announce sql)<br>');
}
$topic_rowset = array();
$total_announcements = 0;
while( $row = $db->sql_fetchrow($result) ) {
$topic_rowset[] = $row;
$total_announcements++;
}
$db->sql_freeresult($result);
}
else {
$error = true;
output_die('Error: Wrong value for argument (announce)<br>');
}
}
else {
$topic_rowset = array();
$total_announcements = 0;
}
$max = $limit - $total_announcements;
if ($max < 1) {
$max = 0;
}
if (isset($HTTP_GET_VARS['s'])) {
if ($HTTP_GET_VARS['s'] == 'y') {
$sticky_sql = '';
}
else {
$error = true;
output_die('Error: Wrong value for argument (sticky)<br>');
}
}
else {
$sticky_sql = "AND t.topic_type <> " . POST_STICKY;
}
if (isset($HTTP_GET_VARS['l'])) {
if ($HTTP_GET_VARS['l'] == 'y') {
$locked_sql = '';
}
else {
$error = true;
output_die('Error: Wrong value for argument (locked)<br>');
}
}
else {
$locked_sql = "AND t.topic_status <> " . TOPIC_LOCKED;
}
if (isset($HTTP_GET_VARS['m'])) {
if ($HTTP_GET_VARS['m'] == 'y') {
$moved_sql = '';
}
else {
$error = true;
output_die('Error: Wrong value for argument (moved)<br>');
}
}
else {
$moved_sql = "AND t.topic_status <> " . TOPIC_MOVED;
}
if (isset($HTTP_GET_VARS['rt'])) {
if ($HTTP_GET_VARS['rt'] == 'n') {
$reg_sql = "AND t.topic_type <> " . POST_NORMAL;
}
else {
$error = true;
output_die('Error: Wrong value for argument (regular topics)<br>');
}
}
else {
$reg_sql = '';
}
if ($max)
{
$sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time, f.forum_name
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2, " . FORUMS_TABLE . " f
WHERE t.topic_poster = u.user_id
$forum_sql
AND p.post_id = t.topic_first_post_id
AND p2.post_id = t.topic_last_post_id
AND t.forum_id = f.forum_id
AND u2.user_id = p2.poster_id
AND t.topic_type <> " . POST_ANNOUNCE . "
$sticky_sql
$locked_sql
$moved_sql
$reg_sql
ORDER BY t.topic_type DESC, t.topic_last_post_id DESC
LIMIT $max";
if ( !($result = $db->sql_query($sql)) ) {
$error = true;
output_die('General Error: Could not obtain topic information (topics sql)<br>');
}
$total_topics = 0;
while( $row = $db->sql_fetchrow($result) ) {
$topic_rowset[] = $row;
$total_topics++;
}
$db->sql_freeresult($result);
}
$total_topics += $total_announcements;
}
// Define censored word matches
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);
$html_list = false;
$list_wrap_before = '';
$list_wrap_after = '';
if (isset($HTTP_GET_VARS['b']))
{
if ($HTTP_GET_VARS['b'] == 'dis' || $HTTP_GET_VARS['b'] == 'cir' || $HTTP_GET_VARS['b'] == 'squ' || $HTTP_GET_VARS['b'] == 'num')
{
$html_list = true;
switch($HTTP_GET_VARS['b']) {
case "dis":
$html_wrap_before = '<ul type="disc">';
$html_wrap_after = '</ul>';
break;
case "cir":
$html_wrap_before = '<ul type="circle">';
$html_wrap_after = '</ul>';
break;
case "squ":
$html_wrap_before = '<ul type="square">';
$html_wrap_after = '</ul>';
break;
case "num":
$html_wrap_before = '<ol type="1">';
$html_wrap_after = '</ol>';
break;
default:
break;
}
}
}
if ($html_wrap_before != '') {
array_push($outputarray, $html_wrap_before);
}
if($total_topics) {
for($i = 0; $i < $total_topics; $i++)
{
$topic_id = $topic_rowset[$i]['topic_id'];
$topic_title = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']) : $topic_rowset[$i]['topic_title'];
$replies = $topic_rowset[$i]['topic_replies'];
$topic_type = $topic_rowset[$i]['topic_type'];
$forum_id = $topic_rowset[$i]['forum_id'];
$forum_name = $topic_rowset[$i]['forum_name'];
if( $topic_type == POST_ANNOUNCE ) {
if (isset($HTTP_GET_VARS['h'])) {
if (strstr($HTTP_GET_VARS['h'], 'a')) {
$topic_type = '';
}
else {
$topic_type = '<b>Объявление:</b> ';
}
}
else {
$topic_type = '<b>Объявление:</b> ';
}
}
else if( $topic_type == POST_STICKY )
{
if (isset($HTTP_GET_VARS['h']))
{
if (strstr($HTTP_GET_VARS['h'], 's')) {
$topic_type = '';
}
else {
$topic_type = '<b>Прилеплена:</b> ';
}
}
else {
$topic_type = '<b>Прилеплена:</b> ';
}
}
else {
$topic_type = '';
}
if( $topic_rowset[$i]['topic_vote'] ) {
if (isset($HTTP_GET_VARS['h'])) {
if (!strstr($HTTP_GET_VARS['h'], 'p')) {
$topic_type .= '<b>Опрос</b> ';
}
}
else {
$topic_type .= '<b>Опрос</b> ';
}
}
if( $topic_rowset[$i]['topic_status'] == TOPIC_MOVED )
{
if (isset($HTTP_GET_VARS['h'])) {
if (!strstr($HTTP_GET_VARS['h'], 'm')) {
$topic_type .= '<b>Перемещена</b> ';
}
}
else {
$topic_type .= '<b>Перемещена</b> ';
}
$topic_id = $topic_rowset[$i]['topic_moved_id'];
}
if( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED )
{
if (isset($HTTP_GET_VARS['h'])) {
if (!strstr($HTTP_GET_VARS['h'], 'l')) {
$topic_type .= '<b>Тема закрыта</b> ';
}
}
else {
$topic_type .= '<b>Тема закрыта</b> ';
}
}
$separator = ' - ';
if (isset($HTTP_GET_VARS['br'])) {
if ($HTTP_GET_VARS['br'] == 'y') {
$separator = '<br>';
}
}
$last_post_author = '';
if (isset($HTTP_GET_VARS['lpb']))
{
$last_post_author = ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ($topic_rowset[$i]['post_username2'] != '' ) ? $topic_rowset[$i]['post_username2'] . ' ' : 'Гость ' ) : $topic_rowset[$i]['user2'];
if (is_numeric($HTTP_GET_VARS['lpb']))
{
if (intval($HTTP_GET_VARS['lpb']) == 1) {
$last_post_author = $separator . 'Последнее сообщение ' . $last_post_author;
}
else {
$last_post_author = $separator . $last_post_author;
}
}
}
$in_forum = '';
if (isset($HTTP_GET_VARS['sfn']))
{
if ($HTTP_GET_VARS['sfn'] == 'y')
{
if (isset($HTTP_GET_VARS['fnl']))
{
if ($HTTP_GET_VARS['fnl'] == 'y') {
$view_forum_url = $full_url . "/viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
$in_forum = ' в <a href="' . $view_forum_url . '"' . $target_link . '>' . addslashes($forum_name) . '</a>';
}
else {
$in_forum = ' в ' . addslashes($forum_name);
}
}
else {
$in_forum = ' в ' . addslashes($forum_name);
}
}
else {
$error = true;
output_die('Error: Wrong value for argument (locked)<br>');
}
}
$last_post_time = '';
if (isset($HTTP_GET_VARS['lpd']))
{
if (is_numeric($HTTP_GET_VARS['lpd']))
{
if (intval($HTTP_GET_VARS['lpd']) < count($date_formats)) {
$last_post_time = create_date($date_formats[$HTTP_GET_VARS['lpd']], $topic_rowset[$i]['post_time'], $board_config['board_timezone']);
}
else {
$last_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['post_time'], $board_config['board_timezone']);
}
}
else {
$last_post_time = create_date($board_config['default_dateformat'], $topic_rowset[$i]['post_time'], $board_config['board_timezone']);
}
$last_post_time = ', ' . $last_post_time;
}
if (isset($HTTP_GET_VARS['r']))
{
if ($HTTP_GET_VARS['r'] == 'y')
{
if (isset($HTTP_GET_VARS['sr']))
{
if ($HTTP_GET_VARS['sr'] == 'y') {
$replies = ' (' . $replies . ' ' . (($replies == '1')? 'Ответ' : 'Ответов' ) . ')';
}
else {
$error = true;
output_die('Error: Wrong value for argument (showrepliesword)<br>');
}
}
else {
$replies = ' (' . $replies . ')';
}
}
else {
$error = true;
output_die('Error: Wrong value for argument (replies)<br>');
}
}
else {
$replies = '';
}
$view_topic_url = $full_url . "/viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
$views = $topic_rowset[$i]['topic_views'];
if (isset($HTTP_GET_VARS['ch']))
{
if (is_numeric($HTTP_GET_VARS['ch']))
{
$max_title_length = intval($HTTP_GET_VARS['ch']);
if ($max_title_length > 0)
{
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$topic_title = strtr($topic_title, $trans);
if (strlen($topic_title) > $max_title_length)
{
if (isset($HTTP_GET_VARS['chw']))
{
if ($HTTP_GET_VARS['chw'] == 'p') {
$topic_title = (strstr(strrev(substr($topic_title, 0, $max_title_length)), ' ')) ? strrev(strstr(strrev(substr($topic_title, 0, $max_title_length)), ' ')) . '...' : substr($topic_title, 0, $max_title_length) . '...';
}
else if ($HTTP_GET_VARS['chw'] == 'n') {
$topic_title_orig = $topic_title;
$topic_title = substr($topic_title_orig, 0, $max_title_length);
$lastpart = substr($topic_title_orig, strlen($topic_title));
if (strrpos(strrev($lastpart), ' ') === false) {
$topic_title = $topic_title_orig;
}
else {
$topic_title .= substr($lastpart, 0, -(strrpos(strrev($lastpart), ' '))) . '...';
}
}
else {
$topic_title = substr($topic_title, 0, $max_title_length) . '...';
}
}
else {
$topic_title = substr($topic_title, 0, $max_title_length) . '...';
}
}
$trans = array_flip($trans);
$topic_title = strtr($topic_title, $trans);
}
}
}
$item = $topic_type . '<a href="' . $view_topic_url . '"' . $target_link . '>' . addslashes($topic_title) . '</a>' . $in_forum . $replies . addslashes($last_post_author) . $last_post_time;
$last_post_url = ' <a href="' . $full_url . "/viewtopic.$phpEx?" . POST_POST_URL . '=' . $topic_rowset[$i]['topic_last_post_id'] . '#' . $topic_rowset[$i]['topic_last_post_id'] . '"' . $target_link . '><img src="' . $full_url . '/' . $images['icon_latest_reply'] . '" alt="Посмотреть последнее" title="Посмотреть последнее" border="0" /></a>';
if (isset($HTTP_GET_VARS['lpi'])) {
if ($HTTP_GET_VARS['lpi'] == 'y' && $HTTP_GET_VARS['b'] != 'lpi') {
$item = $item . $last_post_url;
}
}
if (isset($HTTP_GET_VARS['bl'])) {
if ($HTTP_GET_VARS['bl'] == 'y') {
$item = $item . '<br>';
}
}
if ($html_list) {
$item = '<li>' . $item . '</li>';
}
else
{
if (isset($HTTP_GET_VARS['b']))
{
if ($HTTP_GET_VARS['b'] == 'non') {
$item = $item . '<br>';
}
else if ($HTTP_GET_VARS['b'] == 'lpi') {
$item = $last_post_url . ' ' . $item . '<br>';
}
else if (is_numeric($HTTP_GET_VARS['b']))
{
if (intval($HTTP_GET_VARS['b']) < count($bullets)) {
$item = $bullets[intval($HTTP_GET_VARS['b'])] . ' ' . $item . '<br>';
}
else {
$error = true;
output_die('Error: Wrong value for argument (bullet)<br>');
}
}
else {
$error = true;
output_die('Error: Wrong value for argument (bullet)<br>');
}
}
}
if ($flag_topics_pub != "no") {
array_push($outputarray, $item);
}
}
}
else
{
if ($html_list) {
$item = '<li>' . 'Ни одного заголовка там нет.' . '</li>';
}
else {
if (isset($HTTP_GET_VARS['b'])) {
if ($HTTP_GET_VARS['b'] == 'non' || $HTTP_GET_VARS['b'] == 'lpi') {
$item = 'Ни одного заголовка там нет.<br>';
}
else if (is_numeric($HTTP_GET_VARS['b']))
{
if (intval($HTTP_GET_VARS['b']) < count($bullets)) {
$item = $bullets[intval($HTTP_GET_VARS['b'])] . ' Ни одного заголовка там нет.<br>';
}
else {
$error = true;
output_die('Error: Wrong value for argument (bullet)<br>');
}
}
}
}
array_push($outputarray, $item);
}
if ($html_wrap_before != '') {
array_push($outputarray, $html_wrap_after);
}
while ($item = array_shift($outputarray)) {
echo "document.writeln('$item');\n";
}
}
if ($error) {
output_die($errorstring);
}
}
?>