Customizing SMF > Portals, Bridges, and Integrations

New tools to help integrating SMF with something else

(1/32) > >>

Andre N:
You want to integrate SMF with something else. Here's 2 files that will help you accomplish that.

The API will let you control SMF from your other system.

The integration hooks will let you control your other system from SMF

How to use the API:
1. Upload it to your server. Anywhere. Make sure your SMF installation is on the same server. It will seek out your installation and create a settings.txt file with the location of your Settings.php file for it's own future reference (to make it load faster)

2. In your script, include the API file. Include it anywhere you like as long as it gets included before you try to use it's functions.

--- Code: ---require_once '/path/to/api/file/smf_2_api.php'
--- End code ---

3. Call the functions. They are documented pretty well but if you have questions ask below.
Example:

--- Code: ---smfapi_logout($email);
--- End code ---
Would log the user out of SMF.
This makes the assumption that you have the users email address in the string $email. You would put this code in your other system just before or after the user is logged out there, so now they are logged out together.

4. Repeat for all the other functions you need to use.


How to use the integration hooks:
1. Make it easy on yourself and download the integration hooks skeleton file here. It has been written for maximum ease of use.

2. Upload the skeleton file onto your server. Anywhere. Make sure your SMF installation is on the same server.

3. Open the file index.php in your SMF root directory. This is SMF's 'main' index.php file. At the very top, include the hooks file:

--- Code: ---[code]require_once '/path/to/hooks/file/smf_2_integration_hooks.php'
--- End code ---
[/code]

4. Write the code inside the functions that will manipulate your other system. Taking logout as an example, inside function smf_logout_function($memberName) you might put:

--- Code: ---function smf_logout_function($memberName)
{
$sessionData = smf_session_save_function(); //save and close the SMF session

require_once('other/system/file.php');
other_system_function_logout($memberName);

smf_session_restore_function($sessionData); //load the SMF session and put session data back
}

--- End code ---

5. Repeat this process for all the hooks you want to use.

Hint: For the hooks you can get SMF variables in the functions by declaring them as global.

--- Code: ---function smf_logout_function($memberName)
{
global $user_info, $context;
//now you have the user info and context variables SMF has available to your function
}

--- End code ---

Hint: For the hooks, if you aren't sure what variables are being passed to it, do something like this:

--- Code: ---function smf_logout_function($memberName)
{
var_dump($memberName);
exit();
}

--- End code ---
Then log out of SMF and you will see what information SMF is passing to the hook.

Questions, comments and suggestions welcome. Please post your finished hook files for other systems too and it will help others using that system to integrate

edit 11/1/11 updated integration hooks file to make fixes to the save and restore functions

NEW - I made a 'REST' API for SMF that you can download and use. Check out it's thread here:
http://www.simplemachines.org/community/index.php?topic=458832.0
It let's you use all the SSI functions, all the API functions, a couple other things like post and pm, it's easy to extend, and you do it all from a different domain than your SMF install (or same if you like) :)

edit 2/29/12 updated API to version 0.1.2 to fix some bugs and make it work with magic quotes hopefully

ghrom:
Can I crate a new thread using this? Say, from Objective-C iPhone app?

Andre N:
You could, but you'd have to write your own function for that in the API. See Sources/Post.php for the code SMF uses

ghrom:
Thanks. Is there any chance you will be adding this in your api, please?

EDIT: Actually, it was easier than I thought. Thanks for pointing me in the right direction!

BREZ:
I am a bit confused.

Exactly where would the
--- Code: ---smfapi_logout($email);
--- End code ---
go in 4images script?

Navigation

[0] Message Index

[#] Next page

Go to full version