Похожие темы

Похожие темы 1.1.0

в топик пхп в конец, перед принт тпл

PHP:
// Похожие темы НАЧАЛО
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) . "%'";

      $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
            GROUP BY t.topic_title LIMIT 0,8";
      if ( !($result = DB()->sql_query($sql)) )
      {
          bb_die("Could not get main information for similar topics");
      }
      $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="'. "viewtopic.php?". POST_TOPIC_URL .'='. $similar[$i]['topic_id'] .'">'. $title . '</a>';

            $poster_url = "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 = "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,
            'ROW_CLASS'   => !($i % 2) ? 'row1' : 'row2',
            ));
          }
      }
    }
// Похожие темы КОНЕЦ

в топик тпл перед <!-- IF QUICK_REPLY -->

HTML:
<!-- Похожие темы НАЧАЛО -->
    <!-- BEGIN similar -->
    <table width="100%" class="forumline">
    <thead>
    <tr>
        <th width="20%"><b>{L_FORUM}</b></th>
        <th width="65%"><b>{L_TOPIC}</b></th>
        <th width="80"><b>{L_AUTHOR}</b></th>
        <th width="80"><b>{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 -->
<!-- Похожие темы КОНЕЦ -->

правда есть минус +1 запрос в топике

ланги

// Похожие темы НАЧАЛО
$lang['SIMILAR'] = 'Похожие темы';
// Похожие темы КОНЕЦ
 
Last edited:
Адаптирован под 2.4.x и исправный
PHP:
Открыть viewtopic.php и найти
------------------------------------------------------------
print_page('viewtopic.tpl');
------------------ Перед ставить ---------------------------
// Похожие темы НАЧАЛО
if (!empty($t_data['allow_reg_tracker']))
{
    // Обрезаем название темы для поиска
    $title = (strlen($topic_title) > 10) ? substr($topic_title, 0, 10) : $topic_title;
    $title = DB()->escape($title);

    $topic_id = intval($topic_id);

    $sql = "
        SELECT
            t.topic_id,
            t.topic_title,
            u.user_id,
            u.username,
            f.forum_id,
            f.forum_name,
            tor.size
        FROM " . BB_TOPICS . " t
        INNER JOIN " . BB_BT_TORRENTS . " tor ON tor.topic_id = t.topic_id
        INNER JOIN " . BB_FORUMS . " f ON f.forum_id = t.forum_id
        INNER JOIN " . BB_USERS . " u ON u.user_id = t.topic_poster
        WHERE t.topic_id != $topic_id
          AND f.allow_reg_tracker = 1
          AND t.topic_title LIKE '%$title%'
        ORDER BY t.topic_time DESC
        LIMIT 8
    ";

    if (!($result = DB()->sql_query($sql))) {
        bb_die("Could not get similar topics");
    }

    $similar = [];
    while ($row = DB()->sql_fetchrow($result)) {
        $similar[] = $row;
    }

    $count_similar = count($similar);

    if ($count_similar > 0) {
        $template->assign_block_vars('similar', []);

        if ($count_similar > 2) {
            $page_cfg['use_tablesorter'] = true;
        }

        foreach ($similar as $i => $row) {
            $title = str_short($row['topic_title'], 200);
            $topic_url = '<a title="' . htmlspecialchars($row['topic_title']) . '" href="viewtopic.php?' . POST_TOPIC_URL . '=' . $row['topic_id'] . '">' . $title . '</a>';

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

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

            $tor_size = humn_size($row['size']);

            $template->assign_block_vars('similar.topics', [
                'TOPICS'    => $topic_url,
                'AUTHOR'    => $poster_username,
                'FORUM'     => $forum,
                'TOR_SIZE'  => $tor_size,
                'ROW_CLASS' => ($i % 2 === 0) ? 'row1' : 'row2',
            ]);
        }
    }
}
// Похожие темы КОНЕЦ

HTML:
Открыть viewtopic.tpl b и найти
------------------------------------------------------------
<!-- IF QUICK_REPLY -->
------------------ Перед ставить ---------------------------

<!-- Похожие темы НАЧАЛО -->
    <!-- BEGIN similar -->
    <table width="100%" class="forumline">
    <thead>
    <tr>
        <th width="20%"><b>{L_FORUM}</b></th>
        <th width="65%"><b>{L_TOPIC}</b></th>
        <th width="80"><b>{L_AUTHOR}</b></th>
        <th width="80"><b>{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 -->
<!-- Похожие темы КОНЕЦ -->

PHP:
Открыть library/language/ru/main.php и самый внизу ставить

// Похожие темы НАЧАЛО
$lang['SIMILAR'] = 'Похожие темы';
// Похожие темы КОНЕЦ
 
Last edited:
Обязательно добавь кэширование запроса хотя бы на час
 
Last edited:
Back
Top