Ticket #620 (closed enhancement: fixed)

Opened 2 years ago

Last modified 1 year ago

Front-end changes to enable forum hierarchy

Reported by: sambauers Assigned to: sambauers
Priority: normal Milestone: 0.8.2
Component: Front-end Version: 0.8.1
Severity: normal Keywords: has-patch
Cc:

Description

Attached is a patch to put the new forum hierarchy code from [734] to work on the front-end.

This is fairly basic usage of the forum hierarchy. It will place a forum list containing child forums inside any forum page that has them. It also limits the front-page to show only the root forums and one level down.

Also attached is an image for use on the front-page. It belongs in /bb-templates/kakumei/images

Attachments

forumlist_child_background.gif (305 bytes) - added by sambauers on 03/21/07 23:46:42.
subforums-display-build788.patch (6.3 kB) - added by sambauers on 03/23/07 15:51:07.
subforums-display-with-walker-build789.patch (22.0 kB) - added by sambauers on 03/31/07 07:03:02.
620.diff (30.5 kB) - added by mdawaffe on 04/13/07 03:04:02.
bb_forum_pad-build-806.patch (1.2 kB) - added by sambauers on 04/20/07 03:29:06.
nested_divs-build-806.patch (1.6 kB) - added by sambauers on 04/20/07 05:54:19.

Change History

03/21/07 23:46:42 changed by sambauers

  • attachment forumlist_child_background.gif added.

03/23/07 15:51:07 changed by sambauers

  • attachment subforums-display-build788.patch added.

03/23/07 15:52:55 changed by sambauers

Replaced patch with new file. New topic form in forums pages was posting topics into the wrong forum when children list was present.

03/26/07 00:51:49 changed by sambauers

  • owner set to sambauers.

03/26/07 17:02:51 changed by mdawaffe

Rather than include a bunch of new functions, I'd like to import the Walker class from WP and use an extension of that both in the admin area and as a template function. Hopefully the template function will then be flexible enough to specify depth, root, etc so that it can be used in several different places.

We also need to be careful about DB queries and scalability. Right now we query the whole table (which is probably fine) and then do a sort of complicated algorithm in bb_get_forums_hierarchical() to determine the hierarchy from knowing the forum_parents.

We should probably just build the hierarchy only when it changes and store that info using bb_update_opiton().

03/30/07 08:05:42 changed by sambauers

Slight problem.

If I put the Walker class from WordPress in wp-includes.php I can't then extend it in classes.php because classes.php is included before wp-includes.php

There are a couple of solutions, but the neatest I think would be to create a wp-classes.php file that gets included just before classes.php. This new file can contain the couple of WP classes that are in wp-functions.php already.

03/30/07 12:43:55 changed by sambauers

The walker class' walk function has been designed to take a depth, but not a root to work from. We are still going to need a function to build a set of forums, from a specified root and in the right order to match the hierarchy. bb_get_forums_hierarchical() might do the job, but I couldn't figure it out last time I looked at it.

03/30/07 16:20:48 changed by sambauers

I'm not sure how sound this is in the end. There are some problems with the WordPress Walker class that meant I had to hack around it about to build my extended Walker classes.

See attachment: subforums-display-with-walker-build789.patch

This puts the hierarchical forum retrieval into classes as suggested. Some files are re-organised to allow for this. I suggest anyone wanting to review this should do so on a clean install.

BB_Cache::get_forums() has been modified to allow for some additional args to be passed. Because the Walker class doesn't allow you to specify a root id to start at, I had to work out a decent way to limit the returned forums.

This patch also deals with the administration forum list as well, although a nasty hack was required to get the forum id into the opening ul tags.

It's all kind of messy, but I guess now we have two options on the table for solving this.

03/30/07 16:32:49 changed by sambauers

Hmmm... I put the functions for fetching the admin forum list in bb-includes/template-functions.php when it should probably be in bb-admin/admin-functions.php

It will still work, it should just maybe go somewhere else.

03/31/07 07:03:02 changed by sambauers

  • attachment subforums-display-with-walker-build789.patch added.

03/31/07 07:04:03 changed by sambauers

There was a small error involving the admin area in the last patch. Re-uploaded it with fixes just now.

04/13/07 03:03:39 changed by mdawaffe

WordPress' post loop has been extremely successful, largely because of how completely customizable the markup it generates is. I think we need something equally customizable for bbPress forum "loop" (and topics and posts too), except that it will have to handle hierarchy too.

Here's what I came up with. It's heavily based on sambauers' patch above. The template would look like:

<?php if ( bb_forums() ) : ?>

<h2><?php _e('Forums'); ?></h2>
<table id="forumlist">

<tr>
        <th><?php _e('Main Theme'); ?></th>
        <th><?php _e('Topics'); ?></th>
        <th><?php _e('Posts'); ?></th>
</tr>

<?php while ( bb_forum() ) : ?>

<tr<?php bb_forum_class(); ?>>
        <td><?php bb_forum_pad( ' &#8212; ' ); ?><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small></td>
        <td class="num"><?php forum_topics(); ?></td>
        <td class="num"><?php forum_posts(); ?></td>
</tr>

<?php endwhile; ?>

</table>

<?php endif; ?>
  1. bb_forums() sets up the loop and takes two forms:
    1. bb_forums( $get_forums_formatted_args );
    2. bb_forums( [ one of 'flat', 'ul' ], $get_forums_formatted_args );

All parameters are optional.

In the second form, you can specify whether the loop should be "flat" (no structural hierarchy will appear in the html except what you put in manually (see below)) or should be a hierarchical, nested UL. "flat" is good for flat tables and is the default behavior.

  1. bb_forum() advanceds the loop. Everything inside the while block will be printed for each forum. The function returns the hierarchy's current depth, so you can do
while ( $depth = bb_forum() ) :

and do something fancy with that.

  1. bb_forum_pad( $pad ) just str_repeat()s $pad a number of times equal to the current depth in the hierarchy. You can use it to print out a bunch of EMdashes as in the example above, or something fancier like:
bb_forum_pad( '<span class="nest"> ); bb_forum_name(); bb_forum_pad( '</span>' );
  1. bb_forum_class() outputs a host of hierarchically based classes on wihch to wield CSS-fu.

The above point 1 isn't super clear. Let me give two code examples and their resulting markup.

<?php if ( bb_forums() ) : // See if there are forums and set up the loop.  'flat' is the default ?>

<table>

<tr>
 <th>Name</th>
</tr>

<?php while ( bb_forum() ) : // Advance the loop ?>

<tr>
 <td><?php bb_forum_pad( ' - ' ); forum_name(); ?>
</tr>

<?php endwhile; ?>

</table>

<?php endif; ?>

Will produce

<table>

<tr>
 <th>Name</th>
</tr>

<tr>
 <td>Forum 1</td>
</tr>

<tr>
 <td> - Forum 1.1</td>
</tr>

<tr>
 <td>Forum 2</td>
</tr>

</table>

And

<?php if ( bb_forums( 'ul' ) ) : // 'ul' for hierarchical UL ?>

<ul>

<?php while ( bb_forum() ) : ?>

<li><?php forum_name(); ?></li>

<?php endwhile; ?>

</ul>

<?php endif; ?>

Will produce

<ul>

 <li>Forum 1
  <ul>
   <li>Forum 1.1</li>
  </ul>
 </li>

 <li>Forum 2</li>

</ul>

(Whitespace edited for clarity.)


Accomplished by

  1. BB_Walker class. Walker wasn't quite up to the task, though I think BB_Walker is 100% backward compatible, so I'll see if WP will take it over after their next release.
  2. BB_Loop class. Sets up, controls, and advances the arrays and pointers of a Walker object. Abstract versions of bb_forums(), bb_forum(), bb_forum_pad(), bb_forum_class(). Can be used for other template loops like topics, posts, etc.
  3. Corrupting sambauer's patch and using his array skillz and admin code.

It isn't *quite* as easy as WordPress' post loop (it is without the "hidden" flat/UL feature), but I think it's not too bad.

Opinions?

04/13/07 03:04:02 changed by mdawaffe

  • attachment 620.diff added.

04/20/07 02:18:00 changed by mdawaffe

  • status changed from new to closed.
  • resolution set to fixed.

(In [806]) Hierarchical forums front end based on sambauers. Fixes #620

04/20/07 02:19:35 changed by mdawaffe

I'm very much open to improvements. I think the if ( bb_forums ) : while ( bb_forum() ) template tags are good, though. Ideally, there wouldn't be any dollar signs in any of the templates.

04/20/07 02:47:25 changed by sambauers

I meant to respond about this earlier... sorry.

I'm not a big fan of the bb_forum_pad method you are using. I thought it could be better done through CSS. But the way I did it through CSS wasn't all that great either. Perhaps I could adapt it to return a number which increments for each level deep we are in the hierarchy, the function could take a number to multiply by before it returns, the result would be something like:

<?php while ( bb_forum() ) : ?>
<tr<?php bb_forum_class(); ?>>
	<td style="padding-left:<?php bb_forum_pad( 10 ); ?>px;"><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small></td>
	<td class="num"><?php forum_topics(); ?></td>
	<td class="num"><?php forum_posts(); ?></td>
</tr>
<?php endwhile; ?>

The CSS that is in there is rich, but a little too complicated for most - it would be better if there was some example usage of it in the standard css file. I'm happy to look into this.

(follow-up: ↓ 16 ) 04/20/07 02:55:28 changed by mdawaffe

bb_forum_pad() could do what it does now if !is_numeric() and could do what you describe if is_numeric().

Inline style won't work for the default templates. We have all of our RTL brethren to think of.

If we can come up with a nice way to indent table rows using straight, non-inline CSS and without even using bb_forum_pad(), that'd be awesome.

I'm happy for you to look into anything :)

04/20/07 03:27:23 changed by sambauers

We could pad the left and the right...... ;)

04/20/07 03:28:51 changed by sambauers

Here's the extension to bb_forum_pad - I was writing the code at the same time that you were writing your suggestion as to how to write the code.

04/20/07 03:29:06 changed by sambauers

  • attachment bb_forum_pad-build-806.patch added.

(in reply to: ↑ 13 ; follow-up: ↓ 18 ) 04/20/07 04:10:20 changed by sambauers

Replying to mdawaffe:

Inline style won't work for the default templates. We have all of our RTL brethren to think of.

The pad method that has been committed won't work either in that case. I'd say it's *worse* than using an inline style. I'm working on it.

04/20/07 04:25:49 changed by mdawaffe

(In [812]) use hierarchy in bb_get_forum_dropdown. Fixes #260. re #620

(in reply to: ↑ 16 ) 04/20/07 05:08:46 changed by sambauers

Replying to sambauers:

The pad method that has been committed won't work either in that case. I'd say it's *worse* than using an inline style. I'm working on it.

I eat my words, I was wrong about that. We can use an inline text-indent style. Only problem is that if the description wraps to a second line it stuffs up.

04/20/07 05:54:07 changed by sambauers

Here's a suggestion for padding child forums using nested DIVs. It's RTL friendly too.

04/20/07 05:54:19 changed by sambauers

  • attachment nested_divs-build-806.patch added.

05/29/07 23:10:47 changed by mdawaffe

(In [836]) better markup for front end forum hierarchy. Big props sambauers. re #620

05/29/07 23:11:56 changed by mdawaffe

(In [837]) typo in [836] re #620

06/07/07 21:10:25 changed by mdawaffe

  • milestone changed from 1.0 to 0.8.2.