looking for docco on context and is_admin, is_mod, can_mod...

Started by Deprecated, July 31, 2008, 05:06:50 PM

Previous topic - Next topic

Deprecated

I've looked all around the SMF site and can't find any explanation of these things. I did find adding your own custom, but I don't need to understand custom. I need to understand the existing code first, and then I'm sure custom will become clear if I need it later.

I'm trying to modify a mod from the SMF mod site, to change it from admin only to mod only. I have a user group based upon global moderator, and I want that derivative class of members to be able to use the mod.

If there's no docco, perhaps somebody could recommend which file I need to reverse engineer? :)

SMF 2.0 Beta 3.1

Thanks!

Nathaniel

I don't believe that there is good documentation for that sort of stuff. The best way to learn about the SMF system is to look through the source code, you can also use the var_dump() function to show the contents of arrays if you need to see what they have in them.

I can probably help or tell you what you need to do, if you can name the mod which you are trying to edit. There is no specific file that this sort of stuff is set up in, its ussually used throughout the source files of SMF.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

Deprecated

I had a feeling I was going to just have to read the code. Gawd, how many places I've worked at where the code IS the documentation. ;) And what's worse, apparently nobody I worked with had ever heard of comments!

I'm trying to understand the context of is_admin, is_mod, can_mod, and wonder if there are any related ones. Of course is_admin seems clear, but I'm a little confused with the other two. I've already written one (small) mod package that didn't need this, but my next mod will, so I'm going to have to understand the concept. If you or anybody has a specific PHP file in mind where these are best illustrated I'll appreciate knowing the file name.

I'm modifying Remove Post Modified (Last Edit) Time to allow use by moderators. To be more precise, I have a member group based upon Global Moderator, and I want both Global Moderator and the derived group to be able to use the Remove Modified. If at all possible, other members with moderating privileges but not Global or the derived group should not be able to remove tags.

I believe changing these two lines will do it but haven't tried it yet:

if($context['user']['is_admin'])

That's in Display.template.php. I was going to change it to:

if($context['user']['is_admin'] || $context['user']['is_mod'])

The other line is in RemoveModified.php which is:

isAllowedTo('admin_forum');

I would be guessing at the equivalent for a moderator and here's my guess:

isAllowedTo('mod_forum');

So I was going to try that stuff out, but my experience is that it's better to understand what you're doing rather than just throwing code against the wall and seeing what sticks. :)

So that's what's going on with my mod mod, and I'll appreciate any advice or enlightenment that can be provided.

Eliana Tamerin

is_admin asks if the user is in group #1 (the normal admin group on default SMF)
is_mod asks if the person has moderator capabilities for a particular board
admin_forum checks the particular permission of Admin Forum & Database
mod_forum doesn't exist, but moderate_forum does, and that checks if a user has global permissions to moderate
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

Deprecated

Thank you so much Eliana! That perfectly covers what I needed to know, and now I can go make my mod of the mod probably with no further problems. :D

Deprecated

I've got my modified Remove Post Modified (Last Edit) Time mod working, not quite the way I had intended it to work, but it works. I wanted to give only global moderators the additional ability to remove "edited by" tags, but finally I ended up giving it to all moderators, apparently. I was trying to use is_mod to control whether the "Remove" tag is visible, but my Global Moderator account couldn't see the tag. I finally ended up going with can_mod which I presume applies to all moderators plus Global Moderators and Administrators.

When clicked the link takes you to PresumeModified.php where again I ran into problems making it work right, my Global Moderator being kicked out until I used isAllowedTo('access_mod_center') which is reasonable security check for all mods and admins, although perhaps imperfect.

Honestly, I didn't test it with a board moderator account because it works well enough for me now. I'll appreciate any feedback if anybody notices a bug or security threat. I tested it on 2.0 Beta 3.1 only.

I wouldn't even presume to upload my modified mod package without permission from the author (rsw686) but I think it will be okay to describe what I did if anybody else wants to mod their local copy.




Description: Modification to Remove Post Modified (Last Edit) Time to allow access by moderators in addition to the original administrator access.

In 2b3-install.xml change if($context['user']['is_admin']) to if($context['user']['can_mod']).

In RemoveModified.php, change isAllowedTo('admin_forum') to if($context['user']['can_mod'])




I know somebody will ask why I didn't use isAllowedTo('moderate_forum') and all I can say is it didn't work. I tried various other methods in both areas, and ended up with not what I wanted but good enough. If anybody else is interested, by all means go ahead and tinker with it.

It would be kind of nice if the mod had some settings in the admin area to select admin only, admin and global mods, or admin, global and regular mods. It would also be nice if an armored truck drove past my house and a bag of $100 bills fell out. ;) I'm tired of playing with it and I'm moving on to working on my own original mod. If anybody thinks I should post this somewhere else (the mod apparently has no discussion thread) let me know. If the author should be informed, please do so.

Thank you all for your help. If nothing else I've learned a lot more about SMF internals. :)

Eliana Tamerin

IMHO, you should post that in rsw686's support topic for the mod.
Do NOT PM me for support.

SimplePortal 2.3.6 is OUT!
SimplePortal Project Manager
Download | Docs
SimplePortal: Power of Simplicity!

Deprecated

There is none linked from the mod site and searching the forums revealed no topics on his mod. If you can find it, please tell me where it is and I'll do it. :)


Deprecated

Well I guess it helps to have been on the site for a while. I've been all over the mod page

http://custom.simplemachines.org/mods/index.php?mod=982

and can't find any link to the discussion thread, and I searched the mod board for that mod, and found nada.

After reading the thread you linked I think I'll re-think my modifications. Evidently more experienced people have been over the same ground, and their solutions may be more elegant than mine.

I go bye bye. :) Thanks! :)

[SiNaN]

I got lost. Do you want just the global moderators or the board moderators in their board too?
Former SMF Core Developer | My Mods | SimplePortal

Deprecated

I had intended to just make it just global moderators. I haven't tested for it, but I expect my changes above would let both global mods and board mods remove the tags. On a big forum that would be too much power in the hands of too many.

I've got only one global mod and myself as admin, so it's not very important right now. If my forum grows as I hope, by the time I need another moderator I'll probably know enough SMF to restrict to global mods.

Actually as I looked through the code I saw some more complicated stuff that would probably work. I lost interest since my forum was down due to stupid server ops, and had to move it to a different hosting service. It wasn't a good time to keep writing code.

I'm happy with it right now. It wouldn't make any practical difference to me if it worked the other way.

This SMF code is addictive. Why didn't anybody warn me of that? :D

Nathaniel

Quote from: Deprecated on August 02, 2008, 02:35:08 AM
This SMF code is addictive. Why didn't anybody warn me of that? :D

Because now that you are sucked in, you have to make millions of mods and help the community with its ultimate aim of world domination! ;D
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

[SiNaN]

$context['user']['is_admin'] is true only if the user in the group with the ID of 1.

$context['user']['is_mod'] is true only if the user is the moderator of the specified board. It is false for global moderators.

$context['user']['can_mod'] is true only if the user has access to the mod center or is a moderator of a board/group.

If you want to just check if the guy is a Global Moderator or not, try this:

if(in_array(2, $user_info['groups']))
     echo 'I\'m a global moderator.';
Former SMF Core Developer | My Mods | SimplePortal

Deprecated

Yeah, that's the code I was considering trying. I recognize it. :)

I needed is_admin plus your code above to make it work. One question though, my global moderators are actually in a group derived from global moderators. I suspect that means they are in a different group, not 2. But now that I've got the idea, I just need to find out what group they are in and test for that number.

I think I can get it going later today when I wake up. Thanks!

[SiNaN]

$user_info['groups'] is the index where all the groups that user in are added. Just you need to change 2 with the ID of the group that your moderators are in. You can see the ID from

Admin CP >> Membergroups

in the url of the membergroup.
Former SMF Core Developer | My Mods | SimplePortal

Deprecated

I've learned quite a lot in the last week, in fact never heard of SMF until about 10-12 days ago. Just a couple days ago I installed phpMySQL and yesterday I was browsing through the database, and can see all the greatest info there. It's like "God mode." :)

Well I've just poured my first cup of coffee, so my blood stream has not reached sufficient caffeine level for programming yet. :D

Advertisement: