Похожие темы / Similar Topics

InKomen

Пользователь
Автор: Log
Описание мода: Мод выводит в конце страницы просмотра темы таблицу топиков, схожих по названию. (Поиск осуществляется и выводится только в DL-топиках)
Сложность установки: Легко
Время установки: ~ 2 минуты

Please Login or Register to view hidden text.



В viewtopic.php
найти:
Код:
print_page('viewtopic.tpl');
перед вставить:
Код:
// Похожие темы НАЧАЛО
if ($t_data['allow_reg_tracker'])
{
      $title = (strlen($topic_title) > 10) ? (substr($topic_title, 0, 10) . '') : $topic_title;
      $sgl_search = "t.topic_title LIKE '%" . addslashes($title) . "%'";

      $porno_forums = $bb_cfg['porno_forums'] ? $bb_cfg['porno_forums'] : '0';
      $trash_forums = $bb_cfg['trash_forum_id'] ? $bb_cfg['trash_forum_id'] : '0';

      $sql = "SELECT t.*, u.user_id, u.username, f.forum_id, f.forum_name, tor.size
            FROM ". BB_TOPICS ." t, ". BB_USERS ." u, ". BB_FORUMS ." f, ". BB_BT_TORRENTS ." tor
          WHERE t.topic_id != $topic_id
          AND tor.topic_id = t.topic_id
            AND $sgl_search
            AND f.allow_reg_tracker = 1
            AND t.forum_id = f.forum_id
            AND t.topic_poster = u.user_id
            AND f.forum_id NOT IN ($trash_forums, $porno_forums)
            GROUP BY t.topic_title LIMIT 0,8";
      if ( !($result = DB()->sql_query($sql)) )
      {
          message_die(GENERAL_ERROR, "Could not get main information for similar topics", '', __LINE__, __FILE__, $sql);
      }
      $similar = array();
      while ( $row = DB()->sql_fetchrow($result) )
      {
          $similar[] = $row;
      }
      $count_similar = count($similar);
      if ( $count_similar > 0)
      {
          $template->assign_block_vars('similar', array());

            if ($count_similar > 2)
            {
              $page_cfg['use_tablesorter'] = true;
            }
          for($i = 0; $i < $count_similar; $i++)
          {
            $title = wbr(str_short($similar[$i]['topic_title'], 200));
            $topic_url = '<a title="'.$similar[$i]['topic_title'].'" href="'. append_sid("viewtopic.php?". POST_TOPIC_URL .'='. $similar[$i]['topic_id']) .'">'. $title . '</a>';

            $poster_url = append_sid("profile.php?mode=viewprofile&amp;". POST_USERS_URL .'='. $similar[$i]['user_id']);
            $similar[$i]['username'] = wbr($similar[$i]['username']);
            $poster_username = '<a class="genmed" href="'. $poster_url .'">'. $similar[$i]['username'] .'</a>';

            $forum_url = append_sid("viewforum.php?f=". $similar[$i]['forum_id']);
            $forum = '<a class="genmed" href="'. $forum_url .'">'. $similar[$i]['forum_name'] .'</a>';

          $tor_size = humn_size($similar[$i]['size']);

            $template->assign_block_vars('similar.topics', array(
                'TOPICS'    => $topic_url,
                'AUTHOR'    => $poster_username,
                'FORUM'      => $forum,
            'TOR_SIZE'    => $tor_size,
            ));
          }
      }
    }
// Похожие темы КОНЕЦ

В viewtopic.tpl
найти:
Код:
<!-- IF QUICK_REPLY -->
<form action="{QR_POST_ACTION}" method="post" name="post" onsubmit="if(checkForm(this)){ dis_submit_btn(); }else{ return false; }">
перед вставить:
Код:
<!-- Похожие темы НАЧАЛО -->
    <!-- BEGIN similar -->
    <div class="cat pad_2"><center><b>{L_SIMILAR}</b></center></div>
    <table width="100%" class="forumline tablesorter">
    <thead>
    <tr>
        <th width="20%" class="{sorter: 'text'}"><b class="tbs-text">{L_FORUM}</b></th>
        <th width="65%" class="{sorter: 'text'}"><b class="tbs-text">{L_TOPIC}</b></th>
        <th width="80" class="{sorter: 'text'}"><b class="tbs-text">{L_AUTHOR}</b></th>    
        <th width="80" class="{sorter: 'text'}"><b class="tbs-text">{L_SIZE}</b></th>
    </tr>
    </thead>
    <!-- BEGIN topics -->
    <tr class="tCenter {similar.topics.ROW_CLASS}">
        <td>{similar.topics.FORUM}</td>    
        <td class="tLeft"><span class="topictitle">{similar.topics.TOPICS}</span></td>
        <td>{similar.topics.AUTHOR}</td>
        <td><b>{similar.topics.TOR_SIZE}</b></td>
    </tr>
    <!-- END topics -->
    </table>
    <div class="spacer_10"></div>
    <!-- END similar -->
<!-- Похожие темы КОНЕЦ -->

В lang_main.php в самом конце вставить:
Код:
// Похожие темы НАЧАЛО
$lang['SIMILAR'] = 'Похожие темы';
// Похожие темы КОНЕЦ

У меня все отлично работает, тестим.
 

Ragnar

Пользователь
PHP:
// Similar Topics
if ($t_data['allow_reg_tracker'])
{
      $title = (strlen($topic_title) > 10) ? (substr($topic_title, 0, 10) . '') : $topic_title;
      $sgl_search = "t.topic_title LIKE '%" . addslashes($title) . "%'";

      $porno_forums = $bb_cfg['porno_forums'] ? $bb_cfg['porno_forums'] : '0';
      $trash_forums = $bb_cfg['trash_forum_id'] ? $bb_cfg['trash_forum_id'] : '0';

      $sql = "SELECT t.*, u.*, f.*, u.*, u2.username as last_username, u2.user_id as last_user_id, tor.*, sn.seeders, sn.leechers
            FROM ". BB_TOPICS ." t, ". BB_USERS ." u, ". BB_FORUMS ." f, ". BB_POSTS ." p, ". BB_USERS ." u2, ". BB_BT_TORRENTS ." tor, ". BB_BT_TRACKER_SNAP ." sn
          WHERE t.topic_id != $topic_id
            AND $sgl_search
          AND tor.topic_id = t.topic_id
            AND f.allow_reg_tracker = 1
            AND t.forum_id = f.forum_id
            AND p.post_id = t.topic_last_post_id
            AND p.poster_id = u2.user_id
            AND t.topic_poster = u.user_id
            AND f.forum_id NOT IN ($trash_forums, $porno_forums)
            AND t.topic_id = tor.topic_id
            AND tor.topic_id = sn.topic_id
        GROUP BY t.topic_title LIMIT 0,8";
      if ( !($result = DB()->sql_query($sql)) )
      {
          message_die(GENERAL_ERROR, "Could not get main information for similar topics", '', __LINE__, __FILE__, $sql);
      }
      $similar = array();
      while ( $row = DB()->sql_fetchrow($result) )
      {
          $similar[] = $row;
      }
      $count_similar = count($similar);
      if ( $count_similar > 0)
      {
          $template->assign_block_vars('similar', array());

            if ($count_similar > 2)
            {
              $page_cfg['use_tablesorter'] = true;
            }
          for($i = 0; $i < $count_similar; $i++)
          {
            $title = wbr(str_short($similar[$i]['topic_title'], 200));
            $topic_url = '<a title="'.$similar[$i]['topic_title'].'" href="'. append_sid("viewtopic.php?". POST_TOPIC_URL .'='. $similar[$i]['topic_id']) .'">'. $title . '</a>';

            $author_url = append_sid("profile.php?mode=viewprofile&amp;". POST_USERS_URL .'='. $similar[$i]['user_id']);
            $similar[$i]['username'] = wbr($similar[$i]['username']);
            $poster_url = append_sid("profile.php?mode=viewprofile&amp;". POST_USERS_URL .'='. $similar[$i]['last_user_id']);
        $similar[$i]['last_username'] = wbr($similar[$i]['last_username']);

            $author_username = '<a class="genmed" href="'. $author_url .'">'. $similar[$i]['username'] .'</a>';
            $poster_username = '<a class="genmed" href="'. $poster_url .'">'. $similar[$i]['last_username'] .'</a>';

            $forum_url = append_sid("viewforum.php?f=". $similar[$i]['forum_id']);
            $forum = '<a class="genmed" href="'. $forum_url .'">'. $similar[$i]['forum_name'] .'</a>';

            $is_unread = is_unread($similar[$i]['topic_last_post_time'], $similar[$i]['topic_id'], $similar[$i]['forum_id']);

            $tor_size = humn_size($similar[$i]['size']);

            $template->assign_block_vars('similar.topics', array(
        'POST_ID'          => $similar[$i]['topic_first_post_id'],
        'TOPIC_ID'          => $similar[$i]['topic_id'],
        'TOPIC_TITLE'  => wbr($similar[$i]['topic_title']),
                'TOPICS'    => $topic_url,
                'AUTHOR'    => $author_username,
                'FORUM'      => $forum,
        'REPLIES'          => $similar[$i]['topic_replies'],
        'VIEWS'            => $similar[$i]['topic_views'],
        'POSTER'            => $poster_username,
        'LAST_POST_TIME'    => bb_date($similar[$i]['topic_last_post_time']),
        'LAST_POST_ID'      => $similar[$i]['topic_last_post_id'],
        'IS_UNREAD'        => $is_unread,
        'TOPIC_ICON'      => get_topic_icon($similar[$i], $is_unread),
        'PAGINATION'        => ($similar[$i]['topic_status'] == TOPIC_MOVED) ? '' : build_topic_pagination(TOPIC_URL . $similar[$i]['topic_id'], $similar[$i]['topic_replies'], $bb_cfg['posts_per_page']),
        'TOR_STATUS_ICON'  => isset($similar[$i]['tor_status']) ? $bb_cfg['tor_icons'][$similar[$i]['tor_status']] : '',
        'TOR_STATUS_TEXT'  => isset($similar[$i]['tor_status']) ? $lang['TOR_STATUS_NAME'][$similar[$i]['tor_status']] : '',
        'STATUS'          => $similar[$i]['topic_status'],
        'TYPE'            => $similar[$i]['topic_type'],
        'SEEDERS'          => $similar[$i]['seeders'],
        'LEECHERS'          => $similar[$i]['leechers'],
        'TOR_SIZE'    => $tor_size,
        'COMPL_CNT'        => $similar[$i]['complete_count'],
        'ATTACH_ID'        => $similar[$i]['attach_id'],
        'TOR_FROZEN'      => isset($similar[$i]['tor_status']) ? ((!IS_AM) ? isset($bb_cfg['tor_frozen'][$similar[$i]['tor_status']]) : '') : '',
            ));
          }
      }
    }
// Similar Topics [END]

PHP:
<!-- BEGIN similar -->
<script type="text/javascript">
ajax.openedPosts = {};

ajax.view_post = function(post_id, src) {
    if (!ajax.openedPosts[post_id]) {
        ajax.exec({
            action  : 'view_post',
            post_id : post_id
        });
    }
    else {
        var $post = $('#post_'+post_id);
        if ($post.is(':visible')) {
            $post.hide();
        }    else {
            $post.css({ display: '' });
        }
    }
    $(src).toggleClass('unfolded2');
};

ajax.callback.view_post = function(data) {
    var post_id = data.post_id;
    var $tor = $('#tor_'+post_id);
    window.location.href='#tor_'+post_id;
    $('#post-row tr')
        .clone()
        .attr({ id: 'post_'+post_id })
        .find('div.post_body').html(data.post_html).end()
        .find('a.tLink').attr({ href: $('a.tLink', $tor).attr('href') }).end()
        .find('a.dLink').attr({ href: $('a.tr-dl', $tor).attr('href') }).end()
        .insertAfter($tor)
    ;
    initPostBBCode('#post_'+post_id);
    var maxH  = screen.height - 290;
    var maxW  = screen.width - 60;
    var $post  = $('div.post_similar_wrap', $('#post_'+post_id));
    var $links = $('div.post_links', $('#post_'+post_id));
    $post.css({ maxWidth: maxW, maxHeight: maxH });
    $links.css({ maxWidth: maxW });
    if ($.browser.msie) {
        if ($post.height() > maxH) { $post.height(maxH); }
        if ($post.width() > maxW)  { $post.width(maxW); $links.width(maxW); }
    }
    ajax.openedPosts[post_id] = true;
};
</script>

<style type="text/css">
.post_similar_wrap { border: 1px #A5AFB4 solid; margin: 8px 8px 6px; overflow: auto; }
.post_links { margin: 6px; }
.unfolded2, .folded2 { display: block; }
</style>

<table id="post-row" style="display: none;">
<tr>
    <td class="row2" colspan="8">
        <div class="post_similar_wrap row1">
            <div class="post_body pad_6"></div>
            <div class="clear"></div>
        </div>
        <div class="post_links med bold tCenter"><a class="tLink">{L_OPEN_TOPIC}</a> &nbsp;&#0183;&nbsp; <a class="dLink">{L_DL_TORRENT}</a></div>
    </td>
</tr>
</table>
<div class="spacer_10"></div>
    <div class="cat pad_2"><center><b>{L_SIMILAR}</b></center></div>
    <table width="100%" class="forumline tablesorter">
    <thead>
    <tr>
    <th class="{sorter: 'text'}"></th>
    <th class="{sorter: 'text'}"></th>
        <th width="20%" class="{sorter: 'text'}"><b class="tbs-text">{L_FORUM}</b></th>
        <th width="65%" class="{sorter: 'text'}"><b class="tbs-text">{L_TOPIC}</b></th>
        <th width="80" class="{sorter: 'text'}"><b class="tbs-text">{L_AUTHOR}</b></th>
    <th class="{sorter: false}">{L_TORRENT}</th>
    <th class="{sorter: false}">{L_REPLIES_SHORT}</th>
    <th width="120" class="{sorter: 'text'} nowrap"><b class="tbs-text">{L_LASTPOST}</b></th>
    </tr>
    </thead>
<!-- BEGIN topics -->
<tr class="tCenter row1 med" {similar.topics.ROW_CLASS}">
    <td>
            <span style="display: none;">{similar.topics.TOPIC_ICON}</span>
            <img src="{similar.topics.TOPIC_ICON}">
    </td>
    <td>
        <!-- IF similar.topics.TOR_STATUS_ICON --><span id="status-{similar.topics.TOPIC_ID}" title="{similar.topics.TOR_STATUS_TEXT}">{similar.topics.TOR_STATUS_ICON}</span><!-- ENDIF -->
    </td>
        <td>{similar.topics.FORUM}</td>
    <td class="tLeft">
        <a class="folded2 tLink" onclick="ajax.view_post({similar.topics.POST_ID}, this); return false;" href="{TOPIC_URL}{similar.topics.TOPIC_ID}"><!-- IF similar.topics.TOR_FROZEN -->{similar.topics.TOPIC_TITLE}<!-- ELSE --><b>{similar.topics.TOPIC_TITLE}</b><!-- ENDIF --></a>
        <!-- IF similar.topics.PAGINATION --><span class="topicPG">&nbsp;[{ICON_GOTOPOST}{L_GOTO_SHORT} {similar.topics.PAGINATION} ]</span><!-- ENDIF -->
    </td>
        <td>{similar.topics.AUTHOR}</td>
    <td class="tCenter nowrap" style="padding: 2px 4px;">
        <div title="{L_DL_TORRENT}">
            <div><span class="seedmed" title="{L_SEEDERS}"><b>{similar.topics.SEEDERS}</b></span><span class="med"> | </span><span class="leechmed" title="{L_LEECHERS}"><b>{similar.topics.LEECHERS}</b></span></div>
            <div style="padding-top: 2px" class="small"><!-- IF similar.topics.TOR_FROZEN -->{similar.TOR_SIZE}<!-- ELSE --><a href="{DOWNLOAD_URL}{similar.topics.ATTACH_ID}" class="tr-dl" style="text-decoration: none">{similar.topics.TOR_SIZE}</a><!-- ENDIF --></div>
        </div>
    <td class="tCenter small nowrap" style="padding: 3px 4px 2px;">
    <p>
        <span title="{L_REPLIES}">{similar.topics.REPLIES}</span>
        <span class="small"> | </span>
        <span title="{L_VIEWS}">{similar.topics.VIEWS}</span>
    </p>
    <p style="padding-top: 2px" class="med" title="{L_COMPLETED}">
        <b>{similar.topics.COMPL_CNT}</b>
    </p>
    </td>
    <td class="tCenter small nowrap">
        <div>{similar.topics.LAST_POST_TIME}</div>
        <a class="med">{similar.topics.POSTER}</a> <!-- IF similar.topics.IS_UNREAD --><a href="{TOPIC_URL}{similar.topics.TOPIC_ID}{NEWEST_URL}">{ICON_NEWEST_REPLY}</a><!-- ELSE -->
        <a href="{POST_URL}{similar.topics.LAST_POST_ID}#{similar.topics.LAST_POST_ID}">{ICON_LATEST_REPLY}</a><!-- ENDIF -->
    </td>
</tr>
<!-- END topics -->
</table>
<div class="spacer_10"></div>
<!-- END similar -->

Вот добавил вывод статусов, сидов+личеров, возможность скачивания, кол-ва скаченного и последнего поста, а таже аякс-предпросмотр (только он не работает). Ищет не все похожие темы.
http://s017.*******.host/i400/1112/c0/b77b92697112.jpg
Может кто допилит.
 

pilot

Пользователь
Здравствуйте, подскажите как сделать что бы вывод был как на тапках??? т.е в viewtopic_attach.tpl а не в viewtopic.tpl
 

Basilevs

Пользователь
krumax, они завернули в спойлер и пристроили под таблицу.

pilot, просто найдите кусок, где torrent_reg и добавьте вывод после таблицы.
 
Сверху