Advertisement:

Author Topic: New tools to help integrating SMF with something else  (Read 271732 times)

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #60 on: February 25, 2012, 05:20:27 PM »
Glad it works. It will work from anywhere as long as it can find your Settings.php file. Once it finds it, it tries to create a text file with the location saved so it doesn't have to search again. The first time it loads it does the search if it's not in the same directory as Settings.php, and if you didn't specify the location in the script.
It's possible it was unable to write the settings file (no write permissions in the folder it was in) and it failed, or timed out the second time. Are there any error logs for this?
Since you know it works now from the forum directory, you can move it wherever you want, and specify the path to the settings file in the API and it should still work. Delete the settings.txt file with the old location saved too.
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #61 on: February 27, 2012, 11:28:23 AM »
@frytec I think I see your problem. There is a bug in the logout function. Go to ~line 1047 of the API to where the code says:
...
It looks like I had been using the wrong variable name for the member ID  :-[

it still does not work.
its so wierd, all tests are ok, i can log in, but cant log out.
do you have any other idea?
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #62 on: February 27, 2012, 12:26:17 PM »
Replace your entire logout function in the API with this:
Code: [Select]
function smfapi_logout($username='')
{
    global $sourcedir, $user_info, $user_settings, $context, $modSettings, $smcFunc;

    if ($user_info['is_guest']) {
        smfapi_loadUserSettings();
    }

    if ('' == $username) {
        if ($user_info['is_guest']) {
            return false;
        } else {
            $username = $user_info['username'];
        }
    }

    $user_data = smfapi_getUserData($username);

    if (!$user_data) {
        return false;
    }

    //delete them from log_online
    $smcFunc['db_query']('', '
        DELETE FROM {db_prefix}log_online
        WHERE id_member = {int:current_member}',
        array(
            'current_member' => $user_data['id_member'],
        )
    );

    if (isset($_SESSION['pack_ftp'])) {
$_SESSION['pack_ftp'] = null;
    }

// they cannot be open ID verified any longer.
if (isset($_SESSION['openid'])) {
unset($_SESSION['openid']);
    }

// it won't be first login anymore.
if (isset($_SESSION['openid'])) {
    unset($_SESSION['first_login']);
    }

    //destroy the cookie
smfapi_setLoginCookie(-3600, 0);

    return true;
}
and it should work. Let me know :)
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #63 on: February 27, 2012, 01:14:36 PM »
and it should work. Let me know :)

yeah, that worked, lol.
thanks a lot!

now im heading to registration, im sure i will be here again soon, hehehe

edit, im back =D

im trying to make the registration, im using this in my registration block:

   $regOptions = array();
   $regOptions['member_name'] = $username;
   $regOptions['password'] = $password;
   $regOptions['email'] = $email;
   smfapi_registerMember($regOptions);

its like giving me a blank screen when i try to register.
im probably missing something here right?
« Last Edit: February 27, 2012, 02:33:39 PM by frytec »
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #64 on: February 27, 2012, 03:47:09 PM »
That's the correct usage. Make sure you included the API script somewhere before all that. Also make sure those variable are set. There's not going to be any output echo'd from the function, it will return the int member ID or bool false. If you were expecting output from other parts of your script, check the error logs to see why the execution halted; the code you posted looks fine.
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #65 on: February 27, 2012, 04:25:33 PM »
@ andre,

check it:
Quote from: errorlog
[27-Feb-2012 18:20:41] PHP Fatal error: The database value you're trying to insert does not exist: member_ip(smf_2_api.php-1595) in /home/aikaforum/cata/public_html/forum/Sources/Subs-Db-mysql.php on line 684
[27-Feb-2012 18:23:25] PHP Fatal error: The database value you're trying to insert does not exist: p_member_ip(smf_2_api.php-2522) in /home/aikaforum/cata/public_html/forum/Sources/Subs-Db-mysql.php on line 684
[27-Feb-2012 18:23:26] PHP Notice: Undefined index: USER_AGENT in /home/aikaforum/cata/public_html/forum/smf_2_api.php on line 1875
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #66 on: February 27, 2012, 04:42:54 PM »
When you're registering members, the script is trying to use $user_info['ip'] to register the user's IP address with their other info, but it looks like that isn't being set for some reason.
Try calling loadUserSettings() before you register them to try to get the IP.
If that doesn't work, try changing $user_info['ip'] for $_SERVER['REMOTE_ADDR'] on ~line 1475
Is that server variable set? Are you running this on localhost?
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #67 on: February 28, 2012, 02:52:06 PM »
@andre, its running on the server,
i changed the ip thing but that didnt help.
it still not registering.
do you think if i throw my full function here will help your visualization?
or maybe you want to login to my ftp.. idk..
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #68 on: February 29, 2012, 11:30:14 AM »
@andre, its running on the server,
i changed the ip thing but that didnt help.
it still not registering.
do you think if i throw my full function here will help your visualization?
or maybe you want to login to my ftp.. idk..


Hi frytec,
I updated the API to 0.1.2 to fix the issue with those variables being unset, the logout trouble, the magic quotes issue, and anything else mentioned in the previous threads. This should take care of your problem with registering. Can you download the new version (from the first post of this thread) and upload it and try it out?
Try the login, logout too as I modified them a little bit. If it doesn't work still can you post the error message from the log or pm me a temporary ftp account and the location of your script? :)
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #69 on: February 29, 2012, 12:10:48 PM »
ok, im gona test the new version of api, justo to clarify, whats the correct usage of logout function?

smfapi_logout();

or

smfapi_logout($username);

or

smfapi_loadUserSettings(); smfapi_logout();

?

Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #70 on: February 29, 2012, 12:15:50 PM »
ok, im gona test the new version of api, justo to clarify, whats the correct usage of logout function?

smfapi_logout();

or

smfapi_logout($username);

or

smfapi_loadUserSettings(); smfapi_logout();

?


All of those will work, but to keep it simple just use smfapi_logout()

The function will call smfapi_loadUserSettings() itself if it needs to, and it will get the current user so there's no need to pass the username unless you're trying to log out someone who's not the current user from the who's online list :)
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline frytec

  • Jr. Member
  • **
  • Posts: 134
  • Admin Aika Fórum
    • CataLink.com.br
Re: New tools to help integrating SMF with something else
« Reply #71 on: March 02, 2012, 03:55:32 PM »
@andre, i couldnt make the registration works via api, but with some sql queries i made the registration work thought.
so i think this is not an issue anymore,

but i would like help with something:

when i login into my website (and therefore automaticly login SMF), and them close the browser window for a long time, and than reopen it, i appears logged out of my website, but SFM still logged in.

Is there a way to fix this?
Comunidade Aika Forum > http://www.aikaforum.com.br
Portal DetetiveWEB > http://www.detetiveweb.com.br
CataLink.com.br > http://www.catalink.com.br

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #72 on: March 02, 2012, 04:03:35 PM »
@andre, i couldnt make the registration works via api, but with some sql queries i made the registration work thought.
so i think this is not an issue anymore,

but i would like help with something:

when i login into my website (and therefore automaticly login SMF), and them close the browser window for a long time, and than reopen it, i appears logged out of my website, but SFM still logged in.

Is there a way to fix this?

Yes. When you call the login function, specify how long you want them logged into smf as the second parameter of the function. Example:
Code: [Select]
smfapi_login('frytec', 60); //will log in user frytec for 60 minutes

The second parameter should be the integer value of your site's session duration in minutes. So check how long your main site sets the cookie for and just match that :)

Why didn't the register function work for you? I tested it and it worked with the new version of the API, and the old version worked all the time for me too... Did you get any errors, or notice as to why it wouldn't work? That's one of the functions that will almost never fail because all it does is basically db queries and inserts, so as long as the db connection is made and the data you pass in is ok, it should never fail :p
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline Handmade

  • Newbie
  • *
  • Posts: 5
Re: New tools to help integrating SMF with something else
« Reply #73 on: March 05, 2012, 11:22:22 AM »
Would like to take a sec a publicly thank Andre for all his assistance with integration, his work is spotless and functions spot on.
Thanks Andre!! 8)

Offline jershell

  • Newbie
  • *
  • Posts: 1
Re: New tools to help integrating SMF with something else
« Reply #74 on: March 11, 2012, 09:45:22 AM »
Hello, please tell me what the function sends a letter confirming email? when you call smfapi_registermember, the user is created, but the letter was not sent when the 'require' => 'activation'.
PS: Sorry my english, written by "Google Translator".

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #75 on: March 14, 2012, 07:59:43 PM »
Hello, please tell me what the function sends a letter confirming email? when you call smfapi_registermember, the user is created, but the letter was not sent when the 'require' => 'activation'.
PS: Sorry my english, written by "Google Translator".

Try adding this code to the bottom of the smfapi_registerMember() function to add confirmation emails being sent. Put it just before the member ID is returned:
Code: [Select]
global $sourcedir;
require_once($sourcedir . '/Subs-Post.php'); //needed for sendmail and loadEmailTemplate functions
if ($regOptions['require'] == 'activation' || $regOptions['require'] == 'coppa')
{
$replacements = array(
'REALNAME' => $regOptions['register_vars']['real_name'],
'USERNAME' => $regOptions['username'],
'PASSWORD' => $regOptions['password'],
'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
'OPENID' => !empty($regOptions['openid']) ? $regOptions['openid'] : '',
);

if ($regOptions['require'] == 'activation')
$replacements += array(
'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $memberID . ';code=' . $validation_code,
'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $memberID,
'ACTIVATIONCODE' => $validation_code,
);
else
$replacements += array(
'COPPALINK' => $scripturl . '?action=coppa;u=' . $memberID,
);

$emaildata = loadEmailTemplate('register_' . ($regOptions['auth_method'] == 'openid' ? 'openid_' : '') . ($regOptions['require'] == 'activation' ? 'activate' : 'coppa'), $replacements);

sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
}

You might need to make some modifications to get it to work but that's the way SMF is doing it. If you are registering a member through another system though, and using the API to register them in SMF, why not let the other system handle the confirmation and the rest of it too?
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline colby2152

  • Sr. Member
  • ****
  • Posts: 912
  • Gender: Male
    • ProFSL
Re: New tools to help integrating SMF with something else
« Reply #76 on: March 26, 2012, 09:01:39 PM »
Where is the API file? :o
ProFSL.com - Pro Fantasy Sports Leagues - Advanced fantasy sports leagues, contests, free chances at cash/prizes, and sports discussion.

Need a server? I am happy to advocate this hosting solution - hands on customer service and reliability is relieving!!!

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,433
  • Gender: Male
    • Kindred-999 on GitHub
Re: New tools to help integrating SMF with something else
« Reply #77 on: March 27, 2012, 09:52:44 AM »
ummmmm.....    attached to the first post in this thread, silly....
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline kristen_tg

  • Newbie
  • *
  • Posts: 2
Re: New tools to help integrating SMF with something else
« Reply #78 on: March 29, 2012, 09:57:54 PM »
Andre, I'm having a few issues with the API.  I am attempting to integrate it with a custom webapp, nothing more than when the user logs into the site they also get logged into the forums.

Right now I'm just working on the sign in side of things:

Code: [Select]
Notice: Undefined variable: cookieData in /home/public_html/forums_3/smf_2_api.php on line 1909
Notice: A session had already been started - ignoring session_start() in /home/public_html/security_scripts/signin.php on line 56

The user is properly logged into the SMF forums but NOT the application. The session, however, contains the proper information my system needs to validate it.

What's in smf_2_api.php that might be causing this? I suspect it's smfapi_loadSession() although it shouldn't execute if a session already exists (should it?)

ETA:

I solved the loadSesssion() error.  Feel a little silly now.  :o Too many 14 hours days in a row....

Still getting the $cookiedata notice. Would that be a cookie path issue? 



« Last Edit: March 29, 2012, 10:29:59 PM by kristen_tg »

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: New tools to help integrating SMF with something else
« Reply #79 on: March 30, 2012, 12:39:19 PM »
Hi kristen_tg,

The API doesn't really need a session for anything. You can prevent it from starting one, or start your other webapp session first. loadSession won't start a session if one exists but it will always be called.

For the error, looks like $cookieData wasn't declared by the time the script got to line 1909, which means that your SMF cookie probably isn't set yet because it didn't go through the previous if/elseif block that would've set it.

You could add the @ operator to suppress the error from having the variable unset like this:
Code: [Select]
if (0 == $id_member) {
        $unserializedData = array();
        $success = funserialize(@$cookieData, $unserializedData);
        if ($success) {
            $id_member = $unserializedData[0];
            $password  = $unserializedData[1];
        } else {
            // they're either a guest or your cookie is not visible
        }
}

Or, probably safer, declare $cookieData again just in case...
Code: [Select]
if (0 == $id_member) {
        $unserializedData = array();
        $cookieData = stripslashes($_COOKIE[$cookiename]);
        $success = funserialize($cookieData, $unserializedData);
        if ($success) {
            $id_member = $unserializedData[0];
            $password  = $unserializedData[1];
        } else {
            // they're either a guest or your cookie is not visible (need subdomain independent cookies)
        }
}

let me know how that works :)
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"