function testTagFields() { $POD = new PeoplePod(); $user = $POD->getPerson(); $user->email = 'ben+test@e'; //create user $user->password = '******'; $user->set('nick', 'test'); $user->save(); $POD->changeActor(array('id' => $user->id)); //log in as user $content = $POD->getContent(); $content->set('headline', 'this is the headline'); $content->set('type', 'this is the type'); $content->save(); $this->assertFalse($content->hasTag('foo')); $content->addTag('foo'); $content->save(); $this->assertTrue($content->hasTag('foo')); $tags = $content->tags(); $tag = $tags->getNext(); $this->assertIsA($tag, 'Tag'); /// test of fields ////////////////////// $this->assertNotNull($tag->id); $this->assertEqual($tag->value, 'foo'); $this->assertNotNull($tag->get('date')); //////////////////////////////////////// $content->removeTag('nonexistant'); $this->assertFalse($content->success()); // should not be able to remove a tag that does not exist $tag_count = $content->tags()->count(); $this->assertEqual($tag_count, 1); $content->removeTag('foo'); $tag_count = $content->tags()->count(); $this->assertEqual($tag_count, 0); $string = "foo bar baz"; $content->tagsFromString($string); $tag_count = $content->tags()->count(); $this->assertEqual($tag_count, 3); $string = $content->tagsAsString(); $this->assertEqual($string, "foo bar baz"); $content->addTag(""); $this->assertEqual($tag_count, 3); $string = $content->tagsAsString(); $this->assertEqual($string, "foo bar baz "); $string = ""; //test adding a null value tag $content->tagsFromString($string); $tag_count = $content->tags()->count(); $this->assertEqual($tag_count, 0); $content->delete(); $user->delete(); }
function testCommentFunctions() { $POD = new PeoplePod(); $user = $POD->getPerson(); $user->email = '*****@*****.**'; //create user $user->password = '******'; $user->nick = 'test'; $user->save(); $POD->changeActor(array('id' => $user->id)); $content = $POD->getContent(); $content->set('headline', 'this is the headline'); $content->set('type', 'this is the type'); $content->save(); $comment = $content->addComment('amazing!'); $comment->type = 'rating'; $comment2 = $content->addComment('blah'); $comment->type = 'rating'; $this->assertEqual($comment->author()->get('id'), $user->id); $this->assertEqual($comment->parent()->id, $content->id); $comment_stack = $content->comments(); $this->assertEqual($comment_stack->count(), 2); $next_comm = $comment_stack->getNext(); $this->assertIsA($next_comm, 'Comment'); $pod_comm_stack = $POD->getComments(); $pod_comm = $pod_comm_stack->getNext(); $this->assertIsA($pod_comm, 'Comment'); //test getComment to return a specific comment $pull_comm = $POD->getComment(array('id' => $comment2->id)); $this->assertEqual($pull_comm->comment, 'blah'); //test getComment to create a comment and associate it with a person and content obj $new_comment = $POD->getComment(); $new_comment->set('comment', 'This comment sucks!'); $new_comment->set('userId', $user->id); $new_comment->set('contentId', $content->get('id')); $new_comment->save(); $comment_stack = $POD->getComments(array('userId' => $user->id)); $this->assertEqual($comment_stack->count(), 3); $comment->delete(); $content->delete(); $user->delete(); }
function Test_relationship_functions() { $POD = new PeoplePod(); $user = $POD->getPerson(); $user->email = '*****@*****.**'; //create user $user->password = '******'; $user->nick = 'test'; $user->save(); $POD->changeActor(array('id' => $user->id)); $content = $POD->getContent(); $content->set('headline', 'this is the test_tags headline'); $content->set('type', 'this is the type'); $content->save(); $new_content = $POD->getContent(); $new_content->set('headline', 'new child document'); $new_content->set('type', 'post'); $new_content->set('parentId', $content->get('id')); $new_content->save(); //Below tests parent(), and child() //test that the new content's id is set to it's parent's id $this->assertIdentical($new_content->get('parentId'), $content->get('id')); $this->assertIsA($content->children(), 'Stack'); //$this->assertIdentical($new_content->parent()->get('id'), $content->get('id')); //$this->assertFalse(is_string($new_content->parent()->get('id'))); //**Note** $new_content->'id' is either getting set, cashed, or returned as a string. While the parent content is set to an integer $this->assertEqual($new_content->parent()->get('id'), $content->get('id')); $this->assertFalse(is_string($content->get('id'))); //below tests comments() $content->addComment('first comment'); $content->addComment('second comment'); $content->addComment('third comment'); $content_comments = $content->comments(); $this->assertIsA($content_comments, 'Stack'); $first = $content_comments->getNext(); $this->assertEqual($first->comment, 'first comment'); $first = $content_comments->getNext(); $first = $content_comments->getNext(); // this should be the 'third comment' $this->assertEqual($first->comment, 'third comment'); $first = $content_comments->getNext(); // this should return null $this->assertNull($first); $content_comments->reset(); $first = $content_comments->getNext(); $this->assertEqual($first->comment, 'first comment'); //below tests files() $img_file = $content->files(); $this->assertNotNull($img_file); //below tests group() $group = $POD->getGroup(); $group->set('groupname', 'group 1'); $group->set('description', 'this is the group'); $group->save(); $this->assertTrue($group->success()); $content->setGroup($group->get('id')); $this->assertTrue($content->success()); $this->assertEqual($group->get('id'), $content->get('groupId')); $this->assertIsA($content->group(), 'Group'); // below tests tag() $string = "foo bar baz"; $content->tagsFromString($string); $tag_stack = $content->tags(); $this->assertIsA($tag_stack, 'Stack'); $tag = $tag_stack->getNext(); $this->assertIsA($tag, 'Tag'); $this->assertEqual($tag->value, 'foo'); $group->delete(); $new_content->delete(); $content->delete(); $user->delete(); }
function Test_favorite_watched() { $POD = new PeoplePod(); $user = $POD->getPerson(); $user->email = '*****@*****.**'; //create user $user->password = '******'; $user->nick = 'test'; $user->save(); $POD->changeActor(array('id' => $user->id)); //log in as user $content = $POD->getContent(); $content->set('headline', 'this is the headline'); $content->set('type', 'this is the type'); $content->save(); $isFavorite = $user->isFavorite($content); $this->assertFalse($isFavorite); $user->toggleFavorite($content); $isFavorite = $user->isFavorite($content); $this->assertTrue($isFavorite); $isWatched = $user->isWatched($content); $this->assertTrue($isWatched); $user->toggleWatch($content); $isWatched = $user->isWatched($content); $this->assertFalse($isWatched); $content->delete(); $user->delete(); }
<?php include_once "../../PeoplePods.php"; $POD = new PeoplePod(array('lockdown' => 'adminUser', 'authSecret' => @$_COOKIE['pp_auth'])); $POD->changeTheme('admin'); $group = $_GET['group']; $doc = $_GET['doc']; $action = 'add'; if ($_GET['action']) { $action = $_GET['action']; } // load parent $parent = $POD->getGroup(array('id' => $group)); if ($parent->success()) { // load child $child = $POD->getContent(array('id' => $doc)); if ($child->success()) { if ($action == 'add') { $parent->addContent($child); } else { if ($action == 'remove') { $parent->removeContent($child); } } if ($parent->success()) { // refill the children stack $parent->content()->fill(); } else { echo "Could not add to group! " . $parent->error(); } } else {
if ($method == "alert.markAsRead") { if ($POD->isAuthenticated()) { $alert = $POD->getAlert(array('id' => $_GET['id'])); $alert->markAsRead(); if ($alert->success()) { echo json_encode($alert->asArray()); } else { echo json_encode(array('error' => $alert->error(), 'id' => $_GET['id'])); } } else { echo json_encode(array('error' => 'PERMISSION DENIED', 'id' => $_GET['docId'])); } } if ($method == "markAsRead") { if ($POD->isAuthenticated()) { $doc = $POD->getContent(array('id' => $_GET['docId'])); if ($doc->success()) { $doc->markCommentsAsRead(); if ($doc->success()) { echo json_encode($doc->asArray()); } else { echo json_encode(array('error' => $doc->error(), 'id' => $_GET['docId'])); } } else { echo json_encode(array('error' => $doc->error(), 'id' => $_GET['docId'])); } } else { echo json_encode(array('error' => 'PERMISSION DENIED', 'id' => $_GET['docId'])); } } if ($method == "addWatch") {
* * Documentation for this pod can be found here: * http://peoplepods.net/readme /**********************************************/ include_once "../../PeoplePods.php"; $POD = new PeoplePod(array('authSecret' => @$_COOKIE['pp_auth'], 'debug' => 0)); // $method defines what action we are going to take $method = @$_GET['method']; // $data will hold all of information for our response $data = array(); // in order to avoid duplication in the methods below // let's load any objects specified up here, and properly handle them // at the end, we may have $content, $user, $comment, $file, and/or $group set. if (@$_GET['content']) { if (is_numeric($_GET['content'])) { $content = $POD->getContent(array('id' => $_GET['content'])); } else { $content = $POD->getContent(array('stub' => $_GET['content'])); } if (!$content->success()) { echo results(array('error' => $content->error())); exit; } $data['content'] = $content->asArray(); } if (@$_GET['person']) { if (is_numeric($_GET['person'])) { $person = $POD->getPerson(array('id' => $_GET['person'])); } else { $person = $POD->getPerson(array('nick' => $_GET['person'])); }
function testGroupContentPrivacy() { $POD = new PeoplePod(); $user = $POD->getPerson(); $user->email = '*****@*****.**'; //create user $user->password = '******'; $user->set('nick', 'test'); $user->save(); $POD->changeActor(array('id' => $user->id)); //log in as user $content = $POD->getContent(); $content->set('headline', 'this is the headline'); $content->set('type', 'this is the type'); $content->save(); $content2 = $POD->getContent(); $content2->set('headline', 'for friends'); $content2->set('type', 'Friends only'); $content2->set('privacy', 'friends_only'); $content2->save(); $content3 = $POD->getContent(); $content3->set('headline', 'Group members only!'); $content3->set('type', 'private'); $content3->save(); $group = $POD->getGroup(); $group->set('groupname', 'Music Learning Club Austin'); $group->set('description', 'A club where Austin people learn music.'); $group->save(); $group->addContent($content); $group->addContent($content2); $group->addContent($content3); $content3->set('privacy', 'group_only'); $content3->save(); $get_contents = $group->content(); $this->assertEqual($get_contents->count(), 3); //$user should have access to all three contents $user2 = $POD->getPerson(); $user2->email = '*****@*****.**'; //create user $user2->password = '******'; $user2->set('nick', 'test2'); $user2->save(); $POD->changeActor(array('id' => $user2->id)); $group->POD->changeActor(array('id' => $user2->id)); // $user2->addFriend($user); //at this point $user is in $user2's friendlist, but not in the group $get_contents = $group->content()->fill(); $this->assertEqual($get_contents->count(), 1); while ($check = $get_contents->getNext()) { $this->assertNotEqual($check->get('headline'), 'Group members only!'); $this->assertNotEqual($check->get('headline'), 'for friends'); } $POD->changeActor(array('id' => $user->id)); $group->delete(); $user->delete(); $POD->changeActor(array('id' => $user2->id)); $user2->delete(); }
$group->set('description',$_POST['description']); $group->set('type',$_POST['type']); $group->save(); if (!$group->success()) { $POD->addMessage("Save Failed! " . $group->error()); $template = "edit_group"; } else { $POD->addMessage("Group Saved!"); } } else { $template = "edit_group"; } } if ($_GET['command'] == "remove") { $doc = $POD->getContent(array('id'=>$_GET['docId'])); if ($doc->success()) { $group->removeContent($doc); if ($group->success()) { $POD->addMessage("Post removed from group!"); } else { $POD->addMessage("Error: " . $group->error()); } } else { $POD->addMessage("Error! " . $doc->error()); } } if ($_GET['command'] == "join") { if ($group->isMember($POD->currentUser())=="invitee") {
<?php // include the peoplepods library and instantiate a pod object require_once "../../PeoplePods.php"; $POD = new PeoplePod(array('authSecret' => @$_COOKIE['pp_auth'], 'debug' => 2)); // create an empty piece of content $doc = $POD->getContent(); if (isset($_GET['q'])) { $doc->headline = 'Sample pod with parameter = ' . $_GET['q']; } else { $doc->headline = 'Sample pod with no parameters'; } // print the header $POD->header($doc->headline); // output the sample content using a custom template that is included with the pod. $doc->output('custom.template', dirname(__FILE__)); // print the footer. $POD->footer();
function CreateBaseContent() { $POD = new PeoplePod(); $user = $POD->getPerson(); $user->email = '*****@*****.**'; //create user $user->password = '******'; $user->nick = 'test'; $user->addMeta('testcase', 'testuser'); // add a new field $user->save(); $user2 = $POD->getPerson(); $user2->email = '*****@*****.**'; //create user $user2->password = '******'; $user2->nick = 'test2'; $user2->addMeta('testcase', 'testuser'); // add a new field $user2->save(); $user3 = $POD->getPerson(); $user3->email = '*****@*****.**'; //create user $user3->password = '******'; $user3->nick = 'test3'; $user3->addMeta('testcase', 'testuser'); // add a new field $user3->save(); $POD->changeActor(array('id' => $user->id)); //log in as test $content = $POD->getContent(); $content->set('headline', 'first headline'); $content->set('type', 'same type'); $content->addMeta('testcase', 'testcontent'); // add a new field $content->save(); $content2 = $POD->getContent(); $content2->set('headline', 'second headline'); $content2->set('type', 'same type'); $content2->addMeta('testcase', 'testcontent'); // add a new field $content2->save(); $content3 = $POD->getContent(); $content3->set('headline', 'second headline'); $content3->set('type', 'different type'); $content3->addMeta('testcase', 'testcontent'); // add a new field $content3->save(); return $POD; }
* http://peoplepods.net/readme/new-content-type /**********************************************/ include_once "content_type.php"; // this defines some variables for use within this pod include_once "../../PeoplePods.php"; $POD = new PeoplePod(array('debug' => 0, 'lockdown' => 'verified', 'authSecret' => @$_COOKIE['pp_auth'])); if (!$POD->libOptions("enable_contenttype_{$content_type}_add")) { header("Location: " . $POD->siteRoot(false)); exit; } // by default, this script will redirect to the homepage of the site. // this can be changed by passing in an alternative via the redirect parameter $redirect = $POD->siteRoot(false); if ($_POST) { if (isset($_POST['id'])) { $content = $POD->getContent(array('id' => $_POST['id'])); if (!$content->success()) { $POD->addMessage($content->error()); } if (!$content->isEditable()) { $POD->addMessage("Access Denied"); } } else { $content = $POD->getContent(); } if (isset($_POST['headline'])) { $content->set('headline', $_POST['headline']); } if (isset($_POST['body'])) { $content->set('body', $_POST['body']); }
<? // include the peoplepods library and instantiate a pod object require_once("../../PeoplePods.php"); $POD = new PeoplePod(array('authSecret'=>@$_COOKIE['pp_auth'],'debug'=>2)); // create an empty piece of content $doc = $POD->getContent(); if (isset($_POST['selected_wiki'])) { $selWiki=$POD->getContent(array('stub'=>$_POST['selected_wiki'])); $selWiki->addFlag('username',$POD->currentUser(),$_POST['user_name']); } $doc->headline = 'My Wikis'; // print the header $POD->header($doc->headline); // output the sample content using a custom template that is included with the pod. $doc->output('custom.template',dirname(__FILE__)); // print the footer. $POD->footer();
<?php include_once "../../PeoplePods.php"; $POD = new PeoplePod(array('lockdown' => 'adminUser', 'authSecret' => @$_COOKIE['pp_auth'])); $POD->changeTheme('admin'); $id = $_GET['parent']; $child = $_GET['child']; $action = 'addChild'; if (isset($_GET['action'])) { $action = $_GET['action']; } // load parent $parent = $POD->getContent(array('id' => $id)); if ($parent->success()) { // load child $child = $POD->getContent(array('id' => $child)); if ($child->success()) { if ($action == 'addChild') { // echo "Setting documentId to " . $parent->get('id'); $child->set('parentId', $parent->get('id')); } else { if ($action == 'removeChild') { // echo "Clearing documentId"; $child->set('parentId', null); } } $child->save(); if ($child->success()) { // refill the children stack $parent->children()->fill(); } else {
$POD->changeTheme('admin'); $offset = isset($_GET['offset']) ? $_GET['offset'] : 0; $content = null; $oflags = null; $iflags = null; $user = null; $message = null; if (isset($_GET['removeFlag'])) { $flag = $_GET['removeFlag']; $type = $_GET['type']; $itemId = $_GET['itemId']; $userId = $_GET['userId']; if ($type == "user") { $obj = $POD->getPerson(array('id' => $itemId)); } else { $obj = $POD->getContent(array('id' => $itemId)); } $u = $POD->getPerson(array('id' => $userId)); $obj->removeFlag($flag, $u); if (!$obj->success()) { $ret['error'] = $obj->error(); } else { $ret = $_GET; $ret['flag'] = $flag; $ret['new_action'] = "add"; $ret['old_action'] = "remove"; } echo json_encode($ret); exit; } else { if (isset($_GET['addFlag'])) {
/**********************************************/ include_once "content_type.php"; // this defines some variables for use within this pod include_once "../../PeoplePods.php"; if ($_POST) { $lockdown = 'verified'; } else { $lockdown = null; } $POD = new PeoplePod(array('debug' => 0, 'lockdown' => $lockdown, 'authSecret' => @$_COOKIE['pp_auth'])); if (!$POD->libOptions("enable_core_pages")) { header("Location: " . $POD->siteRoot(false)); exit; } if (isset($_GET['stub'])) { $doc = $POD->getContent(array('stub' => $_GET['stub'])); } else { if (isset($_GET['id'])) { $doc = $POD->getContent(array('id' => $_GET['id'])); } else { if (isset($_POST['id'])) { $doc = $POD->getContent(array('id' => $_POST['id'])); } } } if (!$doc->success()) { header("Status: 404 Not Found"); echo "404 Not Found"; exit; } if (isset($_POST['comment'])) {
<?php include_once "../../PeoplePods.php"; $POD = new PeoplePod(array('lockdown' => 'adminuser', 'authSecret' => @$_COOKIE['pp_auth'])); $POD->changeTheme('admin'); $mode = $_GET['mode']; if ($mode == 'upload') { // someone just uploaded or modified an image } else { if ($mode == 'list') { $content = $POD->getContent(array('id' => $_GET['docId'])); ?> <div id="fileBrowser_list"> <?php // output an upload form $content->output('browser.upload'); // output list of files $content->files()->output('browser.list', 'list_header', 'list_footer', null, 'No files attached to this content.'); ?> </div> <div id="fileBrowser_details" style="display:none;"> </div> <?php } else { if ($mode == 'details') { $content = $POD->getContent(array('id' => $_GET['docId'])); $file = $content->files()->contains('id', $_GET['fileId']);
<?php include_once "../../PeoplePods.php"; $POD = new PeoplePod(array('lockdown' => 'adminUser', 'authSecret' => @$_COOKIE['pp_auth'])); if (@$_POST['id']) { $CGI = $_POST; } else { if (@$_GET['id']) { $CGI = $_GET; } } if ($POD->currentUser()->get('adminUser')) { $doc = $POD->getContent(array('id' => $CGI['id'])); $doc->changeStatus($CGI['status']); if ($doc->success()) { header("Location: " . $_SERVER['HTTP_REFERER']); } else { echo "Status change failed! " . $doc->error(); } } ?>