You are here

function blogapi_get_recent_posts in Blog API 7.2

Helper function. Returns the latest few nodes created by a given user.

3 calls to blogapi_get_recent_posts()
blogapi_blogger_get_recent_posts in modules/blogapi_blogger/blogapi_blogger.module
Service callback for blogger.getRecentPosts
blogapi_metaweblog_get_recent_posts in modules/blogapi_metaweblog/blogapi_metaweblog.module
Service callback for metaWeblog.getRecentPosts
blogapi_movabletype_get_recent_post_titles in modules/blogapi_movabletype/blogapi_movabletype.module
Service callback for mt.getRecentPostTitles

File

./blogapi.module, line 241
Enable users to post using applications that support BlogAPIs.

Code

function blogapi_get_recent_posts($blogid, $username, $password, $number_of_posts = 10, $bodies = TRUE) {

  // Validate the user.
  $user = blogapi_validate_user($username, $password);

  // Validate the content type.
  blogapi_validate_content_type($blogid);
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', $blogid)
    ->propertyCondition('uid', $user->uid)
    ->propertyOrderBy('created', 'DESC')
    ->range(0, $number_of_posts);
  $result = $query
    ->execute();
  if (!empty($result['node'])) {
    $blog_nids = array();
    $posts = array();
    foreach ($result['node'] as $node) {
      $blog_nids[] = $node->nid;
    }
    $blogs = node_load_multiple($blog_nids);
    foreach ($blogs as $blog) {
      $posts[] = blogapi_format_post_for_xmlrpc($blog, $bodies);
    }
    return $posts;
  }
  return array();
}