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.
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.
JFBConnect will create the following variables that can be used anywhere in your functions
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.
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:
$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.
This function should return an array of id => name pairs of fields that can be imported into the 3rd party extension:
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.
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.
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).
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.
Method called to import the user's cover photo. $cover is a JRegistry object with the following parameters:
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.