mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
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:
parent
2857b43d78
commit
ee5ec0c505
@ -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");
|
$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) {
|
function wxr_missing_parents($categories) {
|
||||||
if ( !is_array($categories) || empty($categories) )
|
if ( !is_array($categories) || empty($categories) )
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
foreach ( $categories as $category )
|
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)));
|
$parents = array_unique(array_diff($parents, array_keys($parents)));
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ function wxr_missing_parents($categories) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ( $parents = 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) )
|
if ( is_array($found_parents) && count($found_parents) )
|
||||||
$categories = array_merge($categories, $found_parents);
|
$categories = array_merge($categories, $found_parents);
|
||||||
else
|
else
|
||||||
@ -90,8 +90,8 @@ while ( $parents = wxr_missing_parents($categories) ) {
|
|||||||
$pass = 0;
|
$pass = 0;
|
||||||
$passes = 1000 + count($categories);
|
$passes = 1000 + count($categories);
|
||||||
while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
|
while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
|
||||||
if ( $cat->category_parent == 0 || isset($cats[$cat->category_parent]) ) {
|
if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
|
||||||
$cats[$cat->cat_ID] = $cat;
|
$cats[$cat->term_id] = $cat;
|
||||||
} else {
|
} else {
|
||||||
$categories[] = $cat;
|
$categories[] = $cat;
|
||||||
}
|
}
|
||||||
@ -110,17 +110,17 @@ function wxr_cdata($str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wxr_cat_name($c) {
|
function wxr_cat_name($c) {
|
||||||
if ( empty($c->cat_name) )
|
if ( empty($c->name) )
|
||||||
return;
|
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) {
|
function wxr_category_description($c) {
|
||||||
if ( empty($c->category_description) )
|
if ( empty($c->description) )
|
||||||
return;
|
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";
|
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>
|
<generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
|
||||||
<language><?php echo get_option('rss_language'); ?></language>
|
<language><?php echo get_option('rss_language'); ?></language>
|
||||||
<?php if ( $cats ) : foreach ( $cats as $c ) : ?>
|
<?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 endforeach; endif; ?>
|
||||||
<?php do_action('rss2_head'); ?>
|
<?php do_action('rss2_head'); ?>
|
||||||
<?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
|
<?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
|
||||||
|
@ -101,14 +101,15 @@ foreach ($scheduled as $post) {
|
|||||||
<?php
|
<?php
|
||||||
$numposts = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
|
$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'");
|
$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');
|
$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');
|
$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');
|
$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>
|
</div>
|
||||||
|
|
||||||
<?php do_action('activity_box_end'); ?>
|
<?php do_action('activity_box_end'); ?>
|
||||||
|
@ -56,7 +56,7 @@ function start_wp() {
|
|||||||
function the_category_ID($echo = true) {
|
function the_category_ID($echo = true) {
|
||||||
// Grab the first cat in the list.
|
// Grab the first cat in the list.
|
||||||
$categories = get_the_category();
|
$categories = get_the_category();
|
||||||
$cat = $categories[0]->cat_ID;
|
$cat = $categories[0]->term_id;
|
||||||
|
|
||||||
if ( $echo )
|
if ( $echo )
|
||||||
echo $cat;
|
echo $cat;
|
||||||
@ -217,12 +217,10 @@ function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />',
|
|||||||
$limit = -1, $show_updated = 0) {
|
$limit = -1, $show_updated = 0) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$cat_id = -1;
|
$cat_id = -1;
|
||||||
$results = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");
|
$cat = get_term_by('name', $cat_name, 'link_category');
|
||||||
if ($results) {
|
if ( $cat )
|
||||||
foreach ($results as $result) {
|
$cat_id = $cat->term_id;
|
||||||
$cat_id = $result->cat_ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
get_links($cat_id, $before, $after, $between, $show_images, $orderby,
|
get_links($cat_id, $before, $after, $between, $show_images, $orderby,
|
||||||
$show_description, $show_rating, $limit, $show_updated);
|
$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 = '') {
|
function wp_get_linksbyname($category, $args = '') {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category' LIMIT 1");
|
$cat = get_term_by('name', $cat_name, 'link_category');
|
||||||
|
if ( !$cat )
|
||||||
if (! $cat_id)
|
return false;
|
||||||
return;
|
$cat_id = $cat->term_id;
|
||||||
|
|
||||||
$args = add_query_arg('category', $cat_id, $args);
|
$args = add_query_arg('category', $cat_id, $args);
|
||||||
wp_get_links($args);
|
wp_get_links($args);
|
||||||
@ -263,17 +261,13 @@ function wp_get_linksbyname($category, $args = '') {
|
|||||||
** echo '<li>'.$link->link_name.'</li>';
|
** echo '<li>'.$link->link_name.'</li>';
|
||||||
** }
|
** }
|
||||||
**/
|
**/
|
||||||
// Deprecate in favor of get_linkz().
|
|
||||||
function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
|
function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$cat_id = -1;
|
$cat_id = -1;
|
||||||
//$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");
|
$cat = get_term_by('name', $cat_name, 'link_category');
|
||||||
// TODO: Fix me.
|
if ( $cat )
|
||||||
if ($results) {
|
$cat_id = $cat->term_id;
|
||||||
foreach ($results as $result) {
|
|
||||||
$cat_id = $result->cat_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return get_linkobjects($cat_id, $orderby, $limit);
|
return get_linkobjects($cat_id, $orderby, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,41 +307,17 @@ function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit
|
|||||||
** link_notes
|
** link_notes
|
||||||
**/
|
**/
|
||||||
// Deprecate in favor of get_linkz().
|
// 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;
|
global $wpdb;
|
||||||
|
|
||||||
$sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";
|
$links = get_bookmarks("category=$category&orderby=$orderby&limit=$limit");
|
||||||
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";
|
|
||||||
|
|
||||||
$results = $wpdb->get_results($sql);
|
$links_array = array();
|
||||||
if ($results) {
|
foreach ($links as $link) {
|
||||||
foreach ($results as $result) {
|
$links_array[] = $link;
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $newresults;
|
|
||||||
|
return $links_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** function get_linksbyname_withrating()
|
/** function get_linksbyname_withrating()
|
||||||
|
@ -185,8 +185,9 @@ function wp_title($sep = '»', $display = true) {
|
|||||||
else
|
else
|
||||||
$category_name = $category_name[count($category_name)-2]; // there was a trailling slash
|
$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'");
|
$cat = get_term_by('slug', $category_name, 'category');
|
||||||
$title = apply_filters('single_cat_title', $title);
|
if ( $cat )
|
||||||
|
$title = apply_filters('single_cat_title', $cat->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($tag) ) {
|
if ( !empty($tag) ) {
|
||||||
|
@ -35,6 +35,12 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
|||||||
$wp_taxonomies[$taxonomy] = $args;
|
$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.
|
* 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.
|
* @param int|string $term The term to add or update.
|
||||||
|
Loading…
Reference in New Issue
Block a user