Advertisement:

Author Topic: Modifying smf_recent_topics  (Read 4030 times)

Offline dukeofgaming

  • Semi-Newbie
  • *
  • Posts: 74
Modifying smf_recent_topics
« on: March 31, 2007, 08:23:28 PM »
Hi all, I'm modifying this joomla module for my site for it to exclude some boards from displaying @ home... and it works, however, I want to include those boards on another module below the first one, in order to do that, I would have to exclude all the boards one by one.

Is there any way I can obtain an array or string with ALL of the board IDs [if I create a new board, or delete any, I'd have to rewrite the excluded forums string (its already at modules options), but it may cause an error]?, except certain I specify, so I can pass it as parameter for my modified function?.

Here's the code= http://rapidshare.com/files/23741491/com_smf_recentTopics2.rar.html

Sorry if there are some words in spanish  :P

Hope you can help me, thnx in advance =)

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,960
  • Gender: Male
    • Kindred-999 on GitHub
Re: Modifying smf_recent_topics
« Reply #1 on: March 31, 2007, 10:53:40 PM »
why do you have to code in the exclusions?  Excluding board is a standard feature than can be done through the module config screen without touching the code at all...
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Sarge

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,209
  • Gender: Male
    • Zëri YT!
Re: Modifying smf_recent_topics
« Reply #2 on: April 01, 2007, 03:47:57 AM »
Kindred, I took a look at the uploaded code. It seems to me that the list is not hardcoded, it is indeed set through the module config screen:
Code: [Select]
$excluidos = $params->get( 'excluded' );
$excluded_array = ($excluidos === "") ? null : explode(",", $excluidos);
ssi_latestTopics2($num_recent, $color1 ,$color2, $excluded_array);

I think that dukeofgaming needs to use the list of excluded boards in other modules too. How can he do that?



dukeofgaming, I don't know where you got that module you're modifying, but why don't you use mod_smf_recentTopics from the Combined Readme?
http://www.simplemachines.org/community/index.php?topic=81152.msg541423#msg541423

It doesn't display posts with two alternating colors, but of course you can add that.

I noticed a couple things in your code:

- There's an extra newline after every line in function ssi_latestTopics2(). It's not a bug, but still... you'd better remove those for the sake of readability.

This:
Code: [Select]
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() : $exclude_boards;


should be:
Code: [Select]
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() : $exclude_boards;

Also, you'd better use this construct:
Code: [Select]
empty($excluidos)
instead of:
Code: [Select]
$excluidos === ""
Regards.
    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Offline dukeofgaming

  • Semi-Newbie
  • *
  • Posts: 74
Re: Modifying smf_recent_topics
« Reply #3 on: April 01, 2007, 05:18:32 PM »
Sarge, its exactly the one I used, though I took it a while ago and modified it a while ago so it would display more data, you can take a look at it working @ http://www.hardwarecult.com 's frontpage.

Thats why i didnt just call the function from SSI, I copied it and modified it... i have to add the define statement though, cus I cannot add 2 modules lol of the same, could you tell me what should I use?, define?, requireonce? [sorry, not really into php yet]. Changed the construct btw, thx.

Further changes I'm going to add is being able to choose displaying or not certain columns or other X info.

Well, as I said, I want to add the option to wether "Exclude this boards" or "Exclude all boards but these", in order to do that second one I'd have to get all board ids, delete the ones I dont want to exclude, and voila, my question is that if there is a way to get all board IDs from SMF (in a string or array or whatever), because if I create new boards I would have to exclude those new ones too.

Thx again ^^
« Last Edit: April 01, 2007, 05:33:02 PM by dukeofgaming »

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,960
  • Gender: Male
    • Kindred-999 on GitHub
Re: Modifying smf_recent_topics
« Reply #4 on: April 01, 2007, 05:54:45 PM »
I suppose you could scan the smf_boards table in the database for the ID and name of each board entry and assemble an array out of that...
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Sarge

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,209
  • Gender: Male
    • Zëri YT!
Re: Modifying smf_recent_topics
« Reply #5 on: April 02, 2007, 02:50:34 AM »
Well, as I said, I want to add the option to wether "Exclude this boards" or "Exclude all boards but these", in order to do that second one I'd have to get all board ids, delete the ones I dont want to exclude, and voila...

You can combine board exclusion and inclusion, all in one place. A way to do that would be to use FIND_IN_SET or the IN operator inside the query. Try this (be aware that I haven't tested it):

Add a smf_include_boards parameter in the XML file. Just copy and paste the code for excluded and change the name.

In the PHP file, replace this line:
Code: [Select]
function ssi_latestTopics2($num_recent, $color1 , $color2, $exclude_boards = null, $output_method = 'echo')

with this:
Code: [Select]
function ssi_latestTopics2($num_recent, $color1 , $color2, $exclude_boards = null, $include_boards = null, $output_method = 'echo')



Find this:
Code: [Select]
$exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;

and add this line AFTER it:
Code: [Select]
$include_boards = empty($include_boards) ? array() : $include_boards;



Find these lines in the query:
Code: [Select]
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
AND $user_info[query_see_board]

and replace them with:
Code: [Select]
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . (empty($include_boards) ? '' : "
AND b.ID_BOARD IN (" . implode(', ', $include_boards) . ")") . "
AND $user_info[query_see_board]



In the //Params block (at the end of the file), find these lines:
Code: [Select]
$excluidos = $params->get( 'excluded' );
$excluded_array = ($excluidos === "") ? null : explode(",", $excluidos);

Before or after them, add these lines:
Code: [Select]
$included_boards = $params->get( 'smf_include_boards' );
$included_array = ($included_boards === "") ? null : explode(",", $included_boards);



Then replace this:
Code: [Select]
ssi_latestTopics2($num_recent, $color1 ,$color2, $excluded_array);

with this:
Code: [Select]
ssi_latestTopics2($num_recent, $color1 ,$color2, $excluded_array, $included_array);



Save and upload.

As a result, you can use board inclusion, exclusion, or both.
« Last Edit: April 06, 2007, 03:14:25 AM by Sarge »
    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Offline Sarge

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,209
  • Gender: Male
    • Zëri YT!
Re: Modifying smf_recent_topics
« Reply #6 on: April 06, 2007, 04:29:39 AM »
For compatibility with your original module, you might want to add the $include_boards parameter to the end of the function parameters list for the module changes I posted above:

Code: [Select]
function ssi_latestTopics2($num_recent, $color1, $color2, $exclude_boards = null, $output_method = 'echo', $include_boards = null)

For even further compatibility with other scripts (especially if you want to update SSI.php with your/my version of ssi_latestTopics2), I also advise you to preset $color1 and $color2 to null and move them to the end of the parameter list:

Code: [Select]
function ssi_latestTopics2($num_recent, $exclude_boards = null, $output_method = 'echo', $include_boards = null, $color1 = null, $color2 = null)

You should test your variables for being (un)empty, just like with $exclude_boards and $include_boards.

In both cases, you have to update module and function code accordingly.
 
    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Offline dukeofgaming

  • Semi-Newbie
  • *
  • Posts: 74
Re: Modifying smf_recent_topics
« Reply #7 on: April 26, 2007, 04:46:11 PM »
thx, will work on it as soon as i have time ^^