Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

How to create a set list of boards to exclude?

Aloittaja Ahadawan, toukokuu 21, 2014, 05:45:40 AP

« edellinen - seuraava »

Ahadawan

Hi,

I have two sets of boards which I exclude on multiple instances on the site and each time I add a new board I have to change those numbers both in portal blocks/pages and on my index.template-file. I wonder if it would be possible to set this just on one place and have it working everywhere? Would that be my index.template-file perhaps?

So instead of using something like this
$exclude_boards = array(1,2,3,4,5,15,16,17);
and on other places this
$exclude_boards = array(6,7,8,9,10,11,12,13,14);

I could just set that up on index.template and use it everywhere, so when I need to use the first list i could just write "$exclude_boards = $excludeboard_cat1;" and define $excludeboard_cat1 on the index.template?

Of course I still have to change it somewhere every time I add a board which has to be excluded from one of the lists, but at least i wouldn't have to change it on multiple.

Ultimately it would have been nice to define this on the admin-settings or something like that, but that I definitely have no clue have to set up, so just changing one file would be preferable.

What do you think? Is this possible?

/Ahadawan

live627

So, you are using SSI to integrate your site with the forum? I'm pretty sure it doesn't load the theme straight off the bat.

If you have a file that your site loads every time, you could put the array of boards there...

Ahadawan

The forum and portal is the whole site actually, I'm just using those functions in custom portal blocks. So the index.template is always part of the site.

I'll have to try putting them there, I was just uncertain how to get it working on every page at the same time, but perhaps I already have the answer in the question itself. 

live627


Ahadawan

It's so strange because it doesn't :( Maybe I'm just doing it wrong.
I added the boards to index.template.php and it didn't work.

$excludeboard_cat1 = array(1,2,3,4,5);
and then I use this on other places:
$exclude_boards = $excludeboard_cat1;

When I experimented with it I also got some undefined index-errors from the excludeboard_cat1 which was even more strange.

margarett

You probably need to global $excludeboard_cat1;

But the theme is loaded after the Sources so, depending on where you use it, it might not yet be available when you need it...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Ahadawan

So it's not as simple as I thought then. :/

In some cases I want it to load in the same file, index.template, I have four custom functions which I have created. I got them from a portal custom function I used years ago. I've then added them to the body_above function like this:
template_func4();  And template_func4 et cetera is defined/created/placed just above the template_menu() function.

Here is the parts of the functions (because they are quite long) I thinks is relevant.

$exclude_boards = array(1,2,3,4,5);   
$ex_board_clause = !empty($exclude_boards) ? ' AND b.id_board NOT IN (' . implode(', ', $exclude_boards) . ')' : '';


$request = $smcFunc['db_query']("", "
            WHERE " . $where_clause . $ex_board_clause . "

           
So the bits usually placed in the sources-file is actually added in the template-file. This because it is originally from a custom php block added by a portal.

So when I add a board I search through the index.template and add the board ID to two of the functions.

I assume this is not optimal :/ But that's how I've done it. Maybe I should've just used SSI instead but I figured that's not how it's meant to be used?

margarett

It isn't, no. You shouldn't use SSI inside the forum structure.

If you perform certain tasks when adding a board, then you should execute your queries in Sources, where the action of adding a board is performed. By principle, you shouldn't execute computational task in template files.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

live627


Arantor

Why not, just being experimental here, go one step further?

Add it to the modification settings page - it's one line of code to define the setting, one to define the language string, then it's in $modSettings regardless of anything else and will always be available thereafter, so it's just an explode() away at that point.

Sources/ManageSettings.php, you'll find a line:
// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!

After that, and before the closing ) in the next line, add:
array('text', 'excludeBoards'),

Then somewhere in Themes/default/languages/ManageSettings.english.php, add a definition for this new option:
$txt['excludeBoards'] = 'Boards to exclude (e.g. 1,2,3)';

From there, it's just a case of getting at it.
global $modSettings;
$boards = !empty($modSettings['excludeBoards']) ? explode(',', $modSettings['excludeBoards']) : array();
$exclude_boards = array();
foreach ($boards as $board_id)
if ((int) $board_id > 0)
$exclude_boards[] = (int) $board_id;


Presto. $exclude_boards will now be a simple list of boards that are all numeric and positive integers (and if you double-hit comma or something, that'll be taken care of too) and you can drop that code in wherever you'll need the list of boards and it should work.
Holder of controversial views, all of which my own.


Ahadawan

Thank you all :) I'm trying to follow the instructions by Arantor.

I'm uncertain where to place this code,
global $modSettings;
$boards = !empty($modSettings['excludeBoards']) ? explode(',', $modSettings['excludeBoards']) : array();
$exclude_boards = array();
foreach ($boards as $board_id)
if ((int) $board_id > 0)
$exclude_boards[] = (int) $board_id;

Arantor

Um, before wherever you actually want to use $exclude_boards...
Holder of controversial views, all of which my own.


Ahadawan

Oh, right *blushes* Of course! Silly me!

I thought I needed to add it to the settings somewhere to actually display the settings in the admin section but now I see that it already displays in the Modsettings. Thank you! :)

Advertisement: