PDA

View Full Version : Mini-hack: show list of forums from the same category in a popup menu


kmike
05-20-2005, 10:00 PM
Description:
This hack makes navigation within forums from the same category much easier - no need to go to forum home or other aggregate page, just use popup menu similar to "Forum tools". See attached screenshot, it is really self-describing.
There're no new db queries, one .php file changed, one template edited and one template added.

Limitations:
Obviously, this is for forums which are categorized. Also, it will list all sub-forums of a parent forum, including subforums of the current forum and all subforums of forums from the current category. In other words, it's not for boards with advanced tree-like forum structure (more than 1 level deep).

Another issue: it will only work when DHTML popups are enabled. Required code is missing from the part of FORUMDISPLAY template responsible for displaying non-DHTML navigation.

Updates:
1.2 - Add check for active forum state when listing forums.
1.01 - Check forum permissions to hide forums which can't be accessed by user.

Code changes:
In forumdisplay.php, find this code fragment (vb 3.0.7):

else
{
$lastread = $bbuserinfo['lastvisit'];
}

Add these lines below:

// HACK: display sibling forums as related topics menu
require_once('./includes/functions_misc.php');
$childforums = fetch_child_forums($foruminfo['parentid'], 'ARRAY');
foreach ($childforums AS $val)
{
if ($val <> $forumid)
{
$relatedperms = $bbuserinfo['forumpermissions']["$val"];
if (!($relatedperms & CANVIEW) AND $vboptions['hideprivateforums'])
{
continue;
}
$relatedinfo = fetch_foruminfo($val);
if (! ($relatedinfo['options'] & $_FORUMOPTIONS['active']) )
{ // forum isn't active
continue;
}
eval('$relatedtopicbits .= "' . fetch_template('relatedtopicbit') . '";');
}
}
// HACK

In the same file, find this code (near the top):

'none' => array(
'FORUMDISPLAY',

Add this beneath:

'relatedtopicbit',

Template changes:
In the FORUMDISPLAY template, find this line:

<td class="tcat" width="100%">$vbphrase[threads_in_forum]<span class="normal">: $foruminfo[title]</span></td>
underneath it, add this:

<td class="vbmenu_control" id="relatedtools"><a href="#goto_relatedtools">Related Topics</a> <script type="text/javascript"> vbmenu_register("relatedtools"); </script></td>
Find this fragment:

<if condition="$show['popups']">
<br />
<!-- popup menu contents -->

Add underneath it:

<!-- related tools menu -->
<div class="vbmenu_popup" id="relatedtools_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr><td class="thead">Forums<a name="goto_relatedtools"></a></td></tr>
$relatedtopicbits
</table>
</div>
<!-- / related tools menu -->


Create new template named "relatedtopicbit". Populate it with this:

<tr><td class="vbmenu_option"><a href="forumdisplay.php?$session[sessionurl]f=$relatedinfo[forumid]">$relatedinfo[title]</a></td></tr>


That's it.

gldtn
05-21-2005, 10:21 AM
Oooui... first to post and second to click "INSTALL" (=

I'll try it out this afternoon.. Seems quite promissing, thanks Kmike

MrNase
05-21-2005, 02:14 PM
Does this use the permission system so that usergroups only see the forums which they can access? :)

kmike
05-21-2005, 04:33 PM
Does this use the permission system so that usergroups only see the forums which they can access? :)
Good catch. I added permissions check and updated instructions.
Changes from 1.00:
before this line in forumdisplay.php:

$relatedinfo = fetch_foruminfo($val);
add this:

$relatedperms = $bbuserinfo['forumpermissions']["$val"];
if (!($relatedperms & CANVIEW) AND $vboptions['hideprivateforums'])
{
continue;
}

bigcurt
05-21-2005, 08:12 PM
Can you do me a favor and put it into a text file attachment and add to first post ( makes things easier for some ppl ) nice hack!

kmike
05-22-2005, 06:16 AM
I uploaded instructions as a text file.

Slave
05-23-2005, 02:57 PM
I'd love to use this as a way of showing sub forums instead of having them as a block at the top of the page ..

The one thing stopping me using this is that it would mean the sub forums not showing if the parent forum is a forum that posting isn't allowed on .. and therefore empty apart from the subforums ..

So could you point me in the right direction on having this hack only work on forums that allow posting .. therefore allowing me to delete the subforums list at the top of the page .. but still have the subforums showing if its in a forum that doesn't allow posting ..

hmm .. does that make sense?

kmike
05-23-2005, 03:49 PM
Not really :(
This hack works only in forums that allow posting, and displays all sub-forums of a parent forum.

Slave
05-23-2005, 06:27 PM
k .. so if I installed this hack and then deleted the subforum listing from the FORUMDISPLAY template I would then be able to get to the subforums if the forum was open for posts .. but if not then it wouldn't show anything ..

I guess I need an "IF" statement wrapped around the subforum part of the FORUMDISPLAY template to have it work how I would want .. but I have no idea what it would be .. :)

Anyone know?

Slave
05-23-2005, 06:29 PM
hmm .. I've just looked at the code a bit more and I might of sussed it .. :)

Slave
05-23-2005, 06:37 PM
Ok .. this goes to show how bad I am .. :p

I need to use the opposite of ..
<if condition="$show['threadslist']">

So instead of saying "equals" .. I want "not equals" .. :)

Slave
05-23-2005, 06:42 PM
Ahh ..

I used an <else /> tag and that seems to do the trick :)

Slave
05-23-2005, 06:48 PM
Hmm .. just installed it .. and it seems to be listing all of the forums at the same level .. as well as the subforums .. (about 40 forums in all) ..

Any way to change it to just show the subforums of the forum you're in?

Oh .. and it's listing forums that are closed for posting too (and therefore shouldn't be seen) ..

kmike
05-24-2005, 12:21 PM
Well, I stated that it will list ALL subforums under "Limitations" part of hack description. I see no obvious way to show only subforums of the current depth.
I'll add check for closed forums today.

EDIT: do you want to skip forums closed for posting (Forum is Open = No) or forum categories (Act as Forum = No)? Forums closed for posting can still contain threads, so I guess they should be listed.

Slave
05-26-2005, 12:41 AM
Well .. tbh I don't need either any more .. :p

I used your hack as a pointer on how to do it ..

If you go to ..

http://www.savageforums.com/forumdisplay.php?f=6

You'll see that it shows all the subforums in the "non" forum as normal ..

But if you go ..

http://www.savageforums.com/forumdisplay.php?f=104

You'll see that it's an open forum, with subforums, but they have been removed from the top, as is normal, and been put into a "Sub Forums" drop down ..

I just want to say thanks, as I've been wanting a solution for this problem for ages .. and finally I've got it sussed ..

:)

kmike
06-30-2005, 05:34 PM
Somehow the check for active forum state didn't make it to the last update...
I updated instructions. If you already have it installed, find this line in forumdisplay.php:

$relatedinfo = fetch_foruminfo($val);

and add beneath it:

if (! ($relatedinfo['options'] & $_FORUMOPTIONS['active']) )
{ // forum isn't active
continue;
}

yoyoyoyo
08-24-2005, 11:32 PM
works great! thanks much.

uReside.com
09-13-2005, 05:27 AM
will this work in a cmps module?

kmike
09-23-2005, 09:20 AM
Sorry, I have no idea.

Renada
03-31-2006, 12:46 AM
@Kmike,

Is this or will this be ported to 3.5?

Regards,
Renada

kmike
03-31-2006, 06:04 AM
No, at least until we upgrade to 3.5, which is still some months away.

Renada
03-31-2006, 07:32 PM
No, at least until we upgrade to 3.5, which is still some months away.

Thanks for letting me know :) I'll keep an look out for it in the future.

Regards,
Renada