Yii 1.1: faceplugs

A wrapper for facebook plugins.

A wrapper for Facebook plugins using the Javascript SDK and the Open Graph protocol.

All Facebook plugins are available.

Current Version: 1.7.1


Developed and tested on Yii 1.1.5-10. Should work on all 1.1.x branch.



Download and extract the tarball to your extensions folder.

Git Submodule

Alternatively, you may checkout the project as a submodule in Git. This will allow you to update to the latest version right in your Git-enabled project. More on Git submodules.

$ git submodule add git@github.com:digitick/yii-faceplugs.git protected/extensions/faceplugs
$ git submodule init
$ git submodule update


Application ID

Some plugins will not work without a Facebook application ID. The easiest way is to set it for all facebook plugins in your site in your Yii configuration file, as the 'fbAppId' parameter :

return array(
    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params' => array(
        'fbAppId' => '123456789',

Note that you can override this setting when creating the widget.

You may also set the application ID for all plugins of the same type. In your Yii configuration file :

return array(
    'components' => array(
        'widgetFactory' => array(
            'widgets' => array(
                'LiveStream' => array(
                    'app_id' => '123456789',

Finally, you can set the application ID at each instance of plugin creation, this is done by passing the 'app_id' parameter.

Creating the widget

The extension uses the javascript SDK version of the facebook plugins, which work with the Open Graph protocol.

Open Graph properties, except for 'url', are passed as the 'og' parameter to the plugin.

$og = array(
    'title' => 'The coolest site on the WWW',
    'type' => 'website',
    'site_name' => 'My Awesome Site',
    'image' => $this->createAbsoluteUrl('/images/logo.gif'),

To instantiate the plugin, pass the Open Graph properties and the URL of the current page. The application ID should also be set if it isn't defined in the config file.

$this->widget('ext.faceplugs.LikeButton', array(
   'app_id'=>'APPID', // not needed if set in Yii configuration file
   'url' => $this->createAbsoluteUrl('/'),
   'og' => $og

Setting options

All the Facebook plugins have options, check the Facebook plugins documentation pages or simply look at the classes. Options are set as normal widget parameters.

$this->widget('ext.faceplugs.LikeButton', array(
   'url' => $this->createAbsoluteUrl('/'),
   'og' => $og,
   'layout' => 'button_count',
   'action' => 'recommend',
   'colorscheme' => 'dark',

Setting plugin options

These are set as normal widget parameters, and control the initialization and behavior of the plugin.

  • status : Check user's login status.
  • cookie : Enable cookies to allow the server to access the session.
  • xfbml : Parse XFBML.
  • async : Load the Facebook init script asynchronously.
  • debugMode : When active, it loads the debug version of the SDK (en_US only).

Setting the locale

In normal use, the plugin loader will attempt to use the locale of the Yii application automatically. However, not all locales defined by Yii are available in Facebook. Some common fallbacks have been defined (should cover 98% of all internet users), but in some cases you may want to define the locale manually. This is done by passing the 'locale' parameter on widget creation.


Version History

Total 9 comments

#4206 report it
ianaré at 2011/06/15 05:57pm

A github repo has been added for this project.

It is now a simple matter to host code changes and to contribute back to the extension.

Compliance with the LGPL is not needed for usage on a website, the restrictions do not apply to server side code. Only when distributing (i.e. as an appliance), only if modifications to the extension have been made, and not to any other code.

#3923 report it
Backslider at 2011/05/21 04:33pm
Need to understand the LPGL

You need to understand the LPGL. Any modification of your program makes it a derivative work, thus it is both impossible to use in a commercial application or to contribute anything back. The necessity to only link to the library is far too restrictive and defeats the very purpose of why you have chosen the LPGL.

Needless to say, it won't be used, nor for that matter can or will anything be contributed back. Were it BSD or any other truly free and open licence, then it could be used as required and also contributed back to.

#3922 report it
ianaré at 2011/05/21 04:04pm

Actually development was sponsored by a commercial web site.

The license was specifically chosen to allow other businesses to use it, but that any modifications to it must be shared back when these modifications are distributed. As it is LGPL, it isn't "viral", code incorporating this extension does NOT need to be GPL.

Usage on a web site does not constitute distribution.

The extension does not use any Facebook code, it only generates JS/HTML which interacts with the FB Javascript API.

#3921 report it
Backslider at 2011/05/21 02:21pm

Duh.. Yii Framework is released under the BSD as are many applications which are feely contributed back to. It has nothing to do with sharing, but rather that the GPL makes it impossible to use the code in commercial applications. Thus you won't be receiving anything from from the biggest contributors to open source. Think about it.

The LGPL does NOT make it mandatory to contribute anything.

LGPL is not compatible with the Apache 2.0 license under which the SDK you have used is released, so your re-licensing is invalid anyway.

#3919 report it
ianaré at 2011/05/21 08:45am
waste of breath

Tired of people wanting to use my work but not wanting to share any improvements they make to it.

Unless of course you are simply clueless as to what the LGPL actually restricts and in which circumstances.

#3918 report it
Backslider at 2011/05/21 02:11am
Waste of Space

Tired of looking through Extensions only to find GPL code.

Yii Framework is BSD and anything like this should be also.


#3544 report it
intel352 at 2011/04/18 01:56pm
Add this to your instructions

If someone wants to ease pre-configuration of a widget, here's how (better than your config/param solution): http://www.yiiframework.com/doc/guide/1.1/en/topics.theming#customizing-widgets-globally

#3387 report it
got 2 doodle at 2011/04/08 09:42am
Great addition to the repository

Just a note, I added another exception to the rule regarding facebook locales

// canada
                else if ($lang === 'en' && $locale !== 'en_ca') {
            $locale = 'en_US';
#2615 report it
Gustavo at 2011/01/23 09:03am

I was about to create one for personal use, and you just posted it Good work!

Leave a comment

Please to leave your comment.

Create extension