Ticket #3948: sanitized_query.php.diff

File sanitized_query.php.diff, 10.9 KB (added by g30rg3x, 5 years ago)
  • wp-includes/query.php

     
    377377                if ( !empty($query) || !isset($this->query) ) { 
    378378                        $this->init(); 
    379379                        if ( is_array($query) ) 
    380                                 $qv = & $query; 
     380                                $this->query_vars = $query; 
    381381                        else 
    382                                 parse_str($query, $qv); 
     382                                parse_str($query, $this->query_vars); 
    383383                        $this->query = $query; 
    384                         $this->query_vars = $qv; 
    385                 } 
     384                        } 
     385                         
     386                        $this->query_vars = $this->fill_query_vars($this->query_vars);  
     387                        $qv = &$this->query_vars; 
    386388                 
    387                 $qv = $this->fill_query_vars($qv); 
    388                  
    389389                if ( ! empty($qv['robots']) ) { 
    390390                        $this->is_robots = true; 
    391391                        return; 
     
    398398                        } 
    399399                        return; 
    400400                } 
    401  
     401                 
     402                $qv['p'] =  (int) $qv['p'];  
     403          $qv['page_id'] =  (int) $qv['page_id'];  
     404          $qv['year'] = (int) $qv['year'];  
     405          $qv['monthnum'] = (int) $qv['monthnum'];  
     406          $qv['day'] = (int) $qv['day'];  
     407          $qv['w'] = (int) $qv['w']; 
    402408                $qv['m'] =  (int) $qv['m']; 
    403                 $qv['p'] =  (int) $qv['p']; 
     409                if ( '' != $qv['hour'] ) $qv['hour'] = (int) $qv['hour'];  
     410          if ( '' != $qv['minute'] ) $qv['minute'] = (int) $qv['minute'];  
     411          if ( '' != $qv['second'] ) $qv['second'] = (int) $qv['second']; 
    404412 
    405413                // Compat.  Map subpost to attachment. 
    406414                if ( '' != $qv['subpost'] ) 
     
    408416                if ( '' != $qv['subpost_id'] ) 
    409417                        $qv['attachment_id'] = $qv['subpost_id']; 
    410418 
    411                 if ( ('' != $qv['attachment']) || (int) $qv['attachment_id'] ) { 
     419                $qv['attachment_id'] = (int) $qv['attachment_id']; 
     420                         
     421          if ( ('' != $qv['attachment']) || !empty($qv['attachment_id']) ) { 
    412422                        $this->is_single = true; 
    413423                        $this->is_attachment = true; 
    414                 } elseif ('' != $qv['name']) { 
     424                } elseif ( '' != $qv['name'] ) {  
    415425                        $this->is_single = true; 
    416426                } elseif ( $qv['p'] ) { 
    417427                        $this->is_single = true; 
    418                 } elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) { 
     428                } elseif ( ('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day']) ) 
     429                { 
    419430                        // If year, month, day, hour, minute, and second are set, a single 
    420431                        // post is being queried. 
    421432                        $this->is_single = true; 
    422                 } elseif ('' != $qv['static'] || '' != $qv['pagename'] || (int) $qv['page_id']) { 
     433                } elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) {  
    423434                        $this->is_page = true; 
    424435                        $this->is_single = false; 
    425                 } elseif (!empty($qv['s'])) { 
     436                } elseif ( !empty($qv['s']) ) { 
    426437                        $this->is_search = true; 
    427438                } else { 
    428439                // Look for archive queries.  Dates, categories, authors. 
    429440 
    430                         if ( (int) $qv['second']) { 
     441                        if ( '' != $qv['second'] ) {  
    431442                                $this->is_time = true; 
    432443                                $this->is_date = true; 
    433444                        } 
    434445 
    435                         if ( (int) $qv['minute']) { 
     446                        if ( '' != $qv['minute'] ) {  
    436447                                $this->is_time = true; 
    437448                                $this->is_date = true; 
    438449                        } 
    439450 
    440                         if ( (int) $qv['hour']) { 
     451                        if ( '' != $qv['hour'] ) {  
    441452                                $this->is_time = true; 
    442453                                $this->is_date = true; 
    443454                        } 
    444455 
    445                         if ( (int) $qv['day']) { 
     456                        if ( $qv['day'] ) {  
    446457                                if (! $this->is_date) { 
    447458                                        $this->is_day = true; 
    448459                                        $this->is_date = true; 
    449460                                } 
    450461                        } 
    451462 
    452                         if ( (int)  $qv['monthnum']) { 
     463                        if ( $qv['monthnum'] ) {  
    453464                                if (! $this->is_date) { 
    454465                                        $this->is_month = true; 
    455466                                        $this->is_date = true; 
    456467                                } 
    457468                        } 
    458469 
    459                         if ( (int)  $qv['year']) { 
     470                        if ( $qv['year'] ) {  
    460471                                if (! $this->is_date) { 
    461472                                        $this->is_year = true; 
    462473                                        $this->is_date = true; 
    463474                                } 
    464475                        } 
    465476 
    466                         if ( (int)  $qv['m']) { 
     477                        if ( $qv['m'] ) {  
    467478                                $this->is_date = true; 
    468479                                if (strlen($qv['m']) > 9) { 
    469480                                        $this->is_time = true; 
     
    480491                                $this->is_date = true; 
    481492                        } 
    482493 
    483                         if (empty($qv['cat']) || ($qv['cat'] == '0')) { 
     494                        if ( empty($qv['cat']) || ($qv['cat'] == '0') ) {  
    484495                                $this->is_category = false; 
    485496                        } else { 
    486497                                if (stristr($qv['cat'],'-')) { 
     
    490501                                } 
    491502                        } 
    492503 
    493                         if ('' != $qv['category_name']) { 
     504                        if ( '' != $qv['category_name'] ) {  
    494505                                $this->is_category = true; 
    495506                        } 
    496507 
    497                         if ((empty($qv['author'])) || ($qv['author'] == '0')) { 
     508                        if ( empty($qv['author']) || ($qv['author'] == '0') ) { 
    498509                                $this->is_author = false; 
    499510                        } else { 
    500511                                $this->is_author = true; 
    501512                        } 
    502513 
    503                         if ('' != $qv['author_name']) { 
     514                        if ( '' != $qv['author_name'] ) {  
    504515                                $this->is_author = true; 
    505516                        } 
    506517 
    507                         if ( ($this->is_date || $this->is_author || $this->is_category)) { 
     518                        if ( ($this->is_date || $this->is_author || $this->is_category) ) 
    508519                                $this->is_archive = true; 
    509520                        } 
    510                 } 
    511  
    512                 if ('' != $qv['feed']) { 
     521                         
     522                if ( '' != $qv['feed'] ) 
    513523                        $this->is_feed = true; 
    514                 } 
    515  
    516                 if ('' != $qv['tb']) { 
     524                 
     525                if ( '' != $qv['tb'] )  
    517526                        $this->is_trackback = true; 
    518                 } 
    519  
    520                 if ('' != $qv['paged']) { 
     527                         
     528                if ( '' != $qv['paged'] )  
    521529                        $this->is_paged = true; 
    522                 } 
    523530 
    524                 if ('' != $qv['comments_popup']) { 
     531                if ( '' != $qv['comments_popup'] ) 
    525532                        $this->is_comments_popup = true; 
    526                 } 
    527533 
    528534                //if we're previewing inside the write screen 
    529                 if ('' != $qv['preview']) { 
     535                if ('' != $qv['preview'])  
    530536                        $this->is_preview = true; 
    531                 } 
    532537 
    533                 if (strstr($_SERVER['PHP_SELF'], 'wp-admin/')) { 
     538                if ( strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )  
    534539                        $this->is_admin = true; 
    535                 } 
    536540 
    537541                if ( $this->is_single || $this->is_page || $this->is_attachment ) 
    538542                        $this->is_singular = true; 
    539543 
    540                 if ( ! ($this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) { 
     544                if ( ! ($this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) 
    541545                        $this->is_home = true; 
    542                 } 
    543546 
    544                 if ( !empty($query) ) { 
     547                if ( !empty($query) ) 
    545548                        do_action_ref_array('parse_query', array(&$this)); 
    546                 } 
    547549        } 
    548550 
    549551        function set_404() { 
     
    634636                $wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"; 
    635637 
    636638                // If a month is specified in the querystring, load that month 
    637                 if ( (int) $q['m'] ) { 
     639                if ( $q['m'] ) {  
    638640                        $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); 
    639641                        $where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4); 
    640642                        if (strlen($q['m'])>5) 
     
    649651                                $where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2); 
    650652                } 
    651653 
    652                 if ( (int) $q['hour'] ) { 
    653                         $q['hour'] = '' . intval($q['hour']); 
     654                if ( '' != $q['hour'] ) 
    654655                        $where .= " AND HOUR(post_date)='" . $q['hour'] . "'"; 
    655                 } 
    656656 
    657                 if ( (int) $q['minute'] ) { 
    658                         $q['minute'] = '' . intval($q['minute']); 
     657                if ( '' != $q['minute'] ) 
    659658                        $where .= " AND MINUTE(post_date)='" . $q['minute'] . "'"; 
    660                 } 
    661659 
    662                 if ( (int) $q['second'] ) { 
    663                         $q['second'] = '' . intval($q['second']); 
     660                if ( '' != $q['second'] ) 
    664661                        $where .= " AND SECOND(post_date)='" . $q['second'] . "'"; 
    665                 } 
    666662 
    667                 if ( (int) $q['year'] ) { 
    668                         $q['year'] = '' . intval($q['year']); 
     663                if ( $q['year'] ) 
    669664                        $where .= " AND YEAR(post_date)='" . $q['year'] . "'"; 
    670                 } 
    671665 
    672                 if ( (int) $q['monthnum'] ) { 
    673                         $q['monthnum'] = '' . intval($q['monthnum']); 
     666                if ( $q['monthnum'] ) 
    674667                        $where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'"; 
    675                 } 
    676668 
    677                 if ( (int) $q['day'] ) { 
    678                         $q['day'] = '' . intval($q['day']); 
     669                if ( $q['day'] ) 
    679670                        $where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'"; 
    680                 } 
    681671 
    682                 // Compat.  Map subpost to attachment. 
    683                 if ( '' != $q['subpost'] ) 
    684                         $q['attachment'] = $q['subpost']; 
    685                 if ( '' != $q['subpost_id'] ) 
    686                         $q['attachment_id'] = $q['subpost_id']; 
    687672 
    688673                if ('' != $q['name']) { 
    689674                        $q['name'] = sanitize_title($q['name']); 
     
    715700                        $where .= " AND post_name = '" . $q['attachment'] . "'"; 
    716701                } 
    717702 
    718                 if ( (int) $q['w'] ) { 
    719                         $q['w'] = ''.intval($q['w']); 
     703                if ( $q['w'] ) 
    720704                        $where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'"; 
    721                 } 
    722705 
    723706                if ( intval($q['comments_popup']) ) 
    724707                        $q['p'] = intval($q['comments_popup']); 
    725708 
    726                 // If a attachment is requested by number, let it supercede any post number. 
    727                 if ( ($q['attachment_id'] != '') && (intval($q['attachment_id']) != 0) ) 
    728                         $q['p'] = (int) $q['attachment_id']; 
     709                // If an attachment is requested by number, let it supercede any post number. 
     710                if ( $q['attachment_id'] )  
     711                  $q['p'] = $q['attachment_id']; 
    729712 
    730713                // If a post number is specified, load that post 
    731                 if (($q['p'] != '') && intval($q['p']) != 0) { 
    732                         $q['p'] =  (int) $q['p']; 
     714                if ( $q['p'] ) 
    733715                        $where = ' AND ID = ' . $q['p']; 
    734                 } 
    735716 
    736                 if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) { 
    737                         $q['page_id'] = intval($q['page_id']); 
     717                if ( $q['page_id'] ) {  
    738718                        if  ( ('page' == get_option('show_on_front') ) && ( $q['page_id'] == get_option('page_for_posts') ) ) { 
    739719                                $this->is_singular = false; 
    740720                                $this->is_page = false; 
     
    742722                                $this->is_posts_page = true; 
    743723                        } else { 
    744724                                $q['p'] = $q['page_id']; 
    745                                 $where = ' AND ID = '.$q['page_id']; 
     725                                $where = ' AND ID = ' . $q['page_id']; 
    746726                        } 
    747727                } 
    748728 
    749729                // If a search pattern is specified, load the posts that match 
    750                 if (!empty($q['s'])) { 
     730                if ( !empty($q['s']) ) { 
    751731                        // added slashes screw with quote grouping when done early, so done later 
    752732                        $q['s'] = stripslashes($q['s']); 
    753733                        if ($q['sentence']) { 
     
    774754 
    775755                // Category stuff 
    776756 
    777                 if ((empty($q['cat'])) || ($q['cat'] == '0') || 
     757                if ( empty($q['cat']) || ($q['cat'] == '0') || 
    778758                                // Bypass cat checks if fetching specific posts 
    779                                 ( $this->is_single || $this->is_page )) { 
    780                         $whichcat=''; 
     759                                $this->is_singular ) { 
     760                                $whichcat = ''; 
    781761                } else { 
    782762                        $q['cat'] = ''.urldecode($q['cat']).''; 
    783763                        $q['cat'] = addslashes_gpc($q['cat']); 
     
    814794                } 
    815795 
    816796                // Category stuff for nice URLs 
    817                 if ('' != $q['category_name']) { 
     797                if ( '' != $q['category_name'] ) {  
    818798                        $reqcat = get_category_by_path($q['category_name']); 
    819799                        $q['category_name'] = str_replace('%2F', '/', urlencode(urldecode($q['category_name']))); 
    820800                        $cat_paths = '/' . trim($q['category_name'], '/'); 
     
    849829 
    850830                // Author/user stuff 
    851831 
    852                 if ((empty($q['author'])) || ($q['author'] == '0')) { 
     832                if ( empty($q['author']) || ($q['author'] == '0') ) { 
    853833                        $whichauthor=''; 
    854834                } else { 
    855835                        $q['author'] = ''.urldecode($q['author']).''; 
     
    889869 
    890870                $where .= $search.$whichcat.$whichauthor; 
    891871 
    892                 if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) { 
     872                if ( empty($q['order']) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC')) ) 
    893873                        $q['order']='DESC'; 
    894                 } 
    895874 
    896875                // Order by 
    897                 if (empty($q['orderby'])) { 
     876                if ( empty($q['orderby']) ) { 
    898877                        $q['orderby'] = 'post_date '.$q['order']; 
    899878                } else { 
    900879                        // Used to filter values 
     
    950929                $join = apply_filters('posts_join', $join); 
    951930 
    952931                // Paging 
    953                 if (empty($q['nopaging']) && !$this->is_singular) { 
     932                if ( empty($q['nopaging']) && !$this->is_singular ) { 
    954933                        $page = abs(intval($q['paged'])); 
    955934                        if (empty($page)) { 
    956935                                $page = 1;