Make WordPress Core

Changeset 3564


Ignore:
Timestamp:
02/21/2006 08:39:58 AM (19 years ago)
Author:
ryan
Message:

Allow queries by post type. Enable paging in Manage->Pages

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r3563 r3564  
    644644}
    645645
    646 function page_rows($parent = 0, $level = 0, $pages = 0) {
     646function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) {
    647647    global $wpdb, $class, $post;
     648
    648649    if (!$pages)
    649650        $pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' ORDER BY menu_order");
    650651
    651     if ($pages) {
    652         foreach ($pages as $post) {
    653             start_wp();
    654             if ($post->post_parent == $parent) {
    655                 $post->post_title = wp_specialchars($post->post_title);
    656                 $pad = str_repeat('— ', $level);
    657                 $id = $post->ID;
    658                 $class = ('alternate' == $class) ? '' : 'alternate';
     652    if (! $pages)
     653        return false;
     654
     655    foreach ($pages as $post) {
     656        setup_postdata($post);
     657        if ( $hierarchy && ($post->post_parent != $parent) )
     658            continue;
     659
     660        $post->post_title = wp_specialchars($post->post_title);
     661        $pad = str_repeat('— ', $level);
     662        $id = $post->ID;
     663        $class = ('alternate' == $class) ? '' : 'alternate';
    659664?>
    660665  <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
     
    671676
    672677<?php
    673 
    674                 page_rows($id, $level +1, $pages);
    675             }
    676         }
    677     } else {
    678         return false;
     678        if ( $hierarchy) page_rows($id, $level + 1, $pages);
    679679    }
    680680}
  • trunk/wp-admin/edit-pages.php

    r3563 r3564  
    2020
    2121<?php
     22wp('post_type=page&orderby=menu_order&what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1');
    2223
    23 $show_post_type = 'page';
    24 
    25 if ( isset($_GET['s']) )
    26     wp();
     24if ( $_GET['s'] )
     25    $all = false;
    2726else
    28     $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page'");
     27    $all = true;
    2928
    3029if ($posts) {
     
    4140  </tr>
    4241<?php
    43 if ( isset($_GET['s']) ) {
    44 foreach ( $posts as $post ) :
    45     $class = ('alternate' != $class) ? 'alternate' : ''; ?>
    46   <tr id='page-<?php echo $post->ID; ?>' class='<?php echo $class; ?>'>
    47     <th scope="row"><?php echo $post->ID; ?></th>
    48     <td>
    49       <?php echo $pad; ?><?php the_title() ?>
    50     </td>
    51     <td><?php the_author() ?></td>
    52     <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
    53     <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
    54     <td><?php if ( current_user_can('edit_page', $post->ID) ) { echo "<a href='page.php?action=edit&amp;post=$post->ID' class='edit'>" . __('Edit') . "</a>"; } ?></td>
    55     <td><?php if ( current_user_can('delete_page', $post->ID) ) { echo "<a href='page.php?action=delete&amp;post=$post->ID' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('','',0), 1)) . "' );\">" . __('Delete') . "</a>"; } ?></td>
    56   </tr>
    57 <?php
    58 endforeach;
    59 } else {
    60     page_rows();
    61 }
     42page_rows(0, 0, $posts, $all);
    6243?>
    6344</table>
    6445
    6546<div id="ajax-response"></div>
     47
     48<div class="navigation">
     49<div class="alignleft"><?php next_posts_link(__('&laquo; Previous Entries')) ?></div>
     50<div class="alignright"><?php previous_posts_link(__('Next Entries &raquo;')) ?></div>
     51</div>
    6652
    6753<?php
  • trunk/wp-admin/edit.php

    r3528 r3564  
    5656<h2>
    5757<?php
    58 $what_to_show = 'posts';
    59 $posts_per_page = 15;
    60 $posts_per_archive_page = -1;
    61 
    62 wp();
     58
     59wp('what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1');
    6360
    6461if ( is_month() ) {
  • trunk/wp-includes/classes.php

    r3528 r3564  
    115115        } elseif (!empty($qv['s'])) {
    116116            $this->is_search = true;
    117             switch ($qv['show_post_type']) {
    118             case 'page' :
    119                 $this->is_page = true;
    120                 break;
    121             case 'attachment' :
    122                 $this->is_attachment = true;
    123                 break;
    124             }
    125117        } else {
    126118        // Look for archive queries.  Dates, categories, authors.
     
    206198                $this->is_archive = true;
    207199            }
    208 
    209             if ( 'attachment' == $qv['show_post_type'] ) {
    210                 $this->is_attachment = true;
    211             }
    212200        }
    213201
     
    281269        $join = '';
    282270
     271        if ( !isset($q['post_type']) )
     272            $q['post_type'] = 'post';
     273        $post_type = $q['post_type'];
    283274        if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
    284275            $q['posts_per_page'] = get_settings('posts_per_page');
     
    551542        // Order by
    552543        if (empty($q['orderby'])) {
    553             $q['orderby']='date '.$q['order'];
     544            $q['orderby'] = 'post_date '.$q['order'];
    554545        } else {
    555546            // Used to filter values
    556             $allowed_keys = array('author', 'date', 'category', 'title', 'modified');
     547            $allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order');
    557548            $q['orderby'] = urldecode($q['orderby']);
    558549            $q['orderby'] = addslashes_gpc($q['orderby']);
    559550            $orderby_array = explode(' ',$q['orderby']);
    560             if (!in_array($orderby_array[0],$allowed_keys)) {
    561                 $orderby_array[0] = 'date';
    562             }
    563             $q['orderby'] = $orderby_array[0].' '.$q['order'];
    564             if (count($orderby_array)>1) {
    565                 for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) {
    566                     // Only allow certain values for safety
    567                     if (in_array($orderby_array[$i],$allowed_keys)) {
    568                         $q['orderby'] .= ',post_'.$orderby_array[$i].' '.$q['order'];
    569                     }
    570                 }
    571             }
     551            if ( empty($orderby_array) )
     552                $orderby_array[] = $q['orderby'];
     553            $q['orderby'] = '';
     554            for ($i = 0; $i < count($orderby_array); $i++) {
     555                // Only allow certain values for safety
     556                $orderby = $orderby_array[$i];
     557                if ( 'menu_order' != $orderby )
     558                    $orderby = 'post_' . $orderby;
     559                if ( in_array($orderby_array[$i], $allowed_keys) )
     560                    $q['orderby'] .= (($i == 0) ? '' : ',') . "$orderby {$q['order']}";
     561            }
     562            if ( empty($q['orderby']) )
     563                $q['orderby'] = 'post_date '.$q['order'];
    572564        }
    573565
     
    588580            $where .= ' AND (post_type = "post")';
    589581        } else {
    590             $where .= ' AND (post_type = "post" AND (post_status = "publish"';
    591 
    592             if ( $pagenow == 'post.php' || $pagenow == 'edit.php' )
    593                 $where .= " OR post_status = 'future'";
     582            $where .= " AND (post_type = '$post_type' AND (post_status = 'publish'";
     583
     584            if ( is_admin() )
     585                $where .= " OR post_status = 'future' OR post_status = 'draft'";
    594586            else
    595587                $distinct = 'DISTINCT';
     
    637629        $groupby = apply_filters('posts_groupby', $groupby);
    638630        $join = apply_filters('posts_join_paged', $join);
    639         $orderby = "post_" . $q['orderby'];
    640         $orderby = apply_filters('posts_orderby', $orderby);
     631        $orderby = apply_filters('posts_orderby', $q['orderby']);
    641632        $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";
    642633        $this->request = apply_filters('posts_request', $request);
     
    14491440    var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview');
    14501441
    1451     var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'show_post_type');
     1442    var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');
     1443    var $extra_query_vars = array();
    14521444
    14531445    var $query_vars;
     
    14641456
    14651457        if (! empty($extra_query_vars))
    1466             parse_str($extra_query_vars, $extra_query_vars);
    1467         else
    1468             $extra_query_vars = array();
     1458            parse_str($extra_query_vars, $this->extra_query_vars);
    14691459
    14701460        // Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
     
    15401530
    15411531                    // Parse the query.
    1542                     parse_str($query, $query_vars);
     1532                    parse_str($query, $perma_query_vars);
    15431533
    15441534                    // If we're processing a 404 request, clear the error var
     
    15621552                    unset($error);
    15631553
    1564                 if ( isset($query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') )
    1565                     unset($query_vars);
     1554                if ( isset($perma_query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') )
     1555                    unset($perma_query_vars);
    15661556
    15671557                $this->did_permalink = false;
     
    15731563        for ($i=0; $i<count($this->public_query_vars); $i += 1) {
    15741564            $wpvar = $this->public_query_vars[$i];
    1575             if (isset($extra_query_vars[$wpvar]))
    1576                 $this->query_vars[$wpvar] = $extra_query_vars[$wpvar];
     1565            if (isset($this->extra_query_vars[$wpvar]))
     1566                $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
    15771567            elseif (isset($GLOBALS[$wpvar]))
    15781568                $this->query_vars[$wpvar] = $GLOBALS[$wpvar];
     
    15811571            elseif (!empty($_GET[$wpvar]))
    15821572                $this->query_vars[$wpvar] = $_GET[$wpvar];
    1583             elseif (!empty($query_vars[$wpvar]))
    1584                 $this->query_vars[$wpvar] = $query_vars[$wpvar];
     1573            elseif (!empty($perma_query_vars[$wpvar]))
     1574                $this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
    15851575            else
    15861576                $this->query_vars[$wpvar] = '';
     1577        }
     1578
     1579        for ($i=0; $i<count($this->private_query_vars); $i += 1) {
     1580            $wpvar = $this->private_query_vars[$i];
     1581            if (isset($this->extra_query_vars[$wpvar]))
     1582                $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];       
    15871583        }
    15881584
     
    16331629        $this->query_string = '';
    16341630
    1635         foreach ($this->public_query_vars as $wpvar) {
    1636             if (isset($this->query_vars[$wpvar]) && '' != $this->query_vars[$wpvar]) {
     1631        foreach (array_keys($this->query_vars) as $wpvar) {
     1632            if ( '' != $this->query_vars[$wpvar] ) {
    16371633                $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
    16381634                $this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
     
    16411637
    16421638        foreach ($this->private_query_vars as $wpvar) {
    1643             if (isset($GLOBALS[$wpvar]) && '' != $GLOBALS[$wpvar]) {
     1639            if (isset($GLOBALS[$wpvar]) && '' != $GLOBALS[$wpvar] && ! isset($this->extra_query_vars[$wpvar]) ) {
    16441640                $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
    16451641                $this->query_string .= $wpvar . '=' . rawurlencode($GLOBALS[$wpvar]);
Note: See TracChangeset for help on using the changeset viewer.