Make WordPress Core

Ticket #2426: future.diff

File future.diff, 13.6 KB (added by ryan, 19 years ago)

First cut at post_status = future

  • wp-includes/default-filters.php

     
    8484// Actions
    8585add_action('publish_post', 'generic_ping');
    8686add_action('wp_head', 'rsd_link');
     87add_action('publish_future_post', 'wp_publish_post', 10, 1);
    8788
    8889?>
     90 No newline at end of file
  • wp-includes/template-functions-general.php

     
    327327        $add_hours = intval(get_settings('gmt_offset'));
    328328        $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
    329329
    330         $now = current_time('mysql');
    331 
    332330        if ( 'monthly' == $type ) {
    333                 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
     331                $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
    334332                if ( $arcresults ) {
    335333                        $afterafter = $after;
    336334                        foreach ( $arcresults as $arcresult ) {
     
    345343                        }
    346344                }
    347345        } elseif ( 'daily' == $type ) {
    348                 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_date < '$now' AND post_date != '0000-00-00 00:00:00' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
     346                $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
    349347                if ( $arcresults ) {
    350348                        foreach ( $arcresults as $arcresult ) {
    351349                                $url    = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
     
    356354                }
    357355        } elseif ( 'weekly' == $type ) {
    358356                $start_of_week = get_settings('start_of_week');
    359                 $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_date < '$now' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
     357                $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
    360358                $arc_w_last = '';
    361359                if ( $arcresults ) {
    362360                                foreach ( $arcresults as $arcresult ) {
     
    373371                                }
    374372                }
    375373        } elseif ( 'postbypost' == $type ) {
    376                 $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
     374                $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
    377375                if ( $arcresults ) {
    378376                        foreach ( $arcresults as $arcresult ) {
    379377                                if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
  • wp-includes/version.php

     
    33// This just holds the version number, in a separate file so we can bump it without cluttering the SVN
    44
    55$wp_version = '2.1-aplha1';
    6 $wp_db_version = 3513;
     6$wp_db_version = 3514;
    77
    88?>
     9 No newline at end of file
  • wp-includes/functions-post.php

     
    7272                        $post_date_gmt = get_gmt_from_date($post_date);
    7373        }
    7474
     75        if ( 'publish' == $post_status && (mysql2date('U', $post_date_gmt) > time()) )
     76                $post_status = 'future';
     77
    7578        if ( empty($comment_status) ) {
    7679                if ( $update )
    7780                        $comment_status = 'closed';
     
    204207                                add_post_meta($post_ID, '_wp_page_template',  $page_template, true);
    205208        }
    206209
     210        if ( 'future' == $post_status )
     211                wp_schedule_event(mysql2date('U', $post_date_gmt), 'once', 'publish_future_post', $post_ID);
     212
    207213        do_action('save_post', $post_ID);
    208214        do_action('wp_insert_post', $post_ID);
    209215
     
    455461        return wp_insert_post($postarr);
    456462}
    457463
     464function wp_publish_post($post_id) {
     465        $post = get_post($post_id);
     466
     467        if ( empty($post) )
     468                return;
     469
     470        if ( 'publish' == $post->post_status )
     471                return;
     472
     473        return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id));     
     474}
     475
    458476function wp_get_post_cats($blogid = '1', $post_ID = 0) {
    459477        global $wpdb;
    460478       
  • wp-includes/classes.php

     
    571571                        }
    572572                }
    573573
    574                 $now = gmdate('Y-m-d H:i:59');
     574                //$now = gmdate('Y-m-d H:i:59');
    575575               
    576576                //only select past-dated posts, except if a logged in user is viewing a single: then, if they
    577577                //can edit the post, we let them through
    578                 if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) {
    579                         $where .= " AND post_date_gmt <= '$now'";
    580                         $distinct = 'DISTINCT';
    581                 }
     578                //if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) {
     579                //      $where .= " AND post_date_gmt <= '$now'";
     580                //      $distinct = 'DISTINCT';
     581                //}
    582582
    583583                if ( $this->is_attachment ) {
    584584                        $where .= ' AND (post_type = "attachment")';
     
    589589                } else {
    590590                        $where .= ' AND (post_type = "post" AND post_status = "publish"';
    591591
    592                         if (isset($user_ID) && ('' != intval($user_ID)))
     592                        if ( $pagenow == 'post.php' || $pagenow == 'edit.php' )
     593                                $where .= " OR post_status = 'future'";
     594                        else
     595                                $distinct = 'DISTINCT';
     596       
     597                        if ( is_user_logged_in() )
    593598                                $where .= " OR post_author = $user_ID AND post_status = 'private')";
    594599                        else
    595600                                $where .= ')';                         
     
    641646                // Check post status to determine if post should be displayed.
    642647                if ($this->is_single || $this->is_page) {
    643648                        $status = get_post_status($this->posts[0]);
     649                        //$type = get_post_type($this->posts[0]);
    644650                        if ( ('publish' != $status) ) {
    645651                                if ( ! is_user_logged_in() ) {
    646652                                        // User must be logged in to view unpublished posts.
     
    654660                                                        $this->is_preview = true;
    655661                                                        $this->posts[0]->post_date = current_time('mysql');
    656662                                                }
     663                                        }  else if ('future' == $status) {
     664                                                $this->is_preview = true;
     665                                                if (!current_user_can('edit_post', $this->posts[0]->ID)) {
     666                                                        $this->posts = array ( );
     667                                                }
    657668                                        } else {
    658669                                                if (! current_user_can('read_post', $this->posts[0]->ID))
    659670                                                        $this->posts = array();
    660671                                        }
    661672                                }
    662                         } else {
    663                                 if (mysql2date('U', $this->posts[0]->post_date_gmt) > mysql2date('U', $now)) { //it's future dated
    664                                         $this->is_preview = true;
    665                                         if (!current_user_can('edit_post', $this->posts[0]->ID)) {
    666                                                 $this->posts = array ( );
    667                                         }
    668                                 }
    669673                        }
    670674                }
    671675
  • wp-includes/template-functions-links.php

     
    294294                $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
    295295        }
    296296
    297         $now = current_time('mysql');
    298        
    299         return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql AND ID != $post->ID ORDER BY post_date ASC LIMIT 1");
     297        return @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts $join WHERE post_date > '$current_post_date' AND post_type = 'post' AND post_status = 'publish' $posts_in_ex_cats_sql AND ID != $post->ID ORDER BY post_date ASC LIMIT 1");
    300298}
    301299
    302300
  • wp-includes/functions.php

     
    110110        global $cache_lastpostdate, $pagenow, $wpdb;
    111111        $add_seconds_blog = get_settings('gmt_offset') * 3600;
    112112        $add_seconds_server = date('Z');
    113         $now = current_time('mysql', 1);
    114113        if ( !isset($cache_lastpostdate[$timezone]) ) {
    115114                switch(strtolower($timezone)) {
    116115                        case 'gmt':
    117                                 $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
     116                                $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
    118117                                break;
    119118                        case 'blog':
    120                                 $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
     119                                $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
    121120                                break;
    122121                        case 'server':
    123                                 $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
     122                                $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
    124123                                break;
    125124                }
    126125                $cache_lastpostdate[$timezone] = $lastpostdate;
     
    134133        global $cache_lastpostmodified, $pagenow, $wpdb;
    135134        $add_seconds_blog = get_settings('gmt_offset') * 3600;
    136135        $add_seconds_server = date('Z');
    137         $now = current_time('mysql', 1);
    138136        if ( !isset($cache_lastpostmodified[$timezone]) ) {
    139137                switch(strtolower($timezone)) {
    140138                        case 'gmt':
    141                                 $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
     139                                $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
    142140                                break;
    143141                        case 'blog':
    144                                 $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
     142                                $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
    145143                                break;
    146144                        case 'server':
    147                                 $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
     145                                $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
    148146                                break;
    149147                }
    150148                $lastpostdate = get_lastpostdate($timezone);
     
    13501348        if ( !isset($r['order']) )
    13511349                $r['order'] = 'DESC';
    13521350
    1353         $now = current_time('mysql');
    1354 
    13551351        $posts = $wpdb->get_results(
    13561352                "SELECT DISTINCT * FROM $wpdb->posts " .
    13571353                ( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) .
    1358                 " WHERE post_date <= '$now' AND (post_type = 'post' AND post_status = 'publish') ".
     1354                " WHERE (post_type = 'post' AND post_status = 'publish') ".
    13591355                ( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) .
    13601356                " GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] );
    13611357
  • wp-settings.php

     
    217217
    218218function shutdown_action_hook() {
    219219        do_action('shutdown');
     220        wp_cron();
    220221        wp_cache_close();
    221222}
    222223register_shutdown_function('shutdown_action_hook');
  • wp-admin/upgrade-functions.php

     
    3333        if ( $wp_current_db_version < 3308 )
    3434                upgrade_160();
    3535
    36         if ( $wp_current_db_version < 3513 )
     36        if ( $wp_current_db_version < 3514 )
    3737                upgrade_210();
    3838
    3939        $wp_rewrite->flush_rules();
  • wp-admin/upgrade-schema.php

     
    106106  post_title text NOT NULL,
    107107  post_category int(4) NOT NULL default '0',
    108108  post_excerpt text NOT NULL,
    109   post_status enum('publish','draft','private','static','object','attachment','inherit') NOT NULL default 'publish',
     109  post_status enum('publish','draft','private','static','object','attachment','inherit','future') NOT NULL default 'publish',
    110110  comment_status enum('open','closed','registered_only') NOT NULL default 'open',
    111111  ping_status enum('open','closed') NOT NULL default 'open',
    112112  post_password varchar(20) NOT NULL default '',