Project Summary

  Analyzed 1 day ago based on code collected 1 day ago.

sfOpenSocialPluginOverviewThe symfony OpenSocial plugin enables you to create a full-feature OpenSocial Application using Symfony framework. This plugin gives you a complete PHP5 OO implementation of OpenSocial JavaScript API( including Gadgets core and feature-specific Gadgets), which makes you're applications robust, scalable and immune to future OpenSocial versions. This plugin is very flexible taking advantage of both PHP5 ( all the marvelous of object-oriented programming) and the MVC provided by the Symfony framework.

Some of the features provided by this plugin are:

Accessing to People and relationships, Persistence and Activities. Setup application using the "app.yml" Making transparent DataRequests to container withing the actions and accessing to container's response inside the view. Accessing to containers environment variables both from the action and view. Create/access activities and Activities stream from container. The ability to send Messages(Email/Notifications/PrivateMessages/PublicMessages) to the Owner, Viewer or Friends in the container. Taking advantages of the Persistence available the OpenSocial containers. Having feature specific gadgets automatically imported to your application only when used in the application.

Implementation rulesAt start it's important to understand that an OpenSocial application extends the Gadget specification, that specifically corresponds to one static XML file that's imported to some container. This plugin uses one Action (that's the entry point to the application) and in "indexSucces" we import the components as we need them.

Code treeThe sfOpenSocialPlugin implements the OpenSocial API and it has more than 70 classes, so it's important to know how the plugin is structured.

'''sfOpenSocialPlugin''' '''data''' - This is where it's located the PakeTask to create projects '''lib''' - This is where the OpenSocial API is implemented. '''gadgets''' - This is where it's implemented Gadgets classes. '''helpers''' - This is where OpenSocial helpers are implemented. '''opensocial''' - This is where OpenSocial API is implemented. '''misc''' - This package include files used to initialize the application '''modules''' - This section has the sample modules with examples of how to use this plugin '''application''' - This is a sample application InstallationInstall the plugin: symfony plugin-install http://plugins.symfony-project.com/sfOpenSocialPluginCreate an OpenSocial? application: symfony init-opensocial-app UsageConfigure'''Note:''' This tutorial assumes that you have create an application called "opensocial" and an application module called "app".

The first part to create an OpenSocial application is to configure it. Because an OpenSocial application is a gadget you need to say to symfony that it should render the "indexSuccess.php" as a gadget. In this plugin you can find an gadget-layout under "sfOpenSocialPlugin/misc/app/templates/" and you need to set the "indexSuccess.php" layout as a gadget-layout. This is done by setting your "apps/opensocial/modules/application/config/view.yml" like this:

indexSuccess:
http_metas:
content-type: application/xml

layout: gadget_layoutIf you've used "init-opensocial-app"( look at HowToConfigure ) task you already have this configured and you don't need to do it again.

After you had configured the gadget you need to configure the OpenSocial application and in this plugin you can choose two ways of doing it:

You can configure it, using the file "app.yml"; Or using the ModulePrefs class to configure it in the Action.

Configuring the application means to set key-values pairs like:

title : Optional string that provides the title of the gadget description : Optional string that describes the gadget. etc... Most of this values are optional but some containers use them. For more information about those values look at Gadget Preferences. Here it's an example of how an "app.yml" file should be configured:

# default values
all:
opensocial:
base_url: http://www.palcoprincipal.com
api_version: 0.7

module_prefs: #ref: http://code.google.com/apis/gadgets/docs/reference.html#Moduleprefs_Ref
title: My First OpenSocial Application
# directory_title
# title_url
description: This application was created by sfOpenSocialPlugin
author: Daniel Botelho
author_email: botelho.daniel@gmail.com
# author_affiliation
# author_location
# screenshot
thumbnail: http://www.palcoprincipal.com/images/logos/logo_palco_3.jpg
# height
# width
# scaling
# scrolling
# singleton
# author_photo
# author_aboutme
# author_link
# author_quote

locale:
- lang: en
country: us
# messages
# language_direction

requires:
- feature: opensocial-0.7
# - feature: dynamic-height
# - feature: setprefs
# - feature: settitle
# - feature: tabs
# - feature: drag
# - feature: grid
# - feature: minimessage
# - feature: analytics
# - feature: flash
# - feature: finance

user_prefs: # ref: http://code.google.com/apis/gadgets/docs/reference.html#Userprefs_Ref
# - name: difficulty # the name of the User Preference
# display_name: asd
# urlparam: asd
# datatype: asd
# required: asd
# default_value: asd
# enum_value:
# - {value: enum1, display_value: xx }
# - {value: enum2, display_value: xx}

content: # ref: http://code.google.com/apis/gadgets/docs/reference.html#Content_Ref
type: html
# href
# cdata
But for this application to work properly should put in 'all_opensocial_base_url' your symfony project base url. This base_url is used to allow to automatically include stylesheet and Javascript files (look at OpenSocialHelper for more information)

Now that you have configured the application you can start coding it! You can find several examples under the directory our module "application" and you can test them. Also the API is well documented(in progress;) ). Here I'm going to give some simple examples and try to show all the advantages of using this plugin.

How to use PeopleRequest to get Viewer Friends ?As you've seen it's straight forward to configure the OpenSocial application using the "app.yml", but here I'm going to use the class ModulePrefs to do this.

Since we are going to configure the application from the code we should start by doing that. So in the "executeIndex" function in the "/apps/opensocial/modules/application/actions/actions.class.php" you should do this:

public function executeIndex()
{
ModulePrefs::setTitle('My First OpenSocial Application');
ModulePrefs::setDescription('This application was created by sfOpenSocialPlugin');
ModulePrefs::setAuthor('Daniel Botelho');
ModulePrefs::setAuthorEmail('botelho.daniel@gmail.com');
ModulePrefs::setThumbnail('http://palcoprincipal.clix.pt/images/logos/logo_palco_3.jpg');
}By doing this you'll be setting the Title, Description, Author, Author Email and Thumbnail of the application. After doing this, go to the file "apps/opensocial/modules/application/templates/indexSuccess.php" and this should be it's content:

Here we are saying that the indexSuccess is going to include the Component "dataRequest" that is located in the "application"( to understand how Components work you should look at Chapter 7 from "The Definite Guide to symfony").

Now we should go to the "/apps/opensocial/modules/application/actions/components.class.php" and configure this component like this:

public function executeDataRequest()
{
$this->viewer_friends = new OSViewerFriends('viewer_friends');

$this->people_request = new OSPeopleRequest($this->viewer_friends);
$this->people_request->addProfileDetails(OSPersonField::PROFILE_URL);

$data_request = new OSDataRequest('requestInfo');
$data_request->addRequest($this->people_request);

$this->data_response = $data_request->send(true);
echo JSFunction::addJSTags(GadgetsUtil::registerOnLoadHandler($data_request->getDataRequestFunction()));
}Then go to "apps/opensocial/modules/application/templates/dataRequest"

function getJSFunction()->getName() ?>(getJSFunction()->getArgs() ?>)
{
var html = '';
getData($people_request); ?>


getVarName() ?>.each(function(getVarName() ?>) {
var thumb = getField(OSPersonField::THUMBNAIL_URL); ?>
var profile = getField(OSPersonField::PROFILE_URL); ?>
html += '' +'';
document.getElementById('viewer_friends').innerHTML = html;
});
}
After doing this, go to "http://

/index.php/application" and this code should be generated:

Share

In a Nutshell, sfopensocialplugin...

 

Activity

30 Day Summary

Feb 27 2015 — Mar 29 2015

12 Month Summary

Mar 29 2014 — Mar 29 2015

Community

Ratings

Be the first to rate this project
 
Click to add your rating
 
Review this Project!