× Joomla Facebook Connect support forum

Topic-icon Launch script at registration

Active Subscriptions:

None
15 years 4 months ago #6708 by justberare
Hi,

First of all, thanks a lot for this great component !

Now, I have a small question which i believe could be answered with a limited amount of code. I just would like to add a query that fetch for each user a list of user ids corresponding to the user's friends. I guess the friends.get function could do it but I don't know how to use it in fact.
Basically, with the approval of each user, I would love to see a jos_fb_friends table filled with (user_id, userfb_id, friendfb_id) with as many lines as each user has friends. I don't know if that is clear and if it's not please tell me.

To be more specific, what i'm trying to make is the ability for 2 jomsocial users (connected by fbconnect) to see how much friends they have in common and what is the percentage those common friends represents out of the number of each users' friends.

Thanks a lot..

E.
The topic has been locked.
Active Subscriptions:

None
15 years 4 months ago #6717 by justberare
Hi again,

I actually did the previous thing myself (even I didn't imagine that would work). If someone's interested in the code just pm me.

Now I was wondering if it would be easy to launch a side-script on registration or profile modification.

Thank you

E.
The topic has been locked.
Support Specialist
15 years 4 months ago #6728 by alzander
Edouard,
Sorry for the delayed response, and great job with implementing the function. The friend stuff is actually on our task list, but down the list a bit. If you wouldn't mind sharing the code, we'd love to see what you've done and possibly adapt it for an upcoming release.

As for launching a script, it depends on exactly what you're looking for. You should likely create your own User Plugin to do what you're looking for. Within that plugin, you can add some code to different functions like "onBeforeStoreUser", which is triggered before a user updates their profile, or onLoginUser which is called when they login, etc. Alternatively, if it's a minor change, you could put the call directly in our JFBConnect User plugin, but that will get overridden whenever you install a new version.

To create your own plugin, there's a lot of great tutorials on how to do it. Basically, you should start with the Joomla Example plugin, installed with every Joomla installation. Modify the xml file for that extension to change the name and a few other settings and then install the updated xml and php files. Then, you can add the code to the functions already defined there as necessary. To check if the user is a Facebook user, you can use the following code:
jimport('joomla.filesystem.file');
$libraryFile = JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'libraries'.DS.'facebook.php';
if (!JFile::exists($libraryFile))
   return true; # don't prevent logging in, but don't do anything Facebook related either
require_once ($libraryFile);
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $jfbcLibrary->getUserId(FALSE);
if ($fbUserId)
{ 
// Do something
}

Hope this helps get you started. If you have more specific questions, don't hesitate to ask!
The topic has been locked.