Difference between revisions of "Stream API v2"

(Storing & Displaying)
(Storing)
Line 10: Line 10:
  
 
===Storing===
 
===Storing===
Storing the data is pretty much straight forward task and is exactly the same as in V1 with use of '''CActivityStream::add''' API
+
Storing the data is pretty much straight forward task and is exactly the same as in V1 with use of '''CActivityStream::add''' API<br/>
 +
We will provide just a basic example here
 +
<syntaxhighlight lang="php">
 +
$act                = new stdClass();
 +
$act->cmd = 'example.task';
 +
$act->actor = $my->id;
 +
$act->target = 0; // no target
 +
$act->title = 'string';
 +
$act->content = 'Your activity content';
 +
$act->app = 'example.action';
 +
//$act->favicon  = '';
 +
 
 +
CActivityStream::add($act);
 +
</syntaxhighlight>
 +
<br />
 +
Lets decompose this very basic activity stream item addition
 +
* '''$act = new stdClass();''' - We want to create an activity stream object, and assign data to it, without having to formally define a class.
 +
* '''$act->cmd = 'example.task';''' - An unique command for your activity. Used for likes and comments. You can set this to any value but the best practice is to name it like '''pluginname.task'''
 +
{{alert|'''pluginname''' will be explained later. It will be the name of plugin we will create through this turorial|alert}}
 +
{{alert|'''task''' is simply a command that will help '''you''' to easier distinguesh the different activities. For example, if you want to integrate the forum component, you can replace the word ''task'' with ''newpost'' or ''newthread''|alert}}
 +
Whitespace is not allowed

Revision as of 12:22, 24 April 2013

WARNING: API examples below apply to version 2.8. To read the full Activity Stream API for older versions, click here

Overview

Since JomSocial 2.8 onwards, we bring the massive change in how activity streams are handled and introduce a set of new rules to follow which will allow more freedom for third party developers to easier customize every individual's activity stream item;
JomSocial 2.8+ streams are NOT backward compatible with JomSocial 2.6 and bellow, however, some legacy support for old activity stream exist in JomSocial 2.8 and above. This does not necessarily mean your old activity will work though.
You can still use the old API to create the activity streams, but you can't use the {multiple}...{/multiple} tags anymore as they are completely removed and will cause activity streams to break. (It will be created, but will not be shown on Front End).

Storing & Displaying

Unlike JomSocial 2.6 and bellow, where third party activity streams were created by JomSocial APIv1 and later displayed "as they are" directly from the database, in Stream API v2 we first store the activity stream in the database and then manipulate the database data with the community-type plugin

Storing

Storing the data is pretty much straight forward task and is exactly the same as in V1 with use of CActivityStream::add API
We will provide just a basic example here

$act                 = new stdClass();
$act->cmd 	= 'example.task';
$act->actor 	= $my->id;
$act->target 	= 0; // no target
$act->title 	= 'string';
$act->content 	= 'Your activity content';
$act->app 	= 'example.action';
//$act->favicon   = '';
 
CActivityStream::add($act);


Lets decompose this very basic activity stream item addition

  • $act = new stdClass(); - We want to create an activity stream object, and assign data to it, without having to formally define a class.
  • $act->cmd = 'example.task'; - An unique command for your activity. Used for likes and comments. You can set this to any value but the best practice is to name it like pluginname.task
pluginname will be explained later. It will be the name of plugin we will create through this turorial
task is simply a command that will help you to easier distinguesh the different activities. For example, if you want to integrate the forum component, you can replace the word task with newpost or newthread

Whitespace is not allowed