New into smf coding (some help please)

Started by marcusslavorum, November 14, 2013, 08:42:19 AM

Previous topic - Next topic

marcusslavorum

Hello all. I've been using SMF for 2 years now and i love it as it's fast, ritch in features, secured and thus i have achieved a successful website with nice community thanks to smf. Being forced due to my website to maintain the website i've been dwelling into php more and more so i figured hey if i'm into maintaining the website all the time i might as well learn php completely to contribute SMF community and my own website.

So I'm going atm onto extensive php programming classes also, and i've played a lot with both php code and software as wordpress which is rather simple to understand.
Now i've started to look up into smf code and it's really big, robust and abstract (unlike wordpress) so i'm having some problems in understanding how all and everything works, but i guess i'd need at least a year or two just focusing into SMF to understand everything. Best way to learn i guess is to start making changes and modding around so if anyone can help me around a bit i'd be greatful as i look forward into learning about smf. I've read most of the docs and wiki, and searched quite a bit here on forum to see how things are made. I've set one empty smf forum install to start practicing.

Question:
* Smf doesn't use a lot of DB dumping in mods, rather stores through xml files as arrays filled with info/values on mod settings into parent arrays as in Managesettings.php and throught that they end up in settings table in mysql. Is that right or am i missing something?


Mod example - question

So let's say i want to make a "profile avatar mod" that in settings gives to Admin an option to select a default member group that will have certain avatar size and to select other/few non-post based membergroups (as premium members/moderators/admin etc.) that would have a certain larger size avatars.

Options in settings should be something like:
Fill in default avatar size [50px] <--textbox
Fill in special membergroup avatar size [100px] <--textbox
Pick special membergroup ["Premium membergroup"] <- select dropdown



So what pages contain profile avatar info?
* I'm understanding that Subs.php and Load.php contain the info that i should edit for the actual sizes of avatar as profile avatar comes from Load.php through loadMemberContext() ?
* and to add settings (learning from that WIP tutorial), i need to edit ManageSettings.php, Admin.php and that's it?
* where are global variables $txt['something'], $context['something'] and modsettings['something'] stored?

Thanks in advance, i'm just trying to pick up the whole things :)

Arantor

QuoteSmf doesn't use a lot of DB dumping in mods, rather stores through xml files as arrays filled with info/values on mod settings into parent arrays as in Managesettings.php and throught that they end up in settings table in mysql. Is that right or am i missing something?

Well, no XML is used for settings at all.

The arrays used in ManageSettings.php indicate the type of settings and their names, and that's all PHP. prepateDBSettingContext() sets up the data for use with the form itself, template_show_settings invariably displays it. And when received, saveDBSettings will save it to the database. (For simple settings pages, at least. Complex pages, not so much)

Quote* I'm understanding that Subs.php and Load.php contain the info that i should edit for the actual sizes of avatar as profile avatar comes from Load.php through loadMemberContext() ?

Load.php does this. The only place where Subs.php will do so is for the current user.

Quote* and to add settings (learning from that WIP tutorial), i need to edit ManageSettings.php, Admin.php and that's it?

Why edit Admin.php? You don't need to edit it if you're putting the settings into the Configuration > Mod Settings page ;)

Technically, you don't need to edit of these, they can be expanded upon using hooks but editing is probably a simpler solution right now.

Quote* where are global variables $txt['something'], $context['something'] and modsettings['something'] stored?

That's kind of the point, they're not. They're generated over time.

$context is declared in index.php, and each part of the page that loads adds more to it to contain the current state of everything going on with SMF in that page.

$modSettings is declared primarily in Load.php, where it loads it from the database. You should, in general, have little reason to touch the declaration of this.

$txt is declared early on but its contents are defined by the Themes/default/languages file, which are loaded as needed, and then expand $txt as they are loaded.


Doing what you're doing is surprisingly complex, actually. There is no way to create a drop down of groups just as-is. You will need to create a regular dropdown (using the 'select' type) and populate it using the group list obtained from your own query.
Holder of controversial views, all of which my own.


marcusslavorum

Quote from: Arantor on November 14, 2013, 10:54:01 AM



Doing what you're doing is surprisingly complex, actually. There is no way to create a drop down of groups just as-is. You will need to create a regular dropdown (using the 'select' type) and populate it using the group list obtained from your own query.

Yes i might have phrased myself wrong. That what you said i had in mind, the select populated with non-post member groups that fill in from a query. Thanks for clearing up some things...i'll leave this thread un-solved because i'll be coming back with new problems on the topic i guess, as time goes :)

marcusslavorum

I'm at "work" so i can't open phpmyadmin so i'll ask some of you as i can't check it out myself in database.

In ManageAttachments.php

// Uploadable avatars?
      array('title', 'avatar_upload'),   <---- i see the option is created here


However where is avatar_upload value (probably text "Uploadable avatars") defined, in which file? or is the value during forum installation just dumped in db table avatar_upload?

Arantor

-sigh-

That is a *title*, it does not have a value other than the $txt string which is in the language files like all the others.
Holder of controversial views, all of which my own.


marcusslavorum

Thanks.


Finally got some time to play with smf, so far i've made settings for the new "Upload Special Avatars" below "Upload Avatar" in Avatar Settings. Idea is the admin sets here avatar settings for regular avatars (all post count based groups ) and special avatar settings for special users (non-post based as moderators, custom membergroup, subscribers etc).

Now i should edit the profile Modify profile / Forum profile section.

I was thinking to do it with " if ( user is special group member ) { echo special group form for avatar upload etc} else { echo regular group form for avatar upload etc } ". In order to add these forms i should edit Profile-Modify.php or am i missing something?


Then Load.php would also load users avatar width/height settings according to his member group in similar logic with checking if user is special or regular. Does that make any sense? I'm seeing whole coding around avatars is quite complex.



Kindred

why bother doing this?

SMF already handles assigning and displaying images by membergroup...

it's called "stars" (or badges" by some) and images can be set right in the membergroup setup page (see the badges fro me and Arantor denoting our positions
Сл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."

marcusslavorum

#7
Quote from: Kindred on December 12, 2013, 01:52:08 PM
why bother doing this?

SMF already handles assigning and displaying images by membergroup...

it's called "stars" (or badges" by some) and images can be set right in the membergroup setup page (see the badges fro me and Arantor denoting our positions

Well the feature of moderators and donors having larger avatars than regular members. It's a common feature on Vbulletin (i think) and i've seen many webmasters use it in general, in order to reward their subscribers/donators in visual way besides the badge, to make them feel more important and rewarded etc. Thought it might be kinda useful to some that run forums and depend on donations from subscribers as people love the "RPG" feeling of leveling their account and customizing it.

Also thanks for the hint, will look it up.

Kindred

oh...   so you want certain membergroups to still have their own avatars, but they can have a larger SIZE?

that is more complicated -- but not as complicated as you seem to want to make it....  You don't need a separate form or even a separate field.
You just add conditional to the normal avatar stuff regarding the resizing.
Сл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."

marcusslavorum

Quote from: Kindred on December 13, 2013, 08:12:14 AM
oh...   so you want certain membergroups to still have their own avatars, but they can have a larger SIZE?

that is more complicated -- but not as complicated as you seem to want to make it....  You don't need a separate form or even a separate field.
You just add conditional to the normal avatar stuff regarding the resizing.

Yes, idea is it's their same own avatar, but as soon as they become subscriber or a moderator, they get the larger one...
Hehe yeah you're actually right however i still made a new form just to learn how smf logic works and maybe to give the admin a right to decide himself how large he wants the special avatar to be.

However you're right, it would be maybe just more easy and logical to edit the load.php (right?) and where it's reading avatars width and height to ad a condition where if user is a subscriber just to load different/larger high/width values.

Advertisement: