Post status = future. #2426

git-svn-id: http://svn.automattic.com/wordpress/trunk@3514 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-02-12 07:41:56 +00:00
parent d6d431c1be
commit a5fc1e9ebe
10 changed files with 52 additions and 36 deletions

View File

@ -33,7 +33,7 @@ function upgrade_all() {
if ( $wp_current_db_version < 3308 )
upgrade_160();
if ( $wp_current_db_version < 3513 )
if ( $wp_current_db_version < 3514 )
upgrade_210();
$wp_rewrite->flush_rules();

View File

@ -106,7 +106,7 @@ CREATE TABLE $wpdb->posts (
post_title text NOT NULL,
post_category int(4) NOT NULL default '0',
post_excerpt text NOT NULL,
post_status enum('publish','draft','private','static','object','attachment','inherit') NOT NULL default 'publish',
post_status enum('publish','draft','private','static','object','attachment','inherit','future') NOT NULL default 'publish',
comment_status enum('open','closed','registered_only') NOT NULL default 'open',
ping_status enum('open','closed') NOT NULL default 'open',
post_password varchar(20) NOT NULL default '',

View File

@ -571,14 +571,14 @@ class WP_Query {
}
}
$now = gmdate('Y-m-d H:i:59');
//$now = gmdate('Y-m-d H:i:59');
//only select past-dated posts, except if a logged in user is viewing a single: then, if they
//can edit the post, we let them through
if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) {
$where .= " AND post_date_gmt <= '$now'";
$distinct = 'DISTINCT';
}
//if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) {
// $where .= " AND post_date_gmt <= '$now'";
// $distinct = 'DISTINCT';
//}
if ( $this->is_attachment ) {
$where .= ' AND (post_type = "attachment")';
@ -589,7 +589,12 @@ class WP_Query {
} else {
$where .= ' AND (post_type = "post" AND post_status = "publish"';
if (isset($user_ID) && ('' != intval($user_ID)))
if ( $pagenow == 'post.php' || $pagenow == 'edit.php' )
$where .= " OR post_status = 'future'";
else
$distinct = 'DISTINCT';
if ( is_user_logged_in() )
$where .= " OR post_author = $user_ID AND post_status = 'private')";
else
$where .= ')';
@ -641,6 +646,7 @@ class WP_Query {
// Check post status to determine if post should be displayed.
if ($this->is_single || $this->is_page) {
$status = get_post_status($this->posts[0]);
//$type = get_post_type($this->posts[0]);
if ( ('publish' != $status) ) {
if ( ! is_user_logged_in() ) {
// User must be logged in to view unpublished posts.
@ -654,17 +660,15 @@ class WP_Query {
$this->is_preview = true;
$this->posts[0]->post_date = current_time('mysql');
}
} else {
if (! current_user_can('read_post', $this->posts[0]->ID))
$this->posts = array();
}
}
} else {
if (mysql2date('U', $this->posts[0]->post_date_gmt) > mysql2date('U', $now)) { //it's future dated
} else if ('future' == $status) {
$this->is_preview = true;
if (!current_user_can('edit_post', $this->posts[0]->ID)) {
$this->posts = array ( );
}
} else {
if (! current_user_can('read_post', $this->posts[0]->ID))
$this->posts = array();
}
}
}
}

View File

@ -84,5 +84,6 @@ add_filter('the_author', 'ent2ncr', 8);
// Actions
add_action('publish_post', 'generic_ping');
add_action('wp_head', 'rsd_link');
add_action('publish_future_post', 'wp_publish_post', 10, 1);
?>

View File

@ -72,6 +72,9 @@ function wp_insert_post($postarr = array()) {
$post_date_gmt = get_gmt_from_date($post_date);
}
if ( 'publish' == $post_status && (mysql2date('U', $post_date_gmt) > time()) )
$post_status = 'future';
if ( empty($comment_status) ) {
if ( $update )
$comment_status = 'closed';
@ -204,6 +207,9 @@ function wp_insert_post($postarr = array()) {
add_post_meta($post_ID, '_wp_page_template', $page_template, true);
}
if ( 'future' == $post_status )
wp_schedule_event(mysql2date('U', $post_date_gmt), 'once', 'publish_future_post', $post_ID);
do_action('save_post', $post_ID);
do_action('wp_insert_post', $post_ID);
@ -455,6 +461,18 @@ function wp_update_post($postarr = array()) {
return wp_insert_post($postarr);
}
function wp_publish_post($post_id) {
$post = get_post($post_id);
if ( empty($post) )
return;
if ( 'publish' == $post->post_status )
return;
return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id));
}
function wp_get_post_cats($blogid = '1', $post_ID = 0) {
global $wpdb;

View File

@ -110,17 +110,16 @@ function get_lastpostdate($timezone = 'server') {
global $cache_lastpostdate, $pagenow, $wpdb;
$add_seconds_blog = get_settings('gmt_offset') * 3600;
$add_seconds_server = date('Z');
$now = current_time('mysql', 1);
if ( !isset($cache_lastpostdate[$timezone]) ) {
switch(strtolower($timezone)) {
case 'gmt':
$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");
$lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
break;
case 'blog':
$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");
$lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
break;
case 'server':
$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");
$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");
break;
}
$cache_lastpostdate[$timezone] = $lastpostdate;
@ -134,17 +133,16 @@ function get_lastpostmodified($timezone = 'server') {
global $cache_lastpostmodified, $pagenow, $wpdb;
$add_seconds_blog = get_settings('gmt_offset') * 3600;
$add_seconds_server = date('Z');
$now = current_time('mysql', 1);
if ( !isset($cache_lastpostmodified[$timezone]) ) {
switch(strtolower($timezone)) {
case 'gmt':
$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");
$lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
break;
case 'blog':
$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");
$lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
break;
case 'server':
$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");
$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");
break;
}
$lastpostdate = get_lastpostdate($timezone);
@ -1350,12 +1348,10 @@ function get_posts($args) {
if ( !isset($r['order']) )
$r['order'] = 'DESC';
$now = current_time('mysql');
$posts = $wpdb->get_results(
"SELECT DISTINCT * FROM $wpdb->posts " .
( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) .
" WHERE post_date <= '$now' AND (post_type = 'post' AND post_status = 'publish') ".
" WHERE (post_type = 'post' AND post_status = 'publish') ".
( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) .
" GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] );

View File

@ -327,10 +327,8 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
$add_hours = intval(get_settings('gmt_offset'));
$add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
$now = current_time('mysql');
if ( 'monthly' == $type ) {
$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);
$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);
if ( $arcresults ) {
$afterafter = $after;
foreach ( $arcresults as $arcresult ) {
@ -345,7 +343,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
}
}
} elseif ( 'daily' == $type ) {
$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);
$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);
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
$url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
@ -356,7 +354,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
}
} elseif ( 'weekly' == $type ) {
$start_of_week = get_settings('start_of_week');
$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);
$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);
$arc_w_last = '';
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
@ -373,7 +371,7 @@ function get_archives($type='', $limit='', $format='html', $before = '', $after
}
}
} elseif ( 'postbypost' == $type ) {
$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);
$arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit);
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {

View File

@ -294,9 +294,7 @@ function get_next_post($in_same_cat = false, $excluded_categories = '') {
$posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
}
$now = current_time('mysql');
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");
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");
}

View File

@ -3,6 +3,6 @@
// This just holds the version number, in a separate file so we can bump it without cluttering the SVN
$wp_version = '2.1-aplha1';
$wp_db_version = 3513;
$wp_db_version = 3514;
?>

View File

@ -217,6 +217,7 @@ if ( file_exists(TEMPLATEPATH . "/functions.php") )
function shutdown_action_hook() {
do_action('shutdown');
wp_cron();
wp_cache_close();
}
register_shutdown_function('shutdown_action_hook');