Make WordPress Core

Ticket #1220: preview_draft.diff

File preview_draft.diff, 5.6 KB (added by ryan, 20 years ago)
  • wp-blog-header.php

     
    167167$query_string = apply_filters('query_string', $query_string);
    168168
    169169update_category_cache();
     170get_currentuserinfo();
    170171
    171172// Call query posts to do the work.
    172173$posts = & query_posts($query_string);
  • wp-includes/functions-post.php

     
    351351/* returns true if $user_id can edit $post_id */
    352352function user_can_edit_post($user_id, $post_id, $blog_id = 1) {
    353353        $author_data = get_userdata($user_id);
    354         $post_data   = get_postdata($post_id);
    355         $post_author_data = get_userdata($post_data['Author_ID']);
     354        $post = get_post($post_id);
     355        $post_author_data = get_userdata($post->post_author);
    356356
    357         if ( (($user_id == $post_author_data->ID) && !($post_data['post_status'] == 'publish' &&  $author_data->user_level < 2))
     357        if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' &&  $author_data->user_level < 2))
    358358             || ($author_data->user_level > $post_author_data->user_level)
    359359             || ($author_data->user_level >= 10) ) {
    360360                return true;
  • wp-includes/classes.php

     
    493493                }
    494494
    495495                if ($this->is_page) {
    496                         $where .= ' AND (post_status = "static"';
     496                        $where .= ' AND (post_status = "static")';
     497                } elseif ($this->is_single) {
     498                        $where .= ' AND (post_status != "static")';
    497499                } else {
    498500                        $where .= ' AND (post_status = "publish"';
     501
     502                        if (isset($user_ID) && ('' != intval($user_ID)))
     503                                $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
     504                        else
     505                                $where .= ')';                         
    499506                }
    500507
    501                 // Get private posts
    502                 if (isset($user_ID) && ('' != intval($user_ID)))
    503                         $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
    504                 else
    505                         $where .= ')';
    506 
    507508                // Apply filters on where and join prior to paging so that any
    508509                // manipulations to them are reflected in the paging by day queries.
    509510                $where = apply_filters('posts_where', $where);
     
    543544                $orderby = apply_filters('posts_orderby', $orderby);
    544545                $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY " . $orderby . " $limits";
    545546
    546                 if ($q['preview']) {
    547                         $request = 'SELECT 1-1'; // dummy mysql query for the preview
    548                         // little funky fix for IEwin, rawk on that code
    549                         $is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT)));
    550                         if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) {
    551                                 $preview_content =  preg_replace('/\%u([0-9A-F]{4,4})/e',  "'&#'.base_convert('\\1',16,10).';'", $preview_content);
     547                $this->posts = $wpdb->get_results($request);
     548
     549                // Check post status to determine if post should be displayed.
     550                if ($this->is_single) {
     551                        if ('publish' != $this->posts[0]->post_status) {
     552                                if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) {
     553                                        // User must be logged in to view unpublished posts.
     554                                        $this->posts = array();
     555                                } else {
     556                                        if ('draft' == $this->posts[0]->post_status) {
     557                                                // User must have edit permissions on the draft to preview.
     558                                                if (! user_can_edit_post($user_ID, $this->posts[0]->ID))
     559                                                        $this->posts = array();
     560                                        } elseif ('private' == $this->posts[0]->post_status) {
     561                                                if ($this->posts[0]->post_author != $user_ID)
     562                                                        $this->posts = array();
     563                                        }
     564                                }
    552565                        }
    553566                }
    554567
    555                 $this->posts = $wpdb->get_results($request);
    556568                $this->posts = apply_filters('the_posts', $this->posts);
    557569                $this->post_count = count($this->posts);
    558570                if ($this->post_count > 0) {
  • wp-includes/template-functions-links.php

     
    4444
    4545        $permalink = get_settings('permalink_structure');
    4646
    47         if ('' != $permalink) {
     47        if ('' != $permalink && 'draft' != $post->post_status) {
    4848                $unixtime = strtotime($post->post_date);
    4949
    5050                $category = '';
  • wp-includes/functions.php

     
    856856
    857857// Setup global post data.
    858858function setup_postdata($post) {
    859   global $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages, $wp_query;
     859  global $id, $postdata, $authordata, $day, $page, $pages, $multipage, $more, $numpages, $wp_query;
    860860        global $pagenow;
    861861
    862         if (!$preview) {
    863                 $id = $post->ID;
    864         } else {
    865                 $id = 0;
    866                 $postdata = array (
    867                         'ID' => 0,
    868                         'Author_ID' => $_GET['preview_userid'],
    869                         'Date' => $_GET['preview_date'],
    870                         'Content' => $_GET['preview_content'],
    871                         'Excerpt' => $_GET['preview_excerpt'],
    872                         'Title' => $_GET['preview_title'],
    873                         'Category' => $_GET['preview_category'],
    874                         'Notify' => 1
    875                         );
    876         }
     862        $id = $post->ID;
     863
    877864        $authordata = get_userdata($post->post_author);
    878865
    879866        $day = mysql2date('d.m.y', $post->post_date);
     
    11581145        $comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
    11591146        FROM $wpdb->posts
    11601147        LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID  AND comment_approved =  '1')
    1161         WHERE post_status =  'publish' AND ID IN ($post_id_list)
     1148        WHERE ID IN ($post_id_list)
    11621149        GROUP BY ID");
    11631150       
    11641151        if ($comment_counts) {