コード例 #1
0
ファイル: post.php プロジェクト: nxtclass/NXTClass
/**
 * 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;
}
コード例 #2
0
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;
}
コード例 #3
0
 /**
  * Retrieve list of recent posts.
  *
  * @since 1.5.0
  *
  * @param array $args Method parameters.
  * @return array
  */
 function mw_getRecentPosts($args)
 {
     $this->escape($args);
     $blog_ID = (int) $args[0];
     $username = $args[1];
     $password = $args[2];
     if (isset($args[3])) {
         $query = array('numberposts' => absint($args[3]));
     } else {
         $query = array();
     }
     if (!($user = $this->login($username, $password))) {
         return $this->error;
     }
     do_action('xmlrpc_call', 'metaWeblog.getRecentPosts');
     $posts_list = nxt_get_recent_posts($query);
     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';
         }
         // Get post format
         $post_format = get_post_format($entry['ID']);
         if (empty($post_format)) {
             $post_format = 'standard';
         }
         $struct[] = array('dateCreated' => new IXR_Date($post_date), 'userid' => $entry['post_author'], 'postid' => (string) $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' => (string) $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' => $this->get_custom_fields($entry['ID']), 'nxt_post_format' => $post_format);
     }
     $recent_posts = array();
     for ($j = 0; $j < count($struct); $j++) {
         array_push($recent_posts, $struct[$j]);
     }
     return $recent_posts;
 }
コード例 #4
0
	<?php 
$orig_post = $post;
global $post;
$tags = nxt_get_post_tags($post->ID);
if ($tags) {
    $tag_ids = array();
    foreach ($tags as $individual_tag) {
        $tag_ids[] = $individual_tag->term_id;
    }
    $my_query = new nxt_query(array('tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => of_get_option('related_posts_count') + 1));
    if ($my_query->have_posts()) {
        ?>

			<div class="post-info related-posts clf">

				<h3><?php 
        _e('Related Posts', 'huddle');
        ?>
</h3>

				<?php 
        $i = 0;
        while ($my_query->have_posts()) {
            $my_query->the_post();
            ?>
					<div class="post <?php 
            echo ++$i % 2 == 0 ? 'even' : 'odd';
            ?>
">
						<a class="post-img" href="<?php 
コード例 #5
0
 $output = '';
 $post_type = get_post_type($post->ID);
 $post_type_obj = get_post_type_object($post_type);
 $taxonomies_string = 'post_tag, category';
 $taxonomies = array('post_tag', 'category');
 if (isset($post_type_obj->taxonomies) && count($post_type_obj->taxonomies) > 0) {
     $taxonomies_string = join(', ', $post_type_obj->taxonomies);
     $taxonomies = $post_type_obj->taxonomies;
 }
 // Clean up our taxonomies for use in the query.
 if (count($taxonomies)) {
     foreach ($taxonomies as $k => $v) {
         $taxonomies[$k] = trim($v);
     }
 }
 // Determine which terms we're going to relate to this entry.
 $related_terms = array();
 foreach ($taxonomies as $t) {
     $terms = get_the_terms($post->ID, $t);
     if (!empty($terms)) {
         foreach ($terms as $k => $v) {
             $related_terms[$t][$v->term_id] = $v->slug;
         }
     }
 }
 $specific_terms = array();
 foreach ($related_terms as $k => $v) {
     foreach ($v as $i => $j) {
         $specific_terms[] = $j;
     }
 }
 $query_args = array('limit' => $atts['limit'], 'post_type' => $post_type, 'taxonomies' => $taxonomies_string, 'specific_terms' => $specific_terms, 'order' => 'DESC', 'orderby' => 'date', 'exclude' => array($post->ID));
 $posts = woo_get_posts_by_taxonomy($query_args);
 if (count((array) $posts)) {
     $output .= '<div class="' . $css_class . '">' . "\n";
     $output .= '<ul>' . "\n";
     foreach ($posts as $post) {
         setup_postdata($post);
コード例 #6
0
 /**
  * Adds or updates a record of a post to the sitewide posts table.
  *
  * In addition to modifying the record for the post, this also tracks the
  * tags used by the post, updating those in the sitewide tags tables.
  *
  * @param int $blog_id the ID of the blog on which the post was made
  * @param int $post_id the post's ID on its blog
  *
  * @access private
  * @since 0.2
  */
 private function _update_sw_post($blog_id, $post_id)
 {
     global $nxtdb;
     ClassBlogs_NXTClass::switch_to_blog($blog_id);
     // Update the post's record in the sitewide table
     $this->_copy_sw_object($blog_id, $post_id, 'ID', $nxtdb->posts, $this->sw_tables->posts);
     // Get a list of the tags used by the current post and those that have
     // been added to the list of sitewide tags
     $local_tags = $local_tag_slugs = $sw_tag_slugs = array();
     foreach (nxt_get_post_tags($post_id) as $local_tag) {
         $local_tags[$local_tag->slug] = $local_tag;
         $local_tag_slugs[] = $local_tag->slug;
     }
     $sw_tags = $nxtdb->get_results($nxtdb->prepare("\n\t\t\tSELECT t.slug\n\t\t\tFROM {$this->sw_tables->tag_usage} AS tu, {$this->sw_tables->tags} AS t\n\t\t\tWHERE tu.post_id=%d AND tu.blog_id=%d AND tu.uses_tag=t.term_id", $post_id, $blog_id));
     foreach ($sw_tags as $sw_tag) {
         $sw_tag_slugs[] = $sw_tag->slug;
     }
     // Create or modify records for tags that need to be added
     $add_slugs = array_diff($local_tag_slugs, $sw_tag_slugs);
     foreach ($add_slugs as $add_slug) {
         // See if a record of the tag already exists
         $tag = $local_tags[$add_slug];
         $sw_id = $nxtdb->get_var($nxtdb->prepare("SELECT term_id FROM {$this->sw_tables->tags} WHERE slug=%s", ClassBlogs_Utils::slugify($add_slug)));
         // Create a new record for the tag if it doesn't exist or update
         // the usage count for an existing tag record
         if ($sw_id) {
             $nxtdb->query($nxtdb->prepare("\n\t\t\t\t\tUPDATE {$this->sw_tables->tags}\n\t\t\t\t\tSET count=count+1\n\t\t\t\t\tWHERE term_id=%d", $sw_id));
         } else {
             $nxtdb->insert($this->sw_tables->tags, array('name' => $tag->name, 'slug' => $tag->slug, 'count' => 1), array('%s', '%s', '%d'));
             $sw_id = $nxtdb->insert_id;
         }
         // Create the actual tag-usage record
         $nxtdb->query($nxtdb->prepare("INSERT INTO {$this->sw_tables->tag_usage} (post_id, uses_tag, blog_id) VALUES (%d, %d, %d)", $post_id, $sw_id, $blog_id));
     }
     // Remove any unused tags, dropping the usage count, clearing the usage
     // record, and removing any now-unused tags from the sitewide table
     $drop_slugs = array_diff($sw_tag_slugs, $local_tag_slugs);
     foreach ($drop_slugs as $drop_slug) {
         $sw_id = $nxtdb->get_var($nxtdb->prepare("SELECT term_id FROM {$this->sw_tables->tags} WHERE slug=%s", ClassBlogs_Utils::slugify($drop_slug)));
         $nxtdb->query($nxtdb->prepare("UPDATE {$this->sw_tables->tags} SET count=count-1 WHERE term_id=%d", $sw_id));
         $nxtdb->query($nxtdb->prepare("DELETE FROM {$this->sw_tables->tag_usage}\n\t\t\t\tWHERE post_id=%d AND blog_id=%d AND uses_tag=%d", $post_id, $blog_id, $sw_id));
     }
     if (!empty($drop_slugs)) {
         $this->_remove_unused_sitewide_tags();
     }
     ClassBlogs_NXTClass::restore_current_blog();
 }