News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

New tools to help integrating SMF with something else

Started by Andre N, September 19, 2011, 01:35:36 PM

Previous topic - Next topic

mpglivecarlo

thank you so much for this api didnt know it and now im loving it.

cnttlc

Please help show on site home page 10 last post by catalog.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

mpglivecarlo

Hi, wanted to report that when the api is used to register new members, the stats from forum dont get updated, can anyone help? thx

Mystic83

Hey all, I'm having difficulties using this API to get avatar data.

The avatar array doesn't seem to have anything useful in it for onsite avatars. The attachment id can't be used by any functions, as far as I can tell, and the the filename is incorrect. A little bit of poking around shows that on SMF, the attachments are loaded using the id, but I don't appear to be able to do that outside of those particular files. In addition, there is some hashing going on with regards to attachment names, which might explain why the filename is incorrect.

So what am I supposed to do with the data I'm given? I believe using SSI.php solves this problem, but because I need some of the things in the api, it seems silly to use both...

guzh

Quote from: Mystic83 on October 11, 2012, 05:59:53 AM
Hey all, I'm having difficulties using this API to get avatar data.
At least for my use, this worked fine:
<img src="path/to/forum/index.php?action=dlattach;attach=<?php echo $user_info["avatar"]["id_attach"]; ?>;type=avatar" />
It would be a lot easier if the $user_info["avatar"]["url"] pointed to the correct url, though..

Kindred

instead of user_info, you could use
$context['user']['avatar']['href'] or $context['user']['avatar']['image']
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

guzh

Quote from: Kindred on October 12, 2012, 07:29:33 AM
instead of user_info, you could use
$context['user']['avatar']['href'] or $context['user']['avatar']['image']
Yeah, that's an option. But as he/she's already using some functions in the API it shouldn't be necessary to also use the SSI.

I think that $user_info["avatar"]["url"] should be exactly the same as $context['user']['avatar']['href'], and I think that is the intention as well.
However $user_info["avatar"]["url"] doesn't return anything. it's empty.

Kindred

incorrect
$user_info['avatar']['url'] returns the RELATIVE filename/URL of the avatar...
[url] => Symbolism/Vetruvian Man.png

assuming the system defined avatar directory for system avatars and the rest of the array is for custom uploaded avatars...


    [avatar] => Array
        (
            [url] => Symbolism/Vetruvian Man.png
            [filename] =>
            [custom_dir] =>
            [id_attach] => 0
        )
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

guzh

hm.. mine returns:
["avatar"]=>  array(4) {
    ["url"]=>  string(0) ""
    ["filename"]=> string(12) "avatar_6.jpg"
    ["custom_dir"]=> bool(false)
    ["id_attach"]=> string(1) "3"
}



any idea why mine returns something else than yours?

Kindred

hmmm....   good question.

my excerpt was generated by using 
echo '<pre>'; print_r($user_info); echo '</pre>';

(I did include SSI... maybe that's it?)

the user currently logged in is using a system avatar in a subdirectory of the base avatars directory (defined in SMF admin and stored in the database)
   smf_settings.avatar_directory
   smf_settings.avatar_url
the two other settings which might be important
   smf_settings.custom_avatar_directory
   smf_settings.custom_avatar_url
and of course
   smf_members.avatar

I believe that, if the user has an external avatar, the url would be the full url.
I THINK that the filename and custom_dir are for uploaded avatars...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

guzh

I used var_dump, but that shouldn't matter. And I included SSI as well.

I couldn't find smf_settings.custom_avatar_directory and smf_settings_custom_avatar_url.
and at the user logged in the smf_members.avatar is empty.

The avatar is stored in smf_attachment for the user. However if the user use a system avatar it is stored in smf_members.avatar.

It may be because I some years ago moved from phpbb to SMF...?

Anyway. I'll just use the SSI as well as the API, for this matter I think..

Kindred

well, maybe you never set a custom upload directory?

avatar is stored in attachment if it's an uploaded avatar
url is stored in members.avatar if they include an external url (again, the capability for this depends on your settings)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

mredd

Hi All.

OK I am proberbly going to sound real stupid now.

QuoteHow 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)

done this but cant find the settings txt file.

Quote2. 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.

what script do I add it to ?

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

what script do I add it to ?

See told you I would sound real stupid.

Thanks for any help given.
mredd.


Kindred

1- per the instructions you have to CREATE the settings.txt file
2- whatever script you are trying to integrate smf into
3- see #2....   if you don't understand that - no offense, but you should not be trying to code an API function...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

iainjames88

Any suggestions on how to integrate this with a Laravel 4 application?

Phoenix_IV

Quote from: Andre N on September 19, 2011, 01:35:36 PM
Questions, comments and suggestions welcome.

I posted mine in a new thread, trying to keep all of this a little structured:

Subject: SMF API - smfapi_login() doesn't work for me
Link: http://www.simplemachines.org/community/index.php?topic=511697.0

Suggestion: It might be a good idea for everyone to do it like this; creating a new thread and linking it here. Would you like that?

Phoenix_IV

#138
Double post because it's a while ago since the last post and this contains a new topic.

Two improvements concerning smfapi_login():

1. The function maybe should return false if the user can't be logged in due to his 'is_activated' status plus a hint on the reason. (See Topic: SMF API - smfapi_login() doesn't work for me)

2. The documentation should mention the existence of $regOptions['require'].
Currently the documentation reads:

    int    smfapi_registerMember(array $regOptions)
        - register a member
        - $regOptions will contain the variables from the db
        - dump out the results of smfapi_getUserData($user) to see them all
        - required variables are: 'member_name' (unique), 'email' (unique), 'password'

BUT: Statement #2 does not include the field 'is_activated'. This field's value is influenced by the setting $regOptions['require'] (which isn't a field in the table). Example: $regOptions['require'] = 'nothing'). This is because 'require' also triggers the generation of an activation code and such, but thats only one more reason to hint on that option in the documentation.


This would be my updated version of the documentation:

    int    smfapi_registerMember(array $regOptions)
        - register a member
        - $regOptions will contain most variables from the db (table 'members')
            - required variables are: 'member_name' (unique), 'email' (unique), 'password'
            - additional variables are:
                'require'
                    Determines the user's activation status
                    Accepted values: 'nothing', 'activation' (by the user using an activation code)
                    Default: If not set the user will have to be activated by an administrator!
                'memberGroup'
                    Equivalent to field 'id_group'. It will be checked if the given id is valid.
        - $regOptions['register_vars'] will contain ALL variables from the db. However, some of
          these might get overwritten (e.g. 'posts' will always be zero), but also depending on
          the settings from above.
          Dump out the results of smfapi_getUserData($user) or go to the listing of $userdata
          below to see them all.


[...]


/**
* Register a member
*
* Register a new member with SMF
*
* @param  array $regOptions the registration options
*         More information can be found at the head of this file       
* @return int $memberId the user's member id on success
*         array of string $reg_errors on failure. Each string names a reason why this failed.
* @since  0.1.2
*/
function smfapi_registerMember($regOptions)
{

Hitman.pt

Need help
wrote this small script

<?php
require_once('../API/smf_2_api.php');

$usr $_POST['user'];
$pw $_POST['pass'];
$time $_POST['time'];

$res smfapi_authenticate($usr$pw);
if(
$res == 1)
{
smfapi_login($usr);
echo "done";
}
else
{
echo "wrong";
}
?>


It loggs me in on the website but not on SMF any help»?

Advertisement: