News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

SSI Functions

Started by njtweb, September 04, 2018, 08:41:59 AM

Previous topic - Next topic

njtweb

I have 2 questions.

1st. I want to limit the number of top posts by views to 5. How would that SSI function be written?
2nd. I want to show only a specific poll, not recent and not the top poll. Can you declare a specfic poll by ID?

Thank you too all in advance.

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Mick.

Change the 5 to whatever amount of top topic views you want.
ssi_topTopicsViews(5);

njtweb

Can't use either on my TP front page right panel. Too much data shows and it blows up the formatting. Thanks though.

Kindred

so use


$topiclist=ssi_topTopicsViews('replies',5,'array');


then you can output what you want, in the format you want....

foreach ($topiclist as $topic) {

echo

$topic['link'],
$topic['num_views'],
$topic['num_replies'];

}
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mick.

#5
@kindred...
Your code throws a "Wrong value type sent to the database. Integer expected. (limit)" error. I went ahead and did it my way but maybe there's a better approach. I think the OP wants the title and number of views only.


$topiclist=ssi_topTopicsViews(5.0,'array');


foreach ($topiclist as $topic) {

echo '
<div align="left">' ,$topic['link'], '  Views = ' ,$topic['num_views'], '</div>';

}

njtweb

I can't use it anyway, any of the SSI functions totally screw up my right side block. All of the blocks wind up in a scrambled mess, NBD, my basic HTML is fine, I'll just update whatever I see as the top topics by view as I see fit.

Kindred

njtweb...   If they "screw up your block", then you are not doing it right.

If you actually see the code that Mick used, it will not "screw up" anything --   but even if it does, you can reformat it however you like in the echo portion.

The whole point of the array option in the SSI functions is to output the values so that you can format them as you need...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mick.

This one more of my liking. But if it breaks, it's not the code. It's prolly long titles being used. It's set to 5 topics and views only for your top topics.


$topiclist=ssi_topTopicsViews(5.0,'array');

echo '
<span style="float:right">Views</span>';

foreach ($topiclist as $topic)
{
echo '
<table border="0" width="100%">
<tr>
<td>' ,$topic['link'], ' <span style="float:right">' ,$topic['num_views'], '</span></td>
</tr>
</table>';
}

Kindred

ugh.... don't use tables!

If you must do a tabular design, use table/cell classes in a div with css

e.g.

.rTable    { display: table; }
.rTableRow       { display: table-row; }
.rTableHeading    { display: table-header-group; }
.rTableBody    { display: table-row-group; }
.rTableFoot    { display: table-footer-group; }
.rTableCell, .rTableHead  { display: table-cell; }

and, doing that, you can always use overflow:hidden;
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mick.

Quote from: Kindred on September 06, 2018, 10:09:05 AM
ugh.... don't use tables!

If you must do a tabular design, use table/cell classes in a div with css

e.g.

.rTable    { display: table; }
.rTableRow       { display: table-row; }
.rTableHeading    { display: table-header-group; }
.rTableBody    { display: table-row-group; }
.rTableFoot    { display: table-footer-group; }
.rTableCell, .rTableHead  { display: table-cell; }

and, doing that, you can always use overflow:hidden;
I know what you mean, I dont like tables either. This was a quick design. ;)

Mick.

Lol....here you go..  ;D


echo '
<style type="text/css">
.divTable{
display: table;
width: 100%;
}
.divTableRow {
display: table-row;
}
.divTableCell {
display: table-cell;
padding: 3px 10px;
}
.divTableBody {
display: table-row-group;
}
</style>';




$topiclist=ssi_topTopicsViews(5.0,'array');

echo '
          <span style="float:right">Views</span>';

foreach ($topiclist as $topic)
{
echo '

          <div class="divTable">
              <div class="divTableBody">
                  <div class="divTableRow">
                      <div class="divTableCell">' ,$topic['link'], ' <span style="float: right;">' ,$topic['num_views'], '</span></div>
                  </div>
              </div>
          </div>';
}

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mick.


njtweb

I do have a question. 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>';


}

vii

Quote from: njtweb on March 09, 2019, 08:18:38 AM
I do have a question. 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.

-snip-


I think this should work. I didn't test it though.

In /SSI.php

Replace:
function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo')

With:

function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo', $min_views = 0)


Replace:


    // 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.id_last_msg >= {int:min_message_id}
            ' . (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,
        )
    );


With:


    // 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.id_last_msg >= {int:min_message_id}
            ' . (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}' : '') . '
            AND t.num_views >= {int:min_views}
        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,
        )
    );


In the code you posted, replace:


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


With:


// 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_topTopicsViews(15, null, array(85), 'array', 1000);

njtweb

Hi @Virginiaz

I don't actually want to change any physical files. I'm using Tinyportal front page. There are .php blocks where you can drop code into and save and it'll show the results on the tinyportal front page. That code example that I posted is exactly what is currently in there.

Thank you

Arantor

Since the SSI function doesn't do what you want it to do, the only choice really is to modify it, or copy paste the modified version into the HTML block.

Illori

Quote from: Arantor on March 09, 2019, 11:28:20 AM
or copy paste the modified version into the HTML block.

dont you mean PHP block?

njtweb

Quote from: Illori on March 09, 2019, 12:02:45 PM
Quote from: Arantor on March 09, 2019, 11:28:20 AM
or copy paste the modified version into the HTML block.

dont you mean PHP block?

Yes, that's what he means. That didn't work. The block just looks like there's nothing in it on the front page when it's saved.

Advertisement: