Ticket #520: categories-build719.patch

File categories-build719.patch, 50.0 KB (added by sambauers, 5 years ago)
  • bb-templates/kakumei/style.css

     
    169169        padding-bottom: 10px; 
    170170} 
    171171 
    172 #front-page #main h2, h2.post-form, #userlogin, #currentfavorites, #register { 
     172#front-page #main h2, #category-page #main h2, h2.post-form, #userlogin, #currentfavorites, #register { 
    173173        color: #333; 
    174174        border-bottom: 1px solid #ddd; 
    175175        margin: 0 0 10px; 
     
    180180 
    181181.sticky { background: #a1d29a; } 
    182182 
     183tr.category { 
     184        background-color: #4fad4f; 
     185        color: #ffffff; 
     186} 
     187 
     188tr.category td { 
     189        border-top: 1px solid #91d691; 
     190        border-bottom: 1px solid #176e17; 
     191} 
     192 
     193.category:hover { background-color: #339a33 !important; } 
     194 
     195tr.category a { color: #cdf6cd; } 
     196 
     197tr.category h3 { display: inline; } 
     198 
     199tr.category p { margin: 0.3em 0 0 0; } 
     200 
    183201/* Topic Page 
    184202=================================== */ 
    185203 
  • bb-templates/kakumei/category.php

     
     1<?php bb_get_header(); ?> 
     2 
     3<h3 class="bbcrumb"><a href="<?php bb_option('uri'); ?>"><?php bb_option('name'); ?></a> &raquo; <?php bb_category_name(); ?></h3> 
     4 
     5<?php if ( $topics || $stickies ) : ?> 
     6 
     7<h2><?php _e('Latest Discussions'); ?></h2> 
     8 
     9<table id="latest"> 
     10<tr> 
     11        <th><?php _e('Topic'); ?> &#8212; <?php new_topic(); ?></th> 
     12        <th><?php _e('Posts'); ?></th> 
     13        <th><?php _e('Last Poster'); ?></th> 
     14        <th><?php _e('Freshness'); ?></th> 
     15</tr> 
     16 
     17<?php if ( $stickies ) : foreach ( $stickies as $topic ) : ?> 
     18<tr<?php topic_class(); ?>> 
     19        <td><?php _e('Sticky:'); ?> <big><a href="<?php topic_link(); ?>"><?php topic_title(); ?></a></big></td> 
     20        <td class="num"><?php topic_posts(); ?></td> 
     21        <td class="num"><?php topic_last_poster(); ?></td> 
     22        <td class="num"><small><?php topic_time(); ?></small></td> 
     23</tr> 
     24<?php endforeach; endif; ?> 
     25 
     26<?php if ( $topics ) : foreach ( $topics as $topic ) : ?> 
     27<tr<?php topic_class(); ?>> 
     28        <td><a href="<?php topic_link(); ?>"><?php topic_title(); ?></a></td> 
     29        <td class="num"><?php topic_posts(); ?></td> 
     30        <td class="num"><?php topic_last_poster(); ?></td> 
     31        <td class="num"><small><?php topic_time(); ?></small></td> 
     32</tr> 
     33<?php endforeach; endif; ?> 
     34</table> 
     35 
     36<?php endif; ?> 
     37 
     38<h2><?php _e('Forums'); ?></h2> 
     39 
     40<?php 
     41add_filter('get_forums_where', 'bb_get_forums_where_in_category_filter', 1); 
     42$forums = get_forums(); 
     43?> 
     44 
     45<p style="float:right;"><?php bb_category_forums(); ?> <?php echo __ngettext('forum', 'forums', bb_get_category_forums()); ?></p> 
     46 
     47<p><?php bb_category_description(); ?></p> 
     48 
     49<?php if ( $forums ) : ?> 
     50 
     51<table style="clear:both;" id="forumlist"> 
     52 
     53<tr> 
     54        <th><?php _e('Main Theme'); ?></th> 
     55        <th><?php _e('Topics'); ?></th> 
     56        <th><?php _e('Posts'); ?></th> 
     57</tr> 
     58 
     59<?php foreach ( $forums as $forum ) : ?> 
     60<tr<?php alt_class('forum'); ?>> 
     61        <td><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a> &#8212; <small><?php forum_description(); ?></small></td> 
     62        <td class="num"><?php forum_topics(); ?></td> 
     63        <td class="num"><?php forum_posts(); ?></td> 
     64</tr> 
     65<?php endforeach; // forums ?> 
     66</table> 
     67<?php endif; // forums ?> 
     68 
     69<p><a href="<?php bb_category_rss_link(); ?>"><?php _e('RSS feed for this category'); ?></a></p> 
     70 
     71<?php bb_get_footer(); ?> 
  • bb-templates/kakumei/topic.php

     
    11<?php bb_get_header(); ?> 
    22 
    3 <h3 class="bbcrumb"><a href="<?php bb_option('uri'); ?>"><?php bb_option('name'); ?></a> &raquo; <a href="<?php forum_link(); ?>"><?php forum_name(); ?></a></h3> 
     3<h3 class="bbcrumb"> 
     4        <a href="<?php bb_option('uri'); ?>"><?php bb_option('name'); ?></a> &raquo; 
     5<?php if ( $category ): ?> 
     6        <a href="<?php bb_category_link(); ?>"><?php bb_category_name(); ?></a> &raquo; 
     7<?php endif; ?> 
     8        <a href="<?php forum_link(); ?>"><?php forum_name(); ?></a> 
     9</h3> 
    410<div class="infobox"> 
    511 
    612<div id="topic-info"> 
  • bb-templates/kakumei/forum.php

     
    11<?php bb_get_header(); ?> 
    22 
    3 <h3 class="bbcrumb"><a href="<?php bb_option('uri'); ?>"><?php bb_option('name'); ?></a> &raquo; <?php forum_name(); ?></h3> 
     3<h3 class="bbcrumb"> 
     4        <a href="<?php bb_option('uri'); ?>"><?php bb_option('name'); ?></a> &raquo; 
     5<?php if ( $category ): ?> 
     6        <a href="<?php bb_category_link(); ?>"><?php bb_category_name(); ?></a> &raquo; 
     7<?php endif; ?> 
     8        <?php forum_name(); ?> 
     9</h3> 
    410 
    511<?php if ( $topics || $stickies ) : ?> 
    612 
  • bb-templates/kakumei/front-page.php

     
    4040</table> 
    4141<?php endif; ?> 
    4242 
     43<?php if ( $categories ) : ?> 
     44 
    4345<h2><?php _e('Forums'); ?></h2> 
     46 
    4447<table id="forumlist"> 
    4548 
    4649<tr> 
     
    4952        <th><?php _e('Posts'); ?></th> 
    5053</tr> 
    5154 
     55<?php foreach ( $categories as $category ) : ?> 
     56 
     57<?php if ( $category->category_id ) : ?> 
     58<?php 
     59add_filter('get_forums_where', 'bb_get_forums_where_in_category_filter', 1); 
     60$forums = get_forums(); 
     61?> 
     62 
     63<?php if ( $forums ) : ?> 
     64<tr class="category"> 
     65        <td colspan="3"> 
     66                <h3><a href="<?php bb_category_link(); ?>"><?php bb_category_name(); ?></a></h3> &#8212; <?php bb_category_forums(); ?> <?php echo __ngettext('forum', 'forums', bb_get_category_forums()); ?> 
     67<?php if ( bb_get_category_description() ) : ?> 
     68                <p><small><?php bb_category_description(); ?></small></p> 
     69<?php endif; ?> 
     70        </td> 
     71</tr> 
     72<?php endif; ?> 
     73 
     74<?php endif; ?> 
     75 
     76<?php if ( $forums ) : ?> 
    5277<?php foreach ( $forums as $forum ) : ?> 
    5378<tr<?php alt_class('forum'); ?>> 
    5479        <td><a href="<?php forum_link(); ?>"><?php forum_name(); ?></a> &#8212; <small><?php forum_description(); ?></small></td> 
     
    5681        <td class="num"><?php forum_posts(); ?></td> 
    5782</tr> 
    5883<?php endforeach; ?> 
     84<?php elseif ( count($categories) < 2 ) : ?> 
     85<tr> 
     86        <td colspan="3"><?php _e('No forums available.'); ?></td> 
     87</tr> 
     88<?php endif; ?> 
     89 
     90<?php endforeach; // catagories ?> 
     91 
    5992</table> 
    6093 
     94<?php endif; // catagories ?> 
     95 
    6196<?php if ( bb_is_user_logged_in() ) : ?> 
    6297<div id="viewdiv"> 
    6398<h2><?php _e('Views'); ?></h2> 
  • bb-includes/capabilities.php

     
    3737                                                'edit_users' => true, 
    3838                                                'manage_tags' => true,          // Rename, Merge, Destroy 
    3939                                                'edit_others_favorites' => true, 
     40                                                'manage_categories' => true, 
     41                                                'delete_categories' => true, 
    4042                                                'manage_forums' => true,        // Add/Rename forum 
    4143                                                'delete_forums' => true,        // Delete forum 
    4244                                                'delete_topics' => true, 
     
    7476                                                'edit_users' => true,                   //+ 
    7577                                                'manage_tags' => true,                  //+ 
    7678                                                'edit_others_favorites' => true,        //+ 
     79                                                'manage_categories' => true, 
     80                                                'delete_categories' => true, 
    7781                                                'manage_forums' => true,                //+ 
    7882                                                'delete_forums' => true,                //+ 
    7983                                                'delete_topics' => true, 
     
    435439                        $caps[] = 'edit_favorites'; 
    436440                else    $caps[] = 'edit_others_favorites'; 
    437441                break; 
     442        case 'delete_category': 
     443                $caps[] = 'delete_categories'; 
     444                break; 
    438445        case 'delete_forum': 
    439446                $caps[] = 'delete_forums'; 
    440447                break; 
  • bb-includes/default-filters.php

     
    4949 
    5050if ( !bb_get_option( 'mod_rewrite' ) ) { 
    5151        add_filter( 'bb_stylesheet_uri', 'attribute_escape', 1, 9999 ); 
     52        add_filter( 'bb_category_link', 'attribute_escape', 1, 9999 ); 
     53        add_filter( 'bb_category_rss_link', 'attribute_escape', 1, 9999 ); 
    5254        add_filter( 'forum_link', 'attribute_escape', 1, 9999 ); 
    5355        add_filter( 'forum_rss_link', 'attribute_escape', 1, 9999 ); 
    5456        add_filter( 'tag_link', 'attribute_escape', 1, 9999 ); 
  • bb-includes/cache.php

     
    137137                return $posts; 
    138138        } 
    139139 
     140        function get_categories() { 
     141                global $bbdb; 
     142 
     143                $normal = true; 
     144                if ( '' != $where = apply_filters('bb_get_categories_where', '') ) 
     145                        $normal = false; 
     146 
     147                if ( $this->use_cache && $normal && file_exists(BBPATH . 'bb-cache/bb_categories') ) 
     148                        return $this->read_cache(BBPATH . 'bb-cache/bb_categories'); 
     149 
     150                $categories = $bbdb->get_results("SELECT * FROM $bbdb->categories $where ORDER BY category_order"); 
     151                if ( $this->use_cache && $normal && $categories ) 
     152                        $this->write_cache(BBPATH . 'bb-cache/bb_categories', $categories); 
     153                return $categories; 
     154        } 
     155 
     156        function get_category( $category_id ) { 
     157                global $bbdb; 
     158                $category_id = (int) $category_id; 
     159 
     160                $normal = true; 
     161                if ( '' != $where = apply_filters('bb_get_category_where', '') ) 
     162                        $normal = false; 
     163 
     164                if ( $this->use_cache && $normal && file_exists(BBPATH . 'bb-cache/bb_category-' . $category_id) ) 
     165                        return $this->read_cache(BBPATH . 'bb-cache/bb_category-' . $category_id); 
     166 
     167                $category = $bbdb->get_row("SELECT * FROM $bbdb->categories WHERE category_id = $category_id $where"); 
     168                if ( $this->use_cache && $normal && $category ) 
     169                        $this->write_cache(BBPATH . 'bb-cache/bb_category-' . $category_id, $category); 
     170                return $category; 
     171        } 
     172 
    140173        function get_forums() { 
    141174                global $bbdb; 
    142175 
    143176                $normal = true; 
     177                if ( '' != $join = apply_filters('get_forums_join', '') ) 
     178                        $normal = false; 
    144179                if ( '' != $where = apply_filters('get_forums_where', '') ) 
    145180                        $normal = false; 
     181                if ( 'ORDER BY forum_order' != $orderby = apply_filters('get_forums_orderby', 'ORDER BY forum_order')) 
     182                        $normal = false; 
    146183 
    147184                if ( $this->use_cache && $normal && file_exists(BBPATH . 'bb-cache/bb_forums') ) 
    148185                        return $this->read_cache(BBPATH . 'bb-cache/bb_forums'); 
    149186 
    150                 $forums = (array) $bbdb->get_results("SELECT * FROM $bbdb->forums $where ORDER BY forum_order"); 
     187                $forums = (array) $bbdb->get_results("SELECT * FROM $bbdb->forums $join $where $orderby"); 
     188 
    151189                if ( $this->use_cache && $normal && $forums ) 
    152190                        $this->write_cache(BBPATH . 'bb-cache/bb_forums', $forums); 
    153191                return $forums; 
  • bb-includes/functions.php

     
    11<?php 
    22 
     3function bb_get_categories() { 
     4        global $bb_cache; 
     5        return apply_filters('bb_get_categories',$bb_cache->get_categories()); 
     6} 
     7 
     8function bb_get_category( $id ) { 
     9        global $bb_cache; 
     10        return $bb_cache->get_category( $id ); 
     11} 
     12 
    313function get_forums( $callback = false, $callback_args = false ) { 
    414        global $bb_cache; 
    515        $forums = (array) apply_filters('get_forums',$bb_cache->get_forums()); 
     
    95105        else    return false; 
    96106} 
    97107 
     108function bb_get_latest_category_topics( $category = 0, $page = 1, $exclude = '') { 
     109        global $bbdb, $bb_last_countable_query; 
     110        $category = (int) $category; 
     111        $page = (int) $page; 
     112        $where = 'WHERE topic_status = 0'; 
     113        if ( $category ) 
     114                $where .= " AND category_id = $category "; 
     115        if ( !empty( $exclude ) ) 
     116                $where .= " AND category_id NOT IN ('$exclude') "; 
     117        if ( bb_is_category() || is_view() ) 
     118                $where .= " AND topic_sticky = 0 "; 
     119        $limit = bb_get_option('page_topics'); 
     120        $where = apply_filters('bb_get_latest_category_topics_where', $where); 
     121        if ( 1 < $page ) 
     122                $limit = ($limit * ($page - 1)) . ", $limit"; 
     123        $bb_last_countable_query = "SELECT * FROM $bbdb->topics LEFT JOIN $bbdb->forums ON " . $bbdb->forums . ".forum_id = " . $bbdb->topics . ".forum_id $where ORDER BY topic_time DESC LIMIT $limit"; 
     124        if ( $topics = $bbdb->get_results($bb_last_countable_query) ) 
     125                return bb_append_meta( $topics, 'topic' ); 
     126        else 
     127                return false; 
     128} 
    98129 
     130function bb_get_sticky_category_topics( $category = 0, $display = 1 ) { 
     131        global $bbdb, $bb_last_countable_query; 
     132        if ( 1 != $display ) 
     133                return false; 
     134        $category = (int) $category; 
     135        $where = 'WHERE topic_sticky <> 0 AND topic_status = 0'; 
     136        if ( $category ) 
     137                $where .= " AND category_id = $category "; 
     138        $where = apply_filters('bb_get_sticky_category_topics_where', $where); 
     139        $bb_last_countable_query = "SELECT * FROM $bbdb->topics LEFT JOIN $bbdb->forums ON " . $bbdb->forums . ".forum_id = " . $bbdb->topics . ".forum_id $where ORDER BY topic_time DESC"; 
     140        if ( $stickies = $bbdb->get_results($bb_last_countable_query) ) 
     141                return bb_append_meta( $stickies, 'topic' );     
     142        else    return false; 
     143} 
     144 
     145 
    99146// Globalizes the result. 
    100147function bb_get_first_post( $_topic = false, $author_cache = true ) { 
    101148        global $topic, $bb_first_post_cache, $bb_post; 
     
    229276        return; 
    230277} 
    231278 
     279function bb_move_category_forums( $from_category_id, $to_category_id ) { 
     280        global $bb_cache, $bbdb; 
     281         
     282        $from_category_id = (int) $from_category_id ; 
     283        $to_category_id = (int) $to_category_id; 
     284         
     285        add_filter('get_category_where', 'no_where'); // Just in case 
     286         
     287        $from_category = bb_get_category( $from_category_id ); 
     288        if ( !$to_category = bb_get_category( $to_category_id ) ) 
     289                return false; 
     290 
     291        $bb_cache->flush_many( 'category', $from_category_id ); 
     292        $bb_cache->flush_many( 'category', $to_category_id ); 
     293         
     294        $forums = $to_category->forums + ( $from_category ? $from_category->forums : 0 ); 
     295         
     296        $bbdb->query("UPDATE $bbdb->categories SET forums = '$forums' WHERE category_id = '$to_category_id'"); 
     297        $bbdb->query("UPDATE $bbdb->categories SET forums = 0 WHERE category_id = '$from_category_id'"); 
     298        $forum_ids = $bbdb->get_col("SELECT forum_id FROM $bbdb->forums WHERE category_id = '$from_category_id'"); 
     299        $return = $bbdb->query("UPDATE $bbdb->forums SET category_id = '$to_category_id' WHERE category_id = '$from_category_id'"); 
     300        if ( $forum_ids ) 
     301                foreach ( $forum_ids as $forum_id ) { 
     302                        $bb_cache->flush_one( 'forum', $forum_id ); 
     303                } 
     304        $bb_cache->flush_one( 'category', $to_category_id ); 
     305        $bb_cache->flush_many( 'category', $from_category_id ); 
     306        return $return; 
     307} 
     308 
    232309function bb_move_forum_topics( $from_forum_id, $to_forum_id ) { 
    233310        global $bb_cache, $bbdb; 
    234311         
     
    285362        return $bbdb->get_results("SELECT * FROM $bbdb->posts $where ORDER BY post_time DESC LIMIT $limit"); 
    286363} 
    287364 
     365function bb_get_latest_category_posts( $category_id, $limit = 0, $page = 1 ) { 
     366        global $bbdb; 
     367        $limit = (int) $limit; 
     368        $category_id = (int) $category_id; 
     369        if ( !$limit ) 
     370                $limit = bb_get_option( 'page_topics' ); 
     371        if ( 1 < $page ) 
     372                $limit = ($limit * ($page - 1)) . ", $limit"; 
     373        $where = apply_filters('bb_get_latest_category_posts_where', "WHERE `" . $bbdb->forums . "`.category_id = '$category_id' AND post_status = 0"); 
     374        return $bbdb->get_results("SELECT * FROM $bbdb->posts LEFT JOIN $bbdb->forums ON `" . $bbdb->forums . "`.forum_id = `" . $bbdb->posts . "`.forum_id $where ORDER BY post_time DESC LIMIT $limit"); 
     375} 
     376 
    288377function get_user_favorites( $user_id, $list = false ) { 
    289378        global $bbdb, $page; 
    290379        $user = bb_get_user( $user_id ); 
     
    851940 
    852941 
    853942 
    854 function bb_new_forum( $name, $desc, $order = 0 ) { 
     943function bb_new_category( $name, $desc, $order = 0 ) { 
     944        global $bbdb, $bb_cache, $bb_current_user; 
     945        if ( !bb_current_user_can('manage_categories') ) 
     946                return false; 
     947        if ( strlen($name) < 1 ) 
     948                return false; 
     949        $bbdb->query("INSERT INTO $bbdb->categories (category_name, category_desc, category_order) VALUES ('$name', '$desc', '$order')"); 
     950        $bb_cache->flush_one( 'categories' ); 
     951        return $bbdb->insert_id; 
     952} 
     953 
     954function bb_update_category( $category_id, $name, $desc, $order = 0 ) { 
     955        global $bbdb, $bb_cache, $bb_current_user; 
     956        if ( !bb_current_user_can('manage_categories') ) 
     957                return false; 
     958        if ( !$category_id = (int) $category_id ) 
     959                return false; 
     960        $order = (int) $order; 
     961        if ( strlen($name) < 1 ) 
     962                return false; 
     963        $bb_cache->flush_many( 'category', $category_id ); 
     964        return $bbdb->query("UPDATE $bbdb->categories SET category_name = '$name', category_desc = '$desc', category_order = '$order' WHERE category_id = $category_id"); 
     965} 
     966 
     967// When you delete a category, the underlying forums are given a category_id of 0 
     968function bb_delete_category( $category_id ) { 
    855969        global $bbdb, $bb_cache; 
     970        if ( !bb_current_user_can( 'delete_category', $category_id ) ) 
     971                return false; 
     972        if ( !$category_id = (int) $category_id ) 
     973                return false; 
     974 
     975        $category = get_forum( $category_id ); 
     976         
     977        if ( $forum_ids = $bbdb->get_col("SELECT forum_id FROM $bbdb->forums WHERE category_id = '$category_id'") ) { 
     978                $_forum_ids = join(',', $forum_ids); 
     979                $bbdb->query("UPDATE $bbdb->forums SET category_id = 0 WHERE forum_id IN ($_forum_ids)"); 
     980        } 
     981         
     982        $return = $bbdb->query("DELETE FROM $bbdb->categories WHERE category_id = $category_id"); 
     983 
     984        if ( $forum_ids ) 
     985                foreach ( $forum_ids as $forum_id ) { 
     986                        $bb_cache->flush_one( 'forum', $forum_id ); 
     987                } 
     988 
     989        $bb_cache->flush_one( 'categories' ); 
     990        return $return; 
     991} 
     992 
     993function bb_new_forum( $name, $desc, $order = 0, $category_id = 0 ) { 
     994        global $bbdb, $bb_cache; 
    856995        if ( !bb_current_user_can( 'manage_forums' ) ) 
    857996                return false; 
    858997        if ( strlen($name) < 1 ) 
    859998                return false; 
    860         $bbdb->query("INSERT INTO $bbdb->forums (forum_name, forum_desc, forum_order) VALUES ('$name', '$desc', '$order')"); 
     999        $bbdb->query("INSERT INTO $bbdb->forums (category_id, forum_name, forum_desc, forum_order) VALUES ($category_id, '$name', '$desc', '$order')"); 
     1000        $bbdb->query("UPDATE $bbdb->categories SET forums = forums + 1 WHERE category_id = $category_id"); 
    8611001        $bb_cache->flush_one( 'forums' ); 
     1002        $bb_cache->flush_many( 'category', $category_id ); 
    8621003        return $bbdb->insert_id; 
    8631004} 
    8641005 
    865 function bb_update_forum( $forum_id, $name, $desc, $order = 0 ) { 
     1006function bb_update_forum( $forum_id, $name, $desc, $order = 0, $category_id = 0 ) { 
    8661007        global $bbdb, $bb_cache; 
    8671008        if ( !bb_current_user_can( 'manage_forums' ) ) 
    8681009                return false; 
     
    8711012        $order = (int) $order; 
    8721013        if ( strlen($name) < 1 ) 
    8731014                return false; 
     1015         
     1016        $forum = get_forum( $forum_id ); 
     1017         
     1018        $return = $bbdb->query("UPDATE $bbdb->forums SET category_id = $category_id, forum_name = '$name', forum_desc = '$desc', forum_order = '$order' WHERE forum_id = $forum_id"); 
     1019        $bbdb->query("UPDATE $bbdb->categories SET forums = forums + 1 WHERE category_id = $category_id"); 
     1020        $bbdb->query("UPDATE $bbdb->categories SET forums = forums - 1 WHERE category_id = $forum->category_id"); 
    8741021        $bb_cache->flush_many( 'forum', $forum_id ); 
    875         return $bbdb->query("UPDATE $bbdb->forums SET forum_name = '$name', forum_desc = '$desc', forum_order = '$order' WHERE forum_id = $forum_id"); 
     1022        $bb_cache->flush_one( 'categories' ); 
     1023        return $return; 
    8761024} 
    8771025 
    8781026// When you delete a forum, you delete *everything* 
     
    8831031        if ( !$forum_id = (int) $forum_id ) 
    8841032                return false; 
    8851033 
     1034        $forum = get_forum( $forum_id ); 
     1035         
    8861036        if ( $topic_ids = $bbdb->get_col("SELECT topic_id FROM $bbdb->topics WHERE forum_id = '$forum_id'") ) { 
    8871037                $_topic_ids = join(',', $topic_ids); 
    8881038                $bbdb->query("DELETE FROM $bbdb->posts WHERE topic_id IN ($_topic_ids) AND topic_id != 0"); 
     
    8911041        } 
    8921042         
    8931043        $return = $bbdb->query("DELETE FROM $bbdb->forums WHERE forum_id = $forum_id"); 
     1044        $bbdb->query("UPDATE $bbdb->categories SET forums = forums - 1 WHERE category_id = $forum->category_id"); 
    8941045 
    8951046        if ( $topic_ids ) 
    8961047                foreach ( $topic_ids as $topic_id ) { 
     
    8991050                } 
    9001051 
    9011052        $bb_cache->flush_many( 'forum', $forum_id ); 
     1053        $bb_cache->flush_one( 'categories' ); 
    9021054        return $return; 
    9031055} 
    9041056 
     
    15961748 
    15971749        do_action( 'pre_permalink', $permalink ); 
    15981750 
    1599         if ( is_forum() ) { 
     1751        if ( bb_is_category() ) { 
     1752                global $category_id; 
     1753                $category_id = $permalink; 
     1754                $permalink = bb_get_category_link( $permalink, $page ); 
     1755        } elseif ( is_forum() ) { 
    16001756                global $forum_id; 
    16011757                $forum_id = $permalink; 
    16021758                $permalink = get_forum_link( $permalink, $page ); 
     
    18892045                $trans['update']['forums'] = array(__("Are you sure you want to update your forums?"), false); 
    18902046                $trans['delete']['forums'] = array(__("Are you sure you want to delete that forum?"), false); 
    18912047 
     2048                $trans['add']['category'] = array(__("Are you sure you want to add this category?"), false); 
     2049                $trans['update']['categories'] = array(__("Are you sure you want to update your categories?"), false); 
     2050                $trans['delete']['category'] = array(__("Are you sure you want to delete that category?"), false); 
     2051 
    18922052                $trans['do']['counts'] = array(__("Are you sure you want to recount these items?"), false); 
    18932053 
    18942054                $trans['switch']['theme'] = array(__("Are you sure you want to switch themes?"), false); 
  • bb-includes/bozo.php

     
    281281 
    282282add_action( 'pre_permalink', 'bozo_pre_permalink' ); 
    283283add_action( 'bb_index.php_pre_db', 'bozo_latest_filter' ); 
     284add_action( 'bb_category.php_pre_db', 'bozo_latest_filter' ); 
    284285add_action( 'bb_forum.php_pre_db', 'bozo_latest_filter' ); 
    285286add_action( 'bb_topic.php_pre_db', 'bozo_topic_db_filter' ); 
    286287add_action( 'bb_profile.php_pre_db', 'bozo_profile_db_filter' ); 
  • bb-includes/template-functions.php

     
    11<?php 
    22 
    33function bb_load_template( $file, $globals = false ) { 
    4         global $bb, $bbdb, $bb_current_user, $page, $bb_cache, 
     4        global $bb, $bbdb, $bb_current_user, $category, $categories, $page, $bb_cache, 
    55                $posts, $bb_post, $post_id, $topics, $topic, $topic_id, 
    66                $forums, $forum, $forum_id, $tags, $tag, $tag_name, $user, $user_id, $view; 
    77 
     
    193193        case 'index.php' : 
    194194                return 'front-page'; 
    195195                break; 
     196        case 'category.php' : 
     197                return 'category-page'; 
     198                break; 
    196199        case 'forum.php' : 
    197200                return 'forum-page'; 
    198201                break; 
     
    236239                return false; 
    237240} 
    238241 
     242function bb_is_category() { 
     243        if ( 'category-page' == get_bb_location() ) 
     244                return true; 
     245        else 
     246                return false; 
     247} 
     248 
    239249function is_forum() { 
    240250        if ( 'forum-page' == get_bb_location() ) 
    241251                return true; 
     
    310320                $title = get_topic_title(). ' &laquo; '; 
    311321        if ( is_forum() ) 
    312322                $title = get_forum_name() . ' &laquo; '; 
     323        if ( bb_is_category() ) 
     324                $title = bb_get_category_name() . ' &laquo; '; 
    313325        if ( is_tag() ) 
    314326                $title = wp_specialchars( get_tag_name() ). ' &laquo; ' . __('Tags') . ' &laquo; '; 
    315327        if ( is_bb_profile() ) 
     
    329341                $feed_link = '<link rel="alternate" type="application/rss+xml" title="' . attribute_escape( sprintf( __('Tag: %s'), get_tag_name() ) ) . '" href="' . attribute_escape( get_tag_rss_link() ) . '" />'; 
    330342        elseif ( is_forum() ) 
    331343                $feed_link = '<link rel="alternate" type="application/rss+xml" title="' . attribute_escape( sprintf( __('Forum: %s'), get_forum_name() ) ) . '" href="' . attribute_escape( get_forum_rss_link() ) . '" />'; 
     344        elseif ( bb_is_category() ) 
     345                $feed_link = '<link rel="alternate" type="application/rss+xml" title="' . attribute_escape( sprintf( __('Category: %s'), bb_get_category_name() ) ) . '" href="' . attribute_escape( bb_get_category_rss_link() ) . '" />'; 
    332346        elseif ( is_front() ) 
    333347                $feed_link = '<link rel="alternate" type="application/rss+xml" title="' . attribute_escape( __('Recent Posts') ) . '" href="' . attribute_escape( get_recent_rss_link() ) . '" />'; 
    334348        echo apply_filters('bb_feed_head', $feed_link); 
     
    342356        return apply_filters( 'get_recent_rss_link', $link ); 
    343357} 
    344358 
     359// CATEGORIES 
     360 
     361function bb_get_forums_where_in_category_filter() { 
     362        global $category; 
     363        if ($category->category_id) 
     364                return 'WHERE category_id = ' . $category->category_id; 
     365        else    return NULL; 
     366} 
     367 
     368function bb_get_forums_join_categories_filter() { 
     369        global $bbdb; 
     370        return 'LEFT JOIN `' . $bbdb->categories . '` ON `' . $bbdb->categories . '`.`category_id` = `' . $bbdb->forums . '`.`category_id`'; 
     371} 
     372 
     373function bb_get_forums_orderby_category_order_filter() { 
     374        return 'ORDER BY `category_order`, `forum_order`'; 
     375} 
     376 
     377function bb_category_id() { 
     378        echo apply_filters( 'bb_category_id', bb_get_category_id() ); 
     379} 
     380 
     381function bb_get_category_id() { 
     382        global $category; 
     383        return $category->category_id; 
     384} 
     385 
     386function bb_category_link( $category_id = 0, $page = 1 ) { 
     387        echo apply_filters('bb_category_link', bb_get_category_link( $category_id, $page ), $category_id ); 
     388} 
     389 
     390function bb_get_category_link( $category_id = 0, $page = 1 ) { 
     391        global $category; 
     392 
     393        if ( $category_id ) 
     394                $category = bb_get_category( $category_id ); 
     395        if ( bb_get_option( 'mod_rewrite' ) ) 
     396                $link = bb_get_option( 'uri' ) . "category/$category->category_id" . ( 1 < $page ? "/page/$page" : '' ); 
     397        else { 
     398                $args = array(); 
     399                $link = bb_get_option( 'uri' ) . 'category.php'; 
     400                $args['id'] = $category->category_id; 
     401                $args['page'] = 1 < $page ? $page : ''; 
     402                $link = add_query_arg( $args, $link ); 
     403        } 
     404 
     405        return apply_filters( 'bb_get_category_link', $link, $category->category_id ); 
     406} 
     407 
     408function bb_category_name( $category_id = 0 ) { 
     409        echo apply_filters( 'bb_category_name', bb_get_category_name( $category_id ), $category_id ); 
     410} 
     411 
     412function bb_get_category_name( $category_id = 0 ) { 
     413        global $category; 
     414        if ( $category_id ) 
     415                $category = bb_get_category( $category_id ); 
     416        return apply_filters( 'bb_get_category_name', $category->category_name, $forum->category_id ); 
     417} 
     418 
     419function bb_category_description( $category_id = 0 ) { 
     420        echo apply_filters( 'bb_category_description', bb_get_category_description( $category_id ), $category_id ); 
     421} 
     422 
     423function bb_get_category_description( $category_id = 0 ) { 
     424        global $category; 
     425        if ( $category_id ) 
     426                $category = get_forum( $category_id ); 
     427        return apply_filters( 'bb_get_category_description', $category->category_desc, $category->category_id ); 
     428} 
     429 
     430function bb_category_forums( $category_id = 0 ) { 
     431        echo apply_filters( 'bb_category_forums', bb_get_category_forums( $category_id ), $category_id ); 
     432} 
     433 
     434function bb_get_category_forums( $category_id = 0 ) { 
     435        global $category; 
     436        if ( $category_id ) 
     437                $category = bb_get_category( $category_id ); 
     438        return apply_filters( 'bb_get_category_forums', $category->forums, $category->category_id ); 
     439} 
     440 
     441function bb_category_rss_link( $category_id = 0 ) { 
     442        echo apply_filters('bb_category_rss_link', bb_get_category_rss_link( $category_id ) ); 
     443} 
     444 
     445function bb_get_category_rss_link( $category_id = 0 ) { 
     446        global $category; 
     447 
     448        if ( $category_id ) 
     449                $category = bb_get_category( $category_id ); 
     450 
     451        if ( bb_get_option('mod_rewrite') ) 
     452                $link = bb_get_option('uri') . "rss/category/$category->category_id"; 
     453        else 
     454                $link = bb_get_option('uri') . "rss.php?category=$category->category_id"; 
     455 
     456        return apply_filters( 'bb_get_category_rss_link', $link, $category_id ); 
     457} 
     458 
    345459// FORUMS 
    346460 
    347461function forum_link( $forum_id = 0, $page = 1 ) { 
     
    778892                $class[] = 'bozo'; 
    779893        if ( '0' === $topic->topic_open ) 
    780894                $class[] = 'closed'; 
    781         if ( 1 == $topic->topic_sticky && is_forum() ) 
     895        if ( 1 == $topic->topic_sticky && ( is_forum() || bb_is_category() ) ) 
    782896                $class[] = 'sticky'; 
    783         elseif ( 2 == $topic->topic_sticky && ( is_front() || is_forum() ) ) 
     897        elseif ( 2 == $topic->topic_sticky && ( is_front() || is_forum() || bb_is_category() ) ) 
    784898                $class[] = 'sticky super-sticky'; 
    785899        $class = apply_filters( 'topic_class', $class, $topic->topic_id ); 
    786900        $class = join(' ', $class); 
     
    794908 
    795909        if ( is_forum() || is_tag() ) 
    796910                $url = '#postform'; 
    797         elseif ( is_front() ) 
     911        elseif ( is_front() || bb_is_category() ) 
    798912                $url = add_query_arg( 'new', '1', bb_get_option( 'uri' ) ); 
    799913        if ( !bb_is_user_logged_in() ) 
    800914                $url = add_query_arg( 're', urlencode($url), bb_get_option( 'uri' ) . 'bb-login.php' ); 
     
    15641678 
    15651679function bb_get_forum_dropdown( $callback = false, $callback_args = false ) { 
    15661680        global $forum_id; 
    1567         if ( !$forums = get_forums( $callback, $callback_args ) ) 
    1568                 return; 
    1569  
     1681        $categories = bb_get_categories(); 
     1682         
    15701683        $r = '<select name="forum_id" id="forum_id" tabindex="5">'; 
    1571  
    1572         foreach ( $forums as $forum ) : 
    1573                 $selected = ( $forum_id == $forum->forum_id ) ? " selected='selected'" : ''; 
    1574                 $r .= "<option value='$forum->forum_id'$selected>$forum->forum_name</option>"; 
    1575         endforeach; 
     1684        if ($categories) : 
     1685                global $category; 
     1686                foreach ( $categories as $category ) : 
     1687                        add_filter('get_forums_where', 'bb_get_forums_where_in_category_filter', 1); 
     1688                        if ( !$forums = get_forums( $callback, $callback_args ) ) 
     1689                                $forums = false; 
     1690                        if ( $forums ) : 
     1691                                $r .= "<optgroup label='$category->category_name'>"; 
     1692                                foreach ( $forums as $forum ) : 
     1693                                        $selected = ( $forum_id == $forum->forum_id ) ? " selected='selected'" : ''; 
     1694                                        $r .= "<option value='$forum->forum_id'$selected>$forum->forum_name</option>"; 
     1695                                endforeach; 
     1696                                $r .= "</optgroup>"; 
     1697                        endif; 
     1698                endforeach; 
     1699        else : 
     1700                if ( !$forums = get_forums( $callback, $callback_args ) ) 
     1701                        return; 
     1702                foreach ( $forums as $forum ) : 
     1703                        $selected = ( $forum_id == $forum->forum_id ) ? " selected='selected'" : ''; 
     1704                        $r .= "<option value='$forum->forum_id'$selected>$forum->forum_name</option>"; 
     1705                endforeach; 
     1706        endif; 
    15761707        $r .= '</select>'; 
    15771708        return $r; 
    15781709} 
  • bb-includes/db.php

     
    1717        var $queries; 
    1818 
    1919        // Our tables 
     20        var $categories; 
    2021        var $forums; 
    2122        var $posts; 
    2223        var $topics; 
  • index.php

     
    66do_action( 'bb_index.php_pre_db', '' ); 
    77 
    88if ( isset($_GET['new']) && '1' == $_GET['new'] ) : 
     9        $categories = false; 
    910        $forums = false; 
    1011elseif ( !$bb_db_override ) : 
     12        $categories = bb_get_categories(); // Comment to hide categories 
    1113        $forums = get_forums(); // Comment to hide forums 
    1214        $topics = get_latest_topics(); 
    1315        $super_stickies = get_sticky_topics(); 
     16         
     17        if ( $forums && !$categories ) : 
     18                $categories = array( 
     19                        0 => new stdClass() 
     20                ); 
     21                $categories[0]->category_id = 0; 
     22                $categories[0]->forums = $forums ? count($forums) : 0; 
     23        endif; 
    1424endif; 
    1525 
    1626do_action( 'bb_index.php', '' ); 
  • rss.php

     
    2222elseif ( 'forum' == get_path() ) 
    2323        $forum_id = (int) get_path(2); 
    2424 
     25elseif ( isset($_GET['category']) ) 
     26        $category_id = (int) $_GET['category']; 
     27elseif ( 'category' == get_path() ) 
     28        $category_id = (int) get_path(2); 
     29 
    2530$bb_db_override = false; 
    2631do_action( 'bb_rss.php_pre_db', '' ); 
    2732 
     
    4853        if ( !$posts = get_latest_forum_posts( $forum_id ) ) 
    4954                die(); 
    5055        $title = wp_specialchars( bb_get_option( 'name' ) ) . ' ' . __('Forum') . ': ' . get_forum_name( $forum_id ); 
     56} elseif ( isset($category_id) ) { 
     57        if ( !$posts = bb_get_latest_category_posts( $category_id ) ) 
     58                die(); 
     59        $title = wp_specialchars( bb_get_option( 'name' ) ) . ' ' . __('Category') . ': ' . bb_get_category_name( $category_id ); 
    5160} else { 
    5261        if ( !$posts = get_latest_posts( 35 ) ) 
    5362                die(); 
  • category.php

     
     1<?php 
     2 
     3require_once('./bb-load.php'); 
     4 
     5$category_id = 0; 
     6 
     7bb_repermalink(); 
     8 
     9if ( !$category ) 
     10        bb_die(__('Category not found.')); 
     11 
     12$bb_db_override = false; 
     13do_action( 'bb_category.php_pre_db', $category_id ); 
     14 
     15if ( !$bb_db_override ) : 
     16        add_filter('get_forums_where', 'bb_get_forums_where_in_category_filter', 1); 
     17        $forums   = get_forums(); 
     18        $topics   = bb_get_latest_category_topics( $category_id, $page ); 
     19        $stickies = bb_get_sticky_category_topics( $category_id, $page ); 
     20endif; 
     21 
     22do_action( 'bb_category.php', $category_id ); 
     23 
     24bb_load_template( 'category.php', array('bb_db_override', 'stickies') ); 
     25 
     26?> 
  • topic.php

     
    2020if ( !$bb_db_override ) : 
    2121        $posts = get_thread( $topic_id, $page ); 
    2222        $forum = get_forum ( $topic->forum_id ); 
     23        $category = bb_get_category( $forum->category_id ); 
    2324 
    2425        $tags  = get_topic_tags ( $topic_id ); 
    2526        if ( $tags && $bb_current_id = bb_get_current_user_info( 'id' ) ) { 
  • bb-settings.php

     
    6262        require( BBPATH . BBINC . 'db.php'); 
    6363} 
    6464 
     65$bbdb->categories = $bb_table_prefix . 'categories'; 
    6566$bbdb->forums    = $bb_table_prefix . 'forums'; 
    6667$bbdb->posts     = $bb_table_prefix . 'posts'; 
    6768$bbdb->topics    = $bb_table_prefix . 'topics'; 
  • bb-admin/bb-do-counts.php

     
    124124        echo "\n\t</li>\n"; 
    125125endif; 
    126126 
     127if ( isset($_POST['categories']) && 1 == $_POST['categories'] ): 
     128        echo "\t<li>\n"; 
     129        if ( $categories = (array) $bbdb->get_col("SELECT category_id, COUNT(forum_id) FROM $bbdb->forums GROUP BY category_id") ) : 
     130                echo "\t\t" . __('Counting category forums...') . "<br />\n"; 
     131                $counts = (array) $bbdb->get_col('', 1); 
     132                foreach ($categories as $t => $i) 
     133                        $bbdb->query("UPDATE $bbdb->categories SET forums = '{$counts[$t]}' WHERE category_id = $i"); 
     134                unset($topics, $t, $i, $counts); 
     135        endif; 
     136        echo "\t\t" . __('Done counting category forums.'); 
     137        echo "\n\t</li>\n"; 
     138endif; 
     139 
    127140bb_recount_list(); 
    128141 if ( $recount_list ) 
    129142        foreach ( (array) $recount_list as $item ) 
  • bb-admin/bb-category.php

     
     1<?php 
     2require_once('admin.php'); 
     3 
     4if ( !bb_current_user_can('manage_categories') ) 
     5        bb_die(__("You don't have the authority to mess with the categories.")); 
     6 
     7if ( !isset($_POST['action']) ) 
     8        wp_redirect( bb_get_option( 'uri' ) . 'bb-admin/content-categories.php' ); 
     9 
     10$sent_from = wp_get_referer(); 
     11 
     12switch ( $_POST['action'] ) : 
     13case 'add' : 
     14        if ( !isset($_POST['category']) || '' === $_POST['category'] ) 
     15                bb_die(__('Bad category name.  Go back and try again.')); 
     16 
     17        bb_check_admin_referer( 'add-category' ); 
     18 
     19        $category_name = $_POST['category']; 
     20        $category_desc = $_POST['category-desc']; 
     21        $category_order = ( '' === $_POST['category-order'] ) ? 0 : (int) $_POST['category-order']; 
     22        if ( false !== bb_new_category( $category_name, $category_desc, $category_order ) ) : 
     23                wp_redirect( $sent_from ); 
     24                exit; 
     25        else : 
     26                bb_die(__('The category was not added')); 
     27        endif; 
     28        break; 
     29case 'update' : 
     30        bb_check_admin_referer( 'update-categories' ); 
     31 
     32        if ( !$categories = bb_get_categories() ) 
     33                bb_die(__('No categories to update!')); 
     34        foreach ( $categories as $category ) : 
     35                if ( isset($_POST['name-' . $category->category_id]) && '' !== $_POST['name-' . $category->category_id] ) 
     36                        bb_update_category( $category->category_id, $_POST['name-' . $category->category_id], $_POST['desc-' . $category->category_id], $_POST['order-' . $category->category_id]); 
     37        endforeach; 
     38        wp_redirect( $sent_from ); 
     39        exit; 
     40        break; 
     41case 'delete' : 
     42        bb_check_admin_referer( 'delete-category' ); 
     43 
     44        $category_id = (int) $_POST['category_id']; 
     45        $move_forums_category = (int) $_POST['move_forums_category']; 
     46 
     47        if ( !bb_current_user_can( 'delete_category', $forum_id ) ) 
     48                bb_die(__("You don't have the authority to kill off the categories.")); 
     49 
     50        if ( isset($_POST['move_forums']) && $_POST['move_forums'] != 'delete' ) 
     51                bb_move_category_forums( $category_id, $move_forums_category ); 
     52 
     53        if ( !bb_delete_category( $category_id ) ) 
     54                bb_die( __('Error occured while trying to delete category') ); 
     55 
     56        foreach ( array('action', 'id') as $arg ) 
     57                $sent_from = remove_query_arg( $arg, $sent_from ); 
     58        wp_redirect( add_query_arg( 'message', 'deleted', $sent_from ) ); 
     59        exit; 
     60        break; 
     61endswitch; 
     62?> 
  • bb-admin/rewrite-rules.php

     
    1414RewriteEngine On 
    1515RewriteBase <?php bb_option( 'path' ); ?> 
    1616 
     17RewriteRule ^category/([0-9]+)$ <?php bb_option( 'path' ); ?>category.php?id=$1 [L,QSA] 
    1718RewriteRule ^forum/([0-9]+)/page/([0-9]+)$ <?php bb_option( 'path' ); ?>forum.php?id=$1&page=$2 [L,QSA] 
    1819RewriteRule ^forum/([0-9]+)$ <?php bb_option( 'path' ); ?>forum.php?id=$1 [L,QSA] 
    1920RewriteRule ^topic/([0-9]+)/page/([0-9]+)$ <?php bb_option( 'path' ); ?>topic.php?id=$1&page=$2 [L,QSA] 
     
    2829RewriteRule ^view/([a-z-]+)/page/([0-9]+)$ <?php bb_option( 'path' ); ?>view.php?view=$1&page=$2 [L,QSA] 
    2930RewriteRule ^view/([a-z-]+)$ <?php bb_option( 'path' ); ?>view.php?view=$1 [L,QSA] 
    3031RewriteRule ^rss/$ <?php bb_option( 'path' ); ?>rss.php [L,QSA] 
     32RewriteRule ^rss/category/([0-9]+)$ <?php bb_option( 'path' ); ?>rss.php?category=$1 [L,QSA] 
    3133RewriteRule ^rss/forum/([0-9]+)$ <?php bb_option( 'path' ); ?>rss.php?forum=$1 [L,QSA] 
    3234RewriteRule ^rss/topic/([0-9]+)$ <?php bb_option( 'path' ); ?>rss.php?topic=$1 [L,QSA] 
    3335RewriteRule ^rss/tags/([a-z]+)$ <?php bb_option( 'path' ); ?>rss.php?tag=$1 [L,QSA] 
  • bb-admin/content-forums.php

     
    11<?php 
    22require_once('admin.php'); 
    33 
     4add_filter( 'get_forums_join', 'bb_get_forums_join_categories_filter', 1 ); 
     5add_filter( 'get_forums_orderby', 'bb_get_forums_orderby_category_order_filter', 1 ); 
    46$forums = get_forums(); 
    57$forums_count = $forums ? count($forums) : 0; 
    68 
     
    2022} 
    2123 
    2224bb_get_admin_header(); 
     25 
     26$categories = bb_get_categories(); 
    2327?> 
    2428 
    2529<h2><?php _e('Forum Management'); ?></h2> 
     
    7579                 <tr><th scope="row"><?php _e('Position:'); ?></th> 
    7680                     <td><input type="text" name="forum-order" id="forum-order" tabindex="12" maxlength="10" /></td> 
    7781                 </tr> 
     82<?php if ($categories) : ?> 
     83                 <tr><th scope="row"><?php _e('Category:'); ?></th> 
     84                     <td> 
     85                                <select name="forum-category" tabindex="<?php echo $t++; ?>"> 
     86<?php foreach ( $categories as $category ) : ?> 
     87                                        <option value="<?php echo $category->category_id; ?>"><?php bb_category_name(); ?></option> 
     88<?php endforeach; ?> 
     89                                </select> 
     90                     </td> 
     91                 </tr> 
     92<?php endif; ?> 
    7893                </table> 
    7994                <p class="submit alignleft"><input name="Submit" type="submit" value="<?php _e('Add Forum'); ?>" tabindex="13" /><input type="hidden" name="action" value="add" /></p> 
    8095        </fieldset>  
     
    88103                 <tr><th><?php _e('Name'); ?></th> 
    89104                     <th><?php _e('Description'); ?></th> 
    90105                     <th><?php _e('Position'); ?></th> 
     106<?php if ($categories) : ?> 
     107                     <th><?php _e('Category'); ?></th> 
     108<?php endif; ?> 
    91109<?php if ( bb_current_user_can( 'delete_forums' ) && 1 < $forums_count ) : ?> 
    92110                     <th><?php _e('Action'); ?></th> 
    93111<?php endif; ?> 
     
    96114                 <tr><td><input type="text" name="name-<?php forum_id(); ?>"  value="<?php echo wp_specialchars( get_forum_name(), 1 ); ?>" tabindex="<?php echo $t++; ?>" /></td> 
    97115                     <td><input type="text" name="desc-<?php forum_id(); ?>"  value="<?php echo wp_specialchars( get_forum_description(), 1 ); ?>" tabindex="<?php echo $t++; ?>" /></td> 
    98116                     <td><input type="text" name="order-<?php forum_id(); ?>" value="<?php echo $forum->forum_order; ?>" maxlength="10" tabindex="<?php echo $t++; ?>" /></td> 
     117<?php if ($categories) : ?> 
     118                     <td> 
     119                                <select name="category-<?php forum_id(); ?>" tabindex="<?php echo $t++; ?>"> 
     120<?php if ( !$forum->category_id ) : ?> 
     121                                        <option value=""><?php _e('No category!!!'); ?></option> 
     122<?php endif; ?> 
     123<?php foreach ( $categories as $category ) : ?> 
     124<?php 
     125if ($forum->category_id == $category->category_id) { 
     126        $category_selected = ' selected="selected"'; 
     127} else 
     128        $category_selected = ''; 
     129?> 
     130                                        <option value="<?php echo $category->category_id; ?>"<?php echo $category_selected; ?>><?php bb_category_name(); ?></option> 
     131<?php endforeach; ?> 
     132                                </select> 
     133                        </td> 
     134<?php endif; ?> 
    99135<?php if ( bb_current_user_can( 'delete_forums' ) && 1 < $forums_count ) : ?> 
    100                      <td><?php if ( bb_current_user_can( 'delete_forum', $forum->forum_id ) ) : ?><a class="delete" href="<?php bb_option('uri'); ?>bb-admin/content-forums.php?action=delete&id=<?php forum_id();?>"><?php _e('Delete'); ?></a><?php endif; ?></td> 
     136                     <td><?php if ( bb_current_user_can( 'delete_forum', $forum->forum_id ) ) : ?><a class="delete" href="<?php bb_option('uri'); ?>bb-admin/content-forums.php?action=delete&amp;id=<?php forum_id();?>"><?php _e('Delete'); ?></a><?php endif; ?></td> 
    101137<?php endif; ?> 
    102138                 </tr> 
    103139<?php endforeach; ?> 
  • bb-admin/content-categories.php

     
     1<?php 
     2require_once('admin.php'); 
     3 
     4$categories = bb_get_categories(); 
     5$categories_count = $categories ? count($categories) : 0; 
     6 
     7if ( 'delete' == $_GET['action'] ) { 
     8        $category_to_delete = (int) $_GET['id']; 
     9        $deleted_category = bb_get_category( $category_to_delete ); 
     10        if ( !$deleted_category || $categories_count < 1 || !bb_current_user_can( 'delete_category', $category_to_delete ) ) 
     11                wp_redirect( add_query_arg( array('action' => false, 'id' => false) ) ); 
     12} 
     13 
     14if ( isset($_GET['message']) ) { 
     15        switch ( $_GET['message'] ) : 
     16        case 'deleted' : 
     17                bb_admin_notice( sprintf(__('Category deleted.  You should have bbPress <a href="%s">recount your site information</a>.'), bb_get_option( 'uri' ) . 'bb-admin/site.php') ); 
     18                break; 
     19        endswitch; 
     20} 
     21 
     22bb_get_admin_header(); 
     23?> 
     24 
     25<h2><?php _e('Category Management'); ?></h2> 
     26<?php  if ( 'delete' == $_GET['action'] ) : ?> 
     27<div class="ays narrow"> 
     28        <p><big><?php printf(__('Are you sure you want to delete the "<strong>%s</strong>" category?'), $deleted_category->category_name); ?></big></p> 
     29        <p>This category contains</p> 
     30        <ul> 
     31                <li><?php printf(__ngettext('%d forum', '%d forums', $deleted_category->forums), $deleted_category->forums); ?></li> 
     32        </ul> 
     33 
     34        <form method="post" id="delete-category" action="<?php bb_option('uri'); ?>bb-admin/bb-category.php"> 
     35<?php if ( $categories_count > 1 ) : ?> 
     36                <p> 
     37                        <label for="move-forums-delete"><input type="radio" name="move_forums" id="move-forums-delete" value="delete" /> <?php _e('Forums will not be assigned to a category.'); ?></label><br /> 
     38                        <label for="move-forums-move"><input type="radio" name="move_forums" id="move-forums-move" value="move" checked="checked" /> <?php _e('Move forums from this category into'); ?></label> 
     39                        <?php $categories = bb_get_categories(); ?> 
     40                        <select name="move_forums_category" id="move-topics-forum"> 
     41                                <?php foreach ($categories as $category ) : ?> 
     42                                        <?php if ($category->category_id != $deleted_category->category_id) : ?> 
     43 
     44                                                <option value="<?php bb_category_id(); ?>"><?php bb_category_name(); ?></option> 
     45                                        <?php endif; ?> 
     46                                <?php endforeach; ?> 
     47                        </select> 
     48                </p> 
     49<?php else : ?> 
     50                <p> 
     51                        <input type="hidden" name="move_forums" id="move-forums-delete" value="delete" /> <?php _e('Forums will not be assigned to a category.'); ?> 
     52                </p> 
     53<?php endif; ?> 
     54                <p class="submit alignright"> 
     55                        <input class="delete" name="Submit" type="submit" value="<?php _e('Delete category &raquo;'); ?>" tabindex="10" /> 
     56                        <input type="hidden" name="action" value="delete" /> 
     57                        <input type="hidden" name="category_id" value="<?php echo $deleted_category->category_id; ?>" /> 
     58                </p> 
     59                <?php bb_nonce_field( 'delete-categories' ); ?> 
     60        </form> 
     61        <form method="get" action="<?php bb_option('uri'); ?>bb-admin/bb-category.php"> 
     62                <p class="submit alignleft"> 
     63                        <input type="submit" value="<?php _e('&laquo; Go back'); ?>" tabindex="10" /> 
     64                </p> 
     65        </form> 
     66</div> 
     67<?php else: // action ?> 
     68 
     69<form method="post" id="add-category" action="<?php bb_option('uri'); ?>bb-admin/bb-category.php"> 
     70        <h3><?php _e('Add category'); ?></h3> 
     71        <fieldset> 
     72                <table> 
     73                 <tr><th scope="row"><?php _e('Category Name:'); ?></th> 
     74                     <td><input type="text" name="category" id="category" tabindex="10" /></td> 
     75                 </tr> 
     76                 <tr><th scope="row"><?php _e('Category Description:'); ?></th> 
     77                     <td><input type="text" name="category-desc" id="category-desc" tabindex="11" /></td> 
     78                 </tr> 
     79                 <tr><th scope="row"><?php _e('Position:'); ?></th> 
     80                     <td><input type="text" name="category-order" id="category-order" tabindex="12" maxlength="10" /></td> 
     81                 </tr> 
     82                </table> 
     83                <p class="submit alignleft"><input name="Submit" type="submit" value="<?php _e('Add Category'); ?>" tabindex="13" /><input type="hidden" name="action" value="add" /></p> 
     84        </fieldset>  
     85        <?php bb_nonce_field( 'add-category' ); ?> 
     86</form> 
     87<?php if ( $categories ) : ?> 
     88<form method="post" id="update-categories" action="<?php bb_option('uri'); ?>bb-admin/bb-category.php"> 
     89        <h3><?php _e('Update category information'); ?></h3> 
     90        <fieldset> 
     91                <table> 
     92                 <tr><th><?php _e('Name'); ?></th> 
     93                     <th><?php _e('Description'); ?></th> 
     94                     <th><?php _e('Position'); ?></th> 
     95<?php if ( bb_current_user_can( 'delete_categories' ) ) : ?> 
     96                     <th><?php _e('Action'); ?></th> 
     97<?php endif; ?> 
     98                 </tr> 
     99<?php $t = 20; foreach ( $categories as $category ) : ?> 
     100                 <tr><td><input type="text" name="name-<?php bb_category_id(); ?>"  value="<?php echo wp_specialchars( bb_get_category_name(), 1 ); ?>" tabindex="<?php echo $t++; ?>" /></td> 
     101                     <td><input type="text" name="desc-<?php bb_category_id(); ?>"  value="<?php echo wp_specialchars( bb_get_category_description(), 1 ); ?>" tabindex="<?php echo $t++; ?>" /></td> 
     102                     <td><input type="text" name="order-<?php bb_category_id(); ?>" value="<?php echo $category->category_order; ?>" maxlength="10" tabindex="<?php echo $t++; ?>" /></td> 
     103<?php if ( bb_current_user_can( 'delete_categories' ) ) : ?> 
     104                     <td><?php if ( bb_current_user_can( 'delete_category', $category->category_id ) ) : ?><a class="delete" href="<?php bb_option('uri'); ?>bb-admin/content-categories.php?action=delete&amp;id=<?php bb_category_id();?>"><?php _e('Delete'); ?></a><?php endif; ?></td> 
     105<?php endif; ?> 
     106                 </tr> 
     107<?php endforeach; ?> 
     108                </table> 
     109        <p class="submit alignleft"><input name="Submit" type="submit" value="<?php _e('Update'); ?>" tabindex="<?php echo $t; ?>" /><input type="hidden" name="action" value="update" /></p> 
     110        </fieldset> 
     111        <?php bb_nonce_field( 'update-categories' ); ?> 
     112</form> 
     113<?php endif; ?> 
     114 
     115<?php endif; // action ?> 
     116 
     117<?php bb_get_admin_footer(); ?> 
  • bb-admin/admin-functions.php

     
    2828        $bb_submenu['content.php'][5] = array(__('Topics'), 'moderate', 'content.php'); 
    2929        $bb_submenu['content.php'][10] = array(__('Posts'), 'moderate', 'content-posts.php'); 
    3030        $bb_submenu['content.php'][15] = array(__('Forums'), 'moderate', 'content-forums.php'); 
     31        $bb_submenu['content.php'][20] = array(__('Categories'), 'moderate', 'content-categories.php'); 
    3132 
    3233        $bb_submenu['themes.php'][5] = array(__('Themes'), 'use_keys', 'themes.php'); 
    3334 
     
    163164        $recount_list[25] = array('topic-tag-count', __('Count tags for every topic')); 
    164165        $recount_list[30] = array('tags-tag-count', __('Count topics for every tag')); 
    165166        $recount_list[35] = array('zap-tags', __('DELETE tags with no topics.  Only functions if the above checked')); 
     167        $recount_list[40] = array('categories', __('Count forums in every category')); 
    166168        do_action('bb_recount_list'); 
    167169        ksort($recount_list); 
    168170        return $recount_list; 
  • bb-admin/bb-forum.php

     
    1919        $forum_name = $_POST['forum']; 
    2020        $forum_desc = $_POST['forum-desc']; 
    2121        $forum_order = ( '' === $_POST['forum-order'] ) ? 0 : (int) $_POST['forum-order']; 
    22         if ( false !== bb_new_forum( $forum_name, $forum_desc, $forum_order ) ) : 
     22        $forum_category = $_POST['forum-category']; 
     23        if ( false !== bb_new_forum( $forum_name, $forum_desc, $forum_order, $forum_category ) ) : 
    2324                wp_redirect( $sent_from ); 
    2425                exit; 
    2526        else : 
     
    3334                bb_die(__('No forums to update!')); 
    3435        foreach ( $forums as $forum ) : 
    3536                if ( isset($_POST['name-' . $forum->forum_id]) && '' !== $_POST['name-' . $forum->forum_id] ) 
    36                         bb_update_forum( $forum->forum_id, $_POST['name-' . $forum->forum_id], $_POST['desc-' . $forum->forum_id], $_POST['order-' . $forum->forum_id]); 
     37                        bb_update_forum( $forum->forum_id, $_POST['name-' . $forum->forum_id], $_POST['desc-' . $forum->forum_id], $_POST['order-' . $forum->forum_id], $_POST['category-' . $forum->forum_id]); 
    3738        endforeach; 
    3839        wp_redirect( $sent_from ); 
    3940        exit; 
  • bb-admin/upgrade-schema.php

     
    11<?php 
    22global $bb_queries, $bbdb; 
    33 
    4 $bb_queries = "CREATE TABLE $bbdb->forums ( 
     4$bb_queries = "CREATE TABLE $bbdb->categories ( 
     5  category_id int(10) NOT NULL auto_increment, 
     6  category_name varchar(150)  NOT NULL default '', 
     7  category_desc text  NOT NULL, 
     8  category_order int(10) NOT NULL default '0', 
     9  forums bigint(20) NOT NULL default '0', 
     10  PRIMARY KEY  (category_id) 
     11); 
     12CREATE TABLE $bbdb->forums ( 
    513  forum_id int(10) NOT NULL auto_increment, 
     14  category_id int(10) NOT NULL default '0', 
    615  forum_name varchar(150)  NOT NULL default '', 
    716  forum_desc text  NOT NULL, 
    817  forum_order int(10) NOT NULL default '0', 
    918  topics bigint(20) NOT NULL default '0', 
    1019  posts bigint(20) NOT NULL default '0', 
    11   PRIMARY KEY  (forum_id) 
     20  PRIMARY KEY  (forum_id), 
     21  KEY category_id (category_id) 
    1222); 
    1323CREATE TABLE $bbdb->posts ( 
    1424  post_id bigint(20) NOT NULL auto_increment, 
  • forum.php

     
    1313do_action( 'bb_forum.php_pre_db', $forum_id ); 
    1414 
    1515if ( !$bb_db_override ) : 
     16        $category = bb_get_category( $forum->category_id ); 
    1617        $topics   = get_latest_topics( $forum_id, $page ); 
    1718        $stickies = get_sticky_topics( $forum_id, $page ); 
    1819endif;