JFBConnect

JFBConnect

Complete Facebook Integration for Joomla

To create a profile plugin, we first recommend copying the Kunena plugin and renaming the class name from plgJFBCProfilesKunena to plgJFBCProfiles<YourExtension> and doing the same with any references to Kunena in the XML file. Even if you don't know or use Kunena, this plugin is recommended as a starting point as it's the cleanest implemenation of all available profile plugins.

Function Explanation

The profile plugins should all be derived from a base class of JFBConnectProfileLibrary defined in /components/com_jfbconnect/libraries/profile.php. While any functions defined in the base class can (and in some cases should) be overriden in your profile plugin, there are a few main functions that almost all profile plugins should implement for properly pulling data from Facebook into your extension. Each is described below in detail. 

Constructor

The constructor is required to be declared in your profile plugin and is responsible for setting up a few required variables which the base classes uses to automate a lot of the integration:

$this->settings - This is an array of any configuration parameters for your extensions. The value set here is the default, but by defining the value here, you'll be able to use other functions to store overrides in the database.. While you are free to define any variables here you like, the following parameters should be set:

  • profiles_xxxx_import_avatar - When enabled, this will call the updateAvatar function in your profile plugin upon logging in or registering
  • profiles_xxxx_import_always - When enabled, the profile fields and avatar will be imported on login as well as registration.
  • profiles_xxxx_field_map - This is an array of FB Field (key) -> Extension Field (value) mappings. In all JFBConnect plugins, these are defaulted to blank since we allow these to be configured in the admin area. If you want to hard-code the mappings, you can do so in the constructor. See the Configurable Field Map section below for more information.

$this->_componentFolder or $this->_componentFile - These values define a file or folder from your component that JFBConnect can check to verify installation of the extension. This is done to prevent fatal errors or other 'bad' behavior if the profile plugin is enabled but the extension isn't installed. One of these values must be defined.

At the end of the constructor, make sure you are calling parent::construct($subject, $params); so that the base class can set itself up properly.

jfbcProfilesGetRequiredPermissions()

Optional function to set any additional permissions that are requested during the login process. If you're using the field_map configuration field, all permissions for those fields will automatically be requested. This setting should only be for additional permission requests outside of field mapping (for publishing status, reading news feeds, offline access, etc).

Returned value should be an array of values to request. Duplicate values set by your plugin, or requested by others, will automatically be eliminated so as not to cause problems. For all available permissions, see Facebook's Permissions documentation.

jfbcProfilesOnAuthenticate($jUserId, $fbUserId)

This function is used for checking if the user is allowed to login. If your extension has reasons to block certain users from logging into the site using Facebook, you can implement this function and return true to allow the user to login or false to deny them. If your extension has no reason to block users, you don't need to implement this function.

The parameters passed are $jUserId which is the user's Joomla ID and $fbUserId which is the user's Facebook ID.

jfbcProfilesOnRegister($jUserId, $fbUserId)

This function is called when a user is initally registering on your site. Most JFBConnect plugins just call the same logic as OnLogin (below), which is importProfile() 

The parameters passed are $jUserId which is the user's Joomla ID and $fbUserId which is the user's Facebook ID.

jfbcProfilesOnLogin()

This function is called when a user has successfully logged in.Used to do something when the user logs in. This is usually where the users profile is imported from FB into a database. Generally, this should just call parent::importFBProfile(); which will call the function below repeatedly to make your life easier. 

addFieldToDb($fieldId, $value)

When importing a profile, the base class will parse your field_mapping setting and fetch the correct fields from Facebook and pass each one to this function. The field ID is set by you as the key in the field_map setting and the value is what is fetched from Facebook. On each call, you should return the SQL call required for importing this field. Once addFieldToDb has been called for each field, the entire query will be run.

updateAvatar($fbAvatar, $userId, $fbUserId)

This function updates the avatar for the user. The $fbAvatar parameter is the path on your system to a file already downloaded from Facebook. The $userId is the user's Joomla Id. The $fbUserId is the user's Facebook id.

setDefaultAvatar($jUserId)

In the event that an avatar could not be downloaded from Facebook, this function will be called for setting a default, blank, or other avatar of your choosing. $jUserId is the user's Joomla Id.

Configurable Field Maps


As stated above, you can choose to hard-code the field mappings from your extension to Facebook by setting the profiles_xxx_field_map setting in the constructor. Alternatively, if you'd like to be able to easily change these in the admin area (or any other settings), you must create a /tmpl/configuration.php file for your plugin. Here, just put select lists for each of your fields, give them an integer id (used as the $fieldId in addFieldToDb) and show the Facebook fields to map to it (see other profile configuration files for reference). Additionally, by using the usermap functionality, JFBConnect will automatically ask for the permissions you need to get that information. 

Learn More About Us

SourceCoast was founded in 2008. Bringing over 20 years of technology experience to the table, we're a small company devoted to customer happiness. It's our utmost goal to make sure you're happy with your decision to use our products.

Meet the Team

Newsletter

Stay up to date with new releases and features and join our newsletter