Changeset 2478
- Timestamp:
- 03/27/2005 08:45:01 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-blog-header.php
r2378 r2478 170 170 171 171 // Call query posts to do the work. 172 $posts = query_posts($query_string);172 $posts = & query_posts($query_string); 173 173 174 174 // Extract updated query vars back into global namespace. -
trunk/wp-includes/classes.php
r2475 r2478 218 218 } 219 219 220 function get_posts() {220 function &get_posts() { 221 221 global $wpdb, $pagenow, $request, $user_ID; 222 222 … … 596 596 } 597 597 598 function query($query) {598 function &query($query) { 599 599 $this->parse_query($query); 600 600 return $this->get_posts(); … … 610 610 611 611 if ($this->is_category) { 612 global $cache_categories; 613 if (isset($cache_categories[$this->get('cat')])) { 614 $this->queried_object = $cache_categories[$this->get('cat')]; 615 $this->queried_object_id = $this->get('cat'); 616 } 612 $category = &get_category($this->get('cat')); 613 $this->queried_object = &$category; 614 $this->queried_object_id = $this->get('cat'); 617 615 } else if ($this->is_single) { 618 616 $this->queried_object = $this->post; -
trunk/wp-includes/functions.php
r2477 r2478 539 539 } 540 540 541 // Retrieves post data given a post ID or post object. 542 // Handles post caching. 543 function &get_post(&$post, $output = OBJECT) { 544 global $post_cache, $wpdb; 545 546 if ( empty($post) ) { 547 if ( isset($GLOBALS['post']) ) 548 $post = & $GLOBALS['post']; 549 else 550 $post = null; 551 } elseif (is_object($post) ) { 552 if (! isset($post_cache[$post->ID])) 553 $post_cache[$post->ID] = &$post; 554 $post = & $post_cache[$post->ID]; 555 } else { 556 if ( isset($GLOBALS['post']) && ($post == $GLOBALS['post']->ID) ) 557 $post = & $GLOBALS['post']; 558 elseif (isset($post_cache[$post])) 559 $post = & $post_cache[$post]; 560 else { 561 $query = "SELECT * FROM $wpdb->posts WHERE ID=$post"; 562 $post_cache[$post] = & $wpdb->get_row($query); 563 $post = & $post_cache[$post]; 564 } 565 } 566 567 if ( $output == OBJECT ) { 568 return $post; 569 } elseif ( $output == ARRAY_A ) { 570 return get_object_vars($post); 571 } elseif ( $output == ARRAY_N ) { 572 return array_values(get_object_vars($post)); 573 } else { 574 return $post; 575 } 576 } 577 578 // Retrieves category data given a category ID or category object. 579 // The category cache is fully populated by the blog header, so we don't 580 // have to worry with managing it here. 581 function &get_category(&$category, $output = OBJECT) { 582 global $cache_categories; 583 if (is_object($category)) 584 $category = & $cache_categories[$category->cat_ID]; 585 else 586 $category = & $cache_categories[$category]; 587 588 if ( $output == OBJECT ) { 589 return $category; 590 } elseif ( $output == ARRAY_A ) { 591 return get_object_vars($category); 592 } elseif ( $output == ARRAY_N ) { 593 return array_values(get_object_vars($category)); 594 } else { 595 return $category; 596 } 597 } 598 541 599 function get_catname($cat_ID) { 542 global $cache_catnames, $wpdb; 543 if ( !$cache_catnames ) { 544 $results = $wpdb->get_results("SELECT * FROM $wpdb->categories") or die('Oops, couldn\'t query the db for categories.'); 545 foreach ($results as $post) { 546 $cache_catnames[$post->cat_ID] = $post->cat_name; 547 } 548 } 549 $cat_name = $cache_catnames[$cat_ID]; 550 return $cat_name; 600 $category = &get_category($cat_ID); 601 return $category->cat_name; 551 602 } 552 603 … … 996 1047 997 1048 function get_page_uri($page_id) { 998 global $wpdb, $cache_pages; 999 1000 $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified"; 1001 $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created"; 1002 1003 if (!isset($cache_pages[$page_id])) { 1004 $cache_pages[$page_id] = $wpdb->get_row("SELECT ID, post_title, post_name, post_parent $dates FROM $wpdb->posts WHERE ID = '$page_id'"); 1005 } 1006 1007 $page = $cache_pages[$page_id]; 1049 $page = get_post($page_id); 1008 1050 $uri = urldecode($page->post_name); 1009 1051 … … 1012 1054 return $uri; 1013 1055 } 1014 1056 1015 1057 while ($page->post_parent != 0) { 1016 if (isset($cache_pages[$page->post_parent])) { 1017 $page = $cache_pages[$page->post_parent]; 1018 } else { 1019 $page = $wpdb->get_row("SELECT ID, post_title, post_name, post_parent $dates FROM $wpdb->posts WHERE ID = '$page->post_parent'"); 1020 $cache_pages[$page->ID] = $page; 1021 } 1058 $page = get_post($page->post_parent); 1022 1059 $uri = urldecode($page->post_name) . "/" . $uri; 1023 1060 } … … 1050 1087 } 1051 1088 1052 function query_posts($query) {1089 function &query_posts($query) { 1053 1090 global $wp_query; 1054 1091 return $wp_query->query($query); 1055 1092 } 1056 1093 1057 function update_post_caches($posts) { 1058 global $category_cache, $comment_count_cache, $post_meta_cache; 1094 function update_post_cache(&$posts) { 1095 global $post_cache; 1096 1097 if ( !$posts ) 1098 return; 1099 1100 for ($i = 0; $i < count($posts); $i++) { 1101 $post_cache[$posts[$i]->ID] = &$posts[$i]; 1102 } 1103 } 1104 1105 function update_post_category_cache($post_ids) { 1106 global $wpdb, $category_cache, $cache_categories; 1107 1108 if (empty($post_ids)) 1109 return; 1110 1111 if (is_array($post_ids)) 1112 $post_ids = implode(',', $post_ids); 1113 1114 $dogs = $wpdb->get_results("SELECT DISTINCT 1115 post_id, category_id FROM $wpdb->categories, $wpdb->post2cat 1116 WHERE category_id = cat_ID AND post_id IN ($post_ids)"); 1117 1118 if ( !empty($dogs) ) { 1119 foreach ($dogs as $catt) { 1120 $category_cache[$catt->post_id][$catt->category_id] = &$cache_categories[$catt->category_id]; 1121 } 1122 } 1123 } 1124 1125 function update_post_caches(&$posts) { 1126 global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache; 1059 1127 global $wpdb; 1060 1128 … … 1064 1132 1065 1133 // Get the categories for all the posts 1066 foreach ($posts as $post) 1067 $post_id_list[] = $post->ID; 1134 for ($i = 0; $i < count($posts); $i++) { 1135 $post_id_list[] = $posts[$i]->ID; 1136 $post_cache[$posts[$i]->ID] = &$posts[$i]; 1137 } 1138 1068 1139 $post_id_list = implode(',', $post_id_list); 1069 1070 $dogs = $wpdb->get_results("SELECT DISTINCT 1071 post_id, category_id, cat_name, category_nicename, category_description, category_parent 1072 FROM $wpdb->categories, $wpdb->post2cat 1073 WHERE category_id = cat_ID AND post_id IN ($post_id_list)"); 1074 1075 if ( !empty($dogs) ) { 1076 foreach ($dogs as $catt) { 1077 $category_cache[$catt->post_id][$catt->category_id] = $catt; 1078 } 1079 } 1140 1141 update_post_category_cache($post_id_list); 1080 1142 1081 1143 // Do the same for comment numbers … … 1115 1177 global $cache_categories, $wpdb; 1116 1178 $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories"); 1117 foreach ($dogs as $catt) 1179 foreach ($dogs as $catt) { 1180 $catt->category_id = $catt->cat_ID; // Alias. 1118 1181 $cache_categories[$catt->cat_ID] = $catt; 1182 } 1119 1183 } 1120 1184 -
trunk/wp-includes/template-functions-category.php
r2450 r2478 2 2 3 3 function get_the_category($id = false) { 4 global $post, $ wpdb, $category_cache;4 global $post, $category_cache; 5 5 6 6 if ( !$id ) 7 7 $id = $post->ID; 8 8 9 if ( $category_cache[$id] ) { 10 $categories = $category_cache[$id]; 11 } else { 12 $categories = $wpdb->get_results(" 13 SELECT category_id, cat_name, category_nicename, category_description, category_parent 14 FROM $wpdb->categories, $wpdb->post2cat 15 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$id' 16 "); 17 } 9 if ( ! isset($category_cache[$id]) ) 10 update_post_category_cache($id); 11 12 $categories = $category_cache[$id]; 18 13 19 14 if (!empty($categories)) … … 26 21 27 22 function get_category_link($category_id) { 28 global $wp db, $wp_rewrite, $querystring_start, $querystring_equal, $cache_categories;23 global $wp_rewrite; 29 24 $catlink = $wp_rewrite->get_category_permastruct(); 30 25 … … 33 28 $catlink = $file . '?cat=' . $category_id; 34 29 } else { 35 if ($cache_categories[$category_id]->category_nicename) 36 $category_nicename = $cache_categories[$category_id]->category_nicename; 37 else 38 $category_nicename = $wpdb->get_var('SELECT category_nicename FROM ' . $wpdb->categories . ' WHERE cat_ID=' . $category_id); 39 40 if ($parent = $cache_categories[$category_id]->category_parent) 30 $category = &get_category($category_id); 31 $category_nicename = $category->category_nicename; 32 33 if ($parent = $category->category_parent) 41 34 $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/'; 42 35 … … 109 102 110 103 function get_the_category_by_ID($cat_ID) { 111 global $cache_categories, $wpdb; 112 if ( !$cache_categories[$cat_ID] ) { 113 $cat_name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); 114 $cache_categories[$cat_ID]->cat_name = $cat_name; 115 } else { 116 $cat_name = $cache_categories[$cat_ID]->cat_name; 117 } 118 return($cat_name); 104 $category = &get_category($cat_ID); 105 return $category->cat_name; 119 106 } 120 107 121 108 function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){ 122 global $cache_categories;123 109 $chain = ''; 124 $parent = $cache_categories[$id];110 $parent = &get_category($id); 125 111 if ($nicename) { 126 112 $name = $parent->category_nicename; … … 176 162 177 163 function category_description($category = 0) { 178 global $cat , $wpdb, $cache_categories;164 global $cat; 179 165 if (!$category) $category = $cat; 180 $category_description = $cache_categories[$category]->category_description; 181 $category_description = apply_filters('category_description', $category_description, $category); 182 return $category_description; 166 $category = & get_category($category); 167 return apply_filters('category_description', $category->category_description, $category->cat_ID); 183 168 } 184 169 -
trunk/wp-includes/template-functions-general.php
r2344 r2478 194 194 $p = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$name'"); 195 195 } 196 $post _data = get_postdata($p);197 $title = $post _data['Title'];196 $post = & get_post($p); 197 $title = $post->post_title; 198 198 $title = apply_filters('single_post_title', $title); 199 199 if ($display) { … … 348 348 } 349 349 } elseif ('postbypost' == $type) { 350 $arcresults = $wpdb->get_results("SELECT ID, post_date, post_titleFROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);350 $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); 351 351 if ($arcresults) { 352 352 foreach ($arcresults as $arcresult) { 353 353 if ($arcresult->post_date != '0000-00-00 00:00:00') { 354 $url = get_permalink($arcresult ->ID);354 $url = get_permalink($arcresult); 355 355 $arc_title = $arcresult->post_title; 356 356 if ($arc_title) { -
trunk/wp-includes/template-functions-links.php
r2422 r2478 23 23 } 24 24 25 function get_permalink($id = false) { 26 global $post, $wpdb; 27 25 function get_permalink($id = 0) { 28 26 $rewritecode = array( 29 27 '%year%', … … 40 38 ); 41 39 42 if ($id) { 43 $idpost = $wpdb->get_row("SELECT ID, post_date, post_name, post_status, post_author FROM $wpdb->posts WHERE ID = $id"); 44 } else { 45 $idpost = $post; 40 $post = & get_post($id); 41 if ($post->post_status == 'static') { 42 return get_page_link($post->ID); 46 43 } 47 44 48 if ($idpost->post_status == 'static') {49 return get_page_link($idpost->ID);50 }51 52 45 $permalink = get_settings('permalink_structure'); 53 46 54 47 if ('' != $permalink) { 55 $unixtime = strtotime($ idpost->post_date);48 $unixtime = strtotime($post->post_date); 56 49 57 50 $category = ''; 58 51 if (strstr($permalink, '%category%')) { 59 $cats = get_the_category($ idpost->ID);52 $cats = get_the_category($post->ID); 60 53 $category = $cats[0]->category_nicename; 61 54 if ($parent=$cats[0]->category_parent) $category = get_category_parents($parent, FALSE, '/', TRUE) . $category; 62 55 } 63 56 64 $authordata = get_userdata($ idpost->post_author);57 $authordata = get_userdata($post->post_author); 65 58 $author = $authordata->user_nicename; 66 59 $rewritereplace = … … 72 65 date('i', $unixtime), 73 66 date('s', $unixtime), 74 $ idpost->post_name,75 $ idpost->ID,67 $post->post_name, 68 $post->ID, 76 69 $category, 77 70 $author, 78 $ idpost->post_name,71 $post->post_name, 79 72 ); 80 return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $ idpost);73 return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post); 81 74 } else { // if they're not using the fancy permalink option 82 $permalink = get_settings('home') . '/?p=' . $ idpost->ID;83 return apply_filters('post_link', $permalink, $ idpost);75 $permalink = get_settings('home') . '/?p=' . $post->ID; 76 return apply_filters('post_link', $permalink, $post); 84 77 } 85 78 } -
trunk/wp-includes/template-functions-post.php
r2435 r2478 27 27 28 28 function get_the_title($id = 0) { 29 global $post, $wpdb; 30 31 if ( 0 != $id ) { 32 $id_post = $wpdb->get_row("SELECT post_title, post_password FROM $wpdb->posts WHERE ID = $id"); 33 $title = $id_post->post_title; 34 if (!empty($id_post->post_password)) 35 $title = sprintf(__('Protected: %s'), $title); 36 } 37 else { 38 $title = $post->post_title; 39 if (!empty($post->post_password)) 40 $title = sprintf(__('Protected: %s'), $title); 41 } 29 $post = &get_post($id); 30 31 $title = $post->post_title; 32 if (!empty($post->post_password)) 33 $title = sprintf(__('Protected: %s'), $title); 34 42 35 return $title; 43 36 } 44 37 45 38 function get_the_guid( $id = 0 ) { 46 global $post, $wpdb; 47 $guid = $post->guid; 48 49 if ( 0 != $id ) 50 $guid = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE ID = $id"); 51 $guid = apply_filters('get_the_guid', $guid); 52 return $guid; 39 $post = &get_post($id); 40 41 return apply_filters('get_the_guid', $post->guid); 53 42 } 54 43 55 44 function the_guid( $id = 0 ) { 56 echo get_the_guid( );45 echo get_the_guid($id); 57 46 } 58 47 … … 262 251 // 263 252 264 function get_pages($args = '') {253 function &get_pages($args = '') { 265 254 global $wpdb, $cache_pages; 266 255 … … 281 270 } 282 271 283 $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified";284 $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created";285 286 272 $post_parent = ''; 287 273 if ($r['child_of']) { … … 289 275 } 290 276 291 $pages = $wpdb->get_results("SELECT " . 292 "ID, post_title, post_name, post_parent " . 293 "$dates " . 277 $pages = $wpdb->get_results("SELECT * " . 294 278 "FROM $wpdb->posts " . 295 279 "WHERE post_status = 'static' " . … … 298 282 "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']); 299 283 300 // Update page cache. 301 if (count($pages)) { 302 foreach($pages as $page) { 303 $cache_pages[$page->ID] = $page; 304 } 305 } 284 // Update cache. 285 update_post_cache($pages); 306 286 307 287 if ( empty($pages) ) … … 320 300 321 301 // Query pages. 322 $pages = get_pages($args);302 $pages = & get_pages($args); 323 303 if ( $pages ) : 324 304 … … 339 319 if (! empty($r['show_date'])) { 340 320 if ('modified' == $r['show_date']) 341 $page_tree[$page->ID]['ts'] = $page-> time_modified;321 $page_tree[$page->ID]['ts'] = $page->post_modified; 342 322 else 343 $page_tree[$page->ID]['ts'] = $page-> time_created;323 $page_tree[$page->ID]['ts'] = $page->post_date; 344 324 } 345 325 … … 384 364 if(isset($args['date_format'])) 385 365 $format = $args['date_format']; 386 echo " " . gmdate($format,$cur_page['ts']);366 echo " " . mysql2date($format,$cur_page['ts']); 387 367 } 388 368 echo "\n";
Note: See TracChangeset
for help on using the changeset viewer.