/** * Retrieve a single post, based on post ID. * * Has categories in 'post_category' property or key. Has tags in 'tags_input' * property or key. * * @since 1.0.0 * * @param int $postid Post ID. * @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A. * @return object|array Post object or array holding post contents and information */ function nxt_get_single_post($postid = 0, $mode = OBJECT) { $postid = (int) $postid; $post = get_post($postid, $mode); if (OBJECT == $mode && empty($post->ID) || OBJECT != $mode && empty($post['ID'])) { return OBJECT == $mode ? null : array(); } // Set categories and tags if ($mode == OBJECT) { $post->post_category = array(); if (is_object_in_taxonomy($post->post_type, 'category')) { $post->post_category = nxt_get_post_categories($postid); } $post->tags_input = array(); if (is_object_in_taxonomy($post->post_type, 'post_tag')) { $post->tags_input = nxt_get_post_tags($postid, array('fields' => 'names')); } } else { $post['post_category'] = array(); if (is_object_in_taxonomy($post['post_type'], 'category')) { $post['post_category'] = nxt_get_post_categories($postid); } $post['tags_input'] = array(); if (is_object_in_taxonomy($post['post_type'], 'post_tag')) { $post['tags_input'] = nxt_get_post_tags($postid, array('fields' => 'names')); } } return $post; }
function express_getPostsWithOffset($args) { global $nxtdb; global $nxt_xmlrpc_server; $nxt_xmlrpc_server->escape($args); $blog_ID = (int) $args[0]; $username = $args[1]; $password = $args[2]; $num_posts = (int) $args[3]; $offset = (int) $args[4]; $status = $args[5]; if (!($user = $nxt_xmlrpc_server->login($username, $password))) { return $nxt_xmlrpc_server->error; } do_action('xmlrpc_call', 'metaWeblog.getRecentPosts'); // -- Added code if ($status == '') { $statuses = "'draft', 'publish', 'future', 'pending', 'private'"; } else { $status_array = explode(",", $status); $statuses = "'" . implode("','", $status_array) . "'"; } $sql = "SELECT * FROM {$nxtdb->posts} WHERE post_type = 'post' AND post_status IN ( {$statuses} ) ORDER BY post_date DESC LIMIT {$offset},{$num_posts}"; $result = $nxtdb->get_results($sql, ARRAY_A); $posts_list = $result ? $result : array(); // End added code -- if (!$posts_list) { return array(); } foreach ($posts_list as $entry) { if (!current_user_can('edit_post', $entry['ID'])) { continue; } $post_date = mysql2date('Ymd\\TH:i:s', $entry['post_date'], false); $post_date_gmt = mysql2date('Ymd\\TH:i:s', $entry['post_date_gmt'], false); // For drafts use the GMT version of the date if ($entry['post_status'] == 'draft') { $post_date_gmt = get_gmt_from_date(mysql2date('Y-m-d H:i:s', $entry['post_date']), 'Ymd\\TH:i:s'); } $categories = array(); $catids = nxt_get_post_categories($entry['ID']); foreach ($catids as $catid) { $categories[] = get_cat_name($catid); } $tagnames = array(); $tags = nxt_get_post_tags($entry['ID']); if (!empty($tags)) { foreach ($tags as $tag) { $tagnames[] = $tag->name; } $tagnames = implode(', ', $tagnames); } else { $tagnames = ''; } $post = get_extended($entry['post_content']); $link = post_permalink($entry['ID']); // Get the post author info. $author = get_userdata($entry['post_author']); $allow_comments = 'open' == $entry['comment_status'] ? 1 : 0; $allow_pings = 'open' == $entry['ping_status'] ? 1 : 0; // Consider future posts as published if ($entry['post_status'] === 'future') { $entry['post_status'] = 'publish'; } $struct[] = array('dateCreated' => new IXR_Date($post_date), 'userid' => $entry['post_author'], 'postid' => $entry['ID'], 'description' => $post['main'], 'title' => $entry['post_title'], 'link' => $link, 'permaLink' => $link, 'categories' => $categories, 'mt_excerpt' => $entry['post_excerpt'], 'mt_text_more' => $post['extended'], 'mt_allow_comments' => $allow_comments, 'mt_allow_pings' => $allow_pings, 'mt_keywords' => $tagnames, 'nxt_slug' => $entry['post_name'], 'nxt_password' => $entry['post_password'], 'nxt_author_id' => $author->ID, 'nxt_author_display_name' => $author->display_name, 'date_created_gmt' => new IXR_Date($post_date_gmt), 'post_status' => $entry['post_status'], 'custom_fields' => $nxt_xmlrpc_server->get_custom_fields($entry['ID'])); } $recent_posts = array(); for ($j = 0; $j < count($struct); $j++) { array_push($recent_posts, $struct[$j]); } return $recent_posts; }
/** * @since 1.0.1 * @deprecated 2.1 * @deprecated Use nxt_get_post_categories() * @see nxt_get_post_categories() * * @param int $blogid Not Used * @param int $post_ID * @return unknown */ function nxt_get_post_cats($blogid = '1', $post_ID = 0) { _deprecated_function(__FUNCTION__, '2.1', 'nxt_get_post_categories()'); return nxt_get_post_categories($post_ID); }
/** * Sets a post's publish status to 'publish'. * * @since 1.5.0 * * @param array $args Method parameters. * @return int */ function mt_publishPost($args) { $this->escape($args); $post_ID = (int) $args[0]; $username = $args[1]; $password = $args[2]; if (!($user = $this->login($username, $password))) { return $this->error; } do_action('xmlrpc_call', 'mt.publishPost'); if (!current_user_can('publish_posts') || !current_user_can('edit_post', $post_ID)) { return new IXR_Error(401, __('Sorry, you cannot publish this post.')); } $postdata = nxt_get_single_post($post_ID, ARRAY_A); $postdata['post_status'] = 'publish'; // retain old cats $cats = nxt_get_post_categories($post_ID); $postdata['post_category'] = $cats; $this->escape($postdata); $result = nxt_update_post($postdata); return $result; }
/** * Process the post data for the bulk editing of posts. * * Updates all bulk edited posts/pages, adding (but not removing) tags and * categories. Skips pages when they would be their own parent or child. * * @since 2.7.0 * * @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal. * @return array */ function bulk_edit_posts($post_data = null) { global $nxtdb; if (empty($post_data)) { $post_data =& $_POST; } if (isset($post_data['post_type'])) { $ptype = get_post_type_object($post_data['post_type']); } else { $ptype = get_post_type_object('post'); } if (!current_user_can($ptype->cap->edit_posts)) { if ('page' == $ptype->name) { nxt_die(__('You are not allowed to edit pages.')); } else { nxt_die(__('You are not allowed to edit posts.')); } } if (-1 == $post_data['_status']) { $post_data['post_status'] = null; unset($post_data['post_status']); } else { $post_data['post_status'] = $post_data['_status']; } unset($post_data['_status']); $post_IDs = array_map('intval', (array) $post_data['post']); $reset = array('post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky'); foreach ($reset as $field) { if (isset($post_data[$field]) && ('' == $post_data[$field] || -1 == $post_data[$field])) { unset($post_data[$field]); } } if (isset($post_data['post_category'])) { if (is_array($post_data['post_category']) && !empty($post_data['post_category'])) { $new_cats = array_map('absint', $post_data['post_category']); } else { unset($post_data['post_category']); } } $tax_input = array(); if (isset($post_data['tax_input'])) { foreach ($post_data['tax_input'] as $tax_name => $terms) { if (empty($terms)) { continue; } if (is_taxonomy_hierarchical($tax_name)) { $tax_input[$tax_name] = array_map('absint', $terms); } else { $tax_input[$tax_name] = preg_replace('/\\s*,\\s*/', ',', rtrim(trim($terms), ' ,')); $tax_input[$tax_name] = explode(',', $tax_input[$tax_name]); } } } if (isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent'])) { $pages = $nxtdb->get_results("SELECT ID, post_parent FROM {$nxtdb->posts} WHERE post_type = 'page'"); $children = array(); for ($i = 0; $i < 50 && $parent > 0; $i++) { $children[] = $parent; foreach ($pages as $page) { if ($page->ID == $parent) { $parent = $page->post_parent; break; } } } } if (isset($post_data['post_format'])) { if ('0' == $post_data['post_format']) { $post_data['post_format'] = false; } elseif (!current_theme_supports('post-formats', $post_data['post_format'])) { unset($post_data['post_format']); } } $updated = $skipped = $locked = array(); foreach ($post_IDs as $post_ID) { $post_type_object = get_post_type_object(get_post_type($post_ID)); if (!isset($post_type_object) || isset($children) && in_array($post_ID, $children) || !current_user_can($post_type_object->cap->edit_post, $post_ID)) { $skipped[] = $post_ID; continue; } if (nxt_check_post_lock($post_ID)) { $locked[] = $post_ID; continue; } $post = get_post($post_ID); $tax_names = get_object_taxonomies($post); foreach ($tax_names as $tax_name) { $taxonomy_obj = get_taxonomy($tax_name); if (isset($tax_input[$tax_name]) && current_user_can($taxonomy_obj->cap->assign_terms)) { $new_terms = $tax_input[$tax_name]; } else { $new_terms = array(); } if ($taxonomy_obj->hierarchical) { $current_terms = (array) nxt_get_object_terms($post_ID, $tax_name, array('fields' => 'ids')); } else { $current_terms = (array) nxt_get_object_terms($post_ID, $tax_name, array('fields' => 'names')); } $post_data['tax_input'][$tax_name] = array_merge($current_terms, $new_terms); } if (isset($new_cats) && in_array('category', $tax_names)) { $cats = (array) nxt_get_post_categories($post_ID); $post_data['post_category'] = array_unique(array_merge($cats, $new_cats)); unset($post_data['tax_input']['category']); } $post_data['post_mime_type'] = $post->post_mime_type; $post_data['guid'] = $post->guid; $post_data['ID'] = $post_ID; $updated[] = nxt_update_post($post_data); if (isset($post_data['sticky']) && current_user_can($ptype->cap->edit_others_posts)) { if ('sticky' == $post_data['sticky']) { stick_post($post_ID); } else { unstick_post($post_ID); } } if (isset($post_data['post_format'])) { set_post_format($post_ID, $post_data['post_format']); } } return array('updated' => $updated, 'skipped' => $skipped, 'locked' => $locked); }