Make WordPress Core

Changeset 5563


Ignore:
Timestamp:
05/27/2007 07:32:45 PM (19 years ago)
Author:
ryan
Message:

Fix up exporter. Remove more refrences to the categories table. see #4189

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/export.php

    r5263 r5563  
    6262$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    6363
    64 $categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (category_id = cat_id) LEFT JOIN $wpdb->posts ON (post_id <=> id) $where GROUP BY cat_id");
     64$categories = (array) get_categories('get=all');
    6565
    6666function wxr_missing_parents($categories) {
    … …  
    6969
    7070        foreach ( $categories as $category )
    71                 $parents[$category->cat_ID] = $category->category_parent;
     71                $parents[$category->term_id] = $category->parent;
    7272
    7373        $parents = array_unique(array_diff($parents, array_keys($parents)));
    … …  
    8080
    8181while ( $parents = wxr_missing_parents($categories) ) {
    82         $found_parents = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories WHERE cat_ID IN (" . join(', ', $parents) . ")");
     82        $found_parents = get_categories("include=" . join(', ', $parents));
    8383        if ( is_array($found_parents) && count($found_parents) )
    8484                $categories = array_merge($categories, $found_parents);
    … …  
    9191$passes = 1000 + count($categories);
    9292while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
    93         if ( $cat->category_parent == 0 || isset($cats[$cat->category_parent]) ) {
    94                 $cats[$cat->cat_ID] = $cat;
     93        if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
     94                $cats[$cat->term_id] = $cat;
    9595        } else {
    9696                $categories[] = $cat;
    … …  
    111111
    112112function wxr_cat_name($c) {
    113         if ( empty($c->cat_name) )
     113        if ( empty($c->name) )
    114114                return;
    115115
    116         echo '<wp:cat_name>' . wxr_cdata($c->cat_name) . '</wp:cat_name>';
     116        echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
    117117}
    118118
    119119function wxr_category_description($c) {
    120         if ( empty($c->category_description) )
     120        if ( empty($c->description) )
    121121                return;
    122122
    123         echo '<wp:category_description>' . wxr_cdata($c->category_description) . '</wp:category_description>';
     123        echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
    124124}
    125125
    … …  
    164164        <language><?php echo get_option('rss_language'); ?></language>
    165165<?php if ( $cats ) : foreach ( $cats as $c ) : ?>
    166         <wp:category><wp:category_nicename><?php echo $c->category_nicename; ?></wp:category_nicename><wp:category_parent><?php echo $c->category_parent ? $cats[$c->category_parent]->cat_name : ''; ?></wp:category_parent><wp:posts_private><?php echo $c->posts_private ? '1' : '0'; ?></wp:posts_private><wp:links_private><?php echo $c->links_private ? '1' : '0'; ?></wp:links_private><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category>
     166        <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category>
    167167<?php endforeach; endif; ?>
    168168        <?php do_action('rss2_head'); ?>
  • trunk/wp-admin/index.php

    r5308 r5563  
    102102$numposts = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
    103103$numcomms = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
    104 $numcats  = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories");
     104$numcats  = wp_count_terms('category');
     105$numtags = wp_count_terms('post_tag');
    105106
    106107$post_str = sprintf(__ngettext('%1$s <a href="%2$s" title="Posts">post</a>', '%1$s <a href="%2$s" title="Posts">posts</a>', $numposts), number_format_i18n($numposts), 'edit.php');
    … …  
    109110?>
    110111
    111 <p><?php printf(__('There are currently %1$s and %2$s, contained within %3$s.'), $post_str, $comm_str, $cat_str); ?></p>
     112<p><?php printf(__('There are currently %1$s and %2$s, contained within %3$s and %4$s tags.'), $post_str, $comm_str, $cat_str, $numtags); ?></p>
    112113</div>
    113114
  • trunk/wp-includes/deprecated.php

    r5444 r5563  
    5757        // Grab the first cat in the list.
    5858        $categories = get_the_category();
    59         $cat = $categories[0]->cat_ID;
     59        $cat = $categories[0]->term_id;
    6060
    6161        if ( $echo )
    … …  
    218218                global $wpdb;
    219219                $cat_id = -1;
    220                 $results = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");
    221                 if ($results) {
    222                                 foreach ($results as $result) {
    223                                                 $cat_id = $result->cat_ID;
    224                                 }
    225                 }
     220                $cat = get_term_by('name', $cat_name, 'link_category');
     221                if ( $cat )
     222                        $cat_id = $cat->term_id;
     223
    226224                get_links($cat_id, $before, $after, $between, $show_images, $orderby,
    227225                                                        $show_description, $show_rating, $limit, $show_updated);
    … …  
    236234        global $wpdb;
    237235
    238         $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category' LIMIT 1");
    239 
    240         if (! $cat_id)
    241                 return;
     236        $cat = get_term_by('name', $cat_name, 'link_category');
     237        if ( !$cat )
     238                return false;
     239        $cat_id = $cat->term_id;       
    242240
    243241        $args = add_query_arg('category', $cat_id, $args);
    … …  
    264262 ** }
    265263 **/
    266 // Deprecate in favor of get_linkz().
    267264function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
    268265                global $wpdb;
    269266                $cat_id = -1;
    270                 //$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");
    271                 // TODO: Fix me.
    272                 if ($results) {
    273                                 foreach ($results as $result) {
    274                                                 $cat_id = $result->cat_id;
    275                                 }
    276                 }
     267                $cat = get_term_by('name', $cat_name, 'link_category');
     268                if ( $cat )
     269                        $cat_id = $cat->term_id;       
     270
    277271                return get_linkobjects($cat_id, $orderby, $limit);
    278272}
    … …  
    314308 **/
    315309// Deprecate in favor of get_linkz().
    316 function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) {
     310function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) {
    317311                global $wpdb;
    318312
    319                 $sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";
    320                 if ($category != -1) {
    321                                 $sql .= " AND link_category = $category ";
     313                $links = get_bookmarks("category=$category&orderby=$orderby&limit=$limit");
     314
     315                $links_array = array();
     316                foreach ($links as $link) {
     317                        $links_array[] = $link;
    322318                }
    323                 if ($orderby == '')
    324                                 $orderby = 'id';
    325                 if (substr($orderby,0,1) == '_') {
    326                                 $direction = ' DESC';
    327                                 $orderby = substr($orderby,1);
    328                 }
    329                 if (strcasecmp('rand',$orderby) == 0) {
    330                                 $orderby = 'rand()';
    331                 } else {
    332                                 $orderby = " link_" . $orderby;
    333                 }
    334                 $sql .= ' ORDER BY ' . $orderby;
    335                 $sql .= $direction;
    336                 /* The next 2 lines implement LIMIT TO processing */
    337                 if ($limit != -1)
    338                                 $sql .= " LIMIT $limit";
    339 
    340                 $results = $wpdb->get_results($sql);
    341                 if ($results) {
    342                                 foreach ($results as $result) {
    343                                                 $result->link_url         = $result->link_url;
    344                                                 $result->link_name        = $result->link_name;
    345                                                 $result->link_description = $result->link_description;
    346                                                 $result->link_notes       = $result->link_notes;
    347                                                 $newresults[] = $result;
    348                                 }
    349                 }
    350                 return $newresults;
     319
     320                return $links_array;
    351321}
    352322
  • trunk/wp-includes/general-template.php

    r5536 r5563  
    186186                                        $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
    187187                }
    188                 $title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
    189                 $title = apply_filters('single_cat_title', $title);
     188                $cat = get_term_by('slug', $category_name, 'category');
     189                if ( $cat )
     190                        $title = apply_filters('single_cat_title', $cat->name);
    190191        }
    191192
  • trunk/wp-includes/taxonomy.php

    r5560 r5563  
    3434        $args['object_type'] = $object_type;
    3535        $wp_taxonomies[$taxonomy] = $args;
     36}
     37
     38function wp_count_terms( $taxonomy ) {
     39        global $wpdb;
     40
     41        return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = '$taxonomy'");
    3642}
    3743
Note: See TracChangeset for help on using the changeset viewer.