mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Start moving link categories to taxonomy. see #4189
git-svn-id: https://develop.svn.wordpress.org/trunk@5523 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
+6
-62
@@ -463,78 +463,22 @@ function wp_delete_link($link_id) {
|
||||
do_action('deleted_link', $link_id);
|
||||
}
|
||||
|
||||
function wp_get_link_cats($link_ID = 0) {
|
||||
global $wpdb;
|
||||
function wp_get_link_cats($link_id = 0) {
|
||||
|
||||
$sql = "SELECT category_id
|
||||
FROM $wpdb->link2cat
|
||||
WHERE link_id = $link_ID
|
||||
ORDER BY category_id";
|
||||
$cats = get_object_terms($link_id, 'link_category', 'get=ids');
|
||||
|
||||
$result = $wpdb->get_col($sql);
|
||||
|
||||
if ( !$result )
|
||||
$result = array();
|
||||
|
||||
return array_unique($result);
|
||||
return array_unique($cats);
|
||||
}
|
||||
|
||||
function wp_set_link_cats($link_ID = 0, $link_categories = array()) {
|
||||
global $wpdb;
|
||||
function wp_set_link_cats($link_id = 0, $link_categories = array()) {
|
||||
// If $link_categories isn't already an array, make it one:
|
||||
if (!is_array($link_categories) || 0 == count($link_categories))
|
||||
$link_categories = array(get_option('default_link_category'));
|
||||
|
||||
$link_categories = array_map('intval', $link_categories);
|
||||
$link_categories = array_unique($link_categories);
|
||||
|
||||
// First the old categories
|
||||
$old_categories = $wpdb->get_col("
|
||||
SELECT category_id
|
||||
FROM $wpdb->link2cat
|
||||
WHERE link_id = '$link_ID'");
|
||||
|
||||
if (!$old_categories) {
|
||||
$old_categories = array();
|
||||
} else {
|
||||
$old_categories = array_unique($old_categories);
|
||||
}
|
||||
|
||||
// Delete any?
|
||||
$delete_cats = array_diff($old_categories,$link_categories);
|
||||
|
||||
if ($delete_cats) {
|
||||
foreach ($delete_cats as $del) {
|
||||
$del = (int) $del;
|
||||
$wpdb->query("
|
||||
DELETE FROM $wpdb->link2cat
|
||||
WHERE category_id = '$del'
|
||||
AND link_id = '$link_ID'
|
||||
");
|
||||
}
|
||||
}
|
||||
|
||||
// Add any?
|
||||
$add_cats = array_diff($link_categories, $old_categories);
|
||||
|
||||
if ($add_cats) {
|
||||
foreach ($add_cats as $new_cat) {
|
||||
$new_cat = (int) $new_cat;
|
||||
if ( !empty($new_cat) )
|
||||
$wpdb->query("
|
||||
INSERT INTO $wpdb->link2cat (link_id, category_id)
|
||||
VALUES ('$link_ID', '$new_cat')");
|
||||
}
|
||||
}
|
||||
|
||||
// Update category counts.
|
||||
$all_affected_cats = array_unique(array_merge($link_categories, $old_categories));
|
||||
foreach ( $all_affected_cats as $cat_id ) {
|
||||
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'");
|
||||
$wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'");
|
||||
wp_cache_delete($cat_id, 'category');
|
||||
do_action('edit_category', $cat_id);
|
||||
}
|
||||
|
||||
wp_set_object_terms($link_id, $link_categories, 'link_category');
|
||||
} // wp_set_link_cats()
|
||||
|
||||
function post_exists($title, $content = '', $post_date = '') {
|
||||
|
||||
@@ -740,20 +740,11 @@ function dropdown_categories( $default = 0 ) {
|
||||
write_nested_categories( get_nested_categories( $default) );
|
||||
}
|
||||
|
||||
function return_link_categories_list( $parent = 0 ) {
|
||||
global $wpdb;
|
||||
return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( type & " . TAXONOMY_CATEGORY . " != 0 ) AND ( category_count = 0 OR link_count != 0 ) ORDER BY link_count DESC" );
|
||||
}
|
||||
|
||||
function get_nested_link_categories( $default = 0, $parent = 0 ) {
|
||||
global $post_ID, $link_id, $mode, $wpdb;
|
||||
function dropdown_link_categories( $default = 0 ) {
|
||||
global $link_id;
|
||||
|
||||
if ( $link_id ) {
|
||||
$checked_categories = $wpdb->get_col( "
|
||||
SELECT category_id
|
||||
FROM $wpdb->categories, $wpdb->link2cat
|
||||
WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id'
|
||||
" );
|
||||
$checked_categories = wp_get_link_cats($link_id);
|
||||
|
||||
if ( count( $checked_categories ) == 0 ) {
|
||||
// No selected categories, strange
|
||||
@@ -763,25 +754,17 @@ function get_nested_link_categories( $default = 0, $parent = 0 ) {
|
||||
$checked_categories[] = $default;
|
||||
}
|
||||
|
||||
$cats = return_link_categories_list( $parent);
|
||||
$result = array ();
|
||||
$categories = get_terms('link_category', 'orderby=count');
|
||||
|
||||
if ( empty($categories) )
|
||||
return;
|
||||
|
||||
if ( is_array( $cats ) ) {
|
||||
foreach ( $cats as $cat) {
|
||||
$result[$cat]['children'] = get_nested_link_categories( $default, $cat);
|
||||
$result[$cat]['cat_ID'] = $cat;
|
||||
$result[$cat]['checked'] = in_array( $cat, $checked_categories );
|
||||
$result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
|
||||
}
|
||||
foreach ( $categories as $category ) {
|
||||
$cat_id = $category->term_id;
|
||||
$name = wp_specialchars( apply_filters('the_category', $category->name));
|
||||
$checked = in_array( $cat_id, $checked_categories );
|
||||
echo '<li id="category-', $cat_id, '"><label for="in-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="post_category[]" id="in-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
|
||||
}
|
||||
|
||||
usort( $result, 'sort_cats' );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function dropdown_link_categories( $default = 0 ) {
|
||||
write_nested_categories( get_nested_link_categories( $default) );
|
||||
}
|
||||
|
||||
// Dandy new recursive multiple category stuff.
|
||||
|
||||
@@ -159,8 +159,8 @@ if ( $links ) {
|
||||
?><td><?php
|
||||
$cat_names = array();
|
||||
foreach ($link->link_category as $category) {
|
||||
$cat_name = get_the_category_by_ID($category);
|
||||
$cat_name = wp_specialchars(apply_filters('link_category', $cat_name));
|
||||
$cat = get_term($category, 'link_category');
|
||||
$cat_name = wp_specialchars(apply_filters('link_category', $cat->name));
|
||||
if ( $cat_id != $category )
|
||||
$cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
|
||||
$cat_names[] = $cat_name;
|
||||
|
||||
Reference in New Issue
Block a user