function wp_insert_post($postarr = array()) { global $wpdb, $wp_id, $blog_charset, $to_wiki; // export array as variables extract($postarr); // Charset Encoding $post_content = mb_conv($post_content, $blog_charset, "auto"); $post_title = mb_conv($post_title, $blog_charset, "auto"); $post_excerpt = mb_conv($post_excerpt, $blog_charset, "auto"); //Simple HTML to PukiWiki Format(for kousagi only) if ($to_wiki) { $post_content = miniHTMLtoWiki($post_content); $post_excerpt = miniHTMLtoWiki($post_excerpt); } // Do some escapes for safety $post_content = $wpdb->escape($post_content); $post_title = $wpdb->escape($post_title); $post_excerpt = $wpdb->escape($post_excerpt); // Make sure we set a valid category if (0 == count($post_category) || !is_array($post_category)) { $post_category = array($post_default_category); } $post_cat = $post_category[0]; if (empty($post_date)) { $post_date = current_time('mysql'); } $sql = "INSERT INTO {$wpdb->posts[$wp_id]} \n\t\t(post_author, post_date, post_content, post_title, post_excerpt, post_category, post_status) \n\t\tVALUES ('{$post_author}','{$post_date}','{$post_content}','{$post_title}', '{$post_excerpt}','{$post_cat}', '{$post_status}')"; $result = $wpdb->query($sql); $post_ID = $wpdb->insert_id; wp_set_post_cats('', $post_ID, $post_category); // Return insert_id if we got a good result, otherwise return zero. return $result ? $post_ID : 0; }
function wp_insert_post($postarr = array()) { global $wpdb, $wp_id, $blog_charset, $to_wiki; // export array as variables extract($postarr); // Charset Encoding $post_content = mb_conv($post_content, $blog_charset, "auto"); $post_title = mb_conv($post_title, $blog_charset, "auto"); $post_excerpt = mb_conv($post_excerpt, $blog_charset, "auto"); //Simple HTML to PukiWiki Format(for kousagi only) if ($to_wiki) { $post_content = miniHTMLtoWiki($post_content); $post_excerpt = miniHTMLtoWiki($post_excerpt); } // Do some escapes for safety $post_content = $wpdb->escape($post_content); $post_title = $wpdb->escape($post_title); $post_excerpt = $wpdb->escape($post_excerpt); $post_name = sanitize_title($post_title); // Make sure we set a valid category if (0 == count($post_category) || !is_array($post_category)) { $post_category = array($post_default_category); } $post_cat = $post_category[0]; if (empty($post_date)) { $post_date = current_time('mysql'); } $sql = "INSERT INTO {$wpdb->posts[$wp_id]} \n\t\t(post_author, post_date, post_content, post_title, post_excerpt, post_category, post_status, post_name) \n\t\tVALUES ('{$post_author}','{$post_date}','{$post_content}','{$post_title}', '{$post_excerpt}','{$post_cat}', '{$post_status}', '{$post_name}')"; $result = $wpdb->query($sql); if ($result) { $post_ID = $wpdb->insert_id; if ($post_name == "") { $post_name = "post-" . $post_ID; $wpdb->query("UPDATE {$wpdb->posts[$wp_id]} SET post_name='{$post_name}' WHERE ID = {$post_ID}"); } wp_set_post_cats('', $post_ID, $post_category); do_action('publish_post', $post_ID); return $post_ID; } else { return 0; } }
function wp_update_post($postarr = array()) { $postHandler =& wp_handler('Post'); if ($postObject =& $postHandler->get($postarr['ID'])) { if (!empty($postarr['post_content'])) { // Charset Encoding $post_content = mb_conv($postarr['post_content'], $GLOBALS['blog_charset'], 'auto'); //Simple HTML to PukiWiki Format(for kousagi only) if (get_param('kousagi') == 2) { $post_content = miniHTMLtoWiki($post_content); } $postObject->setVar('post_content', $post_content, true); } if (!empty($postarr['post_excerpt'])) { $post_excerpt = mb_conv($postarr['post_excerpt'], $GLOBALS['blog_charset'], 'auto'); //Simple HTML to PukiWiki Format(for kousagi only) if (get_param('kousagi') == 2) { $post_excerpt = miniHTMLtoWiki($post_excerpt); } $postObject->setVar('post_excerpt', $post_excerpt, true); } if (!empty($postarr['post_title'])) { $post_title = mb_conv($postarr['post_title'], $GLOBALS['blog_charset'], 'auto'); $postObject->setVar('post_title', $post_title, true); $post_name = sanitize_title($post_title); if ($post_name == '') { $post_name = 'post-' . $postarr['ID']; } $postObject->setVar('post_name', $post_name, true); } if (!empty($postarr['post_category'])) { // Make sure we set a valid category $post_category = $postarr['post_category']; if (count($post_category) == 0 || !is_array($post_category)) { $post_category = array($GLOBALS['post_default_category']); } $postObject->setVar('post_category', $post_category[0], true); } else { $post_category = array($GLOBALS['post_default_category']); } if (!empty($postarr['post_status'])) { $postObject->setVar('post_status', $postarr['post_status'], true); } else { $postObject->setVar('post_status', get_settings('default_post_status'), true); } if (!empty($postarr['ping_status'])) { $postObject->setVar('ping_status', $postarr['ping_status'], true); } else { $postObject->setVar('ping_status', get_settings('default_ping_status'), true); } if (!empty($postarr['comment_status'])) { $postObject->setVar('comment_status', $postarr['comment_status'], true); } else { $postObject->setVar('comment_status', get_settings('default_comment_status'), true); } if (!empty($postarr['comment_status'])) { $postObject->setVar('comment_status', $postarr['comment_status'], true); } if ($postHandler->insert($postObject, true, true)) { $post_ID = $postObject->getVar('ID'); $postObject->assignCategories($post_category, true); do_action('publish_post', $post_ID); return $post_ID; } else { return 0; } } else { return 0; } }