Home » Documentation » What is PeoplePods? » SDK Documentation » SDK Quick Start Guide

SDK Quick Start Guide

This page is intended to give developers a quick overview of the basic functionality of PeoplePods. Links to further documentation are scattered throughout - we highly encourage you to explore further to get a good feel for the scope and power of PeoplePods.

Using the techniques below, you can layer PeoplePods functionality onto existing PHP-powered sites, or you can create new plugin pods which function within PeoplePods.

Creating a $POD

To access PeoplePods, you need to create a $POD object. You do this by including the library file, and calling PeoplePod's constructor. In order to do so in a manner compatible with the core pods and default theme, you need to call it like so:

include_once("/readme/sdk_quick_start_guide/my_peoplepods_dir/PeoplePods.html");
$POD = new PeoplePod(array('authSecret'=>$_COOKIE['pp_auth']));

You may want to specify that the new feature you are creating can only be accessed by certain people. You can do this using the 'lockdown' parameter:

// only allow logged in people
$POD = new PeoplePod(array(
 'authSecret'=>$_COOKIE['pp_auth'],
  'lockdown'=>'login'
));

// only allow logged in people who have confirmed their email address
$POD = new PeoplePod(array(
  'authSecret'=>$_COOKIE['pp_auth'],
  'lockdown'=>'verified'
));

// only allow logged in people with the adminUser permission
$POD = new PeoplePod(array(
  'authSecret'=>$_COOKIE['pp_auth'],
  'lockdown'=>'adminUser'
));

Once you've got your $POD object, you can access the details about the current logged in user, if one exists, using $POD->isAuthenticated() and $POD->currentUser().

Creating Content

Creating a piece of PeoplePods content is as easy as creating an empty content object to store it using $POD->getContent(), then calling the save() function. At the bare minimum, a piece of content must have a headline and a type:

$new_content = $POD->getContent();
$new_content->headline = 'This is a new post';
$new_content->type = 'post';
$new_content->save();

Part of the magic of PeoplePods is that you can create any field you want, on the fly, and PeoplePods will automatically handle it as if it was a native field in your database. This allows you to create many types of content in many different configurations. We call this creating meta fields. But you don't need to know anything special to access this functionality - it all happens behind the scenes.

$new_content->new_field = 'foo';
echo $new_content->new_field;

PeoplePods automatically tracks a bunch of information about the content, including when it was created and who created it, so you can just worry about stuffing your website with cool content.

Once you've created your content, you can add tags, comments and files using simple object methods:

$content->addComment('my comment goes here');
$content->addTag('foo');
$content->addFile($filename,$_FILES[$filename]);

Combining all of these features, you can create and manage virtually any kind of web content, and can do so without any sort of pre-configuration.

// create a new piece of content of type 'post'
$new_post = $POD->getContent();
$new_post->type='post';
$new_post->headline='my new post';
$new_post->save();

// now create another piece of content of type 'receipt'
// the receipt will use a meta field to track what content was created
$receipt = $POD->getContent();
$receipt->type = 'receipt';
$receipt->headline='Created content';
$receipt->content_created = $new_post->get('id');
$receipt->cost = 500;
$receipt->save();

Finding and Displaying Stuff

PeoplePods provides a query interface to all of the stuff it manages, including your website content, users, groups, comments, files and tags. You can use this interface to generate customized and personalized lists of stuff, then output them into your pages. In this way, you can create blogs, sidebars, tag clouds, lists of attached files, comment streams, and many other configurations.

Each type of "stuff" PeoplePods manages has its own query function, but all of the functions take the same parameters:

$posts = $POD->getContents($conditions,$sort,$count,$offset);
$people = $POD->getPeople($conditions,$sort,$count,$offset);
$files = $POD->getFiles($conditions,$sort,$count,$offset);
$groups = $POD->getGroups($conditions,$sort,$count,$offset);
$tags = $POD->getTags($conditions,$sort,$count,$offset);
$comments = $POD->getComments($conditions,$sort,$count,$offset);

Most of the time, you'll be concerned with the $conditions parameter. This is an array of field=>value pairs that describe the content you want to load. This might be as simple as specifying the type of content or the id of the content's owner, or it might involve a combination of several fields. You can read about stack parameters here.

The return value of these functions is a list of objects, or what we call a stack. You can do all sorts of things with stacks, including iterating over them, searching them, and outputting them to the page.

Each object also has its own output function, which uses a template file located in one of the themes. You can also output individual fields using write() and other related functions.

// get recent posts
$posts = $POD->getContents(array('type'=>'post'));

// get recent posts by a specific author
$posts = $POD->getContents(array('type'=>'post','userId'=>6));

// use foreach to iterate over the results
foreach ($posts as $post) { 
  $post->output();
}

// use while to iterate over the results
while ($post = $posts->getNext()) {
  $post->output();
}

// just output the entire list, with automatically generated headers and footers
$posts->output();

You can query any of the different object types using any field in their object definition as well as any fields you create using the meta fields technique. You can also query fields in related objects, like the author of a post, members of groups, or a comment's parent content. Using this capability, you can create virtually any view of your website that you can imagine.

// get all comments that are attached to content in a specific group
$comments = $POD->getComments(array('d.groupId'=>5));

// get all files created by an admin user
$files = $POD->getFiles(array('u.adminUser'=>1));

Once you have the stuff you want, you can access related stuff without more queries. Each type of object comes with predefined stacks:

$comments = $content->comments();
$author = $content->author();
$files = $content->files();
$content = $comment->parent();
$people = $group->members();

Creating Relationships Between People and Content

You can create relationships between 2 people, or between a person and a piece of content using flags:

// add $content to $user's favorites
$content->addFlag('favorite',$user);

// add $friend as $user's friend
$friend->addFlag('friend',$user);

You can then query the content and people using those flags:

// load my favorites
$favorites = $POD->getContents(array(
  'flag.name'=>'favorite',
   'flag.userId'=>$user->id
));

// load my friends
$friends = $POD->getPeople(array(
  'flag.name'=>'friend',
  'flag.userId'=>$user->id
));

Luckily, PeoplePods provides a bunch of built in flag management for favorites, friends, followers, and comment subscriptions.

Groups

We believe the future of online community revolves around small groups. Groups for clubs, groups for interests, groups for neighborhoods, and group for groups! Thus, we've built basic group handling right into the core of PeoplePods.

// create a group
$new_group = $POD->getGroup();
$new_group->group_name = 'Scoobies';
$new_group->description = 'For vampire hunters';
$new_group->save();

// add a piece of content to a group
$new_group->addContent($post);

// add a user to the group
$new_group->addMember($user);

Read more about groups here.

  • Discuss This Document

No comments have been posted yet.

Download Download the latest version of PeoplePods!

0.7 Latest Version:
Release Notes

A free membership is required to download PeoplePods.

  Already Registered? Login

Recent Posts from Our Blog

Version 0.7 Now Available

Last night, I uploaded a new release of PeoplePods: version 0.7. The most exciting new features in this version are: new dynamic image resizing options, a faster comment polling system, new ways...

Developer Preview Launch!

I am very excited to announce the launch of PeoplePods version 0.666, THE DEVELOPER PREVIEW! After tons of hacking, I have tweaked the last line of code, and I am finally ready for a wider audience...