Changeset 14401
- Timestamp:
- 05/03/2010 08:19:13 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/query.php
r14341 r14401 1205 1205 ); 1206 1206 1207 foreach ( $keys as $key) {1207 foreach ( $keys as $key ) { 1208 1208 if ( !isset($array[$key])) 1209 1209 $array[$key] = ''; … … 1228 1228 * @param string|array $query 1229 1229 */ 1230 function parse_query($query ) {1230 function parse_query($query ) { 1231 1231 if ( !empty($query) || !isset($this->query) ) { 1232 1232 $this->init(); … … 1302 1302 1303 1303 if ( $qv['day'] ) { 1304 if ( ! $this->is_date) {1304 if ( ! $this->is_date ) { 1305 1305 $this->is_day = true; 1306 1306 $this->is_date = true; … … 1309 1309 1310 1310 if ( $qv['monthnum'] ) { 1311 if ( ! $this->is_date) {1311 if ( ! $this->is_date ) { 1312 1312 $this->is_month = true; 1313 1313 $this->is_date = true; … … 1316 1316 1317 1317 if ( $qv['year'] ) { 1318 if ( ! $this->is_date) {1318 if ( ! $this->is_date ) { 1319 1319 $this->is_year = true; 1320 1320 $this->is_date = true; … … 1324 1324 if ( $qv['m'] ) { 1325 1325 $this->is_date = true; 1326 if ( strlen($qv['m']) > 9) {1326 if ( strlen($qv['m']) > 9 ) { 1327 1327 $this->is_time = true; 1328 } else if ( strlen($qv['m']) > 7) {1328 } else if ( strlen($qv['m']) > 7 ) { 1329 1329 $this->is_day = true; 1330 } else if ( strlen($qv['m']) > 5) {1330 } else if ( strlen($qv['m']) > 5 ) { 1331 1331 $this->is_month = true; 1332 1332 } else { … … 1335 1335 } 1336 1336 1337 if ( '' != $qv['w']) {1337 if ( '' != $qv['w'] ) { 1338 1338 $this->is_date = true; 1339 1339 } … … 1342 1342 $this->is_category = false; 1343 1343 } else { 1344 if ( strpos($qv['cat'], '-') !== false) {1344 if ( strpos($qv['cat'], '-') !== false ) { 1345 1345 $this->is_category = false; 1346 1346 } else { … … 1455 1455 1456 1456 // if we're previewing inside the write screen 1457 if ( '' != $qv['preview'])1457 if ( '' != $qv['preview'] ) 1458 1458 $this->is_preview = true; 1459 1459 … … 1511 1511 } 1512 1512 1513 if ( !empty($qv['post_type']) ) 1514 if (is_array($qv['post_type']))1513 if ( !empty($qv['post_type']) ) { 1514 if ( is_array($qv['post_type']) ) 1515 1515 $qv['post_type'] = array_map('sanitize_user', $qv['post_type'], array(true)); 1516 1516 else … … 1527 1527 // Done correcting is_* for page_on_front and page_for_posts 1528 1528 1529 if ( '404' == $qv['error'])1529 if ( '404' == $qv['error'] ) 1530 1530 $this->set_404(); 1531 1531 … … 1546 1546 $this->is_404 = true; 1547 1547 1548 $this->is_feed = $is_feed;1548 //$this->is_feed = $is_feed; 1549 1549 } 1550 1550 … … 1559 1559 */ 1560 1560 function get($query_var) { 1561 if ( isset($this->query_vars[$query_var])) {1561 if ( isset($this->query_vars[$query_var]) ) 1562 1562 return $this->query_vars[$query_var]; 1563 }1564 1563 1565 1564 return ''; … … 1640 1639 $q['posts_per_page'] = $q['posts_per_archive_page']; 1641 1640 if ( !isset($q['nopaging']) ) { 1642 if ( $q['posts_per_page'] == -1) {1641 if ( $q['posts_per_page'] == -1 ) { 1643 1642 $q['nopaging'] = true; 1644 1643 } else { … … 1665 1664 } 1666 1665 1667 if ( isset($q['page'])) {1666 if ( isset($q['page']) ) { 1668 1667 $q['page'] = trim($q['page'], '/'); 1669 1668 $q['page'] = absint($q['page']); … … 1680 1679 $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); 1681 1680 $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4); 1682 if ( strlen($q['m'])>5)1681 if ( strlen($q['m']) > 5 ) 1683 1682 $where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2); 1684 if ( strlen($q['m'])>7)1683 if ( strlen($q['m']) > 7 ) 1685 1684 $where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2); 1686 if ( strlen($q['m'])>9)1685 if ( strlen($q['m']) > 9 ) 1687 1686 $where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2); 1688 if ( strlen($q['m'])>11)1687 if ( strlen($q['m']) > 11 ) 1689 1688 $where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2); 1690 if ( strlen($q['m'])>13)1689 if ( strlen($q['m']) > 13 ) 1691 1690 $where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2); 1692 1691 } … … 1717 1716 continue; 1718 1717 1719 if ( ! $ptype_obj->hierarchical || strpos($q[ $ptype_obj->query_var ], '/') === false ) {1718 if ( ! $ptype_obj->hierarchical || strpos($q[ $ptype_obj->query_var ], '/') === false ) { 1720 1719 // Non-hierarchical post_types & parent-level-hierarchical post_types can directly use 'name' 1721 1720 $q['name'] = $q[ $ptype_obj->query_var ]; … … 1774 1773 } 1775 1774 } 1776 } elseif ( '' != $q['attachment']) {1775 } elseif ( '' != $q['attachment'] ) { 1777 1776 $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment']))); 1778 1777 $attach_paths = '/' . trim($q['attachment'], '/'); … … 1825 1824 $n = !empty($q['exact']) ? '' : '%'; 1826 1825 $searchand = ''; 1827 foreach( (array) $q['search_terms'] as $term ) {1826 foreach( (array) $q['search_terms'] as $term ) { 1828 1827 $term = addslashes_gpc($term); 1829 1828 $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))"; … … 1969 1968 $intersections = array('category__and' => 'category', 'tag__and' => 'post_tag', 'tag_slug__and' => 'post_tag', 'tag__in' => 'post_tag', 'tag_slug__in' => 'post_tag'); 1970 1969 $tagin = array('tag__in', 'tag_slug__in'); // These are used to make some exceptions below 1971 foreach ( $intersections as $item => $taxonomy) {1970 foreach ( $intersections as $item => $taxonomy ) { 1972 1971 if ( empty($q[$item]) ) continue; 1973 1972 if ( in_array($item, $tagin) && empty($q['cat']) ) continue; // We should already have what we need if categories aren't being used … … 2045 2044 2046 2045 if ( empty($q['author']) || ($q['author'] == '0') ) { 2047 $whichauthor ='';2046 $whichauthor = ''; 2048 2047 } else { 2049 $q['author'] = ''.urldecode($q['author']).'';2048 $q['author'] = (string)urldecode($q['author']); 2050 2049 $q['author'] = addslashes_gpc($q['author']); 2051 if ( strpos($q['author'], '-') !== false) {2050 if ( strpos($q['author'], '-') !== false ) { 2052 2051 $eq = '!='; 2053 2052 $andor = 'AND'; 2054 2053 $q['author'] = explode('-', $q['author']); 2055 $q['author'] = '' .absint($q['author'][1]);2054 $q['author'] = (string)absint($q['author'][1]); 2056 2055 } else { 2057 2056 $eq = '='; … … 2059 2058 } 2060 2059 $author_array = preg_split('/[,\s]+/', $q['author']); 2061 $ whichauthor .= " AND ($wpdb->posts.post_author ".$eq.' '.absint($author_array[0]);2062 for ($i = 1; $i < (count($author_array)); $i = $i + 1) {2063 $ whichauthor .= ' '.$andor." $wpdb->posts.post_author ".$eq.' '.absint($author_array[$i]);2064 }2065 $whichauthor .= ')';2060 $_author_array = array(); 2061 foreach ( $author_array as $key => $_author ) 2062 $_author_array[] = "$wpdb->posts.post_author " . $eq . ' ' . absint($_author); 2063 $whichauthor .= ' AND (' . implode(" $andor ", $_author_array) . ')'; 2064 unset($author_array, $_author_array); 2066 2065 } 2067 2066 2068 2067 // Author stuff for nice URLs 2069 2068 2070 if ( '' != $q['author_name']) {2071 if ( strpos($q['author_name'], '/') !== false) {2072 $q['author_name'] = explode('/', $q['author_name']);2073 if ( $q['author_name'][count($q['author_name'])-1]) {2074 $q['author_name'] = $q['author_name'][count($q['author_name'])-1]; #no trailing slash2069 if ( '' != $q['author_name'] ) { 2070 if ( strpos($q['author_name'], '/') !== false ) { 2071 $q['author_name'] = explode('/', $q['author_name']); 2072 if ( $q['author_name'][ count($q['author_name'])-1 ] ) { 2073 $q['author_name'] = $q['author_name'][count($q['author_name'])-1]; #no trailing slash 2075 2074 } else { 2076 $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; #there was a trailling slash2075 $q['author_name'] = $q['author_name'][count($q['author_name'])-2]; #there was a trailling slash 2077 2076 } 2078 2077 } … … 2081 2080 if ( $q['author'] ) 2082 2081 $q['author'] = $q['author']->ID; 2083 $whichauthor .= " AND ($wpdb->posts.post_author = " .absint($q['author']).')';2082 $whichauthor .= " AND ($wpdb->posts.post_author = " . absint($q['author']) . ')'; 2084 2083 } 2085 2084 … … 2089 2088 $whichmimetype = wp_post_mime_type_where($q['post_mime_type']); 2090 2089 2091 $where .= $search .$whichcat.$whichauthor.$whichmimetype;2090 $where .= $search . $whichcat . $whichauthor . $whichmimetype; 2092 2091 2093 2092 if ( empty($q['order']) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC')) ) … … 2096 2095 // Order by 2097 2096 if ( empty($q['orderby']) ) { 2098 $q['orderby'] = "$wpdb->posts.post_date " .$q['order'];2097 $q['orderby'] = "$wpdb->posts.post_date " . $q['order']; 2099 2098 } elseif ( 'none' == $q['orderby'] ) { 2100 2099 $q['orderby'] = ''; … … 2117 2116 continue; 2118 2117 2119 switch ( $orderby) {2118 switch ( $orderby ) { 2120 2119 case 'menu_order': 2121 2120 break; … … 2175 2174 $where .= " AND $wpdb->posts.post_type = 'attachment'"; 2176 2175 $post_type_object = get_post_type_object ( 'attachment' ); 2177 } elseif ( $this->is_page) {2176 } elseif ( $this->is_page ) { 2178 2177 $where .= " AND $wpdb->posts.post_type = 'page'"; 2179 2178 $post_type_object = get_post_type_object ( 'page' ); … … 2299 2298 $pgstrt = ''; 2300 2299 $pgstrt = ($page - 1) * $q['posts_per_page'] . ', '; 2301 $limits = 'LIMIT ' .$pgstrt.$q['posts_per_page'];2300 $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; 2302 2301 } else { // we're ignoring $page and using 'offset' 2303 2302 $q['offset'] = absint($q['offset']); … … 2334 2333 $post_ids = array(); 2335 2334 2336 foreach ( $this->comments as $comment)2335 foreach ( $this->comments as $comment ) 2337 2336 $post_ids[] = (int) $comment->comment_post_ID; 2338 2337 … … 2422 2421 if ( $post_status_obj->protected ) { 2423 2422 // User must have edit permissions on the draft to preview. 2424 if ( ! current_user_can($edit_cap, $this->posts[0]->ID)) {2423 if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) { 2425 2424 $this->posts = array(); 2426 2425 } else { 2427 2426 $this->is_preview = true; 2428 if ( 'future' != $status)2427 if ( 'future' != $status ) 2429 2428 $this->posts[0]->post_date = current_time('mysql'); 2430 2429 } … … 2498 2497 2499 2498 // Sanitize before caching so it'll only get done once 2500 for ( $i = 0; $i < $this->post_count; $i++) {2499 for ( $i = 0; $i < $this->post_count; $i++ ) { 2501 2500 $this->posts[$i] = sanitize_post($this->posts[$i], 'raw'); 2502 2501 } … … 2505 2504 update_post_caches($this->posts, $post_type); 2506 2505 2507 if ( $this->post_count > 0) {2506 if ( $this->post_count > 0 ) { 2508 2507 $this->post = $this->posts[0]; 2509 2508 } … … 2562 2561 */ 2563 2562 function have_posts() { 2564 if ( $this->current_post + 1 < $this->post_count) {2563 if ( $this->current_post + 1 < $this->post_count ) { 2565 2564 return true; 2566 } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0) {2565 } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) { 2567 2566 do_action_ref_array('loop_end', array(&$this)); 2568 2567 // Do some cleaning up after the loop … … 2582 2581 function rewind_posts() { 2583 2582 $this->current_post = -1; 2584 if ( $this->post_count > 0) {2583 if ( $this->post_count > 0 ) { 2585 2584 $this->post = $this->posts[0]; 2586 2585 } … … 2615 2614 $comment = $this->next_comment(); 2616 2615 2617 if ( $this->current_comment == 0) {2616 if ( $this->current_comment == 0 ) { 2618 2617 do_action('comment_loop_start'); 2619 2618 } … … 2631 2630 */ 2632 2631 function have_comments() { 2633 if ( $this->current_comment + 1 < $this->comment_count) {2632 if ( $this->current_comment + 1 < $this->comment_count ) { 2634 2633 return true; 2635 } elseif ( $this->current_comment + 1 == $this->comment_count) {2634 } elseif ( $this->current_comment + 1 == $this->comment_count ) { 2636 2635 $this->rewind_comments(); 2637 2636 } … … 2648 2647 function rewind_comments() { 2649 2648 $this->current_comment = -1; 2650 if ( $this->comment_count > 0) {2649 if ( $this->comment_count > 0 ) { 2651 2650 $this->comment = $this->comments[0]; 2652 2651 } … … 2739 2738 $this->get_queried_object(); 2740 2739 2741 if ( isset($this->queried_object_id)) {2740 if ( isset($this->queried_object_id) ) { 2742 2741 return $this->queried_object_id; 2743 2742 } … … 2758 2757 */ 2759 2758 function WP_Query($query = '') { 2760 if ( ! empty($query)) {2759 if ( ! empty($query) ) { 2761 2760 $this->query($query); 2762 2761 }
Note: See TracChangeset
for help on using the changeset viewer.