Plugin Directory

Changeset 8323

Timestamp:
03/17/2007 01:28:26 AM (19 years ago)
Author:
majelbstoat
Message:
  • Make sure get_categories filter still respects the hierarchy. Padded counts will be wrong, but we can live with that for now.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • gengo/trunk/gengo/gengo.php

    r8314 r8323  
    651651
    652652    // Called from wp_list_categories.
    653     function get_categories($categories, $arguments) {
    654       global $wpdb;
     653function get_categories($categories, $arguments) {
     654  global $wpdb;
    655655
    656656        if (('post' != $arguments['type']) || !$categories) return $categories;
     
    660660        }
    661661        $category_ids = implode(',', $category_ids);
     662
    662663        $viewable_codes = explode(GENGO_LANGUAGE_DIVIDER, $this->viewable_code_string);
    663664        foreach ($viewable_codes as $viewable_code) $ids[] = $this->codes2ids[$viewable_code];
    664665        $language_ids = implode(',', $ids);
    665666        if ($language_ids) {
    666             $categories = $wpdb->get_results("SELECT c.*, COUNT(DISTINCT (CASE WHEN translation_group > 0 THEN -translation_group ELSE p2l.post_id END)) as category_count FROM $this->post2lang_table p2l INNER JOIN $wpdb->post2cat p2c ON p2c.post_id = p2l.post_id INNER JOIN $wpdb->posts p ON p2l.post_id = p.ID INNER JOIN $wpdb->categories AS c ON p2c.category_id = c.cat_ID WHERE p2l.language_id IN ($language_ids) AND p2c.category_id IN ($category_ids) AND p.post_type = 'post' AND p.post_status = 'publish' GROUP BY c.cat_ID $sort_column $sort_order");
     667            $counted_categories = $wpdb->get_results("SELECT c.cat_ID, p.post_type, COUNT(DISTINCT (CASE WHEN translation_group > 0 THEN -translation_group ELSE p2l.post_id END)) as category_count FROM $this->post2lang_table p2l INNER JOIN $wpdb->post2cat p2c ON p2c.post_id = p2l.post_id INNER JOIN $wpdb->posts p ON p2l.post_id = p.ID INNER JOIN $wpdb->categories AS c ON p2c.category_id = c.cat_ID WHERE p2l.language_id IN ($language_ids) AND p2c.category_id IN ($category_ids) AND p.post_status = 'publish' GROUP BY c.cat_ID, p.post_type $sort_column $sort_order");
     668
     669            foreach ($counted_categories as $counted_category) {
     670              $hashed_counts[$counted_category->post_type][$counted_category->cat_ID] = $counted_category->category_count;
     671            }
     672            $post_types = array_keys($hashed_counts);
     673
     674            foreach ($categories as $cat) {
     675                foreach ($post_types as $post_type) {
     676                    $count_slot = ('post' == $post_type) ? 'category_count' : 'category_' . $post_type . 'count';
     677                    $cat->$count_slot = $hashed_counts[$post_type][$cat->cat_ID];
     678                }
     679            }
     680
     681            if ($arguments['hide_empty'] || $arguments['pad_counts']) {
     682                $protected = -1;
     683              $pad = array();
     684              $keys = array_reverse(array_keys($categories));
     685              foreach ($keys as $k) {
     686                    $cat = $categories[$k];
     687                    if ($cat->category_count || ($cat->cat_ID == $protected)) {
     688                        if ($arguments['hierarchical']) {
     689                            $protected = $cat->category_parent;
     690                        }
     691                        if ($arguments['pad_counts']) {
     692                            // Known bug: if a post belongs to a category and its parent, counted twice. Not worth the trouble.
     693                            $cat->category_count += $pad[$cat->cat_ID];
     694                    if ($cat->category_parent) {
     695                                $pad[$cat->category_parent] += $cat->category_count;
     696                            }
     697                  }
     698                } elseif ($arguments['hide_empty']) {
     699                        unset($categories[$k]);
     700                }
     701              }
     702            }
    667703        }
    668704        return $categories;
    669     }
     705}
    670706
    671707    function post_comments_feed_link($url) {
     
    19221958/*
    19231959
    1924 Fatal error get_currentuserinfo()
    1925 categories from MAP.
    1926 in_category().
    1927 
    192819600.91:
    19291961-----
    19301962
     1963
     1964
    19311965autochange the spellchecker if possible...
    19321966move the caching into the_posts()
Note: See TracChangeset for help on using the changeset viewer.