News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Questions/Comments on "A guide to the SMF integration hooks"

Started by Orstio, May 26, 2007, 05:19:48 PM

Previous topic - Next topic

Orstio

That should work, yes, though you should be aware it will also add the overhead of your functions.php to your forum load.

PS:  Something else you might also notice is that every external page shows as the forum main page in the whos online list.  You can circumvent that by using the ssi_log_online function on the non-forum pages.

Mike Bobbitt

Thanks, I'll give that a shot. functions.php shouldn't add too much, it really just defines about 10 common functions but doesn't do too much else.

Mike Bobbitt

Thanks for the PS tip, I've noticed that too... I currently use writeLog(); but is ssi_log_online(); better?


Vik_R

These hooks look like they might be just what I've been looking for. I'm building a site using CodeIgniter, and I want to integrate it with an SMF forum.

Here's the thing. Registering on a forum means looking at a whole lot of intimidating legalese. For example, here's the registration text for SMF:

QuoteYou agree, through your use of this forum, that you will not post any material which is false, defamatory, inaccurate, abusive, vulgar, hateful, harassing, obscene, profane, sexually oriented, threatening, invasive of a person's privacy, adult material, or otherwise in violation of any International or United States Federal law. You also agree not to post any copyrighted material unless you own the copyright or you have written consent from the owner of the copyrighted material. Spam, flooding, advertisements, chain letters, pyramid schemes, and solicitations are also forbidden on this forum.

Note that it is impossible for the staff or the owners of this forum to confirm the validity of posts. Please remember that we do not actively monitor the posted messages, and as such, are not responsible for the content contained within. We do not warrant the accuracy, completeness, or usefulness of any information presented. The posted messages express the views of the author, and not necessarily the views of this forum, its staff, its subsidiaries, or this forum's owner. Anyone who feels that a posted message is objectionable is encouraged to notify an administrator or moderator of this forum immediately. The staff and the owner of this forum reserve the right to remove objectionable content, within a reasonable time frame, if they determine that removal is necessary. This is a manual process, however, please realize that they may not be able to remove or edit particular messages immediately. This policy applies to member profile information as well.

You remain solely responsible for the content of your posted messages. Furthermore, you agree to indemnify and hold harmless the owners of this forum, any related websites to this forum, its staff, and its subsidiaries. The owners of this forum also reserve the right to reveal your identity (or any other related information collected on this service) in the event of a formal complaint or legal action arising from any situation caused by your use of this forum.

You have the ability, as you register, to choose your username. We advise that you keep the name appropriate. With this user account you are about to register, you agree to never give your password out to another person except an administrator, for your protection and for validity reasons. You also agree to NEVER use another person's account for any reason.  We also HIGHLY recommend you use a complex and unique password for your account, to prevent account theft.

After you register and login to this forum, you will be able to fill out a detailed profile. It is your responsibility to present clean and accurate information. Any information the forum owner or staff determines to be inaccurate or vulgar in nature will be removed, with or without prior notice. Appropriate sanctions may be applicable.

Please note that with each post, your IP address is recorded, in the event that you need to be banned from this forum or your ISP contacted. This will only happen in the event of a major violation of this agreement.

Also note that the software places a cookie, a text file containing bits of information (such as your username and password), in your browser's cache. This is ONLY used to keep you logged in/out. The software does not collect or send any other form of information to your computer.

Yikes!  I don't want to show all that to people who just want to register on the CI site I'm building. I just want them to be able to register quickly and easily, probably with email verification.

Of course, if they want to use the forum, then they need to see all that legalese.

I guess I could do this:

- Users could register on the forum, and my site will check the SMF database to look for their name and password when they log onto my site.

- Users could also register on my site and that auto-adds them to the forum. But then how do I make sure they see the legalese before they start posting to the forum?

Thanks in advance to all for any info.


Orstio

You could add a field to the profile info (something like "seen_forum"), and set it to false.  If they try to access the forum, and that field is false, you direct them to a page that shows them the TOS, and when they agree, the form submission sets it to true.

You could set this all up in CI, so it wouldn't need to touch the forum.

Vik_R

Thanks very much, Orstio. If they access the SMF forum from an SMF login page, is there a hook I can use to check the "seen_forum" field and direct them to the TOS page if necessary?

Orstio

It depends where you would want to trigger it.  You could do it on the login event with the integrate_login hook, or you could do it on the initial page load of the forum with the integrate_pre_load hook.

It is important to note that this hook occurs in the workflow before the user information is loaded, so that may be something you would need to do in the hook function.

Vik_R

Excellent!  Now, I still have two questions about how these hooks are used.

1) To make them accessible, is it correct that I just put this at the top of my php code?

Quoterequire($smf_path."/index.php");

2) Suppose I want to use the integrate_login hook. How do I get my own code to be called via the integrate_login hook?

Thanks very much in advance for this great info!

Orstio

Quote1) To make them accessible, is it correct that I just put this at the top of my php code?


Quote
require($smf_path."/index.php");

No, that will load and display SMF.  It will also start up the hooks, but only because SMF is loaded.

What you need is the hook startup:

http://www.simplemachines.org/community/index.php?topic=173483.0#post_starting_up

Quote2) Suppose I want to use the integrate_login hook. How do I get my own code to be called via the integrate_login hook?

See the post linked above.

Vik_R

Okay, I think I'm starting to get it. I use the following array:

Quote//define the integration functions
define('SMF_INTEGRATION_SETTINGS', serialize(array(
   'integrate_change_email' => 'change_email_function',
   'integrate_change_member_data' => 'change_member_data_function',
   'integrate_reset_pass' => 'reset_pass_function',
   'integrate_exit' => 'exit_function',
   'integrate_logout' => 'logout_function',
   'integrate_outgoing_email' => 'outgoing_email_function',
   'integrate_login' => 'login_function',
   'integrate_validate_login' => 'validate_login_function',
   'integrate_redirect' => 'redirect_function',
   'integrate_delete_member' => 'delete_member_function',
   'integrate_register' => 'register_function',
   'integrate_pre_load' => 'pre_load_function',
   'integrate_whos_online' => 'whos_online_function',
)));

For example, if I want to use the integrate_login hook, I edit the line for that function in the above array like this:

   
Quote'integrate_login' => 'my_login_function',

Then I define a function like this in my php code:

Quotefunction my_login_function()
{
}

...and it will be called by SMF at the correct time. Am I correct so far?

Now, I still think I need to somehow do some sort of a require or require once at the top of my php code, so that SMF gets started.  Is this correct, and if so, what do SMF file do I use in the require statement?

Orstio

You have the right idea.

The integrate_login hook is called during SMF's login procedure.  So, as long as the form submits to SMF, you don't need to worry about including SMF in the workflow, because it will be the workflow.

What you will probably need to do is either create a whole bridge (similar to the Mambo bridge, where the entire SMF workflow is wrapped in the CMS), or include/require a file at the beginning of SMF that will define the integration array.

Vik_R

Quoteinclude/require a file at the beginning of SMF that will define the integration array.

That sounds like a very good way to go. How can I tell SMF where to find the php functions I specify in the SMF_INTEGRATION_SETTINGS array?

Orstio

As long as that file is included near the beginning of SMF's index.php, it will find them.

You could also use the integrate_pre_include hook by adding the variable=>value pair to the smf_settings table:

integrate_pre_include => my_include_file.php

Vik_R

Very cool! So, I could have a library php file, that just contains the functions I need to use for the hooks.

I guess I should include this library file near the beginning of SMF's index.php, so that my functions will be called even if the user enters the system through SMF, rather than through my CI app.

QuoteAs long as that file is included near the beginning of SMF's index.php, it will find them.

Should I directly edit the SMF index.php file, to include my library file (via a 'require' statement), or is there a more elegant way to do this?

Orstio

QuoteShould I directly edit the SMF index.php file, to include my library file (via a 'require' statement), or is there a more elegant way to do this?

Unfortunately, there is no better way at this time.

Vik_R

It's cool - it's just one line. This is very cool. Thank you so much for all your help!

Vik_R

I'm getting started today on implementing the good advice I have received here, and adding an SMF forum to my site. :) 

When a user registers on my CI site, rather than on my SMF forum, I would like to auto-add them to my SMF forum database, as we discussed.  What's the best way for me to do this? Should I use a routine from ssi.php, or from smf.api - or is there an even better way? Thanks very much in advance for your thoughts.



Advertisement: