Modifying smf_recent_topics

Started by dukeofgaming, March 31, 2007, 08:23:28 PM

Previous topic - Next topic

dukeofgaming

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 =)

Kindred

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...
Сл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."

Sarge

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:

$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:

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:

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:
empty($excluidos)

instead of:
$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

dukeofgaming

#3
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 ^^

Kindred

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...
Сл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."

Sarge

#5
Quote from: dukeofgaming on April 01, 2007, 05:18:32 PM
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:

function ssi_latestTopics2($num_recent, $color1 , $color2, $exclude_boards = null, $output_method = 'echo')


with this:

function ssi_latestTopics2($num_recent, $color1 , $color2, $exclude_boards = null, $include_boards = null, $output_method = 'echo')





Find this:

$exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;


and add this line AFTER it:

$include_boards = empty($include_boards) ? array() : $include_boards;





Find these lines in the query:

AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
AND $user_info[query_see_board]


and replace them with:

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:

$excluidos = $params->get( 'excluded' );
$excluded_array = ($excluidos === "") ? null : explode(",", $excluidos);


Before or after them, add these lines:

$included_boards = $params->get( 'smf_include_boards' );
$included_array = ($included_boards === "") ? null : explode(",", $included_boards);





Then replace this:

ssi_latestTopics2($num_recent, $color1 ,$color2, $excluded_array);


with this:

ssi_latestTopics2($num_recent, $color1 ,$color2, $excluded_array, $included_array);





Save and upload.

As a result, you can use board inclusion, exclusion, or both.

    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

Sarge

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:


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:


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

dukeofgaming

thx, will work on it as soon as i have time ^^

Advertisement: