Commit e5ca3065 by Maiyannah Bishop

ActivityStreamJSONDocument documentation

1 parent f4995f61
......@@ -47,16 +47,29 @@
* o GNU social <https://www.gnu.org/s/social/>
* ============================================================================
*/
// This file is formatted so that it provides useful documentation output in
// NaturalDocs. Please be considerate of this before changing formatting.
if (!defined('POSTACTIV')) { exit(1); }
/**
* A class for generating JSON documents that represent an Activity Streams
*/
// ----------------------------------------------------------------------------
// Function: ActivityStreamJSONDocument
// A class for generating JSON documents that represent an Activity Streams
//
// Defines:
// o CONTENT_TYPE = 'application/json; charset=utf-8';
//
// Variables:
// o $doc - Top level array representing the document
// o $cur - The current authenticated user
// o $scoped - default null
// o $title - Title of the document
// o $links - Links associated with this document
// o $count - Count of items in this document.
// This is cryptically referred to in the spec:
// "The Stream serialization MAY contain a count property.
class ActivityStreamJSONDocument extends JSONActivityCollection
{
// Note: Lot of AS folks think the content type should be:
......@@ -65,130 +78,117 @@ class ActivityStreamJSONDocument extends JSONActivityCollection
// it.
const CONTENT_TYPE = 'application/json; charset=utf-8';
/* Top level array representing the document */
protected $doc = array();
/* The current authenticated user */
protected $cur;
protected $scoped = null;
/* Title of the document */
protected $title;
/* Links associated with this document */
protected $links;
/* Count of items in this document */
// XXX This is cryptically referred to in the spec: "The Stream serialization MAY contain a count property."
protected $count;
/**
* Constructor
*
* @param User $cur the current authenticated user
*/
function __construct($cur = null, $title = null, $items = null, $links = null, $url = null)
{
parent::__construct($items, $url);
$this->cur = $cur ?: common_current_user();
$this->scoped = !is_null($this->cur) ? $this->cur->getProfile() : null;
/* Title of the JSON document */
$this->title = $title;
if (!empty($items)) {
$this->count = count($this->items);
}
/* Array of links associated with the document */
$this->links = empty($links) ? array() : $items;
/* URL of a document, this document? containing a list of all the items in the stream */
if (!empty($this->url)) {
$this->url = $this->url;
}
}
/**
* Set the title of the document
*
* @param String $title the title
*/
function setTitle($title)
{
$this->title = $title;
}
function setUrl($url)
{
$this->url = $url;
}
/**
* Add more than one Item to the document
*
* @param mixed $notices an array of Notice objects or handle
*
*/
function addItemsFromNotices($notices)
{
if (is_array($notices)) {
foreach ($notices as $notice) {
$this->addItemFromNotice($notice);
}
} else {
while ($notices->fetch()) {
$this->addItemFromNotice($notices);
}
}
}
/**
* Add a single Notice to the document
*
* @param Notice $notice a Notice to add
*/
function addItemFromNotice($notice)
{
$act = $notice->asActivity($this->scoped);
$act->extra[] = $notice->noticeInfo($this->scoped);
array_push($this->items, $act->asArray());
$this->count++;
}
/**
* Add a link to the JSON document
*
* @param string $url the URL for the link
* @param string $rel the link relationship
*/
function addLink($url = null, $rel = null, $mediaType = null)
{
$link = new ActivityStreamsLink($url, $rel, $mediaType);
array_push($this->links, $link->asArray());
}
/*
* Return the entire document as a big string of JSON
*
* @return string encoded JSON output
*/
function asString()
{
$this->doc['generator'] = 'GNU social ' . GNUSOCIAL_VERSION; // extension
$this->doc['title'] = $this->title;
$this->doc['url'] = $this->url;
$this->doc['totalItems'] = $this->count;
$this->doc['items'] = $this->items;
$this->doc['links'] = $this->links; // extension
return json_encode(array_filter($this->doc)); // filter out empty elements
}
// -------------------------------------------------------------------------
// Constructor
//
// Parameters:
// o User $cur the current authenticated user
function __construct($cur = null, $title = null, $items = null, $links = null, $url = null)
{
parent::__construct($items, $url);
$this->cur = $cur ?: common_current_user();
$this->scoped = !is_null($this->cur) ? $this->cur->getProfile() : null;
/* Title of the JSON document */
$this->title = $title;
if (!empty($items)) {
$this->count = count($this->items);
}
/* Array of links associated with the document */
$this->links = empty($links) ? array() : $items;
/* URL of a document, this document? containing a list of all the items in the stream */
if (!empty($this->url)) {
$this->url = $this->url;
}
}
// -------------------------------------------------------------------------
// Function: setTitle
// Set the title of the document
//
// Parameters:
// o String $title the title
function setTitle($title) {
$this->title = $title;
}
// -------------------------------------------------------------------------
// Function: setUrl
function setUrl($url) {
$this->url = $url;
}
// -------------------------------------------------------------------------
// Function: addItemsFromNotices
// Add more than one Item to the document
//
// Parameters:
// o mixed $notices an array of Notice objects or handle
function addItemsFromNotices($notices) {
if (is_array($notices)) {
foreach ($notices as $notice) {
$this->addItemFromNotice($notice);
}
} else {
while ($notices->fetch()) {
$this->addItemFromNotice($notices);
}
}
}
// -------------------------------------------------------------------------
// Function: addItemFromNotice
// Add a single Notice to the document
//
// Parameters:
// o Notice $notice a Notice to add
function addItemFromNotice($notice) {
$act = $notice->asActivity($this->scoped);
$act->extra[] = $notice->noticeInfo($this->scoped);
array_push($this->items, $act->asArray());
$this->count++;
}
// -------------------------------------------------------------------------
// Function: addLink
// Add a link to the JSON document
//
// Parameters:
// o string $url the URL for the link
// o string $rel the link relationship
function addLink($url = null, $rel = null, $mediaType = null) {
$link = new ActivityStreamsLink($url, $rel, $mediaType);
array_push($this->links, $link->asArray());
}
// -------------------------------------------------------------------------
// Function: asString
// Return the entire document as a big string of JSON
//
// Returns:
// o string encoded JSON output
function asString() {
$this->doc['generator'] = 'GNU social ' . GNUSOCIAL_VERSION; // extension
$this->doc['title'] = $this->title;
$this->doc['url'] = $this->url;
$this->doc['totalItems'] = $this->count;
$this->doc['items'] = $this->items;
$this->doc['links'] = $this->links; // extension
return json_encode(array_filter($this->doc)); // filter out empty elements
}
}
// END OF FILE
......
This diff could not be displayed because it is too large.
......@@ -59,6 +59,36 @@ var indexSectionsWithContent = {
"Y": false,
"Z": false
},
"General": {
"Symbols": true,
"Numbers": false,
"A": true,
"B": true,
"C": true,
"D": true,
"E": true,
"F": true,
"G": true,
"H": true,
"I": true,
"J": true,
"K": false,
"L": true,
"M": true,
"N": true,
"O": true,
"P": true,
"Q": true,
"R": true,
"S": true,
"T": true,
"U": true,
"V": true,
"W": false,
"X": false,
"Y": true,
"Z": false
},
"Classes": {
"Symbols": false,
"Numbers": false,
......@@ -118,35 +148,5 @@ var indexSectionsWithContent = {
"X": false,
"Y": true,
"Z": false
},
"General": {
"Symbols": true,
"Numbers": false,
"A": true,
"B": true,
"C": true,
"D": true,
"E": true,
"F": true,
"G": true,
"H": true,
"I": true,
"J": true,
"K": false,
"L": true,
"M": true,
"N": true,
"O": true,
"P": true,
"Q": true,
"R": true,
"S": true,
"T": true,
"U": true,
"V": true,
"W": false,
"X": false,
"Y": true,
"Z": false
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ if (browserType) {document.write("<div class=" + browserType + ">");if (browserV
<div id=Index><div class=IPageTitle>Search Results</div><div class=SRStatus id=Loading>Loading...</div><table border=0 cellspacing=0 cellpadding=0><div class=SRResult id=SR_ack><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.ack" class=ISymbol>ack</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_age><div class=IEntry><a href="../files/classes/queue/RedisQueue-php.html#RedisQueueItem.age" class=ISymbol>age</a>, <span class=IParent>RedisQueueItem</span></div></div><div class=SRResult id=SR_asArray><div class=IEntry><a href="javascript:searchResults.Toggle('SR_asArray')" class=ISymbol>asArray</a><div class=ISubIndex><a href="../files/classes/activity/Activity-php.html#Activity.asArray" class=IParent>Activity</a><a href="../files/classes/activity/ActivityContext-php.html#ActivityContext.asArray" class=IParent>ActivityContext</a></div></div></div><div class=SRResult id=SR_asString><div class=IEntry><a href="../files/classes/activity/Activity-php.html#Activity.asString" class=ISymbol>asString</a>, <span class=IParent>Activity</span></div></div></table><div class=SRStatus id=Searching>Searching...</div><div class=SRStatus id=NoMatches>No Matches</div><script type="text/javascript"><!--
<div id=Index><div class=IPageTitle>Search Results</div><div class=SRStatus id=Loading>Loading...</div><table border=0 cellspacing=0 cellpadding=0><div class=SRResult id=SR_ack><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.ack" class=ISymbol>ack</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_addItemFromNotice><div class=IEntry><a href="../files/classes/activity/ActivityStreamJSONDocument-php.html#addItemFromNotice" class=ISymbol>addItemFromNotice</a></div></div><div class=SRResult id=SR_addItemsFromNotices><div class=IEntry><a href="../files/classes/activity/ActivityStreamJSONDocument-php.html#addItemsFromNotices" class=ISymbol>addItemsFromNotices</a></div></div><div class=SRResult id=SR_addLink><div class=IEntry><a href="../files/classes/activity/ActivityStreamJSONDocument-php.html#addLink" class=ISymbol>addLink</a></div></div><div class=SRResult id=SR_age><div class=IEntry><a href="../files/classes/queue/RedisQueue-php.html#RedisQueueItem.age" class=ISymbol>age</a>, <span class=IParent>RedisQueueItem</span></div></div><div class=SRResult id=SR_asArray><div class=IEntry><a href="javascript:searchResults.Toggle('SR_asArray')" class=ISymbol>asArray</a><div class=ISubIndex><a href="../files/classes/activity/Activity-php.html#Activity.asArray" class=IParent>Activity</a><a href="../files/classes/activity/ActivityContext-php.html#ActivityContext.asArray" class=IParent>ActivityContext</a></div></div></div><div class=SRResult id=SR_asString><div class=IEntry><a href="javascript:searchResults.Toggle('SR_asString')" class=ISymbol>asString</a><div class=ISubIndex><a href="../files/classes/activity/ActivityStreamJSONDocument-php.html#asString" class=IParent>Global</a><a href="../files/classes/activity/Activity-php.html#Activity.asString" class=IParent>Activity</a></div></div></div></table><div class=SRStatus id=Searching>Searching...</div><div class=SRStatus id=NoMatches>No Matches</div><script type="text/javascript"><!--
document.getElementById("Loading").style.display="none";
document.getElementById("NoMatches").style.display="none";
var searchResults = new SearchResults("searchResults", "FramedHTML");
......
......@@ -14,7 +14,7 @@ if (browserType) {document.write("<div class=" + browserType + ">");if (browserV
<div id=Index><div class=IPageTitle>Search Results</div><div class=SRStatus id=Loading>Loading...</div><table border=0 cellspacing=0 cellpadding=0><div class=SRResult id=SR_saveNew><div class=IEntry><a href="../files/classes/Attention-php.html#Attention.saveNew" class=ISymbol>saveNew</a>, <span class=IParent>Attention</span></div></div><div class=SRResult id=SR_schemaDef><div class=IEntry><a href="javascript:searchResults.Toggle('SR_schemaDef')" class=ISymbol>schemaDef</a><div class=ISubIndex><a href="../files/classes/Attention-php.html#Attention.schemaDef" class=IParent>Attention</a><a href="../files/classes/Avatar-php.html#Avatar.schemaDef" class=IParent>Avatar</a><a href="../files/classes/User_im_prefs-php.html#User_im_prefs.schemaDef" class=IParent>User_im_prefs</a><a href="../files/classes/User_location_prefs-php.html#User_location_prefs.schemaDef" class=IParent>User_location_prefs</a><a href="../files/classes/User_urlshortener_prefs-php.html#User_urlshortener_prefs.schemaDef" class=IParent>User_urlshortener_prefs</a><a href="../files/classes/User_username-php.html#User_username.schemaDef" class=IParent>User_username</a></div></div></div><div class=SRResult id=SR_scrub><div class=IEntry><a href="../files/classes/queue/RedisQueue-php.html#RedisQueue.scrub" class=ISymbol>scrub</a>, <span class=IParent>RedisQueue</span></div></div><div class=SRResult id=SR_send_undraw_undmessage><div class=IEntry><a href="../files/classes/queue/ImManager-php.html#ImManager.send_raw_message" class=ISymbol>send_raw_message</a>, <span class=IParent>ImManager</span></div></div><div class=SRResult id=SR_sendControlSignal><div class=IEntry><a href="javascript:searchResults.Toggle('SR_sendControlSignal')" class=ISymbol>sendControlSignal</a><div class=ISubIndex><a href="../files/classes/queue/QueueManager-php.html#QueueManager.sendControlSignal" class=IParent>QueueManager</a><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.sendControlSignal" class=IParent>StompQueueManager</a></div></div></div><div class=SRResult id=SR_setActiveGroup><div class=IEntry><a href="../files/classes/queue/QueueManager-php.html#QueueManager.setActiveGroup" class=ISymbol>setActiveGroup</a>, <span class=IParent>QueueManager</span></div></div><div class=SRResult id=SR_setActiveGroups><div class=IEntry><a href="../files/classes/queue/QueueManager-php.html#QueueManager.setActiveGroups" class=ISymbol>setActiveGroups</a>, <span class=IParent>QueueManager</span></div></div><div class=SRResult id=SR_setupRW><div class=IEntry><a href="../files/index-php.html#setupRW" class=ISymbol>setupRW</a></div></div><div class=SRResult id=SR_smarty_undmake_undtimestamp_lanbr_ran><div class=IEntry><a href="../files/extlib/Smarty/plugins/shared-make_timestamp-php.html#smarty_make_timestampbr" class=ISymbol>smarty_make_timestamp&lt;br&gt;</a></div></div><div class=SRResult id=SR_start><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.start" class=ISymbol>start</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_stats><div class=IEntry><a href="javascript:searchResults.Toggle('SR_stats')" class=ISymbol>stats</a><div class=ISubIndex><a href="../files/classes/queue/QueueManager-php.html#QueueManager.stats" class=IParent>QueueManager</a><a href="../files/classes/queue/QueueMonitor-php.html#QueueMonitor.stats" class=IParent>QueueMonitor</a></div></div></div><div class=SRResult id=SR_subscribeProfile><div class=IEntry><a href="../files/classes/activity/ActivityImporter-php.html#ActivityImporter.subscribeProfile" class=ISymbol>subscribeProfile</a>, <span class=IParent>ActivityImporter</span></div></div><div class=SRResult id=SR_subscriptions><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.subscriptions" class=ISymbol>subscriptions</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_switchSite><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.switchSite" class=ISymbol>switchSite</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_sync><div class=IEntry><a href="../files/classes/queue/RedisQueue-php.html#RedisQueue.sync" class=ISymbol>sync</a>, <span class=IParent>RedisQueue</span></div></div></table><div class=SRStatus id=Searching>Searching...</div><div class=SRStatus id=NoMatches>No Matches</div><script type="text/javascript"><!--
<div id=Index><div class=IPageTitle>Search Results</div><div class=SRStatus id=Loading>Loading...</div><table border=0 cellspacing=0 cellpadding=0><div class=SRResult id=SR_saveNew><div class=IEntry><a href="../files/classes/Attention-php.html#Attention.saveNew" class=ISymbol>saveNew</a>, <span class=IParent>Attention</span></div></div><div class=SRResult id=SR_schemaDef><div class=IEntry><a href="javascript:searchResults.Toggle('SR_schemaDef')" class=ISymbol>schemaDef</a><div class=ISubIndex><a href="../files/classes/Attention-php.html#Attention.schemaDef" class=IParent>Attention</a><a href="../files/classes/Avatar-php.html#Avatar.schemaDef" class=IParent>Avatar</a><a href="../files/classes/User_im_prefs-php.html#User_im_prefs.schemaDef" class=IParent>User_im_prefs</a><a href="../files/classes/User_location_prefs-php.html#User_location_prefs.schemaDef" class=IParent>User_location_prefs</a><a href="../files/classes/User_urlshortener_prefs-php.html#User_urlshortener_prefs.schemaDef" class=IParent>User_urlshortener_prefs</a><a href="../files/classes/User_username-php.html#User_username.schemaDef" class=IParent>User_username</a></div></div></div><div class=SRResult id=SR_scrub><div class=IEntry><a href="../files/classes/queue/RedisQueue-php.html#RedisQueue.scrub" class=ISymbol>scrub</a>, <span class=IParent>RedisQueue</span></div></div><div class=SRResult id=SR_send_undraw_undmessage><div class=IEntry><a href="../files/classes/queue/ImManager-php.html#ImManager.send_raw_message" class=ISymbol>send_raw_message</a>, <span class=IParent>ImManager</span></div></div><div class=SRResult id=SR_sendControlSignal><div class=IEntry><a href="javascript:searchResults.Toggle('SR_sendControlSignal')" class=ISymbol>sendControlSignal</a><div class=ISubIndex><a href="../files/classes/queue/QueueManager-php.html#QueueManager.sendControlSignal" class=IParent>QueueManager</a><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.sendControlSignal" class=IParent>StompQueueManager</a></div></div></div><div class=SRResult id=SR_setActiveGroup><div class=IEntry><a href="../files/classes/queue/QueueManager-php.html#QueueManager.setActiveGroup" class=ISymbol>setActiveGroup</a>, <span class=IParent>QueueManager</span></div></div><div class=SRResult id=SR_setActiveGroups><div class=IEntry><a href="../files/classes/queue/QueueManager-php.html#QueueManager.setActiveGroups" class=ISymbol>setActiveGroups</a>, <span class=IParent>QueueManager</span></div></div><div class=SRResult id=SR_setTitle><div class=IEntry><a href="../files/classes/activity/ActivityStreamJSONDocument-php.html#setTitle" class=ISymbol>setTitle</a></div></div><div class=SRResult id=SR_setupRW><div class=IEntry><a href="../files/index-php.html#setupRW" class=ISymbol>setupRW</a></div></div><div class=SRResult id=SR_setUrl><div class=IEntry><a href="../files/classes/activity/ActivityStreamJSONDocument-php.html#setUrl" class=ISymbol>setUrl</a></div></div><div class=SRResult id=SR_smarty_undmake_undtimestamp_lanbr_ran><div class=IEntry><a href="../files/extlib/Smarty/plugins/shared-make_timestamp-php.html#smarty_make_timestampbr" class=ISymbol>smarty_make_timestamp&lt;br&gt;</a></div></div><div class=SRResult id=SR_start><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.start" class=ISymbol>start</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_stats><div class=IEntry><a href="javascript:searchResults.Toggle('SR_stats')" class=ISymbol>stats</a><div class=ISubIndex><a href="../files/classes/queue/QueueManager-php.html#QueueManager.stats" class=IParent>QueueManager</a><a href="../files/classes/queue/QueueMonitor-php.html#QueueMonitor.stats" class=IParent>QueueMonitor</a></div></div></div><div class=SRResult id=SR_subscribeProfile><div class=IEntry><a href="../files/classes/activity/ActivityImporter-php.html#ActivityImporter.subscribeProfile" class=ISymbol>subscribeProfile</a>, <span class=IParent>ActivityImporter</span></div></div><div class=SRResult id=SR_subscriptions><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.subscriptions" class=ISymbol>subscriptions</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_switchSite><div class=IEntry><a href="../files/classes/queue/StompQueueManager-php.html#StompQueueManager.switchSite" class=ISymbol>switchSite</a>, <span class=IParent>StompQueueManager</span></div></div><div class=SRResult id=SR_sync><div class=IEntry><a href="../files/classes/queue/RedisQueue-php.html#RedisQueue.sync" class=ISymbol>sync</a>, <span class=IParent>RedisQueue</span></div></div></table><div class=SRStatus id=Searching>Searching...</div><div class=SRStatus id=NoMatches>No Matches</div><script type="text/javascript"><!--
document.getElementById("Loading").style.display="none";
document.getElementById("NoMatches").style.display="none";
var searchResults = new SearchResults("searchResults", "FramedHTML");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!