To create a profile plugin, we first recommend copying the Kunena plugin and renaming the class name from plgSocialProfilesKunena to plgSocialProfiles<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 simplest implemenation of all available profile plugins.

Background Information

JFBConnect will automatically take care of many routine things, like generating the proper 'scope' required to fetch a user's profile, store the profile mapping of which social fields should be stored in your extension, and handle the login and registration process. Creating a Social Profile plugin is simply the bridge for telling JFBConnect how to store profile data in your extension. This can be done through direct SQL calls or by calling your own models and tables. It's up to you which method will work best.

Common Variables

JFBConnect will create the following variables that can be used anywhere in your functions

  • $this->joomlaId - The Id of Joomla user that has just registered or is logging in.
  • $this->socialId - The social network's unique identifier for the user registering or logging in
  • $this->network - The system name of network the user is logging in from (facebook, google, linkedin, twitter)
  • $this->profileLibrary - The profile library for the social network being logged in from. You can find the base classes for each profile library in the /components/com_jfbconnect/libraries/profile directory
  • $this->settings - The JRegistry object for the settings the admin has chosen for your profile plugin
  • $this->db - A handle to the Joomla Database object

Function Explanation

The profile plugins are all be derived from a base class of SocialProfilePlugin defined in /libraries/sourcecoast/plugins/socialprofile.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 social networks 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->defaultSettings - 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:

  • import_avatar - When enabled, this will call the updateAvatar function in your profile plugin upon logging in or registering
  • import_always - When enabled, the profile fields and avatar will be imported on login as well as registration.

$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.

Make sure you are calling parent::construct($subject, $params); before the defaultSettings definitions so that the plugin is properly created and your values are set correct.

getProfileFields()

This function should return an array of id => name pairs of fields that can be imported into the 3rd party extension:

  • id - The system name that your extension can use later to look up how to store the field
  • name - The 'pretty' name that a user will see in the Profiles configuration area

createUser($profileData)

This function is used to create the user in the 3rd party system on registration. Many extensions need to initialize the user to a default state or create a blank row in the database so that further information can be stored.

$profileData is a JRegistry object of the user information. This data should be used for setting up the initial user as it will be a combination of data imported from the social network as well as user-input fields, like username, email address, etc.

saveProfileField($fieldId, $value)

When importing a profile, JFBConnect will automatically 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 from the getProfileFields function and the value is what is fetched from the social network. On each call, the data should be stored to the database either using a SQL query or your model/table files.

setAvatar($socialAvatar)

This function updates the avatar for the user. The $socialAvatar parameter is the name of the file on your system already downloaded from the social network to $this->getAvatarPath() (usually the /tmp directory).

setDefaultAvatar()

In the event that an avatar could not be downloaded from the social network, this function will be called for setting a default, blank, or other avatar of your choosing.

setCoverPhoto($cover)

Method called to import the user's cover photo. $cover is a JRegistry object with the following parameters:

  • path - The full path, including image name, to the cover photo downloaded from the social network
  • offsetX - The offset of the cover photo in the X dimension. This is returned by some social networks to 'crop' the photo
  • offsetY - The offset of the cover photo in the Y dimension. This is returned by some social networks to 'crop' the photo.
  • type - Currently always set to 'image/jpeg'

socialProfilesGetRequiredScope()

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.