Changeset 3576
- Timestamp:
- 02/28/06 08:00:39 (3 years ago)
- Files:
-
- trunk/wp-includes/cache.php (modified) (1 diff)
- trunk/wp-includes/classes.php (modified) (3 diffs)
- trunk/wp-includes/functions.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-includes/cache.php
r3517 r3576 182 182 foreach ($dogs as $catt) 183 183 $this->cache['category'][$catt->cat_ID] = $catt; 184 185 foreach ($this->cache['category'] as $catt) {186 $curcat = $catt->cat_ID;187 $fullpath = '/'.$this->cache['category'][$catt->cat_ID]->category_nicename;188 while ($this->cache['category'][$curcat]->category_parent != 0) {189 $curcat = $this->cache['category'][$curcat]->category_parent;190 $fullpath = '/'.$this->cache['category'][$curcat]->category_nicename.$fullpath;191 }192 $this->cache['category'][$catt->cat_ID]->fullpath = $fullpath;193 }194 184 } 195 185 } else trunk/wp-includes/classes.php
r3566 r3576 360 360 } else if ('' != $q['pagename']) { 361 361 $reqpage = get_page_by_path($q['pagename']); 362 if ( !empty($reqpage) ) 363 $reqpage = $reqpage->ID; 364 else 365 $reqpage = 0; 362 366 $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); 363 367 $page_paths = '/' . trim($q['pagename'], '/'); … … 464 468 global $cache_categories; 465 469 if ('' != $q['category_name']) { 470 $reqcat = get_category_by_path($q['category_name']); 471 $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name']))); 472 $cat_paths = '/' . trim($q['category_name'], '/'); 473 $q['category_name'] = sanitize_title(basename($cat_paths)); 474 466 475 $cat_paths = '/' . trim(urldecode($q['category_name']), '/'); 467 476 $q['category_name'] = sanitize_title(basename($cat_paths)); … … 470 479 $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); 471 480 472 $all_cat_ids = get_all_category_ids();473 $q['cat'] = 0; $partial_match = 0;474 foreach ( $all_cat_ids as $cat_id ) {475 $cat = get_category($cat_id);476 if ( $cat->fullpath == $cat_path ) {477 $q['cat'] = $cat_id;478 break;479 } elseif ( $cat->category_nicename == $q['category_name'] ) {480 $partial_match = $cat_id;481 }482 }483 484 481 //if we don't match the entire hierarchy fallback on just matching the nicename 485 if (!$q['cat'] && $partial_match) { 486 $q['cat'] = $partial_match; 487 } 488 482 if ( empty($reqcat) ) 483 $reqcat = get_category_by_path($q['category_name'], false); 484 485 if ( !empty($reqcat) ) 486 $reqcat = $reqcat->cat_ID; 487 else 488 $reqcat = 0; 489 490 $q['cat'] = $reqcat; 491 489 492 $tables = ", $wpdb->post2cat, $wpdb->categories"; 490 493 $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) "; trunk/wp-includes/functions.php
r3573 r3576 651 651 } 652 652 653 function set_page_path($page) { 654 $page->fullpath = '/' . $page->post_name; 655 $path = $page->fullpath; 656 $curpage = $page; 657 while ($curpage->post_parent != 0) { 658 $curpage = get_page($curpage->post_parent); 659 $path = '/' . $curpage->post_name . $path; 660 } 661 662 $page->fullpath = $path; 663 664 return $page; 665 } 666 667 function get_page_by_path($page_path) { 653 function get_page_by_path($page_path, $output = OBJECT) { 668 654 global $wpdb; 669 655 $page_path = rawurlencode(urldecode($page_path)); … … 679 665 680 666 if ( empty($pages) ) 681 return 0;667 return NULL; 682 668 683 669 foreach ($pages as $page) { … … 690 676 691 677 if ( $path == $full_path ) 692 return $page->ID;693 } 694 695 return 0;678 return get_page($page->ID, $output); 679 } 680 681 return NULL; 696 682 } 697 683 … … 728 714 wp_cache_add($_page->ID, $_page, 'pages'); 729 715 } 730 }731 732 if (!isset($_page->fullpath)) {733 $_page = set_page_path($_page);734 wp_cache_replace($_page->ID, $_page, 'pages');735 716 } 736 717 … … 824 805 } 825 806 826 function set_category_path($cat) { 827 $cat->fullpath = '/' . $cat->category_nicename; 828 $path = $cat->fullpath; 829 $curcat = $cat; 830 while ($curcat->category_parent != 0) { 831 $curcat = get_category($curcat->category_parent); 832 $path = '/' . $curcat->category_nicename . $path; 833 } 834 835 $cat->fullpath = $path; 836 837 return $cat; 807 function get_category_by_path($category_path, $full_match = true, $output = OBJECT) { 808 global $wpdb; 809 $category_path = rawurlencode(urldecode($category_path)); 810 $category_path = str_replace('%2F', '/', $category_path); 811 $category_path = str_replace('%20', ' ', $category_path); 812 $category_paths = '/' . trim($category_path, '/'); 813 $leaf_path = sanitize_title(basename($category_paths)); 814 $category_paths = explode('/', $category_paths); 815 foreach($category_paths as $pathdir) 816 $full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); 817 818 $categories = $wpdb->get_results("SELECT cat_ID, category_nicename, category_parent FROM $wpdb->categories WHERE category_nicename = '$leaf_path'"); 819 820 if ( empty($categories) ) 821 return NULL; 822 823 foreach ($categories as $category) { 824 $path = '/' . $leaf_path; 825 $curcategory = $category; 826 while ($curcategory->category_parent != 0) { 827 $curcategory = $wpdb->get_row("SELECT cat_ID, category_nicename, category_parent FROM $wpdb->categories WHERE cat_ID = '$curcategory->category_parent'"); 828 $path = '/' . $curcategory->category_nicename . $path; 829 } 830 831 if ( $path == $full_path ) 832 return get_category($category->cat_ID, $output); 833 } 834 835 // If full matching is not required, return the first cat that matches the leaf. 836 if ( ! $full_match ) 837 return get_category($categories[0]->cat_ID, $output); 838 839 return NULL; 838 840 } 839 841 … … 854 856 wp_cache_add($category, $_category, 'category'); 855 857 } 856 }857 858 if ( !isset($_category->fullpath) ) {859 $_category = set_category_path($_category);860 wp_cache_replace($_category->cat_ID, $_category, 'category');861 858 } 862 859
