collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 633
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

Welcome to SimplePortal.net! You can download SimplePortal from the Downloads Area!

Author Topic: How would i exclude boards from TopBoards and TopPosters?  (Read 3564 times)

0 Members and 1 Guest are viewing this topic.

Offline Tarista

  • Semi Newbie
  • *
  • Posts: 37
  • SMF Version: 2.0.10
  • SP Version: 2.3.5
How would i exclude boards from TopBoards and TopPosters?
« on: May 21, 2014, 06:45:39 AM »
Hi,

I'm wondering how to exclude boards from the TopBoards and TopPosters blocks? I assume I can either change the code in the PortalBlocks-page or copy the code from the function there, use it in a custom PHP block and change that. However, I'm not sure how i would make it work.

I assume it would be quite difficult in TopPosters but TopBoards already excludes the recycle board in the SSI which SimplePortal PortalBlocks is based on.

Code: (This is from the function in PortalBlocks) [Select]
$block_parameters = array(
'limit' => 'int',
);

if ($return_parameters)
return $block_parameters;

$limit = !empty($parameters['limit']) ? $parameters['limit'] : 5;

$boards = ssi_topBoards($limit, 'array');

I think it's in this file I have to start, but unsure how?
Code: (This is from SSI.php, function ssi_topBoards) [Select]
function ssi_topBoards($num_top = 10, $output_method = 'echo')
{
global $context, $settings, $db_prefix, $txt, $scripturl, $user_info, $modSettings, $smcFunc;

// Find boards with lots of posts.
$request = $smcFunc['db_query']('', '
SELECT
b.name, b.num_topics, b.num_posts, b.id_board,' . (!$user_info['is_guest'] ? ' 1 AS is_read' : '
(IFNULL(lb.id_msg, 0) >= b.id_last_msg) AS is_read') . '
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
WHERE {query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_board}' : '') . '
ORDER BY b.num_posts DESC
LIMIT ' . $num_top,
array(
'current_member' => $user_info['id'],
'recycle_board' => (int) $modSettings['recycle_board'],
)
);
$boards = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$boards[] = array(
'id' => $row['id_board'],
'num_posts' => $row['num_posts'],
'num_topics' => $row['num_topics'],
'name' => $row['name'],
'new' => empty($row['is_read']),
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
);
$smcFunc['db_free_result']($request);


I also took a look at this code which do seem to have the variables to exclude boards, but not sure how to make it work in TopBoards

Code: (This is from SSI.php, function ssi_recentTopics) [Select]
function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo')
{
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();
}

... [irrelevant codes]

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,
)
);

I hope I didn't flood you with code, but I assume it's easier if I show the code instead of anyone else having to look through their files to find which lines I mean.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: How would i exclude boards from TopBoards and TopPosters?
« Reply #1 on: May 22, 2014, 11:20:36 AM »
You are certainly on the right track, and you have figured out that the changes you want call for a significant rewrite to the functionality.  I see you are not afraid to search the code, and have identified how other pieces of code do what you want your piece of code to do.

Step 1.  Write a replacement for ssi_topBoards, one with the include_boards and exclude_boards logic from ssi_recentTopics.  You want to test this, using a custom php block to call your new function, and make sure you don't get errors.  Do this one changed line at a time, testing every single time. You will have to make a change to the SQL statement that the function uses.  You can use the SQL statement in ssi_recentTopics as a guide.  This change will probably be the trickiest part of the work.

Step 2. Make changes to sp_topBoards. Add 'boards' to the parameter list, and copy the "explode" line from sp_recent.  Test that this seems to work (even though it won't do anything yet) by playing with it in the blocks editor.

Step 3. Make sp_topBoards call your new ssi_topBoards replacement function, including the part where it passes the information about boards.

Enjoy!
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline Tarista

  • Semi Newbie
  • *
  • Posts: 37
  • SMF Version: 2.0.10
  • SP Version: 2.3.5
Re: How would i exclude boards from TopBoards and TopPosters?
« Reply #2 on: May 22, 2014, 12:11:20 PM »
Thank you! :) I'll give this a try.

What I don't understand is how I can add the parameters, and do I need both exclude and include? I understand i have to change the other files too, but regarding the function where would I need to add the boards I want to exclude?
In the custom PHP block using boards = array(1,5); or something similar? I don't actually know how to use the end result-code if I manage to build it.

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: How would i exclude boards from TopBoards and TopPosters?
« Reply #3 on: May 22, 2014, 12:17:39 PM »
If it were me,
* I would alter PortalBlocks.php, because then you get the "easy" way to add parameters.
* Do try adding the parameter "boards" to the function and see what happens in the block editor.  The block editor is pretty smart that way.

* You might find it easier to test your new custom replacement for the SSI function directly from your customized PortalBlocks.php function. 

* One really great way to test is to add additional "echo" lines right after you do something you are not sure if you understand whether you did it right -- to write the result out right to your forum page.

* You do have a "test" version of your forum set up for testing this stuff, right?
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Offline Tarista

  • Semi Newbie
  • *
  • Posts: 37
  • SMF Version: 2.0.10
  • SP Version: 2.3.5
Re: How would i exclude boards from TopBoards and TopPosters?
« Reply #4 on: May 22, 2014, 12:54:08 PM »
You mean it might actually show up in the block editor as a field for me to write in? That would be great. I'll definitely try that then.

What do you mean test it directly in the PortalBlocks.php?

About the additional echo's I'm not sure what you mean, I know I can print_r an array but thats something else completely isnt it?

And well, I don't actually have a copy of my forum which I use for testing since I don't know how to copy the database and get it working, :(
So right now I'm building a new forum and will open it when I've figured stuff like this out. My host takes backup as well and I try to do it regularly and have also installed a clean extra forum which I can copy the files from if one of them stops working. Also I don't close the program before I have tested something and checked error logs, so if the edits don't work I can reverse the steps. :)
Not as perfect as having a copy of my live forum, but yeah


Perhaps I should try to get the SSI-function to work properly first.
Now I've got this and not sure how to test it correctly.
Mainly I think it's incorrect since it checks the recycled_board two times.

Code: [Select]
function ssi_topBoards2($num_top = 10, $exclude_boards = null, $output_method = 'echo')
{
global $context, $settings, $db_prefix, $txt, $scripturl, $user_info, $modSettings, $smcFunc;

// Excluding certain boards...
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));


// Find boards with lots of posts.
$request = $smcFunc['db_query']('', '
SELECT
b.name, b.num_topics, b.num_posts, b.id_board,' . (!$user_info['is_guest'] ? ' 1 AS is_read' : '
(IFNULL(lb.id_msg, 0) >= b.id_last_msg) AS is_read') . '
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
WHERE {query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_board}' : '') . '
' . (empty($exclude_boards) ? '' : '
AND b.id_board NOT IN ({array_int:exclude_boards})') . '
ORDER BY b.num_posts DESC
LIMIT ' . $num_top,
array(
'current_member' => $user_info['id'],
'recycle_board' => (int) $modSettings['recycle_board'],
'exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,
)
);

Offline Tarista

  • Semi Newbie
  • *
  • Posts: 37
  • SMF Version: 2.0.10
  • SP Version: 2.3.5
Re: How would i exclude boards from TopBoards and TopPosters?
« Reply #5 on: May 22, 2014, 01:02:50 PM »
Or maybe it works anyway, I can at least use:
Code: [Select]
ssi_topBoards2(10,array(4,36));
Not sure if it's safe but I don't see any errors. Would it be simpler just to use that in a custom block, or would that be bad for performance somehow?

Offline AngelinaBelle

  • Comrade
  • *
  • Posts: 4870
  • Gender: Female
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: How would i exclude boards from TopBoards and TopPosters?
« Reply #6 on: May 22, 2014, 02:12:47 PM »
1) if you can create a new database, then it is VERY easy to backup your SMF tables from one database, restore them to another database, create a new installation of SMF (in a new folder like /smftest, for example), and then run repair-settings.php to fix various things to point to the correct directories.  For help with that, ask on over at simplemachines.org.
2) No, there is no performance hit that I can think of for calling that function from a php block vs from the sp_topBoards block.  The SQL involved would be the same.  So that is certainly a good way to test it.

Enjoy!
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?