Changeset 1531

Show
Ignore:
Timestamp:
05/14/08 17:18:17 (7 months ago)
Author:
sambauers
Message:

Enable categories using forum meta data. See #520

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bb-admin/admin-functions.php

    r1528 r1531  
    506506                return false; 
    507507 
    508         $defaults = array( 'forum_name' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => false ); 
     508        $defaults = array( 'forum_name' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => false, 'forum_is_category' => 0 ); 
    509509        $args = wp_parse_args( $args, $defaults ); 
    510510        if ( 1 < func_num_args() ) : // For back compat 
     
    521521        $forum_order = (int) $forum_order; 
    522522        $forum_parent = (int) $forum_parent; 
     523        $forum_is_category = (int) $forum_is_category; 
    523524 
    524525        $forum_name = apply_filters( 'bb_pre_forum_name', stripslashes($forum_name) ); 
     
    540541        $bbdb->insert( $bbdb->forums, compact( 'forum_name', 'forum_slug', 'forum_desc', 'forum_parent', 'forum_order' ) ); 
    541542        $forum_id = $bbdb->insert_id; 
    542  
     543        if ($forum_id && $forum_is_category) 
     544                bb_update_forummeta($forum_id, 'forum_is_category', $forum_is_category); 
    543545        wp_cache_flush( 'bb_forums' ); 
    544546 
     
    552554                return false; 
    553555 
    554         $defaults = array( 'forum_id' => 0, 'forum_name' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => 0 ); 
     556        $defaults = array( 'forum_id' => 0, 'forum_name' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => 0, 'forum_is_category' => 0 ); 
    555557        $args = wp_parse_args( $args, $defaults ); 
    556558        if ( 1 < func_num_args() ) : // For back compat 
     
    567569        $forum_order = (int) $forum_order; 
    568570        $forum_parent = (int) $forum_parent; 
     571        $forum_is_category = (int) $forum_is_category; 
    569572 
    570573        $forum_name = apply_filters( 'bb_pre_forum_name', stripslashes($forum_name) ); 
     
    578581        wp_cache_flush( 'bb_forums' ); 
    579582 
    580         return $bbdb->update( $bbdb->forums, compact( 'forum_name', 'forum_desc', 'forum_parent', 'forum_order' ), compact( 'forum_id' ) ); 
     583        $update_result = $bbdb->update( $bbdb->forums, compact( 'forum_name', 'forum_desc', 'forum_parent', 'forum_order' ), compact( 'forum_id' ) ); 
     584        if ($update_result) 
     585                if ($forum_is_category) 
     586                        bb_update_forummeta($forum_id, 'forum_is_category', $forum_is_category); 
     587                else 
     588                        bb_delete_forummeta($forum_id, 'forum_is_category'); 
     589        return $update_result; 
    581590} 
    582591 
     
    662671                </tr> 
    663672                <tr id="forum-parent-row"><th scope="row"><label for="forum_parent"><?php _e('Forum Parent:'); ?></label></th> 
    664                         <td><?php bb_forum_dropdown( array('cut_branch' => $forum_id, 'id' => 'forum_parent', 'none' => true, 'selected' => $forum_id ? get_forum_parent( $forum_id ) : 0) ); ?></td> 
     673                        <td><?php bb_forum_dropdown( array('cut_branch' => $forum_id, 'id' => 'forum_parent', 'none' => true, 'selected' => $forum_id ? get_forum_parent( $forum_id ) : 0, 'disable_categories' => 0) ); ?></td> 
    665674                </tr> 
    666675                <tr id="forum-position-row"><th scope="row"><label for="forum-order"><?php _e('Position:'); ?></label></th> 
    667676                        <td><input type="text" name="forum_order" id="forum-order" value="<?php if ( $forum_id ) echo get_forum_position( $forum_id ); ?>" tabindex="12" maxlength="10" class="widefat" /></td> 
     677                </tr> 
     678                <tr id="forum-is-category-row"><th scope="row"><label for="forum-is-category"><?php _e('Forum is Category:'); ?></label></th> 
     679                        <td><input type="checkbox" name="forum_is_category" id="forum-is-category" value="1" <?php if ( $forum_id && bb_get_forum_is_category($forum_id) ) : ?>checked="checked" <?php endif; ?>tabindex="13" /></td> 
    668680                </tr> 
    669681        </table> 
  • trunk/bb-includes/template-functions.php

    r1517 r1531  
    130130function post_form( $h2 = '' ) { 
    131131        global $page, $topic, $forum; 
     132         
     133        if ($forum->forum_is_category) 
     134                return; 
     135         
    132136        $add = topic_pages_add(); 
    133137        if ( empty($h2) && false !== $h2 ) { 
     
    547551} 
    548552 
     553function bb_get_forum_is_category( $forum_id = 0 ) { 
     554        $forum = get_forum( get_forum_id( $forum_id ) ); 
     555        return apply_filters( 'bb_get_forum_is_category', $forum->forum_is_category, $forum->forum_id ); 
     556} 
     557 
    549558function forum_topics( $forum_id = 0 ) { 
    550559        echo apply_filters( 'forum_topics', get_forum_topics( $forum_id ), $forum_id ); 
     
    22082217 
    22092218function bb_get_forum_dropdown( $args = '' ) { 
    2210         $defaults = array( 'callback' => false, 'callback_args' => false, 'id' => 'forum_id', 'none' => false, 'selected' => false, 'tab' => 5, 'hierarchical' => 1, 'depth' => 0, 'child_of' => 0 ); 
     2219        $defaults = array( 'callback' => false, 'callback_args' => false, 'id' => 'forum_id', 'none' => false, 'selected' => false, 'tab' => 5, 'hierarchical' => 1, 'depth' => 0, 'child_of' => 0, 'disable_categories' => 1 ); 
    22112220        if ( $args && is_string($args) && false === strpos($args, '=') ) 
    22122221                $args = array( 'callback' => $args ); 
     
    22312240                $none = __('- None -'); 
    22322241 
    2233         $r = "<select name='$name' id='$id' tabindex='$tab'>\n"; 
     2242        $r = '<select name="' . $name . '" id="' . $id . '" tabindex="' . $tab . '">' . "\n"; 
    22342243        if ( $none ) 
    2235                 $r .= "\n<option value='0'>$none</option>\n"; 
    2236  
     2244                $r .= "\n" . '<option value="0">' . $none . '</option>' . "\n"; 
     2245 
     2246        $no_option_selected = true; 
     2247        $options = array(); 
    22372248        while ( $depth = bb_forum() ) : 
    22382249                global $forum; // Globals + References = Pain 
    2239                 $_selected = ( !$selected && $forum_id == $forum->forum_id || $selected == $forum->forum_id ) ? " selected='selected'" : ''; 
    2240                 $r .= "\n<option value='$forum->forum_id'$_selected>" . str_repeat( '&nbsp;&nbsp;&nbsp;', $depth - 1 ) . " $forum->forum_name</option>\n"; 
     2250                if ($disable_categories && $forum->forum_is_category) { 
     2251                        $options[] = array( 
     2252                                'value' => 0, 
     2253                                'display' => str_repeat( '&nbsp;&nbsp;&nbsp;', $depth - 1 ) . $forum->forum_name, 
     2254                                'disabled' => true, 
     2255                                'selected' => false 
     2256                        ); 
     2257                        continue; 
     2258                } 
     2259                $_selected = false; 
     2260                if ( (!$selected && $forum_id == $forum->forum_id) || $selected == $forum->forum_id ) { 
     2261                        $_selected = true; 
     2262                        $no_option_selected = false; 
     2263                } 
     2264                $options[] = array( 
     2265                        'value' => $forum->forum_id, 
     2266                        'display' => str_repeat( '&nbsp;&nbsp;&nbsp;', $depth - 1 ) . $forum->forum_name, 
     2267                        'disabled' => false, 
     2268                        'selected' => $_selected 
     2269                ); 
    22412270        endwhile; 
     2271         
     2272        foreach ($options as $option_index => $option_value) { 
     2273                if (!$none && !$selected && $no_option_selected && !$option_value['disabled']) { 
     2274                        $option_value['selected'] = true; 
     2275                        $no_option_selected = false; 
     2276                } 
     2277                $option_disabled = $option_value['disabled'] ? ' disabled="disabled"' : ''; 
     2278                $option_selected = $option_value['selected'] ? ' selected="selected"' : ''; 
     2279                $r .= "\n" . '<option value="' . $option_value['value'] . '"' . $option_disabled . $option_selected . '>' . $option_value['display'] . '</option>' . "\n"; 
     2280        } 
     2281         
    22422282        $forum = $old_global; 
    2243         $r .= "</select>\n"; 
     2283        $r .= '</select>' . "\n"; 
    22442284        return $r; 
    22452285} 
  • trunk/bb-templates/kakumei/forum.php

    r1337 r1531  
    4848 
    4949<?php while ( bb_forum() ) : ?> 
     50<?php if (bb_get_forum_is_category()) : ?> 
     51<tr<?php bb_forum_class('bb-category'); ?>> 
     52        <td colspan="3"><?php bb_forum_pad( '<div class="nest">' ); ?><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small><?php bb_forum_pad( '</div>' ); ?></td> 
     53</tr> 
     54<?php continue; endif; ?> 
    5055<tr<?php bb_forum_class(); ?>> 
    5156        <td><?php bb_forum_pad( '<div class="nest">' ); ?><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small><?php bb_forum_pad( '</div>' ); ?></td> 
  • trunk/bb-templates/kakumei/front-page.php

    r1337 r1531  
    5151</tr> 
    5252<?php while ( bb_forum() ) : ?> 
     53<?php if (bb_get_forum_is_category()) : ?> 
     54<tr<?php bb_forum_class('bb-category'); ?>> 
     55        <td colspan="3"><?php bb_forum_pad( '<div class="nest">' ); ?><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small><?php bb_forum_pad( '</div>' ); ?></td> 
     56</tr> 
     57<?php continue; endif; ?> 
    5358<tr<?php bb_forum_class(); ?>> 
    5459        <td><?php bb_forum_pad( '<div class="nest">' ); ?><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a><small><?php forum_description(); ?></small><?php bb_forum_pad( '</div>' ); ?></td> 
  • trunk/bb-templates/kakumei/style.css

    r1508 r1531  
    478478        padding: 5px 10px; 
    479479        text-transform: uppercase; 
     480} 
     481 
     482tr.bb-category td { 
     483        background-color: #ddd; 
    480484} 
    481485