| @@ 178-239 (lines=62) @@ | ||
| 175 | return build_query( array( 'value' => urlencode( $post->$column ), 'id' => $post->ID ) ); |
|
| 176 | } |
|
| 177 | ||
| 178 | function handle_where_for_page_handle( $where ) { |
|
| 179 | global $wpdb; |
|
| 180 | ||
| 181 | $column = $this->performed_query['orderby']; |
|
| 182 | if ( ! $column ) { |
|
| 183 | $column = 'date'; |
|
| 184 | } |
|
| 185 | $order = $this->performed_query['order']; |
|
| 186 | if ( ! $order ) { |
|
| 187 | $order = 'DESC'; |
|
| 188 | } |
|
| 189 | ||
| 190 | if ( ! in_array( $column, array( 'ID', 'title', 'date', 'modified', 'comment_count' ) ) ) { |
|
| 191 | return $where; |
|
| 192 | } |
|
| 193 | ||
| 194 | if ( ! in_array( $order, array( 'DESC', 'ASC' ) ) ) { |
|
| 195 | return $where; |
|
| 196 | } |
|
| 197 | ||
| 198 | $db_column = ''; |
|
| 199 | $db_value = ''; |
|
| 200 | switch( $column ) { |
|
| 201 | case 'ID': |
|
| 202 | $db_column = 'ID'; |
|
| 203 | $db_value = '%d'; |
|
| 204 | break; |
|
| 205 | case 'title': |
|
| 206 | $db_column = 'post_title'; |
|
| 207 | $db_value = '%s'; |
|
| 208 | break; |
|
| 209 | case 'date': |
|
| 210 | $db_column = 'post_date'; |
|
| 211 | $db_value = 'CAST( %s as DATETIME )'; |
|
| 212 | break; |
|
| 213 | case 'modified': |
|
| 214 | $db_column = 'post_modified'; |
|
| 215 | $db_value = 'CAST( %s as DATETIME )'; |
|
| 216 | break; |
|
| 217 | case 'comment_count': |
|
| 218 | $db_column = 'comment_count'; |
|
| 219 | $db_value = '%d'; |
|
| 220 | break; |
|
| 221 | } |
|
| 222 | ||
| 223 | if ( 'DESC'=== $order ) { |
|
| 224 | $db_order = '<'; |
|
| 225 | } else { |
|
| 226 | $db_order = '>'; |
|
| 227 | } |
|
| 228 | ||
| 229 | // Add a clause that limits the results to items beyond the passed item, or equivalent to the passed item |
|
| 230 | // but with an ID beyond the passed item. When we're ordering by the ID already, we only ask for items |
|
| 231 | // beyond the passed item. |
|
| 232 | $where .= $wpdb->prepare( " AND ( ( `$wpdb->posts`.`$db_column` $db_order $db_value ) ", $this->page_handle['value'] ); |
|
| 233 | if ( $db_column !== 'ID' ) { |
|
| 234 | $where .= $wpdb->prepare( "OR ( `$wpdb->posts`.`$db_column` = $db_value AND `$wpdb->posts`.ID $db_order %d )", $this->page_handle['value'], $this->page_handle['id'] ); |
|
| 235 | } |
|
| 236 | $where .= ' )'; |
|
| 237 | ||
| 238 | return $where; |
|
| 239 | } |
|
| 240 | ||
| 241 | function handle_date_range( $where ) { |
|
| 242 | global $wpdb; |
|
| @@ 475-536 (lines=62) @@ | ||
| 472 | return $this->_build_date_range_query( 'post_modified_gmt', $this->modified_range, $where ); |
|
| 473 | } |
|
| 474 | ||
| 475 | function handle_where_for_page_handle( $where ) { |
|
| 476 | global $wpdb; |
|
| 477 | ||
| 478 | $column = $this->performed_query['orderby']; |
|
| 479 | if ( ! $column ) { |
|
| 480 | $column = 'date'; |
|
| 481 | } |
|
| 482 | $order = $this->performed_query['order']; |
|
| 483 | if ( ! $order ) { |
|
| 484 | $order = 'DESC'; |
|
| 485 | } |
|
| 486 | ||
| 487 | if ( ! in_array( $column, array( 'ID', 'title', 'date', 'modified', 'comment_count' ) ) ) { |
|
| 488 | return $where; |
|
| 489 | } |
|
| 490 | ||
| 491 | if ( ! in_array( $order, array( 'DESC', 'ASC' ) ) ) { |
|
| 492 | return $where; |
|
| 493 | } |
|
| 494 | ||
| 495 | $db_column = ''; |
|
| 496 | $db_value = ''; |
|
| 497 | switch ( $column ) { |
|
| 498 | case 'ID': |
|
| 499 | $db_column = 'ID'; |
|
| 500 | $db_value = '%d'; |
|
| 501 | break; |
|
| 502 | case 'title': |
|
| 503 | $db_column = 'post_title'; |
|
| 504 | $db_value = '%s'; |
|
| 505 | break; |
|
| 506 | case 'date': |
|
| 507 | $db_column = 'post_date'; |
|
| 508 | $db_value = 'CAST( %s as DATETIME )'; |
|
| 509 | break; |
|
| 510 | case 'modified': |
|
| 511 | $db_column = 'post_modified'; |
|
| 512 | $db_value = 'CAST( %s as DATETIME )'; |
|
| 513 | break; |
|
| 514 | case 'comment_count': |
|
| 515 | $db_column = 'comment_count'; |
|
| 516 | $db_value = '%d'; |
|
| 517 | break; |
|
| 518 | } |
|
| 519 | ||
| 520 | if ( 'DESC' === $order ) { |
|
| 521 | $db_order = '<'; |
|
| 522 | } else { |
|
| 523 | $db_order = '>'; |
|
| 524 | } |
|
| 525 | ||
| 526 | // Add a clause that limits the results to items beyond the passed item, or equivalent to the passed item |
|
| 527 | // but with an ID beyond the passed item. When we're ordering by the ID already, we only ask for items |
|
| 528 | // beyond the passed item. |
|
| 529 | $where .= $wpdb->prepare( " AND ( ( `$wpdb->posts`.`$db_column` $db_order $db_value ) ", $this->page_handle['value'] ); |
|
| 530 | if ( $db_column !== 'ID' ) { |
|
| 531 | $where .= $wpdb->prepare( "OR ( `$wpdb->posts`.`$db_column` = $db_value AND `$wpdb->posts`.ID $db_order %d )", $this->page_handle['value'], $this->page_handle['id'] ); |
|
| 532 | } |
|
| 533 | $where .= ' )'; |
|
| 534 | ||
| 535 | return $where; |
|
| 536 | } |
|
| 537 | ||
| 538 | function handle_orderby_for_page_handle( $orderby ) { |
|
| 539 | global $wpdb; |
|