Ticket #1243: tags.diff

File tags.diff, 24.6 KB (added by GautamGupta, 2 years ago)

Better Tags Management

  • bb-admin/includes/functions.bb-admin.php

     
    6868                $bb_submenu['topics.php'][5]   = array( __( 'Topics' ), 'moderate', 'topics.php' ); 
    6969        $bb_menu[160] = array( __( 'Posts' ), 'moderate', 'posts.php', '', 'bb-menu-posts' ); 
    7070                $bb_submenu['posts.php'][5]   = array( __( 'Posts' ), 'moderate', 'posts.php' ); 
     71        $bb_menu[165] = array( __( 'Tags' ), 'manage_tags', 'tags.php', '', 'bb-menu-tags' ); 
     72                $bb_submenu['tags.php'][5] = array( __( 'Tags' ), 'manage_tags', 'tags.php' ); 
    7173 
    7274        // 200 < Plugin added menu items < 250 
    7375 
     
    710712 
    711713} 
    712714 
     715/* Tags */ 
     716 
     717function bb_tag_row( $tag ) { 
     718         
     719        $actions  = "<a href='" . esc_attr( bb_get_tag_link( (int) $tag['tag_id'] ) ) . "'>" . __( 'View' ) . "</a>"; 
     720        $actions .= " | <a href='" . bb_get_tag_link( (int) $tag['tag_id'] ) . "#manage-tags'>" . __( 'Edit' ) . "</a>"; 
     721        $actions .= " | <a href='" . esc_attr( bb_nonce_url( bb_get_uri( 'bb-admin/tags.php', array( 'action' => 'destroy', 'id' => $tag['tag_id'] ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ), 'destroy-tag_' . $tag['tag_id'] ) ) . "' onclick=\"return confirm('" . esc_js( sprintf(__( 'Are you sure you want to destroy the "%s" tag? This is permanent and cannot be undone.' ), $tag['name'] ) ) . "');\">" . __( 'Delete' ) . "</a>"; 
     722         
     723        $r  = "\t<tr id='tag-" . $tag['tag_id'] . "'" . get_alt_class( 'tag' ) . ">\n"; 
     724        $r .= "\t<td class='check-column'><input type='checkbox' name='tag[]' value='" . $tag['tag_id'] . "' /></td>"; 
     725        $r .= "\t\t<td class=\"tag\"><span class=\"row-title\">" . $tag['tag_id'] . "</td>\n"; 
     726        $r .= "\t\t<td class=\"tag\"><span class=\"row-title\"><a href='" . bb_get_tag_link( (int) $tag['tag_id'] ) . "'>" . $tag['name'] . "</a></span><div><span class=\"row-actions\">$actions</span>&nbsp;</div></td>\n"; 
     727        $r .= "\t\t<td>" . $tag['count'] . "</td>\n"; 
     728        $r .= "\t</tr>\n"; 
     729         
     730        return $r; 
     731} 
     732 
     733// BB_Tag_Search class 
     734// Derived from BB_User_Search 
     735 
     736class BB_Tag_Search { 
     737        var $results; 
     738        var $search_term; 
     739        var $page; 
     740        var $raw_page; 
     741        var $tags_per_page = 25; 
     742        var $first_tag; 
     743        var $last_tag; 
     744        var $query_limit; 
     745        var $total_tags_for_query = 0; 
     746        var $search_errors; 
     747        var $paging_text; 
     748        var $paging_text_bottom; 
     749        var $order_by = 'name'; 
     750        var $order = 'ASC'; 
     751 
     752        function BB_Tag_Search ( $search_term = false, $page = 1, $getorder_by = 'name', $getorder = 'ASC' ) { // constructor 
     753                $this->search_term = $search_term ? stripslashes( $search_term ) : false; 
     754                $this->raw_page = ( '' == $page ) ? false : (int) $page; 
     755                $page = (int) $page; 
     756                $this->page = $page < 2 ? 1 : $page; 
     757                 
     758                $this->order_by = in_array( $getorder_by, array( 'id', 'name', 'count' ) ) ? $getorder_by : 'name'; 
     759                $this->order = in_array( $getorder, array( 'ASC', 'DESC' ) ) ? $getorder : 'ASC'; 
     760                 
     761                $this->prepare_query(); 
     762                $this->query(); 
     763                $this->prepare_vars_for_template_usage(); 
     764                $this->do_paging(); 
     765        } 
     766 
     767        function prepare_query() { 
     768                $this->first_tag = ( $this->page - 1 ) * $this->tags_per_page; 
     769        } 
     770 
     771        function query() { 
     772                global $wp_taxonomy_object; 
     773                 
     774                $terms = $wp_taxonomy_object->get_terms( 
     775                                'bb_topic_tag', 
     776                                array( 
     777                                      'search' => $this->search_term, 
     778                                      'offset' => $this->first_tag, 
     779                                      'number' => $this->tags_per_page, 
     780                                      'orderby' => $this->order_by, 
     781                                      'order' => $this->order, 
     782                                      'get' => 'all' 
     783                                      ) 
     784                                ); 
     785                if ( is_wp_error( $terms ) ) 
     786                        $this->search_errors = $terms; 
     787                 
     788                $tags = array(); 
     789                 
     790                for ( $i = 0; isset( $terms[$i] ); $i++ ) { 
     791                        $tags[$i]['tag_id']     = $terms[$i]->term_id; 
     792                        $tags[$i]['name']       = $terms[$i]->name; 
     793                        $tags[$i]['count']      = $terms[$i]->count; 
     794                } 
     795                 
     796                $this->results = $tags; 
     797 
     798                if ( $this->results ) 
     799                        $this->total_tags_for_query = bb_count_last_query(); 
     800                elseif ( !is_wp_error( $this->search_errors ) ) 
     801                        $this->search_errors = new WP_Error( 'no_matching_users_found', '<strong>' . __( 'No matching tags were found!' ) . '</strong>' ); 
     802 
     803                if ( is_wp_error( $this->search_errors ) ) 
     804                        bb_admin_notice( $this->search_errors ); 
     805        } 
     806 
     807        function prepare_vars_for_template_usage() { 
     808                $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone 
     809        } 
     810 
     811        function do_paging() { 
     812                global $bb_current_submenu; 
     813                $displaying_num = sprintf( 
     814                        __( '%1$s to %2$s of %3$s' ), 
     815                        bb_number_format_i18n( ( $this->page - 1 ) * $this->tags_per_page + 1 ), 
     816                        $this->page * $this->tags_per_page < $this->total_tags_for_query ? bb_number_format_i18n( $this->page * $this->tags_per_page ) : '<span class="total-type-count">' . bb_number_format_i18n( $this->total_tags_for_query ) . '</span>', 
     817                        '<span class="total-type-count">' . bb_number_format_i18n( $this->total_tags_for_query ) . '</span>' 
     818                ); 
     819                $page_number_links = $this->total_tags_for_query > $this->tags_per_page ? get_page_number_links( $this->page, $this->total_tags_for_query, $this->tags_per_page, false ) : ''; 
     820                $this->paging_text = "<div class='tablenav-pages'><span class='displaying-num'>$displaying_num</span><span class=\"displaying-pages\">$page_number_links</span><div class=\"clear\"></div></div>\n"; 
     821                $this->paging_text_bottom = "<div class='tablenav-pages'><span class=\"displaying-pages\">$page_number_links</span><div class=\"clear\"></div></div>\n"; 
     822        } 
     823 
     824        function get_results() { 
     825                return (array) $this->results; 
     826        } 
     827 
     828        function page_links() { 
     829                echo $this->paging_text; 
     830        } 
     831 
     832        function results_are_paged() { 
     833                if ( isset($this->paging_text) && $this->paging_text ) 
     834                        return true; 
     835                return false; 
     836        } 
     837 
     838        function is_search() { 
     839                if ( $this->search_term ) 
     840                        return true; 
     841                return false; 
     842        } 
     843 
     844        function display( $show_extra = true ) { 
     845                $r = ''; 
     846 
     847                $h2_search = $this->search_term ? ' ' . sprintf( __( 'matching &#8220;%s&#8221;' ), esc_html( $this->search_term ) ) : ''; 
     848 
     849                $h2_span = '<span class="subtitle">'; 
     850                $h2_span .= apply_filters( 'bb_tag_search_description', $h2_search, $this ); 
     851                $h2_span .= '</span>'; 
     852 
     853                echo "<h2 class=\"first\">" . apply_filters( 'bb_tag_search_title', __( 'Tags' ) ) . $h2_span . "</h2>\n"; 
     854                do_action( 'bb_admin_notices' ); 
     855 
     856                if ( $show_extra ) { 
     857                         
     858                        $order_by = array( 'id' => __( 'Tag ID' ), 'name' => __( 'Tag Name' ), 'count' => __( 'Topic Count' ) ); 
     859                        $orders = array( 'ASC' => __( 'Ascending' ), 'DESC' => __( 'Descending' ) ); 
     860                         
     861                        $r .= "<form action='' method='get' id='search' class='search-form'>\n"; 
     862                        $r .= "<fieldset>\n"; 
     863                         
     864                        /* Search */ 
     865                        $r .= "<div>\n"; 
     866                        $r .= "\t\t<label for='tagsearch'>" . __( 'Search Term' ) . "</label>"; 
     867                        $r .= "\t\t<div><input type='text' name='tagsearch' id='tagsearch' class='text-input' value='" . esc_html( $this->search_term, 1 ) . "' /></div>\n"; 
     868                        $r .= "</div>\n"; 
     869                         
     870                        /* Order by */ 
     871                        $r .= "<div>\n"; 
     872                        $r .= "\t\t<label for='userrole'>" . __( 'Order By' ) . "</label>"; 
     873                        $r .= "\t\t<div><select name='orderby' id='orderby'>\n"; 
     874                         
     875                        foreach ( $order_by as $orderby => $display ) { 
     876                                $selected = ''; 
     877                                if ( $this->order_by == $orderby ) 
     878                                        $selected = ' selected="selected"'; 
     879                                $value = esc_attr( $orderby ); 
     880                                $display = esc_html( $display ); 
     881                                $r .= "\t\t\t<option value='$value'$selected>$display</option>\n"; 
     882                        } 
     883                         
     884                        $r .= "\t\t</select></div>\n"; 
     885                        $r .= "</div>\n"; 
     886                         
     887                        /* Order */ 
     888                        $r .= "<div>\n"; 
     889                        $r .= "\t\t<label for='userrole'>" . __( 'Order' ) . "</label>"; 
     890                        $r .= "\t\t<div><select name='order' id='order'>\n"; 
     891                         
     892                        foreach ( $orders as $order => $display ) { 
     893                                $selected = ''; 
     894                                if ( $this->order == $order ) 
     895                                        $selected = ' selected="selected"'; 
     896                                $value = esc_attr( $order ); 
     897                                $display = esc_html( $display ); 
     898                                $r .= "\t\t\t<option value='$value'$selected>$display</option>\n"; 
     899                        } 
     900                         
     901                        $r .= "\t\t</select></div>\n"; 
     902                        $r .= "</div>\n"; 
     903                         
     904                        $r = apply_filters( 'bb_tag_search_form_inputs', $r, $this ); 
     905                         
     906                        $r .= "<div class=\"submit\">\n"; 
     907                        $r .= "\t\t<label class='hidden' for='submit'>" . __( 'Search' ) . "</label>"; 
     908                        $r .= "\t\t<div><input type='submit' id='submit' class='button submit-input' value='" . __( 'Filter' ) . "' /></div>\n"; 
     909                        $r .= "</div>\n"; 
     910                        $r .= "</fieldset>\n"; 
     911                        $r .= "</form>\n\n"; 
     912                         
     913                        /* Bulk Actions */ 
     914                         
     915                        $bulk_actions = array( 
     916                                'destroy' => __( 'Destroy' ), 
     917                                'merge' => __( 'Merge' ) 
     918                        ); 
     919                         
     920                        do_action_ref_array( 'bulk_post_actions', array( &$bulk_actions ) ); 
     921                         
     922                        $r .= "<form class='table-form bulk-form' method='post'>\n"; 
     923                        $r .= "\t<fieldset>\n"; 
     924                        $r .= "\t\t<select name='action' onchange=\"if(this.value=='merge'){jQuery('#new-tag').css('display','inline');}else{jQuery('#new-tag').css('display','none');}\">\n"; 
     925                        $r .= "\t\t\t<option>" . __( 'Bulk Actions' ) . "</option>\n"; 
     926                        foreach ( $bulk_actions as $value => $label ) { 
     927                                $r .= "\t\t\t<option value='" . esc_attr( $value ) . "'>" . esc_html( $label ) . "</option>\n"; 
     928                        } 
     929                        $r .= "\t\t</select>\n"; 
     930                        $r .= "\t\t<input type='text' name='merge_new_tag' id='new-tag' class='text-input' value='" . esc_html__( 'New Tag Name' ) . "' style='display:none;' />\n"; 
     931                        $r .= "\t\t<input type='submit' value='" . __( 'Apply' ) . "' class='button submit-input' onclick=\"return confirm('" . esc_js( __( 'Are you sure you want to do this? This is permanent and cannot be undone.' ) ) . "');\" />\n"; 
     932                        $r .= bb_nonce_field( 'tags-bulk', '_wpnonce', true, false ); 
     933                        $r .= "\t</fieldset>\n"; 
     934                } 
     935 
     936                if ( $this->get_results() ) { 
     937                        if ( $this->results_are_paged() ) 
     938                                $r .= "<div class='tablenav'>\n" . $this->paging_text . "</div><div class=\"clear\"></div>\n\n"; 
     939                                 
     940                        $r .= "<table class='widefat'>\n"; 
     941                        $r .= "<thead>\n"; 
     942                        $r .= "\t<tr>\n"; 
     943                         
     944                        $r .= "\t\t<th scope='col' class='check-column'><input type='checkbox' /></th>\n"; 
     945                        $r .= "\t\t<th style='width:20%;'>" . __( 'Tag ID' ) . "</th>\n"; 
     946                        $r .= "\t\t<th style='width:50%;'>" . __( 'Tag Name' ) . "</th>\n"; 
     947                        $r .= "\t\t<th style='width:30%;'>" . __( 'Topics' ) . "</th>\n"; 
     948                         
     949                        $r .= "\t</tr>\n"; 
     950                        $r .= "</thead>\n\n"; 
     951                         
     952                        $r .= "<tfoot>\n"; 
     953                        $r .= "\t<tr>\n"; 
     954                         
     955                        $r .= "\t\t<th scope='col' class='check-column'><input type='checkbox' /></th>\n"; 
     956                        $r .= "\t\t<th style='width:20%;'>" . __( 'Tag ID' ) . "</th>\n"; 
     957                        $r .= "\t\t<th style='width:50%;'>" . __( 'Tag Name' ) . "</th>\n"; 
     958                        $r .= "\t\t<th style='width:30%;'>" . __( 'Topics' ) . "</th>\n"; 
     959                         
     960                        $r .= "\t</tr>\n"; 
     961                        $r .= "</tfoot>\n\n"; 
     962 
     963                        $r .= "<tbody id='role-$role'>\n"; 
     964                        foreach ( (array) $this->get_results() as $tag ) 
     965                                $r .= bb_tag_row( $tag ); 
     966                        $r .= "</tbody>\n"; 
     967                        $r .= "</table>\n\n"; 
     968                         
     969                        $r .= "</form>\n"; 
     970 
     971                        if ( $this->results_are_paged() ) 
     972                                $r .= "<div class='tablenav bottom'>\n" . $this->paging_text_bottom . "</div><div class=\"clear\"></div>\n\n"; 
     973                } 
     974                echo $r; 
     975        } 
     976 
     977} 
     978 
    713979/* Forums */ 
    714980 
    715981// Expects forum_name, forum_desc to be pre-escaped 
  • bb-admin/style.css

     
    451451        background-position: -186px -7px; 
    452452} 
    453453 
     454ul#bbAdminMenu li#bb-menu-tags a div.bb-menu-icon { 
     455        background-position: -278px -39px; 
     456} 
     457 
     458ul#bbAdminMenu li#bb-menu-tags.bb-menu-current a div.bb-menu-icon, 
     459ul#bbAdminMenu li#bb-menu-tags a:hover div.bb-menu-icon { 
     460        background-position: -278px -7px; 
     461} 
     462 
    454463ul#bbAdminMenu li#bb-menu-users a div.bb-menu-icon { 
    455464        background-position: -308px -39px; 
    456465} 
     
    847856        color: rgb(70, 70, 70); 
    848857} 
    849858 
    850 form.search-form fieldset div div input.text-input { 
     859form.search-form fieldset div div input.text-input, 
     860#new-tag { 
    851861        width: 100px; 
    852862        padding: 3px; 
    853863        -moz-border-radius: 4px; 
  • bb-admin/tag-destroy.php

     
    1 <?php 
    2 require('admin.php'); 
    3  
    4 if ( !bb_current_user_can('manage_tags') ) 
    5         bb_die(__('You are not allowed to manage tags.')); 
    6  
    7 $tag_id = (int) $_POST['id' ]; 
    8  
    9 bb_check_admin_referer( 'destroy-tag_' . $tag_id ); 
    10  
    11 $old_tag = bb_get_tag( $tag_id ); 
    12 if ( !$old_tag ) 
    13         bb_die(__('Tag not found.')); 
    14  
    15 if ( $destroyed = bb_destroy_tag( $tag_id ) ) { 
    16         printf(__("Rows deleted from tags table: %d <br />\n"), $destroyed['tags']); 
    17         printf(__("Rows deleted from tagged table: %d <br />\n"), $destroyed['tagged']); 
    18         printf(__('<a href="%s">Home</a>'), bb_get_uri()); 
    19 } else { 
    20    die(printf(__("Something odd happened when attempting to destroy that tag.<br />\n<a href=\"%s\">Try Again?</a>"), wp_get_referer())); 
    21 } 
    22 ?> 
  • bb-admin/tag-merge.php

     
    1 <?php 
    2 require('admin.php'); 
    3  
    4 if ( !bb_current_user_can('manage_tags') ) 
    5         bb_die(__('You are not allowed to manage tags.')); 
    6  
    7 $old_id = (int) $_POST['id' ]; 
    8 $tag = $_POST['tag']; 
    9  
    10 bb_check_admin_referer( 'merge-tag_' . $old_id ); 
    11  
    12 if ( ! $tag = bb_get_tag( $tag ) ) 
    13         bb_die(__('Tag specified not found.')); 
    14  
    15 if ( ! bb_get_tag( $old_id ) ) 
    16         bb_die(__('Tag to be merged not found.')); 
    17  
    18 if ( $merged = bb_merge_tags( $old_id, $tag->tag_id ) ) { 
    19         printf(__("Number of topics from which the old tag was removed: %d <br />\n"),  $merged['old_count']); 
    20     printf(__("Number of topics to which the new tag was added: %d <br />\n"),$merged['diff_count']); 
    21         printf(__("Number of rows deleted from tags table:%d <br />\n"),$merged['destroyed']['tags']); 
    22         printf(__('<a href="%s">New Tag</a>'), bb_get_tag_link()); 
    23 } else { 
    24    die(printf(__("Something odd happened when attempting to merge those tags.<br />\n<a href=\"%s\">Try Again?</a>"), wp_get_referer())); 
    25 } 
    26 ?> 
  • bb-admin/tag-rename.php

     
    1 <?php 
    2 require('admin.php'); 
    3  
    4 if ( !bb_current_user_can('manage_tags') ) 
    5         bb_die(__('You are not allowed to manage tags.')); 
    6  
    7 $tag_id = (int) $_POST['id' ]; 
    8 $tag    =       $_POST['tag']; 
    9  
    10 bb_check_admin_referer( 'rename-tag_' . $tag_id ); 
    11  
    12 $old_tag = bb_get_tag( $tag_id ); 
    13 if ( !$old_tag ) 
    14         bb_die(__('Tag not found.')); 
    15  
    16 $tag = stripslashes( $tag ); 
    17 if ( $tag = bb_rename_tag( $tag_id, $tag ) ) 
    18         wp_redirect( bb_get_tag_link() ); 
    19 else 
    20         die(printf(__('There already exists a tag by that name or the name is invalid. <a href="%s">Try Again</a>'), wp_get_referer())); 
    21 exit; 
    22 ?> 
  • bb-admin/tags.php

     
     1<?php 
     2require_once( 'admin.php' ); 
     3 
     4if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) { /* Accepts multiple tags in array */ 
     5        bb_check_admin_referer( 'tags-bulk' ); 
     6 
     7        $tag_ids = array_map( 'absint', (array) $_POST['tag'] ); 
     8        $count = 0; 
     9        $action = trim( $_POST['action'] ); 
     10 
     11        switch ( $action ) { 
     12        case 'destroy' : 
     13                foreach ( $tag_ids as $tag_id ) 
     14                        $count += (int) (bool) bb_destroy_tag( $tag_id ); 
     15                 
     16                $query_vars = array( 'message' => 'destroyed', 'count' => $count ); 
     17                break; 
     18        case 'merge' : 
     19                if ( !$new_tag = (string) trim( $_POST['merge_new_tag'] ) ) 
     20                        break; 
     21                if ( !$new_tag_id = bb_create_tag( $new_tag ) ) /* The tag ID would be returned if tag is already there, else it would be created */ 
     22                        if ( !$new_tag_id = bb_get_tag_id( $new_tag ) ) /* Due to some problem, bb_create_tag doesn't return the term id so we need to try to get the id again */ 
     23                                break; 
     24                 
     25                foreach ( $tag_ids as $tag_id ) { 
     26                        if ( $tag_id == $new_tag_id ) 
     27                                continue; 
     28                        $count += (int) (bool) bb_merge_tags( $tag_id, $new_tag_id ); 
     29                } 
     30                 
     31                $query_vars = array( 'message' => 'merged', 'count' => $count, 'new_id' => $new_tag_id ); 
     32                break; 
     33        default : 
     34                if ( $action ) 
     35                        $query_vars = apply_filters( "bulk_tag__$action", array(), $tag_ids, $action ); 
     36                break; 
     37        } 
     38 
     39        bb_safe_redirect( add_query_arg( $query_vars ) ); 
     40        exit; 
     41} 
     42 
     43if ( !empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'rename', 'merge', 'destroy' ) ) && $old_tag = bb_get_tag( (int) $_GET['id'] ) ) { /* Accepts only one tag */ 
     44        $action = $_GET['action']; 
     45        $old_id = (int) $_GET['id']; 
     46         
     47        bb_check_admin_referer( $action . '-tag_' . $old_id ); 
     48         
     49        switch ( $action ) { 
     50                case 'destroy': 
     51                        $query_vars = ( (bool) bb_destroy_tag( $old_id ) ) ? array( 'message' => 'destroyed' ) : $query_vars = array( 'message' => 'error' ); 
     52                        break; 
     53                case 'merge': 
     54                        if ( !$new_tag = bb_get_tag( $_GET['tag'] ) ) { 
     55                                $query_vars = array( 'message' => 'error' ); 
     56                                break; 
     57                        } 
     58                        $query_vars = ( (bool) bb_merge_tags( $old_id, $new_tag->tag_id ) ) ? array( 'message' => 'merged', 'new_id' => $new_tag->tag_id ) : array( 'message' => 'error' ); 
     59                        break; 
     60                case 'rename': 
     61                        $new_tag = stripslashes( $_GET['tag'] ); 
     62                        $query_vars = ( (bool) bb_rename_tag( $old_id, $new_tag ) ) ? array( 'message' => 'renamed', 'new_id' => $old_id ) : array( 'message' => 'error' ); 
     63                        break; 
     64        } 
     65         
     66        bb_safe_redirect( remove_query_arg( array( 'action', 'tag', 'Submit', 'id', '_wpnonce' ), add_query_arg( $query_vars ) ) ); /* Just keep _wp_http_referer for messages (below) */ 
     67        exit; 
     68} 
     69 
     70if ( !empty( $_GET['message'] ) ) { 
     71        $message_count = isset( $_GET['count'] ) ? (int) $_GET['count'] : 1; 
     72         
     73        switch ( (string) $_GET['message'] ) { 
     74                case 'destroyed': 
     75                        $back = isset( $_GET['_wp_http_referer'] ) ? ' <a href="' . bb_get_uri() . '">' . __( 'Back to forums.' ) . '</a>' : ''; 
     76                        bb_admin_notice( '<strong>' . sprintf( _n( 'Tag destroyed.', '%s tags destroyed.', $message_count ), bb_number_format_i18n( $message_count ) ) . '</strong>' . $back ); 
     77                        break; 
     78                case 'merged': 
     79                        $back = isset( $_GET['_wp_http_referer'] ) ? ' <a href="' . bb_get_tag_link( (int) $_GET['new_id'] ) . '">' . __( 'Back to the merged tag.' ) . '</a>' : ''; 
     80                        bb_admin_notice( '<strong>' . sprintf( _n( 'Tag merged into %2$s.', '%1$s tags merged into %2$s.', $message_count ), bb_number_format_i18n( $message_count ), bb_get_tag_name( (int) $_GET['new_id'] ) ) . '</strong>' . $back ); 
     81                        break; 
     82                case 'renamed': 
     83                        $back = isset( $_GET['_wp_http_referer'] ) ? ' <a href="' . bb_get_tag_link( (int) $_GET['new_id'] ) . '">' . __( 'Back to the renamed tag.' ) . '</a>' : ''; 
     84                        bb_admin_notice( '<strong>' . sprintf( 'Tag renamed to %s.', bb_get_tag_name( (int) $_GET['new_id'] ) ) . '</strong>' . $back ); 
     85                        break; 
     86                case 'error': 
     87                        $back = isset( $_GET['_wp_http_referer'] ) ? ' <a href="' . bb_get_uri() . '">' . __( 'Back to forums.' ) . '</a>' : ''; 
     88                        bb_admin_notice( '<strong>' . __( 'There was an error with your request! Please try again.' ) . '</strong>' . $back ); 
     89                        break; 
     90        } 
     91} 
     92 
     93$tag_query = new BB_Tag_Search( @$_GET['tagsearch'], @$_GET['page'], @$_GET['orderby'], $_GET['order'] ); 
     94 
     95$bb_admin_body_class = ' bb-admin-tags'; 
     96 
     97bb_get_admin_header(); 
     98 
     99if ( !bb_current_user_can( 'manage_tags' ) ) 
     100        die( __( "Now how'd you get here?  And what did you think you'd being doing?" ) ); //This should never happen. 
     101?> 
     102 
     103<div class="wrap"> 
     104 
     105<?php $tag_query->display(); ?> 
     106 
     107</div> 
     108 
     109<?php bb_get_admin_footer(); ?> 
  • bb-includes/functions.bb-template.php

     
    31213121<?php 
    31223122} 
    31233123 
    3124 function manage_tags_forms() 
    3125 { 
     3124function manage_tags_forms() { 
     3125        if ( !bb_current_user_can( 'manage_tags' ) ) 
     3126                return false; 
     3127         
    31263128        global $tag; 
    3127         if ( !bb_current_user_can( 'manage_tags' ) ) { 
    3128                 return false; 
    3129         } 
    31303129 
    31313130        $form  = '<ul id="manage-tags">' . "\n"; 
    3132         $form .= '<li id="tag-rename">' . __('Rename tag:') . "\n\t"; 
    3133         $form .= '<form method="post" action="' . bb_get_uri( 'bb-admin/tag-rename.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ) . '"><div>' . "\n\t"; 
     3131        $form .= '<li id="tag-rename">' . __( 'Rename tag:' ) . "\n\t"; 
     3132        $form .= '<form method="get" action="' . bb_get_uri( 'bb-admin/tags.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ) . '"><div>' . "\n\t"; 
    31343133        $form .= '<input type="text" name="tag" size="10" maxlength="30" />' . "\n\t"; 
    31353134        $form .= '<input type="hidden" name="id" value="' . $tag->tag_id . '" />' . "\n\t"; 
    3136         $form .= "<input type='submit' name='Submit' value='" . __('Rename') . "' />\n\t"; 
     3135        $form .= '<input type="hidden" name="action" value="rename" />' . "\n\t"; 
     3136        $form .= "<input type='submit' name='Submit' value='" . __( 'Rename' ) . "' />\n\t"; 
    31373137        echo $form; 
    31383138        bb_nonce_field( 'rename-tag_' . $tag->tag_id ); 
    31393139        echo "\n\t</div></form>\n  </li>\n "; 
    3140         $form  = "<li id='tag-merge'>" . __('Merge this tag into:') . "\n\t"; 
    3141         $form .= "<form method='post' action='" . bb_get_uri('bb-admin/tag-merge.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN) . "'><div>\n\t"; 
     3140         
     3141        $form  = "<li id='tag-merge'>" . __( 'Merge this tag into:' ) . "\n\t"; 
     3142        $form .= "<form method='get' action='" . bb_get_uri( 'bb-admin/tags.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ) . "'><div>\n\t"; 
    31423143        $form .= "<input type='text' name='tag' size='10' maxlength='30' />\n\t"; 
    31433144        $form .= "<input type='hidden' name='id' value='$tag->tag_id' />\n\t"; 
    3144         $form .= "<input type='submit' name='Submit' value='" . __('Merge') . "' "; 
    3145         $form .= 'onclick="return confirm(\'' . esc_js( sprintf(__('Are you sure you want to merge the "%s" tag into the tag you specified? This is permanent and cannot be undone.'), $tag->raw_tag) ) . "');\" />\n\t"; 
     3145        $form .= '<input type="hidden" name="action" value="merge" />' . "\n\t"; 
     3146        $form .= "<input type='submit' name='Submit' value='" . __( 'Merge' ) . "' "; 
     3147        $form .= 'onclick="return confirm(\'' . esc_js( sprintf(__( 'Are you sure you want to merge the "%s" tag into the tag you specified? This is permanent and cannot be undone.' ), $tag->raw_tag ) ) . "');\" />\n\t"; 
    31463148        echo $form; 
    31473149        bb_nonce_field( 'merge-tag_' . $tag->tag_id ); 
    31483150        echo "\n\t</div></form>\n  </li>\n "; 
    3149         $form  = "<li id='tag-destroy'>" . __('Destroy tag:') . "\n\t"; 
    3150         $form .= "<form method='post' action='" . bb_get_uri('bb-admin/tag-destroy.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN) . "'><div>\n\t"; 
     3151         
     3152        $form  = "<li id='tag-destroy'>" . __( 'Destroy tag:' ) . "\n\t"; 
     3153        $form .= "<form method='get' action='" . bb_get_uri( 'bb-admin/tags.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN ) . "'><div>\n\t"; 
    31513154        $form .= "<input type='hidden' name='id' value='$tag->tag_id' />\n\t"; 
    3152         $form .= "<input type='submit' name='Submit' value='" . __('Destroy') . "' "; 
    3153         $form .= 'onclick="return confirm(\'' . esc_js( sprintf(__('Are you sure you want to destroy the "%s" tag? This is permanent and cannot be undone.'), $tag->raw_tag) ) . "');\" />\n\t"; 
     3155        $form .= '<input type="hidden" name="action" value="destroy" />' . "\n\t"; 
     3156        $form .= "<input type='submit' name='Submit' value='" . __( 'Destroy' ) . "' "; 
     3157        $form .= 'onclick="return confirm(\'' . esc_js( sprintf(__( 'Are you sure you want to destroy the "%s" tag? This is permanent and cannot be undone.' ), $tag->raw_tag ) ) . "');\" />\n\t"; 
    31543158        echo $form; 
    31553159        bb_nonce_field( 'destroy-tag_' . $tag->tag_id ); 
    31563160        echo "\n\t</div></form>\n  </li>\n</ul>"; 
     3161         
    31573162} 
    31583163 
    31593164function bb_tag_remove_link( $args = null ) { 
  • bb-includes/functions.bb-topic-tags.php

     
    422422 
    423423        $tag_id = (int) $tag_id; 
    424424        $raw_tag = bb_trim_for_db( $tag_name, 50 ); 
    425         $tag_name = tag_sanitize( $tag_name );  
     425        $tag_name = bb_pre_term_slug( $tag_name );  
    426426 
    427427        if ( empty( $tag_name ) ) { 
    428428                return false; 
     
    464464        do_action( 'bb_pre_merge_tags', $old_id, $new_id ); 
    465465 
    466466        // Get all topics tagged with old tag 
    467         $old_topics = bb_get_tagged_topic_ids( $old_id ); 
     467        $old_topics = (array) bb_get_tagged_topic_ids( $old_id ); 
    468468 
    469469        // Get all toics tagged with new tag 
    470         $new_topics = bb_get_tagged_topic_ids( $new_id ); 
     470        $new_topics = (array) bb_get_tagged_topic_ids( $new_id ); 
    471471 
    472472        // Get intersection of those topics 
    473         $both_topics = array_intersect( $old_topics, $new_topics ); 
     473        $both_topics = (array) array_intersect( $old_topics, $new_topics ); 
    474474 
    475475        // Discard the intersection from the old tags topics 
    476         $old_topics = array_diff( $old_topics, $both_topics ); 
     476        $old_topics = (array) array_diff( $old_topics, $both_topics ); 
    477477 
    478478        // Add the remainder of the old tag topics to the new tag 
    479479        if ( count( $old_topics ) ) {