Creating Facebook LikeBox Module
- Details
- Category: Joomla Module Development
- Last Updated on Sunday, 11 March 2012 15:30
- Hits: 3203
This Joomla Module Tutorial will teach you how to develop Facebook likebox module for your site as shown below. Facebook Likebox shows the latest post and fans of the facebook page on your site.

The code for Facebook Likebox is taken from http://developers.facebook.com/docs/reference/plugins/like-box/. Here is the sample code in <iframe> tag.
- <iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FLukmyworld%2F132967643489557&width=185&height=550&colorscheme=light&show_faces=true&border_color&stream=true&header=false" scrolling="yes" frameborder="0" style="border:none; overflow:hidden; width:185px; height:550px;" allowTransparency="true">
- </iframe>
We have to use above code to display facebook likebox on the site in our module.
In the above <iframe> tag the one shown in bold is the address of the facebook page.
Creating Variable Request
In the .xml file we will add <config> tag to add variable request like shown below.
Lets create variable request for width, height, facebook link page, show facebook header, show fans, include stream.
- <config>
- <fields name="params">
- <fieldset name="basic">
- <field
- name="pagelink"
- type="text"
- label="Facebook Page Link"
- description="Link of the Facebook Page to be shown, Example:http://www.facebook.com/pages/Lukmyworld/132967643489557" />
- <field
- name="width"
- type="text"
- default="185"
- label="Module Width"
- description="Facebook Likebox Width in px" />
- <field
- name="height"
- type="text"
- default="550"
- label="Module Height"
- description="Facebook Likebox Height in px" />
- <field name="fbfans" type="list" default="1" label="Show Fans" description="Show Fans Thumbs or not ">
- <option value="1">Show</option>
- <option value="2">Hide</option>
- </field>
- <field name="include_stream" type="list" default="1" label="Include Stream" description="Include or not the stream of latest posts from your Facebook Page.">
- <option value="0">No</option>
- <option value="1">Yes</option>
- </field>
- <field name="fbheader" type="list" default="2" label="FanBox Header" description="Show Header Image for find us of Like box if fans or stream is enabled">
- <option value="2">Show</option>
- <option value="1">Hide</option>
- </field>
- </fieldset>
- </fields>
- </config>
<fields> tag contains the name attribute which will be used in the php file to access the variable.
<fieldset> tag groups the variable request under ‘name’ attribute.
<field> tag contains the variable request with various attribute such as name of the variable,type of the variable, default value of the variable, label shown in the module and description shown on mouse hover.
Accessing Variable Request
A variable defined above have to be accessed in the php file.It is done by the get() function.
where,
$params is the <fields> tag name defined in .xml file.
Now we have to use above variable request to create <iframe> tag and display that <iframe>.Using the above <iframe> tag and creating <iframe> tag using the variable request.
- $inputfb = '<iframe src= "//www.facebook.com/plugins/likebox.php?href='.$pagelink.'&width='.$width.'&height='.$height.'&colorscheme=light&show_faces='.$fbfansbool.'&border_color&stream='.$incStreambool.'&header='.$fbHeaderbool.'" scrolling="yes" frameborder="0" style="border:none; overflow:hidden; width:'.$width.'px; height:'.$height.'px;" allowTransparency="true" ></iframe>';
Here '.' is a concatenation operator.
Files Required
1) mod_fblikebox.php: This file is the entry point for the module. It will perform necessary initializations and call helper routine to collect necessary data and include the template which will display module output.
2) helper.php: This file contains the helper class which will collect necessary data to be used in the module from database or any other sources.
3) mod_fblikebox.xml: This file contains the information about the module. This is the installation file for the module.
4) tmpl/default.php: This is the file used for displaying the module output.
1) Creating file mod_fblikebox.php
The Complete code of mod_fblikebox.php is
2) Creating file helper.php
This file contains the class as defined in mod_ fblikebox.php ,here it is modFblikeboxHelper class and contains function getFBInput().
The complete code of helper.php is
- <?php
- // no direct access
- defined( '_JEXEC' ) or die( 'Restricted access' );
- class modFblikeboxHelper
- {
- static function getFBInput(&$params)
- {
- $width = $params->get('width');
- $height = $params->get('height');
- $fbfans = $params->get('fbfans');
- $incStream = $params->get('include_stream');
- $fbHeader = $params->get('fbheader');
- $pagelink = $params->get('pagelink');
- if($fbfans == 1)
- $fbfansbool = "true";
- else
- $fbfansbool = "false";
- if($incStream == 1)
- $incStreambool = "true";
- else
- $incStreambool = "false";
- if($fbHeader == 2)
- $fbHeaderbool = "true";
- else
- $fbHeaderbool = "false";
- $src = $pagelink.'&width='.$width.'&height='.$height.'&colorscheme=light&show_faces='.$fbfansbool.'&border_color&stream='.$incStreambool.'&header='.$fbHeaderbool;
- $inputfb = '<iframe src= "//www.facebook.com/plugins/likebox.php?href='.$src.'" scrolling="yes" frameborder="0" style="border:none; overflow:hidden; width:'.$width.'px; height:'.$height.'px;" allowTransparency="true" ></iframe>';
- return $inputfb;
- }
- }
- ?>
3) Creating installation file mod_fblikebox.xml
This file contains the information about the module.
The complete code of mod_fblikebox .xml is
- <?xml version="1.0" encoding="utf-8"?>
- <extension type="module" version="2.5" client="site" method="upgrade">
- <name>Facebook Like Box</name>
- <author>Larenge Kamal</author>
- <version>1.7</version>
- <description>Facebook LikeBox Module(by Lukmyworld).</description>
- <files>
- <filename>mod_fblikebox.xml</filename>
- <filename module="mod_fblikebox">mod_fblikebox.php</filename>
- <filename>index.html</filename>
- <filename>helper.php</filename>
- <filename>tmpl/default.php</filename>
- <filename>tmpl/index.html</filename>
- </files>
- <config>
- <fields name="params">
- <fieldset name="basic">
- <field
- name="pagelink"
- type="text"
- label="Facebook Page Link"
- description="Link of the Facebook Page to be shown, Example:http://www.facebook.com/pages/Lukmyworld/132967643489557" />
- <field
- name="width"
- type="text"
- default="185"
- label="Module Width"
- description="Facebook Likebox Width in px" />
- <field
- name="height"
- type="text"
- default="550"
- label="Module Height"
- description="Facebook Likebox Height in px" />
- <field name="fbfans" type="list" default="1" label="Show Fans" description="Show Fans Thumbs or not ">
- <option value="1">Show</option>
- <option value="2">Hide</option>
- </field>
- <field name="include_stream" type="list" default="1" label="Include Stream" description="Include or not the stream of latest posts from your Facebook Page.">
- <option value="0">No</option>
- <option value="1">Yes</option>
- </field>
- <field name="fbheader" type="list" default="2" label="FanBox Header" description="Show Header Image for find us of Like box if fans or stream is enabled">
- <option value="2">Show</option>
- <option value="1">Hide</option>
- </field>
- </fieldset>
- </fields>
- </config>
- </extension>
4) Creating file tmpl\default.php
This file contains the output to be displayed by the module. This file has the same scope as that of the mod_fblikebox.php. So the variables defined in mod_fblikebox.php can be directly accessed in this file. ‘$fbin’ variable defined in mod_fblikebox.php can be directly accessed here.
The complete code of tmpl\default.php is
5) Creating file index.html common to all
The complete code of index.html is
which will display an empty page.
Now create the zip file of the folder ‘mod_fblikebox’ which contains the following files.
1) mod_fblikebox.php
2) index.html
3) mod_fblikebox.xml
4) helper.php
5) tmpl\default.php
6) tmpl\index.html
The above zip file can now be installed using Joomla extension manager.
After installing the module,’ Facebook Like Box’ module will appear in the module manager.Variable request will also appear on the right side when this new module is opened in the joomla administrator as shown below.

Enable this new module and set the position for display of this module on the right side to see the output of the module.

Comments (0)