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

git-svn-id: http://svn.automattic.com/wordpress/trunk@5563 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-05-27 19:32:45 +00:00
parent 2857b43d78
commit ee5ec0c505
5 changed files with 42 additions and 64 deletions

View File

@ -61,14 +61,14 @@ if ( isset( $_GET['author'] ) && $_GET['author'] != 'all' ) {
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
$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");
$categories = (array) get_categories('get=all');
function wxr_missing_parents($categories) {
if ( !is_array($categories) || empty($categories) )
return array();
foreach ( $categories as $category )
$parents[$category->cat_ID] = $category->category_parent;
$parents[$category->term_id] = $category->parent;
$parents = array_unique(array_diff($parents, array_keys($parents)));
@ -79,7 +79,7 @@ function wxr_missing_parents($categories) {
}
while ( $parents = wxr_missing_parents($categories) ) {
$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) . ")");
$found_parents = get_categories("include=" . join(', ', $parents));
if ( is_array($found_parents) && count($found_parents) )
$categories = array_merge($categories, $found_parents);
else
@ -90,8 +90,8 @@ while ( $parents = wxr_missing_parents($categories) ) {
$pass = 0;
$passes = 1000 + count($categories);
while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
if ( $cat->category_parent == 0 || isset($cats[$cat->category_parent]) ) {
$cats[$cat->cat_ID] = $cat;
if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
$cats[$cat->term_id] = $cat;
} else {
$categories[] = $cat;
}
@ -110,17 +110,17 @@ function wxr_cdata($str) {
}
function wxr_cat_name($c) {
if ( empty($c->cat_name) )
if ( empty($c->name) )
return;
echo '<wp:cat_name>' . wxr_cdata($c->cat_name) . '</wp:cat_name>';
echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
}
function wxr_category_description($c) {
if ( empty($c->category_description) )
if ( empty($c->description) )
return;
echo '<wp:category_description>' . wxr_cdata($c->category_description) . '</wp:category_description>';
echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
}
print '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
@ -163,7 +163,7 @@ print '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
<generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
<language><?php echo get_option('rss_language'); ?></language>
<?php if ( $cats ) : foreach ( $cats as $c ) : ?>
<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>
<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>
<?php endforeach; endif; ?>
<?php do_action('rss2_head'); ?>
<?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>

View File

@ -101,14 +101,15 @@ foreach ($scheduled as $post) {
<?php
$numposts = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
$numcomms = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
$numcats = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories");
$numcats = wp_count_terms('category');
$numtags = wp_count_terms('post_tag');
$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');
$comm_str = sprintf(__ngettext('%1$s <a href="%2$s" title="Comments">comment</a>', '%1$s <a href="%2$s" title="Comments">comments</a>', $numcomms), number_format_i18n($numcomms), 'edit-comments.php');
$cat_str = sprintf(__ngettext('%1$s <a href="%2$s" title="Categories">category</a>', '%1$s <a href="%2$s" title="Categories">categories</a>', $numcats), number_format_i18n($numcats), 'categories.php');
?>
<p><?php printf(__('There are currently %1$s and %2$s, contained within %3$s.'), $post_str, $comm_str, $cat_str); ?></p>
<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>
</div>
<?php do_action('activity_box_end'); ?>

View File

@ -56,7 +56,7 @@ function start_wp() {
function the_category_ID($echo = true) {
// Grab the first cat in the list.
$categories = get_the_category();
$cat = $categories[0]->cat_ID;
$cat = $categories[0]->term_id;
if ( $echo )
echo $cat;
@ -217,12 +217,10 @@ function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />',
$limit = -1, $show_updated = 0) {
global $wpdb;
$cat_id = -1;
$results = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");
if ($results) {
foreach ($results as $result) {
$cat_id = $result->cat_ID;
}
}
$cat = get_term_by('name', $cat_name, 'link_category');
if ( $cat )
$cat_id = $cat->term_id;
get_links($cat_id, $before, $after, $between, $show_images, $orderby,
$show_description, $show_rating, $limit, $show_updated);
}
@ -235,10 +233,10 @@ function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />',
function wp_get_linksbyname($category, $args = '') {
global $wpdb;
$cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category' LIMIT 1");
if (! $cat_id)
return;
$cat = get_term_by('name', $cat_name, 'link_category');
if ( !$cat )
return false;
$cat_id = $cat->term_id;
$args = add_query_arg('category', $cat_id, $args);
wp_get_links($args);
@ -263,17 +261,13 @@ function wp_get_linksbyname($category, $args = '') {
** echo '<li>'.$link->link_name.'</li>';
** }
**/
// Deprecate in favor of get_linkz().
function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
global $wpdb;
$cat_id = -1;
//$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");
// TODO: Fix me.
if ($results) {
foreach ($results as $result) {
$cat_id = $result->cat_id;
}
}
$cat = get_term_by('name', $cat_name, 'link_category');
if ( $cat )
$cat_id = $cat->term_id;
return get_linkobjects($cat_id, $orderby, $limit);
}
@ -313,41 +307,17 @@ function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit
** link_notes
**/
// Deprecate in favor of get_linkz().
function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) {
function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) {
global $wpdb;
$sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";
if ($category != -1) {
$sql .= " AND link_category = $category ";
}
if ($orderby == '')
$orderby = 'id';
if (substr($orderby,0,1) == '_') {
$direction = ' DESC';
$orderby = substr($orderby,1);
}
if (strcasecmp('rand',$orderby) == 0) {
$orderby = 'rand()';
} else {
$orderby = " link_" . $orderby;
}
$sql .= ' ORDER BY ' . $orderby;
$sql .= $direction;
/* The next 2 lines implement LIMIT TO processing */
if ($limit != -1)
$sql .= " LIMIT $limit";
$links = get_bookmarks("category=$category&orderby=$orderby&limit=$limit");
$results = $wpdb->get_results($sql);
if ($results) {
foreach ($results as $result) {
$result->link_url = $result->link_url;
$result->link_name = $result->link_name;
$result->link_description = $result->link_description;
$result->link_notes = $result->link_notes;
$newresults[] = $result;
}
$links_array = array();
foreach ($links as $link) {
$links_array[] = $link;
}
return $newresults;
return $links_array;
}
/** function get_linksbyname_withrating()

View File

@ -185,8 +185,9 @@ function wp_title($sep = '&raquo;', $display = true) {
else
$category_name = $category_name[count($category_name)-2]; // there was a trailling slash
}
$title = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE category_nicename = '$category_name'");
$title = apply_filters('single_cat_title', $title);
$cat = get_term_by('slug', $category_name, 'category');
if ( $cat )
$title = apply_filters('single_cat_title', $cat->name);
}
if ( !empty($tag) ) {

View File

@ -35,6 +35,12 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
$wp_taxonomies[$taxonomy] = $args;
}
function wp_count_terms( $taxonomy ) {
global $wpdb;
return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = '$taxonomy'");
}
/**
* Adds a new term to the database. Optionally marks it as an alias of an existing term.
* @param int|string $term The term to add or update.