Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Duban Black on August 27, 2024, 08:16:31 PM

Title: username and profile link variables
Post by: Duban Black on August 27, 2024, 08:16:31 PM
Hi guys,
is there any variable that can be used to post the following values?
- username
- profile link

For example some mods like Custom form (https://custom.simplemachines.org/index.php?mod=1279) uses variables like this: {{Name}}

But I would like that when a person posts through my forms, this data is printed in the message. I need it to facilitate the work of the moderators of my forum.

I was looking in the templates, but variables like this: $message['member']['link'] do not print data.

Title: Re: username and profile link variables
Post by: Kindred on August 27, 2024, 08:54:53 PM
Can you please explain specifically what you are trying to accomplish?

It sounds like the custom form mod already does what you ask,  so why do your own code?
Title: Re: username and profile link variables
Post by: Duban Black on August 27, 2024, 09:08:45 PM
Of course, in the mod I have the following output configured:

[url={{Userlink}}]{{Avatar}} - {{Username}}[/url]
{{Avatar}} is the identifier of a form field.

What I need is to take the username, its profile link and post it as a response, for that I need to know if there is any variable in SMF that contains that data.
Title: Re: username and profile link variables
Post by: Kindred on August 27, 2024, 10:12:28 PM
I mean, there IS a variable in the code that has the value - that's how the mod fills it in to start with.

It's how quoting works...

However, the data is transient.  It's not always available and it's not always the same data...
Title: Re: username and profile link variables
Post by: Duban Black on August 27, 2024, 10:42:25 PM
Quote from: Kindred on August 27, 2024, 10:12:28 PMI mean, there IS a variable in the code that has the value - that's how the mod fills it in to start with.

It's how quoting works...

However, the data is transient.  It's not always available and it's not always the same data...

I think I did not explain well {{Userlink}} and {{Username}} they are an example. I need to get those variables somehow, I don't know how to get them.
Title: Re: username and profile link variables
Post by: Kindred on August 28, 2024, 12:37:44 AM
And I am asking WHY...

What is your end goal? What --specifically -- are you trying to do that you think you need that data?

  Because that will inform the answer.
Title: Re: username and profile link variables
Post by: Arantor on August 28, 2024, 02:10:43 AM
The problem is there's no central place to get them, but depending on you telling us what you're trying to do (rather than how you're trying to do it) it might be possible to get you going.
Title: Re: username and profile link variables
Post by: Duban Black on August 28, 2024, 09:29:15 AM
I need it to be displayed in a code so that moderators can copy and paste that information into a control post that manages the forum. The code has this structure:

[url=profilelink]{{Avatar}} - Username[/url]
{{Avatar}} is already collected with the form automatically, I just need to know with which variable I could grab the username and profile link.

For example if the form response was posted here from my account it should look like this:

[url=https://www.simplemachines.org/community/index.php?action=profile;u=290062]Matt lanter - duban1[/url]

Title: Re: username and profile link variables
Post by: Kindred on August 28, 2024, 09:40:12 AM
You are still not actually telling us what you are doing...

Quote from: duban1 on August 28, 2024, 09:29:15 AMI need it to be displayed in a code so that moderators can copy and paste that information into a control post that manages the forum.

Displayed where?? Copy from what/ what location?

QuoteThe code has this structure:

[url=profilelink]{{Avatar}} - Username[/url]
{{Avatar}} is already collected with the form automatically, I just need to know with which variable I could grab the username and profile link.

Again, the Code has that structure where?  Within the custom forms mod assembly of a post?

QuoteFor example if the form response was posted here from my account it should look like this:

[url=https://www.simplemachines.org/community/index.php?action=profile;u=290062]Matt lanter - duban1[/url]

Ok...  so, yes - from the customer form mod, that is a valid output post.

I still don't understand what you are trying to do that the custom forms mod is not already doing....
Title: Re: username and profile link variables
Post by: Duban Black on August 28, 2024, 10:15:36 AM
Quote from: Kindred on August 28, 2024, 09:40:12 AMYou are still not actually telling us what you are doing...
Displayed where?? Copy from what/ what location?
is shown in a post

Quote from: Kindred on August 28, 2024, 09:40:12 AMAgain, the Code has that structure where?  Within the custom forms mod assembly of a post?
the structure was defined by me in the output of the form

Quote from: Kindred on August 28, 2024, 09:40:12 AMOk...  so, yes - from the customer form mod, that is a valid output post.

I still don't understand what you are trying to do that the custom forms mod is not already doing....
the form captures the data that is entered in its fields, I don't need the mod to do something more specific, what I need is to obtain the system variables that contain the username and profilelink data of the user that posts, because I don't want to ask the user to enter those data manually, I want to obtain them automatically from the system.
Title: Re: username and profile link variables
Post by: Illori on August 28, 2024, 10:26:46 AM
maybe you can make something like this work?

https://custom.simplemachines.org/index.php?mod=1602
Title: Re: username and profile link variables
Post by: Kindred on August 28, 2024, 10:55:40 AM
Illori,

I don't think that mod does anything like what the OP is asking.   That just allows wiki format BBC -- he'd still have to manually enter all of the data within the BBC.  WHat he's looking for (if I get it correctly now) is a way to automatically fill in the username and other details when the user adds a post via the custom form mod.

therefore, I am moving this out of 2.1 support and into coding help -- since this is outside of the core design
Title: Re: username and profile link variables
Post by: Duban Black on August 28, 2024, 11:00:04 AM
Quote from: Kindred on August 28, 2024, 10:55:40 AMIllori,

I don't think that mod does anything like what the OP is asking.   That just allows wiki format BBC -- he'd still have to manually enter all of the data within the BBC.  WHat he's looking for (if I get it correctly now) is a way to automatically fill in the username and other details when the user adds a post via the custom form mod.

therefore, I am moving this out of 2.1 support and into coding help -- since this is outside of the core design

That's right, it would be two pieces of information: user name and profile link.

I could get it using javascript but I prefer to look for a way first using the information that SMF has stored.
Title: Re: username and profile link variables
Post by: Arantor on August 28, 2024, 11:04:54 AM
If there isn't a variable to send it from the custom form code, nothing else matters because you're coming at it from the wrong end.

It *has* to come from the custom form mod - and literally nothing else - when it assembles the post, because literally any other source of that data will be incorrect, because the post's owner is not available to the post content during bbcode rendering, so you can't just magically pull anything in.

Does the custom form mod not have an option to inject the poster's name at the point of creating the post?
Title: Re: username and profile link variables
Post by: Aleksi "Lex" Kilpinen on August 28, 2024, 11:37:30 AM
If I remember correctly, yes it does.
Title: Re: username and profile link variables
Post by: Duban Black on August 28, 2024, 01:14:29 PM
Quote from: Arantor on August 28, 2024, 11:04:54 AMIf there isn't a variable to send it from the custom form code, nothing else matters because you're coming at it from the wrong end.

It *has* to come from the custom form mod - and literally nothing else - when it assembles the post, because literally any other source of that data will be incorrect, because the post's owner is not available to the post content during bbcode rendering, so you can't just magically pull anything in.

Does the custom form mod not have an option to inject the poster's name at the point of creating the post?

I have searched through the mod options and it only injects the information entered manually in the form fields, nothing more than that.
Title: Re: username and profile link variables
Post by: Aleksi "Lex" Kilpinen on August 28, 2024, 01:51:21 PM
Is there a reason you need it IN the message? At least the version I've been using actually posts AS the user, if logged in.
Title: Re: username and profile link variables
Post by: Duban Black on August 28, 2024, 02:50:33 PM
Quote from: Aleksi "Lex" Kilpinen on August 28, 2024, 01:51:21 PMIs there a reason you need it IN the message? At least the version I've been using actually posts AS the user, if logged in.
yes, it must be inside the message because that data will be copied and pasted into a list that is used as a forum log.
It is part of an administrative task
Title: Re: username and profile link variables
Post by: Duban Black on August 28, 2024, 09:53:39 PM
I solved it using this code:

        $userId = $user_info['id'];
        $userName = $user_info['name'];
        $userProfileLink = $scripturl . '?action=profile;u=' . $userId;

        $replaceVars = [
            '*Username*' => $userName,
            '*Userlink*' => $userProfileLink,
        ];

        $output = str_replace(array_keys($replaceVars), array_values($replaceVars), $output);
resolved topic