diff options
| author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-02-14 12:09:11 +0000 |
|---|---|---|
| committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-02-14 12:09:11 +0000 |
| commit | 39854b3d3a80e4ac2bfee92a4b1210852baa7091 (patch) | |
| tree | 95125abe2a96d8b137949ce71bc33340a0c6e376 /wp-inst/wp-includes/functions-post.php | |
| parent | 5cd626aede5b92cd056bc0e205ac9dedfd96ae05 (diff) | |
WP Merge - requires upgrading of db through wp-admin/upgrade.php!
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@524 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-inst/wp-includes/functions-post.php')
| -rw-r--r-- | wp-inst/wp-includes/functions-post.php | 179 |
1 files changed, 109 insertions, 70 deletions
diff --git a/wp-inst/wp-includes/functions-post.php b/wp-inst/wp-includes/functions-post.php index 842980f..c3f9bd1 100644 --- a/wp-inst/wp-includes/functions-post.php +++ b/wp-inst/wp-includes/functions-post.php @@ -31,7 +31,7 @@ function wp_insert_post($postarr = array()) { $post_name = apply_filters('name_save_pre', $post_name); $comment_status = apply_filters('comment_status_pre', $comment_status); $ping_status = apply_filters('ping_status_pre', $ping_status); - + // Make sure we set a valid category if (0 == count($post_category) || !is_array($post_category)) { $post_category = array(get_option('default_category')); @@ -43,7 +43,10 @@ function wp_insert_post($postarr = array()) { if ( empty($post_status) ) $post_status = 'draft'; - + + if ( empty($post_type) ) + $post_type = 'post'; + // Get the post ID. if ( $update ) $post_ID = $ID; @@ -56,7 +59,7 @@ function wp_insert_post($postarr = array()) { } else { $post_name = sanitize_title($post_name); } - + // If the post date is empty (due to having been new or a draft) and status is not 'draft', set date to now if (empty($post_date)) { @@ -69,6 +72,12 @@ function wp_insert_post($postarr = array()) { $post_date_gmt = get_gmt_from_date($post_date); } + if ( 'publish' == $post_status ) { + $now = gmdate('Y-m-d H:i:59'); + if ( mysql2date('U', $post_date_gmt) > mysql2date('U', $now) ) + $post_status = 'future'; + } + if ( empty($comment_status) ) { if ( $update ) $comment_status = 'closed'; @@ -101,18 +110,14 @@ function wp_insert_post($postarr = array()) { if ( !isset($post_password) ) $post_password = ''; - if ( ('publish' == $post_status) || ('static' == $post_status) ) { - $post_name_check = ('publish' == $post_status) - ? $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1") - : $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'static' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1"); + if ( 'draft' != $post_status ) { + $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1"); if ($post_name_check) { $suffix = 2; while ($post_name_check) { $alt_post_name = $post_name . "-$suffix"; - $post_name_check = ('publish' == $post_status) - ? $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1") - : $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'static' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1"); + $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1"); $suffix++; } $post_name = $alt_post_name; @@ -130,6 +135,7 @@ function wp_insert_post($postarr = array()) { post_title = '$post_title', post_excerpt = '$post_excerpt', post_status = '$post_status', + post_type = '$post_type', comment_status = '$comment_status', ping_status = '$ping_status', post_password = '$post_password', @@ -144,10 +150,10 @@ function wp_insert_post($postarr = array()) { } else { $wpdb->query( "INSERT IGNORE INTO $wpdb->posts - (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type) + (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, post_type, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type) VALUES - ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type')"); - $post_ID = $wpdb->insert_id; + ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$post_type', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type')"); + $post_ID = $wpdb->insert_id; } if ( empty($post_name) && 'draft' != $post_status ) { @@ -157,7 +163,7 @@ function wp_insert_post($postarr = array()) { wp_set_post_cats('', $post_ID, $post_category); - if ( 'static' == $post_status ) { + if ( 'page' == $post_type ) { clean_page_cache($post_ID); wp_cache_delete($post_ID, 'pages'); } else { @@ -174,11 +180,11 @@ function wp_insert_post($postarr = array()) { $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'"); do_action('private_to_published', $post_ID); } - + do_action('edit_post', $post_ID); } - if ($post_status == 'publish') { + if ($post_status == 'publish' && $post_type == 'post') { do_action('publish_post', $post_ID); if ( !defined('WP_IMPORTING') ) { @@ -195,7 +201,7 @@ function wp_insert_post($postarr = array()) { "); spawn_pinger(); } - } else if ($post_status == 'static') { + } else if ($post_type == 'page') { wp_cache_delete('all_page_ids', 'pages'); $wp_rewrite->flush_rules(); @@ -204,6 +210,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), 'once', 'publish_future_post', $post_ID); + do_action('save_post', $post_ID); do_action('wp_insert_post', $post_ID); @@ -238,13 +247,14 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) { if ( empty($post_author) ) $post_author = $user_ID; - $post_status = 'attachment'; + $post_type = 'attachment'; + $post_status = 'inherit'; // Are we updating or creating? $update = false; if ( !empty($ID) ) { $update = true; - $post_ID = $ID; + $post_ID = $ID; } // Create a valid post name. @@ -252,7 +262,7 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) { $post_name = sanitize_title($post_title); else $post_name = sanitize_title($post_name); - + if (empty($post_date)) $post_date = current_time('mysql'); if (empty($post_date_gmt)) @@ -305,6 +315,7 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) { post_title = '$post_title', post_excerpt = '$post_excerpt', post_status = '$post_status', + post_type = '$post_type', comment_status = '$comment_status', ping_status = '$ping_status', post_password = '$post_password', @@ -321,12 +332,12 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) { } else { $wpdb->query( "INSERT INTO $wpdb->posts - (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type, guid) + (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, post_type, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type, guid) VALUES - ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type', '$guid')"); - $post_ID = $wpdb->insert_id; + ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$post_type', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type', '$guid')"); + $post_ID = $wpdb->insert_id; } - + if ( empty($post_name) ) { $post_name = sanitize_title($post_title, $post_ID); $wpdb->query( "UPDATE $wpdb->posts SET post_name = '$post_name' WHERE ID = '$post_ID'" ); @@ -344,7 +355,7 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) { } else { do_action('add_attachment', $post_ID); } - + return $post_ID; } @@ -355,7 +366,7 @@ function wp_delete_attachment($postid) { if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") ) return $post; - if ( 'attachment' != $post->post_status ) + if ( 'attachment' != $post->post_type ) return false; $meta = get_post_meta($postid, '_wp_attachment_metadata', true); @@ -387,7 +398,7 @@ function wp_get_single_post($postid = 0, $mode = OBJECT) { global $wpdb; $post = get_post($postid, $mode); - + // Set categories if($mode == OBJECT) { $post->post_category = wp_get_post_cats('',$postid); @@ -407,7 +418,7 @@ function wp_get_recent_posts($num = 10) { $limit = "LIMIT $num"; } - $sql = "SELECT * FROM $wpdb->posts WHERE post_status IN ('publish', 'draft', 'private') ORDER BY post_date DESC $limit"; + $sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC $limit"; $result = $wpdb->get_results($sql,ARRAY_A); return $result?$result:array(); @@ -420,7 +431,7 @@ function wp_update_post($postarr = array()) { $postarr = get_object_vars($postarr); // First, get all of the original fields - $post = wp_get_single_post($postarr['ID'], ARRAY_A); + $post = wp_get_single_post($postarr['ID'], ARRAY_A); // Escape data pulled from DB. $post = add_magic_quotes($post); @@ -441,21 +452,33 @@ function wp_update_post($postarr = array()) { // Merge old and new fields with new fields overwriting old ones. $postarr = array_merge($post, $postarr); - $postarr['post_category'] = $post_cats; + $postarr['post_category'] = $post_cats; if ( $clear_date ) { $postarr['post_date'] = ''; $postarr['post_date_gmt'] = ''; } - if ($postarr['post_status'] == 'attachment') + if ($postarr['post_type'] == 'attachment') return wp_insert_attachment($postarr); 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; - + $sql = "SELECT category_id FROM $wpdb->post2cat WHERE post_id = $post_ID @@ -474,7 +497,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array( // If $post_categories isn't already an array, make it one: if (!is_array($post_categories) || 0 == count($post_categories)) $post_categories = array(get_option('default_category')); - + $post_categories = array_unique($post_categories); // First the old categories @@ -482,7 +505,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array( SELECT category_id FROM $wpdb->post2cat WHERE post_id = $post_ID"); - + if (!$old_categories) { $old_categories = array(); } else { @@ -512,13 +535,13 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array( VALUES ($post_ID, $new_cat)"); } } - + // Update category counts. $all_affected_cats = array_unique(array_merge($post_categories, $old_categories)); foreach ( $all_affected_cats as $cat_id ) { - $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status='publish' AND category_id = '$cat_id'"); + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status = 'publish' AND post_type = 'post' AND category_id = '$cat_id'"); $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'"); - wp_cache_delete($cat_id, 'category'); + wp_cache_delete($cat_id, 'category'); } } // wp_set_post_cats() @@ -529,12 +552,12 @@ function wp_delete_post($postid = 0) { if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") ) return $post; - if ( 'attachment' == $post->post_status ) + if ( 'attachment' == $post->post_type ) return wp_delete_attachment($postid); do_action('delete_post', $postid); - if ( 'publish' == $post->post_status) { + if ( 'publish' == $post->post_status && 'post' == $post->post_type ) { $categories = wp_get_post_cats('', $post->ID); if( is_array( $categories ) ) { foreach ( $categories as $cat_id ) { @@ -544,18 +567,18 @@ function wp_delete_post($postid = 0) { } } - if ( 'static' == $post->post_status ) - $wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_status = 'static'"); + if ( 'page' == $post->post_type ) + $wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_type = 'page'"); $wpdb->query("DELETE FROM $wpdb->posts WHERE ID = $postid"); - + $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID = $postid"); $wpdb->query("DELETE FROM $wpdb->post2cat WHERE post_id = $postid"); $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid"); - if ( 'static' == $post->post_status ) { + if ( 'page' == $post->type ) { wp_cache_delete('all_page_ids', 'pages'); $wp_rewrite->flush_rules(); } @@ -575,17 +598,17 @@ function post_permalink($post_id = 0, $mode = '') { // $mode legacy // Get the name of a category from its ID function get_cat_name($cat_id) { global $wpdb; - + $cat_id -= 0; // force numeric $name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=$cat_id"); - + return $name; } // Get the ID of a category from its name function get_cat_ID($cat_name='General') { global $wpdb; - + $cid = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'"); return $cid?$cid:1; // default to cat 1 @@ -619,14 +642,14 @@ function trackback_url_list($tb_list, $post_id) { // import postdata as variables extract($postdata); - + // form an excerpt $excerpt = strip_tags($post_excerpt?$post_excerpt:$post_content); - + if (strlen($excerpt) > 255) { $excerpt = substr($excerpt,0,252) . '...'; } - + $trackback_urls = explode(',', $tb_list); foreach($trackback_urls as $tb_url) { $tb_url = trim($tb_url); @@ -643,6 +666,8 @@ function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_age if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) { foreach ($chars[1] as $char) { // If it's an encoded char in the normal ASCII set, reject + if ( 38 == $char ) + continue; // Unless it's & if ($char < 128) return true; } @@ -662,7 +687,7 @@ function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_age // Do some escaping magic so that '#' chars in the // spam words don't break things: $word = preg_quote($word, '#'); - + $pattern = "#$word#i"; if ( preg_match($pattern, $author ) ) return true; if ( preg_match($pattern, $email ) ) return true; @@ -671,7 +696,7 @@ function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_age if ( preg_match($pattern, $user_ip ) ) return true; if ( preg_match($pattern, $user_agent) ) return true; } - + if ( isset($_SERVER['REMOTE_ADDR']) ) { if ( wp_proxy_check($_SERVER['REMOTE_ADDR']) ) return true; } @@ -700,7 +725,7 @@ function do_trackbacks($post_id) { $wpdb->query("UPDATE $wpdb->posts SET to_ping = '' WHERE ID = '$post_id'"); return; } - + if (empty($post->post_excerpt)) $excerpt = apply_filters('the_content', $post->post_content); else @@ -788,38 +813,38 @@ function get_page_hierarchy($posts, $parent = 0) { return $result; } -function generate_page_rewrite_rules() { +function generate_page_uri_index() { global $wpdb; - + //get pages in order of hierarchy, i.e. children after parents - $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'static'")); + $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'")); //now reverse it, because we need parents after children for rewrite rules to work properly $posts = array_reverse($posts, true); - $page_rewrite_rules = array(); - $page_attachment_rewrite_rules = array(); + $page_uris = array(); + $page_attachment_uris = array(); if ($posts) { - + foreach ($posts as $id => $post) { // URI => page name $uri = get_page_uri($id); - $attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'attachment' AND post_parent = '$id'"); + $attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$id'"); if ( $attachments ) { foreach ( $attachments as $attachment ) { $attach_uri = get_page_uri($attachment->ID); - $page_attachment_rewrite_rules[$attach_uri] = $attachment->post_name; + $page_attachment_uris[$attach_uri] = $attachment->ID; } } - $page_rewrite_rules[$uri] = $post; + $page_uris[$uri] = $id; } - update_option('page_uris', $page_rewrite_rules); - - if ( $page_attachment_rewrite_rules ) - update_option('page_attachment_uris', $page_attachment_rewrite_rules); + update_option('page_uris', $page_uris); + + if ( $page_attachment_uris ) + update_option('page_attachment_uris', $page_attachment_uris); } } @@ -827,7 +852,7 @@ function get_post_status($ID = '') { $post = get_post($ID); if ( is_object($post) ) { - if ( ('attachment' == $post->post_status) && $post->post_parent && ($post->ID != $post->post_parent) ) + if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) ) return get_post_status($post->post_parent); else return $post->post_status; @@ -836,6 +861,20 @@ function get_post_status($ID = '') { return false; } +function get_post_type($post = false) { + global $wpdb, $posts; + + if ( false === $post ) + $post = $posts[0]; + elseif ( (int) $post ) + $post = get_post($post, OBJECT); + + if ( is_object($post) ) + return $post->post_type; + + return false; +} + // Takes a post ID, returns its mime type. function get_post_mime_type($ID = '') { $post = & get_post($ID); @@ -867,7 +906,7 @@ function wp_mkdir_p($target) { return true; } else { if ( is_dir(dirname($target)) ) - return false; + return false; } // If the above failed, attempt to create the parent node, then try again. @@ -918,7 +957,7 @@ function wp_upload_bits($name, $type, $bits) { return array('error' => "Empty filename"); $upload = wp_upload_dir(); - + if ( $upload['error'] !== false ) return $upload; @@ -936,7 +975,7 @@ function wp_upload_bits($name, $type, $bits) { else $filename = str_replace("$number$ext", ++$number . $ext, $filename); } - + $new_file = $upload['path'] . "/$filename"; if ( ! wp_mkdir_p( dirname($new_file) ) ) { $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); @@ -946,7 +985,7 @@ function wp_upload_bits($name, $type, $bits) { $ifp = @ fopen($new_file, 'wb'); if ( ! $ifp ) return array('error' => "Could not write file $new_file."); - + $success = @ fwrite($ifp, $bits); fclose($ifp); // Set correct file permissions |
