TinyPortal

Development => Support => Topic started by: jernatety on March 09, 2019, 12:25:26 PM

Title: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 09, 2019, 12:25:26 PM
Thanks to Mick he got me situated with my block code. Works perfectly.

I do have a question though. It's currently coded to show most viewed topics. Is there a way to make it show all most recent topics with views over 1000? I only want the most viewed topics from one board "board=85.0"

This is the current code.

$array = ssi_topTopicsViews(15,'array');

foreach ($array as $topic) {

echo

$topic['link'];

echo '
<div align="center"><a href="', $topic['href'], '">', $news['subject'], '</a><hr></div>';


}
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: tino on March 10, 2019, 03:33:47 PM
That already orders based on views and uses the internal SSI functionality.

You can edit that and change it so that it looks for > 1000 views.

Find this;


$request = $smcFunc['db_query']('', '
SELECT id_topic
FROM {db_prefix}topics
WHERE num_' . ($type != 'replies' ? 'views' : 'replies') . ' != 0' . ($modSettings['postmod_active'] ? '
AND approved = {int:is_approved}' : '') . '
ORDER BY num_' . ($type != 'replies' ? 'views' : 'replies') . ' DESC
LIMIT {int:limit}',
array(
'is_approved' => 1,
'limit' => $num_topics > 100 ? ($num_topics + ($num_topics / 2)) : 100,
)
);


Change to


$request = $smcFunc['db_query']('', '
SELECT id_topic
FROM {db_prefix}topics
WHERE num_' . ($type != 'replies' ? 'views' : 'replies') . ' >= 1000' . ($modSettings['postmod_active'] ? '
AND approved = {int:is_approved}' : '') . '
ORDER BY num_' . ($type != 'replies' ? 'views' : 'replies') . ' DESC
LIMIT {int:limit}',
array(
'is_approved' => 1,
'limit' => $num_topics > 100 ? ($num_topics + ($num_topics / 2)) : 100,
)
);
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 10, 2019, 03:36:51 PM
Hi Tino,

What Mick gave me is the exact code I have in the block. I didn't edit or change any files. I don't want to change the existing SSI.php file. I only want to put code in the block to find what I'm looking for.

Is that possible?
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: lurkalot on March 10, 2019, 03:58:50 PM
Quote from: jernatety on March 10, 2019, 03:36:51 PM

What Mick gave me is the exact code I have in the block. I didn't edit or change any files. I don't want to change the existing SSI.php file. I only want to put code in the block to find what I'm looking for.

Is that possible?

By the way, that's Mick as in Mick, not Mick as in me = lurkalot  ;)  Yes I only pointed you to the code Mick posted here, https://www.simplemachines.org/community/index.php?topic=562032.msg3987280#msg3987280

Like I already said, if the ssi.php file won't do what you're asking then you'll have to modify it to suite. This has also been confirmed in that topic.

If you're worried about screwing something up in while editing that ssi.php file, just keep a copy of it safe somewhere, so you can put it back should you need to. 
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 10, 2019, 04:08:12 PM
The current recent topics block uses what? SSI.php I presume? I don't want to change that. I want the the default recent topics to do as it currently does, posts the most recent posts. I have default recent topics in the top block on my front page.

I want the .php block in my left column on the front page to be completely different. I want that to provide only the top most recent results with more than 1000 views from only one forum on my site. So basically, I am looking for .php code exclusively for just that left column block.

I am probably not explaining it correctly.
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 11, 2019, 12:52:24 PM
I have no problem paying somebody to write the code I need for that block.
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: tino on March 11, 2019, 09:35:19 PM
Quote from: jernatety on March 10, 2019, 03:36:51 PM
Hi Tino,

What Mick gave me is the exact code I have in the block. I didn't edit or change any files. I don't want to change the existing SSI.php file. I only want to put code in the block to find what I'm looking for.

Is that possible?

Yes you can take what is inside the existing ssi_topTopicsViews and what it calls then edit it as you see fit.
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 12, 2019, 12:26:07 PM
I really don't have any idea what you guys are talking about. I downloaded the SSI.php file and edited it per Tino's first response. Then added that entire page code to my .php block. All that does is blow up my front page screwing everything up.
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 12, 2019, 03:02:34 PM
This has been taken care of and does exactly what I was hoping. Thank you to all for taking a look and making suggestions.
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: @rjen on March 12, 2019, 03:08:20 PM
Cool. Would you mind sharing the final updated block code?
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 12, 2019, 03:12:18 PM
Quote from: @rjen on March 12, 2019, 03:08:20 PM
Cool. Would you mind sharing the final updated block code?

I will ask her if she's ok with it. It definitely wasn't me who figured it out. LOL
Title: Re: Recent Topics "Most Viewed" Block Code
Post by: jernatety on March 12, 2019, 06:02:51 PM
@virginiaz was kind enough to set this up.

The number of topics you want to show in your block can be adjusted here.

// 3rd parameter is what boards to include in search, last parameter is minimum views (use 0 if you want to include new topics)
$array = ssi_recentTopicsEx(15, null, array(85), 'array', 1000);

// Recent topic list:   [board] Subject by Poster    Date
function ssi_recentTopicsEx($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo', $min_views = 0)
{
    global $context, $settings, $scripturl, $txt, $db_prefix, $user_info;
    global $modSettings, $smcFunc;

    if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
        $exclude_boards = array($modSettings['recycle_board']);
    else
        $exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));

    // Only some boards?.
    if (is_array($include_boards) || (int) $include_boards === $include_boards)
    {
        $include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
    }
    elseif ($include_boards != null)
    {
        $output_method = $include_boards;
        $include_boards = array();
    }

    $stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
    $icon_sources = array();
    foreach ($stable_icons as $icon)
        $icon_sources[$icon] = 'images_url';

    // Find all the posts in distinct topics.  Newer ones will have higher IDs.
    $request = $smcFunc['db_query']('substring', '
        SELECT
            m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
            IFNULL(mem.real_name, m.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . ', SUBSTRING(m.body, 1, 384) AS body, m.smileys_enabled, m.icon
        FROM {db_prefix}topics AS t
            INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
            INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
            LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
            LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
            LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})' : '') . '
        WHERE t.num_views >= {int:min_views}
            ' . (empty($exclude_boards) ? '' : '
            AND b.id_board NOT IN ({array_int:exclude_boards})') . '
            ' . (empty($include_boards) ? '' : '
            AND b.id_board IN ({array_int:include_boards})') . '
            AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
            AND t.approved = {int:is_approved}
            AND m.approved = {int:is_approved}' : '') . '
        ORDER BY t.id_last_msg DESC
        LIMIT ' . $num_recent,
        array(
            'current_member' => $user_info['id'],
            'include_boards' => empty($include_boards) ? '' : $include_boards,
            'exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,
            'min_message_id' => $modSettings['maxMsgID'] - 35 * min($num_recent, 5),
            'is_approved' => 1,
            'min_views' => (int)$min_views,
        )
    );
    $posts = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => '')));
        if ($smcFunc['strlen']($row['body']) > 128)
            $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';

        // Censor the subject.
        censorText($row['subject']);
        censorText($row['body']);

        if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
            $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

        // Build the array.
        $posts[] = array(
            'board' => array(
                'id' => $row['id_board'],
                'name' => $row['board_name'],
                'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
                'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
            ),
            'topic' => $row['id_topic'],
            'poster' => array(
                'id' => $row['id_member'],
                'name' => $row['poster_name'],
                'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
                'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
            ),
            'subject' => $row['subject'],
            'replies' => $row['num_replies'],
            'views' => $row['num_views'],
            'short_subject' => shorten_subject($row['subject'], 25),
            'preview' => $row['body'],
            'time' => timeformat($row['poster_time']),
            'timestamp' => forum_time(true, $row['poster_time']),
            'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new" rel="nofollow">' . $row['subject'] . '</a>',
            // Retained for compatibility - is technically incorrect!
            'new' => !empty($row['is_read']),
            'is_new' => empty($row['is_read']),
            'new_from' => $row['new_from'],
            'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
        );
    }
    $smcFunc['db_free_result']($request);

    // Just return it.
    if ($output_method != 'echo' || empty($posts))
        return $posts;

    echo '
        <table border="0" class="ssi_table">';
    foreach ($posts as $post)
        echo '
            <tr>
                <td align="right" valign="top" nowrap="nowrap">
                    [', $post['board']['link'], ']
                </td>
                <td valign="top">
                    <a href="', $post['href'], '">', $post['subject'], '</a>
                    ', $txt['by'], ' ', $post['poster']['link'], '
                    ', !$post['is_new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>', '
                </td>
                <td align="right" nowrap="nowrap">
                    ', $post['time'], '
                </td>
            </tr>';
    echo '
        </table>';
}

// 3rd parameter is what boards to include in search, last parameter is minimum views (use 0 if you want to include new topics)
$array = ssi_recentTopicsEx(15, null, array(85), 'array', 1000);

foreach ($array as $topic) {

echo

$topic['link'];

echo '
<div align="center"><a href="', $topic['href'], '">', $news['subject'], '</a><hr></div>';


}