Advertisement:

Author Topic: Questions/Comments on "A guide to the SMF integration hooks"  (Read 161111 times)

Orstio

  • Guest
http://www.simplemachines.org/community/index.php?topic=173483.0

I've locked the guide topic to keep it strictly informational.

If you would like to see more information, or different information than what I have provided, please let me know in this topic.

Offline wahlau

  • Newbie
  • *
  • Posts: 6
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #1 on: July 04, 2007, 06:53:42 PM »
Hi Orstio,

i have a feeling your guide is the answer to my problem... only thing, i have no idea how to start with your guide. Is there a simple example, like how should i use the hooks, or which file should i include in my own scripts?

which CMS bridge you have applied the hook systems? then i can download and view it myself...

thanks!

wahlau.

Orstio

  • Guest
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #2 on: July 04, 2007, 07:16:27 PM »
Good questions.

All of the bridges use the hook system.  The file to include in your own scripts is mainly just SMF's index.php.

The simplest of the bridges is currently the iGamingCMS bridge.  That would probably be a nice beginner example.  The hooks are defined and used in the file smf.php of that package.

Offline wahlau

  • Newbie
  • *
  • Posts: 6
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #3 on: July 05, 2007, 03:54:11 AM »
i tried, but i think i don't get it :)


say my system is stored in /, and smf in /forum. so i would perform the normal login from /index.php. Following your guide, i will include the hooks in /integrate.php.

so say when i wish to have the integration, in my index.php i will include /integrate.php, which will include /forum/index.php? as soon as i call the method integrate_login($username, $pass, $cookietime), the hooks will take place and i will automatically be logged into SMF system?

hope my example clarifies my understanding... thank you

Orstio

  • Guest
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #4 on: July 05, 2007, 07:01:19 AM »
No, the method integrate_login($username, $pass, $cookietime) will be called when a user attempts to login in SMF.

This would mean that your login form should submit to the integration:

<form action="integrate.php?action=login2" method="post">

In the integrate_login function, you would put the code that will log the user into the CMS.

Offline wahlau

  • Newbie
  • *
  • Posts: 6
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #5 on: July 05, 2007, 08:20:47 AM »
but in that case integrate.php should never be used directly, right? since by loading integrate.php, it will display the standard login page of SMF (from my understanding, integrate.php has an include(/forum/index.php) line...)

thanks.. i have the feeling i am close to the solution. shall try tonight.


Offline jjgallow

  • Jr. Member
  • **
  • Posts: 122
    • StockDiaries.com
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #6 on: July 06, 2007, 12:32:04 AM »
Hey,

I'm just delving into the world of SMF integration, and I really appreciate these hooks.

Being a computer geek, I have to say that my mind works a little differently and instructions may or may not teach me anything at all, no matter how good they are.

Give me one example of a plugin that uses these hooks, and I'm good to go.  While I did see a snippet of code there, I was unable, initially, to relate where that code might go.  SMF?  The CMS?  A plugin?  (just as an example).

Basically, an example plugin with hooks would do wonders.  I'm sure I'm not the only one that is incapable of relating to instructions  :)

Offline jjgallow

  • Jr. Member
  • **
  • Posts: 122
    • StockDiaries.com
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #7 on: July 07, 2007, 02:44:03 AM »
Ok,

I'm somewhat up to speed now, and I'm definitely going to be utilizing these hooks.

 A couple observations:

integrate_register occurs JUST before the user registers.  Which, unfortunately, means that it does not know the User ID, for instance.  In my code, it is essential that the User ID is tracked.  It really should be with any integration code, imho, to properly identify that individual.

I'm wondering if this hook might better occur right After the user registration, and include ID_MEMBER in it's array?


My other comment is that I think these hooks are great, and could be used for much more than integration with a little tweaking.  I hope to see more this in future versions!

Orstio

  • Guest
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #8 on: July 08, 2007, 08:48:23 AM »
Yeah, that makes sense.

You can make the change yourself, actually.  It's in Subs-Members.php:

Code: [Select]
// Call an optional function to validate the users' input.
if (isset($modSettings['integrate_register']) && function_exists($modSettings['integrate_register']))
$modSettings['integrate_register']($regOptions, $theme_vars);

// Register them into the database.
db_query("
INSERT INTO {$db_prefix}members
(" . implode(', ', array_keys($regOptions['register_vars'])) . ")
VALUES (" . implode(', ', $regOptions['register_vars']) . ')', __FILE__, __LINE__);
$memberID = db_insert_id();

Change to:

Code: [Select]
// Register them into the database.
db_query("
INSERT INTO {$db_prefix}members
(" . implode(', ', array_keys($regOptions['register_vars'])) . ")
VALUES (" . implode(', ', $regOptions['register_vars']) . ')', __FILE__, __LINE__);
$memberID = db_insert_id();

// Call an optional function to validate the users' input.
if (isset($modSettings['integrate_register']) && function_exists($modSettings['integrate_register']))
$modSettings['integrate_register']($regOptions, $theme_vars);

Then you'll just need to global $memberID in your integration function.
« Last Edit: July 08, 2007, 08:51:06 AM by Orstio »

Offline giangnt

  • Newbie
  • *
  • Posts: 2
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #9 on: July 09, 2007, 05:55:38 AM »
Hi orstilo,
THis is my code to integrate login from SMF to my CMS,but it don't work.Could you help me
<?php
define('SMF_INTEGRATION_SETTINGS', serialize(array(
   'integrate_change_email' => 'integrate_change_email',
   'integrate_reset_pass' => 'integrate_reset_pass',
   'integrate_exit' => 'ig_smf_exit',
   'integrate_logout' => 'integrate_logout',
   'integrate_outgoing_email' => 'integrate_outgoing_email',
   'integrate_login' => 'integrate_login',
   'integrate_validate_login' => 'integrate_validate_login',
   'integrate_redirect' => 'integrate_redirect',
   'integrate_delete_member' => 'integrate_delete_member',
   'integrate_register' => 'integrate_register',
   'integrate_pre_load' => 'integrate_pre_load'
)));


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

function integrate_login($user, $pass, $cookietime)
{
   
   global $database;
    
      $sql="SELECT * FROM #__bibi_account WHERE #__bibi_account.username='".trim($username)."'";
      $database->setQuery($sql);
      $row=$database->loadObjectList();
      $pwd='';
      if (count($row)>0 )
      {
         if ( $row[0]->activate==1)
         {
            if ($password == '') {
            $pwd     = 1;
            $pwd    = md5( $pwd );
            }
            else{
                  $pwd    = trim( $password );
                  $pwd   = md5($pwd);
            }            
            $query="SELECT * FROM #__bibi_account WHERE password='".$pwd."' AND  username='".trim($username)."'";
            $database->setQuery($query);
            $database->loadObject($rows);         
            if(count($rows)>0)
            {
               // set remember me cookie if selected
               
               
               create_cookie('username',$rows->username,$cookieTime);
               create_cookie('username',$rows->username,$cookieTime);
                              
               // Khoi tao Session
               if(!session_id()){
               session_start();
               }
               session_register('account_id');
               //session_register('user_account_name');
               session_register('username');
               //session_register('user_account_email');
               session_register('usertype');
               session_register('useremail');
               session_register('bibibdate');
               session_register('bibipregnantdate');
               //session_is_registered('user_account_name');
               session_is_registered('username');
               session_is_registered('usertype');
               session_is_registered('useremail');
               session_is_registered('bibibdate');
               session_is_registered('bibipregnantdate');
               //session_is_registered('user_account_email');
               $sql1="SELECT * FROM #__bibi_profiles WHERE account_id=".$rows->account_id;
               $database->setQuery($sql1);
               $database->loadObject($List);
               $_SESSION['account_id']=$rows->account_id;
               $_SESSION['username']=$rows->username;
               $_SESSION['useremail']=$rows->email;
               $_SESSION['bibibdate']=$List->birthday;
               $_SESSION['bibipregnantdate']=$List->pregnant_date;
               session_write_close();
               mosCache::cleanCache();
               //// Chuc nang sau khi dang nhap
               //$message="Xin chào : ". $rows->username;      
               //HtmlbibiAccount::activate($option,$message);
               mosRedirect("index.php?option=bibicontent");
            }
            else
            {
               create_cookie('username','',$cookieTime);
               create_cookie('password','',$cookieTime);
               echo "<script>alert('Sai mật khẩu!'); window.history.go(-1); </script>\n";
            }
         }
         else
         {
            create_cookie('username','',$cookieTime);
            create_cookie('password','',$cookieTime);
            echo "<script> alert('Người dùng chưa được Activate.'); window.history.go(-1); </script>\n";
         }
         
      }
      else
      {
         create_cookie('username','',$cookieTime);
         create_cookie('password','',$cookieTime);
         echo "<script> alert('Người dùng chưa đăng ký.'); window.history.go(-1); </script>\n";
      }
   
}
function checkUser($username,$password,$cookieTime)
 {
    
 }
function create_cookie($name, $value = "",$cookieTime=31536000)
{
   $expires = time() + $cookieTime;
   setcookie($name, $value, $expires,"/","");
}


?>
« Last Edit: July 09, 2007, 06:03:13 AM by giangnt »

Orstio

  • Guest
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #10 on: July 09, 2007, 07:01:01 AM »
Either your CMS is Joomla, or you have a whole lot of Joomla code in there that you shouldn't.

Offline MCo

  • Newbie
  • *
  • Posts: 7
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #11 on: July 09, 2007, 10:55:22 AM »
Hello,

I would like to connect "automatically" my portal users to SMF. I have a form asking user/password, and I check in my tables if it is correct. Then, I would like to active SMF cookie. In simple words, what should I add to my program ?

Offline jjgallow

  • Jr. Member
  • **
  • Posts: 122
    • StockDiaries.com
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #12 on: July 09, 2007, 05:57:28 PM »
Hello Orstio,

Thanks for the code to change integrate_register!

These hooks are great, and I'm almost done my plugin to utilize them.

I'm creating a plugin for others to use as well, so I'm a little scared to be moving that hook around and creating compatibility problems.

For now, my plugin will create it's own hook at that insertion point, so it will still be compatible with other systems that use integrate_register, as well as future versions of SMF which may end up having integrate_register in another location.

cheers!

Offline Carpento

  • Semi-Newbie
  • *
  • Posts: 31
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #13 on: July 15, 2007, 09:10:48 AM »
I am not very well known with SMF at the moment but I am convinced it is very powerful forum software. I am planning to completely rebuild an existing website. This site contains currently a PHPBB forum and also a custom part (with written articles, a photogallery and more). Both parts use the same login information, but you still have to login twice. (If you log in at the forum, you are not logged in at the rest of the site, and otherwise).

Anyway, I would like to use SMF in the future for the forum. I already discovered some possibilities of SSI.php but these integration hooks seem to be more powerful.

My real question is: Is it possible to have only one central login (that of SMF of course) that is used for both forum and the rest of the site ? I'd like to have a possibility to login on the forum ánd on the other part of the site, but you need to login only once for both parts.

Although I read the topic about the integration hooks this did not become totally clear to me, could anybody tell me ?

Orstio

  • Guest
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #14 on: July 15, 2007, 11:55:07 AM »
Yes, the hooks allow you to use SMF's login procedure to login to both SMF and another application.

Offline Carpento

  • Semi-Newbie
  • *
  • Posts: 31
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #15 on: July 15, 2007, 12:14:37 PM »
Yes, the hooks allow you to use SMF's login procedure to login to both SMF and another application.

Even if the login-form is on located on the other application ? (So that in fact no forum is seen when logging in to the other part of the site...)

That would be nicest :)
« Last Edit: July 15, 2007, 12:16:58 PM by Carpento »

Orstio

  • Guest
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #16 on: July 15, 2007, 12:24:02 PM »
In order to use the SMF login hook, the form must submit to SMF.

Offline Carpento

  • Semi-Newbie
  • *
  • Posts: 31
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #17 on: July 16, 2007, 06:01:50 AM »
Well, I feel free to ask some more ;)

How likely is it that these hooks will be available in SMF 2.0 too ? SMF 2.0 looks even more promising but in fact I don't want to wait for it to be released because I would like to start developing the rest of my site this holiday. If the integration hooks remain the same I can use 1.1.3 to develop and (hopefully) switch to 2.0 later.

Is anything known about that ?

Orstio

  • Guest
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #18 on: July 16, 2007, 07:07:23 AM »
The hooks will remain in 2.0.

Offline gazraa

  • Semi-Newbie
  • *
  • Posts: 10
Re: Questions/Comments on "A guide to the SMF integration hooks"
« Reply #19 on: July 18, 2007, 06:09:15 AM »
right, I've been reading this and I think I am getting there.... but want to make sure.

On my own custom built cms when someone logs in, they need to be logged into the forum too so I would now have to use the SMF login with my CMS code in that?

When someone registers on my CMS, can I just call a hook to register on SMF too so it's transparent to the user?

Once I have go those two things sorted, I think the rest will fall into place. I don't want to do massive changes to my existing CMS and keep disruption to a minimum while I'm trying to get this to work.